12#include "../system/system_utils.h"
25 const std::vector<Condition>& conditions,
27 const std::unordered_map<std::string, TaskValue>&
dataPinCache,
31 if (conditions.empty())
34 for (
size_t i = 0;
i < conditions.size(); ++
i)
49 const std::unordered_map<std::string, TaskValue>&
dataPinCache,
67 if (
cond.operatorStr.empty())
69 SYSTEM_LOG <<
"[ConditionEvaluator] Node #" << nodeID
70 <<
": operator is empty — defaulting to false\n";
82 const std::string& mode,
83 const std::string&
pin,
87 const std::unordered_map<std::string, TaskValue>&
dataPinCache,
97 else if (mode ==
"Variable")
101 SYSTEM_LOG <<
"[ConditionEvaluator] Node #" << nodeID
102 <<
": WARNING — Variable mode with empty variable name\n";
107 SYSTEM_LOG <<
"[ConditionEvaluator] Node #" << nodeID
108 <<
": WARNING — Variable '" <<
variable
109 <<
"' not found in blackboard\n";
119 SYSTEM_LOG <<
"[ConditionEvaluator] Node #" << nodeID
120 <<
": WARNING — Failed to read variable '" <<
variable <<
"'\n";
124 else if (mode ==
"Pin")
128 SYSTEM_LOG <<
"[ConditionEvaluator] Node #" << nodeID
129 <<
": WARNING — Pin mode with empty pin reference\n";
138 SYSTEM_LOG <<
"[ConditionEvaluator] Node #" << nodeID
139 <<
": WARNING — Could not parse pin reference '" <<
pin <<
"'\n";
143 std::ostringstream
key;
150 SYSTEM_LOG <<
"[ConditionEvaluator] Node #" << nodeID
151 <<
": WARNING — Pin '" <<
pin
152 <<
"' (cache key '" <<
cacheKey <<
"') not found in DataPinCache\n";
161 SYSTEM_LOG <<
"[ConditionEvaluator] Node #" << nodeID
162 <<
": WARNING — Unknown condition mode '" << mode <<
"'\n";
172 const std::string& op,
183 if (op ==
"==")
return lv ==
rv;
184 if (op ==
"!=")
return lv !=
rv;
185 if (op ==
"<")
return (!
lv &&
rv);
186 if (op ==
">")
return (
lv && !
rv);
187 if (op ==
"<=")
return lv <=
rv;
188 if (op ==
">=")
return lv >=
rv;
189 SYSTEM_LOG <<
"[ConditionEvaluator] Node #" << nodeID
190 <<
": WARNING — Unknown operator '" << op <<
"' for Bool\n";
199 if (op ==
"==")
return lv ==
rv;
200 if (op ==
"!=")
return lv !=
rv;
201 if (op ==
"<")
return lv <
rv;
202 if (op ==
">")
return lv >
rv;
203 if (op ==
"<=")
return lv <=
rv;
204 if (op ==
">=")
return lv >=
rv;
205 SYSTEM_LOG <<
"[ConditionEvaluator] Node #" << nodeID
206 <<
": WARNING — Unknown operator '" << op <<
"' for String\n";
225 if (op ==
"==")
return std::fabs(
lv -
rv) < 1e-6f;
226 if (op ==
"!=")
return std::fabs(
lv -
rv) >= 1e-6f;
227 if (op ==
"<")
return lv <
rv;
228 if (op ==
">")
return lv >
rv;
229 if (op ==
"<=")
return lv <=
rv;
230 if (op ==
">=")
return lv >=
rv;
231 SYSTEM_LOG <<
"[ConditionEvaluator] Node #" << nodeID
232 <<
": WARNING — Unknown operator '" << op <<
"' for numeric\n";
241 const bool eq = (std::fabs(
lv.x -
rv.x) < 1e-6f &&
242 std::fabs(
lv.y -
rv.y) < 1e-6f &&
243 std::fabs(
lv.z -
rv.z) < 1e-6f);
244 if (op ==
"==")
return eq;
245 if (op ==
"!=")
return !
eq;
246 SYSTEM_LOG <<
"[ConditionEvaluator] Node #" << nodeID
247 <<
": WARNING — Operator '" << op
248 <<
"' not supported for Vector (only == and != are valid)\n";
253 SYSTEM_LOG <<
"[ConditionEvaluator] Node #" << nodeID
254 <<
": WARNING — Type mismatch: cannot compare type "
255 <<
static_cast<int>(
lt) <<
" with type "
256 <<
static_cast<int>(
rt)
257 <<
" using operator '" << op <<
"' (E042)\n";
272 const std::string
prefix =
"Node#";
285 const std::string pinName =
rest.substr(
dotPos + 1);
289 for (
size_t i = 0;
i <
idStr.size(); ++
i)
293 id =
id * 10 + (
idStr[
i] -
'0');
Evaluates structured Condition expressions for Branch/While nodes.
ComponentTypeID GetComponentTypeID_Static()
static bool GetConditionValue(const std::string &mode, const std::string &pin, const std::string &variable, const TaskValue &constValue, const LocalBlackboard &localBB, const std::unordered_map< std::string, TaskValue > &dataPinCache, int32_t nodeID, TaskValue &outValue)
Resolves the TaskValue for one side of a condition.
static bool EvaluateAll(const std::vector< Condition > &conditions, const LocalBlackboard &localBB, const std::unordered_map< std::string, TaskValue > &dataPinCache, int32_t nodeID)
Evaluates all conditions (implicit AND) on a Branch/While node.
static bool EvaluateCondition(const Condition &cond, const LocalBlackboard &localBB, const std::unordered_map< std::string, TaskValue > &dataPinCache, int32_t nodeID)
Evaluates a single Condition.
static bool CompareValues(const TaskValue &left, const TaskValue &right, const std::string &op, int32_t nodeID)
Compares two TaskValues using the given operator.
static bool ParsePinRef(const std::string &pinRef, int32_t &outNodeID, std::string &outPinName)
Parses "Node#42.Out" -> nodeID=42, pinName="Out".
Simple map-based blackboard for task graph runtime state.
C++14-compliant type-safe value container for task parameters.
int AsInt() const
Returns the int value.
::Vector AsVector() const
Returns the Vector value.
float AsFloat() const
Returns the float value.
std::string AsString() const
Returns the string value.
bool AsBool() const
Returns the bool value.
VariableType GetType() const
Returns the VariableType tag of the stored value.
< 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.
@ Vector
3-component vector (Vector from vector.h)
Describes a single condition expression for Branch/While nodes.