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=320.0f, float nodeSpacingY=180.0f, float zoomFactor=1.0f)
 Compute layout for a behavior tree.
 
const BTNodeLayoutGetNodeLayout (uint32_t nodeId) const
 Get computed layout for a specific node.
 
bool UpdateNodePosition (uint32_t nodeId, float x, float y)
 Update the stored position for a node (e.g.
 
 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=320.0f, float nodeSpacingY=180.0f, float zoomFactor=1.0f)
 Compute layout for a behavior tree.
 
const BTNodeLayoutGetNodeLayout (uint32_t nodeId) const
 Get computed layout for a specific node.
 
bool UpdateNodePosition (uint32_t nodeId, float x, float y)
 Update the stored position for a node (e.g.
 

Private Member Functions

void AssignLayers (const BehaviorTreeAsset *tree)
 
std::vector< uint32_tGetChildren (const BTNode *node) const
 
void BuildParentMap (const BehaviorTreeAsset *tree)
 
void AssignLayers (const BehaviorTreeAsset *tree)
 
std::vector< uint32_tGetChildren (const BTNode *node) const
 
void BuildParentMap (const BehaviorTreeAsset *tree)
 

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 BFS layering followed by a fixed 400x200 grid to produce a horizontal layout with no overlaps.

Definition at line 60 of file BTGraphLayoutEngine.h.

Constructor & Destructor Documentation

◆ BTGraphLayoutEngine() [1/2]

Olympe::BTGraphLayoutEngine::BTGraphLayoutEngine ( )

Definition at line 18 of file BTGraphLayoutEngine.cpp.

◆ ~BTGraphLayoutEngine() [1/2]

Olympe::BTGraphLayoutEngine::~BTGraphLayoutEngine ( )
default

◆ BTGraphLayoutEngine() [2/2]

Olympe::BTGraphLayoutEngine::BTGraphLayoutEngine ( )

◆ ~BTGraphLayoutEngine() [2/2]

Olympe::BTGraphLayoutEngine::~BTGraphLayoutEngine ( )
default

Member Function Documentation

◆ AssignLayers() [1/2]

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

Definition at line 84 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:

◆ AssignLayers() [2/2]

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

◆ BuildParentMap() [1/2]

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

Definition at line 179 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:

◆ BuildParentMap() [2/2]

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

◆ ComputeLayout() [1/2]

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

Compute layout for a behavior tree.

Parameters
treeThe behavior tree asset to layout
nodeSpacingXHorizontal spacing between nodes (unused, fixed grid used)
nodeSpacingYVertical spacing between layers (unused, fixed grid used)
zoomFactorZoom multiplier (unused, fixed grid used)
Returns
Vector of node layouts with computed positions

Definition at line 22 of file BTGraphLayoutEngine.cpp.

References AssignLayers(), GetComponentTypeID_Static(), m_layers, m_layouts, m_nodeIdToIndex, m_parentMap, and SYSTEM_LOG.

Referenced by Olympe::NodeGraphShared::BehaviorTreeAdapter::ComputeLayout(), and Olympe::NodeGraphShared::BTGraphDocumentConverter::FromBehaviorTree().

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

◆ ComputeLayout() [2/2]

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

Compute layout for a behavior tree.

Parameters
treeThe behavior tree asset to layout
nodeSpacingXHorizontal spacing between nodes (unused, fixed grid used)
nodeSpacingYVertical spacing between layers (unused, fixed grid used)
zoomFactorZoom multiplier (unused, fixed grid used)
Returns
Vector of node layouts with computed positions

◆ GetChildren() [1/2]

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

Definition at line 155 of file BTGraphLayoutEngine.cpp.

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

Referenced by AssignLayers(), and BuildParentMap().

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

◆ GetChildren() [2/2]

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

◆ GetLayoutDirection() [1/2]

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

Get current layout direction.

Returns
Current layout direction

Definition at line 76 of file BTGraphLayoutEngine.h.

References m_layoutDirection.

◆ GetLayoutDirection() [2/2]

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

Get current layout direction.

Returns
Current layout direction

Definition at line 71 of file BTGraphLayoutEngine.h.

References m_layoutDirection.

◆ GetNodeLayout() [1/2]

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 64 of file BTGraphLayoutEngine.cpp.

References GetComponentTypeID_Static(), m_layouts, and m_nodeIdToIndex.

Referenced by Olympe::NodeGraphShared::BehaviorTreeAdapter::GetNodeLayout().

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

◆ GetNodeLayout() [2/2]

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

◆ SetLayoutDirection() [1/2]

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

Set layout direction.

Parameters
directionLayout direction (TopToBottom or LeftToRight)

Definition at line 70 of file BTGraphLayoutEngine.h.

References m_layoutDirection.

◆ SetLayoutDirection() [2/2]

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

Set layout direction.

Parameters
directionLayout direction (TopToBottom or LeftToRight)

Definition at line 65 of file BTGraphLayoutEngine.h.

References m_layoutDirection.

◆ UpdateNodePosition() [1/2]

bool Olympe::BTGraphLayoutEngine::UpdateNodePosition ( uint32_t  nodeId,
float  x,
float  y 
)

Update the stored position for a node (e.g.

after user drag).

Parameters
nodeIdThe BT node ID.
xNew X position in canvas (grid) units.
yNew Y position in canvas (grid) units.
Returns
true if the node was found and updated, false otherwise.

Definition at line 74 of file BTGraphLayoutEngine.cpp.

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

Referenced by Olympe::NodeGraphShared::BehaviorTreeAdapter::UpdateNodePosition().

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

◆ UpdateNodePosition() [2/2]

bool Olympe::BTGraphLayoutEngine::UpdateNodePosition ( uint32_t  nodeId,
float  x,
float  y 
)

Update the stored position for a node (e.g.

after user drag).

Parameters
nodeIdThe BT node ID.
xNew X position in canvas (grid) units.
yNew Y position in canvas (grid) units.
Returns
true if the node was found and updated, false otherwise.

Member Data Documentation

◆ m_layers

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

Definition at line 127 of file BTGraphLayoutEngine.h.

Referenced by AssignLayers(), and ComputeLayout().

◆ m_layoutDirection

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

Default vertical.

Definition at line 120 of file BTGraphLayoutEngine.h.

Referenced by 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 128 of file BTGraphLayoutEngine.h.

Referenced by BuildParentMap(), and ComputeLayout().


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