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

Converts BehaviorTree structures to generic TaskGraphTemplate format for simulation. More...

#include <BehaviorTreeGraphAdapter.h>

Static Public Member Functions

static std::unique_ptr< TaskGraphTemplateAdaptToTaskGraph (const BehaviorTreeAsset &btAsset)
 Converts a BehaviorTreeAsset to TaskGraphTemplate format.
 
static std::string FormatTraceForBehaviorTree (const GraphExecutionTracer &tracer, const BehaviorTreeAsset &btAsset)
 Formats generic execution trace back to BehaviorTree-specific context.
 
static bool ValidateTreeStructure (const BehaviorTreeAsset &btAsset)
 Validates BehaviorTree structure before conversion.
 

Static Private Member Functions

static void AddNodeToGraph (const BTNode &btNode, const BehaviorTreeAsset &btAsset, TaskGraphTemplate &outGraph, std::map< uint32_t, int32_t > &btToGraphIdMap)
 Helper: Recursively adds a node and its children to the graph.
 
static int32_t CalculateNodeDepth (uint32_t nodeId, const BehaviorTreeAsset &btAsset)
 Helper: Calculates depth of a node in BT hierarchy.
 
static uint32_t FindParentNodeId (uint32_t childNodeId, const BehaviorTreeAsset &btAsset)
 Helper: Finds parent node ID for a given child node.
 
static std::string GetBTNodeTypeName (uint8_t type)
 Helper: Gets BehaviorTree node type name.
 

Detailed Description

Converts BehaviorTree structures to generic TaskGraphTemplate format for simulation.

This adapter layer enables the reuse of the generic GraphExecutionSimulator framework for BehaviorTree graphs without code duplication. It performs bidirectional conversion:

Forward (BehaviorTree → Graph):

Reverse (Trace → BehaviorTree Format):

Example Usage:

// Convert to graph format
// Simulate using generic framework
simulator.SimulateExecution(*taskGraph, options, tracer);
// Format trace back to BehaviorTree context
// Display via existing panel
executionPanel->DisplayResults(tracer, btTrace);
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
static std::unique_ptr< TaskGraphTemplate > AdaptToTaskGraph(const BehaviorTreeAsset &btAsset)
Converts a BehaviorTreeAsset to TaskGraphTemplate format.
static std::string FormatTraceForBehaviorTree(const GraphExecutionTracer &tracer, const BehaviorTreeAsset &btAsset)
Formats generic execution trace back to BehaviorTree-specific context.
Simulates blueprint graph execution for validation purposes.
Records execution trace during graph simulation.
Configuration options for graph simulation.

Definition at line 70 of file BehaviorTreeGraphAdapter.h.

Member Function Documentation

◆ AdaptToTaskGraph()

std::unique_ptr< TaskGraphTemplate > Olympe::BehaviorTreeGraphAdapter::AdaptToTaskGraph ( const BehaviorTreeAsset btAsset)
static

Converts a BehaviorTreeAsset to TaskGraphTemplate format.

Parameters
btAssetSource BehaviorTree asset containing hierarchical BTNode structure.
Returns
Unique pointer to TaskGraphTemplate suitable for GraphExecutionSimulator. Returns nullptr if validation fails.

Performs the following transformations:

  1. Validates tree structure (no orphaned nodes, valid cycles, etc.)
  2. Iterates BTNode[] and creates TaskNodeDefinition for each
  3. Maps BTNode.type enum to appropriate TaskNodeType:
    • Selector → Selector (BT type 0)
    • Sequence → Sequence (BT type 1)
    • Condition → AtomicTask with condition ID
    • Action → AtomicTask with action ID
    • Inverter/Repeater → Decorator
  4. Converts hierarchical childIds relationships to explicit ExecPinConnection entries:
    • Each child becomes a connection with SourceNodeID=parent, TargetNodeID=child
    • Pin names: "Control" (output) → "In" (input)
  5. Returns fully populated TaskGraphTemplate ready for simulation
Note
  • The conversion is one-way: BT → Graph (graph is flattened, hierarchy inferred at runtime)
  • All BTNode properties are preserved; nothing is lost
  • BT-specific details (condition type, action type) stored in AtomicTaskID field

Definition at line 23 of file BehaviorTreeGraphAdapter.cpp.

References AddNodeToGraph(), GetComponentTypeID_Static(), and ValidateTreeStructure().

+ Here is the call graph for this function:

◆ AddNodeToGraph()

void Olympe::BehaviorTreeGraphAdapter::AddNodeToGraph ( const BTNode btNode,
const BehaviorTreeAsset btAsset,
TaskGraphTemplate outGraph,
std::map< uint32_t, int32_t > &  btToGraphIdMap 
)
staticprivate

Helper: Recursively adds a node and its children to the graph.

Definition at line 178 of file BehaviorTreeGraphAdapter.cpp.

References Action, AddNodeToGraph(), Olympe::AtomicTask, Condition, Olympe::Decorator, GetComponentTypeID_Static(), Inverter, Olympe::TaskNodeDefinition::NodeID, OnEvent, Repeater, Root, Olympe::Root, Selector, Olympe::Selector, Sequence, Olympe::Sequence, and Olympe::ExecPinConnection::SourceNodeID.

Referenced by AdaptToTaskGraph(), and AddNodeToGraph().

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

◆ CalculateNodeDepth()

int32_t Olympe::BehaviorTreeGraphAdapter::CalculateNodeDepth ( uint32_t  nodeId,
const BehaviorTreeAsset btAsset 
)
staticprivate

Helper: Calculates depth of a node in BT hierarchy.

Definition at line 256 of file BehaviorTreeGraphAdapter.cpp.

References CalculateNodeDepth(), FindParentNodeId(), and GetComponentTypeID_Static().

Referenced by CalculateNodeDepth(), and FormatTraceForBehaviorTree().

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

◆ FindParentNodeId()

uint32_t Olympe::BehaviorTreeGraphAdapter::FindParentNodeId ( uint32_t  childNodeId,
const BehaviorTreeAsset btAsset 
)
staticprivate

Helper: Finds parent node ID for a given child node.

Definition at line 275 of file BehaviorTreeGraphAdapter.cpp.

References GetComponentTypeID_Static().

Referenced by CalculateNodeDepth().

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

◆ FormatTraceForBehaviorTree()

std::string Olympe::BehaviorTreeGraphAdapter::FormatTraceForBehaviorTree ( const GraphExecutionTracer tracer,
const BehaviorTreeAsset btAsset 
)
static

Formats generic execution trace back to BehaviorTree-specific context.

Parameters
tracerGraphExecutionTracer containing generic ExecutionEvent trace.
btAssetOriginal BehaviorTreeAsset for context and hierarchy information.
Returns
Human-readable string with BehaviorTree-specific formatting.

Post-processes the generic execution trace from GraphExecutionSimulator with BehaviorTree-specific enhancements:

  1. Status Symbol Mapping (from event message keywords):
    • SUCCESS → "✓ " (check mark)
    • FAILURE → "✗ " (cross mark)
    • RUNNING → "⊙ " (circle - in-progress)
    • Other → (blank) - informational message
  2. Type Name Replacement:
    • Maps node types back to BT-specific names
  3. Hierarchical Indentation:
    • Calculates node depth in original BT hierarchy
    • Indents output with (depth * 2) spaces for tree-like visualization
Note
  • Called AFTER simulation completes (post-processing layer)
  • Does not modify tracer or btAsset; both remain const
  • Output is human-readable string (for logging, UI display, etc.)

Definition at line 59 of file BehaviorTreeGraphAdapter.cpp.

References CalculateNodeDepth(), GetBTNodeTypeName(), and GetComponentTypeID_Static().

+ Here is the call graph for this function:

◆ GetBTNodeTypeName()

std::string Olympe::BehaviorTreeGraphAdapter::GetBTNodeTypeName ( uint8_t  type)
staticprivate

Helper: Gets BehaviorTree node type name.

Definition at line 290 of file BehaviorTreeGraphAdapter.cpp.

References Action, Condition, Inverter, OnEvent, Repeater, Root, Selector, and Sequence.

Referenced by FormatTraceForBehaviorTree().

+ Here is the caller graph for this function:

◆ ValidateTreeStructure()

bool Olympe::BehaviorTreeGraphAdapter::ValidateTreeStructure ( const BehaviorTreeAsset btAsset)
static

Validates BehaviorTree structure before conversion.

Parameters
btAssetBehaviorTreeAsset to validate.
Returns
true if valid for conversion; false otherwise.

Performs structural validation to catch issues before conversion:

  • Node ID uniqueness
  • Child references validity
  • Cycle detection
  • Node type consistency

Definition at line 126 of file BehaviorTreeGraphAdapter.cpp.

References GetComponentTypeID_Static().

Referenced by AdaptToTaskGraph().

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

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