OpenTTD Source: IntervalTimer< TTimerType > Class Template Reference

OpenTTD Source 14.0-beta1

Public Types | Public Member Functions | Private Member Functions | Private Attributes
IntervalTimer< TTimerType > Class Template Reference

An interval timer will fire every interval, and will continue to fire until it is deleted. More...

`#include <timer.h>`

Inheritance diagram for IntervalTimer< 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
| IntervalTimer (const TPeriod interval, std::function< void(uint)> callback)
| Create a new interval timer. More...
void | SetInterval (const TPeriod interval, bool reset=true)
| Set a new interval for the timer. More...
Public Member Functions inherited from BaseTimer< TTimerType >
| BaseTimer (const TPeriod period)
| Create a new timer. More...
virtual | ~BaseTimer ()
| Delete 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. More...
void | Elapsed (TimerGameEconomy::TElapsed trigger)
void | Elapsed (TimerGameRealtime::TElapsed delta)

## Private Attributes
std::function< void(uint)> | callback

## Additional Inherited Members
Data Fields inherited from BaseTimer< TTimerType >
TPeriod | period
| The period of the timer.
TStorage | storage = {}
| The storage of the timer.

## Detailed Description

### template<typename TTimerType>
class IntervalTimer< TTimerType >

An interval timer will fire every interval, and will continue to fire until it is deleted.

The callback receives how many times the timer has fired since the last time it fired. It will always try to fire every interval, but in times of severe stress it might be late.

Each Timer-type needs to implement the Elapsed() method, and call the callback if needed.

Setting the period to zero disables the interval. It can be reenabled at any time by calling SetInterval() with a non-zero period.

Definition at line 76 of file timer.h.

## Constructor & Destructor Documentation

## ◆ IntervalTimer()

template<typename TTimerType >

IntervalTimer< TTimerType >::IntervalTimer | ( | const TPeriod | interval,
|  | std::function< void(uint)> | callback
| ) |  |
| inline

Create a new interval timer.

Parameters

  interval | The interval between each callback.
  callback | The callback to call when the interval has passed.

Definition at line 87 of file timer.h.

## Member Function Documentation

## ◆ Elapsed()

template<typename TTimerType >

void IntervalTimer< TTimerType >::Elapsed | ( | TElapsed | delta | ) |
| overrideprivatevirtual

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

Parameters

  delta | Depending on the time type, this is either in milliseconds or in ticks.

Implements BaseTimer< TTimerType >.

## ◆ SetInterval()

template<typename TTimerType >

void IntervalTimer< TTimerType >::SetInterval | ( | const TPeriod | interval,
|  | bool | reset = `true`
| ) |  |
| inline

Set a new interval for the timer.

Parameters

  interval | The interval between each callback.
  reset | Whether to reset the timer to zero.

Definition at line 99 of file timer.h.

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

- src/timer/timer.h