From 156f98ba066d576b6b14cf125eca44f6757e1e8b Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Tue, 13 May 2025 01:23:27 +0100 Subject: [PATCH] Fix #14256, dfd9fbf873: Company finance windows not updated when paused. (#14258) Refresh company finance windows via a WindowTimer instead of in game loop. As the invalidation affects multiple windows this is a global timer instead of window-specific. --- src/company_cmd.cpp | 8 ++++---- src/company_gui.h | 1 - src/openttd.cpp | 2 -- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index f5bb4d9433..b83d08d8e5 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -39,6 +39,7 @@ #include "timer/timer.h" #include "timer/timer_game_economy.h" #include "timer/timer_game_tick.h" +#include "timer/timer_window.h" #include "widgets/statusbar_widget.h" @@ -219,8 +220,7 @@ void InvalidateCompanyWindows(const Company *company) /** * Refresh all company finance windows previously marked dirty. */ -void InvalidateCompanyWindows() -{ +static const IntervalTimer invalidate_company_windows_interval(std::chrono::milliseconds(1), [](auto) { for (CompanyID cid : _dirty_company_finances) { if (cid == _local_company) SetWindowWidgetDirty(WC_STATUS_BAR, 0, WID_S_RIGHT); Window *w = FindWindowById(WC_FINANCES, cid); @@ -233,8 +233,8 @@ void InvalidateCompanyWindows() } SetWindowWidgetDirty(WC_COMPANY, cid, WID_C_DESC_COMPANY_VALUE); } - _dirty_company_finances = {}; -} + _dirty_company_finances.Reset(); +}); /** * Get the amount of money that a company has available, or INT64_MAX diff --git a/src/company_gui.h b/src/company_gui.h index 0e951eb5c7..f6149b05fb 100644 --- a/src/company_gui.h +++ b/src/company_gui.h @@ -23,7 +23,6 @@ void ShowCompanyFinances(CompanyID company); void ShowCompany(CompanyID company); void InvalidateCompanyWindows(const Company *c); -void InvalidateCompanyWindows(); void CloseCompanyWindows(CompanyID company); void DirtyCompanyInfrastructureWindows(CompanyID company); diff --git a/src/openttd.cpp b/src/openttd.cpp index a87e1d0353..10ea0951e0 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -1244,7 +1244,6 @@ void StateGameLoop() CallWindowGameTickEvent(); NewsLoop(); - InvalidateCompanyWindows(); } else { if (_debug_desync_level > 2 && TimerGameEconomy::date_fract == 0 && (TimerGameEconomy::date.base() & 0x1F) == 0) { /* Save the desync savegame if needed. */ @@ -1281,7 +1280,6 @@ void StateGameLoop() CallWindowGameTickEvent(); NewsLoop(); - InvalidateCompanyWindows(); cur_company.Restore(); }