Olympe Engine
2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
Source
TaskSystem
AtomicTasks
System
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
16
#include "
Task_GetWorldInstance.h
"
17
#include "../../AtomicTaskRegistry.h"
18
#include "../../LocalBlackboard.h"
19
#include "../../../system/system_utils.h"
20
21
namespace
Olympe
{
22
23
Task_GetWorldInstance::Task_GetWorldInstance
() {}
24
25
void
Task_GetWorldInstance::Abort
()
26
{
27
SYSTEM_LOG
<<
"[Task_GetWorldInstance] Abort()\n"
;
28
}
29
30
TaskStatus
Task_GetWorldInstance::Execute
(
const
ParameterMap
&
/*params*/
)
31
{
32
return
TaskStatus::Failure
;
// requires context; use ExecuteWithContext
33
}
34
35
TaskStatus
Task_GetWorldInstance::ExecuteWithContext
(
const
AtomicTaskContext
&
ctx
,
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"
;
45
return
TaskStatus::Failure
;
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"
;
55
return
TaskStatus::Failure
;
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.
70
const
EntityID
resolvedID
=
INVALID_ENTITY_ID
;
71
72
SYSTEM_LOG
<<
"[Task_GetWorldInstance] Entity "
<<
ctx
.Entity
73
<<
": World entity lookup for '"
<<
instanceName
74
<<
"' not yet wired (stub) — returning Failure\n"
;
75
76
if
(
resolvedID
==
INVALID_ENTITY_ID
)
77
{
78
return
TaskStatus::Failure
;
79
}
80
81
if
(!
ctx
.LocalBB)
82
{
83
SYSTEM_LOG
<<
"[Task_GetWorldInstance] No LocalBlackboard in context\n"
;
84
return
TaskStatus::Failure
;
85
}
86
87
ctx
.LocalBB->SetValueScoped(
"local:TargetInstance"
,
TaskValue
(
resolvedID
));
88
89
SYSTEM_LOG
<<
"[Task_GetWorldInstance] Entity "
<<
ctx
.Entity
90
<<
" -> TargetInstance="
<<
resolvedID
<<
" - Success\n"
;
91
return
TaskStatus::Success
;
92
}
93
94
REGISTER_ATOMIC_TASK
(
Task_GetWorldInstance
,
"Task_GetWorldInstance"
)
95
96
}
// namespace Olympe
REGISTER_ATOMIC_TASK
#define REGISTER_ATOMIC_TASK(ClassName, Id)
Registers a factory for ClassName under Id at static init time.
Definition
AtomicTaskRegistry.h:119
GetComponentTypeID_Static
ComponentTypeID GetComponentTypeID_Static()
Definition
ECS_Entity.h:56
EntityID
std::uint64_t EntityID
Definition
ECS_Entity.h:21
INVALID_ENTITY_ID
const EntityID INVALID_ENTITY_ID
Definition
ECS_Entity.h:23
Task_GetWorldInstance.h
Atomic task that resolves a named World entity and stores its ID.
Olympe::IAtomicTask::ParameterMap
std::unordered_map< std::string, TaskValue > ParameterMap
Convenience alias for the parameter map passed to Execute().
Definition
IAtomicTask.h:67
Olympe::TaskValue
C++14-compliant type-safe value container for task parameters.
Definition
TaskGraphTypes.h:181
Olympe::Task_GetWorldInstance
Finds an entity by name in World and stores its EntityID in LocalBB.
Definition
Task_GetWorldInstance.h:33
Olympe::Task_GetWorldInstance::Execute
TaskStatus Execute(const ParameterMap ¶ms) override
Executes the atomic task for one frame.
Definition
Task_GetWorldInstance.cpp:30
Olympe::Task_GetWorldInstance::Task_GetWorldInstance
Task_GetWorldInstance()
Definition
Task_GetWorldInstance.cpp:23
Olympe::Task_GetWorldInstance::ExecuteWithContext
TaskStatus ExecuteWithContext(const AtomicTaskContext &ctx, const ParameterMap ¶ms) override
Executes the atomic task for one frame with full runtime context.
Definition
Task_GetWorldInstance.cpp:35
Olympe::Task_GetWorldInstance::Abort
void Abort() override
Aborts the task, releasing any in-progress state.
Definition
Task_GetWorldInstance.cpp:25
Olympe
< Provides AssetID and INVALID_ASSET_ID
Definition
BTEditorCommand.cpp:16
Olympe::VariableType::String
@ String
std::string
Olympe::TaskStatus
TaskStatus
Result code returned by IAtomicTask::Execute().
Definition
IAtomicTask.h:38
Olympe::TaskStatus::Success
@ Success
Task completed successfully.
Olympe::TaskStatus::Failure
@ Failure
Task failed.
Olympe::AtomicTaskContext
Lightweight context bundle passed to IAtomicTask::ExecuteWithContext().
Definition
AtomicTaskContext.h:36
SYSTEM_LOG
#define SYSTEM_LOG
Definition
system_utils.h:23
Generated on Mon Apr 13 2026 08:15:20 for Olympe Engine by
1.9.8