FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
fge::Task Class Referenceabstract

Base class for all tasks. More...

#include <C_task.hpp>

Public Member Functions

virtual fge::TaskResult update (fge::TaskHandler &taskHandler, fge::Event &event, std::chrono::microseconds const &deltaTime, fge::Scene *scenePtr)=0
 Update the task.
 
virtual fge::TaskTypeIndex getTypeIndex () const =0
 Get the type index of 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.
 
virtual void pack (fge::net::Packet &pck)=0
 Pack the task data into a packet.
 
virtual void unpackAndInit (fge::net::Packet const &pck)=0
 Unpack the task data from a packet and initialize the task.
 
fge::ObjectgetParentObject () const
 Get the parent object of the task.
 
template<class T >
T * getParentObject () const
 

Protected Attributes

float _g_progress {0.0f}
 

Friends

class TaskHandler
 
class NetworkTypeTasks
 

Detailed Description

Base class for all tasks.

A Task represent an action that can be done by an object. An action can be composed of multiple sub-tasks.

When inheriting from this class, you should implement a init() method that will initialize the task with custom parameters.

This class can also be network aware.

See also
NetworkTypeTasks

Member Function Documentation

◆ getParentObject()

fge::Object * fge::Task::getParentObject ( ) const
inlinenodiscard

Get the parent object of the task.

This is always an object that should generally contain the TaskHandler.

Returns
The parent object of the task

◆ getProgression()

float fge::Task::getProgression ( ) const
inlinenodiscard

Get the progression of the task as a percentage.

Returns
The progression of the task

◆ getStringStatus()

virtual std::string_view fge::Task::getStringStatus ( ) const
nodiscardpure virtual

Get the custom status of the task as a string.

Returns
The custom status of the task

◆ getTypeIndex()

virtual fge::TaskTypeIndex fge::Task::getTypeIndex ( ) const
nodiscardpure virtual

Get the type index of the task.

Every task must have a unique type index that can be retrieved using the task_manager.hpp functions.

See also
task::RegisterNewTask
Returns
The type index of the task

◆ pack()

virtual void fge::Task::pack ( fge::net::Packet & pck)
pure virtual

Pack the task data into a packet.

Parameters
pckThe packet

◆ unpackAndInit()

virtual void fge::Task::unpackAndInit ( fge::net::Packet const & pck)
pure virtual

Unpack the task data from a packet and initialize the task.

Parameters
pckThe packet

◆ update()

virtual fge::TaskResult fge::Task::update ( fge::TaskHandler & taskHandler,
fge::Event & event,
std::chrono::microseconds const & deltaTime,
fge::Scene * scenePtr )
pure virtual

Update the task.

In order to complete a task, it must be updated.

This function can return multiple values:

  • TASK_RESULT_ERROR: The task has encountered an error and must be stopped.
  • TASK_RESULT_UNFINISHED: The task is not finished yet.
  • TASK_RESULT_FINISHED: The task is finished.
  • TASK_RESULT_SUBTASK_REQUIRED: The task is finished but a sub-task is required and has been created.

When receiving ERROR, all tasks from the TaskHandler should be cleared by calling TaskHandler::clearTasks(). When receiving FINISHED, the top task should be removed by calling TaskHandler::popTask().

See also
TaskHandler
Parameters
taskHandlerThe TaskHandler that handle this task
eventThe event object
deltaTimeThe time elapsed since the last update
scenePtrThe scene pointer
Returns
The result of the update

The documentation for this class was generated from the following file: