From f3cedcc1d943ec7ac2244cce9956eb522d84c005 Mon Sep 17 00:00:00 2001 From: mix Date: Sun, 16 Nov 2025 00:19:34 +0000 Subject: [PATCH 1/7] Remove manual map selection invalidation calls --- src/openrct2-ui/scripting/ScTileSelection.hpp | 4 -- src/openrct2-ui/windows/ClearScenery.cpp | 3 -- .../windows/EditorParkEntrance.cpp | 3 -- src/openrct2-ui/windows/Footpath.cpp | 13 ------- src/openrct2-ui/windows/Guest.cpp | 3 -- src/openrct2-ui/windows/Land.cpp | 7 ---- src/openrct2-ui/windows/LandRights.cpp | 2 - src/openrct2-ui/windows/Map.cpp | 2 - src/openrct2-ui/windows/MazeConstruction.cpp | 3 -- src/openrct2-ui/windows/PatrolArea.cpp | 5 --- src/openrct2-ui/windows/RideConstruction.cpp | 16 -------- src/openrct2-ui/windows/Scenery.cpp | 12 ------ src/openrct2-ui/windows/Staff.cpp | 3 -- src/openrct2-ui/windows/TileInspector.cpp | 2 - src/openrct2-ui/windows/TrackDesignPlace.cpp | 3 -- src/openrct2-ui/windows/ViewClipping.cpp | 2 - src/openrct2-ui/windows/Water.cpp | 4 -- src/openrct2/interface/Window.cpp | 3 -- src/openrct2/ride/RideConstruction.cpp | 1 - src/openrct2/ride/TrackDesign.cpp | 1 - src/openrct2/world/MapSelection.cpp | 37 ------------------- src/openrct2/world/MapSelection.h | 2 - 22 files changed, 131 deletions(-) diff --git a/src/openrct2-ui/scripting/ScTileSelection.hpp b/src/openrct2-ui/scripting/ScTileSelection.hpp index bc9b058993..90204844a1 100644 --- a/src/openrct2-ui/scripting/ScTileSelection.hpp +++ b/src/openrct2-ui/scripting/ScTileSelection.hpp @@ -51,7 +51,6 @@ namespace OpenRCT2::Scripting void range_set(DukValue value) { - MapInvalidateSelectionRect(); if (value.type() == DukValue::Type::OBJECT) { auto range = GetMapRange(value); @@ -69,7 +68,6 @@ namespace OpenRCT2::Scripting { gMapSelectFlags.unset(MapSelectFlag::enable); } - MapInvalidateSelectionRect(); } DukValue tiles_get() const @@ -94,7 +92,6 @@ namespace OpenRCT2::Scripting void tiles_set(DukValue value) { - MapInvalidateMapSelectionTiles(); gMapSelectionTiles.clear(); if (value.is_array()) { @@ -124,7 +121,6 @@ namespace OpenRCT2::Scripting { gMapSelectFlags.set(MapSelectFlag::enableConstruct); } - MapInvalidateMapSelectionTiles(); } static void Register(duk_context* ctx) diff --git a/src/openrct2-ui/windows/ClearScenery.cpp b/src/openrct2-ui/windows/ClearScenery.cpp index 6cddde3b3f..f0d221372c 100644 --- a/src/openrct2-ui/windows/ClearScenery.cpp +++ b/src/openrct2-ui/windows/ClearScenery.cpp @@ -218,7 +218,6 @@ namespace OpenRCT2::Ui::Windows { uint8_t state_changed = 0; - MapInvalidateSelectionRect(); gMapSelectFlags.unset(MapSelectFlag::enable); auto mapTile = ScreenGetMapXY(screenPos, nullptr); @@ -275,7 +274,6 @@ namespace OpenRCT2::Ui::Windows state_changed++; } - MapInvalidateSelectionRect(); return state_changed; } @@ -347,7 +345,6 @@ namespace OpenRCT2::Ui::Windows switch (widgetIndex) { case WIDX_BACKGROUND: - MapInvalidateSelectionRect(); gMapSelectFlags.unset(MapSelectFlag::enable); gCurrentToolId = Tool::bulldozer; break; diff --git a/src/openrct2-ui/windows/EditorParkEntrance.cpp b/src/openrct2-ui/windows/EditorParkEntrance.cpp index 18d9c01020..653b727d73 100644 --- a/src/openrct2-ui/windows/EditorParkEntrance.cpp +++ b/src/openrct2-ui/windows/EditorParkEntrance.cpp @@ -166,8 +166,6 @@ namespace OpenRCT2::Ui::Windows void PlaceParkEntranceToolUpdate(const ScreenCoordsXY& screenCoords) { - MapInvalidateSelectionRect(); - MapInvalidateMapSelectionTiles(); gMapSelectFlags.unset(MapSelectFlag::enable, MapSelectFlag::enableArrow, MapSelectFlag::enableConstruct); CoordsXYZD parkEntrancePosition = PlaceParkEntranceGetMapPosition(screenCoords); if (parkEntrancePosition.IsNull()) @@ -190,7 +188,6 @@ namespace OpenRCT2::Ui::Windows gMapSelectArrowDirection = parkEntrancePosition.direction; gMapSelectFlags.set(MapSelectFlag::enableConstruct, MapSelectFlag::enableArrow); - MapInvalidateMapSelectionTiles(); if (gParkEntranceGhostExists && parkEntrancePosition == gParkEntranceGhostPosition) { return; diff --git a/src/openrct2-ui/windows/Footpath.cpp b/src/openrct2-ui/windows/Footpath.cpp index fad523809c..488b00cef4 100644 --- a/src/openrct2-ui/windows/Footpath.cpp +++ b/src/openrct2-ui/windows/Footpath.cpp @@ -254,7 +254,6 @@ namespace OpenRCT2::Ui::Windows { FootpathUpdateProvisional(); ViewportSetVisibility(ViewportVisibility::standard); - MapInvalidateMapSelectionTiles(); gMapSelectFlags.unset(MapSelectFlag::enableConstruct); auto* windowMgr = Ui::GetWindowManager(); @@ -345,7 +344,6 @@ namespace OpenRCT2::Ui::Windows _windowFootpathCost = kMoney64Undefined; ToolCancel(); FootpathUpdateProvisional(); - MapInvalidateMapSelectionTiles(); gMapSelectFlags.unset(MapSelectFlag::enableConstruct); _footpathConstructionMode = PathConstructionMode::dragArea; ToolSet(*this, WIDX_CONSTRUCT_DRAG_AREA, Tool::pathDown); @@ -370,7 +368,6 @@ namespace OpenRCT2::Ui::Windows _windowFootpathCost = kMoney64Undefined; ToolCancel(); FootpathUpdateProvisional(); - MapInvalidateMapSelectionTiles(); gMapSelectFlags.unset(MapSelectFlag::enableConstruct); _footpathConstructionMode = PathConstructionMode::onLand; ToolSet(*this, WIDX_CONSTRUCT_ON_LAND, Tool::pathDown); @@ -395,7 +392,6 @@ namespace OpenRCT2::Ui::Windows _windowFootpathCost = kMoney64Undefined; ToolCancel(); FootpathUpdateProvisional(); - MapInvalidateMapSelectionTiles(); gMapSelectFlags.unset(MapSelectFlag::enableConstruct); _footpathConstructionMode = PathConstructionMode::bridgeOrTunnelPick; ToolSet(*this, WIDX_CONSTRUCT_BRIDGE_OR_TUNNEL, Tool::crosshair); @@ -670,7 +666,6 @@ namespace OpenRCT2::Ui::Windows { gMapSelectFlags.unset(MapSelectFlag::enableArrow); } - MapInvalidateTileFull(footpathLoc); } } @@ -1040,7 +1035,6 @@ namespace OpenRCT2::Ui::Windows */ void WindowFootpathSetProvisionalPathAtPoint(const ScreenCoordsXY& screenCoords) { - MapInvalidateSelectionRect(); gMapSelectFlags.unset(MapSelectFlag::enableArrow); // Get current map pos and handle key modifier state @@ -1107,7 +1101,6 @@ namespace OpenRCT2::Ui::Windows void WindowFootpathSetProvisionalPathDragArea(MapRange range, int32_t baseZ) { - MapInvalidateSelectionRect(); gMapSelectFlags.unset(MapSelectFlag::enableArrow); // Check for change @@ -1146,7 +1139,6 @@ namespace OpenRCT2::Ui::Windows int32_t direction; TileElement* tileElement; - MapInvalidateSelectionRect(); gMapSelectFlags.unset(MapSelectFlag::enable, MapSelectFlag::enableArrow); auto mapCoords = FootpathBridgeGetInfoFromPos(screenCoords, &direction, &tileElement); @@ -1174,8 +1166,6 @@ namespace OpenRCT2::Ui::Windows gMapSelectArrowPosition = CoordsXYZ{ mapCoords, z }; gMapSelectArrowDirection = direction; - - MapInvalidateSelectionRect(); } FootpathPlacementResult WindowFootpathGetPlacementFromScreenCoords(const ScreenCoordsXY& screenCoords) @@ -1602,7 +1592,6 @@ namespace OpenRCT2::Ui::Windows { if (_footpathConstructionMode == PathConstructionMode::bridgeOrTunnel) { - MapInvalidateMapSelectionTiles(); gMapSelectFlags.set(MapSelectFlag::enableConstruct, MapSelectFlag::green); int32_t direction = _footpathConstructDirection; @@ -1610,7 +1599,6 @@ namespace OpenRCT2::Ui::Windows gMapSelectionTiles.push_back( { _footpathConstructFromPosition.x + CoordsDirectionDelta[direction].x, _footpathConstructFromPosition.y + CoordsDirectionDelta[direction].y }); - MapInvalidateMapSelectionTiles(); } uint64_t newPressedWidgets = pressedWidgets @@ -2036,7 +2024,6 @@ namespace OpenRCT2::Ui::Windows _provisionalFootpath.flags.unset(ProvisionalPathFlag::showArrow); gMapSelectFlags.unset(MapSelectFlag::enableArrow); - MapInvalidateTileFull(_footpathConstructFromPosition); } FootpathRemoveProvisional(); } diff --git a/src/openrct2-ui/windows/Guest.cpp b/src/openrct2-ui/windows/Guest.cpp index 90af298993..7b211c5971 100644 --- a/src/openrct2-ui/windows/Guest.cpp +++ b/src/openrct2-ui/windows/Guest.cpp @@ -977,8 +977,6 @@ namespace OpenRCT2::Ui::Windows if (widgetIndex != WIDX_PICKUP) return; - MapInvalidateSelectionRect(); - gMapSelectFlags.unset(MapSelectFlag::enable); auto mapCoords = FootpathGetCoordinatesFromPos({ screenCoords.x, screenCoords.y + 16 }, nullptr, nullptr); @@ -988,7 +986,6 @@ namespace OpenRCT2::Ui::Windows gMapSelectType = MapSelectType::full; gMapSelectPositionA = mapCoords; gMapSelectPositionB = mapCoords; - MapInvalidateSelectionRect(); } gPickupPeepImage = ImageId(); diff --git a/src/openrct2-ui/windows/Land.cpp b/src/openrct2-ui/windows/Land.cpp index 0e2de599f5..9b7cac4c8a 100644 --- a/src/openrct2-ui/windows/Land.cpp +++ b/src/openrct2-ui/windows/Land.cpp @@ -444,7 +444,6 @@ namespace OpenRCT2::Ui::Windows { uint8_t state_changed = 0; - MapInvalidateSelectionRect(); gMapSelectFlags.unset(MapSelectFlag::enable); auto mapTile = ScreenGetMapXY(screenPos, nullptr); @@ -501,7 +500,6 @@ namespace OpenRCT2::Ui::Windows state_changed++; } - MapInvalidateSelectionRect(); return state_changed; } @@ -582,7 +580,6 @@ namespace OpenRCT2::Ui::Windows switch (widgetIndex) { case WIDX_BACKGROUND: - MapInvalidateSelectionRect(); gMapSelectFlags.unset(MapSelectFlag::enable); gCurrentToolId = Tool::digDown; break; @@ -609,8 +606,6 @@ namespace OpenRCT2::Ui::Windows const bool mapCtrlPressed = GetInputManager().isModifierKeyPressed(ModifierKey::ctrl); auto* windowMgr = Ui::GetWindowManager(); - MapInvalidateSelectionRect(); - if (gCurrentToolId == Tool::upDownArrow) { if (!(gMapSelectFlags.has(MapSelectFlag::enable))) @@ -700,7 +695,6 @@ namespace OpenRCT2::Ui::Windows state_changed++; } - MapInvalidateSelectionRect(); if (!state_changed) return; @@ -827,7 +821,6 @@ namespace OpenRCT2::Ui::Windows state_changed++; } - MapInvalidateSelectionRect(); if (!state_changed) return; diff --git a/src/openrct2-ui/windows/LandRights.cpp b/src/openrct2-ui/windows/LandRights.cpp index cfbf37b184..e10b49ac0e 100644 --- a/src/openrct2-ui/windows/LandRights.cpp +++ b/src/openrct2-ui/windows/LandRights.cpp @@ -459,7 +459,6 @@ namespace OpenRCT2::Ui::Windows void onToolUpdate(WidgetIndex widgetIndex, const ScreenCoordsXY& screenCoords) override { - MapInvalidateSelectionRect(); gMapSelectFlags.unset(MapSelectFlag::enable); auto info = GetMapCoordinatesFromPos( @@ -529,7 +528,6 @@ namespace OpenRCT2::Ui::Windows state_changed++; } - MapInvalidateSelectionRect(); if (!state_changed) return; diff --git a/src/openrct2-ui/windows/Map.cpp b/src/openrct2-ui/windows/Map.cpp index 880f37b405..be4fe99028 100644 --- a/src/openrct2-ui/windows/Map.cpp +++ b/src/openrct2-ui/windows/Map.cpp @@ -449,7 +449,6 @@ namespace OpenRCT2::Ui::Windows { int32_t direction; TileElement* tileElement; - MapInvalidateSelectionRect(); gMapSelectFlags.unset(MapSelectFlag::enable, MapSelectFlag::enableArrow); auto mapCoords = FootpathBridgeGetInfoFromPos(screenCoords, &direction, &tileElement); if (mapCoords.IsNull()) @@ -470,7 +469,6 @@ namespace OpenRCT2::Ui::Windows gMapSelectPositionB = mapCoords; gMapSelectArrowPosition = CoordsXYZ{ mapCoords, mapZ }; gMapSelectArrowDirection = DirectionReverse(direction); - MapInvalidateSelectionRect(); } void SetPeepSpawnToolDown(const ScreenCoordsXY& screenCoords) diff --git a/src/openrct2-ui/windows/MazeConstruction.cpp b/src/openrct2-ui/windows/MazeConstruction.cpp index 4113495335..97b1644907 100644 --- a/src/openrct2-ui/windows/MazeConstruction.cpp +++ b/src/openrct2-ui/windows/MazeConstruction.cpp @@ -118,7 +118,6 @@ namespace OpenRCT2::Ui::Windows RideConstructionInvalidateCurrentTrack(); ViewportSetVisibility(ViewportVisibility::standard); - MapInvalidateMapSelectionTiles(); gMapSelectFlags.unset(MapSelectFlag::enableConstruct); gMapSelectFlags.unset(MapSelectFlag::enableArrow); @@ -344,8 +343,6 @@ namespace OpenRCT2::Ui::Windows { RideConstructionInvalidateCurrentTrack(); - MapInvalidateSelectionRect(); - gMapSelectFlags.unset(MapSelectFlag::enable); gMapSelectFlags.unset(MapSelectFlag::enableArrow); diff --git a/src/openrct2-ui/windows/PatrolArea.cpp b/src/openrct2-ui/windows/PatrolArea.cpp index dab5a095d4..8c8f88ae61 100644 --- a/src/openrct2-ui/windows/PatrolArea.cpp +++ b/src/openrct2-ui/windows/PatrolArea.cpp @@ -181,15 +181,10 @@ namespace OpenRCT2::Ui::Windows if (stateChanged) { - // Invalidate previous area - MapInvalidateSelectionRect(); - - // Update and invalidate new area gMapSelectFlags.set(MapSelectFlag::enable); gMapSelectType = MapSelectType::full; gMapSelectPositionA = posA; gMapSelectPositionB = posB; - MapInvalidateSelectionRect(); } } diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index a405657754..0ae144c313 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -286,7 +286,6 @@ namespace OpenRCT2::Ui::Windows RideConstructionInvalidateCurrentTrack(); ViewportSetVisibility(ViewportVisibility::standard); - MapInvalidateMapSelectionTiles(); gMapSelectFlags.unset(MapSelectFlag::enableConstruct); gMapSelectFlags.unset(MapSelectFlag::enableArrow); @@ -2242,7 +2241,6 @@ namespace OpenRCT2::Ui::Windows int32_t trackDirection; CoordsXYZ trackPos{}; - MapInvalidateMapSelectionTiles(); gMapSelectFlags.set(MapSelectFlag::enableConstruct); gMapSelectFlags.set(MapSelectFlag::green); @@ -2274,7 +2272,6 @@ namespace OpenRCT2::Ui::Windows if (GetRide(_currentRideIndex)) { selectMapTiles(trackType, trackDirection, trackPos); - MapInvalidateMapSelectionTiles(); } } @@ -2653,7 +2650,6 @@ namespace OpenRCT2::Ui::Windows void ToolDownEntranceExit(const ScreenCoordsXY& screenCoords) { RideConstructionInvalidateCurrentTrack(); - MapInvalidateSelectionRect(); gMapSelectFlags.unset(MapSelectFlag::enable); gMapSelectFlags.unset(MapSelectFlag::enableArrow); @@ -3288,7 +3284,6 @@ namespace OpenRCT2::Ui::Windows gMapSelectFlags.unset(MapSelectFlag::enableArrow); if (_currentTrackSelectionFlags.has(TrackSelectionFlag::arrow)) gMapSelectFlags.set(MapSelectFlag::enableArrow); - MapInvalidateTileFull(_currentTrackBegin); break; } case RideConstructionState::Selected: @@ -3338,7 +3333,6 @@ namespace OpenRCT2::Ui::Windows gMapSelectFlags.unset(MapSelectFlag::enableArrow); if (_currentTrackSelectionFlags.has(TrackSelectionFlag::arrow)) gMapSelectFlags.set(MapSelectFlag::enableArrow); - MapInvalidateTileFull(trackPos); break; } default: @@ -3354,7 +3348,6 @@ namespace OpenRCT2::Ui::Windows { int32_t z; - MapInvalidateMapSelectionTiles(); gMapSelectFlags.unset(MapSelectFlag::enable); gMapSelectFlags.unset(MapSelectFlag::enableConstruct); gMapSelectFlags.unset(MapSelectFlag::enableArrow); @@ -3362,7 +3355,6 @@ namespace OpenRCT2::Ui::Windows if (!mapCoords) { RideConstructionInvalidateCurrentTrack(); - MapInvalidateMapSelectionTiles(); return; } @@ -3386,7 +3378,6 @@ namespace OpenRCT2::Ui::Windows &trackType, &trackDirection, &rideIndex, &liftHillAndAlternativeState, nullptr, nullptr)) { RideConstructionInvalidateCurrentTrack(); - MapInvalidateMapSelectionTiles(); return; } _currentTrackPieceType = trackType; @@ -3446,7 +3437,6 @@ namespace OpenRCT2::Ui::Windows _currentTrackBegin.z = z; if (_currentTrackSelectionFlags.has(TrackSelectionFlag::track) && _currentTrackBegin == _previousTrackPiece) { - MapInvalidateMapSelectionTiles(); return; } @@ -3475,7 +3465,6 @@ namespace OpenRCT2::Ui::Windows auto intent = Intent(INTENT_ACTION_UPDATE_MAZE_CONSTRUCTION); ContextBroadcastIntent(&intent); - MapInvalidateMapSelectionTiles(); return; } @@ -3564,7 +3553,6 @@ namespace OpenRCT2::Ui::Windows } WindowRideConstructionUpdateActiveElements(); - MapInvalidateMapSelectionTiles(); } /** @@ -3573,8 +3561,6 @@ namespace OpenRCT2::Ui::Windows */ void RideConstructionToolupdateEntranceExit(const ScreenCoordsXY& screenCoords) { - MapInvalidateSelectionRect(); - MapInvalidateMapSelectionTiles(); gMapSelectFlags.unset(MapSelectFlag::enable); gMapSelectFlags.unset(MapSelectFlag::enableConstruct); gMapSelectFlags.unset(MapSelectFlag::enableArrow); @@ -3591,7 +3577,6 @@ namespace OpenRCT2::Ui::Windows gMapSelectPositionB = entranceOrExitCoords; gMapSelectArrowPosition = entranceOrExitCoords; gMapSelectArrowDirection = DirectionReverse(entranceOrExitCoords.direction); - MapInvalidateSelectionRect(); entranceOrExitCoords.direction = DirectionReverse(gRideEntranceExitPlaceDirection); StationIndex stationNum = gRideEntranceExitPlaceStationIndex; @@ -3619,7 +3604,6 @@ namespace OpenRCT2::Ui::Windows WindowBase* w; - MapInvalidateMapSelectionTiles(); RideConstructionInvalidateCurrentTrack(); CoordsXYZ mapCoords{}; diff --git a/src/openrct2-ui/windows/Scenery.cpp b/src/openrct2-ui/windows/Scenery.cpp index c3d3892c06..7b834ac7cc 100644 --- a/src/openrct2-ui/windows/Scenery.cpp +++ b/src/openrct2-ui/windows/Scenery.cpp @@ -1761,8 +1761,6 @@ namespace OpenRCT2::Ui::Windows gMapSelectType = getMapSelectQuarter((quadrant ^ 2)); } - MapInvalidateSelectionRect(); - // If no change in ghost placement if ((gSceneryGhostType & SCENERY_GHOST_FLAG_0) && mapTile == gSceneryGhostPosition && quadrant == _unkF64F0E && gSceneryPlaceZ == _unkF64F0A && gSceneryPlaceObject.SceneryType == SCENERY_TYPE_SMALL @@ -1817,8 +1815,6 @@ namespace OpenRCT2::Ui::Windows gMapSelectPositionB.y = mapTile.y; gMapSelectType = MapSelectType::full; - MapInvalidateSelectionRect(); - // If no change in ghost placement if ((gSceneryGhostType & SCENERY_GHOST_FLAG_1) && mapTile == gSceneryGhostPosition && z == gSceneryGhostPosition.z) { @@ -1856,8 +1852,6 @@ namespace OpenRCT2::Ui::Windows setMapSelectRange(mapTile); gMapSelectType = getMapSelectEdge(edge); - MapInvalidateSelectionRect(); - // If no change in ghost placement if ((gSceneryGhostType & SCENERY_GHOST_FLAG_2) && mapTile == gSceneryGhostPosition && edge == gSceneryGhostWallRotation && gSceneryPlaceZ == _unkF64F0A) @@ -1919,7 +1913,6 @@ namespace OpenRCT2::Ui::Windows } gMapSelectFlags.set(MapSelectFlag::enableConstruct); - MapInvalidateMapSelectionTiles(); // If no change in ghost placement if ((gSceneryGhostType & SCENERY_GHOST_FLAG_3) && mapTile == gSceneryGhostPosition && gSceneryPlaceZ == _unkF64F0A @@ -1977,8 +1970,6 @@ namespace OpenRCT2::Ui::Windows gMapSelectPositionB.y = mapTile.y; gMapSelectType = MapSelectType::full; - MapInvalidateSelectionRect(); - // If no change in ghost placement if ((gSceneryGhostType & SCENERY_GHOST_FLAG_4) && mapTile == gSceneryGhostPosition && z == gSceneryGhostPosition.z && direction == gSceneryPlaceRotation) @@ -1999,9 +1990,6 @@ namespace OpenRCT2::Ui::Windows */ void onToolUpdate(WidgetIndex widgetIndex, const ScreenCoordsXY& screenPos) override { - MapInvalidateSelectionRect(); - MapInvalidateMapSelectionTiles(); - gMapSelectFlags.unset(MapSelectFlag::enable); gMapSelectFlags.unset(MapSelectFlag::enableConstruct); diff --git a/src/openrct2-ui/windows/Staff.cpp b/src/openrct2-ui/windows/Staff.cpp index d62cfd78f6..450ca15550 100644 --- a/src/openrct2-ui/windows/Staff.cpp +++ b/src/openrct2-ui/windows/Staff.cpp @@ -668,8 +668,6 @@ namespace OpenRCT2::Ui::Windows if (widgetIndex != WIDX_PICKUP) return; - MapInvalidateSelectionRect(); - gMapSelectFlags.unset(MapSelectFlag::enable); auto mapCoords = FootpathGetCoordinatesFromPos({ screenCoords.x, screenCoords.y + 16 }, nullptr, nullptr); @@ -679,7 +677,6 @@ namespace OpenRCT2::Ui::Windows gMapSelectType = MapSelectType::full; gMapSelectPositionA = mapCoords; gMapSelectPositionB = mapCoords; - MapInvalidateSelectionRect(); } gPickupPeepImage = ImageId(); diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index 51a12de56c..e79042f0b8 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -969,7 +969,6 @@ static uint64_t PageDisabledWidgets[] = { void onToolUpdate(WidgetIndex widgetIndex, const ScreenCoordsXY& screenCoords) override { - MapInvalidateSelectionRect(); gMapSelectFlags.set(MapSelectFlag::enable); CoordsXY mapCoords; @@ -999,7 +998,6 @@ static uint64_t PageDisabledWidgets[] = { gMapSelectFlags.unset(MapSelectFlag::enable); gMapSelectType = MapSelectType::full; - MapInvalidateSelectionRect(); } void onToolDown(WidgetIndex widgetIndex, const ScreenCoordsXY& screenCoords) override diff --git a/src/openrct2-ui/windows/TrackDesignPlace.cpp b/src/openrct2-ui/windows/TrackDesignPlace.cpp index cc08d55099..c194b9bf04 100644 --- a/src/openrct2-ui/windows/TrackDesignPlace.cpp +++ b/src/openrct2-ui/windows/TrackDesignPlace.cpp @@ -121,7 +121,6 @@ namespace OpenRCT2::Ui::Windows { ClearProvisional(); ViewportSetVisibility(ViewportVisibility::standard); - MapInvalidateMapSelectionTiles(); gMapSelectFlags.unset(MapSelectFlag::enableConstruct); gMapSelectFlags.unset(MapSelectFlag::enableArrow); HideGridlines(); @@ -172,7 +171,6 @@ namespace OpenRCT2::Ui::Windows { TrackDesignState tds{}; - MapInvalidateMapSelectionTiles(); gMapSelectFlags.unset(MapSelectFlag::enable); gMapSelectFlags.unset(MapSelectFlag::enableConstruct); gMapSelectFlags.unset(MapSelectFlag::enableArrow); @@ -256,7 +254,6 @@ namespace OpenRCT2::Ui::Windows void onToolDown(WidgetIndex widgetIndex, const ScreenCoordsXY& screenCoords) override { ClearProvisional(); - MapInvalidateMapSelectionTiles(); gMapSelectFlags.unset(MapSelectFlag::enable); gMapSelectFlags.unset(MapSelectFlag::enableConstruct); gMapSelectFlags.unset(MapSelectFlag::enableArrow); diff --git a/src/openrct2-ui/windows/ViewClipping.cpp b/src/openrct2-ui/windows/ViewClipping.cpp index f6f0b320ee..46966210f4 100644 --- a/src/openrct2-ui/windows/ViewClipping.cpp +++ b/src/openrct2-ui/windows/ViewClipping.cpp @@ -248,14 +248,12 @@ namespace OpenRCT2::Ui::Windows auto mapCoords = ScreenPosToMapPos(screenCoords, &direction); if (mapCoords) { - MapInvalidateSelectionRect(); gMapSelectFlags.set(MapSelectFlag::enable); gMapSelectPositionA.x = std::min(_selectionStart.x, mapCoords->x); gMapSelectPositionB.x = std::max(_selectionStart.x, mapCoords->x); gMapSelectPositionA.y = std::min(_selectionStart.y, mapCoords->y); gMapSelectPositionB.y = std::max(_selectionStart.y, mapCoords->y); gMapSelectType = MapSelectType::full; - MapInvalidateSelectionRect(); } } diff --git a/src/openrct2-ui/windows/Water.cpp b/src/openrct2-ui/windows/Water.cpp index b8af23f4ad..e28ee615e4 100644 --- a/src/openrct2-ui/windows/Water.cpp +++ b/src/openrct2-ui/windows/Water.cpp @@ -224,7 +224,6 @@ namespace OpenRCT2::Ui::Windows switch (widgetIndex) { case WIDX_BACKGROUND: - MapInvalidateSelectionRect(); gMapSelectFlags.unset(MapSelectFlag::enable); gCurrentToolId = Tool::waterDown; break; @@ -295,8 +294,6 @@ namespace OpenRCT2::Ui::Windows */ void ToolUpdateWater(const ScreenCoordsXY& screenPos) { - MapInvalidateSelectionRect(); - auto* windowMgr = Ui::GetWindowManager(); auto& gameState = getGameState(); @@ -392,7 +389,6 @@ namespace OpenRCT2::Ui::Windows state_changed++; } - MapInvalidateSelectionRect(); if (!state_changed) return; diff --git a/src/openrct2/interface/Window.cpp b/src/openrct2/interface/Window.cpp index f69a50ab42..907f4b40e5 100644 --- a/src/openrct2/interface/Window.cpp +++ b/src/openrct2/interface/Window.cpp @@ -696,9 +696,6 @@ static constexpr float kWindowScrollLocations[][2] = { { gInputFlags.unset(InputFlag::toolActive); - MapInvalidateSelectionRect(); - MapInvalidateMapSelectionTiles(); - // Reset map selection gMapSelectFlags.clearAll(); diff --git a/src/openrct2/ride/RideConstruction.cpp b/src/openrct2/ride/RideConstruction.cpp index 589a0899d3..8e6925e3ca 100644 --- a/src/openrct2/ride/RideConstruction.cpp +++ b/src/openrct2/ride/RideConstruction.cpp @@ -533,7 +533,6 @@ void RideConstructionInvalidateCurrentTrack() { _currentTrackSelectionFlags.unset(TrackSelectionFlag::arrow); gMapSelectFlags.unset(MapSelectFlag::enableArrow); - MapInvalidateTileFull(_currentTrackBegin); } RideConstructionRemoveGhosts(); break; diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index a4efaadd5e..6345f9ba11 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -1816,7 +1816,6 @@ static GameActions::Result TrackDesignPlaceVirtual( gMapSelectFlags.set(MapSelectFlag::enableConstruct); gMapSelectFlags.set(MapSelectFlag::enableArrow); gMapSelectFlags.unset(MapSelectFlag::green); - MapInvalidateMapSelectionTiles(); } auto res = GameActions::Result(); diff --git a/src/openrct2/world/MapSelection.cpp b/src/openrct2/world/MapSelection.cpp index fa0138906f..72dc5eea9b 100644 --- a/src/openrct2/world/MapSelection.cpp +++ b/src/openrct2/world/MapSelection.cpp @@ -21,43 +21,6 @@ uint8_t gMapSelectArrowDirection; std::vector gMapSelectionTiles; -/** - * - * rct2: 0x0068AB1B - */ -void MapInvalidateMapSelectionTiles() -{ - if (!(gMapSelectFlags.has(MapSelectFlag::enableConstruct))) - return; - - for (const auto& position : gMapSelectionTiles) - MapInvalidateTileFull(position); -} - -/** - * - * rct2: 0x0068AAE1 - */ -void MapInvalidateSelectionRect() -{ - int32_t x0, y0, x1, y1, left, right, top, bottom; - - if (!(gMapSelectFlags.has(MapSelectFlag::enable))) - return; - - x0 = gMapSelectPositionA.x + 16; - y0 = gMapSelectPositionA.y + 16; - x1 = gMapSelectPositionB.x + 16; - y1 = gMapSelectPositionB.y + 16; - MapGetBoundingBox({ x0, y0, x1, y1 }, &left, &top, &right, &bottom); - left -= 32; - right += 32; - bottom += 32; - top -= 32 + 2080; - - OpenRCT2::ViewportsInvalidate({ { left, top }, { right, bottom } }); -} - MapRange getMapSelectRange() { return MapRange(gMapSelectPositionA, gMapSelectPositionB); diff --git a/src/openrct2/world/MapSelection.h b/src/openrct2/world/MapSelection.h index 8899b8c76c..f266d235ff 100644 --- a/src/openrct2/world/MapSelection.h +++ b/src/openrct2/world/MapSelection.h @@ -63,8 +63,6 @@ extern uint8_t gMapSelectArrowDirection; extern std::vector gMapSelectionTiles; -void MapInvalidateMapSelectionTiles(); -void MapInvalidateSelectionRect(); MapRange getMapSelectRange(); void setMapSelectRange(const MapRange& range); void setMapSelectRange(const CoordsXY coords); From 68dc53bfc8d063c4ca23d85799ac6487da627f4e Mon Sep 17 00:00:00 2001 From: mix Date: Sun, 16 Nov 2025 03:13:08 +0000 Subject: [PATCH 2/7] Invalidate map selection region and arrow only if changed --- src/openrct2/paint/Painter.cpp | 2 ++ src/openrct2/world/MapSelection.cpp | 53 +++++++++++++++++++++++++++++ src/openrct2/world/MapSelection.h | 5 +++ 3 files changed, 60 insertions(+) diff --git a/src/openrct2/paint/Painter.cpp b/src/openrct2/paint/Painter.cpp index 89c102172a..9404507fc2 100644 --- a/src/openrct2/paint/Painter.cpp +++ b/src/openrct2/paint/Painter.cpp @@ -24,6 +24,7 @@ #include "../scenes/intro/IntroScene.h" #include "../ui/UiContext.h" #include "../ui/WindowManager.h" +#include "../world/MapSelection.h" #include "../world/TileInspector.h" using namespace OpenRCT2; @@ -48,6 +49,7 @@ void Painter::Paint(IDrawingEngine& de) } else { + MapSelection::Invalidate(); VirtualFloorInvalidate(false); de.PaintWindows(); diff --git a/src/openrct2/world/MapSelection.cpp b/src/openrct2/world/MapSelection.cpp index 72dc5eea9b..75ba8fdd7b 100644 --- a/src/openrct2/world/MapSelection.cpp +++ b/src/openrct2/world/MapSelection.cpp @@ -21,6 +21,12 @@ uint8_t gMapSelectArrowDirection; std::vector gMapSelectionTiles; +static MapSelectFlags _previousMapSelectFlags; +static CoordsXY _previousMapSelectPositionA; +static CoordsXY _previousMapSelectPositionB; +static CoordsXYZ _previousMapSelectArrowPosition; +static uint8_t _previousMapSelectArrowDirection; + MapRange getMapSelectRange() { return MapRange(gMapSelectPositionA, gMapSelectPositionB); @@ -37,3 +43,50 @@ void setMapSelectRange(const CoordsXY coords) { setMapSelectRange({ coords, coords }); } + +namespace OpenRCT2::MapSelection +{ + + void Invalidate() + { + if (!_previousMapSelectFlags.has(MapSelectFlag::enable) && gMapSelectFlags.has(MapSelectFlag::enable)) + { + MapInvalidateRegion(gMapSelectPositionA, gMapSelectPositionB); + } + else if (_previousMapSelectFlags.has(MapSelectFlag::enable) && !gMapSelectFlags.has(MapSelectFlag::enable)) + { + MapInvalidateRegion(_previousMapSelectPositionA, _previousMapSelectPositionB); + } + else if ( + gMapSelectFlags.has(MapSelectFlag::enable) + && (_previousMapSelectPositionA != gMapSelectPositionA || _previousMapSelectPositionB != gMapSelectPositionB)) + { + MapInvalidateRegion(_previousMapSelectPositionA, _previousMapSelectPositionB); + MapInvalidateRegion(gMapSelectPositionA, gMapSelectPositionB); + } + + if (!_previousMapSelectFlags.has(MapSelectFlag::enableArrow) && gMapSelectFlags.has(MapSelectFlag::enableArrow)) + { + MapInvalidateTile({ gMapSelectArrowPosition, gMapSelectArrowPosition.z }); + } + else if (_previousMapSelectFlags.has(MapSelectFlag::enableArrow) && !gMapSelectFlags.has(MapSelectFlag::enableArrow)) + { + MapInvalidateTile({ _previousMapSelectArrowPosition, _previousMapSelectArrowPosition.z }); + } + else if (gMapSelectFlags.has(MapSelectFlag::enableArrow) && _previousMapSelectArrowPosition != gMapSelectArrowPosition) + { + MapInvalidateTile({ _previousMapSelectArrowPosition, _previousMapSelectArrowPosition.z }); + MapInvalidateTile({ gMapSelectArrowPosition, gMapSelectArrowPosition.z }); + } + else if (_previousMapSelectArrowDirection != gMapSelectArrowDirection) + { + MapInvalidateTile({ gMapSelectArrowPosition, gMapSelectArrowPosition.z }); + } + + _previousMapSelectFlags = gMapSelectFlags; + _previousMapSelectPositionA = gMapSelectPositionA; + _previousMapSelectPositionB = gMapSelectPositionB; + _previousMapSelectArrowPosition = gMapSelectArrowPosition; + _previousMapSelectArrowDirection = gMapSelectArrowDirection; + } +} // namespace OpenRCT2::MapSelection diff --git a/src/openrct2/world/MapSelection.h b/src/openrct2/world/MapSelection.h index f266d235ff..d79f3e3527 100644 --- a/src/openrct2/world/MapSelection.h +++ b/src/openrct2/world/MapSelection.h @@ -66,3 +66,8 @@ extern std::vector gMapSelectionTiles; MapRange getMapSelectRange(); void setMapSelectRange(const MapRange& range); void setMapSelectRange(const CoordsXY coords); + +namespace OpenRCT2::MapSelection +{ + void Invalidate(); +} // namespace OpenRCT2::MapSelection From 6631b452adeb19125c2cab61e5e5278be823b88a Mon Sep 17 00:00:00 2001 From: mix Date: Sun, 16 Nov 2025 03:52:01 +0000 Subject: [PATCH 3/7] Encapsulate selected tiles and invalidate when changed --- src/openrct2-ui/scripting/ScTileSelection.hpp | 8 ++--- .../windows/EditorParkEntrance.cpp | 8 ++--- src/openrct2-ui/windows/Footpath.cpp | 4 +-- src/openrct2-ui/windows/RideConstruction.cpp | 14 ++++---- src/openrct2-ui/windows/Scenery.cpp | 4 +-- src/openrct2/paint/VirtualFloor.cpp | 6 ++-- .../paint/tile_element/Paint.Surface.cpp | 2 +- src/openrct2/ride/TrackDesign.cpp | 11 ++++--- src/openrct2/world/MapSelection.cpp | 33 ++++++++++++++++++- src/openrct2/world/MapSelection.h | 6 ++-- 10 files changed, 65 insertions(+), 31 deletions(-) diff --git a/src/openrct2-ui/scripting/ScTileSelection.hpp b/src/openrct2-ui/scripting/ScTileSelection.hpp index 90204844a1..6c70224204 100644 --- a/src/openrct2-ui/scripting/ScTileSelection.hpp +++ b/src/openrct2-ui/scripting/ScTileSelection.hpp @@ -76,7 +76,7 @@ namespace OpenRCT2::Scripting if (gMapSelectFlags.has(MapSelectFlag::enableConstruct)) { duk_uarridx_t index = 0; - for (const auto& tile : gMapSelectionTiles) + for (const auto& tile : MapSelection::GetSelectedTiles()) { duk_push_object(_ctx); duk_push_int(_ctx, tile.x); @@ -92,7 +92,7 @@ namespace OpenRCT2::Scripting void tiles_set(DukValue value) { - gMapSelectionTiles.clear(); + MapSelection::ClearSelectedTiles(); if (value.is_array()) { value.push(); @@ -105,14 +105,14 @@ namespace OpenRCT2::Scripting auto coords = GetCoordsXY(dukElement); if (coords) { - gMapSelectionTiles.push_back(*coords); + MapSelection::AddSelectedTile(*coords); } } } duk_pop(_ctx); } - if (gMapSelectionTiles.empty()) + if (MapSelection::GetSelectedTiles().empty()) { gMapSelectFlags.unset(MapSelectFlag::enableConstruct); gMapSelectFlags.unset(MapSelectFlag::green); diff --git a/src/openrct2-ui/windows/EditorParkEntrance.cpp b/src/openrct2-ui/windows/EditorParkEntrance.cpp index 653b727d73..19ff78cde6 100644 --- a/src/openrct2-ui/windows/EditorParkEntrance.cpp +++ b/src/openrct2-ui/windows/EditorParkEntrance.cpp @@ -175,12 +175,12 @@ namespace OpenRCT2::Ui::Windows } int32_t sideDirection = (parkEntrancePosition.direction + 1) & 3; - gMapSelectionTiles.clear(); - gMapSelectionTiles.push_back({ parkEntrancePosition.x, parkEntrancePosition.y }); - gMapSelectionTiles.push_back( + MapSelection::ClearSelectedTiles(); + MapSelection::AddSelectedTile({ parkEntrancePosition.x, parkEntrancePosition.y }); + MapSelection::AddSelectedTile( { parkEntrancePosition.x + CoordsDirectionDelta[sideDirection].x, parkEntrancePosition.y + CoordsDirectionDelta[sideDirection].y }); - gMapSelectionTiles.push_back( + MapSelection::AddSelectedTile( { parkEntrancePosition.x - CoordsDirectionDelta[sideDirection].x, parkEntrancePosition.y - CoordsDirectionDelta[sideDirection].y }); diff --git a/src/openrct2-ui/windows/Footpath.cpp b/src/openrct2-ui/windows/Footpath.cpp index 488b00cef4..af039e05c2 100644 --- a/src/openrct2-ui/windows/Footpath.cpp +++ b/src/openrct2-ui/windows/Footpath.cpp @@ -1595,8 +1595,8 @@ namespace OpenRCT2::Ui::Windows gMapSelectFlags.set(MapSelectFlag::enableConstruct, MapSelectFlag::green); int32_t direction = _footpathConstructDirection; - gMapSelectionTiles.clear(); - gMapSelectionTiles.push_back( + MapSelection::ClearSelectedTiles(); + MapSelection::AddSelectedTile( { _footpathConstructFromPosition.x + CoordsDirectionDelta[direction].x, _footpathConstructFromPosition.y + CoordsDirectionDelta[direction].y }); } diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index 0ae144c313..915a28ae2e 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -2257,7 +2257,7 @@ namespace OpenRCT2::Ui::Windows trackPos = _currentTrackBegin; break; case RideConstructionState::EntranceExit: - gMapSelectionTiles.clear(); + MapSelection::ClearSelectedTiles(); return; default: if (WindowRideConstructionUpdateState(&trackType, &trackDirection, nullptr, nullptr, &trackPos, nullptr)) @@ -2286,13 +2286,13 @@ namespace OpenRCT2::Ui::Windows const auto& ted = GetTrackElementDescriptor(trackType); trackDirection &= 3; - gMapSelectionTiles.clear(); + MapSelection::ClearSelectedTiles(); for (uint8_t i = 0; i < ted.numSequences; i++) { CoordsXY offsets = { ted.sequences[i].clearance.x, ted.sequences[i].clearance.y }; CoordsXY currentTileCoords = tileCoords + offsets.Rotate(trackDirection); - gMapSelectionTiles.push_back(currentTileCoords); + MapSelection::AddSelectedTile(currentTileCoords); } } @@ -3367,8 +3367,8 @@ namespace OpenRCT2::Ui::Windows gMapSelectFlags.unset(MapSelectFlag::green); gMapSelectArrowPosition = CoordsXYZ{ *mapCoords, z }; gMapSelectArrowDirection = _currentTrackPieceDirection; - gMapSelectionTiles.clear(); - gMapSelectionTiles.push_back(*mapCoords); + MapSelection::ClearSelectedTiles(); + MapSelection::AddSelectedTile(*mapCoords); RideId rideIndex; OpenRCT2::TrackElemType trackType; @@ -3409,7 +3409,7 @@ namespace OpenRCT2::Ui::Windows if (gMapSelectFlags.has(MapSelectFlag::enableConstruct)) { int32_t highestZ = 0; - for (const auto& selectedTile : gMapSelectionTiles) + for (const auto& selectedTile : MapSelection::GetSelectedTiles()) { if (MapIsLocationValid(selectedTile)) { @@ -3620,7 +3620,7 @@ namespace OpenRCT2::Ui::Windows highestZ = 0; if (gMapSelectFlags.has(MapSelectFlag::enableConstruct)) { - for (const auto& selectedTile : gMapSelectionTiles) + for (const auto& selectedTile : MapSelection::GetSelectedTiles()) { if (!MapIsLocationValid(selectedTile)) continue; diff --git a/src/openrct2-ui/windows/Scenery.cpp b/src/openrct2-ui/windows/Scenery.cpp index 7b834ac7cc..1d9099a441 100644 --- a/src/openrct2-ui/windows/Scenery.cpp +++ b/src/openrct2-ui/windows/Scenery.cpp @@ -1899,7 +1899,7 @@ namespace OpenRCT2::Ui::Windows } auto* sceneryEntry = ObjectManager::GetObjectEntry(selection.EntryIndex); - gMapSelectionTiles.clear(); + MapSelection::ClearSelectedTiles(); for (auto& tile : sceneryEntry->tiles) { @@ -1909,7 +1909,7 @@ namespace OpenRCT2::Ui::Windows rotatedTileCoords.x += mapTile.x; rotatedTileCoords.y += mapTile.y; - gMapSelectionTiles.push_back(rotatedTileCoords); + MapSelection::AddSelectedTile(rotatedTileCoords); } gMapSelectFlags.set(MapSelectFlag::enableConstruct); diff --git a/src/openrct2/paint/VirtualFloor.cpp b/src/openrct2/paint/VirtualFloor.cpp index bf72fa6ffa..9df27a1cd8 100644 --- a/src/openrct2/paint/VirtualFloor.cpp +++ b/src/openrct2/paint/VirtualFloor.cpp @@ -107,7 +107,7 @@ void VirtualFloorInvalidate(const bool alwaysInvalidate) if (gMapSelectFlags.has(MapSelectFlag::enableConstruct)) { - for (const auto& tile : gMapSelectionTiles) + for (const auto& tile : MapSelection::GetSelectedTiles()) { min_position.x = std::min(min_position.x, tile.x); min_position.y = std::min(min_position.y, tile.y); @@ -177,7 +177,7 @@ bool VirtualFloorTileIsFloor(const CoordsXY& loc) if (gMapSelectFlags.has(MapSelectFlag::enableConstruct)) { // Check if we are anywhere near the selection tiles (larger scenery / rides) - for (const auto& tile : gMapSelectionTiles) + for (const auto& tile : MapSelection::GetSelectedTiles()) { if (loc.x >= tile.x - kVirtualFloorBaseSize && loc.y >= tile.y - kVirtualFloorBaseSize && loc.x <= tile.x + kVirtualFloorBaseSize && loc.y <= tile.y + kVirtualFloorBaseSize) @@ -213,7 +213,7 @@ static void VirtualFloorGetTileProperties( // See if we are on top of the selection tiles if (gMapSelectFlags.has(MapSelectFlag::enableConstruct)) { - for (const auto& tile : gMapSelectionTiles) + for (const auto& tile : MapSelection::GetSelectedTiles()) { if (tile == loc) { diff --git a/src/openrct2/paint/tile_element/Paint.Surface.cpp b/src/openrct2/paint/tile_element/Paint.Surface.cpp index 448f8b2090..3654f6ba37 100644 --- a/src/openrct2/paint/tile_element/Paint.Surface.cpp +++ b/src/openrct2/paint/tile_element/Paint.Surface.cpp @@ -1168,7 +1168,7 @@ void PaintSurface(PaintSession& session, uint8_t direction, uint16_t height, con { const CoordsXY& pos = session.MapPosition; - for (const auto& tile : gMapSelectionTiles) + for (const auto& tile : MapSelection::GetSelectedTiles()) { if (tile.x != pos.x || tile.y != pos.y) { diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index 6345f9ba11..b1ae8aa833 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -924,10 +924,11 @@ void TrackDesignMirror(TrackDesign& td) static void TrackDesignAddSelectedTile(const CoordsXY& coords) { - auto tileIterator = std::find(gMapSelectionTiles.begin(), gMapSelectionTiles.end(), coords); - if (tileIterator == gMapSelectionTiles.end()) + const auto& selectedTiles = MapSelection::GetSelectedTiles(); + const auto tileIterator = std::find(selectedTiles.begin(), selectedTiles.end(), coords); + if (tileIterator == selectedTiles.end()) { - gMapSelectionTiles.push_back(coords); + MapSelection::AddSelectedTile(coords); } } @@ -1436,7 +1437,7 @@ static GameActions::Result TrackDesignPlaceMaze( { if (tds.placeOperation == TrackPlaceOperation::drawOutlines) { - gMapSelectionTiles.clear(); + MapSelection::ClearSelectedTiles(); gMapSelectArrowPosition = CoordsXYZ{ origin, TileElementHeight(origin) }; gMapSelectArrowDirection = _currentTrackPieceDirection; } @@ -1565,7 +1566,7 @@ static GameActions::Result TrackDesignPlaceRide( tds.origin = origin; if (tds.placeOperation == TrackPlaceOperation::drawOutlines) { - gMapSelectionTiles.clear(); + MapSelection::ClearSelectedTiles(); gMapSelectArrowPosition = CoordsXYZ{ origin, TileElementHeight(origin) }; gMapSelectArrowDirection = _currentTrackPieceDirection; } diff --git a/src/openrct2/world/MapSelection.cpp b/src/openrct2/world/MapSelection.cpp index 75ba8fdd7b..dc9a83a8b8 100644 --- a/src/openrct2/world/MapSelection.cpp +++ b/src/openrct2/world/MapSelection.cpp @@ -19,7 +19,8 @@ CoordsXY gMapSelectPositionB; CoordsXYZ gMapSelectArrowPosition; uint8_t gMapSelectArrowDirection; -std::vector gMapSelectionTiles; +static std::vector _mapSelectionTiles; +static bool _mapSelectionTilesInvalidate = false; static MapSelectFlags _previousMapSelectFlags; static CoordsXY _previousMapSelectPositionA; @@ -46,6 +47,26 @@ void setMapSelectRange(const CoordsXY coords) namespace OpenRCT2::MapSelection { + void ClearSelectedTiles() + { + for (const CoordsXY& coords : _mapSelectionTiles) + { + MapInvalidateTileFull(coords); + } + _mapSelectionTiles.clear(); + _mapSelectionTilesInvalidate = false; + } + + void AddSelectedTile(const CoordsXY& coords) + { + _mapSelectionTiles.push_back(coords); + _mapSelectionTilesInvalidate = true; + } + + const std::vector& GetSelectedTiles() + { + return _mapSelectionTiles; + } void Invalidate() { @@ -83,6 +104,16 @@ namespace OpenRCT2::MapSelection MapInvalidateTile({ gMapSelectArrowPosition, gMapSelectArrowPosition.z }); } + if (_previousMapSelectFlags.has(MapSelectFlag::enableConstruct) != gMapSelectFlags.has(MapSelectFlag::enableConstruct) + || _mapSelectionTilesInvalidate) + { + for (const CoordsXY& coords : _mapSelectionTiles) + { + MapInvalidateTileFull(coords); + } + _mapSelectionTilesInvalidate = false; + } + _previousMapSelectFlags = gMapSelectFlags; _previousMapSelectPositionA = gMapSelectPositionA; _previousMapSelectPositionB = gMapSelectPositionB; diff --git a/src/openrct2/world/MapSelection.h b/src/openrct2/world/MapSelection.h index d79f3e3527..407171d70f 100644 --- a/src/openrct2/world/MapSelection.h +++ b/src/openrct2/world/MapSelection.h @@ -61,13 +61,15 @@ extern CoordsXY gMapSelectPositionB; extern CoordsXYZ gMapSelectArrowPosition; extern uint8_t gMapSelectArrowDirection; -extern std::vector gMapSelectionTiles; - MapRange getMapSelectRange(); void setMapSelectRange(const MapRange& range); void setMapSelectRange(const CoordsXY coords); namespace OpenRCT2::MapSelection { + void ClearSelectedTiles(); + void AddSelectedTile(const CoordsXY& coords); + const std::vector& GetSelectedTiles(); + void Invalidate(); } // namespace OpenRCT2::MapSelection From 6085665dae15d473f0e9b6f3816ca66af13e0fce Mon Sep 17 00:00:00 2001 From: mix Date: Sun, 16 Nov 2025 08:16:36 +0000 Subject: [PATCH 4/7] Invalidate map selection if selection type was changed --- src/openrct2/world/MapSelection.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/openrct2/world/MapSelection.cpp b/src/openrct2/world/MapSelection.cpp index dc9a83a8b8..d25e4fa24c 100644 --- a/src/openrct2/world/MapSelection.cpp +++ b/src/openrct2/world/MapSelection.cpp @@ -23,6 +23,7 @@ static std::vector _mapSelectionTiles; static bool _mapSelectionTilesInvalidate = false; static MapSelectFlags _previousMapSelectFlags; +static MapSelectType _previousMapSelectType; static CoordsXY _previousMapSelectPositionA; static CoordsXY _previousMapSelectPositionB; static CoordsXYZ _previousMapSelectArrowPosition; @@ -85,6 +86,10 @@ namespace OpenRCT2::MapSelection MapInvalidateRegion(_previousMapSelectPositionA, _previousMapSelectPositionB); MapInvalidateRegion(gMapSelectPositionA, gMapSelectPositionB); } + else if (_previousMapSelectType != gMapSelectType) + { + MapInvalidateRegion(gMapSelectPositionA, gMapSelectPositionB); + } if (!_previousMapSelectFlags.has(MapSelectFlag::enableArrow) && gMapSelectFlags.has(MapSelectFlag::enableArrow)) { @@ -115,6 +120,7 @@ namespace OpenRCT2::MapSelection } _previousMapSelectFlags = gMapSelectFlags; + _previousMapSelectType = gMapSelectType; _previousMapSelectPositionA = gMapSelectPositionA; _previousMapSelectPositionB = gMapSelectPositionB; _previousMapSelectArrowPosition = gMapSelectArrowPosition; From 32b32adffcba5b03e39fb85d5bff60c1244c0a0b Mon Sep 17 00:00:00 2001 From: mix Date: Sun, 16 Nov 2025 15:28:10 +0000 Subject: [PATCH 5/7] Prevent large scenery selected tiles invalidating every frame --- src/openrct2-ui/windows/Scenery.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/openrct2-ui/windows/Scenery.cpp b/src/openrct2-ui/windows/Scenery.cpp index 1d9099a441..dd6050f407 100644 --- a/src/openrct2-ui/windows/Scenery.cpp +++ b/src/openrct2-ui/windows/Scenery.cpp @@ -1899,18 +1899,6 @@ namespace OpenRCT2::Ui::Windows } auto* sceneryEntry = ObjectManager::GetObjectEntry(selection.EntryIndex); - MapSelection::ClearSelectedTiles(); - - for (auto& tile : sceneryEntry->tiles) - { - CoordsXY tileLocation = { tile.offset }; - auto rotatedTileCoords = tileLocation.Rotate(direction); - - rotatedTileCoords.x += mapTile.x; - rotatedTileCoords.y += mapTile.y; - - MapSelection::AddSelectedTile(rotatedTileCoords); - } gMapSelectFlags.set(MapSelectFlag::enableConstruct); @@ -1922,6 +1910,12 @@ namespace OpenRCT2::Ui::Windows return; } + MapSelection::ClearSelectedTiles(); + for (auto& tile : sceneryEntry->tiles) + { + MapSelection::AddSelectedTile(mapTile + tile.offset.Rotate(direction)); + } + SceneryRemoveGhostToolPlacement(); gSceneryPlaceObject.SceneryType = SCENERY_TYPE_LARGE; From f7bc440966996befbb20a5351ab46eca3614f7c7 Mon Sep 17 00:00:00 2001 From: mix Date: Sun, 16 Nov 2025 15:51:13 +0000 Subject: [PATCH 6/7] Add changelog entry for map selection grid invalidation improvements --- distribution/changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 2706afcab6..3bf6af5ff4 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -1,5 +1,6 @@ 0.4.30 (in development) ------------------------------------------------------------------------ +- Improved: [#25529] The map selection grid no longer redraws every frame if it has not changed. - Fix: [#25524] The track construction arrow does not immediately change position when deleting track pieces. 0.4.29 (2025-11-22) From e0f9e756cb37827279b390766718909b949bf016 Mon Sep 17 00:00:00 2001 From: mix Date: Sun, 16 Nov 2025 16:54:01 +0000 Subject: [PATCH 7/7] Rename OpenRCT2::MapSelection functions to lowerCamelCase --- src/openrct2-ui/scripting/ScTileSelection.hpp | 8 ++++---- src/openrct2-ui/windows/EditorParkEntrance.cpp | 8 ++++---- src/openrct2-ui/windows/Footpath.cpp | 4 ++-- src/openrct2-ui/windows/RideConstruction.cpp | 14 +++++++------- src/openrct2-ui/windows/Scenery.cpp | 4 ++-- src/openrct2/paint/Painter.cpp | 2 +- src/openrct2/paint/VirtualFloor.cpp | 6 +++--- src/openrct2/paint/tile_element/Paint.Surface.cpp | 2 +- src/openrct2/ride/TrackDesign.cpp | 8 ++++---- src/openrct2/world/MapSelection.cpp | 8 ++++---- src/openrct2/world/MapSelection.h | 8 ++++---- 11 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/openrct2-ui/scripting/ScTileSelection.hpp b/src/openrct2-ui/scripting/ScTileSelection.hpp index 6c70224204..b3546dd975 100644 --- a/src/openrct2-ui/scripting/ScTileSelection.hpp +++ b/src/openrct2-ui/scripting/ScTileSelection.hpp @@ -76,7 +76,7 @@ namespace OpenRCT2::Scripting if (gMapSelectFlags.has(MapSelectFlag::enableConstruct)) { duk_uarridx_t index = 0; - for (const auto& tile : MapSelection::GetSelectedTiles()) + for (const auto& tile : MapSelection::getSelectedTiles()) { duk_push_object(_ctx); duk_push_int(_ctx, tile.x); @@ -92,7 +92,7 @@ namespace OpenRCT2::Scripting void tiles_set(DukValue value) { - MapSelection::ClearSelectedTiles(); + MapSelection::clearSelectedTiles(); if (value.is_array()) { value.push(); @@ -105,14 +105,14 @@ namespace OpenRCT2::Scripting auto coords = GetCoordsXY(dukElement); if (coords) { - MapSelection::AddSelectedTile(*coords); + MapSelection::addSelectedTile(*coords); } } } duk_pop(_ctx); } - if (MapSelection::GetSelectedTiles().empty()) + if (MapSelection::getSelectedTiles().empty()) { gMapSelectFlags.unset(MapSelectFlag::enableConstruct); gMapSelectFlags.unset(MapSelectFlag::green); diff --git a/src/openrct2-ui/windows/EditorParkEntrance.cpp b/src/openrct2-ui/windows/EditorParkEntrance.cpp index 19ff78cde6..128f2145ad 100644 --- a/src/openrct2-ui/windows/EditorParkEntrance.cpp +++ b/src/openrct2-ui/windows/EditorParkEntrance.cpp @@ -175,12 +175,12 @@ namespace OpenRCT2::Ui::Windows } int32_t sideDirection = (parkEntrancePosition.direction + 1) & 3; - MapSelection::ClearSelectedTiles(); - MapSelection::AddSelectedTile({ parkEntrancePosition.x, parkEntrancePosition.y }); - MapSelection::AddSelectedTile( + MapSelection::clearSelectedTiles(); + MapSelection::addSelectedTile({ parkEntrancePosition.x, parkEntrancePosition.y }); + MapSelection::addSelectedTile( { parkEntrancePosition.x + CoordsDirectionDelta[sideDirection].x, parkEntrancePosition.y + CoordsDirectionDelta[sideDirection].y }); - MapSelection::AddSelectedTile( + MapSelection::addSelectedTile( { parkEntrancePosition.x - CoordsDirectionDelta[sideDirection].x, parkEntrancePosition.y - CoordsDirectionDelta[sideDirection].y }); diff --git a/src/openrct2-ui/windows/Footpath.cpp b/src/openrct2-ui/windows/Footpath.cpp index af039e05c2..ccaa3c13d1 100644 --- a/src/openrct2-ui/windows/Footpath.cpp +++ b/src/openrct2-ui/windows/Footpath.cpp @@ -1595,8 +1595,8 @@ namespace OpenRCT2::Ui::Windows gMapSelectFlags.set(MapSelectFlag::enableConstruct, MapSelectFlag::green); int32_t direction = _footpathConstructDirection; - MapSelection::ClearSelectedTiles(); - MapSelection::AddSelectedTile( + MapSelection::clearSelectedTiles(); + MapSelection::addSelectedTile( { _footpathConstructFromPosition.x + CoordsDirectionDelta[direction].x, _footpathConstructFromPosition.y + CoordsDirectionDelta[direction].y }); } diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index 915a28ae2e..385c639ffa 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -2257,7 +2257,7 @@ namespace OpenRCT2::Ui::Windows trackPos = _currentTrackBegin; break; case RideConstructionState::EntranceExit: - MapSelection::ClearSelectedTiles(); + MapSelection::clearSelectedTiles(); return; default: if (WindowRideConstructionUpdateState(&trackType, &trackDirection, nullptr, nullptr, &trackPos, nullptr)) @@ -2286,13 +2286,13 @@ namespace OpenRCT2::Ui::Windows const auto& ted = GetTrackElementDescriptor(trackType); trackDirection &= 3; - MapSelection::ClearSelectedTiles(); + MapSelection::clearSelectedTiles(); for (uint8_t i = 0; i < ted.numSequences; i++) { CoordsXY offsets = { ted.sequences[i].clearance.x, ted.sequences[i].clearance.y }; CoordsXY currentTileCoords = tileCoords + offsets.Rotate(trackDirection); - MapSelection::AddSelectedTile(currentTileCoords); + MapSelection::addSelectedTile(currentTileCoords); } } @@ -3367,8 +3367,8 @@ namespace OpenRCT2::Ui::Windows gMapSelectFlags.unset(MapSelectFlag::green); gMapSelectArrowPosition = CoordsXYZ{ *mapCoords, z }; gMapSelectArrowDirection = _currentTrackPieceDirection; - MapSelection::ClearSelectedTiles(); - MapSelection::AddSelectedTile(*mapCoords); + MapSelection::clearSelectedTiles(); + MapSelection::addSelectedTile(*mapCoords); RideId rideIndex; OpenRCT2::TrackElemType trackType; @@ -3409,7 +3409,7 @@ namespace OpenRCT2::Ui::Windows if (gMapSelectFlags.has(MapSelectFlag::enableConstruct)) { int32_t highestZ = 0; - for (const auto& selectedTile : MapSelection::GetSelectedTiles()) + for (const auto& selectedTile : MapSelection::getSelectedTiles()) { if (MapIsLocationValid(selectedTile)) { @@ -3620,7 +3620,7 @@ namespace OpenRCT2::Ui::Windows highestZ = 0; if (gMapSelectFlags.has(MapSelectFlag::enableConstruct)) { - for (const auto& selectedTile : MapSelection::GetSelectedTiles()) + for (const auto& selectedTile : MapSelection::getSelectedTiles()) { if (!MapIsLocationValid(selectedTile)) continue; diff --git a/src/openrct2-ui/windows/Scenery.cpp b/src/openrct2-ui/windows/Scenery.cpp index dd6050f407..2bff37e022 100644 --- a/src/openrct2-ui/windows/Scenery.cpp +++ b/src/openrct2-ui/windows/Scenery.cpp @@ -1910,10 +1910,10 @@ namespace OpenRCT2::Ui::Windows return; } - MapSelection::ClearSelectedTiles(); + MapSelection::clearSelectedTiles(); for (auto& tile : sceneryEntry->tiles) { - MapSelection::AddSelectedTile(mapTile + tile.offset.Rotate(direction)); + MapSelection::addSelectedTile(mapTile + tile.offset.Rotate(direction)); } SceneryRemoveGhostToolPlacement(); diff --git a/src/openrct2/paint/Painter.cpp b/src/openrct2/paint/Painter.cpp index 9404507fc2..2117d40604 100644 --- a/src/openrct2/paint/Painter.cpp +++ b/src/openrct2/paint/Painter.cpp @@ -49,7 +49,7 @@ void Painter::Paint(IDrawingEngine& de) } else { - MapSelection::Invalidate(); + MapSelection::invalidate(); VirtualFloorInvalidate(false); de.PaintWindows(); diff --git a/src/openrct2/paint/VirtualFloor.cpp b/src/openrct2/paint/VirtualFloor.cpp index 9df27a1cd8..5f3e490d39 100644 --- a/src/openrct2/paint/VirtualFloor.cpp +++ b/src/openrct2/paint/VirtualFloor.cpp @@ -107,7 +107,7 @@ void VirtualFloorInvalidate(const bool alwaysInvalidate) if (gMapSelectFlags.has(MapSelectFlag::enableConstruct)) { - for (const auto& tile : MapSelection::GetSelectedTiles()) + for (const auto& tile : MapSelection::getSelectedTiles()) { min_position.x = std::min(min_position.x, tile.x); min_position.y = std::min(min_position.y, tile.y); @@ -177,7 +177,7 @@ bool VirtualFloorTileIsFloor(const CoordsXY& loc) if (gMapSelectFlags.has(MapSelectFlag::enableConstruct)) { // Check if we are anywhere near the selection tiles (larger scenery / rides) - for (const auto& tile : MapSelection::GetSelectedTiles()) + for (const auto& tile : MapSelection::getSelectedTiles()) { if (loc.x >= tile.x - kVirtualFloorBaseSize && loc.y >= tile.y - kVirtualFloorBaseSize && loc.x <= tile.x + kVirtualFloorBaseSize && loc.y <= tile.y + kVirtualFloorBaseSize) @@ -213,7 +213,7 @@ static void VirtualFloorGetTileProperties( // See if we are on top of the selection tiles if (gMapSelectFlags.has(MapSelectFlag::enableConstruct)) { - for (const auto& tile : MapSelection::GetSelectedTiles()) + for (const auto& tile : MapSelection::getSelectedTiles()) { if (tile == loc) { diff --git a/src/openrct2/paint/tile_element/Paint.Surface.cpp b/src/openrct2/paint/tile_element/Paint.Surface.cpp index 3654f6ba37..bf132c8cf9 100644 --- a/src/openrct2/paint/tile_element/Paint.Surface.cpp +++ b/src/openrct2/paint/tile_element/Paint.Surface.cpp @@ -1168,7 +1168,7 @@ void PaintSurface(PaintSession& session, uint8_t direction, uint16_t height, con { const CoordsXY& pos = session.MapPosition; - for (const auto& tile : MapSelection::GetSelectedTiles()) + for (const auto& tile : MapSelection::getSelectedTiles()) { if (tile.x != pos.x || tile.y != pos.y) { diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index b1ae8aa833..e2d1914e05 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -924,11 +924,11 @@ void TrackDesignMirror(TrackDesign& td) static void TrackDesignAddSelectedTile(const CoordsXY& coords) { - const auto& selectedTiles = MapSelection::GetSelectedTiles(); + const auto& selectedTiles = MapSelection::getSelectedTiles(); const auto tileIterator = std::find(selectedTiles.begin(), selectedTiles.end(), coords); if (tileIterator == selectedTiles.end()) { - MapSelection::AddSelectedTile(coords); + MapSelection::addSelectedTile(coords); } } @@ -1437,7 +1437,7 @@ static GameActions::Result TrackDesignPlaceMaze( { if (tds.placeOperation == TrackPlaceOperation::drawOutlines) { - MapSelection::ClearSelectedTiles(); + MapSelection::clearSelectedTiles(); gMapSelectArrowPosition = CoordsXYZ{ origin, TileElementHeight(origin) }; gMapSelectArrowDirection = _currentTrackPieceDirection; } @@ -1566,7 +1566,7 @@ static GameActions::Result TrackDesignPlaceRide( tds.origin = origin; if (tds.placeOperation == TrackPlaceOperation::drawOutlines) { - MapSelection::ClearSelectedTiles(); + MapSelection::clearSelectedTiles(); gMapSelectArrowPosition = CoordsXYZ{ origin, TileElementHeight(origin) }; gMapSelectArrowDirection = _currentTrackPieceDirection; } diff --git a/src/openrct2/world/MapSelection.cpp b/src/openrct2/world/MapSelection.cpp index d25e4fa24c..6b2153abcf 100644 --- a/src/openrct2/world/MapSelection.cpp +++ b/src/openrct2/world/MapSelection.cpp @@ -48,7 +48,7 @@ void setMapSelectRange(const CoordsXY coords) namespace OpenRCT2::MapSelection { - void ClearSelectedTiles() + void clearSelectedTiles() { for (const CoordsXY& coords : _mapSelectionTiles) { @@ -58,18 +58,18 @@ namespace OpenRCT2::MapSelection _mapSelectionTilesInvalidate = false; } - void AddSelectedTile(const CoordsXY& coords) + void addSelectedTile(const CoordsXY& coords) { _mapSelectionTiles.push_back(coords); _mapSelectionTilesInvalidate = true; } - const std::vector& GetSelectedTiles() + const std::vector& getSelectedTiles() { return _mapSelectionTiles; } - void Invalidate() + void invalidate() { if (!_previousMapSelectFlags.has(MapSelectFlag::enable) && gMapSelectFlags.has(MapSelectFlag::enable)) { diff --git a/src/openrct2/world/MapSelection.h b/src/openrct2/world/MapSelection.h index 407171d70f..5d732968f0 100644 --- a/src/openrct2/world/MapSelection.h +++ b/src/openrct2/world/MapSelection.h @@ -67,9 +67,9 @@ void setMapSelectRange(const CoordsXY coords); namespace OpenRCT2::MapSelection { - void ClearSelectedTiles(); - void AddSelectedTile(const CoordsXY& coords); - const std::vector& GetSelectedTiles(); + void clearSelectedTiles(); + void addSelectedTile(const CoordsXY& coords); + const std::vector& getSelectedTiles(); - void Invalidate(); + void invalidate(); } // namespace OpenRCT2::MapSelection