Merge pull request #24433 from mixiate/prevent-unnecessary-window-invalidations

Prevent some unnecessary window invalidations
This commit is contained in:
Matt authored and GitHub committed 2025-05-22 23:31:20 +03:00
commit d56dbb68f0
19 files changed
+106 -94

No files matched your search

+1
View File
@@ -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.
+1 -22
View File
@@ -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); });
}
/**
@@ -482,6 +482,8 @@ namespace OpenRCT2::Ui::Windows
}
widgetIndex++;
}
UpdateViewport();
}
void OnPrepareDraw() override
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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)
@@ -218,8 +218,6 @@ namespace OpenRCT2::Ui::Windows
if (WindowEditorInventionsListDragGetItem() != nullptr)
return;
Invalidate();
}
ScreenSize OnScrollGetSize(int32_t scrollIndex) override
+6 -4
View File
@@ -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);
}
}
/**
+3 -2
View File
@@ -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);
+8
View File
@@ -403,6 +403,14 @@ namespace OpenRCT2::Ui::Windows
}
}
void OnViewportRotate() override
{
if (page == WINDOW_PARK_PAGE_ENTRANCE)
{
InitViewport();
}
}
private:
void SetDisabledTabs()
{
+8
View File
@@ -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)
+5 -1
View File
@@ -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
+31 -8
View File
@@ -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<int32_t>(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<int32_t>(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<int32_t>((static_cast<int32_t>(_tabEntries.size()) + MaxTabsPerRow - 1) / MaxTabsPerRow, 0);
}
int32_t GetMaxTabCountInARow()
int32_t GetMaxTabCountInARow() const
{
int32_t tabEntries = static_cast<int32_t>(_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();
+17 -15
View File
@@ -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<Focus> tempFocus = staff->State != PeepState::Picked ? std::optional(Focus(staff->Id))
: std::nullopt;
if (focus != tempFocus)
{
ViewportInit();
}
}
void OverviewToolUpdate(WidgetIndex widgetIndex, const ScreenCoordsXY& screenCoords)
+4 -18
View File
@@ -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<ViewportWindow>(
WindowClass::Viewport, std::max(WW, width), std::max(WH, height), WF_RESIZABLE);
if (w != nullptr)
return w;
return nullptr;
return GetWindowManager()->Create<ViewportWindow>(WindowClass::Viewport, WW, WH, WF_RESIZABLE);
}
} // namespace OpenRCT2::Ui::Windows
+9 -16
View File
@@ -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;
+1
View File
@@ -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
+5 -4
View File
@@ -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;
+2
View File
@@ -39,6 +39,8 @@ struct RatingTuple
bool isNull() const;
void setNull();
bool operator==(const RatingTuple& rhs) const = default;
};
static_assert(sizeof(RatingTuple) == 6);
+1
View File
@@ -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--)