From 147eb898835032fd7f8059c77232f27bf737058b Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Sun, 10 Aug 2025 11:26:40 +0200 Subject: [PATCH] Keep ride list sorted (#24943) --- src/openrct2-ui/windows/RideList.cpp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/openrct2-ui/windows/RideList.cpp b/src/openrct2-ui/windows/RideList.cpp index 07251d4ca4..5672ecb23e 100644 --- a/src/openrct2-ui/windows/RideList.cpp +++ b/src/openrct2-ui/windows/RideList.cpp @@ -206,14 +206,6 @@ namespace OpenRCT2::Ui::Windows Invalidate(); height = min_height; } - - // Refreshing the list can be a very intensive operation - // owing to its use of ride_has_any_track_elements(). - // This makes sure it's only refreshed every 64 ticks. - if (!(gCurrentRealTimeTicks & 0x3f)) - { - RefreshList(); - } } /** @@ -237,7 +229,7 @@ namespace OpenRCT2::Ui::Windows { _windowListSortDescending ^= true; } - RefreshList(); + SortList(); break; case WIDX_HEADER_OTHER: if (list_information_type != _windowRideListInformationType) @@ -249,7 +241,7 @@ namespace OpenRCT2::Ui::Windows { _windowListSortDescending ^= true; } - RefreshList(); + SortList(); break; case WIDX_TAB_1: case WIDX_TAB_2: @@ -385,7 +377,7 @@ namespace OpenRCT2::Ui::Windows if (list_information_type != INFORMATION_TYPE_STATUS) { list_information_type = _windowRideListInformationType; - RefreshList(); + SortList(); } } } @@ -402,6 +394,11 @@ namespace OpenRCT2::Ui::Windows Invalidate(); } + void OnPeriodicUpdate() override + { + SortList(); + } + /** * * rct2: 0x006B35A1 @@ -857,7 +854,7 @@ namespace OpenRCT2::Ui::Windows } /** - * Used in RefreshList() to handle the sorting of the list. + * Used in SortList() to handle the sorting of the list. * Uses a lambda function (predicate) as exit criteria for the algorithm. */ template @@ -912,6 +909,12 @@ namespace OpenRCT2::Ui::Windows _rideList.push_back(std::move(entry)); } + selected_list_item = -1; + SortList(); + } + + void SortList() + { switch (list_information_type) { case INFORMATION_TYPE_STATUS: