mirror of https://github.com/OpenTTD/OpenTTD
Change: Only run vehicle calendar day proc when TimerGameCalendar::date_fract has advanced
parent
a48fb75947
commit
724266616d
|
@ -1472,11 +1472,12 @@ void StateGameLoop()
|
||||||
|
|
||||||
BasePersistentStorageArray::SwitchMode(PSM_ENTER_GAMELOOP);
|
BasePersistentStorageArray::SwitchMode(PSM_ENTER_GAMELOOP);
|
||||||
AnimateAnimatedTiles();
|
AnimateAnimatedTiles();
|
||||||
TimerManager<TimerGameCalendar>::Elapsed(1);
|
if (TimerManager<TimerGameCalendar>::Elapsed(1)) {
|
||||||
|
RunVehicleCalendarDayProc();
|
||||||
|
}
|
||||||
TimerManager<TimerGameEconomy>::Elapsed(1);
|
TimerManager<TimerGameEconomy>::Elapsed(1);
|
||||||
TimerManager<TimerGameTick>::Elapsed(1);
|
TimerManager<TimerGameTick>::Elapsed(1);
|
||||||
RunTileLoop();
|
RunTileLoop();
|
||||||
RunVehicleCalendarDayProc();
|
|
||||||
CallVehicleTicks();
|
CallVehicleTicks();
|
||||||
CallLandscapeTick();
|
CallLandscapeTick();
|
||||||
BasePersistentStorageArray::SwitchMode(PSM_LEAVE_GAMELOOP);
|
BasePersistentStorageArray::SwitchMode(PSM_LEAVE_GAMELOOP);
|
||||||
|
|
|
@ -94,27 +94,27 @@ void TimeoutTimer<TimerGameCalendar>::Elapsed(TimerGameCalendar::TElapsed trigge
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
void TimerManager<TimerGameCalendar>::Elapsed([[maybe_unused]] TimerGameCalendar::TElapsed delta)
|
bool TimerManager<TimerGameCalendar>::Elapsed([[maybe_unused]] TimerGameCalendar::TElapsed delta)
|
||||||
{
|
{
|
||||||
assert(delta == 1);
|
assert(delta == 1);
|
||||||
|
|
||||||
if (_game_mode == GM_MENU) return;
|
if (_game_mode == GM_MENU) return false;
|
||||||
|
|
||||||
/* If calendar day progress is frozen, don't try to advance time. */
|
/* If calendar day progress is frozen, don't try to advance time. */
|
||||||
if (_settings_game.economy.minutes_per_calendar_year == CalendarTime::FROZEN_MINUTES_PER_YEAR) return;
|
if (_settings_game.economy.minutes_per_calendar_year == CalendarTime::FROZEN_MINUTES_PER_YEAR) return false;
|
||||||
|
|
||||||
/* If we are using a non-default calendar progression speed, we need to check the sub_date_fract before updating date_fract. */
|
/* If we are using a non-default calendar progression speed, we need to check the sub_date_fract before updating date_fract. */
|
||||||
if (_settings_game.economy.minutes_per_calendar_year != CalendarTime::DEF_MINUTES_PER_YEAR) {
|
if (_settings_game.economy.minutes_per_calendar_year != CalendarTime::DEF_MINUTES_PER_YEAR) {
|
||||||
TimerGameCalendar::sub_date_fract++;
|
TimerGameCalendar::sub_date_fract++;
|
||||||
|
|
||||||
/* Check if we are ready to increment date_fract */
|
/* Check if we are ready to increment date_fract */
|
||||||
if (TimerGameCalendar::sub_date_fract < (Ticks::DAY_TICKS * _settings_game.economy.minutes_per_calendar_year) / CalendarTime::DEF_MINUTES_PER_YEAR) return;
|
if (TimerGameCalendar::sub_date_fract < (Ticks::DAY_TICKS * _settings_game.economy.minutes_per_calendar_year) / CalendarTime::DEF_MINUTES_PER_YEAR) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
TimerGameCalendar::date_fract++;
|
TimerGameCalendar::date_fract++;
|
||||||
|
|
||||||
/* Check if we entered a new day. */
|
/* Check if we entered a new day. */
|
||||||
if (TimerGameCalendar::date_fract < Ticks::DAY_TICKS) return;
|
if (TimerGameCalendar::date_fract < Ticks::DAY_TICKS) return true;
|
||||||
TimerGameCalendar::date_fract = 0;
|
TimerGameCalendar::date_fract = 0;
|
||||||
TimerGameCalendar::sub_date_fract = 0;
|
TimerGameCalendar::sub_date_fract = 0;
|
||||||
|
|
||||||
|
@ -160,6 +160,8 @@ void TimerManager<TimerGameCalendar>::Elapsed([[maybe_unused]] TimerGameCalendar
|
||||||
days_this_year = TimerGameCalendar::IsLeapYear(TimerGameCalendar::year) ? CalendarTime::DAYS_IN_LEAP_YEAR : CalendarTime::DAYS_IN_YEAR;
|
days_this_year = TimerGameCalendar::IsLeapYear(TimerGameCalendar::year) ? CalendarTime::DAYS_IN_LEAP_YEAR : CalendarTime::DAYS_IN_YEAR;
|
||||||
TimerGameCalendar::date -= days_this_year;
|
TimerGameCalendar::date -= days_this_year;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WITH_ASSERT
|
#ifdef WITH_ASSERT
|
||||||
|
|
|
@ -121,14 +121,14 @@ void TimeoutTimer<TimerGameEconomy>::Elapsed(TimerGameEconomy::TElapsed trigger)
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
void TimerManager<TimerGameEconomy>::Elapsed([[maybe_unused]] TimerGameEconomy::TElapsed delta)
|
bool TimerManager<TimerGameEconomy>::Elapsed([[maybe_unused]] TimerGameEconomy::TElapsed delta)
|
||||||
{
|
{
|
||||||
assert(delta == 1);
|
assert(delta == 1);
|
||||||
|
|
||||||
if (_game_mode == GM_MENU) return;
|
if (_game_mode == GM_MENU) return false;
|
||||||
|
|
||||||
TimerGameEconomy::date_fract++;
|
TimerGameEconomy::date_fract++;
|
||||||
if (TimerGameEconomy::date_fract < Ticks::DAY_TICKS) return;
|
if (TimerGameEconomy::date_fract < Ticks::DAY_TICKS) return true;
|
||||||
TimerGameEconomy::date_fract = 0;
|
TimerGameEconomy::date_fract = 0;
|
||||||
|
|
||||||
/* increase day counter */
|
/* increase day counter */
|
||||||
|
@ -187,6 +187,8 @@ void TimerManager<TimerGameEconomy>::Elapsed([[maybe_unused]] TimerGameEconomy::
|
||||||
for (Vehicle *v : Vehicle::Iterate()) v->ShiftDates(-days_this_year);
|
for (Vehicle *v : Vehicle::Iterate()) v->ShiftDates(-days_this_year);
|
||||||
for (LinkGraph *lg : LinkGraph::Iterate()) lg->ShiftDates(-days_this_year);
|
for (LinkGraph *lg : LinkGraph::Iterate()) lg->ShiftDates(-days_this_year);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WITH_ASSERT
|
#ifdef WITH_ASSERT
|
||||||
|
|
|
@ -54,11 +54,13 @@ void TimeoutTimer<TimerGameRealtime>::Elapsed(TimerGameRealtime::TElapsed delta)
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
void TimerManager<TimerGameRealtime>::Elapsed(TimerGameRealtime::TElapsed delta)
|
bool TimerManager<TimerGameRealtime>::Elapsed(TimerGameRealtime::TElapsed delta)
|
||||||
{
|
{
|
||||||
for (auto timer : TimerManager<TimerGameRealtime>::GetTimers()) {
|
for (auto timer : TimerManager<TimerGameRealtime>::GetTimers()) {
|
||||||
timer->Elapsed(delta);
|
timer->Elapsed(delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WITH_ASSERT
|
#ifdef WITH_ASSERT
|
||||||
|
|
|
@ -51,13 +51,15 @@ void TimeoutTimer<TimerGameTick>::Elapsed(TimerGameTick::TElapsed delta)
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
void TimerManager<TimerGameTick>::Elapsed(TimerGameTick::TElapsed delta)
|
bool TimerManager<TimerGameTick>::Elapsed(TimerGameTick::TElapsed delta)
|
||||||
{
|
{
|
||||||
TimerGameTick::counter++;
|
TimerGameTick::counter++;
|
||||||
|
|
||||||
for (auto timer : TimerManager<TimerGameTick>::GetTimers()) {
|
for (auto timer : TimerManager<TimerGameTick>::GetTimers()) {
|
||||||
timer->Elapsed(delta);
|
timer->Elapsed(delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WITH_ASSERT
|
#ifdef WITH_ASSERT
|
||||||
|
|
|
@ -78,8 +78,9 @@ public:
|
||||||
* Call the Elapsed() method of all active timers.
|
* Call the Elapsed() method of all active timers.
|
||||||
*
|
*
|
||||||
* @param value The amount of time that has elapsed.
|
* @param value The amount of time that has elapsed.
|
||||||
|
* @return True iff time has progressed.
|
||||||
*/
|
*/
|
||||||
static void Elapsed(TElapsed value);
|
static bool Elapsed(TElapsed value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -49,7 +49,7 @@ void TimeoutTimer<TimerWindow>::Elapsed(TimerWindow::TElapsed delta)
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
void TimerManager<TimerWindow>::Elapsed(TimerWindow::TElapsed delta)
|
bool TimerManager<TimerWindow>::Elapsed(TimerWindow::TElapsed delta)
|
||||||
{
|
{
|
||||||
/* Make a temporary copy of the timers, as a timer's callback might add/remove other timers. */
|
/* Make a temporary copy of the timers, as a timer's callback might add/remove other timers. */
|
||||||
auto timers = TimerManager<TimerWindow>::GetTimers();
|
auto timers = TimerManager<TimerWindow>::GetTimers();
|
||||||
|
@ -57,6 +57,8 @@ void TimerManager<TimerWindow>::Elapsed(TimerWindow::TElapsed delta)
|
||||||
for (auto timer : timers) {
|
for (auto timer : timers) {
|
||||||
timer->Elapsed(delta);
|
timer->Elapsed(delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WITH_ASSERT
|
#ifdef WITH_ASSERT
|
||||||
|
|
Loading…
Reference in New Issue