C4 Engine
C4 Engine API Documentation

class Timer

Defined in:  C4Time.h
A deferred task which signals the expiration of a specific amount of time.
Definition

class Timer : public DeferredTask

Member Functions
Timer::GetTime Returns the length of time until the timer is triggered.
Timer::SetTime Sets the length of time which should pass before the timer is triggered.
Constructor

Timer(int32 time, CompletionCallback *callback, void *cookie = nullptr);

Parameters
time The length of time, in milliseconds, which should pass before the timer is triggered.
callback The callback to invoke when the task is triggered.
cookie The cookie that is passed to the trigger callback as its last parameter.
Description
The Timer class encapsulates a deferred task which is triggered after the time specified by the time parameter. Once a timer is registered using the TimeMgr::AddTask function, its remaining time is reduced each frame until it reaches zero, at which point its callback function is invoked. The callback function specified by the callback parameter should have the following prototype.

typedef void CompletionCallback(DeferredTask *, void *);

When the timer is triggered, the callback is invoked with the pointer specified by the cookie parameter passed to it as its second argument. A timer is triggered only once and must be resubmitted with the TimeMgr::AddTask function in order to be triggered again.
Base Classes
DeferredTask Timer objects provide a trigger for DeferredTask objects.