Codechange: make date-related variables constexpr (#11129)

This hints the compiler even more to result math-related questions
compile-time.
This commit is contained in:
Patric Stout 2023-07-12 15:15:24 +02:00 committed by GitHub
parent 7ef6e99083
commit 97138acc8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 13 deletions

View File

@ -45,18 +45,18 @@ static const int INDUSTRY_CUT_TREE_TICKS = INDUSTRY_PRODUCE_TICKS * 2; ///< cyc
*/ */
/** The minimum starting year/base year of the original TTD */ /** The minimum starting year/base year of the original TTD */
static const TimerGameCalendar::Year ORIGINAL_BASE_YEAR = 1920; static constexpr TimerGameCalendar::Year ORIGINAL_BASE_YEAR = 1920;
/** The original ending year */ /** The original ending year */
static const TimerGameCalendar::Year ORIGINAL_END_YEAR = 2051; static constexpr TimerGameCalendar::Year ORIGINAL_END_YEAR = 2051;
/** The maximum year of the original TTD */ /** The maximum year of the original TTD */
static const TimerGameCalendar::Year ORIGINAL_MAX_YEAR = 2090; static constexpr TimerGameCalendar::Year ORIGINAL_MAX_YEAR = 2090;
/** /**
* Calculate the date of the first day of a given year. * Calculate the date of the first day of a given year.
* @param year the year to get the first day of. * @param year the year to get the first day of.
* @return the date. * @return the date.
*/ */
static inline TimerGameCalendar::Date DateAtStartOfYear(TimerGameCalendar::Year year) static constexpr TimerGameCalendar::Date DateAtStartOfYear(TimerGameCalendar::Year year)
{ {
uint number_of_leap_years = (year == 0) ? 0 : ((year - 1) / 4 - (year - 1) / 100 + (year - 1) / 400 + 1); uint number_of_leap_years = (year == 0) ? 0 : ((year - 1) / 4 - (year - 1) / 100 + (year - 1) / 400 + 1);
@ -66,27 +66,27 @@ static inline TimerGameCalendar::Date DateAtStartOfYear(TimerGameCalendar::Year
/** /**
* The date of the first day of the original base year. * The date of the first day of the original base year.
*/ */
static const TimerGameCalendar::Date DAYS_TILL_ORIGINAL_BASE_YEAR = DateAtStartOfYear(ORIGINAL_BASE_YEAR); static constexpr TimerGameCalendar::Date DAYS_TILL_ORIGINAL_BASE_YEAR = DateAtStartOfYear(ORIGINAL_BASE_YEAR);
/** The absolute minimum & maximum years in OTTD */ /** The absolute minimum & maximum years in OTTD */
static const TimerGameCalendar::Year MIN_YEAR = 0; static constexpr TimerGameCalendar::Year MIN_YEAR = 0;
/** The default starting year */ /** The default starting year */
static const TimerGameCalendar::Year DEF_START_YEAR = 1950; static constexpr TimerGameCalendar::Year DEF_START_YEAR = 1950;
/** The default scoring end year */ /** The default scoring end year */
static const TimerGameCalendar::Year DEF_END_YEAR = ORIGINAL_END_YEAR - 1; static constexpr TimerGameCalendar::Year DEF_END_YEAR = ORIGINAL_END_YEAR - 1;
/** /**
* MAX_YEAR, nicely rounded value of the number of years that can * MAX_YEAR, nicely rounded value of the number of years that can
* be encoded in a single 32 bits date, about 2^31 / 366 years. * be encoded in a single 32 bits date, about 2^31 / 366 years.
*/ */
static const TimerGameCalendar::Year MAX_YEAR = 5000000; static constexpr TimerGameCalendar::Year MAX_YEAR = 5000000;
/** The date of the last day of the max year. */ /** The date of the last day of the max year. */
static const TimerGameCalendar::Date MAX_DATE = DateAtStartOfYear(MAX_YEAR + 1) - 1; static constexpr TimerGameCalendar::Date MAX_DATE = DateAtStartOfYear(MAX_YEAR + 1) - 1;
static const TimerGameCalendar::Year INVALID_YEAR = -1; ///< Representation of an invalid year static constexpr TimerGameCalendar::Year INVALID_YEAR = -1; ///< Representation of an invalid year
static const TimerGameCalendar::Date INVALID_DATE = -1; ///< Representation of an invalid date static constexpr TimerGameCalendar::Date INVALID_DATE = -1; ///< Representation of an invalid date
static const Ticks INVALID_TICKS = -1; ///< Representation of an invalid number of ticks static constexpr Ticks INVALID_TICKS = -1; ///< Representation of an invalid number of ticks
#endif /* DATE_TYPE_H */ #endif /* DATE_TYPE_H */