C4 Engine
C4 Engine API Documentation

class DeferredTask

Defined in:  C4Time.h
General base class for objects which can be scheduled to perform a task after a specific amount of time.

class DeferredTask : public ListElement<DeferredTask>, public Completable<DeferredTask>

Member Functions
DeferredTask::GetTaskFlags Returns the task flags.
DeferredTask::SetTaskFlags Sets the task flags.

DeferredTask(CompletionCallback *callback, void *cookie = nullptr);

callback The callback to invoke when the task is triggered.
cookie The cookie that is passed to the trigger callback as its last parameter.
The DeferredTask class encapsulates a callback function that is invoked at some future time when the deferred task object is triggered by some means. Once a deferred task or one of its subclasses has been created, it should be added to the Time Manager using the TimeMgr::AddTask function. The callback function specified by the callback parameter should have the following prototype.

typedef void CompletionCallback(DeferredTask *, void *);

When the deferred task is triggered, the callback is invoked with the pointer specified by the cookie parameter passed to it as its second argument. By default, a deferred task is triggered only once and is then removed from the Time Manager. A deferred task can be made to be triggered repeatedly by setting the kTaskRepeating flag with the DeferredTask::SetTaskFlags function.

The DeferredTask base class is always triggered, so the callback function will be invoked at the beginning of the next frame once the deferred task object has been registered using the TimeMgr::AddTask function. See the Timer class for a deferred task that is triggered after a specified period of time.

Deferred tasks can be persistent or nonpersistent. A persistent task continues to exist after it has been triggered, but a nonpersistent task is automatically destroyed after being triggered. By default, a deferred task is persistent. The persistence state can be changed using the DeferredTask::SetTaskFlags function.
Base Classes
ListElement<DeferredTask> Used internally by the Time Manager.
Completable<DeferredTask> The completion callback is called when the task is triggered.
See Also