Advanced timer with the ability to trigger function calls. More...
Public Types | |
typedef std::tr1::function < void(TriggeringTimer &) > | Listener |
Callback type for events being processed by TriggeringTimer. | |
Public Member Functions | |
TriggeringTimer () | |
Default constructor: Creates an TriggeringTimer that is initially expired. | |
TriggeringTimer (float timeLimit, bool initiallyRunning=false) | |
Constructor: Sets up a new Timer with the given time limit. | |
virtual void | Reset (float timeLimit, bool continueRunning=false) |
Resets the Timer's countdown to the given time limit. | |
void | Update () |
Trigger listeners, if expired. | |
Connection | Connect (const Listener &listener) |
Registers a function which will be called when the time reaches zero. | |
void | ClearConnections () |
Removes all currently associated timer listeners. | |
float | GetRemainingTime () const |
Returns the remaining time. | |
bool | IsRunning () const |
Checks if the timer is currently running. | |
bool | IsExpired () const |
Checks if the timer has expired yet. | |
void | Start () |
Starts or continues the timer. | |
void | Stop () |
Pauses the timer. |
Advanced timer with the ability to trigger function calls.
Clock class that counts time down. As an extension of Timer, this class is able to register functions that are called at expiration time.
Default constructor: Creates an TriggeringTimer that is initially expired.
You have to call Reset() before you can use the countdown functionality.
thor::TriggeringTimer::TriggeringTimer | ( | float | timeLimit, |
bool | initiallyRunning = false |
||
) | [explicit] |
Constructor: Sets up a new Timer with the given time limit.
timeLimit | The initial time (must be greater than zero). |
initiallyRunning | Indicates whether the timer is immediately being started. |
Removes all currently associated timer listeners.
This also invalidates all connections to those listeners.
Connection thor::TriggeringTimer::Connect | ( | const Listener & | listener | ) |
Registers a function which will be called when the time reaches zero.
Make sure to call Check() each frame to invoke potential listeners.
listener | The function you want to associate with the timer expiration. |
float thor::Timer::GetRemainingTime | ( | ) | const [inherited] |
Returns the remaining time.
If the timer has expired, 0.f is returned.
bool thor::Timer::IsExpired | ( | ) | const [inherited] |
Checks if the timer has expired yet.
Timers expire when their remaining time reaches zero.
bool thor::Timer::IsRunning | ( | ) | const [inherited] |
Checks if the timer is currently running.
As soon as the timer expires, it stops running until Reset() is called.
virtual void thor::TriggeringTimer::Reset | ( | float | timeLimit, |
bool | continueRunning = false |
||
) | [virtual] |
Resets the Timer's countdown to the given time limit.
timeLimit | The new time (must be greater than zero). |
continueRunning | Indicates whether the timer just continues. |
Reimplemented from thor::Timer.
void thor::Timer::Start | ( | ) | [inherited] |
Starts or continues the timer.
If it is already running, nothing happens.
void thor::Timer::Stop | ( | ) | [inherited] |
Pauses the timer.
If it is already paused, nothing happens.
void thor::TriggeringTimer::Update | ( | ) |
Trigger listeners, if expired.
This is the most important function of this class. You should call Update() every frame (or, the better way, let this an automated routine do) to assure that all associated listeners are invoked when the timer expires.