OpenTTD Source
20240917-master-g9ab0a47812
|
Go to the documentation of this file.
21 template <
typename TTimerType>
24 using TPeriod =
typename TTimerType::TPeriod;
25 using TElapsed =
typename TTimerType::TElapsed;
26 using TStorage =
typename TTimerType::TStorage;
58 virtual void Elapsed(TElapsed delta) = 0;
75 template <
typename TTimerType>
78 using TPeriod =
typename TTimerType::TPeriod;
79 using TElapsed =
typename TTimerType::TElapsed;
87 [[nodiscard]]
IntervalTimer(
const TPeriod interval, std::function<
void(uint)> callback) :
106 std::function<void(uint)> callback;
108 void Elapsed(TElapsed count)
override;
115 template <
typename TTimerType>
118 using TPeriod =
typename TTimerType::TPeriod;
119 using TElapsed =
typename TTimerType::TElapsed;
130 [[nodiscard]]
TimeoutTimer(
const TPeriod timeout, std::function<
void()> callback,
bool start =
false) :
181 std::function<void()> callback;
183 void Elapsed(TElapsed count)
override;
The base where every other type of timer is derived from.
TimeoutTimer(const TPeriod timeout, std::function< void()> callback, bool start=false)
Create a new timeout timer.
An interval timer will fire every interval, and will continue to fire until it is deleted.
TPeriod period
The period of the timer.
bool HasFired() const
Check whether the timeout occurred.
void Reset()
Reset the timer, so it will fire again after the timeout.
static void ChangeRegisteredTimerPeriod(BaseTimer< TTimerType > &timer, TPeriod new_period)
Change the period of a registered timer.
void Elapsed(TElapsed count) override
Called by the timer manager to notify the timer that the given amount of time has elapsed.
void Elapsed(TElapsed count) override
Called by the timer manager to notify the timer that the given amount of time has elapsed.
bool fired
Whether the timeout has occurred.
The TimerManager manages a single Timer-type.
BaseTimer(const TPeriod period)
Create a new timer.
IntervalTimer(const TPeriod interval, std::function< void(uint)> callback)
Create a new interval timer.
A timeout timer will fire once after the interval.
void Reset(const TPeriod timeout)
Reset the timer, so it will fire again after the timeout.
static void UnregisterTimer(BaseTimer< TTimerType > &timer)
Unregister a timer.
TStorage storage
The storage of the timer.
void SetInterval(const TPeriod interval, bool reset=true)
Set a new interval for the timer.
static void RegisterTimer(BaseTimer< TTimerType > &timer)
Register a timer.
virtual ~BaseTimer()
Delete the timer.
virtual void Elapsed(TElapsed delta)=0
Called by the timer manager to notify the timer that the given amount of time has elapsed.
void Abort()
Abort the timer so it doesn't fire if it hasn't yet.