OpenTTD Source  20241124-master-g9399a92a4f
timer_game_tick.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_TICK_H
11 #define TIMER_GAME_TICK_H
12 
13 #include "../gfx_type.h"
14 
15 #include <chrono>
16 
23 public:
24  using Ticks = int32_t;
25  using TickCounter = uint64_t;
26 
27  enum Priority {
28  NONE,
29 
30  /* For all other priorities, the order is important.
31  * For safety, you can only setup a single timer on a single priority. */
32  COMPETITOR_TIMEOUT,
33  };
34 
35  struct TPeriod {
36  Priority priority;
37  uint value;
38 
39  TPeriod(Priority priority, uint value) : priority(priority), value(value)
40  {}
41 
42  bool operator < (const TPeriod &other) const
43  {
44  /* Sort by priority before value, such that changes in value for priorities other than NONE do not change the container order */
45  if (this->priority != other.priority) return this->priority < other.priority;
46  return this->value < other.value;
47  }
48 
49  bool operator == (const TPeriod &other) const
50  {
51  return this->priority == other.priority && this->value == other.value;
52  }
53  };
54 
55  using TElapsed = uint;
56  struct TStorage {
57  uint elapsed;
58  };
59 
61 };
62 
66 class Ticks {
67 public:
68  static constexpr TimerGameTick::Ticks INVALID_TICKS = -1;
69 
75  static constexpr TimerGameTick::Ticks DAY_TICKS = 74;
77 
78  static constexpr TimerGameTick::Ticks STATION_RATING_TICKS = 185;
81  static constexpr TimerGameTick::Ticks CARGO_AGING_TICKS = 185;
83  static constexpr TimerGameTick::Ticks TOWN_GROWTH_TICKS = 70;
85 };
86 
87 #endif /* TIMER_GAME_TICK_H */
Storage class for Ticks constants.
static constexpr TimerGameTick::Ticks DAY_TICKS
1 day is 74 ticks; TimerGameCalendar::date_fract used to be uint16_t and incremented by 885.
static constexpr TimerGameTick::Ticks INDUSTRY_CUT_TREE_TICKS
Cycle duration for lumber mill's extra action.
static constexpr TimerGameTick::Ticks INVALID_TICKS
Representation of an invalid number of ticks.
static constexpr TimerGameTick::Ticks STATION_LINKGRAPH_TICKS
Cycle duration for cleaning dead links.
static constexpr TimerGameTick::Ticks CARGO_AGING_TICKS
Cycle duration for aging cargo.
static constexpr TimerGameTick::Ticks INDUSTRY_PRODUCE_TICKS
Cycle duration for industry production.
static constexpr TimerGameTick::Ticks TOWN_GROWTH_TICKS
Cycle duration for towns trying to grow (this originates from the size of the town array in TTD).
static constexpr TimerGameTick::Ticks TICKS_PER_SECOND
Estimation of how many ticks fit in a single second.
static constexpr TimerGameTick::Ticks STATION_ACCEPTANCE_TICKS
Cycle duration for updating station acceptance.
static constexpr TimerGameTick::Ticks STATION_RATING_TICKS
Cycle duration for updating station rating.
Timer that represents the game-ticks.
uint64_t TickCounter
The type that the tick counter is stored in.
static TickCounter counter
Monotonic counter, in ticks, since start of game.
@ NONE
These timers can be executed in any order; the order is not relevant.
int32_t Ticks
The type to store ticks in.
static const uint MILLISECONDS_PER_TICK
The number of milliseconds per game tick.
Definition: gfx_type.h:325