From 8b4e0d7babd3ccb0f0311391f5131957ee9bd26c Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Mon, 30 Dec 2019 13:51:01 -0300 Subject: [PATCH] Make Map::wall_remove_*() use CoordsXY* (#10461) * Make Map::wall_remove_at() use CoordsXYRangedZ * Make Map::wall_remove_at_z() use CoordsXYZ * Make Map::wall_remove_intersecting_walls() use CoordsXYRangedZ * Remove useless TODO and simplify functions --- src/openrct2/actions/FootpathPlaceAction.hpp | 16 ++++++------- src/openrct2/actions/LandSetHeightAction.hpp | 2 +- .../actions/LargeSceneryPlaceAction.hpp | 2 +- src/openrct2/actions/MazePlaceTrackAction.hpp | 2 +- src/openrct2/actions/MazeSetTrackAction.hpp | 2 +- .../actions/RideEntranceExitPlaceAction.hpp | 2 +- .../actions/SmallSceneryPlaceAction.hpp | 2 +- src/openrct2/actions/TrackPlaceAction.hpp | 6 ++--- src/openrct2/actions/WaterSetHeightAction.hpp | 2 +- src/openrct2/world/Map.h | 6 ++--- src/openrct2/world/Wall.cpp | 24 +++++++++---------- 11 files changed, 32 insertions(+), 34 deletions(-) diff --git a/src/openrct2/actions/FootpathPlaceAction.hpp b/src/openrct2/actions/FootpathPlaceAction.hpp index ffad41cab8..ed72ff7cb6 100644 --- a/src/openrct2/actions/FootpathPlaceAction.hpp +++ b/src/openrct2/actions/FootpathPlaceAction.hpp @@ -130,13 +130,13 @@ public: if (_direction != INVALID_DIRECTION && !gCheatsDisableClearanceChecks) { // It is possible, let's remove walls between the old and new piece of path - auto zLow = _loc.z / 8; - auto zHigh = zLow + 4; + auto zLow = _loc.z; + auto zHigh = zLow + (4 * 8); wall_remove_intersecting_walls( - _loc.x, _loc.y, zLow, zHigh + ((_slope & TILE_ELEMENT_SURFACE_RAISED_CORNERS_MASK) ? 2 : 0), + { _loc, zLow, zHigh + (_slope & TILE_ELEMENT_SURFACE_RAISED_CORNERS_MASK) ? 16 : 0 }, direction_reverse(_direction)); wall_remove_intersecting_walls( - _loc.x - CoordsDirectionDelta[_direction].x, _loc.y - CoordsDirectionDelta[_direction].y, zLow, zHigh, + { _loc.x - CoordsDirectionDelta[_direction].x, _loc.y - CoordsDirectionDelta[_direction].y, zLow, zHigh }, _direction); } } @@ -411,10 +411,10 @@ private: { if (pathElement->IsSloped() && !(GetFlags() & GAME_COMMAND_FLAG_GHOST)) { - int32_t direction = pathElement->GetSlopeDirection(); - int32_t z = pathElement->base_height; - wall_remove_intersecting_walls(_loc.x, _loc.y, z, z + 6, direction_reverse(direction)); - wall_remove_intersecting_walls(_loc.x, _loc.y, z, z + 6, direction); + auto direction = pathElement->GetSlopeDirection(); + int32_t z = pathElement->GetBaseZ(); + wall_remove_intersecting_walls({ _loc, z, z + (6 * 8) }, direction_reverse(direction)); + wall_remove_intersecting_walls({ _loc, z, z + (6 * 8) }, direction); // Removing walls may have made the pointer invalid, so find it again auto tileElement = map_get_footpath_element(_loc.x / 32, _loc.y / 32, z); if (tileElement == nullptr) diff --git a/src/openrct2/actions/LandSetHeightAction.hpp b/src/openrct2/actions/LandSetHeightAction.hpp index eb55f3d44e..de33ddab24 100644 --- a/src/openrct2/actions/LandSetHeightAction.hpp +++ b/src/openrct2/actions/LandSetHeightAction.hpp @@ -152,7 +152,7 @@ public: if (!gCheatsDisableClearanceChecks) { - wall_remove_at(_coords.x, _coords.y, _height * 8 - 16, _height * 8 + 32); + wall_remove_at({ _coords, _height * 8 - 16, _height * 8 + 32 }); cost += GetSmallSceneryRemovalCost(); SmallSceneryRemoval(); } diff --git a/src/openrct2/actions/LargeSceneryPlaceAction.hpp b/src/openrct2/actions/LargeSceneryPlaceAction.hpp index 495be09568..4972f258a3 100644 --- a/src/openrct2/actions/LargeSceneryPlaceAction.hpp +++ b/src/openrct2/actions/LargeSceneryPlaceAction.hpp @@ -306,7 +306,7 @@ public: footpath_remove_litter(curTile.x, curTile.y, zLow * 8); if (!gCheatsDisableClearanceChecks) { - wall_remove_at(curTile.x, curTile.y, zLow * 8, zHigh * 8); + wall_remove_at({ curTile, zLow * 8, zHigh * 8 }); } } diff --git a/src/openrct2/actions/MazePlaceTrackAction.hpp b/src/openrct2/actions/MazePlaceTrackAction.hpp index 514a2fec00..303bf7485b 100644 --- a/src/openrct2/actions/MazePlaceTrackAction.hpp +++ b/src/openrct2/actions/MazePlaceTrackAction.hpp @@ -151,7 +151,7 @@ public: if (!(flags & GAME_COMMAND_FLAG_GHOST)) { footpath_remove_litter(_loc.x, _loc.y, _loc.z); - wall_remove_at(floor2(_loc.x, 32), floor2(_loc.y, 32), _loc.z, _loc.z + 32); + wall_remove_at({ _loc.ToTileStart(), _loc.z, _loc.z + 32 }); } uint8_t baseHeight = _loc.z / 8; diff --git a/src/openrct2/actions/MazeSetTrackAction.hpp b/src/openrct2/actions/MazeSetTrackAction.hpp index 4b793cccb9..2c9d56c901 100644 --- a/src/openrct2/actions/MazeSetTrackAction.hpp +++ b/src/openrct2/actions/MazeSetTrackAction.hpp @@ -196,7 +196,7 @@ public: if (!(flags & GAME_COMMAND_FLAG_GHOST)) { footpath_remove_litter(_loc.x, _loc.y, _loc.z); - wall_remove_at(floor2(_loc.x, 32), floor2(_loc.y, 32), _loc.z, _loc.z + 32); + wall_remove_at({ _loc.ToTileStart(), _loc.z, _loc.z + 32 }); } uint8_t baseHeight = _loc.z / 8; diff --git a/src/openrct2/actions/RideEntranceExitPlaceAction.hpp b/src/openrct2/actions/RideEntranceExitPlaceAction.hpp index de26914c55..5072bc8eda 100644 --- a/src/openrct2/actions/RideEntranceExitPlaceAction.hpp +++ b/src/openrct2/actions/RideEntranceExitPlaceAction.hpp @@ -170,7 +170,7 @@ public: if (!(GetFlags() & GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED) && !(GetFlags() & GAME_COMMAND_FLAG_GHOST)) { footpath_remove_litter(_loc.x, _loc.y, z); - wall_remove_at_z(_loc.x, _loc.y, z); + wall_remove_at_z({ _loc, z }); } auto clear_z = (z / 8) + (_isExit ? 5 : 7); diff --git a/src/openrct2/actions/SmallSceneryPlaceAction.hpp b/src/openrct2/actions/SmallSceneryPlaceAction.hpp index 4a313e8dcd..264320a3de 100644 --- a/src/openrct2/actions/SmallSceneryPlaceAction.hpp +++ b/src/openrct2/actions/SmallSceneryPlaceAction.hpp @@ -373,7 +373,7 @@ public: footpath_remove_litter(_loc.x, _loc.y, targetHeight); if (!gCheatsDisableClearanceChecks && (scenery_small_entry_has_flag(sceneryEntry, SMALL_SCENERY_FLAG_NO_WALLS))) { - wall_remove_at(_loc.x, _loc.y, targetHeight, targetHeight + sceneryEntry->small_scenery.height); + wall_remove_at({ _loc, targetHeight, targetHeight + sceneryEntry->small_scenery.height }); } } diff --git a/src/openrct2/actions/TrackPlaceAction.hpp b/src/openrct2/actions/TrackPlaceAction.hpp index 8a9d1382c9..36fa46ddd1 100644 --- a/src/openrct2/actions/TrackPlaceAction.hpp +++ b/src/openrct2/actions/TrackPlaceAction.hpp @@ -471,7 +471,7 @@ public: footpath_remove_litter(mapLoc.x, mapLoc.y, mapLoc.z); if (rideTypeFlags & RIDE_TYPE_FLAG_TRACK_NO_WALLS) { - wall_remove_at(mapLoc.x, mapLoc.y, baseZ * 8, clearanceZ * 8); + wall_remove_at({ mapLoc, baseZ * 8, clearanceZ * 8 }); } else { @@ -483,7 +483,7 @@ public: { if (intersectingDirections & (1 << i)) { - wall_remove_intersecting_walls(mapLoc.x, mapLoc.y, baseZ, clearanceZ, i); + wall_remove_intersecting_walls({ mapLoc, baseZ * 8, clearanceZ * 8 }, i); } } } @@ -647,7 +647,7 @@ public: tempLoc.x += CoordsDirectionDelta[tempDirection].x; tempLoc.y += CoordsDirectionDelta[tempDirection].y; tempDirection = direction_reverse(tempDirection); - wall_remove_intersecting_walls(tempLoc.x, tempLoc.y, baseZ, clearanceZ, tempDirection & 3); + wall_remove_intersecting_walls({ tempLoc, baseZ * 8, clearanceZ * 8 }, tempDirection & 3); } } } diff --git a/src/openrct2/actions/WaterSetHeightAction.hpp b/src/openrct2/actions/WaterSetHeightAction.hpp index d8c45396db..0405565284 100644 --- a/src/openrct2/actions/WaterSetHeightAction.hpp +++ b/src/openrct2/actions/WaterSetHeightAction.hpp @@ -116,7 +116,7 @@ public: int32_t surfaceHeight = tile_element_height(_coords); footpath_remove_litter(_coords.x, _coords.y, surfaceHeight); if (!gCheatsDisableClearanceChecks) - wall_remove_at_z(_coords.x, _coords.y, surfaceHeight); + wall_remove_at_z({ _coords, surfaceHeight }); SurfaceElement* surfaceElement = map_get_surface_element_at(_coords); if (surfaceElement == nullptr) diff --git a/src/openrct2/world/Map.h b/src/openrct2/world/Map.h index 57c403f15b..35ffed0ca7 100644 --- a/src/openrct2/world/Map.h +++ b/src/openrct2/world/Map.h @@ -197,7 +197,6 @@ void tile_element_iterator_begin(tile_element_iterator* it); int32_t tile_element_iterator_next(tile_element_iterator* it); void tile_element_iterator_restart_for_tile(tile_element_iterator* it); -void wall_remove_intersecting_walls(int32_t x, int32_t y, int32_t z0, int32_t z1, int32_t direction); void map_update_tiles(); int32_t map_get_highest_z(const CoordsXY& loc); @@ -207,8 +206,9 @@ void map_remove_out_of_range_elements(); void map_extend_boundary_surface(); bool map_large_scenery_sign_set_colour(const CoordsXYZD& signPos, int32_t sequence, uint8_t mainColour, uint8_t textColour); -void wall_remove_at(int32_t x, int32_t y, int32_t z0, int32_t z1); -void wall_remove_at_z(int32_t x, int32_t y, int32_t z); +void wall_remove_at(const CoordsXYRangedZ& wallPos); +void wall_remove_at_z(const CoordsXYZ& wallPos); +void wall_remove_intersecting_walls(const CoordsXYRangedZ& wallPos, Direction direction); void map_invalidate_tile(const CoordsXYRangedZ& tilePos); void map_invalidate_tile_zoom1(const CoordsXYRangedZ& tilePos); diff --git a/src/openrct2/world/Wall.cpp b/src/openrct2/world/Wall.cpp index 400f8e65b3..f22b10eae1 100644 --- a/src/openrct2/world/Wall.cpp +++ b/src/openrct2/world/Wall.cpp @@ -33,27 +33,25 @@ * * rct2: 0x006E588E */ -void wall_remove_at(int32_t x, int32_t y, int32_t z0, int32_t z1) +void wall_remove_at(const CoordsXYRangedZ& wallPos) { TileElement* tileElement; - z0 /= 8; - z1 /= 8; repeat: - tileElement = map_get_first_element_at({ x, y }); + tileElement = map_get_first_element_at(wallPos); if (tileElement == nullptr) return; do { if (tileElement->GetType() != TILE_ELEMENT_TYPE_WALL) continue; - if (z0 >= tileElement->clearance_height) + if (wallPos.baseZ >= tileElement->GetClearanceZ()) continue; - if (z1 <= tileElement->base_height) + if (wallPos.clearanceZ <= tileElement->GetBaseZ()) continue; tile_element_remove_banner_entry(tileElement); - map_invalidate_tile_zoom1({ x, y, tileElement->GetBaseZ(), tileElement->GetBaseZ() + 72 }); + map_invalidate_tile_zoom1({ wallPos, tileElement->GetBaseZ(), tileElement->GetBaseZ() + 72 }); tile_element_remove(tileElement); goto repeat; } while (!(tileElement++)->IsLastForTile()); @@ -63,20 +61,20 @@ repeat: * * rct2: 0x006E57E6 */ -void wall_remove_at_z(int32_t x, int32_t y, int32_t z) +void wall_remove_at_z(const CoordsXYZ& wallPos) { - wall_remove_at(x, y, z, z + 48); + wall_remove_at({ wallPos, wallPos.z, wallPos.z + 48 }); } /** * * rct2: 0x006E5935 */ -void wall_remove_intersecting_walls(int32_t x, int32_t y, int32_t z0, int32_t z1, int32_t direction) +void wall_remove_intersecting_walls(const CoordsXYRangedZ& wallPos, Direction direction) { TileElement* tileElement; - tileElement = map_get_first_element_at({ x, y }); + tileElement = map_get_first_element_at(wallPos); if (tileElement == nullptr) return; do @@ -84,14 +82,14 @@ void wall_remove_intersecting_walls(int32_t x, int32_t y, int32_t z0, int32_t z1 if (tileElement->GetType() != TILE_ELEMENT_TYPE_WALL) continue; - if (tileElement->clearance_height <= z0 || tileElement->base_height >= z1) + if (tileElement->GetClearanceZ() <= wallPos.baseZ || tileElement->GetBaseZ() >= wallPos.clearanceZ) continue; if (direction != tileElement->GetDirection()) continue; tile_element_remove_banner_entry(tileElement); - map_invalidate_tile_zoom1({ x, y, tileElement->GetBaseZ(), tileElement->GetBaseZ() + 72 }); + map_invalidate_tile_zoom1({ wallPos, tileElement->GetBaseZ(), tileElement->GetBaseZ() + 72 }); tile_element_remove(tileElement); tileElement--; } while (!(tileElement++)->IsLastForTile());