From 899b5c136a0860b3908f78bbddf279a9730005ab Mon Sep 17 00:00:00 2001 From: aaruel Date: Tue, 9 Jul 2019 03:04:56 -0400 Subject: [PATCH 1/2] Refactor station locations array to vector --- src/openrct2/ride/Ride.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 8bf3821c47..c0ae247732 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -7114,42 +7114,38 @@ void sub_6CB945(Ride* ride) } } - // Needs room for an entrance and an exit per station, plus one position for the list terminator. - TileCoordsXYZD locations[(MAX_STATIONS * 2) + 1]; - TileCoordsXYZD* locationList = locations; + std::vector locations; for (uint8_t stationId = 0; stationId < MAX_STATIONS; ++stationId) { auto entrance = ride_get_entrance_location(ride, stationId); if (!entrance.isNull()) { - *locationList++ = entrance; + locations.push_back(entrance); ride_clear_entrance_location(ride, stationId); } auto exit = ride_get_exit_location(ride, stationId); if (!exit.isNull()) { - *locationList++ = exit; + locations.push_back(exit); ride_clear_exit_location(ride, stationId); } } - (*locationList++).x = COORDS_NULL; - locationList = locations; - for (; !(*locationList).isNull(); locationList++) + for (auto locationList = locations.cbegin(); locationList != locations.cend(); locationList++) { - TileCoordsXYZD* locationList2 = locationList; + auto locationList2 = locationList; locationList2++; bool duplicateLocation = false; - do + for (; locationList2 != locations.cend(); locationList2++) { if ((*locationList).x == (*locationList2).x && (*locationList).y == (*locationList2).y) { duplicateLocation = true; break; } - } while (!(*locationList2++).isNull()); + } if (duplicateLocation) { From 4eadbe3c6ea8333466e3edec3a197ef08ce1fb7f Mon Sep 17 00:00:00 2001 From: aaruel Date: Tue, 9 Jul 2019 21:10:57 -0400 Subject: [PATCH 2/2] Cleaned up location duplication check --- src/openrct2/ride/Ride.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index c0ae247732..bcad8e20ed 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -7132,15 +7132,16 @@ void sub_6CB945(Ride* ride) } } - for (auto locationList = locations.cbegin(); locationList != locations.cend(); locationList++) + auto locationListIter = locations.cbegin(); + for (const TileCoordsXYZD& locationCoords : locations) { - auto locationList2 = locationList; - locationList2++; + auto locationList = ++locationListIter; bool duplicateLocation = false; - for (; locationList2 != locations.cend(); locationList2++) + while (locationList != locations.cend()) { - if ((*locationList).x == (*locationList2).x && (*locationList).y == (*locationList2).y) + const TileCoordsXYZD& locationCoords2 = *locationList++; + if (locationCoords.x == locationCoords2.x && locationCoords.y == locationCoords2.y) { duplicateLocation = true; break; @@ -7152,7 +7153,7 @@ void sub_6CB945(Ride* ride) continue; } - CoordsXY location = { (*locationList).x * 32, (*locationList).y * 32 }; + CoordsXY location = { locationCoords.x * 32, locationCoords.y * 32 }; TileElement* tileElement = map_get_first_element_at(location.x >> 5, location.y >> 5); do