Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
TaskGraphTypes.h
Go to the documentation of this file.
1/**
2 * @file TaskGraphTypes.h
3 * @brief Core enumerations and TaskValue type-safe variant for the Atomic Task System
4 * @author Olympe Engine
5 * @date 2026-02-20
6 *
7 * @details
8 * Defines the foundational types for the Atomic Task System (v3.0):
9 * - TaskNodeType: Identifies the role of a node in the task graph
10 * - VariableType: Type tags for TaskValue storage
11 * - ParameterBindingType: How a parameter value is supplied
12 * - TaskValue: C++14-compliant type-safe variant (union + non-POD fields)
13 *
14 * C++14 compliant - no std::variant, std::optional, or C++17/20 features.
15 */
16
17#pragma once
18
19#include <string>
20#include <stdexcept>
21#include <cstdint>
22
23#include "../vector.h"
24#include "../ECS_Entity.h"
25
26namespace Olympe {
27
28// ============================================================================
29// Sentinel constants
30// ============================================================================
31
32/**
33 * @brief Sentinel value for "no node" in node index / ID fields.
34 *
35 * Use instead of the magic value -1 wherever a node index or node ID is
36 * absent (similar to Unreal Engine's INDEX_NONE).
37 */
38constexpr int32_t NODE_INDEX_NONE = -1;
39
40// ============================================================================
41// Enumerations
42// ============================================================================
43
44/**
45 * @enum TaskNodeType
46 * @brief Identifies the role of a node in the task graph.
47 *
48 * Values 0-5 are the original BehaviorTree node types (unchanged).
49 * Values 6-17 are ATS Visual Scripting node types (Phase 1 - 2026-03-08).
50 */
51enum class TaskNodeType : uint8_t {
52 AtomicTask = 0, ///< Leaf node that executes a single atomic task
53 Sequence = 1, ///< Executes children in order; stops on first failure
54 Selector = 2, ///< Executes children in order; stops on first success
55 Parallel = 3, ///< Executes all children simultaneously
56 Decorator = 4, ///< Wraps a single child and modifies its behaviour
57 Root = 5, ///< Entry point of the graph (exactly one per template)
58
59 // ATS Visual Scripting node types (Phase 1)
60 EntryPoint = 6, ///< Unique entry node for VS graphs (replaces Root)
61 Branch = 7, ///< If/Else conditional (Then / Else exec outputs)
62 Switch = 8, ///< Multi-branch on value (N exec outputs)
63 VSSequence = 9, ///< Execute N outputs in order ("VS" prefix avoids collision with BT Sequence=1)
64 While = 10, ///< Conditional loop (Loop / Completed exec outputs)
65 ForEach = 11, ///< Iterate over BB list (Loop Body / Completed exec outputs)
66 DoOnce = 12, ///< Single-fire execution (reset via Reset pin)
67 Delay = 13, ///< Timer (Completed exec output after N seconds)
68 GetBBValue = 14, ///< Data node – reads a Blackboard key
69 SetBBValue = 15, ///< Data node – writes a Blackboard key
70 MathOp = 16, ///< Data node – arithmetic operation (+, -, *, /)
71 SubGraph = 17 ///< Sub-graph call (SubTask)
72};
73
74/**
75 * @enum VariableType
76 * @brief Type tags used by TaskValue to identify stored data.
77 *
78 * Values 0-6 are the original types (unchanged).
79 * Values 7-8 are ATS Visual Scripting extensions (Phase 1 - 2026-03-08).
80 */
81enum class VariableType : uint8_t {
82 None, ///< Uninitialized / empty value
83 Bool, ///< Boolean
84 Int, ///< 32-bit signed integer
85 Float, ///< Single-precision float
86 Vector, ///< 3-component vector (Vector from vector.h)
87 EntityID, ///< Entity identifier (uint64_t)
88 String, ///< std::string
89
90 // ATS Visual Scripting extensions (Phase 1)
91 List = 7, ///< std::vector<TaskValue> (used by ForEach node)
92 GlobalRef = 8 ///< Reference to a global blackboard key (scope "global:")
93};
94
95/**
96 * @brief Converts a VariableType to its canonical string representation.
97 * @param t The VariableType to convert.
98 * @return String name (e.g. "Bool", "Int"). Falls back to "Int" for unknown values.
99 */
101
102/**
103 * @enum ParameterBindingType
104 * @brief Describes how a parameter value is provided to a task node.
105 *
106 * Values 0-1 are the original binding types (unchanged).
107 * Values 2-6 are Phase 22-C extensions for dropdown-driven parameter editors.
108 */
110 Literal = 0, ///< Value is embedded directly in the template
111 LocalVariable = 1, ///< Value is read from the local blackboard at runtime
112
113 // Phase 22-C extensions — dropdown-driven parameter types
114 AtomicTaskID = 2, ///< ID of an atomic task (from AtomicTaskUIRegistry)
115 ConditionID = 3, ///< ID of a condition type (from ConditionRegistry)
116 MathOperator = 4, ///< Math operator symbol (+, -, *, /, %) (from OperatorRegistry)
117 ComparisonOp = 5, ///< Comparison operator (==, !=, <, <=, >, >=) (from OperatorRegistry)
118 SubGraphPath = 6 ///< File path to a sub-graph .ats file
119};
120
121// ============================================================================
122// ATS Visual Scripting – Node Types (Phase 1 - 2026-03-08)
123// ============================================================================
124
125// Extended TaskNodeType — appended values (existing values 0-5 unchanged)
126// EntryPoint : unique entry node (replaces Root for VS graphs)
127// Branch : If/Else conditional (2 exec outputs: Then / Else)
128// Switch : Multi-branch on value (N exec outputs)
129// VSSequence : Execute N outputs in order (VS Sequence, distinct from BT Sequence)
130// While : Conditional loop (Loop / Completed)
131// ForEach : Iterate over BB list (Loop Body / Completed)
132// DoOnce : Single-fire execution (reset via Reset pin)
133// Delay : Timer (Completed exec output after N seconds)
134// GetBBValue : Data node – reads a Blackboard key
135// SetBBValue : Data node – writes a Blackboard key
136// MathOp : Data node – arithmetic operation (+, -, *, /)
137// SubGraph : Sub-graph call (SubTask)
138
139// NOTE: TaskNodeType enum values 0-5 (AtomicTask..Root) are unchanged.
140// The following values extend the enum in TaskGraphTypes.h but cannot be
141// added inline here without modifying the enum definition above.
142// See the extended enum in TaskGraphTypes.h (values 6-17).
143
144/**
145 * @enum DataPinDir
146 * @brief Direction of a data pin on a Visual Script node.
147 */
148enum class DataPinDir : uint8_t {
149 Input, ///< Value consumed by the node
150 Output ///< Value produced by the node
151};
152
153/**
154 * @enum ExecPinRole
155 * @brief Role of an exec pin on a Visual Script node.
156 */
157enum class ExecPinRole : uint8_t {
158 In, ///< Triggers execution of the node
159 Out, ///< Normal output / Then
160 OutElse, ///< Else output (Branch)
161 OutLoop, ///< Loop body output (While, ForEach)
162 OutCompleted, ///< End-of-loop output (While, ForEach, Delay, DoOnce)
163 OutCase ///< Switch case output (dynamically named)
164};
165
166// ============================================================================
167// TaskValue
168// ============================================================================
169
170/**
171 * @class TaskValue
172 * @brief C++14-compliant type-safe value container for task parameters.
173 *
174 * @details
175 * Stores one value of type: bool, int, float, Vector, EntityID, or std::string.
176 * POD types share a union; non-POD types (Vector, std::string) are stored
177 * as separate members.
178 *
179 * Throws std::runtime_error on type mismatch when calling typed getters.
180 */
182public:
183
184 // -----------------------------------------------------------------------
185 // Construction
186 // -----------------------------------------------------------------------
187
188 /**
189 * @brief Default constructor: creates a value of type VariableType::None.
190 */
191 TaskValue();
192
193 /**
194 * @brief Construct from bool.
195 * @param v Boolean value.
196 */
197 explicit TaskValue(bool v);
198
199 /**
200 * @brief Construct from int.
201 * @param v Integer value.
202 */
203 explicit TaskValue(int v);
204
205 /**
206 * @brief Construct from float.
207 * @param v Float value.
208 */
209 explicit TaskValue(float v);
210
211 /**
212 * @brief Construct from Vector.
213 * @param v Vector value (2D or 3D via z component).
214 */
215 explicit TaskValue(const ::Vector& v);
216
217 /**
218 * @brief Construct from EntityID.
219 * @param v Entity identifier.
220 */
221 explicit TaskValue(EntityID v);
222
223 /**
224 * @brief Construct from std::string.
225 * @param v String value.
226 */
227 explicit TaskValue(const std::string& v);
228
229 // -----------------------------------------------------------------------
230 // Getters (throw std::runtime_error on type mismatch)
231 // -----------------------------------------------------------------------
232
233 /**
234 * @brief Returns the bool value.
235 * @throws std::runtime_error if the stored type is not Bool.
236 */
237 bool AsBool() const;
238
239 /**
240 * @brief Returns the int value.
241 * @throws std::runtime_error if the stored type is not Int.
242 */
243 int AsInt() const;
244
245 /**
246 * @brief Returns the float value.
247 * @throws std::runtime_error if the stored type is not Float.
248 */
249 float AsFloat() const;
250
251 /**
252 * @brief Returns the Vector value.
253 * @throws std::runtime_error if the stored type is not Vector.
254 */
255 ::Vector AsVector() const;
256
257 /**
258 * @brief Returns the EntityID value.
259 * @throws std::runtime_error if the stored type is not EntityID.
260 */
261 EntityID AsEntityID() const;
262
263 /**
264 * @brief Returns the string value.
265 * @throws std::runtime_error if the stored type is not String.
266 */
267 std::string AsString() const;
268
269 // -----------------------------------------------------------------------
270 // Type queries
271 // -----------------------------------------------------------------------
272
273 /**
274 * @brief Returns the VariableType tag of the stored value.
275 */
276 VariableType GetType() const;
277
278 /**
279 * @brief Returns true if the value has not been set (type == None).
280 */
281 bool IsNone() const;
282
283 /**
284 * @brief Converts the stored value to a string representation.
285 *
286 * Never returns an empty string — falls back to "0" for None or empty values.
287 * This prevents JSON builder failures when serializing uninitialized entries.
288 * @return String representation of the value.
289 */
290 std::string to_string() const;
291
292private:
293
294 // POD storage (bool, int, float, EntityID share a union)
303
304 // Non-POD storage
306 std::string m_stringValue;
307
309};
310
311// ============================================================================
312// ATS Visual Scripting – DataPinDefinition (Phase 1 - 2026-03-08)
313// Declared after TaskValue because it uses TaskValue as a member.
314// ============================================================================
315
316/**
317 * @brief Returns a correctly-typed default TaskValue for the given VariableType.
318 *
319 * Used when a new blackboard variable is created or when its type is changed,
320 * to ensure the Default field is always type-consistent.
321 * @param type The VariableType to create a default value for.
322 * @return A TaskValue of the matching type, initialized to a zero/false/empty value.
323 */
325
326/**
327 * @struct DataPinDefinition
328 * @brief Describes a data pin declared on a Visual Script node.
329 */
331 std::string PinName; ///< Pin name ("Value", "Result", etc.)
332 VariableType PinType = VariableType::None; ///< Type of the data
334 TaskValue Default; ///< Default value when not connected
335};
336
337// ============================================================================
338// ATS Visual Scripting – SubGraphParameterDef (Phase 3 - 2026-03-09)
339// ============================================================================
340
341/**
342 * @struct SubGraphParameterDef
343 * @brief Describes an input or output parameter declared on a SubGraph file.
344 *
345 * Used in TaskGraphTemplate::InputParameters and TaskGraphTemplate::OutputParameters
346 * to describe the interface of a sub-graph that can receive and return values.
347 */
349 std::string Name; ///< Parameter name (must match binding keys)
350 VariableType Type = VariableType::None; ///< Expected variable type
351};
352
353// ============================================================================
354// ATS Visual Scripting – Condition (Phase 23-B.4 - 2026-03-15)
355// ============================================================================
356
357/**
358 * @struct Condition
359 * @brief Describes a single condition expression for Branch/While nodes.
360 *
361 * @details
362 * Supports 6 combinations:
363 * Variable vs Variable (health < max_health)
364 * Variable vs Const (health > 50)
365 * Variable vs Pin (health == Node#42.Out)
366 * Pin vs Pin (Node#42.Out > Node#43.Out)
367 * Pin vs Const (Node#42.Out >= threshold)
368 * Const vs Const (50 < 100, for testing — W015 warning)
369 *
370 * Multiple conditions on one node are evaluated with implicit AND.
371 */
372struct Condition {
373 // -- Left side value source --
374 std::string leftMode; ///< "Pin" | "Variable" | "Const"
375 std::string leftPin; ///< If Pin mode: e.g. "Node#42.Out"
376 std::string leftVariable; ///< If Variable mode: e.g. "health"
377 TaskValue leftConstValue; ///< If Const mode: e.g. TaskValue(50)
378
379 // -- Comparison operator --
380 std::string operatorStr; ///< "==", "!=", "<", ">", "<=", ">="
381
382 // -- Right side value source --
383 std::string rightMode; ///< "Pin" | "Variable" | "Const"
384 std::string rightPin; ///< If Pin mode: e.g. "Node#43.Out"
385 std::string rightVariable; ///< If Variable mode: e.g. "max_health"
386 TaskValue rightConstValue;///< If Const mode: e.g. TaskValue(100)
387
388 // -- Type hint for validation --
389 VariableType compareType = VariableType::None; ///< Int, Float, Bool, String, Vector
390};
391
392// ============================================================================
393// ATS Visual Scripting – SwitchCaseDefinition (Phase 22-A - 2026-03-14)
394// ============================================================================
395
396/**
397 * @struct SwitchCaseDefinition
398 * @brief Describes a single case branch on a Switch node.
399 *
400 * Each case maps a match value to a named exec-out pin.
401 * An optional custom label can be set by the user for readability
402 * (e.g. "Patrol" instead of "Case_5").
403 */
405 std::string value; ///< The value to match (int as decimal string or raw string)
406 std::string pinName; ///< The exec-out pin name used internally (e.g. "Case_0")
407 std::string customLabel; ///< User-defined display label (empty = use pinName)
408
409 /**
410 * @brief Returns the display name shown in the editor.
411 * Returns customLabel if non-empty, otherwise pinName.
412 */
413 const std::string& GetDisplayName() const
414 {
415 return customLabel.empty() ? pinName : customLabel;
416 }
417};
418
419} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
std::uint64_t EntityID
Definition ECS_Entity.h:21
C++14-compliant type-safe value container for task parameters.
VariableType m_type
std::string to_string() const
Converts the stored value to a string representation.
int AsInt() const
Returns the int value.
::Vector AsVector() const
Returns the Vector value.
EntityID AsEntityID() const
Returns the EntityID value.
float AsFloat() const
Returns the float value.
std::string m_stringValue
bool IsNone() const
Returns true if the value has not been set (type == None).
std::string AsString() const
Returns the string value.
bool AsBool() const
Returns the bool value.
TaskValue()
Default constructor: creates a value of type VariableType::None.
VariableType GetType() const
Returns the VariableType tag of the stored value.
union Olympe::TaskValue::PodData m_data
< Provides AssetID and INVALID_ASSET_ID
VariableType
Type tags used by TaskValue to identify stored data.
@ Int
32-bit signed integer
@ GlobalRef
Reference to a global blackboard key (scope "global:")
@ List
std::vector<TaskValue> (used by ForEach node)
@ Vector
3-component vector (Vector from vector.h)
@ None
Uninitialized / empty value.
@ EntityID
Entity identifier (uint64_t)
@ SubGraph
Teal — SubGraph call.
@ Delay
Yellow — Delay timer.
@ EntryPoint
Green — single "Out" exec pin.
ParameterBindingType
Describes how a parameter value is provided to a task node.
@ MathOperator
Math operator symbol (+, -, *, /, %) (from OperatorRegistry)
@ ConditionID
ID of a condition type (from ConditionRegistry)
@ AtomicTaskID
ID of an atomic task (from AtomicTaskUIRegistry)
@ SubGraphPath
File path to a sub-graph .ats file.
@ LocalVariable
Value is read from the local blackboard at runtime.
@ Literal
Value is embedded directly in the template.
ComparisonOp
The relational operator used in a ConditionPreset.
TaskNodeType
Identifies the role of a node in the task graph.
@ Selector
Executes children in order; stops on first success.
@ AtomicTask
Leaf node that executes a single atomic task.
@ While
Conditional loop (Loop / Completed exec outputs)
@ Sequence
Executes children in order; stops on first failure.
@ Decorator
Wraps a single child and modifies its behaviour.
@ DoOnce
Single-fire execution (reset via Reset pin)
@ Parallel
Executes all children simultaneously.
@ GetBBValue
Data node – reads a Blackboard key.
@ MathOp
Data node – arithmetic operation (+, -, *, /)
@ SetBBValue
Data node – writes a Blackboard key.
@ ForEach
Iterate over BB list (Loop Body / Completed exec outputs)
@ Switch
Multi-branch on value (N exec outputs)
@ Branch
If/Else conditional (Then / Else exec outputs)
@ Root
Entry point of the graph (exactly one per template)
@ VSSequence
Execute N outputs in order ("VS" prefix avoids collision with BT Sequence=1)
constexpr int32_t NODE_INDEX_NONE
Sentinel value for "no node" in node index / ID fields.
DataPinDir
Direction of a data pin on a Visual Script node.
@ Output
Value produced by the node.
@ Input
Value consumed by the node.
static std::string VariableTypeToString(VariableType type)
Converts a VariableType to its canonical string representation.
ExecPinRole
Role of an exec pin on a Visual Script node.
@ OutCompleted
End-of-loop output (While, ForEach, Delay, DoOnce)
@ OutLoop
Loop body output (While, ForEach)
@ Out
Normal output / Then.
@ OutCase
Switch case output (dynamically named)
@ OutElse
Else output (Branch)
@ In
Triggers execution of the node.
static TaskValue GetDefaultValueForType(VariableType type)
Returns a correctly-typed default TaskValue for the given VariableType.
Describes a single condition expression for Branch/While nodes.
std::string rightPin
If Pin mode: e.g. "Node#43.Out".
std::string rightMode
"Pin" | "Variable" | "Const"
std::string leftVariable
If Variable mode: e.g. "health".
TaskValue rightConstValue
If Const mode: e.g. TaskValue(100)
TaskValue leftConstValue
If Const mode: e.g. TaskValue(50)
std::string leftPin
If Pin mode: e.g. "Node#42.Out".
std::string leftMode
"Pin" | "Variable" | "Const"
std::string rightVariable
If Variable mode: e.g. "max_health".
std::string operatorStr
"==", "!=", "<", ">", "<=", ">="
VariableType compareType
Int, Float, Bool, String, Vector.
Describes a data pin declared on a Visual Script node.
TaskValue Default
Default value when not connected.
DataPinDir Dir
Direction.
VariableType PinType
Type of the data.
std::string PinName
Pin name ("Value", "Result", etc.)
Describes an input or output parameter declared on a SubGraph file.
std::string Name
Parameter name (must match binding keys)
VariableType Type
Expected variable type.
Describes a single case branch on a Switch node.
std::string value
The value to match (int as decimal string or raw string)
const std::string & GetDisplayName() const
Returns the display name shown in the editor.
std::string pinName
The exec-out pin name used internally (e.g. "Case_0")
std::string customLabel
User-defined display label (empty = use pinName)