Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
TaskRunnerComponent.h
Go to the documentation of this file.
1/**
2 * @file TaskRunnerComponent.h
3 * @brief ECS component that drives task graph execution at runtime.
4 * @author Olympe Engine
5 * @date 2026-02-22
6 *
7 * @details
8 * TaskRunnerComponent holds the per-entity runtime state required to execute
9 * a TaskGraphTemplate. One component instance is attached to each entity
10 * that participates in the Atomic Task System.
11 *
12 * The TaskSystem reads and updates this component every frame to advance
13 * execution through the bound task graph. activeTask stores the IAtomicTask
14 * instance currently executing so that multi-frame Running tasks can be
15 * re-ticked and cleanly Abort()ed when needed.
16 *
17 * C++14 compliant - no C++17/20 features.
18 */
19
20#pragma once
21
22#include <cstdint>
23#include <memory>
24#include <string>
25#include <unordered_map>
26#include <vector>
27
28#include "../../Core/AssetManager.h" ///< Provides AssetID and INVALID_ASSET_ID
29#include "../../TaskSystem/TaskGraphTypes.h" ///< Provides TaskValue and NODE_INDEX_NONE
30
31namespace Olympe {
32
33// Forward declaration: full type is only required in TaskRunnerComponent.cpp
34// where the destructor is defined (unique_ptr delete requires the complete type).
35class IAtomicTask;
36
37/**
38 * @struct TaskRunnerComponent
39 * @brief Per-entity runtime state for task graph execution.
40 *
41 * @details
42 * Fields:
43 * - GraphTemplateID : Identifies which TaskGraphTemplate drives this runner.
44 * - CurrentNodeID : ID of the currently active node.
45 * - StateTimer : Accumulated time (seconds) spent in the current node.
46 * - LocalBlackboard : Typed per-entity blackboard state.
47 * - LastStatus : Result of the most recently completed node execution.
48 * - activeTask : Owning pointer to the IAtomicTask instance currently executing.
49 * - ActiveExecPinName : Name of the active exec pin on the current node.
50 * - SequenceChildIndex : For VSSequence: index of the next child to execute.
51 * - DoOnceFlags : Per-node "already fired" flag (for DoOnce nodes).
52 * - DataPinCache : Frame-local cache of computed data pin values.
53 *
54 * @note TaskRunnerComponent is move-only because activeTask is a unique_ptr.
55 */
57{
58 // -----------------------------------------------------------------------
59 // Status enumeration
60 // -----------------------------------------------------------------------
61
62 /**
63 * @enum TaskStatus
64 * @brief Possible outcomes of a task node execution.
65 */
66 enum class TaskStatus : uint8_t
67 {
68 Success, ///< The node completed successfully.
69 Failure, ///< The node failed.
70 Running, ///< The node is still executing (will be called again next frame).
71 Aborted ///< Execution was interrupted externally.
72 };
73
74 // -----------------------------------------------------------------------
75 // Data members
76 // -----------------------------------------------------------------------
77
78 /// @brief AssetID of the TaskGraphTemplate driving this runner.
79 /// Set to INVALID_ASSET_ID when no template is bound.
81
82 /// @brief Path to the ATS Visual Script JSON asset file (.json).
83 /// When set, TaskSystem can load the template from this path via
84 /// TaskGraphLoader::LoadFromFile() if GraphTemplateID is not yet
85 /// resolved by AssetManager.
86 std::string graphAssetPath;
87
88 /// @brief ID of the currently active node.
90
91 /// @brief Accumulated time (in seconds) spent in the current node state.
92 float StateTimer = 0.0f;
93
94 /// @brief Typed local blackboard for per-entity state.
95 std::unordered_map<std::string, Olympe::TaskValue> LocalBlackboard;
96
97 /// @brief Status returned by the last completed node execution.
99
100 /// @brief Owning pointer to the IAtomicTask instance that is currently
101 /// executing for this runner. nullptr when no task is in flight.
102 /// Persisted across frames so that tasks returning Running are
103 /// re-ticked on the next Process() call. Replaced (old task
104 /// Abort()ed) when the system advances to a different node.
105 std::unique_ptr<IAtomicTask> activeTask;
106
107 /// @brief Name of the active exec pin on the current node (e.g. "Then", "Else", "Loop").
108 std::string ActiveExecPinName;
109
110 /// @brief For VSSequence: index of the next child to execute.
112
113 /// @brief Per-node "already fired" flag for DoOnce nodes (key = nodeID).
114 std::unordered_map<int32_t, bool> DoOnceFlags;
115
116 /// @brief Frame-local cache of computed data pin values (key = "nodeID:pinName").
117 std::unordered_map<std::string, Olympe::TaskValue> DataPinCache;
118
119 // -----------------------------------------------------------------------
120 // Constructors
121 // -----------------------------------------------------------------------
122
125
126 // Move only (unique_ptr member makes copy ill-formed).
129
132};
133
134} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
< Provides AssetID and INVALID_ASSET_ID
uint32_t AssetID
Opaque asset identifier: 32-bit FNV-1a hash of the asset file path.
static const AssetID INVALID_ASSET_ID
Sentinel value indicating an invalid / unloaded asset.
constexpr int32_t NODE_INDEX_NONE
Sentinel value for "no node" in node index / ID fields.
Per-entity runtime state for task graph execution.
int32_t SequenceChildIndex
For VSSequence: index of the next child to execute.
float StateTimer
Accumulated time (in seconds) spent in the current node state.
TaskStatus LastStatus
Status returned by the last completed node execution.
TaskRunnerComponent & operator=(TaskRunnerComponent &&)=default
TaskRunnerComponent(const TaskRunnerComponent &)=delete
std::string ActiveExecPinName
Name of the active exec pin on the current node (e.g. "Then", "Else", "Loop").
TaskStatus
Possible outcomes of a task node execution.
@ Success
The node completed successfully.
@ Running
The node is still executing (will be called again next frame).
@ Aborted
Execution was interrupted externally.
std::unique_ptr< IAtomicTask > activeTask
Owning pointer to the IAtomicTask instance that is currently executing for this runner.
std::unordered_map< std::string, Olympe::TaskValue > LocalBlackboard
Typed local blackboard for per-entity state.
std::string graphAssetPath
Path to the ATS Visual Script JSON asset file (.json).
std::unordered_map< std::string, Olympe::TaskValue > DataPinCache
Frame-local cache of computed data pin values (key = "nodeID:pinName").
AssetID GraphTemplateID
AssetID of the TaskGraphTemplate driving this runner.
std::unordered_map< int32_t, bool > DoOnceFlags
Per-node "already fired" flag for DoOnce nodes (key = nodeID).
TaskRunnerComponent(TaskRunnerComponent &&)=default
TaskRunnerComponent & operator=(const TaskRunnerComponent &)=delete
int32_t CurrentNodeID
ID of the currently active node.