From d7efe4de906bb60a7946b20c783ace05d8012d79 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sat, 21 Dec 2019 09:11:06 -0300 Subject: [PATCH 1/2] Make Map::map_set_tile_elements() use TileCoordsXY --- src/openrct2-ui/windows/RideConstruction.cpp | 33 ++++++++++---------- src/openrct2/world/Map.cpp | 6 ++-- src/openrct2/world/Map.h | 2 +- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index cedb58d69b..2892e807fa 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -2435,20 +2435,19 @@ static void sub_6CBCE2( int32_t baseZ = (originZ + trackBlock->z) >> 3; int32_t clearanceZ = ((trackBlock->var_07 + RideData5[ride->type].clearance_height) >> 3) + baseZ + 4; - int32_t tileX = coords.x >> 5; - int32_t tileY = coords.y >> 5; + auto tileCoords = TileCoordsXY{ coords }; // Replace map elements with temporary ones containing track - _backupTileElementArrays[0] = map_get_first_element_at(tileX + 0, tileY + 0); - _backupTileElementArrays[1] = map_get_first_element_at(tileX + 1, tileY + 0); - _backupTileElementArrays[2] = map_get_first_element_at(tileX - 1, tileY + 0); - _backupTileElementArrays[3] = map_get_first_element_at(tileX + 0, tileY + 1); - _backupTileElementArrays[4] = map_get_first_element_at(tileX + 0, tileY - 1); - map_set_tile_elements(tileX + 0, tileY + 0, &_tempTrackTileElement); - map_set_tile_elements(tileX + 1, tileY + 0, &_tempSideTrackTileElement); - map_set_tile_elements(tileX - 1, tileY + 0, &_tempSideTrackTileElement); - map_set_tile_elements(tileX + 0, tileY + 1, &_tempSideTrackTileElement); - map_set_tile_elements(tileX + 0, tileY - 1, &_tempSideTrackTileElement); + _backupTileElementArrays[0] = map_get_first_element_at(tileCoords.x + 0, tileCoords.y + 0); + _backupTileElementArrays[1] = map_get_first_element_at(tileCoords.x + 1, tileCoords.y + 0); + _backupTileElementArrays[2] = map_get_first_element_at(tileCoords.x - 1, tileCoords.y + 0); + _backupTileElementArrays[3] = map_get_first_element_at(tileCoords.x + 0, tileCoords.y + 1); + _backupTileElementArrays[4] = map_get_first_element_at(tileCoords.x + 0, tileCoords.y - 1); + map_set_tile_elements({ tileCoords.x + 0, tileCoords.y + 0 }, &_tempTrackTileElement); + map_set_tile_elements({ tileCoords.x + 1, tileCoords.y + 0 }, &_tempSideTrackTileElement); + map_set_tile_elements({ tileCoords.x - 1, tileCoords.y + 0 }, &_tempSideTrackTileElement); + map_set_tile_elements({ tileCoords.x + 0, tileCoords.y + 1 }, &_tempSideTrackTileElement); + map_set_tile_elements({ tileCoords.x + 0, tileCoords.y - 1 }, &_tempSideTrackTileElement); // Set the temporary track element _tempTrackTileElement.SetType(TILE_ELEMENT_TYPE_TRACK); @@ -2470,11 +2469,11 @@ static void sub_6CBCE2( sub_68B2B7(session, coords); // Restore map elements - map_set_tile_elements(tileX + 0, tileY + 0, _backupTileElementArrays[0]); - map_set_tile_elements(tileX + 1, tileY + 0, _backupTileElementArrays[1]); - map_set_tile_elements(tileX - 1, tileY + 0, _backupTileElementArrays[2]); - map_set_tile_elements(tileX + 0, tileY + 1, _backupTileElementArrays[3]); - map_set_tile_elements(tileX + 0, tileY - 1, _backupTileElementArrays[4]); + map_set_tile_elements({ tileCoords.x + 0, tileCoords.y + 0 }, _backupTileElementArrays[0]); + map_set_tile_elements({ tileCoords.x + 1, tileCoords.y + 0 }, _backupTileElementArrays[1]); + map_set_tile_elements({ tileCoords.x - 1, tileCoords.y + 0 }, _backupTileElementArrays[2]); + map_set_tile_elements({ tileCoords.x + 0, tileCoords.y + 1 }, _backupTileElementArrays[3]); + map_set_tile_elements({ tileCoords.x + 0, tileCoords.y - 1 }, _backupTileElementArrays[4]); trackBlock++; } diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index a424aaa1eb..58ffa08100 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -192,14 +192,14 @@ TileElement* map_get_nth_element_at(const CoordsXY& coords, int32_t n) return nullptr; } -void map_set_tile_elements(int32_t x, int32_t y, TileElement* elements) +void map_set_tile_elements(const TileCoordsXY& tilePos, TileElement* elements) { - if (!map_is_location_valid({ x * 32, y * 32 })) + if (!map_is_location_valid(tilePos.ToCoordsXY())) { log_error("Trying to access element outside of range"); return; } - gTileElementTilePointers[x + y * MAXIMUM_MAP_SIZE_TECHNICAL] = elements; + gTileElementTilePointers[tilePos.x + tilePos.y * MAXIMUM_MAP_SIZE_TECHNICAL] = elements; } SurfaceElement* map_get_surface_element_at(const CoordsXY& coords) diff --git a/src/openrct2/world/Map.h b/src/openrct2/world/Map.h index 53101d3be8..2b3f56ca41 100644 --- a/src/openrct2/world/Map.h +++ b/src/openrct2/world/Map.h @@ -138,7 +138,7 @@ void map_strip_ghost_flag_from_elements(); void map_update_tile_pointers(); TileElement* map_get_first_element_at(int32_t x, int32_t y); TileElement* map_get_nth_element_at(const CoordsXY& coords, int32_t n); -void map_set_tile_elements(int32_t x, int32_t y, TileElement* elements); +void map_set_tile_elements(const TileCoordsXY& tilePos, TileElement* elements); int32_t map_height_from_slope(const CoordsXY& coords, int32_t slope, bool isSloped); BannerElement* map_get_banner_element_at(const CoordsXYZ& bannerPos, uint8_t direction); SurfaceElement* map_get_surface_element_at(const CoordsXY& coords); From 5fcfc6af00d456bd6a347ac1e6b7ab1761fcfaaf Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sat, 21 Dec 2019 10:25:08 -0300 Subject: [PATCH 2/2] Rename map_set_tile_elements to singular --- src/openrct2-ui/windows/RideConstruction.cpp | 20 ++++++++++---------- src/openrct2/world/Map.cpp | 2 +- src/openrct2/world/Map.h | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index 2892e807fa..fae688e0d8 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -2443,11 +2443,11 @@ static void sub_6CBCE2( _backupTileElementArrays[2] = map_get_first_element_at(tileCoords.x - 1, tileCoords.y + 0); _backupTileElementArrays[3] = map_get_first_element_at(tileCoords.x + 0, tileCoords.y + 1); _backupTileElementArrays[4] = map_get_first_element_at(tileCoords.x + 0, tileCoords.y - 1); - map_set_tile_elements({ tileCoords.x + 0, tileCoords.y + 0 }, &_tempTrackTileElement); - map_set_tile_elements({ tileCoords.x + 1, tileCoords.y + 0 }, &_tempSideTrackTileElement); - map_set_tile_elements({ tileCoords.x - 1, tileCoords.y + 0 }, &_tempSideTrackTileElement); - map_set_tile_elements({ tileCoords.x + 0, tileCoords.y + 1 }, &_tempSideTrackTileElement); - map_set_tile_elements({ tileCoords.x + 0, tileCoords.y - 1 }, &_tempSideTrackTileElement); + map_set_tile_element({ tileCoords.x + 0, tileCoords.y + 0 }, &_tempTrackTileElement); + map_set_tile_element({ tileCoords.x + 1, tileCoords.y + 0 }, &_tempSideTrackTileElement); + map_set_tile_element({ tileCoords.x - 1, tileCoords.y + 0 }, &_tempSideTrackTileElement); + map_set_tile_element({ tileCoords.x + 0, tileCoords.y + 1 }, &_tempSideTrackTileElement); + map_set_tile_element({ tileCoords.x + 0, tileCoords.y - 1 }, &_tempSideTrackTileElement); // Set the temporary track element _tempTrackTileElement.SetType(TILE_ELEMENT_TYPE_TRACK); @@ -2469,11 +2469,11 @@ static void sub_6CBCE2( sub_68B2B7(session, coords); // Restore map elements - map_set_tile_elements({ tileCoords.x + 0, tileCoords.y + 0 }, _backupTileElementArrays[0]); - map_set_tile_elements({ tileCoords.x + 1, tileCoords.y + 0 }, _backupTileElementArrays[1]); - map_set_tile_elements({ tileCoords.x - 1, tileCoords.y + 0 }, _backupTileElementArrays[2]); - map_set_tile_elements({ tileCoords.x + 0, tileCoords.y + 1 }, _backupTileElementArrays[3]); - map_set_tile_elements({ tileCoords.x + 0, tileCoords.y - 1 }, _backupTileElementArrays[4]); + map_set_tile_element({ tileCoords.x + 0, tileCoords.y + 0 }, _backupTileElementArrays[0]); + map_set_tile_element({ tileCoords.x + 1, tileCoords.y + 0 }, _backupTileElementArrays[1]); + map_set_tile_element({ tileCoords.x - 1, tileCoords.y + 0 }, _backupTileElementArrays[2]); + map_set_tile_element({ tileCoords.x + 0, tileCoords.y + 1 }, _backupTileElementArrays[3]); + map_set_tile_element({ tileCoords.x + 0, tileCoords.y - 1 }, _backupTileElementArrays[4]); trackBlock++; } diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index 58ffa08100..1d37cb0971 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -192,7 +192,7 @@ TileElement* map_get_nth_element_at(const CoordsXY& coords, int32_t n) return nullptr; } -void map_set_tile_elements(const TileCoordsXY& tilePos, TileElement* elements) +void map_set_tile_element(const TileCoordsXY& tilePos, TileElement* elements) { if (!map_is_location_valid(tilePos.ToCoordsXY())) { diff --git a/src/openrct2/world/Map.h b/src/openrct2/world/Map.h index 2b3f56ca41..a231d3d994 100644 --- a/src/openrct2/world/Map.h +++ b/src/openrct2/world/Map.h @@ -138,7 +138,7 @@ void map_strip_ghost_flag_from_elements(); void map_update_tile_pointers(); TileElement* map_get_first_element_at(int32_t x, int32_t y); TileElement* map_get_nth_element_at(const CoordsXY& coords, int32_t n); -void map_set_tile_elements(const TileCoordsXY& tilePos, TileElement* elements); +void map_set_tile_element(const TileCoordsXY& tilePos, TileElement* elements); int32_t map_height_from_slope(const CoordsXY& coords, int32_t slope, bool isSloped); BannerElement* map_get_banner_element_at(const CoordsXYZ& bannerPos, uint8_t direction); SurfaceElement* map_get_surface_element_at(const CoordsXY& coords);