1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-31 02:35:46 +01:00

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
This commit is contained in:
Tulio Leao
2019-12-30 13:51:01 -03:00
committed by Duncan
parent a7b33a7d36
commit 8b4e0d7bab
11 changed files with 32 additions and 34 deletions

View File

@@ -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)

View File

@@ -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();
}

View File

@@ -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 });
}
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -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);

View File

@@ -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 });
}
}

View File

@@ -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);
}
}
}

View File

@@ -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)

View File

@@ -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);

View File

@@ -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());