2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 /** @file timer_game_realtime.h Definition of the real time game-timer */
10 #ifndef TIMER_GAME_REALTIME_H
11 #define TIMER_GAME_REALTIME_H
16 * Timer that represents real time for game-related purposes.
18 * For pausing, there are several modes:
19 * - Continue to tick during pause (PeriodFlags::ALWAYS).
20 * - Stop ticking when paused (PeriodFlags::UNPAUSED).
21 * - Only tick when unpaused or when there was a Command executed recently (recently: since last autosave) (PeriodFlags::AUTOSAVE).
23 * @note The lowest possible interval is 1ms, although realistic the lowest
24 * interval is 27ms. This timer is only updated when the game-thread makes
25 * a tick, which happens every 27ms.
26 * @note Callbacks are executed in the game-thread.
28 class TimerGameRealtime
{
31 ALWAYS
, ///< Always run, even when paused.
32 UNPAUSED
, ///< Only run when not paused.
33 AUTOSAVE
, ///< Only run when not paused or there was a Command executed recently.
37 std::chrono::milliseconds period
;
40 TPeriod(std::chrono::milliseconds period
, PeriodFlags flag
) : period(period
), flag(flag
) {}
42 bool operator < (const TPeriod
&other
) const
44 if (this->flag
!= other
.flag
) return this->flag
< other
.flag
;
45 return this->period
< other
.period
;
48 bool operator == (const TPeriod
&other
) const
50 return this->flag
== other
.flag
&& this->period
== other
.period
;
53 using TElapsed
= std::chrono::milliseconds
;
55 std::chrono::milliseconds elapsed
;
59 #endif /* TIMER_GAME_REALTIME_H */