OpenTTD Source  20240919-master-gdf0233f4c2
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 <http://www.gnu.org/licenses/>.
6  */
7 
10 #ifndef TIMER_GAME_REALTIME_H
11 #define TIMER_GAME_REALTIME_H
12 
13 #include <chrono>
14 
29 public:
30  enum PeriodFlags {
34  };
35 
36  struct TPeriod {
37  std::chrono::milliseconds period;
38  PeriodFlags flag;
39 
40  TPeriod(std::chrono::milliseconds period, PeriodFlags flag) : period(period), flag(flag) {}
41 
42  bool operator < (const TPeriod &other) const
43  {
44  if (this->flag != other.flag) return this->flag < other.flag;
45  return this->period < other.period;
46  }
47 
48  bool operator == (const TPeriod &other) const
49  {
50  return this->flag == other.flag && this->period == other.period;
51  }
52  };
53  using TElapsed = std::chrono::milliseconds;
54  struct TStorage {
55  std::chrono::milliseconds elapsed;
56  };
57 };
58 
59 #endif /* TIMER_GAME_REALTIME_H */
TimerGameRealtime::ALWAYS
@ ALWAYS
Always run, even when paused.
Definition: timer_game_realtime.h:31
TimerGameRealtime::UNPAUSED
@ UNPAUSED
Only run when not paused.
Definition: timer_game_realtime.h:32
TimerGameRealtime
Timer that represents real time for game-related purposes.
Definition: timer_game_realtime.h:28
TimerGameRealtime::PeriodFlags
PeriodFlags
Definition: timer_game_realtime.h:30
TimerGameRealtime::TPeriod
Definition: timer_game_realtime.h:36
TimerGameRealtime::TStorage
Definition: timer_game_realtime.h:54
TimerGameRealtime::AUTOSAVE
@ AUTOSAVE
Only run when not paused or there was a Command executed recently.
Definition: timer_game_realtime.h:33