![]() |
Lysa
0.0
Lysa 3D Engine
|
One-shot or repeating countdown timer.
When autoStart is true the timer starts immediately on construction. Each engine physics tick, Timers::update() advances all registered timers. When the wait time elapses the C++ callback (and/or the Lua callback) is invoked; a one-shot timer then stops while a repeating timer resets itself.
Public Typedefs | |
| using | Callback = std::function< void ()> |
Public Member Functions | |
| Timer (float waitTime, bool oneShot=true, bool autoStart=false, const Callback &callback=nullptr) | |
| bool | update (double deltaTime) |
| void | start () |
| void | stop () |
| bool | isStopped () const |
| float | getWaitTime () const |
| void | setWaitTime (const float t) |
| bool | isOneShot () const |
| void | setOneShot (const bool v) |
| virtual | ~Timer () |
Protected Member Functions | |
| virtual void | fireCallback () |
Protected Attributes | |
| float | waitTime |
| bool | oneShot |
| bool | stopped {true} |
| double | elapsed {0.0} |
| Callback | callback |
| Timer | ( | float | waitTime, |
| bool | oneShot = true, |
||
| bool | autoStart = false, |
||
| const Callback & | callback = nullptr |
||
| ) |
Creates a timer.
| waitTime | Delay in seconds before the callback fires (must be > 0). |
| oneShot | If true the timer stops after the first timeout. If false it repeats indefinitely until stop() is called. |
| autoStart | If true start() is called immediately in the constructor. |
| callback | Optional C++ callback invoked on each timeout. Can be set later for Lua. |
|
virtual |
|
protectedvirtual |
|
inline |
Returns the configured wait time in seconds.
|
inline |
Returns true for one-shot mode, false for repeating.
|
inline |
Returns true if the timer is neither running nor waiting to fire.
|
inline |
Enables or disables one-shot mode. Takes effect on the next start().
|
inline |
Sets a new wait time. Takes effect on the next start().
| void start | ( | ) |
Starts or restarts the timer.
| void stop | ( | ) |
Stops the timer without firing the callback.
| bool update | ( | double | deltaTime | ) |
Advances the timer by deltaTime seconds. Fires the callback(s) when the wait time is reached. Called automatically by Timers::update().
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |