From f5f4a8a2f6fa4350b5204a1b605a714fb371e3cc Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Thu, 22 Sep 2022 00:22:45 +0200 Subject: [PATCH] Use gMapSize instead of MAXIMUM_MAP_SIZE_TECHNICAL in appropriate places Backported from my map size refactors. These functions previously scanned the whole map, so this might also provide a slight performance boost (not tested). --- src/openrct2/actions/ClearAction.cpp | 4 ++-- src/openrct2/actions/SetCheatAction.cpp | 4 ++-- src/openrct2/park/ParkFile.cpp | 4 ++-- src/openrct2/ride/Ride.cpp | 8 ++++---- src/openrct2/ride/RideRatings.cpp | 5 ++--- src/openrct2/scenario/Scenario.cpp | 4 ++-- src/openrct2/world/Banner.cpp | 4 ++-- src/openrct2/world/Map.cpp | 4 ++-- 8 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/openrct2/actions/ClearAction.cpp b/src/openrct2/actions/ClearAction.cpp index 5b70d80b3e..0bc41258f0 100644 --- a/src/openrct2/actions/ClearAction.cpp +++ b/src/openrct2/actions/ClearAction.cpp @@ -207,9 +207,9 @@ money32 ClearAction::ClearSceneryFromTile(const CoordsXY& tilePos, bool executin void ClearAction::ResetClearLargeSceneryFlag() { // TODO: Improve efficiency of this - for (int32_t y = 0; y < MAXIMUM_MAP_SIZE_TECHNICAL; y++) + for (int32_t y = 0; y < gMapSize.y; y++) { - for (int32_t x = 0; x < MAXIMUM_MAP_SIZE_TECHNICAL; x++) + for (int32_t x = 0; x < gMapSize.x; x++) { auto tileElement = map_get_first_element_at(TileCoordsXY{ x, y }); do diff --git a/src/openrct2/actions/SetCheatAction.cpp b/src/openrct2/actions/SetCheatAction.cpp index 950a61fcfc..de1df804da 100644 --- a/src/openrct2/actions/SetCheatAction.cpp +++ b/src/openrct2/actions/SetCheatAction.cpp @@ -357,9 +357,9 @@ ParametersRange SetCheatAction::GetParameterRange(CheatType cheatType) const void SetCheatAction::SetGrassLength(int32_t length) const { - for (int32_t y = 0; y < MAXIMUM_MAP_SIZE_TECHNICAL; y++) + for (int32_t y = 0; y < gMapSize.y; y++) { - for (int32_t x = 0; x < MAXIMUM_MAP_SIZE_TECHNICAL; x++) + for (int32_t x = 0; x < gMapSize.x; x++) { auto surfaceElement = map_get_surface_element_at(TileCoordsXY{ x, y }.ToCoordsXY()); if (surfaceElement == nullptr) diff --git a/src/openrct2/park/ParkFile.cpp b/src/openrct2/park/ParkFile.cpp index 2207e17b00..7468833464 100644 --- a/src/openrct2/park/ParkFile.cpp +++ b/src/openrct2/park/ParkFile.cpp @@ -1025,9 +1025,9 @@ namespace OpenRCT2 void UpdateTrackElementsRideType() { - for (int32_t y = 0; y < MAXIMUM_MAP_SIZE_TECHNICAL; y++) + for (int32_t y = 0; y < gMapSize.y; y++) { - for (int32_t x = 0; x < MAXIMUM_MAP_SIZE_TECHNICAL; x++) + for (int32_t x = 0; x < gMapSize.x; x++) { TileElement* tileElement = map_get_first_element_at(TileCoordsXY{ x, y }); if (tileElement == nullptr) diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index b8f9215e1b..3e63299598 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -5696,9 +5696,9 @@ void determine_ride_entrance_and_exit_locations() // Search the map to find it. Skip the outer ring of invisible tiles. bool alreadyFoundEntrance = false; bool alreadyFoundExit = false; - for (int32_t y = 1; y < MAXIMUM_MAP_SIZE_TECHNICAL - 1; y++) + for (int32_t y = 1; y < gMapSize.y - 1; y++) { - for (int32_t x = 1; x < MAXIMUM_MAP_SIZE_TECHNICAL - 1; x++) + for (int32_t x = 1; x < gMapSize.x - 1; x++) { TileElement* tileElement = map_get_first_element_at(TileCoordsXY{ x, y }); @@ -5860,9 +5860,9 @@ void Ride::IncreaseNumShelteredSections() void Ride::UpdateRideTypeForAllPieces() { - for (int32_t y = 0; y < MAXIMUM_MAP_SIZE_TECHNICAL; y++) + for (int32_t y = 0; y < gMapSize.y; y++) { - for (int32_t x = 0; x < MAXIMUM_MAP_SIZE_TECHNICAL; x++) + for (int32_t x = 0; x < gMapSize.x; x++) { auto* tileElement = map_get_first_element_at(TileCoordsXY(x, y)); if (tileElement == nullptr) diff --git a/src/openrct2/ride/RideRatings.cpp b/src/openrct2/ride/RideRatings.cpp index e969d75d2b..2848664877 100644 --- a/src/openrct2/ride/RideRatings.cpp +++ b/src/openrct2/ride/RideRatings.cpp @@ -1456,10 +1456,9 @@ static int32_t ride_ratings_get_scenery_score(Ride* ride) // Count surrounding scenery items int32_t numSceneryItems = 0; auto tileLocation = TileCoordsXY(location); - for (int32_t yy = std::max(tileLocation.y - 5, 0); yy <= std::min(tileLocation.y + 5, MAXIMUM_MAP_SIZE_TECHNICAL - 1); yy++) + for (int32_t yy = std::max(tileLocation.y - 5, 0); yy <= std::min(tileLocation.y + 5, gMapSize.y - 1); yy++) { - for (int32_t xx = std::max(tileLocation.x - 5, 0); xx <= std::min(tileLocation.x + 5, MAXIMUM_MAP_SIZE_TECHNICAL - 1); - xx++) + for (int32_t xx = std::max(tileLocation.x - 5, 0); xx <= std::min(tileLocation.x + 5, gMapSize.x - 1); xx++) { // Count scenery items on this tile TileElement* tileElement = map_get_first_element_at(TileCoordsXY{ xx, yy }); diff --git a/src/openrct2/scenario/Scenario.cpp b/src/openrct2/scenario/Scenario.cpp index b1695ac680..5c25330d6a 100644 --- a/src/openrct2/scenario/Scenario.cpp +++ b/src/openrct2/scenario/Scenario.cpp @@ -440,8 +440,8 @@ bool scenario_create_ducks() constexpr int32_t SquareRadiusSize = SquareCentre * 32; CoordsXY centrePos; - centrePos.x = SquareRadiusSize + (scenario_rand_max(MAXIMUM_MAP_SIZE_TECHNICAL - SquareCentre) * 32); - centrePos.y = SquareRadiusSize + (scenario_rand_max(MAXIMUM_MAP_SIZE_TECHNICAL - SquareCentre) * 32); + centrePos.x = SquareRadiusSize + (scenario_rand_max(gMapSize.x - SquareCentre) * 32); + centrePos.y = SquareRadiusSize + (scenario_rand_max(gMapSize.y - SquareCentre) * 32); Guard::Assert(map_is_location_valid(centrePos)); diff --git a/src/openrct2/world/Banner.cpp b/src/openrct2/world/Banner.cpp index 7da9597648..c4e6d48d1c 100644 --- a/src/openrct2/world/Banner.cpp +++ b/src/openrct2/world/Banner.cpp @@ -260,9 +260,9 @@ void fix_duplicated_banners() std::vector activeBanners; activeBanners.resize(MAX_BANNERS); - for (int y = 0; y < MAXIMUM_MAP_SIZE_TECHNICAL; y++) + for (int y = 0; y < gMapSize.y; y++) { - for (int x = 0; x < MAXIMUM_MAP_SIZE_TECHNICAL; x++) + for (int x = 0; x < gMapSize.x; x++) { const auto bannerPos = TileCoordsXY{ x, y }.ToCoordsXY(); for (auto* bannerElement : OpenRCT2::TileElementsView(bannerPos)) diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index 7dfdb7763e..7ef3b5ce0c 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -445,9 +445,9 @@ void map_count_remaining_land_rights() gLandRemainingOwnershipSales = 0; gLandRemainingConstructionSales = 0; - for (int32_t y = 0; y < MAXIMUM_MAP_SIZE_TECHNICAL; y++) + for (int32_t y = 0; y < gMapSize.y; y++) { - for (int32_t x = 0; x < MAXIMUM_MAP_SIZE_TECHNICAL; x++) + for (int32_t x = 0; x < gMapSize.x; x++) { auto* surfaceElement = map_get_surface_element_at(TileCoordsXY{ x, y }.ToCoordsXY()); // Surface elements are sometimes hacked out to save some space for other map elements