Change: Mark build/autoreplace windows dirty less often in monthy loop.

These window classes were marked dirty for every engine that had
reliability calculated every month.
This commit is contained in:
Peter Nelson 2022-12-09 00:33:32 +00:00 committed by PeterN
parent 85814b29d4
commit 898dadadb2
1 changed files with 11 additions and 2 deletions

View File

@ -613,8 +613,7 @@ static void CalcEngineReliability(Engine *e)
ClearLastVariant(e->index, e->type);
AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
}
SetWindowClassesDirty(WC_BUILD_VEHICLE); // Update to show the new reliability
SetWindowClassesDirty(WC_REPLACE_VEHICLE);
}
/** Compute the value for #_year_engine_aging_stops. */
@ -716,6 +715,9 @@ void StartupEngines()
/* Invalidate any open purchase lists */
InvalidateWindowClassesData(WC_BUILD_VEHICLE);
SetWindowClassesDirty(WC_BUILD_VEHICLE);
SetWindowClassesDirty(WC_REPLACE_VEHICLE);
}
/**
@ -1031,11 +1033,13 @@ static void NewVehicleAvailable(Engine *e)
void EnginesMonthlyLoop()
{
if (_cur_year < _year_engine_aging_stops) {
bool refresh = false;
for (Engine *e : Engine::Iterate()) {
/* Age the vehicle */
if ((e->flags & ENGINE_AVAILABLE) && e->age != MAX_DAY) {
e->age++;
CalcEngineReliability(e);
refresh = true;
}
/* Do not introduce invalid engines */
@ -1062,6 +1066,11 @@ void EnginesMonthlyLoop()
}
InvalidateWindowClassesData(WC_BUILD_VEHICLE); // rebuild the purchase list (esp. when sorted by reliability)
if (refresh) {
SetWindowClassesDirty(WC_BUILD_VEHICLE);
SetWindowClassesDirty(WC_REPLACE_VEHICLE);
}
}
}