Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
BTGraphLayoutEngine.h
Go to the documentation of this file.
1// [DEPRECATED - Phase 5 - 2026-03-07]
2// Ce fichier est archivé. Il ne doit plus être inclus ni compilé.
3// Remplacé par : NodeGraph::FromJson + positions JSON sauvegardées (BTGraphDocumentConverter)
4// Voir : Docs/BLUEPRINT-REFACTOR-MARCH-2026.md
5
6/**
7 * @file BTGraphLayoutEngine.h
8 * @brief Graph layout engine for behavior tree visualization
9 * @author Olympe Engine - Behavior Tree Debugger
10 * @date 2025
11 *
12 * @details
13 * Implements a 2-phase hierarchical graph layout algorithm:
14 * 1. Layering: Assign nodes to layers via BFS
15 * 2. Fixed Grid Placement: Place nodes on a fixed 400x200 grid (horizontal layout)
16 *
17 * Produces a clean horizontal layout with no overlaps.
18 */
19
20#pragma once
21
22#include "../vector.h"
23#include "../AI/BehaviorTree.h"
24#include <vector>
25#include <map>
26
27namespace Olympe
28{
29 /**
30 * @enum BTLayoutDirection
31 * @brief Layout direction for behavior tree visualization
32 */
34 {
35 TopToBottom, ///< Traditional top-down layout (vertical)
36 LeftToRight ///< Horizontal left-to-right layout
37 };
38
39 /**
40 * @struct BTNodeLayout
41 * @brief Layout information for a single behavior tree node
42 */
44 {
45 uint32_t nodeId = 0; ///< BT node ID
46 Vector position; ///< Final position (x, y)
47 int layer = 0; ///< Hierarchical layer (0 = root)
48 int orderInLayer = 0; ///< Order within the layer
49 float width = 200.0f; ///< Node visual width (increased for readability)
50 float height = 100.0f; ///< Node visual height (increased for readability)
51 };
52
53 /**
54 * @class BTGraphLayoutEngine
55 * @brief Computes clean hierarchical layouts for behavior trees
56 *
57 * Uses BFS layering followed by a fixed 400x200 grid to produce
58 * a horizontal layout with no overlaps.
59 */
61 {
62 public:
65
66 /**
67 * @brief Set layout direction
68 * @param direction Layout direction (TopToBottom or LeftToRight)
69 */
71
72 /**
73 * @brief Get current layout direction
74 * @return Current layout direction
75 */
77
78 /**
79 * @brief Compute layout for a behavior tree
80 * @param tree The behavior tree asset to layout
81 * @param nodeSpacingX Horizontal spacing between nodes (unused, fixed grid used)
82 * @param nodeSpacingY Vertical spacing between layers (unused, fixed grid used)
83 * @param zoomFactor Zoom multiplier (unused, fixed grid used)
84 * @return Vector of node layouts with computed positions
85 */
86 std::vector<BTNodeLayout> ComputeLayout(
88 float nodeSpacingX = 320.0f,
89 float nodeSpacingY = 180.0f,
90 float zoomFactor = 1.0f
91 );
92
93 /**
94 * @brief Get computed layout for a specific node
95 * @param nodeId The BT node ID
96 * @return Pointer to layout, or nullptr if not found
97 */
98 const BTNodeLayout* GetNodeLayout(uint32_t nodeId) const;
99
100 /**
101 * @brief Update the stored position for a node (e.g. after user drag).
102 * @param nodeId The BT node ID.
103 * @param x New X position in canvas (grid) units.
104 * @param y New Y position in canvas (grid) units.
105 * @return true if the node was found and updated, false otherwise.
106 */
107 bool UpdateNodePosition(uint32_t nodeId, float x, float y);
108
109 private:
110 // Phase 1: Assign nodes to layers via BFS from root
112
113 // Helper: Get children of a node
114 std::vector<uint32_t> GetChildren(const BTNode* node) const;
115
116 // Helper: Get parent nodes (reverse lookup)
118
119 // Layout configuration
121
122 // Computed layouts
123 std::vector<BTNodeLayout> m_layouts;
124 std::map<uint32_t, size_t> m_nodeIdToIndex; // nodeId -> index in m_layouts
125
126 // Temporary data structures for algorithm
127 std::vector<std::vector<uint32_t>> m_layers; // layer -> [nodeIds]
128 std::map<uint32_t, std::vector<uint32_t>> m_parentMap; // nodeId -> [parentIds]
129 };
130}
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Computes clean hierarchical layouts for behavior trees.
bool UpdateNodePosition(uint32_t nodeId, float x, float y)
Update the stored position for a node (e.g.
const BTNodeLayout * GetNodeLayout(uint32_t nodeId) const
Get computed layout for a specific node.
std::vector< BTNodeLayout > m_layouts
std::vector< uint32_t > GetChildren(const BTNode *node) const
void BuildParentMap(const BehaviorTreeAsset *tree)
void SetLayoutDirection(BTLayoutDirection direction)
Set layout direction.
BTLayoutDirection GetLayoutDirection() const
Get current layout direction.
BTLayoutDirection m_layoutDirection
Default vertical.
std::map< uint32_t, size_t > m_nodeIdToIndex
std::map< uint32_t, std::vector< uint32_t > > m_parentMap
void AssignLayers(const BehaviorTreeAsset *tree)
std::vector< BTNodeLayout > ComputeLayout(const BehaviorTreeAsset *tree, float nodeSpacingX=320.0f, float nodeSpacingY=180.0f, float zoomFactor=1.0f)
Compute layout for a behavior tree.
std::vector< std::vector< uint32_t > > m_layers
< Provides AssetID and INVALID_ASSET_ID
BTLayoutDirection
Layout direction for behavior tree visualization.
@ LeftToRight
Horizontal left-to-right layout.
@ TopToBottom
Traditional top-down layout (vertical)
Represents a single node in a behavior tree.
Layout information for a single behavior tree node.
int orderInLayer
Order within the layer.
Vector position
Final position (x, y)
float height
Node visual height (increased for readability)
uint32_t nodeId
BT node ID.
int layer
Hierarchical layer (0 = root)
float width
Node visual width (increased for readability)