OpenTTD Source 20261112-master-gbcbec5e63f
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
48 constexpr auto operator<=>(const TPeriod &other) const noexcept
49 {
50 if (this->trigger != other.trigger) return this->trigger <=> other.trigger;
51 return this->period <=> other.period;
52 }
53
59 constexpr bool operator==(const TPeriod &other) const noexcept
60 {
61 return this->trigger == other.trigger && this->period == other.period;
62 }
63 };
64 using TElapsed = std::chrono::milliseconds;
65 struct TStorage {
66 std::chrono::milliseconds elapsed;
67 };
68};
69
70#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.
constexpr bool operator==(const TPeriod &other) const noexcept
Compare with another instance of this class.
constexpr auto operator<=>(const TPeriod &other) const noexcept
Compare with another instance of this class.