Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
LinkCache.h
Go to the documentation of this file.
1/**
2 * @file LinkCache.h
3 * @brief Incoming/outgoing link cache for efficient node-graph traversal (Phase 9).
4 * @author Olympe Engine
5 * @date 2026-03-09
6 *
7 * @details
8 * LinkCache builds two hash-maps (source-node -> outgoing links, target-node ->
9 * incoming links) from a flat vector of ExecPinConnections. The cache is
10 * invalidated whenever the topology changes and lazily rebuilt on next access.
11 *
12 * No ImGui dependency. No external dependencies beyond the standard library
13 * and TaskGraphTemplate.h.
14 *
15 * C++14 compliant — no std::optional, structured bindings, std::filesystem.
16 */
17
18#pragma once
19
20#include <unordered_map>
21#include <vector>
22
23#include "../TaskSystem/TaskGraphTemplate.h"
24
25namespace Olympe {
26
27// ============================================================================
28// LinkCache
29// ============================================================================
30
31/**
32 * @class LinkCache
33 * @brief Singleton that caches per-node incoming/outgoing ExecPinConnection lists.
34 *
35 * Typical usage:
36 * @code
37 * auto& lc = LinkCache::Get();
38 * lc.Rebuild(myTemplate.ExecConnections);
39 * const auto& out = lc.GetOutgoing(nodeId);
40 * const auto& in = lc.GetIncoming(nodeId);
41 * @endcode
42 */
43class LinkCache {
44public:
45
46 // -----------------------------------------------------------------------
47 // Singleton access
48 // -----------------------------------------------------------------------
49
50 /** @brief Returns the single shared instance. */
51 static LinkCache& Get();
52
53 // -----------------------------------------------------------------------
54 // Cache management
55 // -----------------------------------------------------------------------
56
57 /**
58 * @brief Rebuilds both outgoing and incoming maps from the supplied list.
59 *
60 * @param connections Flat list of exec-pin connections (e.g. from a
61 * TaskGraphTemplate).
62 */
63 void Rebuild(const std::vector<ExecPinConnection>& connections);
64
65 /**
66 * @brief Marks the cache as stale. The next Rebuild() call refreshes it.
67 */
68 void Invalidate();
69
70 /**
71 * @brief Returns true if the cache has been built and is not stale.
72 */
73 bool IsValid() const;
74
75 // -----------------------------------------------------------------------
76 // Accessors
77 // -----------------------------------------------------------------------
78
79 /**
80 * @brief Returns the list of connections that originate from @p nodeId.
81 * Returns an empty vector if the node has no outgoing connections.
82 */
83 const std::vector<ExecPinConnection>& GetOutgoing(int nodeId) const;
84
85 /**
86 * @brief Returns the list of connections that terminate at @p nodeId.
87 * Returns an empty vector if the node has no incoming connections.
88 */
89 const std::vector<ExecPinConnection>& GetIncoming(int nodeId) const;
90
91 /**
92 * @brief Returns the total number of connections stored in the cache.
93 */
94 int GetConnectionCount() const;
95
96private:
97
98 LinkCache();
99
100 std::unordered_map<int, std::vector<ExecPinConnection>> m_Outgoing;
101 std::unordered_map<int, std::vector<ExecPinConnection>> m_Incoming;
102 std::vector<ExecPinConnection> m_EmptyList; ///< Returned for misses
105};
106
107} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
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