Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
TaskGraphTypes.cpp
Go to the documentation of this file.
1/**
2 * @file TaskGraphTypes.cpp
3 * @brief Implementation of TaskValue for the Atomic Task System
4 * @author Olympe Engine
5 * @date 2026-02-20
6 */
7
8#include "TaskGraphTypes.h"
9
10#include <stdexcept>
11#include <string>
12#include <sstream>
13
14#include "../system/system_utils.h"
15
16namespace Olympe {
17
18// ============================================================================
19// TaskValue - Constructors
20// ============================================================================
21
23 : m_vectorValue()
24 , m_stringValue()
25 , m_type(VariableType::None)
26{
28}
29
31 : m_vectorValue()
32 , m_stringValue()
33 , m_type(VariableType::Bool)
34{
36}
37
39 : m_vectorValue()
40 , m_stringValue()
41 , m_type(VariableType::Int)
42{
44}
45
47 : m_vectorValue()
48 , m_stringValue()
49 , m_type(VariableType::Float)
50{
52}
53
54TaskValue::TaskValue(const ::Vector& v)
55 : m_vectorValue(v)
56 , m_stringValue()
57 , m_type(VariableType::Vector)
58{
60}
61
63 : m_vectorValue()
64 , m_stringValue()
65 , m_type(VariableType::EntityID)
66{
68}
69
70TaskValue::TaskValue(const std::string& v)
71 : m_vectorValue()
72 , m_stringValue(v)
73 , m_type(VariableType::String)
74{
76}
77
78// ============================================================================
79// TaskValue - Typed getters
80// ============================================================================
81
83{
85 {
86 throw std::runtime_error("[TaskValue] Type mismatch: expected Bool");
87 }
88 return m_data.boolValue;
89}
90
92{
94 {
95 throw std::runtime_error("[TaskValue] Type mismatch: expected Int");
96 }
97 return m_data.intValue;
98}
99
101{
103 {
104 throw std::runtime_error("[TaskValue] Type mismatch: expected Float");
105 }
106 return m_data.floatValue;
107}
108
110{
112 {
113 throw std::runtime_error("[TaskValue] Type mismatch: expected Vector");
114 }
115 return m_vectorValue;
116}
117
119{
121 {
122 throw std::runtime_error("[TaskValue] Type mismatch: expected EntityID");
123 }
124 return m_data.entityValue;
125}
126
127std::string TaskValue::AsString() const
128{
130 {
131 throw std::runtime_error("[TaskValue] Type mismatch: expected String");
132 }
133 return m_stringValue;
134}
135
136// ============================================================================
137// TaskValue - Type queries
138// ============================================================================
139
141{
142 return m_type;
143}
144
146{
147 return m_type == VariableType::None;
148}
149
150// ============================================================================
151// TaskValue - String conversion (Fix #4 — never return empty)
152// ============================================================================
153
154std::string TaskValue::to_string() const
155{
156 switch (m_type)
157 {
159 return m_data.boolValue ? "true" : "false";
161 return std::to_string(m_data.intValue);
163 {
164 std::ostringstream oss;
166 return oss.str();
167 }
169 return std::to_string(static_cast<unsigned long long>(m_data.entityValue));
171 return m_stringValue.empty() ? "" : m_stringValue;
173 default:
174 SYSTEM_LOG << "[TaskValue] WARNING: to_string() called on None/unknown type, returning '0'\n";
175 return "0";
176 }
177}
178
179// ============================================================================
180// Free functions
181// ============================================================================
182
183// Fix #3: VariableTypeToString — never returns garbage (fallback to "Int")
185{
186 switch (t)
187 {
188 case VariableType::Bool: return "Bool";
189 case VariableType::Int: return "Int";
190 case VariableType::Float: return "Float";
191 case VariableType::Vector: return "Vector";
192 case VariableType::EntityID: return "EntityID";
193 case VariableType::String: return "String";
194 case VariableType::None: return "None";
195 case VariableType::List: return "List";
196 case VariableType::GlobalRef: return "GlobalRef";
197 default:
198 SYSTEM_LOG << "[VariableTypeToString] ERROR: Unknown type, defaulting to Int\n";
199 return "Int";
200 }
201}
202
203// UX Fix #1: GetDefaultValueForType — returns a type-consistent default value
205{
206 switch (type)
207 {
208 case VariableType::Bool: return TaskValue(false);
209 case VariableType::Int: return TaskValue(0);
210 case VariableType::Float: return TaskValue(0.0f);
211 case VariableType::EntityID: return TaskValue(static_cast<EntityID>(0));
212 case VariableType::String: return TaskValue(std::string(""));
213 case VariableType::Vector: return TaskValue(::Vector());
214 default: return TaskValue(0);
215 }
216}
217
218} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
std::uint64_t EntityID
Definition ECS_Entity.h:21
Core enumerations and TaskValue type-safe variant for the Atomic Task System.
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
@ Float
Single-precision float.
@ String
std::string
@ 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)
static std::string VariableTypeToString(VariableType type)
Converts a VariableType to its canonical string representation.
static TaskValue GetDefaultValueForType(VariableType type)
Returns a correctly-typed default TaskValue for the given VariableType.
#define SYSTEM_LOG