From 0b5fb11be9866f71225812712f974fb8d2c00f3f Mon Sep 17 00:00:00 2001 From: mix Date: Fri, 16 May 2025 22:41:40 +0100 Subject: [PATCH 01/17] Remove unnecessary window OnResize calls --- src/openrct2-ui/interface/Window.cpp | 1 - src/openrct2-ui/windows/Park.cpp | 8 +++++ src/openrct2-ui/windows/RideConstruction.cpp | 6 +++- src/openrct2-ui/windows/Scenery.cpp | 32 +++++++++++++++++--- src/openrct2/interface/Viewport.cpp | 2 -- 5 files changed, 40 insertions(+), 9 deletions(-) diff --git a/src/openrct2-ui/interface/Window.cpp b/src/openrct2-ui/interface/Window.cpp index 0e3a482dbd..5825130361 100644 --- a/src/openrct2-ui/interface/Window.cpp +++ b/src/openrct2-ui/interface/Window.cpp @@ -1030,7 +1030,6 @@ namespace OpenRCT2::Ui::Windows WindowVisitEach([](WindowBase* w) { Windows::WindowUpdateScrollWidgets(*w); WindowInvalidatePressedImageButton(*w); - w->OnResize(); }); } diff --git a/src/openrct2-ui/windows/Park.cpp b/src/openrct2-ui/windows/Park.cpp index 5368a4659b..700bc72381 100644 --- a/src/openrct2-ui/windows/Park.cpp +++ b/src/openrct2-ui/windows/Park.cpp @@ -403,6 +403,14 @@ namespace OpenRCT2::Ui::Windows } } + void OnViewportRotate() override + { + if (page == WINDOW_PARK_PAGE_ENTRANCE) + { + InitViewport(); + } + } + private: void SetDisabledTabs() { diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index 469e9b88a5..472affc117 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -274,6 +274,8 @@ namespace OpenRCT2::Ui::Windows _autoRotatingShop = true; _trackPlaceCtrlState = false; _trackPlaceShiftState = false; + + UpdateTrackPieceWidgets(); } void OnClose() override @@ -330,7 +332,7 @@ namespace OpenRCT2::Ui::Windows } } - void OnResize() override + void UpdateTrackPieceWidgets() { WindowRideConstructionUpdateEnabledTrackPieces(); @@ -1019,6 +1021,8 @@ namespace OpenRCT2::Ui::Windows } UpdateGhostTrackAndArrow(); + + UpdateTrackPieceWidgets(); } void OnMouseUp(WidgetIndex widgetIndex) override diff --git a/src/openrct2-ui/windows/Scenery.cpp b/src/openrct2-ui/windows/Scenery.cpp index 7d62c65b9c..3f3a2c7d69 100644 --- a/src/openrct2-ui/windows/Scenery.cpp +++ b/src/openrct2-ui/windows/Scenery.cpp @@ -233,6 +233,8 @@ namespace OpenRCT2::Ui::Windows _sceneryPaintEnabled = false; // repaint coloured scenery tool state gWindowSceneryEyedropperEnabled = false; + _actualMinHeight = GetMinimumHeight(); + width = GetRequiredWidth(); min_width = width; max_width = width; @@ -489,6 +491,13 @@ namespace OpenRCT2::Ui::Windows min_height = windowHeight; max_height = windowHeight; + + if (height < min_height) + { + height = min_height; + Invalidate(); + ContentUpdateScroll(); + } } } } @@ -503,6 +512,13 @@ namespace OpenRCT2::Ui::Windows } } + if (height > max_height) + { + Invalidate(); + height = max_height; + ContentUpdateScroll(); + } + if (GetCurrentTextBox().window.classification == classification && GetCurrentTextBox().window.number == number) { WindowUpdateTextboxCaret(); @@ -639,10 +655,7 @@ namespace OpenRCT2::Ui::Windows void OnPrepareDraw() override { - // Minimum window height: title, one scenery button, status bar, padding - _actualMinHeight = getTitleBarTargetHeight() + SCENERY_BUTTON_HEIGHT + kDescriptionHeight + 2 * kTabMargin; - _actualMinHeight += static_cast(1 + (_tabEntries.size() / GetMaxTabCountInARow())) * TabHeight; - _actualMinHeight += widgets[WIDX_FILTER_TEXT_BOX].height() + 2 * kInputMargin; + _actualMinHeight = GetMinimumHeight(); // Set the window title StringId titleStringId = STR_MISCELLANEOUS; @@ -1090,6 +1103,15 @@ namespace OpenRCT2::Ui::Windows } private: + int32_t GetMinimumHeight() const + { + // Minimum window height: title, one scenery button, status bar, padding + int32_t minHeight = getTitleBarTargetHeight() + SCENERY_BUTTON_HEIGHT + kDescriptionHeight + 2 * kTabMargin; + minHeight += static_cast(1 + (_tabEntries.size() / GetMaxTabCountInARow())) * TabHeight; + minHeight += widgets[WIDX_FILTER_TEXT_BOX].height() + 2 * kInputMargin; + return minHeight; + } + int32_t GetNumColumns() const { const auto& listWidget = widgets[WIDX_SCENERY_LIST]; @@ -1369,7 +1391,7 @@ namespace OpenRCT2::Ui::Windows return std::max((static_cast(_tabEntries.size()) + MaxTabsPerRow - 1) / MaxTabsPerRow, 0); } - int32_t GetMaxTabCountInARow() + int32_t GetMaxTabCountInARow() const { int32_t tabEntries = static_cast(_tabEntries.size()); return std::clamp(tabEntries, 1, MaxTabsPerRow); diff --git a/src/openrct2/interface/Viewport.cpp b/src/openrct2/interface/Viewport.cpp index 47926ffe9e..8488c9a6c0 100644 --- a/src/openrct2/interface/Viewport.cpp +++ b/src/openrct2/interface/Viewport.cpp @@ -620,8 +620,6 @@ namespace OpenRCT2 Guard::Assert( GetContext()->GetDrawingEngine()->GetDrawingContext() != nullptr, "We must be in a valid drawing context."); - window->OnResize(); - Viewport* viewport = window->viewport; if (viewport == nullptr) return; From 4864b6552cad5c82b09b1fc59b38bbac92d3267a Mon Sep 17 00:00:00 2001 From: mix Date: Sat, 17 May 2025 03:23:44 +0100 Subject: [PATCH 02/17] Fix scenery window invalidating every frame unnecessarily --- src/openrct2-ui/windows/Scenery.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/openrct2-ui/windows/Scenery.cpp b/src/openrct2-ui/windows/Scenery.cpp index 3f3a2c7d69..50742b8e4b 100644 --- a/src/openrct2-ui/windows/Scenery.cpp +++ b/src/openrct2-ui/windows/Scenery.cpp @@ -452,6 +452,7 @@ namespace OpenRCT2::Ui::Windows // This will happen when the mouse leaves the scroll window and is required so that the cost and description // switch to the tool scenery selection. _selectedScenery = {}; + Invalidate(); } } @@ -525,8 +526,6 @@ namespace OpenRCT2::Ui::Windows InvalidateWidget(WIDX_FILTER_TEXT_BOX); } - Invalidate(); - if (!isToolActive(WindowClass::Scenery)) { Close(); @@ -1523,7 +1522,7 @@ namespace OpenRCT2::Ui::Windows void ContentScrollMouseOver(const ScreenCoordsXY& screenCoords) { ScenerySelection scenery = GetSceneryIdByCursorPos(screenCoords); - if (!scenery.IsUndefined()) + if (!scenery.IsUndefined() && _selectedScenery != scenery) { _selectedScenery = scenery; Invalidate(); From ab402a5f15b4c6c417a472139ba551abb55df172 Mon Sep 17 00:00:00 2001 From: mix Date: Sat, 17 May 2025 03:53:33 +0100 Subject: [PATCH 03/17] Prevent inventions window invalidating every frame --- src/openrct2-ui/windows/EditorInventionsList.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/openrct2-ui/windows/EditorInventionsList.cpp b/src/openrct2-ui/windows/EditorInventionsList.cpp index d7230cd321..e7821f5546 100644 --- a/src/openrct2-ui/windows/EditorInventionsList.cpp +++ b/src/openrct2-ui/windows/EditorInventionsList.cpp @@ -218,8 +218,6 @@ namespace OpenRCT2::Ui::Windows if (WindowEditorInventionsListDragGetItem() != nullptr) return; - - Invalidate(); } ScreenSize OnScrollGetSize(int32_t scrollIndex) override From c37fc885c5fabfea78ebd9081a49b0123ef8c18a Mon Sep 17 00:00:00 2001 From: mix Date: Sat, 17 May 2025 04:48:32 +0100 Subject: [PATCH 04/17] Prevent windows invalidating every frame if any button is pressed --- src/openrct2-ui/interface/Window.cpp | 22 +--------------------- src/openrct2-ui/windows/ClearScenery.cpp | 2 +- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/src/openrct2-ui/interface/Window.cpp b/src/openrct2-ui/interface/Window.cpp index 5825130361..85c2ce4565 100644 --- a/src/openrct2-ui/interface/Window.cpp +++ b/src/openrct2-ui/interface/Window.cpp @@ -322,23 +322,6 @@ namespace OpenRCT2 Config::Get().general.DisableScreensaver ? SDL_DisableScreenSaver() : SDL_EnableScreenSaver(); } - /** - * - * rct2: 0x006EA776 - */ - static void WindowInvalidatePressedImageButton(const WindowBase& w) - { - for (WidgetIndex widgetIndex = 0; widgetIndex < w.widgets.size(); widgetIndex++) - { - auto& widget = w.widgets[widgetIndex]; - if (widget.type != WindowWidgetType::ImgBtn) - continue; - - if (WidgetIsPressed(w, widgetIndex) || isToolActive(w, widgetIndex)) - GfxSetDirtyBlocks({ w.windowPos, w.windowPos + ScreenCoordsXY{ w.width, w.height } }); - } - } - void Window::ScrollToViewport() { if (viewport == nullptr || !focus.has_value()) @@ -1027,10 +1010,7 @@ namespace OpenRCT2::Ui::Windows */ void InvalidateAllWindowsAfterInput() { - WindowVisitEach([](WindowBase* w) { - Windows::WindowUpdateScrollWidgets(*w); - WindowInvalidatePressedImageButton(*w); - }); + WindowVisitEach([](WindowBase* w) { Windows::WindowUpdateScrollWidgets(*w); }); } /** diff --git a/src/openrct2-ui/windows/ClearScenery.cpp b/src/openrct2-ui/windows/ClearScenery.cpp index 8e3c6a5070..18de4a206b 100644 --- a/src/openrct2-ui/windows/ClearScenery.cpp +++ b/src/openrct2-ui/windows/ClearScenery.cpp @@ -171,7 +171,7 @@ namespace OpenRCT2::Ui::Windows Close(); } - void Invalidate() + void OnPrepareDraw() override { // Set the preview image button to be pressed down pressed_widgets = (1uLL << WIDX_PREVIEW) | (_clearSmallScenery ? (1uLL << WIDX_SMALL_SCENERY) : 0) From a47ee3f7dee6f3c401acbc2833944de4697ed52a Mon Sep 17 00:00:00 2001 From: mix Date: Sat, 17 May 2025 05:50:31 +0100 Subject: [PATCH 05/17] Prevent new ride window from invalidating on every frame --- src/openrct2-ui/windows/NewRide.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openrct2-ui/windows/NewRide.cpp b/src/openrct2-ui/windows/NewRide.cpp index f092ebb655..b646b66163 100644 --- a/src/openrct2-ui/windows/NewRide.cpp +++ b/src/openrct2-ui/windows/NewRide.cpp @@ -345,7 +345,7 @@ namespace OpenRCT2::Ui::Windows _windowNewRideTabScroll[_currentTab] = scrolls[0].contentOffsetY; // Remove highlight when mouse leaves rides list - if (!WidgetIsHighlighted(*this, WIDX_RIDE_LIST)) + if (!WidgetIsHighlighted(*this, WIDX_RIDE_LIST) && _newRideVars.HighlightedRide.Type != kRideTypeNull) { _newRideVars.HighlightedRide = { kRideTypeNull, kObjectEntryIndexNull }; InvalidateWidget(WIDX_RIDE_LIST); From 3c9136ac4ffca5aff833504e2a81024ec58c2a97 Mon Sep 17 00:00:00 2001 From: mix Date: Sat, 17 May 2025 21:21:47 +0100 Subject: [PATCH 06/17] Prevent ride ratings from invalidating ride windows unnecessarily --- src/openrct2-ui/windows/Ride.cpp | 7 +++++++ src/openrct2/ride/Ride.h | 1 + src/openrct2/ride/RideRatings.cpp | 9 +++++---- src/openrct2/ride/RideRatings.h | 2 ++ src/openrct2/ride/Vehicle.cpp | 1 + 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index 0b2e397e17..a6c9e7fe2c 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -5511,6 +5511,13 @@ namespace OpenRCT2::Ui::Windows frame_no++; OnPrepareDraw(); InvalidateWidget(WIDX_TAB_7); + + Ride* const ride = GetRide(rideId); + if (ride && ride->windowInvalidateFlags & RIDE_INVALIDATE_RIDE_RATINGS) + { + Invalidate(); + ride->windowInvalidateFlags &= ~RIDE_INVALIDATE_RIDE_RATINGS; + } } void MeasurementsOnToolDown(WidgetIndex widgetIndex, const ScreenCoordsXY& screenCoords) diff --git a/src/openrct2/ride/Ride.h b/src/openrct2/ride/Ride.h index 92405060ac..abf2ed9237 100644 --- a/src/openrct2/ride/Ride.h +++ b/src/openrct2/ride/Ride.h @@ -797,6 +797,7 @@ enum RIDE_INVALIDATE_RIDE_OPERATING = 1 << 4, RIDE_INVALIDATE_RIDE_MAINTENANCE = 1 << 5, RIDE_INVALIDATE_RIDE_MUSIC = 1 << 6, + RIDE_INVALIDATE_RIDE_RATINGS = 1 << 7, }; enum diff --git a/src/openrct2/ride/RideRatings.cpp b/src/openrct2/ride/RideRatings.cpp index 7cd0504fa1..458d85df2d 100644 --- a/src/openrct2/ride/RideRatings.cpp +++ b/src/openrct2/ride/RideRatings.cpp @@ -433,9 +433,6 @@ static void ride_ratings_update_state_3(RideRatingUpdateState& state) RideRatingsCalculate(state, *ride); RideRatingsCalculateValue(*ride); - auto* windowMgr = Ui::GetWindowManager(); - windowMgr->InvalidateByNumber(WindowClass::Ride, state.CurrentRide.ToUnderlying()); - state.State = RIDE_RATINGS_STATE_FIND_NEXT_RIDE; } @@ -1049,7 +1046,11 @@ static void RideRatingsCalculate(RideRatingUpdateState& state, Ride& ride) // Universl ratings adjustments RideRatingsApplyIntensityPenalty(ratings); RideRatingsApplyAdjustments(ride, ratings); - ride.ratings = ratings; + if (ride.ratings != ratings) + { + ride.ratings = ratings; + ride.windowInvalidateFlags |= RIDE_INVALIDATE_RIDE_RATINGS; + } ride.upkeepCost = RideComputeUpkeep(state, ride); ride.windowInvalidateFlags |= RIDE_INVALIDATE_RIDE_INCOME; diff --git a/src/openrct2/ride/RideRatings.h b/src/openrct2/ride/RideRatings.h index 9bf582d58b..451489c6d0 100644 --- a/src/openrct2/ride/RideRatings.h +++ b/src/openrct2/ride/RideRatings.h @@ -39,6 +39,8 @@ struct RatingTuple bool isNull() const; void setNull(); + + bool operator==(const RatingTuple& rhs) const = default; }; static_assert(sizeof(RatingTuple) == 6); diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 9a8db2c315..3e71a11316 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -2318,6 +2318,7 @@ static void test_finish(Ride& ride) { ride.lifecycleFlags &= ~RIDE_LIFECYCLE_TEST_IN_PROGRESS; ride.lifecycleFlags |= RIDE_LIFECYCLE_TESTED; + ride.windowInvalidateFlags |= RIDE_INVALIDATE_RIDE_RATINGS; auto rideStations = ride.getStations(); for (int32_t i = ride.numStations - 1; i >= 1; i--) From 7fcfef97f7dd0345fca52bffc948a3ce57b81057 Mon Sep 17 00:00:00 2001 From: mix Date: Sun, 18 May 2025 02:49:39 +0100 Subject: [PATCH 07/17] Fix ride window viewport focus on viewport rotate --- src/openrct2-ui/windows/Ride.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index a6c9e7fe2c..9cd8c37266 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -2311,6 +2311,7 @@ namespace OpenRCT2::Ui::Windows void MainViewportRotate() { + focus = std::nullopt; InitViewport(); } From 5e51c89d9ff414307a178b1295c9741ed792cb1f Mon Sep 17 00:00:00 2001 From: mix Date: Sun, 18 May 2025 03:17:36 +0100 Subject: [PATCH 08/17] Fix extra viewport invalidating every frame --- src/openrct2-ui/windows/Viewport.cpp | 22 ++++------------------ src/openrct2/interface/Viewport.cpp | 2 +- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/src/openrct2-ui/windows/Viewport.cpp b/src/openrct2-ui/windows/Viewport.cpp index 1beea92aba..ecf3939d52 100644 --- a/src/openrct2-ui/windows/Viewport.cpp +++ b/src/openrct2-ui/windows/Viewport.cpp @@ -98,7 +98,7 @@ namespace OpenRCT2::Ui::Windows viewport->flags |= VIEWPORT_FLAG_SOUND_ON | VIEWPORT_FLAG_INDEPEDENT_ROTATION; - WindowSetResize(*this, { WW, WH }, { WW, WH }); + WindowSetResize(*this, { WW, WH }, { (ContextGetWidth() * 4) / 5, (ContextGetHeight() * 4) / 5 }); } void OnUpdate() override @@ -107,14 +107,11 @@ namespace OpenRCT2::Ui::Windows if (mainWindow == nullptr) return; - if (viewport != nullptr && viewport->flags != mainWindow->viewport->flags) + if (viewport != nullptr && viewport->flags != (mainWindow->viewport->flags | VIEWPORT_FLAG_INDEPEDENT_ROTATION)) { viewport->flags = mainWindow->viewport->flags | VIEWPORT_FLAG_INDEPEDENT_ROTATION; - Invalidate(); + InvalidateWidget(WIDX_VIEWPORT); } - - // Not sure how to invalidate part of the viewport that has changed, this will have to do for now - // widget_invalidate(*this, WIDX_VIEWPORT); } void OnMouseUp(WidgetIndex widgetIndex) override @@ -220,17 +217,6 @@ namespace OpenRCT2::Ui::Windows WindowBase* ViewportOpen() { - int32_t screenWidth = ContextGetWidth(); - int32_t screenHeight = ContextGetHeight(); - int32_t width = (screenWidth / 2); - int32_t height = (screenHeight / 2); - - auto* windowMgr = GetWindowManager(); - auto* w = windowMgr->Create( - WindowClass::Viewport, std::max(WW, width), std::max(WH, height), WF_RESIZABLE); - - if (w != nullptr) - return w; - return nullptr; + return GetWindowManager()->Create(WindowClass::Viewport, 300, 300, WF_RESIZABLE); } } // namespace OpenRCT2::Ui::Windows diff --git a/src/openrct2/interface/Viewport.cpp b/src/openrct2/interface/Viewport.cpp index 8488c9a6c0..fe097a33b7 100644 --- a/src/openrct2/interface/Viewport.cpp +++ b/src/openrct2/interface/Viewport.cpp @@ -589,7 +589,7 @@ namespace OpenRCT2 // rct2: 0x006E7A15 static void ViewportSetUndergroundFlag(int32_t underground, WindowBase* window, Viewport* viewport) { - if (window->classification != WindowClass::MainWindow + if ((window->classification != WindowClass::MainWindow && window->classification != WindowClass::Viewport) || (window->classification == WindowClass::MainWindow && !window->viewport_smart_follow_sprite.IsNull())) { if (!underground) From 03d31d1a7c677e83123b66e0897cf59f7d9333cf Mon Sep 17 00:00:00 2001 From: mix Date: Sun, 18 May 2025 04:32:15 +0100 Subject: [PATCH 09/17] Fix viewport invalidation offsetting position each loop iteration --- src/openrct2/interface/Viewport.cpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/openrct2/interface/Viewport.cpp b/src/openrct2/interface/Viewport.cpp index fe097a33b7..07f38437e1 100644 --- a/src/openrct2/interface/Viewport.cpp +++ b/src/openrct2/interface/Viewport.cpp @@ -247,29 +247,26 @@ namespace OpenRCT2 return mainWindow->viewport; } - void ViewportsInvalidate(int32_t x, int32_t y, int32_t z0, int32_t z1, ZoomLevel maxZoom) + void ViewportsInvalidate(const int32_t x, const int32_t y, const int32_t z0, const int32_t z1, const ZoomLevel maxZoom) { for (auto& vp : _viewports) { if (vp.isVisible && (maxZoom == ZoomLevel{ -1 } || vp.zoom <= ZoomLevel{ maxZoom })) { - int32_t x1, y1, x2, y2; + const auto screenCoord = Translate3DTo2DWithZ(vp.rotation, CoordsXYZ{ x + 16, y + 16, 0 }); - x += 16; - y += 16; - auto screenCoord = Translate3DTo2DWithZ(vp.rotation, CoordsXYZ{ x, y, 0 }); - - x1 = screenCoord.x - 32; - y1 = screenCoord.y - 32 - z1; - x2 = screenCoord.x + 32; - y2 = screenCoord.y + 32 - z0; + const int32_t x1 = screenCoord.x - 32; + const int32_t y1 = screenCoord.y - 32 - z1; + const int32_t x2 = screenCoord.x + 32; + const int32_t y2 = screenCoord.y + 32 - z0; ViewportInvalidate(&vp, ScreenRect{ { x1, y1 }, { x2, y2 } }); } } } - void ViewportsInvalidate(const CoordsXYZ& pos, int32_t width, int32_t minHeight, int32_t maxHeight, ZoomLevel maxZoom) + void ViewportsInvalidate( + const CoordsXYZ& pos, const int32_t width, const int32_t minHeight, const int32_t maxHeight, const ZoomLevel maxZoom) { for (auto& vp : _viewports) { @@ -284,7 +281,7 @@ namespace OpenRCT2 } } - void ViewportsInvalidate(const ScreenRect& screenRect, ZoomLevel maxZoom) + void ViewportsInvalidate(const ScreenRect& screenRect, const ZoomLevel maxZoom) { for (auto& vp : _viewports) { From 07635362def90e042f01a982d601692d60db38d9 Mon Sep 17 00:00:00 2001 From: mix Date: Sun, 18 May 2025 04:56:20 +0100 Subject: [PATCH 10/17] Fix new ride window not invalidating on group ride change --- src/openrct2-ui/windows/NewRide.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/openrct2-ui/windows/NewRide.cpp b/src/openrct2-ui/windows/NewRide.cpp index b646b66163..7c738045d8 100644 --- a/src/openrct2-ui/windows/NewRide.cpp +++ b/src/openrct2-ui/windows/NewRide.cpp @@ -369,7 +369,8 @@ namespace OpenRCT2::Ui::Windows case WIDX_GROUP_BY_TRACK_TYPE: Config::Get().interface.ListRideVehiclesSeparately = !Config::Get().interface.ListRideVehiclesSeparately; Config::Save(); - SetPage(_currentTab); + PopulateRideList(); + Invalidate(); break; case WIDX_FILTER_TEXT_BOX: WindowStartTextbox(*this, widgetIndex, _filter, kTextInputSize); From 98f62f2e97a4bfdbe2f0e7327df1c1dff4c218a3 Mon Sep 17 00:00:00 2001 From: mix Date: Sun, 18 May 2025 05:44:20 +0100 Subject: [PATCH 11/17] Fix staff window viewport issues --- src/openrct2-ui/windows/Staff.cpp | 32 ++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/openrct2-ui/windows/Staff.cpp b/src/openrct2-ui/windows/Staff.cpp index 949937f14d..b74e24297e 100644 --- a/src/openrct2-ui/windows/Staff.cpp +++ b/src/openrct2-ui/windows/Staff.cpp @@ -143,6 +143,8 @@ namespace OpenRCT2::Ui::Windows if (staff->AssignedStaffType == StaffType::Entertainer) _availableCostumes = getAvailableCostumeStrings(AnimationPeepType::Entertainer); + + ViewportInit(); } void OnOpen() override @@ -531,6 +533,14 @@ namespace OpenRCT2::Ui::Windows widgets[WIDX_FIRE].left = width - 25; widgets[WIDX_FIRE].right = width - 2; + + if (viewport != nullptr) + { + const Widget& viewportWidget = widgets[WIDX_VIEWPORT]; + viewport->pos = windowPos + ScreenCoordsXY{ viewportWidget.left + 1, viewportWidget.top + 1 }; + viewport->width = widgets[WIDX_VIEWPORT].width() - 1; + viewport->height = widgets[WIDX_VIEWPORT].height() - 1; + } } void OverviewDraw(RenderTarget& rt) @@ -605,21 +615,6 @@ namespace OpenRCT2::Ui::Windows { WindowSetResize(*this, { WW, WH }, { 500, 450 }); - if (viewport != nullptr) - { - auto widget = widgets[WIDX_VIEWPORT]; - auto newWidth = widget.width() - 1; - auto newHeight = widget.height() - 1; - viewport->pos = windowPos + ScreenCoordsXY{ widget.left + 1, widget.top + 1 }; - - // Update the viewport size - if (viewport->width != newWidth || viewport->height != newHeight) - { - viewport->width = newWidth; - viewport->height = newHeight; - } - } - ViewportInit(); } @@ -648,6 +643,13 @@ namespace OpenRCT2::Ui::Windows picked_peep_frame %= pickAnimLength * 4; InvalidateWidget(WIDX_TAB_1); + + const std::optional tempFocus = staff->State != PeepState::Picked ? std::optional(Focus(staff->Id)) + : std::nullopt; + if (focus != tempFocus) + { + ViewportInit(); + } } void OverviewToolUpdate(WidgetIndex widgetIndex, const ScreenCoordsXY& screenCoords) From b84caf8da6621f3b919c29b16b5be6e9524ac81c Mon Sep 17 00:00:00 2001 From: mix Date: Sun, 18 May 2025 16:14:33 +0100 Subject: [PATCH 12/17] Restore original extra viewport opening window size --- src/openrct2-ui/windows/Viewport.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openrct2-ui/windows/Viewport.cpp b/src/openrct2-ui/windows/Viewport.cpp index ecf3939d52..987a843b23 100644 --- a/src/openrct2-ui/windows/Viewport.cpp +++ b/src/openrct2-ui/windows/Viewport.cpp @@ -217,6 +217,6 @@ namespace OpenRCT2::Ui::Windows WindowBase* ViewportOpen() { - return GetWindowManager()->Create(WindowClass::Viewport, 300, 300, WF_RESIZABLE); + return GetWindowManager()->Create(WindowClass::Viewport, WW, WH, WF_RESIZABLE); } } // namespace OpenRCT2::Ui::Windows From 6d8d593b89331debd4f12dc6e01da5f3b0399ed4 Mon Sep 17 00:00:00 2001 From: mix Date: Sun, 18 May 2025 17:05:19 +0100 Subject: [PATCH 13/17] Fix scenery window scrollbar thumb size on window expansion --- src/openrct2-ui/windows/Scenery.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/openrct2-ui/windows/Scenery.cpp b/src/openrct2-ui/windows/Scenery.cpp index 50742b8e4b..d22a433dc3 100644 --- a/src/openrct2-ui/windows/Scenery.cpp +++ b/src/openrct2-ui/windows/Scenery.cpp @@ -496,8 +496,9 @@ namespace OpenRCT2::Ui::Windows if (height < min_height) { height = min_height; - Invalidate(); + OnPrepareDraw(); ContentUpdateScroll(); + Invalidate(); } } } @@ -517,6 +518,7 @@ namespace OpenRCT2::Ui::Windows { Invalidate(); height = max_height; + OnPrepareDraw(); ContentUpdateScroll(); } From 1292afb7c72e325257b6f4a5c5958a7ec1fe1692 Mon Sep 17 00:00:00 2001 From: mix Date: Tue, 20 May 2025 00:09:25 +0100 Subject: [PATCH 14/17] Fix plugin window viewports on open and prevent unnecessary invalid --- src/openrct2-ui/scripting/CustomWindow.cpp | 2 ++ src/openrct2-ui/scripting/ScViewport.hpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/openrct2-ui/scripting/CustomWindow.cpp b/src/openrct2-ui/scripting/CustomWindow.cpp index 59811cd242..6f489b55b8 100644 --- a/src/openrct2-ui/scripting/CustomWindow.cpp +++ b/src/openrct2-ui/scripting/CustomWindow.cpp @@ -482,6 +482,8 @@ namespace OpenRCT2::Ui::Windows } widgetIndex++; } + + UpdateViewport(); } void OnPrepareDraw() override diff --git a/src/openrct2-ui/scripting/ScViewport.hpp b/src/openrct2-ui/scripting/ScViewport.hpp index 80165d24c4..77f2248623 100644 --- a/src/openrct2-ui/scripting/ScViewport.hpp +++ b/src/openrct2-ui/scripting/ScViewport.hpp @@ -271,7 +271,7 @@ namespace OpenRCT2::Scripting if (w != nullptr) { auto viewport = w->viewport; - if (viewport != nullptr) + if (viewport != nullptr && (viewport->viewPos.x != left || viewport->viewPos.y != top)) { viewport->viewPos.x = left; viewport->viewPos.y = top; From a27d9ccc07d01544a408cc64c9c0c03ef14335dc Mon Sep 17 00:00:00 2001 From: mix Date: Tue, 20 May 2025 04:01:44 +0100 Subject: [PATCH 15/17] Prevent path window invalidating unnecessarily --- src/openrct2-ui/windows/Footpath.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/openrct2-ui/windows/Footpath.cpp b/src/openrct2-ui/windows/Footpath.cpp index daac21880b..5856c8e550 100644 --- a/src/openrct2-ui/windows/Footpath.cpp +++ b/src/openrct2-ui/windows/Footpath.cpp @@ -246,7 +246,6 @@ namespace OpenRCT2::Ui::Windows void OnUpdate() override { - InvalidateWidget(WIDX_CONSTRUCT); WindowFootpathUpdateProvisionalPathForBridgeMode(); // #2502: The camera might have changed rotation, so we need to update which directional buttons are pressed @@ -1056,11 +1055,14 @@ namespace OpenRCT2::Ui::Windows // Set provisional path auto pathType = gFootpathSelection.GetSelectedSurface(); auto constructFlags = FootpathCreateConstructFlags(pathType); - _windowFootpathCost = FootpathProvisionalSet( + const auto footpathCost = FootpathProvisionalSet( pathType, gFootpathSelection.Railings, { *mapPos, baseZ }, slope, constructFlags); - auto* windowMgr = Ui::GetWindowManager(); - windowMgr->InvalidateByClass(WindowClass::Footpath); + if (_windowFootpathCost != footpathCost) + { + _windowFootpathCost = footpathCost; + InvalidateWidget(WIDX_CONSTRUCT); + } } /** From 12606f3d9b773cca50e3c4ba72cb7dc4c34face7 Mon Sep 17 00:00:00 2001 From: mix Date: Tue, 20 May 2025 14:54:27 +0100 Subject: [PATCH 16/17] Simplify the code of a couple of viewport screen coord calculations --- src/openrct2-ui/scripting/ScViewport.hpp | 2 +- src/openrct2/interface/Viewport.cpp | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/openrct2-ui/scripting/ScViewport.hpp b/src/openrct2-ui/scripting/ScViewport.hpp index 77f2248623..b64f2c2644 100644 --- a/src/openrct2-ui/scripting/ScViewport.hpp +++ b/src/openrct2-ui/scripting/ScViewport.hpp @@ -271,7 +271,7 @@ namespace OpenRCT2::Scripting if (w != nullptr) { auto viewport = w->viewport; - if (viewport != nullptr && (viewport->viewPos.x != left || viewport->viewPos.y != top)) + if (viewport != nullptr && viewport->viewPos != ScreenCoordsXY(left, top)) { viewport->viewPos.x = left; viewport->viewPos.y = top; diff --git a/src/openrct2/interface/Viewport.cpp b/src/openrct2/interface/Viewport.cpp index 07f38437e1..e9421d88ae 100644 --- a/src/openrct2/interface/Viewport.cpp +++ b/src/openrct2/interface/Viewport.cpp @@ -255,12 +255,10 @@ namespace OpenRCT2 { const auto screenCoord = Translate3DTo2DWithZ(vp.rotation, CoordsXYZ{ x + 16, y + 16, 0 }); - const int32_t x1 = screenCoord.x - 32; - const int32_t y1 = screenCoord.y - 32 - z1; - const int32_t x2 = screenCoord.x + 32; - const int32_t y2 = screenCoord.y + 32 - z0; + const auto topLeft = screenCoord - ScreenCoordsXY(32, 32 + z1); + const auto bottomRight = screenCoord + ScreenCoordsXY(32, 32 - z0); - ViewportInvalidate(&vp, ScreenRect{ { x1, y1 }, { x2, y2 } }); + ViewportInvalidate(&vp, ScreenRect{ topLeft, bottomRight }); } } } From c394712d70d847ed5fc41273ec56e1f3b0d70b28 Mon Sep 17 00:00:00 2001 From: mix Date: Thu, 22 May 2025 16:24:46 +0100 Subject: [PATCH 17/17] Add changelog entry for improving window invalidations --- distribution/changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 93cda657d3..b630f05df6 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -7,6 +7,7 @@ - Improved: [#24409] Steam installs of RCT Classic are now detected automatically. - Improved: [#24413] Better performance when moving the viewport on Windows and Linux platforms. - Improved: [#24417] Improve the fallback vehicle sprites for Dive Loops. +- Improved: [#24433] The ride, new ride, scenery, path, viewport, park and tool windows no longer redraw every frame if they have not changed. - Improved: [#24467] Apply tweening only to on-screen entities when not zoomed out for better performance with uncapped FPS. - Change: [#24342] g2.dat is now split into g2.dat and fonts.dat. - Change: [#24362] The Windows installer now prevents installing to the same folder as RollerCoaster Tycoon 2 or Classic.