Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
BTDebugAdapter.h
Go to the documentation of this file.
1/**
2 * @file BTDebugAdapter.h
3 * @brief Debug adapter for BehaviorTree runtime visualization
4 * @author Olympe Engine - NodeGraphShared
5 * @date 2025-02-19
6 *
7 * @details
8 * Provides a unified interface to visualize BehaviorTree runtime state.
9 *
10 * NOTE: This adapter is part of the planned unified architecture migration.
11 * Currently not actively used - see BehaviorTreeDebugWindow_UnifiedMigration_Plan.md
12 *
13 * Future integration will enable:
14 * - Read-only visualization of runtime trees via NodeGraphRenderer
15 * - Active node highlighting with pulse animation
16 * - Consistent rendering with standalone editor
17 * - Zero-copy lazy conversion (BT -> GraphDocument on demand)
18 */
19
20#pragma once
21
22// Forward declarations to avoid circular dependencies
23namespace Olympe { namespace NodeGraph { class NodeGraphRenderer; class GraphDocument; struct RenderConfig; } }
25class BTGraphLayoutEngine;
26struct BTNodeLayout;
27
28#include <memory>
29#include <cstdint>
30#include <vector>
31
32namespace Olympe
33{
34namespace NodeGraphShared
35{
36
37/**
38 * @class BTDebugAdapter
39 * @brief Adapter for visualizing BehaviorTree runtime using unified renderer
40 *
41 * Usage in BehaviorTreeDebugWindow:
42 * @code
43 * // Setup (once per tree load)
44 * BTDebugAdapter adapter(&tree, &layoutEngine);
45 * adapter.Initialize(&renderer);
46 *
47 * // Update active node each frame
48 * adapter.SetActiveNode(btRuntime.AICurrentNodeIndex);
49 *
50 * // Render
51 * adapter.Render(deltaTime);
52 * @endcode
53 */
55{
56public:
57 /**
58 * @brief Construct a debug adapter for a behavior tree
59 * @param tree BehaviorTree runtime asset to visualize
60 * @param layoutEngine Layout engine for node positioning
61 */
65 );
66
68
69 // ========================================================================
70 // Lifecycle
71 // ========================================================================
72
73 /**
74 * @brief Initialize the adapter with a renderer instance
75 * @param renderer NodeGraphRenderer to use (must outlive adapter)
76 * @param config Optional render configuration (nullptr = use defaults)
77 */
79 NodeGraph::NodeGraphRenderer* renderer,
80 const NodeGraph::RenderConfig* config = nullptr
81 );
82
83 /**
84 * @brief Shutdown and cleanup resources
85 */
86 void Shutdown();
87
88 /**
89 * @brief Check if adapter is ready to render
90 */
91 bool IsInitialized() const { return m_renderer != nullptr; }
92
93 // ========================================================================
94 // Runtime State
95 // ========================================================================
96
97 /**
98 * @brief Set the currently executing node (for highlighting)
99 * @param nodeId ID of active node (0 = none)
100 */
102
103 /**
104 * @brief Clear all runtime highlighting
105 */
107
108 /**
109 * @brief Get current active node ID
110 */
112
113 // ========================================================================
114 // Layout & View Control
115 // ========================================================================
116
117 /**
118 * @brief Recompute layout (call after tree structure changes)
119 * @param nodeSpacingX Horizontal spacing between nodes
120 * @param nodeSpacingY Vertical spacing between nodes
121 * @param zoomFactor Current zoom level
122 */
123 void RecomputeLayout(float nodeSpacingX, float nodeSpacingY, float zoomFactor);
124
125 /**
126 * @brief Update a single node position (user drag in editor mode)
127 * @param nodeId Node to move
128 * @param x New X position
129 * @param y New Y position
130 * @return true if position updated successfully
131 */
132 bool UpdateNodePosition(uint32_t nodeId, float x, float y);
133
134 /**
135 * @brief Fit graph to view (auto-zoom)
136 */
137 void FitToView();
138
139 /**
140 * @brief Center view on active node
141 */
143
144 // ========================================================================
145 // Rendering
146 // ========================================================================
147
148 /**
149 * @brief Render the behavior tree using unified pipeline
150 * @param deltaTime Time since last frame (for animations)
151 */
152 void Render(float deltaTime);
153
154 // ========================================================================
155 // Editor Mode (Optional)
156 // ========================================================================
157
158 /**
159 * @brief Enable editor mode (allows modifications via commands)
160 * @param commandStack Command stack for undo/redo (nullptr = read-only)
161 */
162 void SetEditorMode(bool enabled);
163
164 /**
165 * @brief Check if adapter is in editor mode
166 */
167 bool IsEditorMode() const { return m_editorMode; }
168
169private:
170 // Data conversion (lazy)
174
175 // Rendering helpers
177
178 // State
181 NodeGraph::NodeGraphRenderer* m_renderer;
182
183 // Converted document (lazy-initialized)
184 std::unique_ptr<NodeGraph::GraphDocument> m_document;
186
187 // Runtime state
190
191 // Layout cache
192 std::vector<BTNodeLayout> m_currentLayout;
196};
197
198} // namespace NodeGraphShared
199} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
static SDL_Renderer * renderer
Computes clean hierarchical layouts for behavior trees.
Adapter for visualizing BehaviorTree runtime using unified renderer.
bool IsInitialized() const
Check if adapter is ready to render.
uint32_t GetActiveNodeId() const
Get current active node ID.
bool IsEditorMode() const
Check if adapter is in editor mode.
std::vector< BTNodeLayout > m_currentLayout
void FitToView()
Fit graph to view (auto-zoom)
bool UpdateNodePosition(uint32_t nodeId, float x, float y)
Update a single node position (user drag in editor mode)
void ClearRuntimeState()
Clear all runtime highlighting.
NodeGraph::NodeGraphRenderer * m_renderer
BTDebugAdapter(const BehaviorTreeAsset *tree, BTGraphLayoutEngine *layoutEngine)
Construct a debug adapter for a behavior tree.
void CenterOnActiveNode()
Center view on active node.
void Render(float deltaTime)
Render the behavior tree using unified pipeline.
void Shutdown()
Shutdown and cleanup resources.
void SetEditorMode(bool enabled)
Enable editor mode (allows modifications via commands)
void RecomputeLayout(float nodeSpacingX, float nodeSpacingY, float zoomFactor)
Recompute layout (call after tree structure changes)
void Initialize(NodeGraph::NodeGraphRenderer *renderer, const NodeGraph::RenderConfig *config=nullptr)
Initialize the adapter with a renderer instance.
void SetActiveNode(uint32_t nodeId)
Set the currently executing node (for highlighting)
std::unique_ptr< NodeGraph::GraphDocument > m_document
< Provides AssetID and INVALID_ASSET_ID