17#ifndef _FGE_C_TASK_HPP_INCLUDED
18#define _FGE_C_TASK_HPP_INCLUDED
20#include "FastEngine/fge_extern.hpp"
21#include "FastEngine/C_event.hpp"
22#include "FastEngine/manager/task_manager.hpp"
23#include "FastEngine/network/C_networkType.hpp"
27#define FGE_TASK_DEFAULT_GETTER(type_) \
28 [[nodiscard]] fge::TaskTypeIndex getTypeIndex() const override \
30 return fge::task::GetTaskIndex(typeid(type_)).value(); \
32 [[nodiscard]] static fge::TaskTypeIndex GetTypeIndex() \
34 return fge::task::GetTaskIndex(typeid(type_)).value(); \
42using TasksChecksum = uint16_t;
43using TaskTypeIndex = uint16_t;
49 TASK_RESULT_UNFINISHED,
51 TASK_RESULT_SUBTASK_REQUIRED
67 enum SyncType : uint8_t
88 fge::TasksChecksum g_checksumCopy;
108 virtual ~Task() =
default;
133 std::chrono::microseconds
const& deltaTime,
181 [[nodiscard]]
inline T* getParentObject()
const
183 return reinterpret_cast<T*
>(this->g_parentObject);
187 friend class TaskHandler;
188 friend class NetworkTypeTasks;
189 inline void setParentObject(
fge::Object* parentObject) { this->g_parentObject = parentObject; }
194 float _g_progress{0.0f};
197using TaskList = std::vector<std::unique_ptr<fge::Task>>;
226 [[nodiscard]]
fge::Object* getParentObject()
const;
228 [[nodiscard]] std::size_t getTaskSize()
const;
239 template<
class T = fge::Task>
240 T* setMainTask(std::unique_ptr<T>&& newTask);
243 template<
class T,
class... TArgs>
244 T* setMainTaskAndInit(TArgs&&... args);
254 template<
class T = fge::Task>
255 T* addSubTask(std::unique_ptr<T>&& newTask);
258 template<
class T,
class... TArgs>
259 T* addSubTaskAndInit(TArgs&&... args);
261 [[nodiscard]]
fge::Task* getMainTask()
const;
262 [[nodiscard]]
fge::Task* getActualTask()
const;
263 [[nodiscard]] std::optional<fge::TaskTypeIndex> getActualTaskType()
const;
267 [[nodiscard]] fge::TaskList
const& getTasks()
const;
269 [[nodiscard]] std::optional<fge::TaskTypeIndex> getLastTask()
const;
270 void clearLastTask();
282 [[nodiscard]] fge::TasksChecksum getChecksum()
const;
287 void computeChecksum();
290 fge::TaskList g_tasks;
291 std::optional<fge::TaskTypeIndex> g_lastTask;
292 fge::TasksChecksum g_tasksChecksum{0};
297#include "FastEngine/C_task.inl"
This class is used to handle callbacks in a safe way.
Definition C_callback.hpp:189
This class is a wrapper for SDL events.
Definition C_event.hpp:59
Network type for the TaskHandler.
Definition C_task.hpp:65
void packData(fge::net::Packet &pck, fge::net::Identity const &id) override
Pack the data into a packet and reset the modification flag of the identity.
bool check() const override
Check if the value have been modified.
void forceCheck() override
Force the value to be modified (even if it is not)
void const * getSource() const override
Get the source pointer that have been used to create this network type.
void packData(fge::net::Packet &pck) override
Pack the data without any client identity.
bool applyData(fge::net::Packet const &pck) override
Apply the data packed by the same network type from a server.
void forceUncheck() override
Remove the forced modification of the value.
The Object class is the base class for all objects in the engine.
Definition C_object.hpp:102
A scene contain a collection of object and handle them.
Definition C_scene.hpp:450
Handle the tasks of an object.
Definition C_task.hpp:208
void setParentObject(fge::Object &parentObject)
Set the parent object of the TaskHandler.
fge::CallbackHandler< TaskHandler & > _onMainTaskChanged
Called when the main task is changed.
Definition C_task.hpp:284
void networkRegister(fge::net::NetworkTypeHandler &netList)
Register the network types of the tasks.
Base class for all tasks.
Definition C_task.hpp:105
virtual void pack(fge::net::Packet &pck)=0
Pack the task data into a packet.
virtual fge::TaskTypeIndex getTypeIndex() const =0
Get the type index of the task.
fge::Object * getParentObject() const
Get the parent object of the task.
Definition C_task.hpp:179
virtual void unpackAndInit(fge::net::Packet const &pck)=0
Unpack the task data from a packet and initialize the task.
virtual std::string_view getStringStatus() const =0
Get the custom status of the task as a string.
virtual fge::TaskResult update(fge::TaskHandler &taskHandler, fge::Event &event, std::chrono::microseconds const &deltaTime, fge::Scene *scenePtr)=0
Update the task.
float getProgression() const
Get the progression of the task as a percentage.
Definition C_task.hpp:157
Base class for a network type.
Definition C_networkType.hpp:70
A regroupment of network types.
Definition C_networkType.hpp:590
Definition C_packet.hpp:70
A class to represent a client or server identity with an IP address and a port.
Definition C_identity.hpp:31