Replace day length scaled tick macros with global variables.

This is to avoid needing to expensively re-calculate them all the time.
Instead update them by incrementing.
This commit is contained in:
Jonathan G Rennison
2016-09-10 00:32:00 +01:00
parent d733955d33
commit 375b069f82
16 changed files with 54 additions and 27 deletions

View File

@@ -30,6 +30,8 @@ Date _date; ///< Current date in days (day counter)
DateFract _date_fract; ///< Fractional part of the day.
uint16 _tick_counter; ///< Ever incrementing (and sometimes wrapping) tick counter for setting off various events
uint8 _tick_skip_counter; ///< Counter for ticks, when only vehicles are moving and nothing else happens
uint32 _scaled_tick_counter; ///< Tick counter in daylength-scaled ticks
DateTicksScaled _scaled_date_ticks; ///< Date as ticks in daylength-scaled ticks
/**
* Set the date.
@@ -47,6 +49,13 @@ void SetDate(Date date, DateFract fract)
ConvertDateToYMD(date, &ymd);
_cur_year = ymd.year;
_cur_month = ymd.month;
SetScaledTickVariables();
}
void SetScaledTickVariables()
{
_scaled_date_ticks = ((((DateTicksScaled)_date * DAY_TICKS) + _date_fract) * _settings_game.economy.day_length_factor) + _tick_skip_counter;
_scaled_tick_counter = (((uint32)_tick_counter) * _settings_game.economy.day_length_factor) + _tick_skip_counter;
}
#define M(a, b) ((a << 5) | b)