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) diff --git a/src/openrct2-ui/scripting/ScTileSelection.hpp b/src/openrct2-ui/scripting/ScTileSelection.hpp index bc9b058993..b3546dd975 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 @@ -78,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); @@ -94,8 +92,7 @@ namespace OpenRCT2::Scripting void tiles_set(DukValue value) { - MapInvalidateMapSelectionTiles(); - gMapSelectionTiles.clear(); + MapSelection::clearSelectedTiles(); if (value.is_array()) { value.push(); @@ -108,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); @@ -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..128f2145ad 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()) @@ -177,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 }); @@ -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..ccaa3c13d1 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,15 +1592,13 @@ namespace OpenRCT2::Ui::Windows { if (_footpathConstructionMode == PathConstructionMode::bridgeOrTunnel) { - MapInvalidateMapSelectionTiles(); 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 }); - 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..385c639ffa 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); @@ -2259,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)) @@ -2274,7 +2272,6 @@ namespace OpenRCT2::Ui::Windows if (GetRide(_currentRideIndex)) { selectMapTiles(trackType, trackDirection, trackPos); - MapInvalidateMapSelectionTiles(); } } @@ -2289,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); } } @@ -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; } @@ -3375,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; @@ -3386,7 +3378,6 @@ namespace OpenRCT2::Ui::Windows &trackType, &trackDirection, &rideIndex, &liftHillAndAlternativeState, nullptr, nullptr)) { RideConstructionInvalidateCurrentTrack(); - MapInvalidateMapSelectionTiles(); return; } _currentTrackPieceType = trackType; @@ -3418,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)) { @@ -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{}; @@ -3636,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 c3d3892c06..2bff37e022 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) @@ -1905,21 +1899,8 @@ namespace OpenRCT2::Ui::Windows } auto* sceneryEntry = ObjectManager::GetObjectEntry(selection.EntryIndex); - gMapSelectionTiles.clear(); - - for (auto& tile : sceneryEntry->tiles) - { - CoordsXY tileLocation = { tile.offset }; - auto rotatedTileCoords = tileLocation.Rotate(direction); - - rotatedTileCoords.x += mapTile.x; - rotatedTileCoords.y += mapTile.y; - - gMapSelectionTiles.push_back(rotatedTileCoords); - } gMapSelectFlags.set(MapSelectFlag::enableConstruct); - MapInvalidateMapSelectionTiles(); // If no change in ghost placement if ((gSceneryGhostType & SCENERY_GHOST_FLAG_3) && mapTile == gSceneryGhostPosition && gSceneryPlaceZ == _unkF64F0A @@ -1929,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; @@ -1977,8 +1964,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 +1984,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/paint/Painter.cpp b/src/openrct2/paint/Painter.cpp index 89c102172a..2117d40604 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/paint/VirtualFloor.cpp b/src/openrct2/paint/VirtualFloor.cpp index bf72fa6ffa..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 : 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..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 : gMapSelectionTiles) + for (const auto& tile : MapSelection::getSelectedTiles()) { if (tile.x != pos.x || tile.y != pos.y) { 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..e2d1914e05 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; } @@ -1816,7 +1817,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..6b2153abcf 100644 --- a/src/openrct2/world/MapSelection.cpp +++ b/src/openrct2/world/MapSelection.cpp @@ -19,44 +19,15 @@ CoordsXY gMapSelectPositionB; CoordsXYZ gMapSelectArrowPosition; uint8_t gMapSelectArrowDirection; -std::vector gMapSelectionTiles; +static std::vector _mapSelectionTiles; +static bool _mapSelectionTilesInvalidate = false; -/** - * - * 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 } }); -} +static MapSelectFlags _previousMapSelectFlags; +static MapSelectType _previousMapSelectType; +static CoordsXY _previousMapSelectPositionA; +static CoordsXY _previousMapSelectPositionB; +static CoordsXYZ _previousMapSelectArrowPosition; +static uint8_t _previousMapSelectArrowDirection; MapRange getMapSelectRange() { @@ -74,3 +45,85 @@ void setMapSelectRange(const CoordsXY coords) { setMapSelectRange({ coords, 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() + { + 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); + } + else if (_previousMapSelectType != gMapSelectType) + { + 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 }); + } + + if (_previousMapSelectFlags.has(MapSelectFlag::enableConstruct) != gMapSelectFlags.has(MapSelectFlag::enableConstruct) + || _mapSelectionTilesInvalidate) + { + for (const CoordsXY& coords : _mapSelectionTiles) + { + MapInvalidateTileFull(coords); + } + _mapSelectionTilesInvalidate = false; + } + + _previousMapSelectFlags = gMapSelectFlags; + _previousMapSelectType = gMapSelectType; + _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 8899b8c76c..5d732968f0 100644 --- a/src/openrct2/world/MapSelection.h +++ b/src/openrct2/world/MapSelection.h @@ -61,10 +61,15 @@ extern CoordsXY gMapSelectPositionB; extern CoordsXYZ gMapSelectArrowPosition; extern uint8_t gMapSelectArrowDirection; -extern std::vector gMapSelectionTiles; - -void MapInvalidateMapSelectionTiles(); -void MapInvalidateSelectionRect(); 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