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(); \
40using DeltaTime = std::chrono::microseconds;
44using TasksChecksum = uint16_t;
45using TaskTypeIndex = uint16_t;
51 TASK_RESULT_UNFINISHED,
53 TASK_RESULT_SUBTASK_REQUIRED
69 enum class SyncType : uint8_t
76 ~NetworkTypeTasks()
override =
default;
90 fge::TasksChecksum g_checksumCopy;
110 virtual ~Task() =
default;
133 virtual fge::TaskResult
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; }
191 fge::Object* g_parentObject{
nullptr};
194 float _g_progress{0.0f};
197using TaskList = std::vector<std::unique_ptr<fge::Task>>;
207class FGE_API TaskHandler
210 TaskHandler() =
default;
211 TaskHandler(TaskHandler
const& r) =
delete;
212 TaskHandler(TaskHandler&& r)
noexcept;
213 ~TaskHandler() =
default;
215 TaskHandler& operator=(TaskHandler
const& r) =
delete;
216 TaskHandler& operator=(TaskHandler&& r)
noexcept =
delete;
226 [[nodiscard]]
fge::Object* getParentObject()
const;
228 [[nodiscard]] std::size_t getTaskSize()
const;
239 template<
class T = fge::Task>
243 template<
class T,
class... TArgs>
244 T* setMainTaskAndInit(TArgs&&... args);
254 template<
class T = fge::Task>
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
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:465
Handle the tasks of an object.
Definition C_task.hpp:208
T * addSubTask(std::unique_ptr< T > &&newTask)
Add a sub-task.
Definition C_task.inl:44
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.
T * setMainTask(std::unique_ptr< T > &&newTask)
Set the main task.
Definition C_task.inl:21
Base class for all tasks.
Definition C_task.hpp:107
virtual fge::TaskResult update(fge::TaskHandler &taskHandler, fge::Event &event, DeltaTime const &deltaTime, fge::Scene *scenePtr)=0
Update the task.
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.
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:125
A regroupment of network types.
Definition C_networkType.hpp:690
Definition C_packet.hpp:52
A class to represent a client or server identity with an IP address and a port.
Definition C_identity.hpp:31