Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
BTNodeRegistry.cpp
Go to the documentation of this file.
1/**
2 * @file BTNodeRegistry.cpp
3 * @brief Implementation of BTNodeRegistry
4 * @author Olympe Engine
5 * @date 2026-02-18
6 */
7
8#include "BTNodeRegistry.h"
9#include "../../system/system_utils.h"
10#include "../../BlueprintEditor/ColorScheme.h"
11
12namespace Olympe {
13namespace AI {
14
15// Helper to convert IM_COL32 (RRGGBBAA) to registry color format (AABBGGRR)
17 uint32_t r = (imguiColor >> 0) & 0xFF;
18 uint32_t g = (imguiColor >> 8) & 0xFF;
19 uint32_t b = (imguiColor >> 16) & 0xFF;
20 uint32_t a = (imguiColor >> 24) & 0xFF;
21 return (a << 24) | (b << 16) | (g << 8) | r;
22}
23
28
32
34 // ========================================================================
35 // COMPOSITES (Flow Control)
36 // ========================================================================
37
39 "BT_Selector",
40 "Selector",
41 "Executes children until one succeeds (OR logic)",
44 "+", // Plus symbol
45 1, // Min 1 child
46 -1, // Unlimited children
47 true, // Allows decorator
48 {} // No parameters
49 });
50
52 "BT_Sequence",
53 "Sequence",
54 "Executes children until one fails (AND logic)",
57 "->", // Arrow
58 1, // Min 1 child
59 -1, // Unlimited children
60 true, // Allows decorator
61 {} // No parameters
62 });
63
65 "BT_Parallel",
66 "Parallel",
67 "Executes all children simultaneously",
70 "||", // Parallel bars
71 2, // Min 2 children
72 -1, // Unlimited children
73 true, // Allows decorator
74 {} // No parameters
75 });
76
77 // ========================================================================
78 // DECORATORS (Modifiers)
79 // ========================================================================
80
82 "BT_Inverter",
83 "Inverter",
84 "Inverts child result (SUCCESS <-> FAILURE)",
87 "!", // Not symbol
88 1, // Exactly 1 child
89 1, // Exactly 1 child
90 false, // No decorator on decorator
91 {} // No parameters
92 });
93
95 "BT_Repeater",
96 "Repeater",
97 "Repeats child N times",
100 "@", // At symbol
101 1, // Exactly 1 child
102 1, // Exactly 1 child
103 false, // No decorator on decorator
104 {"repeatCount"}
105 });
106
108 "BT_UntilSuccess",
109 "Until Success",
110 "Repeats child until it succeeds",
113 "^", // Up arrow
114 1, // Exactly 1 child
115 1, // Exactly 1 child
116 false, // No decorator on decorator
117 {}
118 });
119
121 "BT_UntilFailure",
122 "Until Failure",
123 "Repeats child until it fails",
126 "v", // Down arrow
127 1, // Exactly 1 child
128 1, // Exactly 1 child
129 false, // No decorator on decorator
130 {}
131 });
132
134 "BT_Cooldown",
135 "Cooldown",
136 "Limits execution frequency",
139 "#", // Hash symbol
140 1, // Exactly 1 child
141 1, // Exactly 1 child
142 false, // No decorator on decorator
143 {"cooldownDuration"}
144 });
145
146 // ========================================================================
147 // CONDITIONS (Boolean Checks)
148 // ========================================================================
149
151 "BT_CheckBlackboardValue",
152 "Check Blackboard Value",
153 "Compares blackboard value against expected value",
156 "?", // Question mark
157 0, // No children
158 0, // No children
159 true, // Allows decorator
160 {"key", "operator", "value"}
161 });
162
164 "BT_HasTarget",
165 "Has Target",
166 "Checks if entity has a target",
169 "T", // Target symbol
170 0, // No children
171 0, // No children
172 true, // Allows decorator
173 {}
174 });
175
177 "BT_IsTargetInRange",
178 "Is Target In Range",
179 "Checks if target is within specified distance",
182 "R", // Range symbol
183 0, // No children
184 0, // No children
185 true, // Allows decorator
186 {"distance"}
187 });
188
190 "BT_CanSeeTarget",
191 "Can See Target",
192 "Checks line of sight to target",
195 "E", // Eye symbol
196 0, // No children
197 0, // No children
198 true, // Allows decorator
199 {}
200 });
201
202 // ========================================================================
203 // ACTIONS (Leaf Execution Nodes)
204 // ========================================================================
205
207 "BT_Wait",
208 "Wait",
209 "Waits for N seconds",
212 "W", // Wait symbol
213 0, // No children
214 0, // No children
215 true, // Allows decorator
216 {"duration"}
217 });
218
220 "BT_WaitRandomTime",
221 "Wait Random Time",
222 "Waits for random duration",
225 "w", // Small wait
226 0, // No children
227 0, // No children
228 true, // Allows decorator
229 {"minDuration", "maxDuration"}
230 });
231
233 "BT_SetBlackboardValue",
234 "Set Blackboard Value",
235 "Modifies blackboard value",
238 "=", // Equals symbol
239 0, // No children
240 0, // No children
241 true, // Allows decorator
242 {"key", "value"}
243 });
244
246 "BT_MoveToTarget",
247 "Move To Target",
248 "Moves entity towards target",
251 "M", // Move symbol
252 0, // No children
253 0, // No children
254 true, // Allows decorator
255 {"speed"}
256 });
257
259 "BT_MoveToPosition",
260 "Move To Position",
261 "Moves entity to specific position",
264 "P", // Position symbol
265 0, // No children
266 0, // No children
267 true, // Allows decorator
268 {"x", "y"}
269 });
270
272 "BT_AttackTarget",
273 "Attack Target",
274 "Attacks current target",
277 "A", // Attack symbol
278 0, // No children
279 0, // No children
280 true, // Allows decorator
281 {}
282 });
283
285 "BT_PlayAnimation",
286 "Play Animation",
287 "Plays specified animation",
290 "*", // Star symbol
291 0, // No children
292 0, // No children
293 true, // Allows decorator
294 {"animationName"}
295 });
296
298 "BT_EmitSound",
299 "Emit Sound",
300 "Plays sound effect",
303 "S", // Sound symbol
304 0, // No children
305 0, // No children
306 true, // Allows decorator
307 {"soundId"}
308 });
309
310 // ========================================================================
311 // ROOT NODE (Entry Point)
312 // ========================================================================
313
315 "BT_Root",
316 "Root",
317 "Entry point for behavior tree execution (auto-created, undeletable)",
320 "▶", // Play symbol
321 1, // Exactly 1 child
322 1, // Exactly 1 child
323 false, // No decorator on root
324 {} // No parameters
325 });
326
327 // ========================================================================
328 // EVENT NODES (Event-Driven Execution)
329 // ========================================================================
330
332 "BT_OnEvent",
333 "On Event",
334 "Entry point triggered by EventQueue message (parameterized by event type)",
337 "📨", // Envelope symbol
338 1, // Exactly 1 child
339 1, // Exactly 1 child
340 false, // No decorator on event root
341 {"eventType", "eventMessage"} // Filter by event type and optional message
342 });
343
344 // ========================================================================
345 // NEW COMPOSITE NODES
346 // ========================================================================
347
349 "BT_RandomSelector",
350 "Random Selector",
351 "Selects a random child to execute (non-deterministic)",
354 "?", // Question mark
355 1, // Min 1 child
356 -1, // Unlimited children
357 true, // Allows decorator
358 {} // No parameters
359 });
360
362 "BT_ParallelThreshold",
363 "Parallel Threshold",
364 "Executes children in parallel with success/failure thresholds",
367 "≈", // Threshold symbol
368 2, // Min 2 children
369 -1, // Unlimited children
370 true, // Allows decorator
371 {"successThreshold", "failureThreshold"} // Number of children that must succeed/fail
372 });
373
374 // ========================================================================
375 // NEW DECORATOR NODES
376 // ========================================================================
377
379 "BT_Monitor",
380 "Monitor",
381 "Continuously re-evaluates condition during child execution",
384 "◉", // Circle symbol (monitoring)
385 1, // Exactly 1 child
386 1, // Exactly 1 child
387 false, // No decorator on decorator
388 {"checkInterval"} // Re-evaluation interval in milliseconds
389 });
390
391 // ========================================================================
392 // MESSAGE SENDING ACTION
393 // ========================================================================
394
396 "BT_SendMessage",
397 "Send Message",
398 "Emit event to EventQueue for other systems to receive",
401 "→", // Arrow (message send)
402 0, // No children
403 0, // No children
404 true, // Allows decorator
405 {"eventType", "domain", "param1", "param2", "state"} // Message parameters
406 });
407
408 // ========================================================================
409 // SUBGRAPH NODES (Behavior Composition & Reusability)
410 // ========================================================================
411
413 "BT_SubGraph",
414 "SubGraph",
415 "Encapsulates and executes another behavior tree (enables reusability and modularity)",
418 "◈", // Diamond symbol (encapsulation)
419 0, // No children (children come from loaded SubGraph)
420 0, // No children
421 true, // Allows decorator
422 {"subgraphPath", "inputParamCount", "outputParamCount", "inputBindingCount", "outputBindingCount"}
423 });
424
425 SYSTEM_LOG << "[BTNodeRegistry] Initialized " << m_nodeTypes.size() << " built-in node types" << std::endl;
426}
427
431
432const BTNodeTypeInfo* BTNodeRegistry::GetNodeTypeInfo(const std::string& typeName) const {
433 auto it = m_nodeTypes.find(typeName);
434 return (it != m_nodeTypes.end()) ? &it->second : nullptr;
435}
436
437std::vector<std::string> BTNodeRegistry::GetAllNodeTypes() const {
438 std::vector<std::string> result;
439 result.reserve(m_nodeTypes.size());
440
441 for (auto it = m_nodeTypes.begin(); it != m_nodeTypes.end(); ++it) {
442 result.push_back(it->first);
443 }
444
445 return result;
446}
447
448std::vector<std::string> BTNodeRegistry::GetNodeTypesByCategory(BTNodeCategory category) const {
449 std::vector<std::string> result;
450
451 for (auto it = m_nodeTypes.begin(); it != m_nodeTypes.end(); ++it) {
452 if (it->second.category == category) {
453 result.push_back(it->first);
454 }
455 }
456
457 return result;
458}
459
460bool BTNodeRegistry::IsValidNodeType(const std::string& typeName) const {
461 return m_nodeTypes.find(typeName) != m_nodeTypes.end();
462}
463
464bool BTNodeRegistry::CanHaveChildren(const std::string& typeName) const {
465 const BTNodeTypeInfo* info = GetNodeTypeInfo(typeName);
466 if (info == nullptr) {
467 return false;
468 }
469
470 return info->maxChildren != 0;
471}
472
473int BTNodeRegistry::GetMinChildren(const std::string& typeName) const {
474 const BTNodeTypeInfo* info = GetNodeTypeInfo(typeName);
475 if (info == nullptr) {
476 return 0;
477 }
478
479 return info->minChildren;
480}
481
482int BTNodeRegistry::GetMaxChildren(const std::string& typeName) const {
483 const BTNodeTypeInfo* info = GetNodeTypeInfo(typeName);
484 if (info == nullptr) {
485 return 0;
486 }
487
488 return info->maxChildren;
489}
490
491} // namespace AI
492} // namespace Olympe
Registry of all Behavior Tree node types for AIGraphPlugin_BT.
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Singleton registry for all BT node types.
bool CanHaveChildren(const std::string &typeName) const
Check if a node type can have children.
std::map< std::string, BTNodeTypeInfo > m_nodeTypes
void RegisterNodeType(const BTNodeTypeInfo &info)
Register a new node type.
int GetMaxChildren(const std::string &typeName) const
Get maximum number of children for a node type.
std::vector< std::string > GetNodeTypesByCategory(BTNodeCategory category) const
Get node types in a specific category.
const BTNodeTypeInfo * GetNodeTypeInfo(const std::string &typeName) const
Get metadata for a node type.
bool IsValidNodeType(const std::string &typeName) const
Check if a node type exists.
std::vector< std::string > GetAllNodeTypes() const
Get all registered node type names.
void InitializeBuiltInTypes()
Initialize all built-in BT node types.
static BTNodeRegistry & Get()
Get singleton instance.
int GetMinChildren(const std::string &typeName) const
Get minimum number of children for a node type.
constexpr ImU32 Composite_Primary
Definition ColorScheme.h:19
constexpr ImU32 EntryPoint_Primary
Definition ColorScheme.h:13
constexpr ImU32 SubGraph_Primary
Definition ColorScheme.h:49
constexpr ImU32 Inverter_Primary
Definition ColorScheme.h:37
constexpr ImU32 FlowControl_Primary
Definition ColorScheme.h:25
constexpr ImU32 Repeater_Primary
Definition ColorScheme.h:43
constexpr ImU32 Action_Primary
Definition ColorScheme.h:31
BTNodeCategory
Categories of behavior tree nodes.
@ Action
Leaf execution nodes (Wait, Move, Attack, etc.)
@ Composite
Flow control nodes (Selector, Sequence, Parallel)
@ Decorator
Modifiers (Inverter, Repeater, Cooldown, etc.)
@ Condition
Boolean checks (HasTarget, InRange, etc.)
uint32_t ConvertColorFormat(ImU32 imguiColor)
< Provides AssetID and INVALID_ASSET_ID
Metadata for a behavior tree node type.
#define SYSTEM_LOG