Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
BehaviorTreeDebugWindow.h
Go to the documentation of this file.
1/**
2 * @file BehaviorTreeDebugWindow.h
3 * @brief Runtime debugger for behavior tree visualization and inspection
4 * @author Olympe Engine - Behavior Tree Debugger
5 * @date 2025
6 *
7 * @details
8 * Provides real-time visualization of AI decision-making with:
9 * - Entity list with filtering and sorting
10 * - Interactive node graph with execution token highlighting
11 * - Inspector panel with blackboard and execution log
12 */
13
14#pragma once
15
16#include "../ECS_Entity.h"
17#include "../vector.h"
18#include "../json_helper.h"
19#include "BehaviorTree.h"
20#include "../BlueprintEditor/NodeGraphPanel.h"
21#include "../BlueprintEditor/BTNodeGraphManager.h"
22#include <string>
23#include <vector>
24#include <deque>
25#include <map>
26#include <unordered_map>
27#include <unordered_set>
28#include <cstdint>
29#include "../EditorCommon/EditorAutosaveManager.h"
30
31 // Forward declarations for SDL3
32struct SDL_Window;
33struct SDL_Renderer;
34union SDL_Event;
35struct ImGuiContext;
36
37namespace Olympe
38{
39 /**
40 * @struct ExecutionLogEntry
41 * @brief Single entry in the execution log
42 */
44 {
45 float timeAgo = 0.0f; ///< Time since entry (seconds)
46 EntityID entity = 0; ///< Entity that executed
47 uint32_t nodeId = 0; ///< Node that was executed
48 std::string nodeName; ///< Node name
49 BTStatus status = BTStatus::Running; ///< Execution result
50 };
51
52 /**
53 * @struct EntityDebugInfo
54 * @brief Cached debug information for a single entity
55 */
57 {
59 std::string entityName;
61 std::string treeName;
62 bool isActive = false;
63 bool hasTarget = false;
66 std::string aiMode;
67 float lastUpdateTime = 0.0f;
68 };
69
70 /**
71 * @class BehaviorTreeDebugWindow
72 * @brief Main debug window for behavior tree runtime visualization
73 *
74 * Provides comprehensive debugging capabilities for AI behavior trees,
75 * including entity selection, graph visualization, and blackboard inspection.
76 *
77 * Renders in a separate SDL3 native window (not embedded in main engine window).
78 */
80 {
81 public:
84
85 /**
86 * @brief Initialize the debug window
87 */
88 void Initialize();
89
90 /**
91 * @brief Shutdown and cleanup
92 */
93 void Shutdown();
94
95 /**
96 * @brief Render the debug window (in separate SDL3 window)
97 */
98 void Render();
99
100 /**
101 * @brief Toggle window visibility (creates/destroys separate window)
102 */
103 void ToggleVisibility();
104
105 /**
106 * @brief Check if window is visible
107 */
108 bool IsVisible() const { return m_isVisible; }
109
110 /**
111 * @brief Process SDL events for separate window
112 * @param event SDL event to process
113 */
115
116 /**
117 * @brief Add an execution log entry
118 * @param entity Entity that executed
119 * @param nodeId Node that was executed
120 * @param nodeName Node name
121 * @param status Execution result
122 */
123 void AddExecutionEntry(EntityID entity, uint32_t nodeId, const std::string& nodeName, BTStatus status);
124
125 private:
126 // Main panel rendering
129
130 // Separate window management
134
135 // Entity list helpers
136 void RefreshEntityList();
138 void UpdateEntitySorting();
140
141 // Inspector helpers
142 void RenderRuntimeInfo();
144 void RenderExecutionLog();
145
146 // Data management
147 std::vector<EntityDebugInfo> m_entities;
148 std::vector<EntityDebugInfo> m_filteredEntities;
150
151 // Execution log (circular buffer with max 100 entries)
152 std::deque<ExecutionLogEntry> m_executionLog;
153 const size_t MAX_LOG_ENTRIES = 100;
154
155 // UI state
156 bool m_isVisible = false;
157 bool m_isInitialized = false;
159
160 // Filtering
161 char m_filterText[256] = "";
162 bool m_filterActiveOnly = false;
163 bool m_filterHasTarget = false;
164
165 // Sorting
166 enum class SortMode
167 {
168 Name,
169 TreeName,
171 AIMode
172 };
174 bool m_sortAscending = true;
175
176 // Panel layout
177 float m_entityListWidth = 250.0f;
178 float m_inspectorWidth = 350.0f;
179
180 // ImNodes context flag (shared with NodeGraphPanel rendering pipeline)
182
183 // Separate SDL3 window for debugger
187
188 // Separate ImGui context for this window
190
191 // Async autosave – persists node positions without blocking the UI.
193
194 // --- Unified NodeGraph Debug Panel (Blueprint Editor pipeline) ---
198
202 };
203}
Data-driven behavior tree system for AI decision making.
BTStatus
Behavior tree node execution status.
@ Running
Node is currently executing.
AIMode
AI behavior modes for NPCs.
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
std::uint64_t EntityID
Definition ECS_Entity.h:21
Main debug window for behavior tree runtime visualization.
void Initialize()
Initialize the debug window.
std::vector< EntityDebugInfo > m_filteredEntities
void ToggleVisibility()
Toggle window visibility (creates/destroys separate window)
std::deque< ExecutionLogEntry > m_executionLog
void Render()
Render the debug window (in separate SDL3 window)
void RenderEntityEntry(const EntityDebugInfo &info)
std::vector< EntityDebugInfo > m_entities
void AddExecutionEntry(EntityID entity, uint32_t nodeId, const std::string &nodeName, BTStatus status)
Add an execution log entry.
bool IsVisible() const
Check if window is visible.
void ProcessEvent(SDL_Event *event)
Process SDL events for separate window.
NodeGraphPanel - ImGui/ImNodes panel for node graph editing Provides visual editor for behavior trees...
< Provides AssetID and INVALID_ASSET_ID
Cached debug information for a single entity.
Single entry in the execution log.
float timeAgo
Time since entry (seconds)
EntityID entity
Entity that executed.
BTStatus status
Execution result.
uint32_t nodeId
Node that was executed.