OpenTTD Source 20260206-master-g4d4e37dbf1
timer_game_realtime.h
Go to the documentation of this file.
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#ifndef TIMER_GAME_REALTIME_H
11#define TIMER_GAME_REALTIME_H
12
13#include <chrono>
14
29public:
31 enum class Trigger : uint8_t {
35 };
36
37 struct TPeriod {
38 std::chrono::milliseconds period;
39 Trigger trigger;
40
41 TPeriod(std::chrono::milliseconds period, Trigger trigger) : period(period), trigger(trigger) {}
42
43 bool operator < (const TPeriod &other) const
44 {
45 if (this->trigger != other.trigger) return this->trigger < other.trigger;
46 return this->period < other.period;
47 }
48
49 bool operator == (const TPeriod &other) const
50 {
51 return this->trigger == other.trigger && this->period == other.period;
52 }
53 };
54 using TElapsed = std::chrono::milliseconds;
55 struct TStorage {
56 std::chrono::milliseconds elapsed;
57 };
58};
59
60#endif /* TIMER_GAME_REALTIME_H */
Timer that represents real time for game-related purposes.
Trigger
When is the timer supposed to be run.
@ Autosave
Only run when not paused or there was a Command executed recently.
@ Always
Always run, even when paused.
@ Unpaused
Only run when not paused.