From 0b3fa8a9d33e305842c16f755ee1e4248a73ac58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Mon, 29 Nov 2021 13:09:58 +0200 Subject: [PATCH] Refactor iterating over all map tiles in ride_clear_blocked_tiles --- src/openrct2/ride/RideConstruction.cpp | 31 ++++++++++++-------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/openrct2/ride/RideConstruction.cpp b/src/openrct2/ride/RideConstruction.cpp index 7416f7cd4e..3689b18232 100644 --- a/src/openrct2/ride/RideConstruction.cpp +++ b/src/openrct2/ride/RideConstruction.cpp @@ -36,6 +36,7 @@ #include "../world/MapAnimation.h" #include "../world/Park.h" #include "../world/Scenery.h" +#include "../world/TileElementsView.h" #include "Ride.h" #include "RideData.h" #include "Track.h" @@ -343,26 +344,22 @@ void ride_remove_peeps(Ride* ride) void ride_clear_blocked_tiles(Ride* ride) { - for (int32_t y = 0; y < MAXIMUM_MAP_SIZE_TECHNICAL; y++) + const auto mapSizeXY = GetMapSizeMaxXY(); + + for (TileCoordsXY tilePos = {}; tilePos.x < mapSizeXY; ++tilePos.x) { - for (int32_t x = 0; x < MAXIMUM_MAP_SIZE_TECHNICAL; x++) + for (; tilePos.y < mapSizeXY; ++tilePos.y) { - auto element = map_get_first_element_at(TileCoordsXY{ x, y }); - if (element != nullptr) + for (auto* trackElement : TileElementsView(tilePos.ToCoordsXY())) { - do - { - if (element->GetType() == TILE_ELEMENT_TYPE_TRACK && element->AsTrack()->GetRideIndex() == ride->id) - { - // Unblock footpath element that is at same position - auto footpathElement = map_get_footpath_element( - TileCoordsXYZ{ x, y, element->base_height }.ToCoordsXYZ()); - if (footpathElement != nullptr) - { - footpathElement->AsPath()->SetIsBlockedByVehicle(false); - } - } - } while (!(element++)->IsLastForTile()); + // Unblock footpath element that is at same position + auto* footpathElement = map_get_footpath_element( + TileCoordsXYZ{ tilePos, trackElement->base_height }.ToCoordsXYZ()); + + if (footpathElement == nullptr) + continue; + + footpathElement->AsPath()->SetIsBlockedByVehicle(false); } } }