Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
BlackboardSystem.h
Go to the documentation of this file.
1/**
2 * @file BlackboardSystem.h
3 * @brief Blackboard system for shared graph variables (Phase 2.1)
4 * @author Olympe Engine
5 * @date 2026-02-19
6 *
7 * @details
8 * Provides a serializable, type-aware container of named variables that can
9 * be shared across AI graph nodes. Supports Int, Float, Bool, String, Vector3.
10 */
11
12#pragma once
13
14#include "../json_helper.h"
15#include <string>
16#include <map>
17
18namespace Olympe {
19namespace NodeGraph {
20
21// ============================================================================
22// Blackboard types
23// ============================================================================
24
25/**
26 * @enum BlackboardType
27 * @brief Supported variable types in the blackboard
28 */
29enum class BlackboardType : uint8_t {
30 Int = 0,
31 Float,
32 Bool,
33 String,
35};
36
37/**
38 * @struct BlackboardValue
39 * @brief Stores a typed value for a blackboard entry.
40 *
41 * The active field is determined by the `type` member.
42 */
44 BlackboardType type = BlackboardType::Int;
45 int intValue = 0;
46 float floatValue = 0.0f;
47 bool boolValue = false;
48 std::string stringValue;
49 float vec3X = 0.0f;
50 float vec3Y = 0.0f;
51 float vec3Z = 0.0f;
52};
53
54// ============================================================================
55// BlackboardSystem
56// ============================================================================
57
58/**
59 * @class BlackboardSystem
60 * @brief Manages named blackboard variables for a graph
61 */
63public:
64 BlackboardSystem() = default;
65 ~BlackboardSystem() = default;
66
67 /**
68 * @brief Check if an entry exists
69 * @param name Variable name
70 */
71 bool HasEntry(const std::string& name) const;
72
73 /**
74 * @brief Get a const pointer to an entry
75 * @param name Variable name
76 * @return Const pointer or nullptr if not found
77 */
78 const BlackboardValue* GetEntry(const std::string& name) const;
79
80 /**
81 * @brief Create a new entry
82 * @param name Variable name (must be unique)
83 * @param type Variable type
84 * @param initialValue Initial value
85 * @return true if created, false if name already exists
86 */
87 bool CreateEntry(const std::string& name, BlackboardType type,
89
90 /**
91 * @brief Remove an entry
92 * @param name Variable name
93 * @return true if removed, false if not found
94 */
95 bool RemoveEntry(const std::string& name);
96
97 /**
98 * @brief Rename an entry
99 * @param oldName Current variable name
100 * @param newName New variable name
101 * @return true if renamed, false on error (not found, or newName already used)
102 */
103 bool RenameEntry(const std::string& oldName, const std::string& newName);
104
105 /**
106 * @brief Update the value of an existing entry
107 * @param name Variable name
108 * @param value New value (type must match the entry's type)
109 * @return true if updated, false if not found or type mismatch
110 */
111 bool SetValue(const std::string& name, const BlackboardValue& value);
112
113 /**
114 * @brief Get all entries (for UI / serialization)
115 * @return Const reference to internal map
116 */
117 const std::map<std::string, BlackboardValue>& GetAll() const;
118
119 /**
120 * @brief Serialize blackboard to JSON
121 * @return JSON array of variable objects
122 */
123 json ToJson() const;
124
125 /**
126 * @brief Deserialize blackboard from JSON
127 * @param j JSON array produced by ToJson()
128 */
129 void FromJson(const json& j);
130
131private:
132 std::map<std::string, BlackboardValue> m_entries;
133
134 /**
135 * @brief Convert a BlackboardType to its string representation
136 */
137 static std::string TypeToString(BlackboardType t);
138
139 /**
140 * @brief Convert a string to BlackboardType (returns Int on unknown)
141 */
142 static BlackboardType StringToType(const std::string& s);
143};
144
145} // namespace NodeGraph
146} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Manages named blackboard variables for a graph.
bool CreateEntry(const std::string &name, BlackboardType type, const BlackboardValue &initialValue)
Create a new entry.
bool RenameEntry(const std::string &oldName, const std::string &newName)
Rename an entry.
bool RemoveEntry(const std::string &name)
Remove an entry.
const std::map< std::string, BlackboardValue > & GetAll() const
Get all entries (for UI / serialization)
bool SetValue(const std::string &name, const BlackboardValue &value)
Update the value of an existing entry.
std::map< std::string, BlackboardValue > m_entries
const BlackboardValue * GetEntry(const std::string &name) const
Get a const pointer to an entry.
static BlackboardType StringToType(const std::string &s)
Convert a string to BlackboardType (returns Int on unknown)
json ToJson() const
Serialize blackboard to JSON.
void FromJson(const json &j)
Deserialize blackboard from JSON.
bool HasEntry(const std::string &name) const
Check if an entry exists.
static std::string TypeToString(BlackboardType t)
Convert a BlackboardType to its string representation.
BlackboardType
Supported variable types in the blackboard.
< Provides AssetID and INVALID_ASSET_ID
nlohmann::json json
@ Int
32-bit signed integer
Stores a typed value for a blackboard entry.