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. diff --git a/src/openrct2-ui/interface/Window.cpp b/src/openrct2-ui/interface/Window.cpp index 0e3a482dbd..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,11 +1010,7 @@ namespace OpenRCT2::Ui::Windows */ void InvalidateAllWindowsAfterInput() { - WindowVisitEach([](WindowBase* w) { - Windows::WindowUpdateScrollWidgets(*w); - WindowInvalidatePressedImageButton(*w); - w->OnResize(); - }); + WindowVisitEach([](WindowBase* w) { Windows::WindowUpdateScrollWidgets(*w); }); } /** 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..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) + if (viewport != nullptr && viewport->viewPos != ScreenCoordsXY(left, top)) { viewport->viewPos.x = left; viewport->viewPos.y = top; 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) 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 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); + } } /** diff --git a/src/openrct2-ui/windows/NewRide.cpp b/src/openrct2-ui/windows/NewRide.cpp index f092ebb655..7c738045d8 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); @@ -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); 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/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index 0b2e397e17..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(); } @@ -5511,6 +5512,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-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..d22a433dc3 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; @@ -450,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(); } } @@ -489,6 +492,14 @@ namespace OpenRCT2::Ui::Windows min_height = windowHeight; max_height = windowHeight; + + if (height < min_height) + { + height = min_height; + OnPrepareDraw(); + ContentUpdateScroll(); + Invalidate(); + } } } } @@ -503,14 +514,20 @@ namespace OpenRCT2::Ui::Windows } } + if (height > max_height) + { + Invalidate(); + height = max_height; + OnPrepareDraw(); + ContentUpdateScroll(); + } + if (GetCurrentTextBox().window.classification == classification && GetCurrentTextBox().window.number == number) { WindowUpdateTextboxCaret(); InvalidateWidget(WIDX_FILTER_TEXT_BOX); } - Invalidate(); - if (!isToolActive(WindowClass::Scenery)) { Close(); @@ -639,10 +656,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 +1104,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 +1392,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); @@ -1501,7 +1524,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(); 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) diff --git a/src/openrct2-ui/windows/Viewport.cpp b/src/openrct2-ui/windows/Viewport.cpp index 1beea92aba..987a843b23 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, WW, WH, WF_RESIZABLE); } } // namespace OpenRCT2::Ui::Windows diff --git a/src/openrct2/interface/Viewport.cpp b/src/openrct2/interface/Viewport.cpp index 47926ffe9e..e9421d88ae 100644 --- a/src/openrct2/interface/Viewport.cpp +++ b/src/openrct2/interface/Viewport.cpp @@ -247,29 +247,24 @@ 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 }); + const auto topLeft = screenCoord - ScreenCoordsXY(32, 32 + z1); + const auto bottomRight = screenCoord + ScreenCoordsXY(32, 32 - z0); - x1 = screenCoord.x - 32; - y1 = screenCoord.y - 32 - z1; - x2 = screenCoord.x + 32; - y2 = screenCoord.y + 32 - z0; - - ViewportInvalidate(&vp, ScreenRect{ { x1, y1 }, { x2, y2 } }); + ViewportInvalidate(&vp, ScreenRect{ topLeft, bottomRight }); } } } - 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 +279,7 @@ namespace OpenRCT2 } } - void ViewportsInvalidate(const ScreenRect& screenRect, ZoomLevel maxZoom) + void ViewportsInvalidate(const ScreenRect& screenRect, const ZoomLevel maxZoom) { for (auto& vp : _viewports) { @@ -589,7 +584,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) @@ -620,8 +615,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; 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--)