Olympe Engine
2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
Source
TaskSystem
IAtomicTask.h
Go to the documentation of this file.
1
/**
2
* @file IAtomicTask.h
3
* @brief Interface for atomic tasks in the Atomic Task System.
4
* @author Olympe Engine
5
* @date 2026-02-22
6
*
7
* @details
8
* IAtomicTask is the base interface that every concrete atomic task must
9
* implement. An atomic task receives a parameter map (string -> TaskValue)
10
* at Execute() time and returns a TaskStatus indicating success, failure,
11
* or running (for multi-frame tasks). If the system needs to interrupt
12
* a running task it calls Abort() so the task can clean up any state.
13
*
14
* ### Backwards-compatible context API (Phase 3.0)
15
* ExecuteWithContext() is a non-breaking addition that provides richer
16
* runtime context (World*, LocalBlackboard*, EntityID, dt, StateTimer).
17
* The default implementation forwards to the legacy Execute(params) so
18
* existing tasks continue to work without any changes. New tasks may
19
* override ExecuteWithContext() instead of Execute() to access the context.
20
*
21
* C++14 compliant - no C++17/20 features.
22
*/
23
24
#pragma once
25
26
#include <string>
27
#include <unordered_map>
28
29
#include "
TaskGraphTypes.h
"
30
#include "
AtomicTaskContext.h
"
31
32
namespace
Olympe
{
33
34
/**
35
* @enum TaskStatus
36
* @brief Result code returned by IAtomicTask::Execute().
37
*/
38
enum class
TaskStatus
:
uint8_t
{
39
Success
,
///< Task completed successfully
40
Failure
,
///< Task failed
41
Running
///< Task is still in progress (multi-frame tasks)
42
};
43
44
/**
45
* @class IAtomicTask
46
* @brief Abstract interface for a single atomic unit of work.
47
*
48
* @details
49
* Implement Execute() to perform the task logic and Abort() to release
50
* any resources or state when the task is interrupted before completion.
51
* Tasks receive their parameters as a map of TaskValue instances keyed
52
* by parameter name.
53
*
54
* Example:
55
* @code
56
* class Task_MyTask : public IAtomicTask {
57
* public:
58
* TaskStatus Execute(const ParameterMap& params) override { ... }
59
* void Abort() override { ... }
60
* };
61
* @endcode
62
*/
63
class
IAtomicTask
{
64
public
:
65
66
/// Convenience alias for the parameter map passed to Execute().
67
using
ParameterMap
= std::unordered_map<std::string, TaskValue>;
68
69
virtual
~IAtomicTask
() =
default
;
70
71
/**
72
* @brief Executes the atomic task for one frame.
73
*
74
* @param params Named parameters provided by the task graph node.
75
* @return TaskStatus::Success, Failure, or Running.
76
* Returning Running causes the task to be ticked again next frame.
77
*/
78
virtual
TaskStatus
Execute
(
const
ParameterMap
&
params
) = 0;
79
80
/**
81
* @brief Executes the atomic task for one frame with full runtime context.
82
*
83
* @details
84
* New tasks should override this method to access the richer context
85
* (World pointer, LocalBlackboard, EntityID, dt, StateTimer). The
86
* default implementation simply forwards to Execute(params) so all
87
* existing tasks remain compatible without any changes.
88
*
89
* @param ctx Runtime context for this tick (Entity, World*, LocalBB, dt, StateTimer).
90
* @param params Named parameters provided by the task graph node.
91
* @return TaskStatus::Success, Failure, or Running.
92
*/
93
virtual
TaskStatus
ExecuteWithContext
(
const
AtomicTaskContext
&
ctx
,
94
const
ParameterMap
&
params
)
95
{
96
(
void
)
ctx
;
// suppress unused-parameter warning for legacy tasks
97
return
Execute
(
params
);
98
}
99
100
/**
101
* @brief Aborts the task, releasing any in-progress state.
102
*
103
* Called by the TaskSystem when execution is interrupted (e.g. a parent
104
* node is aborted or a new graph is bound while a task is Running).
105
* Concrete tasks must implement this to clean up timers, reservations,
106
* animations, or any other side-effects started in Execute().
107
*/
108
virtual
void
Abort
() = 0;
109
};
110
111
}
// namespace Olympe
AtomicTaskContext.h
Runtime context passed to IAtomicTask::ExecuteWithContext().
GetComponentTypeID_Static
ComponentTypeID GetComponentTypeID_Static()
Definition
ECS_Entity.h:56
TaskGraphTypes.h
Core enumerations and TaskValue type-safe variant for the Atomic Task System.
Olympe::IAtomicTask
Abstract interface for a single atomic unit of work.
Definition
IAtomicTask.h:63
Olympe::IAtomicTask::Abort
virtual void Abort()=0
Aborts the task, releasing any in-progress state.
Olympe::IAtomicTask::ExecuteWithContext
virtual TaskStatus ExecuteWithContext(const AtomicTaskContext &ctx, const ParameterMap ¶ms)
Executes the atomic task for one frame with full runtime context.
Definition
IAtomicTask.h:93
Olympe::IAtomicTask::ParameterMap
std::unordered_map< std::string, TaskValue > ParameterMap
Convenience alias for the parameter map passed to Execute().
Definition
IAtomicTask.h:67
Olympe::IAtomicTask::Execute
virtual TaskStatus Execute(const ParameterMap ¶ms)=0
Executes the atomic task for one frame.
Olympe::IAtomicTask::~IAtomicTask
virtual ~IAtomicTask()=default
Olympe
< Provides AssetID and INVALID_ASSET_ID
Definition
BTEditorCommand.cpp:16
Olympe::DataPinEvalStatus::Success
@ Success
Evaluation completed successfully.
Olympe::TaskStatus
TaskStatus
Result code returned by IAtomicTask::Execute().
Definition
IAtomicTask.h:38
Olympe::TaskStatus::Failure
@ Failure
Task failed.
Olympe::DebugState::Running
@ Running
Normal execution.
Olympe::AtomicTaskContext
Lightweight context bundle passed to IAtomicTask::ExecuteWithContext().
Definition
AtomicTaskContext.h:36
Generated on Mon Apr 13 2026 08:15:20 for Olympe Engine by
1.9.8