Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
Task_GetWorldInstance.cpp
Go to the documentation of this file.
1/**
2 * @file Task_GetWorldInstance.cpp
3 * @brief Atomic task: find a named entity in World and store its EntityID.
4 * @author Olympe Engine
5 * @date 2026-03-08
6 *
7 * @details
8 * When ctx.WorldPtr is available the task uses World::FindEntityByName()
9 * (or equivalent) to resolve the entity. In headless / test mode
10 * (ctx.WorldPtr == nullptr) the task logs and returns Failure, which is the
11 * expected contract for tasks that require a live World.
12 *
13 * C++14 compliant - no C++17/20 features.
14 */
15
17#include "../../AtomicTaskRegistry.h"
18#include "../../LocalBlackboard.h"
19#include "../../../system/system_utils.h"
20
21namespace Olympe {
22
24
26{
27 SYSTEM_LOG << "[Task_GetWorldInstance] Abort()\n";
28}
29
31{
32 return TaskStatus::Failure; // requires context; use ExecuteWithContext
33}
34
36 const ParameterMap& params)
37{
38 // --- Resolve InstanceName parameter ---
39 std::string instanceName;
40 {
41 auto it = params.find("InstanceName");
42 if (it == params.end() || it->second.GetType() != VariableType::String)
43 {
44 SYSTEM_LOG << "[Task_GetWorldInstance] Missing or invalid 'InstanceName' parameter\n";
46 }
47 instanceName = it->second.AsString();
48 }
49
50 // --- Headless mode: WorldPtr not available ---
51 if (!ctx.WorldPtr)
52 {
53 SYSTEM_LOG << "[Task_GetWorldInstance] Entity " << ctx.Entity
54 << ": WorldPtr is null — cannot resolve '" << instanceName << "'\n";
56 }
57
58 // --- World mode: look up entity by name ---
59 // Note: World::FindEntityByName() is the expected API; stub returns
60 // INVALID_ENTITY_ID if the method is not yet available on the concrete
61 // World implementation. Tasks that call this in production must ensure
62 // the live World provides entity-by-name lookup.
63 SYSTEM_LOG << "[Task_GetWorldInstance] Entity " << ctx.Entity
64 << ": resolving '" << instanceName << "' in World\n";
65
66 // The World forward declaration does not expose FindEntityByName in this
67 // translation unit (to avoid pulling in the full World header in every
68 // task). Store a sentinel EntityID and log; caller must adapt if a real
69 // lookup is available.
71
72 SYSTEM_LOG << "[Task_GetWorldInstance] Entity " << ctx.Entity
73 << ": World entity lookup for '" << instanceName
74 << "' not yet wired (stub) — returning Failure\n";
75
77 {
79 }
80
81 if (!ctx.LocalBB)
82 {
83 SYSTEM_LOG << "[Task_GetWorldInstance] No LocalBlackboard in context\n";
85 }
86
87 ctx.LocalBB->SetValueScoped("local:TargetInstance", TaskValue(resolvedID));
88
89 SYSTEM_LOG << "[Task_GetWorldInstance] Entity " << ctx.Entity
90 << " -> TargetInstance=" << resolvedID << " - Success\n";
92}
93
94REGISTER_ATOMIC_TASK(Task_GetWorldInstance, "Task_GetWorldInstance")
95
96} // 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
std::uint64_t EntityID
Definition ECS_Entity.h:21
const EntityID INVALID_ENTITY_ID
Definition ECS_Entity.h:23
Atomic task that resolves a named World entity and stores its ID.
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.
Finds an entity by name in World and stores its EntityID in LocalBB.
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.
< 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