Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
Olympe::LocalBlackboard Class Reference

Simple map-based blackboard for task graph runtime state. More...

#include <LocalBlackboard.h>

+ Inheritance diagram for Olympe::LocalBlackboard:

Public Member Functions

 LocalBlackboard ()
 Default constructor.
 
void Initialize (const TaskGraphTemplate &tmpl)
 Initialises the blackboard from a template.
 
void Reset ()
 Resets all variables to their default values.
 
TaskValue GetValue (const std::string &varName) const
 Returns the current value of a variable.
 
void SetValue (const std::string &varName, const TaskValue &value)
 Sets the value of a variable.
 
bool HasVariable (const std::string &varName) const
 Returns true if a variable with the given name is registered.
 
std::vector< std::string > GetVariableNames () const
 Returns all registered variable names (useful for debugging / editor).
 
void Serialize (std::vector< uint8_t > &outBytes) const
 Serializes all variable names and typed values into a byte buffer.
 
void Deserialize (const std::vector< uint8_t > &inBytes)
 Restores variable values from a byte buffer produced by Serialize().
 
void InitializeFromEntries (const std::vector< BlackboardEntry > &entries)
 Initializes the blackboard from a vector of BlackboardEntry (ATS VS schema v4).
 
void SetValueScoped (const std::string &scopedKey, const TaskValue &value)
 Sets a value using a scoped key (prefix "local:" is stripped).
 
TaskValue GetValueScoped (const std::string &scopedKey) const
 Gets a value using a scoped key (prefix "local:" is stripped).
 

Private Attributes

std::unordered_map< std::string, TaskValuem_variables
 Current values for each registered variable.
 
std::unordered_map< std::string, TaskValuem_defaults
 Default (initial) values used by Reset().
 
std::unordered_map< std::string, VariableTypem_types
 Declared type of each variable (used for type validation in SetValue).
 

Detailed Description

Simple map-based blackboard for task graph runtime state.

Variables must be registered via Initialize() before use. SetValue() enforces type compatibility: the new value must match the declared type of the variable. Throws std::runtime_error on unknown variable or type mismatch.

Definition at line 37 of file LocalBlackboard.h.

Constructor & Destructor Documentation

◆ LocalBlackboard()

Olympe::LocalBlackboard::LocalBlackboard ( )

Default constructor.

Blackboard is empty until Initialize() is called.

Definition at line 24 of file LocalBlackboard.cpp.

Member Function Documentation

◆ Deserialize()

void Olympe::LocalBlackboard::Deserialize ( const std::vector< uint8_t > &  inBytes)

Restores variable values from a byte buffer produced by Serialize().

The blackboard schema (m_types) must already be initialised via Initialize() before calling this method. Unknown variable names and type-mismatched entries are skipped with a warning log. The buffer is consumed in one pass; parsing stops on any truncation error.

Parameters
inBytesByte buffer previously produced by Serialize().

Definition at line 213 of file LocalBlackboard.cpp.

References Olympe::Bool, Olympe::EntityID, Olympe::Float, GetComponentTypeID_Static(), Olympe::Int, m_types, m_variables, Olympe::String, SYSTEM_LOG, and Olympe::Vector.

+ Here is the call graph for this function:

◆ GetValue()

TaskValue Olympe::LocalBlackboard::GetValue ( const std::string &  varName) const

Returns the current value of a variable.

Parameters
varNameName of the variable.
Exceptions
std::runtime_errorif the variable is not registered.

Definition at line 64 of file LocalBlackboard.cpp.

References GetComponentTypeID_Static(), and m_variables.

Referenced by Olympe::EntityBlackboard::GetLocalValue(), GetValueScoped(), and Olympe::InspectorPanel::RenderDebugBlackboard().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetValueScoped()

TaskValue Olympe::LocalBlackboard::GetValueScoped ( const std::string &  scopedKey) const

Gets a value using a scoped key (prefix "local:" is stripped).

Forwards "global:" scope to GlobalBlackboard singleton.

Parameters
scopedKeyKey with optional prefix.
Returns
Stored value or default TaskValue() if not found.

Definition at line 411 of file LocalBlackboard.cpp.

References Olympe::GlobalBlackboard::Get(), GetComponentTypeID_Static(), GetValue(), and Olympe::GlobalBlackboard::GetVar().

+ Here is the call graph for this function:

◆ GetVariableNames()

std::vector< std::string > Olympe::LocalBlackboard::GetVariableNames ( ) const

Returns all registered variable names (useful for debugging / editor).

Definition at line 99 of file LocalBlackboard.cpp.

References GetComponentTypeID_Static(), and m_variables.

Referenced by Olympe::InspectorPanel::RenderDebugBlackboard(), and Olympe::DebugPanel::RenderWatchVariables().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HasVariable()

bool Olympe::LocalBlackboard::HasVariable ( const std::string &  varName) const

Returns true if a variable with the given name is registered.

Parameters
varNameName of the variable.

Definition at line 94 of file LocalBlackboard.cpp.

References GetComponentTypeID_Static(), and m_variables.

Referenced by Olympe::EntityBlackboard::HasLocalVariable().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Initialize()

void Olympe::LocalBlackboard::Initialize ( const TaskGraphTemplate tmpl)

Initialises the blackboard from a template.

Registers all local variables defined in tmpl, copying their types and default values. Any previous state is discarded.

Parameters
tmplThe TaskGraphTemplate that owns this blackboard's schema.

Definition at line 32 of file LocalBlackboard.cpp.

References Olympe::VariableDefinition::DefaultValue, GetComponentTypeID_Static(), m_defaults, m_types, m_variables, Olympe::VariableDefinition::Name, SYSTEM_LOG, and Olympe::VariableDefinition::Type.

Referenced by Olympe::TaskSystem::ExecuteAtomicTask(), and Olympe::EntityBlackboard::Initialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ InitializeFromEntries()

void Olympe::LocalBlackboard::InitializeFromEntries ( const std::vector< BlackboardEntry > &  entries)

Initializes the blackboard from a vector of BlackboardEntry (ATS VS schema v4).

Companion to Initialize(const TaskGraphTemplate&) for VS graphs that use the BlackboardEntry schema instead of VariableDefinition.

Parameters
entriesBlackboard entries from TaskGraphTemplate::Blackboard.

Definition at line 342 of file LocalBlackboard.cpp.

References Olympe::BlackboardEntry::Default, GetComponentTypeID_Static(), m_defaults, m_types, m_variables, and SYSTEM_LOG.

Referenced by Olympe::TaskSystem::ExecuteVSFrame(), and Olympe::VSGraphExecutor::HandleSubGraph().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Reset()

void Olympe::LocalBlackboard::Reset ( )

Resets all variables to their default values.

Does not change the set of registered variables.

Definition at line 50 of file LocalBlackboard.cpp.

References GetComponentTypeID_Static(), m_defaults, m_variables, and SYSTEM_LOG.

Referenced by Olympe::EntityBlackboard::Reset().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Serialize()

void Olympe::LocalBlackboard::Serialize ( std::vector< uint8_t > &  outBytes) const

Serializes all variable names and typed values into a byte buffer.

Binary format (little-endian): uint32_t count - number of variables for each variable: uint32_t nameLen - length of name in bytes <nameLen bytes> - variable name (UTF-8) uint8_t type - VariableType tag

: Bool -> uint8_t (0 = false, 1 = true) Int -> int32_t Float -> float Vector -> float x, float y, float z EntityID-> uint64_t String -> uint32_t len, <len bytes>

Parameters
outBytesOutput byte buffer (cleared before writing).

Definition at line 139 of file LocalBlackboard.cpp.

References Olympe::Bool, Olympe::EntityID, Olympe::Float, GetComponentTypeID_Static(), Olympe::Int, m_variables, Olympe::String, SYSTEM_LOG, and Olympe::Vector.

+ Here is the call graph for this function:

◆ SetValue()

void Olympe::LocalBlackboard::SetValue ( const std::string &  varName,
const TaskValue value 
)

Sets the value of a variable.

The type of value must match the declared type of the variable.

Parameters
varNameName of the variable.
valueNew value.
Exceptions
std::runtime_errorif the variable is not registered.
std::runtime_errorif the type of value does not match the declared type of the variable.

Definition at line 74 of file LocalBlackboard.cpp.

References GetComponentTypeID_Static(), Olympe::TaskValue::GetType(), m_types, and m_variables.

Referenced by Olympe::EntityBlackboard::SetLocalValue(), and SetValueScoped().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetValueScoped()

void Olympe::LocalBlackboard::SetValueScoped ( const std::string &  scopedKey,
const TaskValue value 
)

Sets a value using a scoped key (prefix "local:" is stripped).

Forwards "global:" scope to GlobalBlackboard singleton.

Parameters
scopedKeyKey with optional "local:" or "global:" prefix.
valueValue to set.

Definition at line 371 of file LocalBlackboard.cpp.

References Olympe::GlobalBlackboard::Get(), GetComponentTypeID_Static(), SetValue(), Olympe::GlobalBlackboard::SetVar(), and SYSTEM_LOG.

+ Here is the call graph for this function:

Member Data Documentation

◆ m_defaults

std::unordered_map<std::string, TaskValue> Olympe::LocalBlackboard::m_defaults
private

Default (initial) values used by Reset().

Definition at line 178 of file LocalBlackboard.h.

Referenced by Initialize(), InitializeFromEntries(), and Reset().

◆ m_types

std::unordered_map<std::string, VariableType> Olympe::LocalBlackboard::m_types
private

Declared type of each variable (used for type validation in SetValue).

Definition at line 181 of file LocalBlackboard.h.

Referenced by Deserialize(), Initialize(), InitializeFromEntries(), and SetValue().

◆ m_variables

std::unordered_map<std::string, TaskValue> Olympe::LocalBlackboard::m_variables
private

Current values for each registered variable.

Definition at line 175 of file LocalBlackboard.h.

Referenced by Deserialize(), GetValue(), GetVariableNames(), HasVariable(), Initialize(), InitializeFromEntries(), Reset(), Serialize(), and SetValue().


The documentation for this class was generated from the following files: