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 (sf::Time timeLimit, bool initiallyRunning=false) | |
Constructor: Sets up a new Timer with the given time limit. | |
virtual void | Reset (sf::Time timeLimit, bool restart=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. | |
sf::Time | 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 | ( | sf::Time | 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 Update() each frame to invoke potential listeners.
listener | The function you want to associate with the timer expiration. |
sf::Time thor::Timer::GetRemainingTime | ( | ) | const [inherited] |
Returns the remaining time.
If the timer has expired, sf::Time::Zero 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 | ( | sf::Time | timeLimit, |
bool | restart = false |
||
) | [virtual] |
Resets the timer's countdown to the given time limit.
timeLimit | The new time limit (must be greater than zero). |
restart | True when the timer continues to run, false if it waits for the next Start() call. |
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.