OpenTTD Source
20241124-master-g9399a92a4f
|
Template class for all TimerGame based timers. More...
#include <timer_game_common.h>
Data Structures | |
struct | DateTag |
The type to store our dates in. More... | |
struct | TPeriod |
struct | TStorage |
struct | YearMonthDay |
Data structure to convert between Date and triplet (year, month, and day). More... | |
struct | YearTag |
Type for the year, note: 0 based, i.e. More... | |
Public Types | |
enum | Trigger { DAY , WEEK , MONTH , QUARTER , YEAR } |
enum | Priority { NONE , COMPANY , DISASTER , ENGINE , INDUSTRY , STATION , SUBSIDY , TOWN , VEHICLE } |
using | Date = StrongType::Typedef< int32_t, DateTag< T >, StrongType::Compare, StrongType::Integer > |
using | DateFract = uint16_t |
The fraction of a date we're in, i.e. More... | |
using | Year = StrongType::Typedef< int32_t, struct YearTag< T >, StrongType::Compare, StrongType::Integer > |
using | Month = uint8_t |
Type for the month, note: 0 based, i.e. More... | |
using | Day = uint8_t |
Type for the day of the month, note: 1 based, first day of a month is 1. | |
using | TElapsed = uint |
Static Public Member Functions | |
static constexpr bool | IsLeapYear (Year year) |
Checks whether the given year is a leap year or not. More... | |
static YearMonthDay | CalendarConvertDateToYMD (Date date) |
Converts a Date to a Year, Month & Day. More... | |
static Date | CalendarConvertYMDToDate (Year year, Month month, Day day) |
Converts a tuple of Year, Month and Day to a Date. More... | |
static constexpr Year | DateToYear (Date date) |
Calculate the year of a given date. More... | |
static constexpr Date | DateAtStartOfYear (Year year) |
Calculate the date of the first day of a given year. More... | |
Template class for all TimerGame based timers.
As Calendar and Economy are very similar, this class is used to share code between them.
IntervalTimer and TimeoutTimer based on this Timer are a bit unusual, as their count is always one. You create those timers based on a transition: a new day, a new month or a new year.
Additionally, you need to set a priority. To ensure deterministic behaviour, events are executed in priority. It is important that if you assign NONE, you do not use Random() in your callback. Other than that, make sure you only set one callback per priority.
For example: IntervalTimer<TimerGameCalendar>({TimerGameCalendar::DAY, TimerGameCalendar::Priority::NONE}, [](uint count) {});
Definition at line 31 of file timer_game_common.h.
The fraction of a date we're in, i.e.
the number of ticks since the last date changeover.
Definition at line 38 of file timer_game_common.h.
Type for the month, note: 0 based, i.e.
0 = January, 11 = December.
Definition at line 44 of file timer_game_common.h.
enum TimerGame::Priority |
Enumerator | |
---|---|
NONE | These timers can be executed in any order; there is no Random() in them, so order is not relevant. |
Definition at line 105 of file timer_game_common.h.
|
static |
Converts a Date to a Year, Month & Day.
date | the date to convert from |
Definition at line 64 of file timer_game_common.cpp.
|
static |
Converts a tuple of Year, Month and Day to a Date.
year | is a number between 0..MAX_YEAR |
month | is a number between 0..11 |
day | is a number between 1..31 |
Definition at line 122 of file timer_game_common.cpp.
References _accum_days_for_month.
|
inlinestaticconstexpr |
Calculate the date of the first day of a given year.
year | the year to get the first day of. |
Definition at line 88 of file timer_game_common.h.
|
inlinestaticconstexpr |
Calculate the year of a given date.
date | The date to consider. |
Definition at line 77 of file timer_game_common.h.
|
inlinestaticconstexpr |
Checks whether the given year is a leap year or not.
year | The year to check. |
year
is a leap year, otherwise false. Definition at line 63 of file timer_game_common.h.