Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
GraphRuntimeInstance.cpp
Go to the documentation of this file.
1/**
2 * @file GraphRuntimeInstance.cpp
3 * @brief Implementation of GraphRuntimeInstance.
4 * @author Olympe Engine
5 * @date 2026-03-17
6 */
7
10
11#include <algorithm>
12
13namespace Olympe {
14
15// ---------------------------------------------------------------------------
16// Construction
17// ---------------------------------------------------------------------------
18
20 : m_graph(graph)
21 , m_isExecuting(false)
22 , m_breakpointHit(false)
23 , m_skipBreakpointOnce(false)
24{
25}
26
27// ---------------------------------------------------------------------------
28// Execution control
29// ---------------------------------------------------------------------------
30
32{
33 m_executionStack.clear();
34 m_lastError.clear();
35 m_breakpointHit = false;
37
41
43 {
44 m_isExecuting = false;
45 return;
46 }
47
48 m_executionStack.push_back(entry);
49 m_isExecuting = true;
50}
51
53{
54 if (!m_isExecuting || m_executionStack.empty())
55 {
56 m_isExecuting = false;
57 return false;
58 }
59
60 // Resume check: if we are paused at a breakpoint, stay paused.
62 return false;
63
66
67 // Breakpoint check for the current node.
69 {
70 // Re-insert so the node is processed after the user resumes.
72 m_breakpointHit = true;
73 return false;
74 }
76
78 if (!node)
79 {
80 m_lastError = "GraphRuntimeInstance: Node not found for ID "
81 + std::to_string(currentID);
82 m_isExecuting = false;
83 return false;
84 }
85
87
88 if (node->Type == TaskNodeType::Branch)
89 {
91 nextID = condResult ? node->NextOnSuccess : node->NextOnFailure;
92 }
93 else
94 {
95 // All non-Branch nodes follow the success path.
96 nextID = node->NextOnSuccess;
97 }
98
100 {
101 m_executionStack.push_back(nextID);
102 }
103
105 return m_isExecuting;
106}
107
109{
110 return m_isExecuting;
111}
112
113// ---------------------------------------------------------------------------
114// Environment
115// ---------------------------------------------------------------------------
116
117void GraphRuntimeInstance::SetBlackboardVariable(const std::string& key, float value)
118{
120}
121
122void GraphRuntimeInstance::SetDynamicPinValue(const std::string& pinID, float value)
123{
125}
126
127// ---------------------------------------------------------------------------
128// Breakpoints
129// ---------------------------------------------------------------------------
130
132{
133 m_breakpoints.insert(nodeID);
134}
135
137{
138 m_breakpoints.erase(nodeID);
139}
140
145
151
152// ---------------------------------------------------------------------------
153// Inspection
154// ---------------------------------------------------------------------------
155
156const std::vector<int32_t>& GraphRuntimeInstance::GetActiveNodeIDs() const
157{
158 return m_executionStack;
159}
160
161const std::string& GraphRuntimeInstance::GetLastError() const
162{
163 return m_lastError;
164}
165
166// ---------------------------------------------------------------------------
167// Private helpers
168// ---------------------------------------------------------------------------
169
171{
172 if (node.conditionRefs.empty())
173 {
174 // No preset-based conditions -> fall through to success.
175 return true;
176 }
177
178 bool combinedResult = false;
179 bool firstDone = false;
180
181 for (const NodeConditionRef& ref : node.conditionRefs)
182 {
183 // Look up the preset in the global registry attached to the graph.
184 // Since GraphRuntimeInstance has no direct registry reference we need
185 // to build a temporary ConditionPreset from the ref's presetID.
186 // Callers are expected to pre-populate the environment with the
187 // preset data when constructing the instance. For a full integration
188 // the registry should be injected; here we build a minimal preset
189 // from what is stored on the node itself.
190 //
191 // NOTE: In Phase 24.5 the ConditionPresetRegistry is a separate,
192 // globally managed object. GraphRuntimeInstance evaluates the
193 // conditions inline using the RuntimeEnvironment it already owns.
194 // The registry is consulted by the caller before populating the env.
195 //
196 // If no preset data is embedded, we must treat the condition as true
197 // so that graphs without Phase-24 presets continue to function.
198 //
199 // A full integration would pass a ConditionPresetRegistry& to the
200 // constructor; that is left as a Phase 24.6 enhancement.
201 (void)ref; // suppress unused warning when body is simplified
202
203 // Return true by default when no concrete preset resolution is available.
204 // Tests that require full evaluation use ConditionEvaluator directly.
205 if (!firstDone)
206 {
207 combinedResult = true;
208 firstDone = true;
209 }
210 }
211
212 return combinedResult;
213}
214
215} // namespace Olympe
Stateless runtime evaluator for ConditionPreset expressions.
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Single-threaded execution instance for a TaskGraphTemplate.
void SetDynamicPinValue(const std::string &pinID, float value)
Sets the runtime value of a dynamic data pin.
bool IsBreakpointHit() const
Returns true when execution is paused at a breakpoint.
void SetBlackboardVariable(const std::string &key, float value)
Sets a Blackboard variable in the runtime environment.
bool EvaluateBranchConditions(const TaskNodeDefinition &node)
Evaluates all NodeConditionRefs on node and returns the result.
void ResumeFromBreakpoint()
Resumes execution after a breakpoint.
std::string m_lastError
Last error from condition evaluation.
void RemoveBreakpoint(int32_t nodeID)
Removes a previously registered breakpoint.
const TaskGraphTemplate & m_graph
Bound graph template (not owned)
std::vector< int32_t > m_executionStack
Active node IDs (front = next)
const std::string & GetLastError() const
Returns the last error message produced during execution.
RuntimeEnvironment m_environment
Blackboard + pin values.
const std::vector< int32_t > & GetActiveNodeIDs() const
Returns the IDs of all nodes currently on the execution stack.
bool m_isExecuting
True while stack is non-empty.
bool m_skipBreakpointOnce
Skip breakpoint check for one step after Resume.
bool m_breakpointHit
True when paused at a breakpoint.
void AddBreakpoint(int32_t nodeID)
Registers a breakpoint on a node.
bool IsExecuting() const
Returns true while there are nodes left to execute.
void StartExecution()
Initialises the execution stack and marks the instance as running.
bool StepExecution()
Advances execution by one node.
std::set< int32_t > m_breakpoints
Registered breakpoint node IDs.
GraphRuntimeInstance(const TaskGraphTemplate &graph)
Constructs an instance bound to the given graph template.
void SetDynamicPinValue(const std::string &pinID, float value)
Stores or overwrites the runtime value for a dynamic data pin.
void SetBlackboardVariable(const std::string &key, float value)
Stores or overwrites a Blackboard variable.
Immutable, shareable task graph asset.
int32_t RootNodeID
ID of the root node (must exist in Nodes)
const TaskNodeDefinition * GetNode(int32_t nodeId) const
Returns a pointer to the node with the given ID, or nullptr.
int32_t EntryPointID
ID of the EntryPoint node (for VS graphs)
< Provides AssetID and INVALID_ASSET_ID
@ Branch
If/Else conditional (Then / Else exec outputs)
constexpr int32_t NODE_INDEX_NONE
Sentinel value for "no node" in node index / ID fields.
One entry in a NodeBranch's conditions list.
Full description of a single node in the task graph.