OpenTTD Source 20241224-master-gee860a5c8e
|
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 (TimerGameCalendar::TElapsed delta) |
bool | Elapsed (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. | |
static void | UnregisterTimer (BaseTimer< TTimerType > &timer) |
Unregister a timer. | |
static void | ChangeRegisteredTimerPeriod (BaseTimer< TTimerType > &timer, TPeriod new_period) |
Change the period of a registered timer. | |
static bool | Elapsed (TElapsed value) |
Called when time for this timer elapsed. | |
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.
using TimerManager< TTimerType >::TElapsed = typename TTimerType::TElapsed |
Definition at line 30 of file timer_manager.h.
using TimerManager< TTimerType >::TPeriod = typename TTimerType::TPeriod |
Definition at line 29 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 StateGameLoop(), and UpdateWindows().
bool TimerManager< TimerGameCalendar >::Elapsed | ( | TimerGameCalendar::TElapsed | delta | ) |
Definition at line 97 of file timer_game_calendar.cpp.
bool TimerManager< TimerGameEconomy >::Elapsed | ( | TimerGameEconomy::TElapsed | delta | ) |
Definition at line 124 of file timer_game_economy.cpp.
bool TimerManager< TimerGameRealtime >::Elapsed | ( | TimerGameRealtime::TElapsed | delta | ) |
Definition at line 57 of file timer_game_realtime.cpp.
bool TimerManager< TimerGameTick >::Elapsed | ( | TimerGameTick::TElapsed | delta | ) |
Definition at line 54 of file timer_game_tick.cpp.
bool TimerManager< TimerWindow >::Elapsed | ( | TimerWindow::TElapsed | delta | ) |
Definition at line 52 of file timer_window.cpp.
|
inlinestaticprivate |
Singleton list, to store all the active timers.
Definition at line 115 of file timer_manager.h.
Referenced by TimerManager< TTimerType >::RegisterTimer(), and TimerManager< TTimerType >::UnregisterTimer().
|
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().