16#include "../Core/AssetManager.h"
17#include "../system/system_utils.h"
59 SYSTEM_LOG <<
"[VSGraphExecutor] Entity " << entity
61 <<
" not found in template '" <<
tmpl.Name <<
"'\n";
126 SYSTEM_LOG <<
"[VSGraphExecutor] Entity " << entity
127 <<
": unhandled node type "
128 <<
static_cast<int>(
node->Type)
150 SYSTEM_LOG <<
"[VSGraphExecutor] Entity " << entity
152 <<
") in template '" <<
tmpl.Name <<
"' — possible infinite loop\n";
160 const std::string& pinName,
163 for (
size_t i = 0;
i <
tmpl.ExecConnections.size(); ++
i)
191 SYSTEM_LOG <<
"[VSGraphExecutor] Warning: Failed to evaluate all input pins for node "
192 << nodeID <<
" — some pins may use default values\n";
252 float floatValue = 0.0f;
259 floatValue =
static_cast<float>(value.
AsInt());
263 floatValue = value.
AsBool() ? 1.0f : 0.0f;
267 env.SetBlackboardVariable(
varName, floatValue);
287 const std::unordered_map<std::string, TaskValue>&
dataPinCache)
291 const std::string&
pinID =
it->first;
295 float floatValue = 0.0f;
302 floatValue =
static_cast<float>(value.
AsInt());
306 floatValue = value.
AsBool() ? 1.0f : 0.0f;
309 env.SetDynamicPinValue(
pinID, floatValue);
326 if (
node !=
nullptr && !
node->conditionRefs.empty())
340 const std::string
presetPath =
"./Blueprints/Presets/condition_presets.json";
356 SYSTEM_LOG <<
"[VSGraphExecutor] Branch node " << nodeID
357 <<
": " <<
errorMsg <<
" — defaulting to Else\n";
369 if (
node !=
nullptr && !
node->conditions.empty())
381 condKey << nodeID <<
":Condition";
387 if (
it !=
runner.DataPinCache.end())
416 if (
node !=
nullptr && !
node->ConditionID.empty())
418 SYSTEM_LOG <<
"[VSGraphExecutor] Branch node " << nodeID
419 <<
": ConditionID '" <<
node->ConditionID
420 <<
"' evaluation not implemented — defaulting to Else\n";
451 std::ostringstream
valKey;
452 valKey << nodeID <<
":Value";
458 if (
it !=
runner.DataPinCache.end())
469 std::ostringstream
oss;
478 for (
size_t i = 0;
i <
node->SwitchCases.size(); ++
i)
507 runner.SequenceChildIndex++;
512 runner.SequenceChildIndex = 0;
527 condKey << nodeID <<
":Condition";
533 if (
it !=
runner.DataPinCache.end())
548 if (
node !=
nullptr && !
node->ConditionID.empty())
550 SYSTEM_LOG <<
"[VSGraphExecutor] While node " << nodeID
552 <<
"' evaluation not implemented — exiting loop\n";
575 auto it =
runner.DoOnceFlags.find(nodeID);
576 if (
it !=
runner.DoOnceFlags.end() &&
it->second)
583 runner.DoOnceFlags[nodeID] =
true;
611 return runner.CurrentNodeID;
632 std::ostringstream
outKey;
633 outKey << nodeID <<
":Value";
655 std::ostringstream
inKey;
656 inKey << nodeID <<
":Value";
660 if (
it !=
runner.DataPinCache.end())
666 SYSTEM_LOG <<
"[VSGraphExecutor] SetBBValue node " << nodeID
667 <<
": no value in DataPinCache for 'Value' pin — skipping write\n";
688 std::ostringstream
keyA;
689 keyA << nodeID <<
":A";
690 std::ostringstream
keyB;
691 keyB << nodeID <<
":B";
706 try {
a =
static_cast<float>(
v.AsInt()); }
catch (...) {}
720 try {
b =
static_cast<float>(
v.AsInt()); }
catch (...) {}
725 const std::string& op =
node->MathOperator;
747 SYSTEM_LOG <<
"[VSGraphExecutor] MathOp node " << nodeID
748 <<
": division by zero — result is 0\n";
754 SYSTEM_LOG <<
"[VSGraphExecutor] MathOp node " << nodeID
755 <<
": unknown operator '" << op <<
"'\n";
790 SYSTEM_LOG <<
"[VSGraphExecutor] Entity " << entity
791 <<
": unknown AtomicTaskID '" <<
node->AtomicTaskID
792 <<
"' at node " << nodeID <<
" — skipping\n";
800 for (
auto it =
node->Parameters.begin();
it !=
node->Parameters.end(); ++
it)
808 if (
localBB.HasVariable(
it->second.VariableName))
816 SYSTEM_LOG <<
"[VSGraphExecutor] Entity " << entity
817 <<
": failed to read variable '"
818 <<
it->second.VariableName <<
"'\n";
825 for (
size_t p = 0;
p <
node->DataPins.size(); ++
p)
830 std::ostringstream
key;
833 if (
it !=
runner.DataPinCache.end())
857 return runner.CurrentNodeID;
861 runner.activeTask.reset();
893 SYSTEM_LOG <<
"[VSGraphExecutor][ERROR] HandleSubGraph: node " << nodeID
894 <<
" not found in template '" <<
tmpl.Name <<
"'\n";
898 if (
node->SubGraphPath.empty())
900 SYSTEM_LOG <<
"[VSGraphExecutor] Entity " << entity
901 <<
": SubGraph node " << nodeID
902 <<
" has no SubGraphPath — skipping\n";
909 SYSTEM_LOG <<
"[VSGraphExecutor][ERROR] SubGraph recursion depth exceeded (max "
917 SYSTEM_LOG <<
"[VSGraphExecutor][ERROR] SubGraph cycle detected: '";
934 SYSTEM_LOG <<
"[VSGraphExecutor][ERROR] SubGraph file not found or invalid: '"
935 <<
node->SubGraphPath <<
"'\n";
947 for (
auto it =
node->InputParams.begin();
it !=
node->InputParams.end(); ++
it)
966 <<
"': LocalVariable '" <<
binding.VariableName
967 <<
"' not found in parent BB — using default\n";
992 for (
auto it =
node->OutputParams.begin();
it !=
node->OutputParams.end(); ++
it)
1007 <<
"': failed to write to '" <<
targetBBKey <<
"'\n";
Singleton registry for atomic task factories.
Evaluates structured Condition expressions for Branch/While nodes.
Stack-based recursive evaluation of data pin networks for "data pure" nodes.
ComponentTypeID GetComponentTypeID_Static()
Interface for atomic tasks in the Atomic Task System.
Exécuteur de graphes ATS Visual Scripting (flowchart).
const TaskGraphTemplate * LoadTaskGraphFromFile(const std::string &path, std::vector< std::string > &outErrors)
Loads a TaskGraphTemplate from path and returns a direct pointer.
static AssetManager & Get()
Returns the singleton AssetManager instance.
std::unique_ptr< IAtomicTask > Create(const std::string &id) const
Creates a new instance of the task identified by id.
static AtomicTaskRegistry & Get()
Returns the singleton instance.
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 EvaluateConditionChain(const std::vector< NodeConditionRef > &conditions, const ConditionPresetRegistry ®istry, RuntimeEnvironment &env, std::string &outErrorMsg)
Evaluates a chain of conditions combined with logical operators (AND/OR).
Manages the global pool of ConditionPreset objects.
bool Load(const std::string &filepath)
Loads presets from a JSON file (clears existing data first).
static bool EvaluateNodeInputPins(int32_t nodeID, const TaskGraphTemplate &tmpl, TaskRunnerComponent &runner, LocalBlackboard &localBB)
Evaluate all input data pins for a given node before execution.
std::unordered_map< std::string, TaskValue > ParameterMap
Convenience alias for the parameter map passed to Execute().
Simple map-based blackboard for task graph runtime state.
void InitializeFromEntries(const std::vector< BlackboardEntry > &entries)
Initializes the blackboard from a vector of BlackboardEntry (ATS VS schema v4).
Provides Blackboard variable values and dynamic pin values at runtime.
Immutable, shareable task graph asset.
C++14-compliant type-safe value container for task parameters.
int AsInt() const
Returns the int 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.
static int32_t HandleWhile(int32_t nodeID, TaskRunnerComponent &runner, const TaskGraphTemplate &tmpl, LocalBlackboard &localBB)
static int32_t FindExecTarget(int32_t sourceNodeID, const std::string &pinName, const TaskGraphTemplate &tmpl)
Retourne l'ID du node cible sur un exec pin nommé pinName depuis sourceNodeID.
static int32_t HandleSubGraph(EntityID entity, int32_t nodeID, TaskRunnerComponent &runner, const TaskGraphTemplate &tmpl, LocalBlackboard &localBB, World *worldPtr, float dt, SubGraphCallStack &callStack)
static TaskValue ReadBBValue(const std::string &scopedKey, LocalBlackboard &localBB)
Lit une valeur BB depuis localBB avec support du scope "local:" et "global:".
static int32_t HandleGetBBValue(int32_t nodeID, TaskRunnerComponent &runner, const TaskGraphTemplate &tmpl, LocalBlackboard &localBB)
static void ResolveDataPins(int32_t nodeID, TaskRunnerComponent &runner, const TaskGraphTemplate &tmpl, LocalBlackboard &localBB)
Résout les data pins entrantes d'un node et peuple runner.DataPinCache.
static const int MAX_SUBGRAPH_DEPTH
Out-of-class definition required in C++14 for ODR-used static const members.
static void WriteBBValue(const std::string &scopedKey, const TaskValue &value, LocalBlackboard &localBB)
Écrit une valeur BB dans localBB avec support du scope "local:".
static int32_t HandleMathOp(int32_t nodeID, TaskRunnerComponent &runner, const TaskGraphTemplate &tmpl)
static int32_t HandleSwitch(int32_t nodeID, TaskRunnerComponent &runner, const TaskGraphTemplate &tmpl, LocalBlackboard &localBB)
static int32_t HandleVSSequence(int32_t nodeID, TaskRunnerComponent &runner, const TaskGraphTemplate &tmpl)
static int32_t HandleEntryPoint(int32_t nodeID, const TaskGraphTemplate &tmpl)
static int32_t HandleSetBBValue(int32_t nodeID, TaskRunnerComponent &runner, const TaskGraphTemplate &tmpl, LocalBlackboard &localBB)
static int32_t HandleBranch(int32_t nodeID, TaskRunnerComponent &runner, const TaskGraphTemplate &tmpl, LocalBlackboard &localBB)
static int32_t HandleDoOnce(int32_t nodeID, TaskRunnerComponent &runner, const TaskGraphTemplate &tmpl)
static void ExecuteFrame(EntityID entity, TaskRunnerComponent &runner, const TaskGraphTemplate &tmpl, LocalBlackboard &localBB, World *worldPtr, float dt)
Point d'entrée principal : exécute le graphe pour une entité.
static int32_t HandleAtomicTask(EntityID entity, int32_t nodeID, TaskRunnerComponent &runner, const TaskGraphTemplate &tmpl, LocalBlackboard &localBB, World *worldPtr, float dt)
static int32_t HandleDelay(int32_t nodeID, TaskRunnerComponent &runner, const TaskGraphTemplate &tmpl, float dt)
Core ECS manager and world coordinator.
< Provides AssetID and INVALID_ASSET_ID
@ Int
32-bit signed integer
@ Float
Single-precision float.
TaskStatus
Result code returned by IAtomicTask::Execute().
@ Success
Task completed successfully.
@ Running
Task is still in progress (multi-frame tasks)
static void PopulateRuntimeEnvironmentFromDataPins(RuntimeEnvironment &env, const std::unordered_map< std::string, TaskValue > &dataPinCache)
Populates a RuntimeEnvironment with dynamic pin values.
static const int MAX_STEPS_PER_FRAME
Maximum steps per frame to prevent infinite loops.
@ LocalVariable
Value is read from the local blackboard at runtime.
@ Literal
Value is embedded directly in the template.
static void PopulateRuntimeEnvironmentFromBlackboard(RuntimeEnvironment &env, const LocalBlackboard &localBB)
Populates a RuntimeEnvironment with blackboard variables.
@ AtomicTask
Leaf node that executes a single atomic task.
@ While
Conditional loop (Loop / Completed exec outputs)
@ SubGraph
Sub-graph call (SubTask)
@ DoOnce
Single-fire execution (reset via Reset pin)
@ Delay
Timer (Completed exec output after N seconds)
@ GetBBValue
Data node – reads a Blackboard key.
@ MathOp
Data node – arithmetic operation (+, -, *, /)
@ SetBBValue
Data node – writes a Blackboard key.
@ Switch
Multi-branch on value (N exec outputs)
@ EntryPoint
Unique entry node for VS graphs (replaces Root)
@ Branch
If/Else conditional (Then / Else exec outputs)
@ 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.
@ Input
Value consumed by the node.
Lightweight context bundle passed to IAtomicTask::ExecuteWithContext().
EntityID Entity
The entity whose task graph is being executed.
Describes a data pin declared on a Visual Script node.
std::string PinName
Pin name ("Value", "Result", etc.)
Explicit connection between a named exec-out pin of a source node and the exec-in pin of a target nod...
Describes how a single parameter value is supplied to a task node.
Tracks the SubGraph call chain to detect cycles and enforce depth limits.
Full description of a single node in the task graph.
std::string ConditionID
For Branch/While/Switch: ATS condition ID.
std::vector< int32_t > ChildrenIDs
Child node IDs (control-flow nodes only; empty for AtomicTask/Decorator leaf)
Per-entity runtime state for task graph execution.
@ Success
The node completed successfully.
@ Failure
The node failed.
int32_t CurrentNodeID
ID of the currently active node.