OpenTTD Source
20241108-master-g80f628063a
|
The TimerManager manages a single Timer-type. More...
#include <timer_manager.h>
Data Structures | |
struct | base_timer_sorter |
Sorter for timers. More... | |
Public Types | |
using | TPeriod = typename TTimerType::TPeriod |
using | TElapsed = typename TTimerType::TElapsed |
Public Member Functions | |
TimerManager (TimerManager const &)=delete | |
TimerManager & | operator= (TimerManager const &)=delete |
bool | Elapsed ([[maybe_unused]] TimerGameCalendar::TElapsed delta) |
bool | Elapsed ([[maybe_unused]] TimerGameEconomy::TElapsed delta) |
bool | Elapsed (TimerGameRealtime::TElapsed delta) |
bool | Elapsed (TimerGameTick::TElapsed delta) |
bool | Elapsed (TimerWindow::TElapsed delta) |
Static Public Member Functions | |
static void | RegisterTimer (BaseTimer< TTimerType > &timer) |
Register a timer. More... | |
static void | UnregisterTimer (BaseTimer< TTimerType > &timer) |
Unregister a timer. More... | |
static void | ChangeRegisteredTimerPeriod (BaseTimer< TTimerType > &timer, TPeriod new_period) |
Change the period of a registered timer. More... | |
static bool | Elapsed (TElapsed value) |
Called when time for this timer elapsed. More... | |
Static Private Member Functions | |
static std::set< BaseTimer< TTimerType > *, base_timer_sorter > & | GetTimers () |
Singleton list, to store all the active timers. | |
The TimerManager manages a single Timer-type.
It allows for automatic registration and unregistration of timers like Interval and OneShot.
Each Timer-type needs to implement the Elapsed() method, and distribute that to the timers if needed.
Definition at line 27 of file timer_manager.h.
|
inlinestatic |
Change the period of a registered timer.
timer | The timer to change the period of. |
new_period | The new period value. |
Definition at line 65 of file timer_manager.h.
References BaseTimer< TTimerType >::period, TimerManager< TTimerType >::RegisterTimer(), and TimerManager< TTimerType >::UnregisterTimer().
Referenced by TimeoutTimer< TTimerType >::Reset(), and IntervalTimer< TTimerType >::SetInterval().
|
static |
Called when time for this timer elapsed.
The implementation per type is different, but they all share a similar goal: Call the Elapsed() method of all active timers.
value | The amount of time that has elapsed. |
Referenced by UpdateWindows().
|
inlinestatic |
Register a timer.
timer | The timer to register. |
Definition at line 41 of file timer_manager.h.
References TimerManager< TTimerType >::GetTimers(), and BaseTimer< TTimerType >::period.
Referenced by BaseTimer< TTimerType >::BaseTimer(), and TimerManager< TTimerType >::ChangeRegisteredTimerPeriod().
|
inlinestatic |
Unregister a timer.
timer | The timer to unregister. |
Definition at line 54 of file timer_manager.h.
References TimerManager< TTimerType >::GetTimers().
Referenced by TimerManager< TTimerType >::ChangeRegisteredTimerPeriod(), and BaseTimer< TTimerType >::~BaseTimer().