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

A timeout timer will fire once after the interval. More...

#include <timer.h>

Inheritance diagram for TimeoutTimer< TTimerType >:
BaseTimer< TTimerType >

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

 TimeoutTimer (const TPeriod timeout, std::function< void()> callback, bool start=false)
 Create a new timeout timer.
 
void Reset ()
 Reset the timer, so it will fire again after the timeout.
 
void Reset (const TPeriod timeout)
 Reset the timer, so it will fire again after the timeout.
 
void Abort ()
 Abort the timer so it doesn't fire if it hasn't yet.
 
bool HasFired () const
 Check whether the timeout occurred.
 
- Public Member Functions inherited from BaseTimer< TTimerType >
 BaseTimer (const TPeriod period)
 Create a new timer.
 
virtual ~BaseTimer ()
 Delete the timer.
 

Data Fields

bool fired
 Whether the timeout has occurred.
 
- Data Fields inherited from BaseTimer< TTimerType >
TPeriod period
 The period of the timer.
 
TStorage storage = {}
 The storage of 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 (TimerGameCalendar::TElapsed trigger)
 
void Elapsed (TimerGameEconomy::TElapsed trigger)
 
void Elapsed (TimerGameRealtime::TElapsed delta)
 
void Elapsed (TimerGameTick::TElapsed delta)
 

Private Attributes

std::function< void()> callback
 

Additional Inherited Members

Detailed Description

template<typename TTimerType>
class TimeoutTimer< TTimerType >

A timeout timer will fire once after the interval.

You can reset it to fire again. The timer will never fire before the interval has passed, but in times of severe stress it might be late.

Definition at line 116 of file timer.h.

Member Typedef Documentation

◆ TElapsed

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

Definition at line 119 of file timer.h.

◆ TPeriod

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

Definition at line 118 of file timer.h.

Constructor & Destructor Documentation

◆ TimeoutTimer()

template<typename TTimerType >
TimeoutTimer< TTimerType >::TimeoutTimer ( const TPeriod  timeout,
std::function< void()>  callback,
bool  start = false 
)
inline

Create a new timeout timer.

By default the timeout starts aborted; you will have to call Reset() before it starts.

Parameters
timeoutThe timeout after which the timer will fire.
callbackThe callback to call when the timeout has passed.
startWhether to start the timer immediately. If false, you can call Reset() to start it.

Definition at line 130 of file timer.h.

Member Function Documentation

◆ Abort()

template<typename TTimerType >
void TimeoutTimer< TTimerType >::Abort ( )
inline

Abort the timer so it doesn't fire if it hasn't yet.

Definition at line 161 of file timer.h.

References TimeoutTimer< TTimerType >::fired.

Referenced by StatusBarWindow::OnInvalidateData(), and StartupCompanies().

◆ Elapsed() [1/5]

template<typename TTimerType >
void TimeoutTimer< TTimerType >::Elapsed ( TElapsed  delta)
overrideprivatevirtual

Called by the timer manager to notify the timer that the given amount of time has elapsed.

Parameters
deltaDepending on the time type, this is either in milliseconds or in ticks.

Implements BaseTimer< TTimerType >.

◆ Elapsed() [2/5]

void TimeoutTimer< TimerGameCalendar >::Elapsed ( TimerGameCalendar::TElapsed  trigger)
private

Definition at line 86 of file timer_game_calendar.cpp.

◆ Elapsed() [3/5]

void TimeoutTimer< TimerGameEconomy >::Elapsed ( TimerGameEconomy::TElapsed  trigger)
private

Definition at line 113 of file timer_game_economy.cpp.

◆ Elapsed() [4/5]

void TimeoutTimer< TimerGameRealtime >::Elapsed ( TimerGameRealtime::TElapsed  delta)
private

Definition at line 41 of file timer_game_realtime.cpp.

◆ Elapsed() [5/5]

void TimeoutTimer< TimerGameTick >::Elapsed ( TimerGameTick::TElapsed  delta)
private

Definition at line 40 of file timer_game_tick.cpp.

◆ HasFired()

template<typename TTimerType >
bool TimeoutTimer< TTimerType >::HasFired ( ) const
inline

Check whether the timeout occurred.

Returns
True iff the timeout occurred.

Definition at line 171 of file timer.h.

References TimeoutTimer< TTimerType >::fired.

Referenced by StatusBarWindow::DrawWidget().

◆ Reset() [1/2]

template<typename TTimerType >
void TimeoutTimer< TTimerType >::Reset ( )
inline

◆ Reset() [2/2]

template<typename TTimerType >
void TimeoutTimer< TTimerType >::Reset ( const TPeriod  timeout)
inline

Reset the timer, so it will fire again after the timeout.

Parameters
timeoutSet a new timeout for the next trigger.

Definition at line 151 of file timer.h.

References TimerManager< TTimerType >::ChangeRegisteredTimerPeriod(), TimeoutTimer< TTimerType >::fired, and BaseTimer< TTimerType >::storage.

Field Documentation

◆ callback

template<typename TTimerType >
std::function<void()> TimeoutTimer< TTimerType >::callback
private

Definition at line 181 of file timer.h.

◆ fired

template<typename TTimerType >
bool TimeoutTimer< TTimerType >::fired

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