10#include "../NodeGraphCore/GlobalBlackboard.h"
16#include "../system/system_utils.h"
38 for (
size_t i = 0;
i <
tmpl.LocalVariables.size(); ++
i)
46 SYSTEM_LOG <<
"[LocalBlackboard] Initialized with " <<
tmpl.LocalVariables.size()
47 <<
" variables from template '" <<
tmpl.Name <<
"'" << std::endl;
57 SYSTEM_LOG <<
"[LocalBlackboard] Reset to defaults" << std::endl;
69 throw std::runtime_error(
"[LocalBlackboard] Unknown variable: " +
varName);
79 throw std::runtime_error(
"[LocalBlackboard] Unknown variable: " +
varName);
84 throw std::runtime_error(
"[LocalBlackboard] Type mismatch for variable: " +
varName);
101 std::vector<std::string>
names;
127 if (
pos +
n >
buf.size())
return false;
148 const std::string& name =
it->first;
158 switch (
val.GetType())
174 float fv =
val.AsFloat();
194 const std::string&
sv =
val.AsString();
205 SYSTEM_LOG <<
"[LocalBlackboard] Serialized " <<
count <<
" variables ("
220 SYSTEM_LOG <<
"[LocalBlackboard] Deserialize: buffer too short for count\n";
230 SYSTEM_LOG <<
"[LocalBlackboard] Deserialize: buffer truncated at entry " <<
i <<
"\n";
235 SYSTEM_LOG <<
"[LocalBlackboard] Deserialize: name bytes truncated at entry " <<
i <<
"\n";
245 SYSTEM_LOG <<
"[LocalBlackboard] Deserialize: buffer truncated at type for '" << name <<
"'\n";
279 float x = 0.0f, y = 0.0f, z = 0.0f;
307 SYSTEM_LOG <<
"[LocalBlackboard] Deserialize: unknown type tag "
308 <<
static_cast<int>(
typeTag) <<
" for '" << name <<
"' - aborting\n";
314 SYSTEM_LOG <<
"[LocalBlackboard] Deserialize: buffer truncated while reading value for '"
323 SYSTEM_LOG <<
"[LocalBlackboard] Deserialize: unknown variable '" << name <<
"' - skipping\n";
328 SYSTEM_LOG <<
"[LocalBlackboard] Deserialize: type mismatch for '" << name <<
"' - skipping\n";
335 SYSTEM_LOG <<
"[LocalBlackboard] Deserialized " <<
count <<
" entries\n";
363 SYSTEM_LOG <<
"[LocalBlackboard] InitializeFromEntries: registered "
383 catch (
const std::exception&
e)
385 SYSTEM_LOG <<
"[LocalBlackboard] SetValueScoped: " <<
e.what() <<
"\n";
400 catch (
const std::exception&
e)
402 SYSTEM_LOG <<
"[LocalBlackboard] SetValueScoped: " <<
e.what() <<
"\n";
ComponentTypeID GetComponentTypeID_Static()
Runtime key-value store for task graph variables.
Immutable asset structure shared by all task graph runners.
void SetVar(const std::string &key, const TaskValue &value)
Writes or creates a variable.
static GlobalBlackboard & Get()
Returns the singleton instance.
TaskValue GetVar(const std::string &key) const
Reads a variable by key.
void Serialize(std::vector< uint8_t > &outBytes) const
Serializes all variable names and typed values into a byte buffer.
std::unordered_map< std::string, VariableType > m_types
Declared type of each variable (used for type validation in SetValue).
TaskValue GetValueScoped(const std::string &scopedKey) const
Gets a value using a scoped key (prefix "local:" is stripped).
void Deserialize(const std::vector< uint8_t > &inBytes)
Restores variable values from a byte buffer produced by Serialize().
void Reset()
Resets all variables to their default values.
void Initialize(const TaskGraphTemplate &tmpl)
Initialises the blackboard from a template.
std::unordered_map< std::string, TaskValue > m_defaults
Default (initial) values used by Reset().
bool HasVariable(const std::string &varName) const
Returns true if a variable with the given name is registered.
void SetValue(const std::string &varName, const TaskValue &value)
Sets the value of a variable.
TaskValue GetValue(const std::string &varName) const
Returns the current value of a variable.
void SetValueScoped(const std::string &scopedKey, const TaskValue &value)
Sets a value using a scoped key (prefix "local:" is stripped).
std::unordered_map< std::string, TaskValue > m_variables
Current values for each registered variable.
std::vector< std::string > GetVariableNames() const
Returns all registered variable names (useful for debugging / editor).
LocalBlackboard()
Default constructor.
void InitializeFromEntries(const std::vector< BlackboardEntry > &entries)
Initializes the blackboard from a vector of BlackboardEntry (ATS VS schema v4).
Immutable, shareable task graph asset.
C++14-compliant type-safe value container for task parameters.
VariableType GetType() const
Returns the VariableType tag of the stored value.
static void WriteBytes(std::vector< uint8_t > &buf, const T &value)
static bool ReadBytes(const std::vector< uint8_t > &buf, size_t &pos, void *dst, size_t n)
< Provides AssetID and INVALID_ASSET_ID
VariableType
Type tags used by TaskValue to identify stored data.
@ Int
32-bit signed integer
@ Float
Single-precision float.
@ Vector
3-component vector (Vector from vector.h)
@ EntityID
Entity identifier (uint64_t)
Single entry in the graph's declared blackboard schema (local or global).
Declares a single variable in the task graph's blackboard schema.
std::string Name
Variable name (must be unique within the template)
VariableType Type
Declared type.
TaskValue DefaultValue
Initial value (used by LocalBlackboard::Reset)