Repository: OpenRCT2/OpenRCT2
Pull request #23975: Skip setting page/widgets if we're already on the page
Author: login: AaronVanGeffen
Created: 2025-03-12T11:08:23Z | Merged: 2025-03-12T18:50:20Z

Optimisation from #23590 that should ideally be reviewed separately, hence this PR.

Only affects tabbed windows, so the test vector is limited.


Diff:
diff --git a/src/openrct2-ui/windows/About.cpp b/src/openrct2-ui/windows/About.cpp
index 8d319a374655..c76396c18240 100644
--- a/src/openrct2-ui/windows/About.cpp
+++ b/src/openrct2-ui/windows/About.cpp
@@ -199,6 +199,10 @@ namespace OpenRCT2::Ui::Windows
     private:
         void SetPage(int32_t p)
         {
+            // Skip setting page if we're already on this page, unless we're initialising the window
+            if (page == p && !widgets.empty())
+                return;
+
             page = p;
             frame_no = 0;
             pressed_widgets = 0;
diff --git a/src/openrct2-ui/windows/Cheats.cpp b/src/openrct2-ui/windows/Cheats.cpp
index c71aa0917709..713814a71a93 100644
--- a/src/openrct2-ui/windows/Cheats.cpp
+++ b/src/openrct2-ui/windows/Cheats.cpp
@@ -737,6 +737,10 @@ static StringId window_cheats_page_titles[] = {
     private:
         void SetPage(int32_t p)
         {
+            // Skip setting page if we're already on this page, unless we're initialising the window
+            if (page == p && !widgets.empty())
+                return;
+
             page = p;
             frame_no = 0;
 
diff --git a/src/openrct2-ui/windows/EditorObjectSelection.cpp b/src/openrct2-ui/windows/EditorObjectSelection.cpp
index 285fe17608af..a77227f3262d 100644
--- a/src/openrct2-ui/windows/EditorObjectSelection.cpp
+++ b/src/openrct2-ui/windows/EditorObjectSelection.cpp
@@ -1143,7 +1143,8 @@ namespace OpenRCT2::Ui::Windows
 
         void SetPage(int32_t _page)
         {
-            if (selected_tab == _page)
+            // Skip setting page if we're already on this page, unless we're initialising the window
+            if (selected_tab == _page && !widgets.empty())
                 return;
 
             selected_tab = _page;
diff --git a/src/openrct2-ui/windows/EditorObjectiveOptions.cpp b/src/openrct2-ui/windows/EditorObjectiveOptions.cpp
index d79480a87176..18af75661263 100644
--- a/src/openrct2-ui/windows/EditorObjectiveOptions.cpp
+++ b/src/openrct2-ui/windows/EditorObjectiveOptions.cpp
@@ -303,6 +303,10 @@ namespace OpenRCT2::Ui::Windows
          */
         void SetPage(int32_t newPage)
         {
+            // Skip setting page if we're already on this page, unless we're initialising the window
+            if (page == newPage && !widgets.empty())
+                return;
+
             page = newPage;
             frame_no = 0;
             _rideableRides.clear();
diff --git a/src/openrct2-ui/windows/EditorScenarioOptions.cpp b/src/openrct2-ui/windows/EditorScenarioOptions.cpp
index 22e83575435d..70f92359946e 100644
--- a/src/openrct2-ui/windows/EditorScenarioOptions.cpp
+++ b/src/openrct2-ui/windows/EditorScenarioOptions.cpp
@@ -340,6 +340,10 @@ namespace OpenRCT2::Ui::Windows
 
         void SetPage(int32_t newPage)
         {
+            // Skip setting page if we're already on this page, unless we're initialising the window
+            if (page == newPage && !widgets.empty())
+                return;
+
             page = newPage;
             frame_no = 0;
             hold_down_widgets = window_editor_scenario_options_page_hold_down_widgets[page];
diff --git a/src/openrct2-ui/windows/Finances.cpp b/src/openrct2-ui/windows/Finances.cpp
index e78bdae04671..67bb076ed652 100644
--- a/src/openrct2-ui/windows/Finances.cpp
+++ b/src/openrct2-ui/windows/Finances.cpp
@@ -481,6 +481,10 @@ namespace OpenRCT2::Ui::Windows
 
         void SetPage(int32_t p)
         {
+            // Skip setting page if we're already on this page, unless we're initialising the window
+            if (page == p && !widgets.empty())
+                return;
+
             page = p;
             frame_no = 0;
 
diff --git a/src/openrct2-ui/windows/Guest.cpp b/src/openrct2-ui/windows/Guest.cpp
index b17084df122c..63b3665c48f5 100644
--- a/src/openrct2-ui/windows/Guest.cpp
+++ b/src/openrct2-ui/windows/Guest.cpp
@@ -496,6 +496,10 @@ namespace OpenRCT2::Ui::Windows
                     listen = 1;
             }
 
+            // Skip setting page if we're already on this page, unless we're initialising the window
+            if (page == newPage && !widgets.empty())
+                return;
+
             page = newPage;
             frame_no = 0;
             _riddenRides.clear();
diff --git a/src/openrct2-ui/windows/MapGen.cpp b/src/openrct2-ui/windows/MapGen.cpp
index b13f2b95f440..58635c8c16c5 100644
--- a/src/openrct2-ui/windows/MapGen.cpp
+++ b/src/openrct2-ui/windows/MapGen.cpp
@@ -274,6 +274,10 @@ namespace OpenRCT2::Ui::Windows
 
         void SetPage(int32_t newPage)
         {
+            // Skip setting page if we're already on this page, unless we're initialising the window
+            if (page == newPage && !widgets.empty())
+                return;
+
             page = newPage;
             frame_no = 0;
             RemoveViewport();
diff --git a/src/openrct2-ui/windows/Multiplayer.cpp b/src/openrct2-ui/windows/Multiplayer.cpp
index 74315e14fc64..ba88f18f34ab 100644
--- a/src/openrct2-ui/windows/Multiplayer.cpp
+++ b/src/openrct2-ui/windows/Multiplayer.cpp
@@ -203,6 +203,10 @@ namespace OpenRCT2::Ui::Windows
 
     void MultiplayerWindow::SetPage(int32_t page_number)
     {
+        // Skip setting page if we're already on this page, unless we're initialising the window
+        if (page == page_number && !widgets.empty())
+            return;
+
         _windowInformationSize.reset();
 
         page = page_number;
diff --git a/src/openrct2-ui/windows/NewRide.cpp b/src/openrct2-ui/windows/NewRide.cpp
index 17be1057f7c3..d39234decf86 100644
--- a/src/openrct2-ui/windows/NewRide.cpp
+++ b/src/openrct2-ui/windows/NewRide.cpp
@@ -539,6 +539,10 @@ namespace OpenRCT2::Ui::Windows
 
         void SetPage(NewRideTabId tab)
         {
+            // Skip setting page if we're already on this page, unless we're initialising the window
+            if (_currentTab == tab && !widgets.empty())
+                return;
+
             _currentTab = tab;
             frame_no = 0;
             _newRideVars.HighlightedRide = { kRideTypeNull, kObjectEntryIndexNull };
diff --git a/src/openrct2-ui/windows/Options.cpp b/src/openrct2-ui/windows/Options.cpp
index 69f389554518..fe64a85d0452 100644
--- a/src/openrct2-ui/windows/Options.cpp
+++ b/src/openrct2-ui/windows/Options.cpp
@@ -2107,6 +2107,10 @@ namespace OpenRCT2::Ui::Windows
 
         void SetPage(int32_t p)
         {
+            // Skip setting page if we're already on this page, unless we're initialising the window
+            if (page == p && !widgets.empty())
+                return;
+
             page = p;
             frame_no = 0;
             pressed_widgets = 0;
diff --git a/src/openrct2-ui/windows/Park.cpp b/src/openrct2-ui/windows/Park.cpp
index baf3fe11999c..a2cd0083092d 100644
--- a/src/openrct2-ui/windows/Park.cpp
+++ b/src/openrct2-ui/windows/Park.cpp
@@ -1183,6 +1183,10 @@ namespace OpenRCT2::Ui::Windows
             if (newPage == WINDOW_PARK_PAGE_ENTRANCE && viewport != nullptr && !(viewport->flags & VIEWPORT_FLAG_SOUND_ON))
                 listen = true;
 
+            // Skip setting page if we're already on this page, unless we're initialising the window
+            if (page == newPage && !widgets.empty())
+                return;
+
             page = newPage;
             frame_no = 0;
             _peepAnimationFrame = 0;
diff --git a/src/openrct2-ui/windows/Player.cpp b/src/openrct2-ui/windows/Player.cpp
index 9b97aeeb674d..e770c941d43c 100644
--- a/src/openrct2-ui/windows/Player.cpp
+++ b/src/openrct2-ui/windows/Player.cpp
@@ -209,6 +209,10 @@ namespace OpenRCT2::Ui::Windows
     private:
         void SetPage(int32_t newPage)
         {
+            // Skip setting page if we're already on this page, unless we're initialising the window
+            if (page == newPage && !widgets.empty())
+                return;
+
             int32_t originalPage = page;
 
             page = newPage;
diff --git a/src/openrct2-ui/windows/Research.cpp b/src/openrct2-ui/windows/Research.cpp
index d2a74765912b..6efb34ef2f9d 100644
--- a/src/openrct2-ui/windows/Research.cpp
+++ b/src/openrct2-ui/windows/Research.cpp
@@ -129,6 +129,9 @@ namespace OpenRCT2::Ui::Windows
 
         void SetPage(int32_t newPageIndex)
         {
+            if (page == newPageIndex && !widgets.empty())
+                return;
+
             page = newPageIndex;
             frame_no = 0;
             RemoveViewport();
diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp
index e45a786ef690..864774fbbbb7 100644
--- a/src/openrct2-ui/windows/Ride.cpp
+++ b/src/openrct2-ui/windows/Ride.cpp
@@ -1152,6 +1152,10 @@ namespace OpenRCT2::Ui::Windows
                 && !(viewport->flags & VIEWPORT_FLAG_SOUND_ON))
                 listen = true;
 
+            // Skip setting page if we're already on this page, unless we're initialising the window
+            if (page == newPage && !widgets.empty())
+                return;
+
             page = newPage;
             frame_no = 0;
             picked_peep_frame = 0;
diff --git a/src/openrct2-ui/windows/Staff.cpp b/src/openrct2-ui/windows/Staff.cpp
index 320fd57b0f51..7d4b6e47abfa 100644
--- a/src/openrct2-ui/windows/Staff.cpp
+++ b/src/openrct2-ui/windows/Staff.cpp
@@ -1060,6 +1060,10 @@ namespace OpenRCT2::Ui::Windows
                     listen = 1;
             }
 
+            // Skip setting page if we're already on this page, unless we're initialising the window
+            if (pageNum == page && !widgets.empty())
+                return;
+
             page = pageNum;
             frame_no = 0;
             pressed_widgets = 0;
diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp
index 62c19976a80a..cb3f5a2c32d4 100644
--- a/src/openrct2-ui/windows/TileInspector.cpp
+++ b/src/openrct2-ui/windows/TileInspector.cpp
@@ -1764,6 +1764,10 @@ static uint64_t PageDisabledWidgets[] = {
     private:
         void SetPage(const TileInspectorPage p)
         {
+            // Skip setting page if we're already on this page, unless we're initialising the window
+            if (tileInspectorPage == p && !widgets.empty())
+                return;
+
             Invalidate();
             // subtract current page height, then add new page height
             if (tileInspectorPage != TileInspectorPage::Default)


Reviews:
user: login: Gymnasiast
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-03-12T11:53:20Z
user: login: AaronVanGeffen
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-03-12T12:02:38Z
user: login: Gymnasiast
state: APPROVED
author_association: MEMBER
submitted_at: 2025-03-12T18:50:18Z

Review comments:
diff_hunk: @@ -486,6 +486,7 @@ namespace OpenRCT2::Ui::Windows
 
         void SetPage(int32_t newPage)
         {
+            // Skip setting page if we're already on this page, unless we're initialising the window
path: src/openrct2-ui/windows/Guest.cpp
user: login: Gymnasiast
body: Shouldn’t this comment be on line +500?
created_at: 2025-03-12T11:53:20Z
author_association: MEMBER
diff_hunk: @@ -486,6 +486,7 @@ namespace OpenRCT2::Ui::Windows
 
         void SetPage(int32_t newPage)
         {
+            // Skip setting page if we're already on this page, unless we're initialising the window
path: src/openrct2-ui/windows/Guest.cpp
user: login: AaronVanGeffen
body: Nice catch. Yes, I'm not sure how this happened.
created_at: 2025-03-12T12:02:38Z
author_association: MEMBER

PR comments:
user: login: Gymnasiast
created_at: 2025-03-12T11:52:26Z
body: https://github.com/OpenRCT2/OpenRCT2/pull/23590 is really starting to be some kind of Hydra, with all the spin-off PRs it has spawned and issues it has laid bare... :')
author_association: MEMBER
user: login: AaronVanGeffen
created_at: 2025-03-18T00:23:21Z
body: This may have broken the 'listen' effect when double-clicking the overview tab in the guest/park/ride/staff windows 😬 Will investigate.
author_association: MEMBER