Refactor map selection invalidation and prevent unnecessary invalidations (#25529)

* Remove manual map selection invalidation calls

* Invalidate map selection region and arrow only if changed

* Encapsulate selected tiles and invalidate when changed

* Invalidate map selection if selection type was changed

* Prevent large scenery selected tiles invalidating every frame

* Add changelog entry for map selection grid invalidation improvements

* Rename OpenRCT2::MapSelection functions to lowerCamelCase
This commit is contained in:
Michael Steenbeek authored and GitHub committed 2025-11-25 11:52:03 +01:00
commit 99c95b941c
26 files changed
+135 -171

No files matched your search

+1
View File
@@ -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)
@@ -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)
-3
View File
@@ -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;
@@ -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;
+2 -15
View File
@@ -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();
}
-3
View File
@@ -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();
-7
View File
@@ -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;
-2
View File
@@ -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;
-2
View File
@@ -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)
@@ -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);
-5
View File
@@ -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();
}
}
+7 -23
View File
@@ -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;
+6 -24
View File
@@ -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<LargeSceneryEntry>(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);
-3
View File
@@ -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();
@@ -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
@@ -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);
-2
View File
@@ -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();
}
}
-4
View File
@@ -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;
-3
View File
@@ -696,9 +696,6 @@ static constexpr float kWindowScrollLocations[][2] = {
{
gInputFlags.unset(InputFlag::toolActive);
MapInvalidateSelectionRect();
MapInvalidateMapSelectionTiles();
// Reset map selection
gMapSelectFlags.clearAll();
+2
View File
@@ -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();
+3 -3
View File
@@ -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)
{
@@ -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)
{
-1
View File
@@ -533,7 +533,6 @@ void RideConstructionInvalidateCurrentTrack()
{
_currentTrackSelectionFlags.unset(TrackSelectionFlag::arrow);
gMapSelectFlags.unset(MapSelectFlag::enableArrow);
MapInvalidateTileFull(_currentTrackBegin);
}
RideConstructionRemoveGhosts();
break;
+6 -6
View File
@@ -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();
+90 -37
View File
@@ -19,44 +19,15 @@ CoordsXY gMapSelectPositionB;
CoordsXYZ gMapSelectArrowPosition;
uint8_t gMapSelectArrowDirection;
std::vector<CoordsXY> gMapSelectionTiles;
static std::vector<CoordsXY> _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<CoordsXY>& 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
+9 -4
View File
@@ -61,10 +61,15 @@ extern CoordsXY gMapSelectPositionB;
extern CoordsXYZ gMapSelectArrowPosition;
extern uint8_t gMapSelectArrowDirection;
extern std::vector<CoordsXY> 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<CoordsXY>& getSelectedTiles();
void invalidate();
} // namespace OpenRCT2::MapSelection