OpenTTD Source
20241108-master-g80f628063a
|
A timeout timer will fire once after the interval. More...
#include <timer.h>
Public Types | |
using | TPeriod = typename TTimerType::TPeriod |
using | TElapsed = typename TTimerType::TElapsed |
Public Types inherited from BaseTimer< TTimerType > | |
using | TPeriod = typename TTimerType::TPeriod |
using | TElapsed = typename TTimerType::TElapsed |
using | TStorage = typename TTimerType::TStorage |
Public Member Functions | |
TimeoutTimer (const TPeriod timeout, std::function< void()> callback, bool start=false) | |
Create a new timeout timer. More... | |
void | Reset () |
Reset the timer, so it will fire again after the timeout. | |
void | Reset (const TPeriod timeout) |
Reset the timer, so it will fire again after the timeout. More... | |
void | Abort () |
Abort the timer so it doesn't fire if it hasn't yet. | |
bool | HasFired () const |
Check whether the timeout occurred. More... | |
Public Member Functions inherited from BaseTimer< TTimerType > | |
BaseTimer (const TPeriod period) | |
Create a new timer. More... | |
virtual | ~BaseTimer () |
Delete the timer. | |
Data Fields | |
bool | fired |
Whether the timeout has occurred. | |
Data Fields inherited from BaseTimer< TTimerType > | |
TPeriod | period |
The period of the timer. | |
TStorage | storage = {} |
The storage of the timer. | |
Private Member Functions | |
void | Elapsed (TElapsed count) override |
Called by the timer manager to notify the timer that the given amount of time has elapsed. More... | |
void | Elapsed (TimerGameCalendar::TElapsed trigger) |
void | Elapsed (TimerGameEconomy::TElapsed trigger) |
void | Elapsed (TimerGameRealtime::TElapsed delta) |
void | Elapsed (TimerGameTick::TElapsed delta) |
Private Attributes | |
std::function< void()> | callback |
Additional Inherited Members |
A timeout timer will fire once after the interval.
You can reset it to fire again. The timer will never fire before the interval has passed, but in times of severe stress it might be late.
|
inline |
Create a new timeout timer.
By default the timeout starts aborted; you will have to call Reset() before it starts.
timeout | The timeout after which the timer will fire. |
callback | The callback to call when the timeout has passed. |
start | Whether to start the timer immediately. If false, you can call Reset() to start it. |
|
overrideprivatevirtual |
Called by the timer manager to notify the timer that the given amount of time has elapsed.
delta | Depending on the time type, this is either in milliseconds or in ticks. |
Implements BaseTimer< TTimerType >.
|
inline |
Check whether the timeout occurred.
Definition at line 171 of file timer.h.
References TimeoutTimer< TTimerType >::fired.
|
inline |
Reset the timer, so it will fire again after the timeout.
timeout | Set a new timeout for the next trigger. |
Definition at line 151 of file timer.h.
References TimerManager< TTimerType >::ChangeRegisteredTimerPeriod(), TimeoutTimer< TTimerType >::fired, and BaseTimer< TTimerType >::storage.