OpenTTD Source 20241224-master-gee860a5c8e
|
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. | |
void | SetInterval (const TPeriod interval, bool reset=true) |
Set a new interval for the timer. | |
Public Member Functions inherited from BaseTimer< TTimerType > | |
BaseTimer (const TPeriod period) | |
Create a new timer. | |
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. | |
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.
using IntervalTimer< TTimerType >::TElapsed = typename TTimerType::TElapsed |
using IntervalTimer< TTimerType >::TPeriod = typename TTimerType::TPeriod |
|
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 >.
|
private |
Definition at line 105 of file timer_game_economy.cpp.
|
private |
Definition at line 21 of file timer_game_realtime.cpp.
|
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.
Referenced by ChangeAutosaveFrequency(), and ChangeNetworkRestartTime().
|
private |