OpenTTD Source 20260206-master-g4d4e37dbf1
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)
void Elapsed (TimerWindow::TElapsed delta)

Private Attributes

std::function< void()> callback

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

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.

References BaseTimer< TTimerType >::BaseTimer(), and fired.

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 fired.

◆ Elapsed() [1/6]

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/6]

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

Definition at line 83 of file timer_game_calendar.cpp.

◆ Elapsed() [3/6]

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

Definition at line 111 of file timer_game_economy.cpp.

◆ Elapsed() [4/6]

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

Definition at line 38 of file timer_game_realtime.cpp.

◆ Elapsed() [5/6]

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

Definition at line 37 of file timer_game_tick.cpp.

◆ Elapsed() [6/6]

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

Definition at line 35 of file timer_window.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 fired.

Referenced by ErrmsgWindow::OnPaint().

◆ Reset() [1/2]

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

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

Definition at line 140 of file timer.h.

References fired, and BaseTimer< TTimerType >::storage.

Referenced by ErrmsgWindow::OnPaint(), MainWindow::OnResize(), and MainWindow::OnScroll().

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

Whether the timeout has occurred.

Definition at line 178 of file timer.h.

Referenced by Abort(), HasFired(), Reset(), Reset(), and TimeoutTimer().


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