Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
LinkCache.cpp
Go to the documentation of this file.
1/**
2 * @file LinkCache.cpp
3 * @brief LinkCache implementation (Phase 9).
4 * @author Olympe Engine
5 * @date 2026-03-09
6 */
7
8#include "LinkCache.h"
9
10namespace Olympe {
11
12// ============================================================================
13// Singleton
14// ============================================================================
15
17{
18 static LinkCache s_Instance;
19 return s_Instance;
20}
21
23 : m_IsValid(false)
24 , m_ConnectionCount(0)
25{
26}
27
28// ============================================================================
29// Cache management
30// ============================================================================
31
32void LinkCache::Rebuild(const std::vector<ExecPinConnection>& connections)
33{
34 m_Outgoing.clear();
35 m_Incoming.clear();
37
38 for (size_t i = 0; i < connections.size(); ++i)
39 {
41 m_Outgoing[static_cast<int>(conn.SourceNodeID)].push_back(conn);
42 m_Incoming[static_cast<int>(conn.TargetNodeID)].push_back(conn);
44 }
45
46 m_IsValid = true;
47}
48
50{
51 m_IsValid = false;
52}
53
55{
56 return m_IsValid;
57}
58
59// ============================================================================
60// Accessors
61// ============================================================================
62
63const std::vector<ExecPinConnection>& LinkCache::GetOutgoing(int nodeId) const
64{
65 auto it = m_Outgoing.find(nodeId);
66 if (it != m_Outgoing.end())
67 return it->second;
68 return m_EmptyList;
69}
70
71const std::vector<ExecPinConnection>& LinkCache::GetIncoming(int nodeId) const
72{
73 auto it = m_Incoming.find(nodeId);
74 if (it != m_Incoming.end())
75 return it->second;
76 return m_EmptyList;
77}
78
80{
81 return m_ConnectionCount;
82}
83
84} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Incoming/outgoing link cache for efficient node-graph traversal (Phase 9).
Singleton that caches per-node incoming/outgoing ExecPinConnection lists.
Definition LinkCache.h:43
int GetConnectionCount() const
Returns the total number of connections stored in the cache.
Definition LinkCache.cpp:79
const std::vector< ExecPinConnection > & GetIncoming(int nodeId) const
Returns the list of connections that terminate at nodeId.
Definition LinkCache.cpp:71
void Invalidate()
Marks the cache as stale.
Definition LinkCache.cpp:49
void Rebuild(const std::vector< ExecPinConnection > &connections)
Rebuilds both outgoing and incoming maps from the supplied list.
Definition LinkCache.cpp:32
std::unordered_map< int, std::vector< ExecPinConnection > > m_Incoming
Definition LinkCache.h:101
const std::vector< ExecPinConnection > & GetOutgoing(int nodeId) const
Returns the list of connections that originate from nodeId.
Definition LinkCache.cpp:63
std::unordered_map< int, std::vector< ExecPinConnection > > m_Outgoing
Definition LinkCache.h:100
bool IsValid() const
Returns true if the cache has been built and is not stale.
Definition LinkCache.cpp:54
static LinkCache & Get()
Returns the single shared instance.
Definition LinkCache.cpp:16
std::vector< ExecPinConnection > m_EmptyList
Returned for misses.
Definition LinkCache.h:102
< Provides AssetID and INVALID_ASSET_ID
Explicit connection between a named exec-out pin of a source node and the exec-in pin of a target nod...