Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
Task_SetVariable.cpp
Go to the documentation of this file.
1/**
2 * @file Task_SetVariable.cpp
3 * @brief Atomic task: write a value into the LocalBlackboard.
4 * @author Olympe Engine
5 * @date 2026-02-23
6 *
7 * C++14 compliant - no C++17/20 features.
8 */
9
10#include "Task_SetVariable.h"
11#include "../../AtomicTaskRegistry.h"
12#include "../../LocalBlackboard.h"
13#include "../../../system/system_utils.h"
14
15namespace Olympe {
16
18
20{
21 SYSTEM_LOG << "[Task_SetVariable] Abort()\n";
22}
23
25{
26 return TaskStatus::Failure; // requires context; use ExecuteWithContext
27}
28
30 const ParameterMap& params)
31{
32 // --- Resolve VarName parameter ---
33 std::string varName;
34 {
35 auto it = params.find("VarName");
36 if (it == params.end() || it->second.GetType() != VariableType::String)
37 {
38 SYSTEM_LOG << "[Task_SetVariable] Missing or invalid 'VarName' parameter\n";
40 }
41 varName = it->second.AsString();
42 }
43
44 // --- Resolve Value parameter ---
45 auto valueIt = params.find("Value");
46 if (valueIt == params.end() || valueIt->second.IsNone())
47 {
48 SYSTEM_LOG << "[Task_SetVariable] Missing 'Value' parameter\n";
50 }
51
52 // --- Write to LocalBlackboard ---
53 if (!ctx.LocalBB)
54 {
55 SYSTEM_LOG << "[Task_SetVariable] No LocalBlackboard in context\n";
57 }
58
59 try
60 {
61 ctx.LocalBB->SetValue(varName, valueIt->second);
62 }
63 catch (const std::exception& e)
64 {
65 SYSTEM_LOG << "[Task_SetVariable] Failed to set '" << varName
66 << "': " << e.what() << "\n";
68 }
69
70 SYSTEM_LOG << "[Task_SetVariable] Entity " << ctx.Entity
71 << " set '" << varName << "' - Success\n";
73}
74
75REGISTER_ATOMIC_TASK(Task_SetVariable, "Task_SetVariable")
76
77} // namespace Olympe
#define REGISTER_ATOMIC_TASK(ClassName, Id)
Registers a factory for ClassName under Id at static init time.
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Atomic task that writes a value into the LocalBlackboard.
std::unordered_map< std::string, TaskValue > ParameterMap
Convenience alias for the parameter map passed to Execute().
Definition IAtomicTask.h:67
Atomic task that writes a value into the LocalBlackboard.
TaskStatus Execute(const ParameterMap &params) override
Executes the atomic task for one frame.
void Abort() override
Aborts the task, releasing any in-progress state.
TaskStatus ExecuteWithContext(const AtomicTaskContext &ctx, const ParameterMap &params) override
Executes the atomic task for one frame with full runtime context.
< Provides AssetID and INVALID_ASSET_ID
@ String
std::string
TaskStatus
Result code returned by IAtomicTask::Execute().
Definition IAtomicTask.h:38
@ Success
Task completed successfully.
@ Failure
Task failed.
Lightweight context bundle passed to IAtomicTask::ExecuteWithContext().
#define SYSTEM_LOG