Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
Task_SetPosition.cpp
Go to the documentation of this file.
1/**
2 * @file Task_SetPosition.cpp
3 * @brief Atomic task: set entity position via ECS or LocalBlackboard.
4 * @author Olympe Engine
5 * @date 2026-03-08
6 *
7 * C++14 compliant - no C++17/20 features.
8 */
9
10#include "Task_SetPosition.h"
11#include "../../AtomicTaskRegistry.h"
12#include "../../LocalBlackboard.h"
13#include "../../TaskWorldFacade.h"
14#include "../../../system/system_utils.h"
15
16namespace Olympe {
17
19
21{
22 SYSTEM_LOG << "[Task_SetPosition] Abort()\n";
23}
24
26{
27 return TaskStatus::Failure; // requires context; use ExecuteWithContext
28}
29
31 const ParameterMap& params)
32{
33 // --- Resolve Target parameter ---
34 ::Vector target(0.0f, 0.0f, 0.0f);
35 {
36 auto it = params.find("Target");
37 if (it == params.end() || it->second.GetType() != VariableType::Vector)
38 {
39 SYSTEM_LOG << "[Task_SetPosition] Missing or invalid 'Target' parameter\n";
41 }
42 target = it->second.AsVector();
43 }
44
45 SYSTEM_LOG << "[Task_SetPosition] Entity " << ctx.Entity
46 << " -> (" << target.x << "," << target.y << ")\n";
47
48 // -----------------------------------------------------------------------
49 // World mode: write directly to PositionComponent when available
50 // -----------------------------------------------------------------------
51 if (ctx.ComponentFacade && ctx.ComponentFacade->Position)
52 {
53 ctx.ComponentFacade->Position->Position = target;
54 SYSTEM_LOG << "[Task_SetPosition] (WorldMode) Entity " << ctx.Entity
55 << " position set - Success\n";
57 }
58
59 // -----------------------------------------------------------------------
60 // Headless mode: write to "local:Position" in LocalBlackboard
61 // -----------------------------------------------------------------------
62 if (!ctx.LocalBB)
63 {
64 SYSTEM_LOG << "[Task_SetPosition] No LocalBlackboard in context\n";
66 }
67
68 ctx.LocalBB->SetValueScoped("local:Position", TaskValue(target));
69
70 SYSTEM_LOG << "[Task_SetPosition] Entity " << ctx.Entity
71 << " position written to LocalBB - Success\n";
73}
74
75REGISTER_ATOMIC_TASK(Task_SetPosition, "Task_SetPosition")
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 sets the entity's position.
std::unordered_map< std::string, TaskValue > ParameterMap
Convenience alias for the parameter map passed to Execute().
Definition IAtomicTask.h:67
C++14-compliant type-safe value container for task parameters.
Sets entity position via ECS or LocalBlackboard.
TaskStatus Execute(const ParameterMap &params) override
Executes the atomic task for one frame.
TaskStatus ExecuteWithContext(const AtomicTaskContext &ctx, const ParameterMap &params) override
Executes the atomic task for one frame with full runtime context.
void Abort() override
Aborts the task, releasing any in-progress state.
float y
Definition vector.h:25
float x
Definition vector.h:25
< Provides AssetID and INVALID_ASSET_ID
@ Vector
3-component vector (Vector from vector.h)
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