OpenTTD Source 20241224-master-gee860a5c8e
TimerManager< TTimerType > Class Template Reference

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
 
TimerManageroperator= (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.
 

Detailed Description

template<typename TTimerType>
class TimerManager< TTimerType >

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.

Member Typedef Documentation

◆ TElapsed

template<typename TTimerType >
using TimerManager< TTimerType >::TElapsed = typename TTimerType::TElapsed

Definition at line 30 of file timer_manager.h.

◆ TPeriod

template<typename TTimerType >
using TimerManager< TTimerType >::TPeriod = typename TTimerType::TPeriod

Definition at line 29 of file timer_manager.h.

Member Function Documentation

◆ ChangeRegisteredTimerPeriod()

template<typename TTimerType >
static void TimerManager< TTimerType >::ChangeRegisteredTimerPeriod ( BaseTimer< TTimerType > &  timer,
TPeriod  new_period 
)
inlinestatic

Change the period of a registered timer.

Parameters
timerThe timer to change the period of.
new_periodThe 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().

◆ Elapsed() [1/6]

template<typename TTimerType >
static bool TimerManager< TTimerType >::Elapsed ( TElapsed  value)
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.

Parameters
valueThe amount of time that has elapsed.
Returns
True iff time has progressed.

Referenced by StateGameLoop(), and UpdateWindows().

◆ Elapsed() [2/6]

bool TimerManager< TimerGameCalendar >::Elapsed ( TimerGameCalendar::TElapsed  delta)

Definition at line 97 of file timer_game_calendar.cpp.

◆ Elapsed() [3/6]

bool TimerManager< TimerGameEconomy >::Elapsed ( TimerGameEconomy::TElapsed  delta)

Definition at line 124 of file timer_game_economy.cpp.

◆ Elapsed() [4/6]

bool TimerManager< TimerGameRealtime >::Elapsed ( TimerGameRealtime::TElapsed  delta)

Definition at line 57 of file timer_game_realtime.cpp.

◆ Elapsed() [5/6]

bool TimerManager< TimerGameTick >::Elapsed ( TimerGameTick::TElapsed  delta)

Definition at line 54 of file timer_game_tick.cpp.

◆ Elapsed() [6/6]

bool TimerManager< TimerWindow >::Elapsed ( TimerWindow::TElapsed  delta)

Definition at line 52 of file timer_window.cpp.

◆ GetTimers()

template<typename TTimerType >
static std::set< BaseTimer< TTimerType > *, base_timer_sorter > & TimerManager< TTimerType >::GetTimers ( )
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().

◆ RegisterTimer()

template<typename TTimerType >
static void TimerManager< TTimerType >::RegisterTimer ( BaseTimer< TTimerType > &  timer)
inlinestatic

Register a timer.

Parameters
timerThe 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().

◆ UnregisterTimer()

template<typename TTimerType >
static void TimerManager< TTimerType >::UnregisterTimer ( BaseTimer< TTimerType > &  timer)
inlinestatic

Unregister a timer.

Parameters
timerThe 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().


The documentation for this class was generated from the following file: