OpenTTD Source
20241124-master-g9399a92a4f
|
An interval timer will fire every interval, and will continue to fire until it is deleted. 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 | |
IntervalTimer (const TPeriod interval, std::function< void(uint)> callback) | |
Create a new interval timer. More... | |
void | SetInterval (const TPeriod interval, bool reset=true) |
Set a new interval for the timer. More... | |
Public Member Functions inherited from BaseTimer< TTimerType > | |
BaseTimer (const TPeriod period) | |
Create a new timer. More... | |
virtual | ~BaseTimer () |
Delete 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 (TimerGameEconomy::TElapsed trigger) |
void | Elapsed (TimerGameRealtime::TElapsed delta) |
Private Attributes | |
std::function< void(uint)> | callback |
Additional Inherited Members | |
Data Fields inherited from BaseTimer< TTimerType > | |
TPeriod | period |
The period of the timer. | |
TStorage | storage = {} |
The storage of the timer. | |
An interval timer will fire every interval, and will continue to fire until it is deleted.
The callback receives how many times the timer has fired since the last time it fired. It will always try to fire every interval, but in times of severe stress it might be late.
Each Timer-type needs to implement the Elapsed() method, and call the callback if needed.
Setting the period to zero disables the interval. It can be reenabled at any time by calling SetInterval() with a non-zero period.
|
inline |
|
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 |
Set a new interval for the timer.
interval | The interval between each callback. |
reset | Whether to reset the timer to zero. |
Definition at line 99 of file timer.h.
References TimerManager< TTimerType >::ChangeRegisteredTimerPeriod(), and BaseTimer< TTimerType >::storage.