From 898dadadb2a34b589f4d43f65a146c81b674e502 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Fri, 9 Dec 2022 00:33:32 +0000 Subject: [PATCH] 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. --- src/engine.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/engine.cpp b/src/engine.cpp index a55fac9b7e..6c75ee3e74 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -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); + } } }