Remove costly recalculation of a date format we already have.

(cherry picked from commit 6aca18d18252f1c2f6d4a215999b7d7afb7df813)

See #36
pull/59/head
keldorkatarn 6 years ago committed by Jonathan G Rennison
parent 9ab2b8fa3e
commit 4955996b35

@ -1324,9 +1324,7 @@ DEF_CONSOLE_CMD(ConGetDate)
return true;
}
YearMonthDay ymd;
ConvertDateToYMD(_date, &ymd);
IConsolePrintF(CC_DEFAULT, "Date: %d-%d-%d", ymd.day, ymd.month + 1, ymd.year);
IConsolePrintF(CC_DEFAULT, "Date: %d-%d-%d", _cur_date_ymd.day, _cur_date_ymd.month + 1, _cur_date_ymd.year);
return true;
}

@ -364,7 +364,7 @@ char *CrashLog::FillCrashLog(char *buffer, const char *last) const
YearMonthDay ymd;
ConvertDateToYMD(_date, &ymd);
buffer += seprintf(buffer, last, "In game date: %i-%02i-%02i (%i, %i)\n\n", ymd.year, ymd.month + 1, ymd.day, _date_fract, _tick_skip_counter);
buffer += seprintf(buffer, last, "In game date: %i-%02i-%02i (%i, %i)\n\n", _cur_date_ymd.year, _cur_date_ymd.month + 1, _cur_date_ymd.day, _date_fract, _tick_skip_counter);
buffer = this->LogError(buffer, last, CrashLog::message);

@ -27,6 +27,7 @@
Year _cur_year; ///< Current year, starting at 0
Month _cur_month; ///< Current month (0..11)
YearMonthDay _cur_date_ymd; ///< Current date as YearMonthDay struct
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
@ -51,6 +52,7 @@ void SetDate(Date date, DateFract fract)
ConvertDateToYMD(date, &ymd);
_cur_year = ymd.year;
_cur_month = ymd.month;
_cur_date_ymd = ymd;
SetScaledTickVariables();
}
@ -319,6 +321,7 @@ void IncreaseDate()
bool new_year = ymd.year != _cur_year;
/* update internal variables before calling the daily/monthly/yearly loops */
_cur_date_ymd = ymd;
_cur_month = ymd.month;
_cur_year = ymd.year;

@ -16,6 +16,7 @@
extern Year _cur_year;
extern Month _cur_month;
extern YearMonthDay _cur_date_ymd;
extern Date _date;
extern DateFract _date_fract;
extern uint16 _tick_counter;

@ -571,9 +571,7 @@ byte GetSnowLine()
{
if (_snow_line == NULL) return _settings_game.game_creation.snow_line_height;
YearMonthDay ymd;
ConvertDateToYMD(_date, &ymd);
return _snow_line->table[ymd.month][ymd.day];
return _snow_line->table[_cur_date_ymd.month][_cur_date_ymd.day];
}
/**

@ -5780,10 +5780,8 @@ bool GetGlobalVariable(byte param, uint32 *value, const GRFFile *grffile)
return true;
case 0x02: { // detailed date information: month of year (bit 0-7), day of month (bit 8-12), leap year (bit 15), day of year (bit 16-24)
YearMonthDay ymd;
ConvertDateToYMD(_date, &ymd);
Date start_of_year = ConvertYMDToDate(ymd.year, 0, 1);
*value = ymd.month | (ymd.day - 1) << 8 | (IsLeapYear(ymd.year) ? 1 << 15 : 0) | (_date - start_of_year) << 16;
Date start_of_year = ConvertYMDToDate(_cur_date_ymd.year, 0, 1);
*value = _cur_date_ymd.month | (_cur_date_ymd.day - 1) << 8 | (IsLeapYear(_cur_date_ymd.year) ? 1 << 15 : 0) | (_date - start_of_year) << 16;
return true;
}

@ -849,9 +849,7 @@ static bool LoadOldIndustry(LoadgameState *ls, int num)
if (i->type > 0x06) i->type++; // Printing Works were added
if (i->type == 0x0A) i->type = 0x12; // Iron Ore Mine has different ID
YearMonthDay ymd;
ConvertDateToYMD(_date, &ymd);
i->last_prod_year = ymd.year;
i->last_prod_year = _cur_date_ymd.year;
i->random_colour = RemapTTOColour(i->random_colour);
}

@ -146,9 +146,6 @@ struct SubsidyListWindow : Window {
{
if (widget != WID_SUL_PANEL) return;
YearMonthDay ymd;
ConvertDateToYMD(_date, &ymd);
int right = r.right - WD_FRAMERECT_RIGHT;
int y = r.top + WD_FRAMERECT_TOP;
int x = r.left + WD_FRAMERECT_LEFT;
@ -167,7 +164,7 @@ struct SubsidyListWindow : Window {
if (IsInsideMM(pos, 0, cap)) {
/* Displays the two offered towns */
SetupSubsidyDecodeParam(s, true);
SetDParam(7, _date - ymd.day + s->remaining * 32);
SetDParam(7, _date - _cur_date_ymd.day + s->remaining * 32);
DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_SUBSIDIES_OFFERED_FROM_TO);
}
pos++;
@ -191,7 +188,7 @@ struct SubsidyListWindow : Window {
if (IsInsideMM(pos, 0, cap)) {
SetupSubsidyDecodeParam(s, true);
SetDParam(7, s->awarded);
SetDParam(8, _date - ymd.day + s->remaining * 32);
SetDParam(8, _date - _cur_date_ymd.day + s->remaining * 32);
/* Displays the two connected stations */
DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_SUBSIDIES_SUBSIDISED_FROM_TO);

Loading…
Cancel
Save