Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
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
32namespace Olympe {
33
34/**
35 * @enum TaskStatus
36 * @brief Result code returned by IAtomicTask::Execute().
37 */
38enum 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 */
64public:
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 */
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 */
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
Runtime context passed to IAtomicTask::ExecuteWithContext().
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Core enumerations and TaskValue type-safe variant for the Atomic Task System.
Abstract interface for a single atomic unit of work.
Definition IAtomicTask.h:63
virtual void Abort()=0
Aborts the task, releasing any in-progress state.
virtual TaskStatus ExecuteWithContext(const AtomicTaskContext &ctx, const ParameterMap &params)
Executes the atomic task for one frame with full runtime context.
Definition IAtomicTask.h:93
std::unordered_map< std::string, TaskValue > ParameterMap
Convenience alias for the parameter map passed to Execute().
Definition IAtomicTask.h:67
virtual TaskStatus Execute(const ParameterMap &params)=0
Executes the atomic task for one frame.
virtual ~IAtomicTask()=default
< Provides AssetID and INVALID_ASSET_ID
@ Success
Evaluation completed successfully.
TaskStatus
Result code returned by IAtomicTask::Execute().
Definition IAtomicTask.h:38
@ Failure
Task failed.
@ Running
Normal execution.
Lightweight context bundle passed to IAtomicTask::ExecuteWithContext().