Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
BehaviorTreeExecutor.h
Go to the documentation of this file.
1/**
2 * @file BehaviorTreeExecutor.h
3 * @brief Native BehaviorTree execution for simulation and tracing
4 * @author Olympe Engine
5 * @date 2026-03-24
6 *
7 * @details
8 * Executes a BehaviorTree using its native execution model and records
9 * trace events for debugging and validation. Unlike GraphExecutionSimulator
10 * which is designed for VisualScript graphs, this executor understands
11 * BehaviorTree semantics (Selector, Sequence, Condition, Action, etc.)
12 *
13 * C++14 compliant.
14 */
15
16#pragma once
17
18#include <vector>
19#include <memory>
20#include <cstdint>
21
22#include "../AI/BehaviorTree.h"
24
25namespace Olympe {
26
27/**
28 * @class BehaviorTreeExecutor
29 * @brief Executes a BehaviorTree and collects trace information.
30 *
31 * This executor simulates BehaviorTree execution without modifying runtime state.
32 * It records each node execution, condition evaluation, and branch decision.
33 */
35public:
38
39 /**
40 * @brief Execute a BehaviorTree and collect trace information.
41 * @param btAsset The BehaviorTree asset to execute
42 * @param outTracer [out] Execution trace collection
43 * @return Execution status (Success, Failure, or Running)
44 */
46
47private:
48 /**
49 * @brief Recursively execute a single BehaviorTree node.
50 * @param nodeId The node to execute
51 * @param btAsset Reference to tree asset (for node lookups)
52 * @param outTracer Trace collection object
53 * @return Node execution status
54 */
56
57 /**
58 * @brief Execute a Selector (OR) composite node.
59 * @details A Selector succeeds if ANY child succeeds. Stops on first success.
60 */
62
63 /**
64 * @brief Execute a Sequence (AND) composite node.
65 * @details A Sequence succeeds only if ALL children succeed. Stops on first failure.
66 */
68
69 /**
70 * @brief Execute a Condition leaf node.
71 * @details Evaluates condition and returns Success (true) or Failure (false).
72 */
74
75 /**
76 * @brief Execute an Action leaf node.
77 * @details Actions always succeed in simulation (no runtime effects).
78 */
80
81 /**
82 * @brief Apply a Decorator (Inverter, Repeater) to a child node result.
83 */
85
86 /**
87 * @brief Convert BTStatus to string for logging.
88 */
89 static const char* StatusToString(BTStatus status);
90
91 /**
92 * @brief Phase 39: Execute a SubGraph reference node.
93 * @details Loads external BT or ATS file and executes it recursively.
94 */
96
97 int m_maxDepth = 0; ///< Track recursion depth to detect cycles
98 int m_executedNodes = 0; ///< Count of executed nodes
99
100 /// Phase 39: Call stack for SubGraph recursion tracking
102};
103
104} // namespace Olympe
BTStatus
Behavior tree node execution status.
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Graph execution tracing for simulation and validation.
Executes a BehaviorTree and collects trace information.
BTStatus ExecuteSelector(const BTNode &node, const BehaviorTreeAsset &btAsset, GraphExecutionTracer &outTracer)
Execute a Selector (OR) composite node.
static const char * StatusToString(BTStatus status)
Convert BTStatus to string for logging.
SubGraphCallStack m_callStack
Phase 39: Call stack for SubGraph recursion tracking.
BTStatus ExecuteCondition(const BTNode &node, GraphExecutionTracer &outTracer)
Execute a Condition leaf node.
BTStatus ExecuteTree(const BehaviorTreeAsset &btAsset, GraphExecutionTracer &outTracer)
Execute a BehaviorTree and collect trace information.
int m_executedNodes
Count of executed nodes.
BTStatus ExecuteNode(uint32_t nodeId, const BehaviorTreeAsset &btAsset, GraphExecutionTracer &outTracer)
Recursively execute a single BehaviorTree node.
BTStatus ExecuteAction(const BTNode &node, GraphExecutionTracer &outTracer)
Execute an Action leaf node.
int m_maxDepth
Track recursion depth to detect cycles.
BTStatus ExecuteSubGraph(const BTNode &node, const BehaviorTreeAsset &btAsset, GraphExecutionTracer &outTracer)
Phase 39: Execute a SubGraph reference node.
BTStatus ExecuteSequence(const BTNode &node, const BehaviorTreeAsset &btAsset, GraphExecutionTracer &outTracer)
Execute a Sequence (AND) composite node.
BTStatus ExecuteDecorator(const BTNode &node, const BehaviorTreeAsset &btAsset, GraphExecutionTracer &outTracer)
Apply a Decorator (Inverter, Repeater) to a child node result.
Records execution trace during graph simulation.
< Provides AssetID and INVALID_ASSET_ID
Represents a single node in a behavior tree.
Tracks the SubGraph call chain to detect cycles and enforce depth limits.