Fix: Don't allow right-click to close world generation progress window. (#13084)
[openttd-github.git] / src / timer / timer_game_realtime.h
blob22432501b31ae0f8b5f75521533ede0fd1dcf9ce
1 /*
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/>.
6 */
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
13 #include <chrono>
15 /**
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 {
29 public:
30 enum PeriodFlags {
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.
36 struct TPeriod {
37 std::chrono::milliseconds period;
38 PeriodFlags flag;
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;
54 struct TStorage {
55 std::chrono::milliseconds elapsed;
59 #endif /* TIMER_GAME_REALTIME_H */