ezEngine  Milestone 7
ezTask Class Referenceabstract

Derive from this base class to implement custom tasks. More...

#include <TaskSystem.h>

Inheritance diagram for ezTask:

Public Member Functions

void SetTaskName (const char *szName)
 Changes the name of the task, which it will be displayed in profiling tools. More...
 
void SetOnTaskFinished (OnTaskFinished Callback)
 Sets an additional callback function to execute when the task is finished (or canceled). The most common use case for this is to deallocate the task at this time.
 
bool IsTaskFinished () const
 Returns whether the task has been finished. This includes being canceled. More...
 
bool HasBeenCanceled () const
 Can be used inside an overridden 'Execute' function to terminate execution prematurely.
 

Private Types

typedef ezDelegate< void(ezTask *)> OnTaskFinished
 Function type for callbacks when a task has been finished (or canceled).
 

Private Member Functions

 EZ_DISALLOW_COPY_AND_ASSIGN (ezTask)
 
virtual void Execute ()=0
 Override this to implement the task's supposed functionality.
 
void Reset ()
 
void Run ()
 Called by ezTaskSystem to execute the task. Calls 'Execute' internally.
 
const ezProfilingIdCreateProfilingID ()
 Allocates and returns a profiling ID for this task. Called by ezTaskSystem.
 

Private Attributes

volatile bool m_bIsFinished
 Set to true once the task is finished or properly canceled.
 
volatile bool m_bCancelExecution
 Set to true when the task is SUPPOSED to cancel. Whether the task is able to do that, depends on its implementation.
 
bool m_bTaskIsScheduled
 Whether this task has been scheduled for execution already, or is still waiting for dependencies to finish.
 
bool m_bProfilingIDGenerated
 Just stores whether m_ProfilingID has been generated, to prevent doing it twice.
 
ezProfilingId m_ProfilingID
 The profiling ID for this task.
 
OnTaskFinished m_OnTaskFinished
 Optional callback to be fired when the task has finished or was canceled.
 
ezTaskGroupID m_BelongsToGroup
 The parent group to which this task belongs.
 
ezString m_sTaskName
 

Friends

class ezTaskWorkerThread
 
class ezTaskSystem
 

Detailed Description

Derive from this base class to implement custom tasks.

Member Function Documentation

bool ezTask::IsTaskFinished ( ) const
inline

Returns whether the task has been finished. This includes being canceled.

Note
This function is only reliable when you KNOW that the task has not been reused. So that limits its usage to the time frame while the task is in use, and it should only be queried by code that actually manages when to reuse the task. If other code needs to be able to check whether a task is finished, you should give it the ezTaskGroupID of the task's group. That one can be used to query whether the group has finished, even minutes later.
void ezTask::SetTaskName ( const char *  szName)

Changes the name of the task, which it will be displayed in profiling tools.

This will only have an effect if it is called before the task is added to a task group.


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