OpenTTD Source  20241108-master-g80f628063a
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 ([[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.
 

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 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()

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 UpdateWindows().

◆ 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: