Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
ConnectionCache.h
Go to the documentation of this file.
1/**
2 * @file ConnectionCache.h
3 * @brief Bezier control-point cache for VS graph connections (Phase 7).
4 * @author Olympe Engine
5 * @date 2026-03-10
6 *
7 * @details
8 * ConnectionCache avoids recomputing cubic Bezier control points for every
9 * rendered connection each frame. When a connection's endpoints change,
10 * the caller calls Invalidate() so the renderer recomputes and re-stores
11 * the points via SetBezier().
12 *
13 * C++14 compliant — no std::optional, structured bindings, std::filesystem.
14 */
15
16#pragma once
17
18#include <cstddef>
19#include <map>
20
21namespace Olympe {
22
23// ============================================================================
24// Supporting types
25// ============================================================================
26
27/**
28 * @struct BezierPoints
29 * @brief Four cubic Bezier control points (P0..P3).
30 */
32 float p0x, p0y; ///< Start point
33 float p1x, p1y; ///< First control point
34 float p2x, p2y; ///< Second control point
35 float p3x, p3y; ///< End point
36};
37
38// ============================================================================
39// ConnectionCache
40// ============================================================================
41
42/**
43 * @class ConnectionCache
44 * @brief Singleton cache mapping connection IDs to Bezier control points.
45 *
46 * Typical usage:
47 * @code
48 * auto& cc = ConnectionCache::Get();
49 * if (!cc.HasCached(connId))
50 * {
51 * BezierPoints pts = ComputeBezier(src, dst);
52 * cc.SetBezier(connId, pts);
53 * }
54 * const BezierPoints& pts = cc.GetBezier(connId);
55 * DrawBezier(pts);
56 * @endcode
57 */
59public:
60
61 // -----------------------------------------------------------------------
62 // Singleton access
63 // -----------------------------------------------------------------------
64
65 /**
66 * @brief Returns the single shared instance.
67 */
68 static ConnectionCache& Get();
69
70 // -----------------------------------------------------------------------
71 // Cache operations
72 // -----------------------------------------------------------------------
73
74 /**
75 * @brief Returns true if Bezier points are stored for @p connectionId.
76 */
77 bool HasCached(int connectionId) const;
78
79 /**
80 * @brief Returns the cached Bezier points for @p connectionId.
81 * Returns a default (zero-initialised) BezierPoints if not cached.
82 */
83 const BezierPoints& GetBezier(int connectionId) const;
84
85 /**
86 * @brief Stores or overwrites the Bezier points for @p connectionId.
87 */
88 void SetBezier(int connectionId, const BezierPoints& pts);
89
90 /**
91 * @brief Removes the cached entry for @p connectionId.
92 */
93 void Invalidate(int connectionId);
94
95 /**
96 * @brief Clears all cached entries.
97 */
98 void InvalidateAll();
99
100 /**
101 * @brief Returns the number of entries currently in the cache.
102 */
103 size_t GetCacheSize() const;
104
105private:
106
108
109 std::map<int, BezierPoints> m_Cache;
110 BezierPoints m_DefaultBezier; ///< Returned when ID is not in cache
111};
112
113} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Singleton cache mapping connection IDs to Bezier control points.
std::map< int, BezierPoints > m_Cache
BezierPoints m_DefaultBezier
Returned when ID is not in cache.
bool HasCached(int connectionId) const
Returns true if Bezier points are stored for connectionId.
void SetBezier(int connectionId, const BezierPoints &pts)
Stores or overwrites the Bezier points for connectionId.
static ConnectionCache & Get()
Returns the single shared instance.
size_t GetCacheSize() const
Returns the number of entries currently in the cache.
void InvalidateAll()
Clears all cached entries.
void Invalidate(int connectionId)
Removes the cached entry for connectionId.
const BezierPoints & GetBezier(int connectionId) const
Returns the cached Bezier points for connectionId.
< Provides AssetID and INVALID_ASSET_ID
Four cubic Bezier control points (P0..P3).
float p2y
Second control point.
float p0y
Start point.
float p1y
First control point.
float p3y
End point.