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

Computes clean hierarchical layouts for behavior trees. More...

#include <BTGraphLayoutEngine.h>

Public Member Functions

 BTGraphLayoutEngine ()
 
 ~BTGraphLayoutEngine ()=default
 
void SetLayoutDirection (BTLayoutDirection direction)
 Set layout direction.
 
BTLayoutDirection GetLayoutDirection () const
 Get current layout direction.
 
std::vector< BTNodeLayoutComputeLayout (const BehaviorTreeAsset *tree, float nodeSpacingX=180.0f, float nodeSpacingY=120.0f, float zoomFactor=1.0f)
 Compute layout for a behavior tree.
 
const BTNodeLayoutGetNodeLayout (uint32_t nodeId) const
 Get computed layout for a specific node.
 

Private Member Functions

void AssignLayers (const BehaviorTreeAsset *tree)
 
void InitialOrdering ()
 
void ReduceCrossings (const BehaviorTreeAsset *tree)
 
void ApplyBuchheimWalkerLayout (const BehaviorTreeAsset *tree)
 
void ResolveNodeCollisionsForceDirected (float nodePadding, int maxIterations)
 
void AssignXCoordinates (float nodeSpacingX)
 
void ResolveCollisions (float nodeSpacingX)
 
std::vector< uint32_tGetChildren (const BTNode *node) const
 
void BuildParentMap (const BehaviorTreeAsset *tree)
 
float CalculateBarycenter (uint32_t nodeId, const std::vector< BTNodeLayout * > &neighbors) const
 
void PlaceSubtree (uint32_t nodeId, const BehaviorTreeAsset *tree, int depth, float &nextAvailableX)
 
void ShiftSubtree (uint32_t nodeId, const BehaviorTreeAsset *tree, float offset)
 
bool DoNodesOverlap (const BTNodeLayout &a, const BTNodeLayout &b, float padding) const
 
void PushNodeApart (uint32_t nodeA, uint32_t nodeB, float minDistance)
 
int CountEdgeCrossings (const BehaviorTreeAsset *tree) const
 

Private Attributes

BTLayoutDirection m_layoutDirection = BTLayoutDirection::TopToBottom
 Default vertical.
 
std::vector< BTNodeLayoutm_layouts
 
std::map< uint32_t, size_tm_nodeIdToIndex
 
std::vector< std::vector< uint32_t > > m_layers
 
std::map< uint32_t, std::vector< uint32_t > > m_parentMap
 

Detailed Description

Computes clean hierarchical layouts for behavior trees.

Uses the Sugiyama algorithm to create readable, professional-looking node graphs without overlaps.

Definition at line 59 of file BTGraphLayoutEngine.h.

Constructor & Destructor Documentation

◆ BTGraphLayoutEngine()

Olympe::BTGraphLayoutEngine::BTGraphLayoutEngine ( )

Definition at line 14 of file BTGraphLayoutEngine.cpp.

◆ ~BTGraphLayoutEngine()

Olympe::BTGraphLayoutEngine::~BTGraphLayoutEngine ( )
default

Member Function Documentation

◆ ApplyBuchheimWalkerLayout()

void Olympe::BTGraphLayoutEngine::ApplyBuchheimWalkerLayout ( const BehaviorTreeAsset tree)
private

Definition at line 471 of file BTGraphLayoutEngine.cpp.

References GetComponentTypeID_Static(), m_layers, m_layouts, and PlaceSubtree().

Referenced by ComputeLayout().

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

◆ AssignLayers()

void Olympe::BTGraphLayoutEngine::AssignLayers ( const BehaviorTreeAsset tree)
private

Definition at line 146 of file BTGraphLayoutEngine.cpp.

References BuildParentMap(), GetChildren(), GetComponentTypeID_Static(), m_layers, m_layouts, m_nodeIdToIndex, and Olympe::BTNodeLayout::nodeId.

Referenced by ComputeLayout().

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

◆ AssignXCoordinates()

void Olympe::BTGraphLayoutEngine::AssignXCoordinates ( float  nodeSpacingX)
private

Definition at line 355 of file BTGraphLayoutEngine.cpp.

References GetComponentTypeID_Static(), m_layers, m_layouts, and m_nodeIdToIndex.

+ Here is the call graph for this function:

◆ BuildParentMap()

void Olympe::BTGraphLayoutEngine::BuildParentMap ( const BehaviorTreeAsset tree)
private

Definition at line 443 of file BTGraphLayoutEngine.cpp.

References GetChildren(), GetComponentTypeID_Static(), and m_parentMap.

Referenced by AssignLayers().

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

◆ CalculateBarycenter()

float Olympe::BTGraphLayoutEngine::CalculateBarycenter ( uint32_t  nodeId,
const std::vector< BTNodeLayout * > &  neighbors 
) const
private

Definition at line 457 of file BTGraphLayoutEngine.cpp.

References GetComponentTypeID_Static().

Referenced by ReduceCrossings().

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

◆ ComputeLayout()

std::vector< BTNodeLayout > Olympe::BTGraphLayoutEngine::ComputeLayout ( const BehaviorTreeAsset tree,
float  nodeSpacingX = 180.0f,
float  nodeSpacingY = 120.0f,
float  zoomFactor = 1.0f 
)

Compute layout for a behavior tree.

Parameters
treeThe behavior tree asset to layout
nodeSpacingXHorizontal spacing between nodes (default: 180px, reduced from 250px)
nodeSpacingYVertical spacing between layers (default: 120px, reduced from 180px)
zoomFactorZoom multiplier applied to final positions (default: 1.0)
Returns
Vector of node layouts with computed positions

Definition at line 18 of file BTGraphLayoutEngine.cpp.

References ApplyBuchheimWalkerLayout(), AssignLayers(), GetComponentTypeID_Static(), InitialOrdering(), m_layers, m_layoutDirection, m_layouts, m_nodeIdToIndex, m_parentMap, ReduceCrossings(), ResolveNodeCollisionsForceDirected(), and Olympe::TopToBottom.

Referenced by Olympe::BehaviorTreeDebugWindow::RenderInSeparateWindow().

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

◆ CountEdgeCrossings()

int Olympe::BTGraphLayoutEngine::CountEdgeCrossings ( const BehaviorTreeAsset tree) const
private

Definition at line 680 of file BTGraphLayoutEngine.cpp.

References GetChildren(), GetComponentTypeID_Static(), and m_layers.

Referenced by ReduceCrossings().

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

◆ DoNodesOverlap()

bool Olympe::BTGraphLayoutEngine::DoNodesOverlap ( const BTNodeLayout a,
const BTNodeLayout b,
float  padding 
) const
private

Definition at line 612 of file BTGraphLayoutEngine.cpp.

References GetComponentTypeID_Static(), Olympe::BTNodeLayout::position, and Vector::x.

Referenced by ResolveNodeCollisionsForceDirected().

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

◆ GetChildren()

std::vector< uint32_t > Olympe::BTGraphLayoutEngine::GetChildren ( const BTNode node) const
private

Definition at line 419 of file BTGraphLayoutEngine.cpp.

References GetComponentTypeID_Static(), Inverter, Repeater, Selector, and Sequence.

Referenced by AssignLayers(), BuildParentMap(), CountEdgeCrossings(), PlaceSubtree(), ReduceCrossings(), and ShiftSubtree().

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

◆ GetLayoutDirection()

BTLayoutDirection Olympe::BTGraphLayoutEngine::GetLayoutDirection ( ) const
inline

Get current layout direction.

Returns
Current layout direction

Definition at line 75 of file BTGraphLayoutEngine.h.

References m_layoutDirection.

◆ GetNodeLayout()

const BTNodeLayout * Olympe::BTGraphLayoutEngine::GetNodeLayout ( uint32_t  nodeId) const

Get computed layout for a specific node.

Parameters
nodeIdThe BT node ID
Returns
Pointer to layout, or nullptr if not found

Definition at line 136 of file BTGraphLayoutEngine.cpp.

References GetComponentTypeID_Static(), m_layouts, and m_nodeIdToIndex.

+ Here is the call graph for this function:

◆ InitialOrdering()

void Olympe::BTGraphLayoutEngine::InitialOrdering ( )
private

Definition at line 204 of file BTGraphLayoutEngine.cpp.

References GetComponentTypeID_Static(), m_layers, m_layouts, and m_nodeIdToIndex.

Referenced by ComputeLayout().

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

◆ PlaceSubtree()

void Olympe::BTGraphLayoutEngine::PlaceSubtree ( uint32_t  nodeId,
const BehaviorTreeAsset tree,
int  depth,
float nextAvailableX 
)
private

Definition at line 496 of file BTGraphLayoutEngine.cpp.

References GetChildren(), GetComponentTypeID_Static(), m_layouts, m_nodeIdToIndex, PlaceSubtree(), and ShiftSubtree().

Referenced by ApplyBuchheimWalkerLayout(), and PlaceSubtree().

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

◆ PushNodeApart()

void Olympe::BTGraphLayoutEngine::PushNodeApart ( uint32_t  nodeA,
uint32_t  nodeB,
float  minDistance 
)
private

Definition at line 630 of file BTGraphLayoutEngine.cpp.

References GetComponentTypeID_Static(), m_layouts, m_nodeIdToIndex, Olympe::BTNodeLayout::position, and Vector::x.

Referenced by ResolveNodeCollisionsForceDirected().

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

◆ ReduceCrossings()

void Olympe::BTGraphLayoutEngine::ReduceCrossings ( const BehaviorTreeAsset tree)
private

Definition at line 222 of file BTGraphLayoutEngine.cpp.

References CalculateBarycenter(), CountEdgeCrossings(), GetChildren(), GetComponentTypeID_Static(), m_layers, m_layouts, m_nodeIdToIndex, and m_parentMap.

Referenced by ComputeLayout().

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

◆ ResolveCollisions()

void Olympe::BTGraphLayoutEngine::ResolveCollisions ( float  nodeSpacingX)
private

Definition at line 375 of file BTGraphLayoutEngine.cpp.

References GetComponentTypeID_Static(), m_layers, m_layouts, m_nodeIdToIndex, Olympe::BTNodeLayout::position, and Vector::x.

+ Here is the call graph for this function:

◆ ResolveNodeCollisionsForceDirected()

void Olympe::BTGraphLayoutEngine::ResolveNodeCollisionsForceDirected ( float  nodePadding,
int  maxIterations 
)
private

Definition at line 568 of file BTGraphLayoutEngine.cpp.

References DoNodesOverlap(), GetComponentTypeID_Static(), m_layers, m_layouts, m_nodeIdToIndex, and PushNodeApart().

Referenced by ComputeLayout().

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

◆ SetLayoutDirection()

void Olympe::BTGraphLayoutEngine::SetLayoutDirection ( BTLayoutDirection  direction)
inline

Set layout direction.

Parameters
directionLayout direction (TopToBottom or LeftToRight)

Definition at line 69 of file BTGraphLayoutEngine.h.

References m_layoutDirection.

◆ ShiftSubtree()

void Olympe::BTGraphLayoutEngine::ShiftSubtree ( uint32_t  nodeId,
const BehaviorTreeAsset tree,
float  offset 
)
private

Definition at line 549 of file BTGraphLayoutEngine.cpp.

References GetChildren(), GetComponentTypeID_Static(), m_layouts, m_nodeIdToIndex, and ShiftSubtree().

Referenced by PlaceSubtree(), and ShiftSubtree().

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

Member Data Documentation

◆ m_layers

std::vector<std::vector<uint32_t> > Olympe::BTGraphLayoutEngine::m_layers
private

◆ m_layoutDirection

BTLayoutDirection Olympe::BTGraphLayoutEngine::m_layoutDirection = BTLayoutDirection::TopToBottom
private

Default vertical.

Definition at line 140 of file BTGraphLayoutEngine.h.

Referenced by ComputeLayout(), GetLayoutDirection(), and SetLayoutDirection().

◆ m_layouts

std::vector<BTNodeLayout> Olympe::BTGraphLayoutEngine::m_layouts
private

◆ m_nodeIdToIndex

std::map<uint32_t, size_t> Olympe::BTGraphLayoutEngine::m_nodeIdToIndex
private

◆ m_parentMap

std::map<uint32_t, std::vector<uint32_t> > Olympe::BTGraphLayoutEngine::m_parentMap
private

Definition at line 148 of file BTGraphLayoutEngine.h.

Referenced by BuildParentMap(), ComputeLayout(), and ReduceCrossings().


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