Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
Olympe::BehaviorTreeExecutor Class Reference

Executes a BehaviorTree and collects trace information. More...

#include <BehaviorTreeExecutor.h>

+ Collaboration diagram for Olympe::BehaviorTreeExecutor:

Public Member Functions

 BehaviorTreeExecutor ()
 
 ~BehaviorTreeExecutor ()
 
BTStatus ExecuteTree (const BehaviorTreeAsset &btAsset, GraphExecutionTracer &outTracer)
 Execute a BehaviorTree and collect trace information.
 

Private Member Functions

BTStatus ExecuteNode (uint32_t nodeId, const BehaviorTreeAsset &btAsset, GraphExecutionTracer &outTracer)
 Recursively execute a single BehaviorTree node.
 
BTStatus ExecuteSelector (const BTNode &node, const BehaviorTreeAsset &btAsset, GraphExecutionTracer &outTracer)
 Execute a Selector (OR) composite node.
 
BTStatus ExecuteSequence (const BTNode &node, const BehaviorTreeAsset &btAsset, GraphExecutionTracer &outTracer)
 Execute a Sequence (AND) composite node.
 
BTStatus ExecuteCondition (const BTNode &node, GraphExecutionTracer &outTracer)
 Execute a Condition leaf node.
 
BTStatus ExecuteAction (const BTNode &node, GraphExecutionTracer &outTracer)
 Execute an Action leaf node.
 
BTStatus ExecuteDecorator (const BTNode &node, const BehaviorTreeAsset &btAsset, GraphExecutionTracer &outTracer)
 Apply a Decorator (Inverter, Repeater) to a child node result.
 
BTStatus ExecuteSubGraph (const BTNode &node, const BehaviorTreeAsset &btAsset, GraphExecutionTracer &outTracer)
 Phase 39: Execute a SubGraph reference node.
 

Static Private Member Functions

static const charStatusToString (BTStatus status)
 Convert BTStatus to string for logging.
 

Private Attributes

int m_maxDepth = 0
 Track recursion depth to detect cycles.
 
int m_executedNodes = 0
 Count of executed nodes.
 
SubGraphCallStack m_callStack
 Phase 39: Call stack for SubGraph recursion tracking.
 

Detailed Description

Executes a BehaviorTree and collects trace information.

This executor simulates BehaviorTree execution without modifying runtime state. It records each node execution, condition evaluation, and branch decision.

Definition at line 34 of file BehaviorTreeExecutor.h.

Constructor & Destructor Documentation

◆ BehaviorTreeExecutor()

Olympe::BehaviorTreeExecutor::BehaviorTreeExecutor ( )

Definition at line 14 of file BehaviorTreeExecutor.cpp.

◆ ~BehaviorTreeExecutor()

Olympe::BehaviorTreeExecutor::~BehaviorTreeExecutor ( )

Definition at line 19 of file BehaviorTreeExecutor.cpp.

Member Function Documentation

◆ ExecuteAction()

BTStatus Olympe::BehaviorTreeExecutor::ExecuteAction ( const BTNode node,
GraphExecutionTracer outTracer 
)
private

Execute an Action leaf node.

Actions always succeed in simulation (no runtime effects).

Definition at line 234 of file BehaviorTreeExecutor.cpp.

References AttackIfClose, ChooseRandomNavigablePoint, ClearTarget, FollowPath, GetComponentTypeID_Static(), Idle, MoveToGoal, PatrolPickNextPoint, RequestPathfinding, SendMessage, SetMoveGoalToLastKnownTargetPos, SetMoveGoalToPatrolPoint, SetMoveGoalToTarget, Success, and WaitRandomTime.

Referenced by ExecuteNode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ExecuteCondition()

BTStatus Olympe::BehaviorTreeExecutor::ExecuteCondition ( const BTNode node,
GraphExecutionTracer outTracer 
)
private

Execute a Condition leaf node.

Evaluates condition and returns Success (true) or Failure (false).

Definition at line 198 of file BehaviorTreeExecutor.cpp.

References CanAttack, Failure, GetComponentTypeID_Static(), HasMoveGoal, HasNavigableDestination, HasReachedDestination, HasValidPath, HealthBelow, HeardNoise, IsWaitTimerExpired, Success, TargetInRange, and TargetVisible.

Referenced by ExecuteNode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ExecuteDecorator()

BTStatus Olympe::BehaviorTreeExecutor::ExecuteDecorator ( const BTNode node,
const BehaviorTreeAsset btAsset,
GraphExecutionTracer outTracer 
)
private

Apply a Decorator (Inverter, Repeater) to a child node result.

Definition at line 266 of file BehaviorTreeExecutor.cpp.

References ExecuteNode(), Failure, GetComponentTypeID_Static(), Inverter, Repeater, and Success.

Referenced by ExecuteNode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ExecuteNode()

BTStatus Olympe::BehaviorTreeExecutor::ExecuteNode ( uint32_t  nodeId,
const BehaviorTreeAsset btAsset,
GraphExecutionTracer outTracer 
)
private

Recursively execute a single BehaviorTree node.

Parameters
nodeIdThe node to execute
btAssetReference to tree asset (for node lookups)
outTracerTrace collection object
Returns
Node execution status

< Phase 39

Definition at line 53 of file BehaviorTreeExecutor.cpp.

References Action, Condition, ExecuteAction(), ExecuteCondition(), ExecuteDecorator(), ExecuteNode(), ExecuteSelector(), ExecuteSequence(), ExecuteSubGraph(), Failure, GetComponentTypeID_Static(), Inverter, m_executedNodes, m_maxDepth, OnEvent, Repeater, Root, Selector, Sequence, SubGraph, Success, and SYSTEM_LOG.

Referenced by ExecuteDecorator(), ExecuteNode(), ExecuteSelector(), ExecuteSequence(), and ExecuteTree().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ExecuteSelector()

BTStatus Olympe::BehaviorTreeExecutor::ExecuteSelector ( const BTNode node,
const BehaviorTreeAsset btAsset,
GraphExecutionTracer outTracer 
)
private

Execute a Selector (OR) composite node.

A Selector succeeds if ANY child succeeds. Stops on first success.

Definition at line 146 of file BehaviorTreeExecutor.cpp.

References ExecuteNode(), Failure, GetComponentTypeID_Static(), and Success.

Referenced by ExecuteNode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ExecuteSequence()

BTStatus Olympe::BehaviorTreeExecutor::ExecuteSequence ( const BTNode node,
const BehaviorTreeAsset btAsset,
GraphExecutionTracer outTracer 
)
private

Execute a Sequence (AND) composite node.

A Sequence succeeds only if ALL children succeed. Stops on first failure.

Definition at line 172 of file BehaviorTreeExecutor.cpp.

References ExecuteNode(), Failure, GetComponentTypeID_Static(), and Success.

Referenced by ExecuteNode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ExecuteSubGraph()

BTStatus Olympe::BehaviorTreeExecutor::ExecuteSubGraph ( const BTNode node,
const BehaviorTreeAsset btAsset,
GraphExecutionTracer outTracer 
)
private

Phase 39: Execute a SubGraph reference node.

Loads external BT or ATS file and executes it recursively.

Definition at line 294 of file BehaviorTreeExecutor.cpp.

References Olympe::SubGraphCallStack::Contains(), ExecuteTree(), Failure, BehaviorTreeManager::Get(), GetComponentTypeID_Static(), BehaviorTreeManager::GetTreeByAnyId(), BehaviorTreeManager::LoadTreeFromFile(), m_callStack, SubGraphCallStack::MAX_DEPTH, Olympe::SubGraphCallStack::Pop(), Olympe::SubGraphCallStack::Push(), StatusToString(), and SYSTEM_LOG.

Referenced by ExecuteNode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ExecuteTree()

BTStatus Olympe::BehaviorTreeExecutor::ExecuteTree ( const BehaviorTreeAsset btAsset,
GraphExecutionTracer outTracer 
)

Execute a BehaviorTree and collect trace information.

Parameters
btAssetThe BehaviorTree asset to execute
outTracer[out] Execution trace collection
Returns
Execution status (Success, Failure, or Running)

Definition at line 23 of file BehaviorTreeExecutor.cpp.

References ExecuteNode(), Failure, GetComponentTypeID_Static(), m_executedNodes, m_maxDepth, StatusToString(), Success, and SYSTEM_LOG.

Referenced by ExecuteSubGraph(), and Olympe::BehaviorTreeRenderer::OnRunGraphClicked().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ StatusToString()

const char * Olympe::BehaviorTreeExecutor::StatusToString ( BTStatus  status)
staticprivate

Convert BTStatus to string for logging.

Definition at line 390 of file BehaviorTreeExecutor.cpp.

References Aborted, Failure, Idle, Running, and Success.

Referenced by ExecuteSubGraph(), and ExecuteTree().

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_callStack

SubGraphCallStack Olympe::BehaviorTreeExecutor::m_callStack
private

Phase 39: Call stack for SubGraph recursion tracking.

Definition at line 101 of file BehaviorTreeExecutor.h.

Referenced by ExecuteSubGraph().

◆ m_executedNodes

int Olympe::BehaviorTreeExecutor::m_executedNodes = 0
private

Count of executed nodes.

Definition at line 98 of file BehaviorTreeExecutor.h.

Referenced by ExecuteNode(), and ExecuteTree().

◆ m_maxDepth

int Olympe::BehaviorTreeExecutor::m_maxDepth = 0
private

Track recursion depth to detect cycles.

Definition at line 97 of file BehaviorTreeExecutor.h.

Referenced by ExecuteNode(), and ExecuteTree().


The documentation for this class was generated from the following files: