From 5a74d057b05a5e5173d0ebcb86bcf732589a44a5 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Mon, 13 Jan 2020 20:18:47 -0300 Subject: [PATCH 1/9] Use CoordsXY on banner_get_closest_ride_index() --- .../actions/LargeSceneryPlaceAction.hpp | 2 +- src/openrct2/actions/SignSetNameAction.hpp | 5 +--- src/openrct2/actions/WallPlaceAction.hpp | 2 +- src/openrct2/world/Banner.cpp | 23 +++++++++++-------- src/openrct2/world/Banner.h | 2 +- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/openrct2/actions/LargeSceneryPlaceAction.hpp b/src/openrct2/actions/LargeSceneryPlaceAction.hpp index 3836645458..d5158a40ee 100644 --- a/src/openrct2/actions/LargeSceneryPlaceAction.hpp +++ b/src/openrct2/actions/LargeSceneryPlaceAction.hpp @@ -266,7 +266,7 @@ public: banner->position.x = _loc.x / 32; banner->position.y = _loc.y / 32; - ride_id_t rideIndex = banner_get_closest_ride_index(_loc.x, _loc.y, maxHeight); + ride_id_t rideIndex = banner_get_closest_ride_index({ _loc, maxHeight }); if (rideIndex != RIDE_ID_NULL) { banner->ride_index = rideIndex; diff --git a/src/openrct2/actions/SignSetNameAction.hpp b/src/openrct2/actions/SignSetNameAction.hpp index 74199cd44e..06d24a7893 100644 --- a/src/openrct2/actions/SignSetNameAction.hpp +++ b/src/openrct2/actions/SignSetNameAction.hpp @@ -60,9 +60,6 @@ public: { auto banner = GetBanner(_bannerIndex); - int32_t x = banner->position.x << 5; - int32_t y = banner->position.y << 5; - if (!_name.empty()) { banner->flags &= ~BANNER_FLAG_LINKED_TO_RIDE; @@ -72,7 +69,7 @@ public: else { // If empty name take closest ride name. - ride_id_t rideIndex = banner_get_closest_ride_index(x, y, 16); + ride_id_t rideIndex = banner_get_closest_ride_index({ banner->position.ToCoordsXY(), 16 }); if (rideIndex == RIDE_ID_NULL) { banner->flags &= ~BANNER_FLAG_LINKED_TO_RIDE; diff --git a/src/openrct2/actions/WallPlaceAction.hpp b/src/openrct2/actions/WallPlaceAction.hpp index 3327ee12fe..7031052b24 100644 --- a/src/openrct2/actions/WallPlaceAction.hpp +++ b/src/openrct2/actions/WallPlaceAction.hpp @@ -362,7 +362,7 @@ public: banner->position.x = _loc.x / 32; banner->position.y = _loc.y / 32; - ride_id_t rideIndex = banner_get_closest_ride_index(_loc.x, _loc.y, targetHeight); + ride_id_t rideIndex = banner_get_closest_ride_index({ _loc, targetHeight }); if (rideIndex != RIDE_ID_NULL) { banner->ride_index = rideIndex; diff --git a/src/openrct2/world/Banner.cpp b/src/openrct2/world/Banner.cpp index ff2275b3b3..69491a5c76 100644 --- a/src/openrct2/world/Banner.cpp +++ b/src/openrct2/world/Banner.cpp @@ -209,15 +209,21 @@ WallElement* banner_get_scrolling_wall_tile_element(BannerIndex bannerIndex) * * rct2: 0x006B7D86 */ -uint8_t banner_get_closest_ride_index(int32_t x, int32_t y, int32_t z) +uint8_t banner_get_closest_ride_index(const CoordsXYZ& mapPos) { - static constexpr const LocationXY16 NeighbourCheckOrder[] = { { 32, 0 }, { -32, 0 }, { 0, 32 }, - { 0, -32 }, { -32, +32 }, { +32, -32 }, - { +32, +32 }, { -32, +32 }, { 0, 0 } }; + static constexpr const std::array NeighbourCheckOrder = { CoordsXY{ COORDS_XY_STEP, 0 }, + CoordsXY{ -COORDS_XY_STEP, 0 }, + { 0, COORDS_XY_STEP }, + CoordsXY{ 0, -COORDS_XY_STEP }, + CoordsXY{ -COORDS_XY_STEP, +COORDS_XY_STEP }, + CoordsXY{ +COORDS_XY_STEP, -COORDS_XY_STEP }, + CoordsXY{ +COORDS_XY_STEP, +COORDS_XY_STEP }, + CoordsXY{ -COORDS_XY_STEP, +COORDS_XY_STEP }, + CoordsXY{ 0, 0 } }; - for (size_t i = 0; i < std::size(NeighbourCheckOrder); i++) + for (const auto& neighhbourCoords : NeighbourCheckOrder) { - ride_id_t rideIndex = banner_get_ride_index_at(x + NeighbourCheckOrder[i].x, y + NeighbourCheckOrder[i].y, z); + ride_id_t rideIndex = banner_get_ride_index_at(mapPos.x + neighhbourCoords.x, mapPos.y + neighhbourCoords.y, mapPos.z); if (rideIndex != RIDE_ID_NULL) { return rideIndex; @@ -235,9 +241,8 @@ uint8_t banner_get_closest_ride_index(int32_t x, int32_t y, int32_t z) if (location.isNull()) continue; - int32_t rideX = location.x * 32; - int32_t rideY = location.y * 32; - int32_t distance = abs(x - rideX) + abs(y - rideY); + auto rideCoords = location.ToCoordsXY(); + int32_t distance = abs(mapPos.x - rideCoords.x) + abs(mapPos.y - rideCoords.y); if (distance < resultDistance) { resultDistance = distance; diff --git a/src/openrct2/world/Banner.h b/src/openrct2/world/Banner.h index 0fe1d373d8..750ee66390 100644 --- a/src/openrct2/world/Banner.h +++ b/src/openrct2/world/Banner.h @@ -49,7 +49,7 @@ void banner_init(); BannerIndex create_new_banner(uint8_t flags); TileElement* banner_get_tile_element(BannerIndex bannerIndex); WallElement* banner_get_scrolling_wall_tile_element(BannerIndex bannerIndex); -uint8_t banner_get_closest_ride_index(int32_t x, int32_t y, int32_t z); +uint8_t banner_get_closest_ride_index(const CoordsXYZ& mapPos); void banner_reset_broken_index(); void fix_duplicated_banners(); Banner* GetBanner(BannerIndex id); From 49bd8e0c67a5b7a27f060c4337992ab0ac1fff3d Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Mon, 13 Jan 2020 20:47:18 -0300 Subject: [PATCH 2/9] Use CoordsXYZ on banner_get_ride_index_at() --- src/openrct2/world/Banner.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/openrct2/world/Banner.cpp b/src/openrct2/world/Banner.cpp index 69491a5c76..b7830d04bb 100644 --- a/src/openrct2/world/Banner.cpp +++ b/src/openrct2/world/Banner.cpp @@ -77,9 +77,9 @@ size_t Banner::FormatTextTo(void* argsV) const * * rct2: 0x006B7EAB */ -static uint8_t banner_get_ride_index_at(int32_t x, int32_t y, int32_t z) +static uint8_t banner_get_ride_index_at(const CoordsXYZ& bannerCoords) { - TileElement* tileElement = map_get_first_element_at({ x, y }); + TileElement* tileElement = map_get_first_element_at(bannerCoords); ride_id_t resultRideIndex = RIDE_ID_NULL; if (tileElement == nullptr) return resultRideIndex; @@ -93,7 +93,7 @@ static uint8_t banner_get_ride_index_at(int32_t x, int32_t y, int32_t z) if (ride == nullptr || ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_IS_SHOP)) continue; - if ((tileElement->GetClearanceZ()) + 32 <= z) + if ((tileElement->GetClearanceZ()) + (4 * COORDS_Z_STEP) <= bannerCoords.z) continue; resultRideIndex = rideIndex; @@ -223,7 +223,7 @@ uint8_t banner_get_closest_ride_index(const CoordsXYZ& mapPos) for (const auto& neighhbourCoords : NeighbourCheckOrder) { - ride_id_t rideIndex = banner_get_ride_index_at(mapPos.x + neighhbourCoords.x, mapPos.y + neighhbourCoords.y, mapPos.z); + ride_id_t rideIndex = banner_get_ride_index_at({ CoordsXY{ mapPos } + neighhbourCoords, mapPos.z }); if (rideIndex != RIDE_ID_NULL) { return rideIndex; From e65f9424cfe2a9a9cd2849c7ab29e14dde508835 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Mon, 13 Jan 2020 21:03:57 -0300 Subject: [PATCH 3/9] Use CoordsXYZ on rct_duck::MoveTo() --- src/openrct2/world/Duck.cpp | 42 ++++++++++++++++++------------------- src/openrct2/world/Sprite.h | 2 +- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/openrct2/world/Duck.cpp b/src/openrct2/world/Duck.cpp index 8fd74157db..2ca268fe12 100644 --- a/src/openrct2/world/Duck.cpp +++ b/src/openrct2/world/Duck.cpp @@ -100,9 +100,9 @@ void rct_duck::Remove() sprite_remove((rct_sprite*)this); } -void rct_duck::MoveTo(int16_t destX, int16_t destY, int16_t destZ) +void rct_duck::MoveTo(const CoordsXYZ& destination) { - sprite_move(destX, destY, destZ, (rct_sprite*)this); + sprite_move(destination.x, destination.y, destination.z, (rct_sprite*)this); } void rct_duck::UpdateFlyToWater() @@ -119,9 +119,8 @@ void rct_duck::UpdateFlyToWater() Invalidate(); int32_t manhattanDistance = abs(target_x - x) + abs(target_y - y); int32_t direction = sprite_direction >> 3; - int32_t newX = x + DuckMoveOffset[direction].x; - int32_t newY = y + DuckMoveOffset[direction].y; - int32_t manhattanDistanceN = abs(target_x - newX) + abs(target_y - newY); + auto destination = CoordsXYZ{ CoordsXY{ x, y } + DuckMoveOffset[direction], 0 }; + int32_t manhattanDistanceN = abs(target_x - destination.x) + abs(target_y - destination.y); auto surfaceElement = map_get_surface_element_at(CoordsXY{ target_x, target_y }); int32_t waterHeight = surfaceElement != nullptr ? surfaceElement->GetWaterHeight() : 0; @@ -132,29 +131,29 @@ void rct_duck::UpdateFlyToWater() } else { - int32_t newZ = abs(z - waterHeight); + destination.z = abs(z - waterHeight); if (manhattanDistanceN <= manhattanDistance) { - if (newZ > manhattanDistanceN) + if (destination.z > manhattanDistanceN) { - newZ = z - 2; + destination.z = z - 2; if (waterHeight >= z) { - newZ += 4; + destination.z += 4; } frame = 1; } else { - newZ = z; + destination.z = z; } - MoveTo(newX, newY, newZ); + MoveTo(destination); Invalidate(); } else { - if (newZ > 4) + if (destination.z > 4) { state = DUCK_STATE::FLY_AWAY; UpdateFlyAway(); @@ -220,14 +219,14 @@ void rct_duck::UpdateSwim() } int32_t direction = sprite_direction >> 3; - int32_t newX = x + DuckMoveOffset[direction].x; - int32_t newY = y + DuckMoveOffset[direction].y; - landZ = tile_element_height({ newX, newY }); - waterZ = tile_element_water_height({ newX, newY }); + auto destination = CoordsXYZ{ CoordsXY{ x, y } + DuckMoveOffset[direction], 0 }; + landZ = tile_element_height(destination); + waterZ = tile_element_water_height(destination); if (z >= landZ && z == waterZ) { - MoveTo(newX, newY, waterZ); + destination.z = waterZ; + MoveTo(destination); Invalidate(); } } @@ -278,12 +277,11 @@ void rct_duck::UpdateFlyAway() Invalidate(); int32_t direction = sprite_direction >> 3; - int32_t newX = x + (DuckMoveOffset[direction].x * 2); - int32_t newY = y + (DuckMoveOffset[direction].y * 2); - int32_t newZ = std::min(z + 2, 496); - if (map_is_location_valid({ newX, newY })) + auto destination = CoordsXYZ{ x + (DuckMoveOffset[direction].x * 2), y + (DuckMoveOffset[direction].y * 2), + std::min(z + 2, 496) }; + if (map_is_location_valid(destination)) { - MoveTo(newX, newY, newZ); + MoveTo(destination); Invalidate(); } else diff --git a/src/openrct2/world/Sprite.h b/src/openrct2/world/Sprite.h index e4570d97ba..a94c4f8317 100644 --- a/src/openrct2/world/Sprite.h +++ b/src/openrct2/world/Sprite.h @@ -69,7 +69,7 @@ struct rct_duck : rct_sprite_generic uint32_t GetFrameImage(int32_t direction) const; void Invalidate(); void Remove(); - void MoveTo(int16_t x, int16_t y, int16_t z); + void MoveTo(const CoordsXYZ& destination); }; struct rct_money_effect : rct_sprite_common From d34321fdaa27b83286040e5708580a1fdaaf4049 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Mon, 13 Jan 2020 21:19:08 -0300 Subject: [PATCH 4/9] Use CoordsXY on ride_entrance_exit_place_ghost() --- src/openrct2-ui/windows/RideConstruction.cpp | 3 +-- src/openrct2/ride/Ride.h | 2 +- src/openrct2/world/Entrance.cpp | 20 ++++++++++---------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index 1e3e0eafa4..bd70b82642 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -3713,8 +3713,7 @@ void ride_construction_toolupdate_entrance_exit(ScreenCoordsXY screenCoords) if (ride != nullptr) { _currentTrackPrice = ride_entrance_exit_place_ghost( - ride, entranceOrExitCoords.x, entranceOrExitCoords.y, entranceOrExitCoords.direction, - gRideEntranceExitPlaceType, stationNum); + ride, entranceOrExitCoords, entranceOrExitCoords.direction, gRideEntranceExitPlaceType, stationNum); } window_ride_construction_update_active_elements(); } diff --git a/src/openrct2/ride/Ride.h b/src/openrct2/ride/Ride.h index 59b223732d..78cbec6381 100644 --- a/src/openrct2/ride/Ride.h +++ b/src/openrct2/ride/Ride.h @@ -1222,7 +1222,7 @@ void ride_get_start_of_track(CoordsXYE* output); void window_ride_construction_update_active_elements(); void ride_construction_remove_ghosts(); money32 ride_entrance_exit_place_ghost( - Ride* ride, int32_t x, int32_t y, int32_t direction, int32_t placeType, int32_t stationNum); + Ride* ride, const CoordsXY& entranceExitCoords, int32_t direction, int32_t placeType, int32_t stationNum); CoordsXYZD ride_get_entrance_or_exit_position_from_screen_position(ScreenCoordsXY screenCoords); bool ride_select_backwards_from_front(); diff --git a/src/openrct2/world/Entrance.cpp b/src/openrct2/world/Entrance.cpp index aab195337e..35c5cc7455 100644 --- a/src/openrct2/world/Entrance.cpp +++ b/src/openrct2/world/Entrance.cpp @@ -36,10 +36,10 @@ CoordsXYZD gRideEntranceExitGhostPosition; uint8_t gRideEntranceExitGhostStationIndex; static money32 RideEntranceExitPlaceGhost( - ride_id_t rideIndex, int16_t x, int16_t y, uint8_t direction, uint8_t placeType, uint8_t stationNum) + ride_id_t rideIndex, const CoordsXY& entranceExitCoords, uint8_t direction, uint8_t placeType, uint8_t stationNum) { auto rideEntranceExitPlaceAction = RideEntranceExitPlaceAction( - { x, y }, direction, rideIndex, stationNum, placeType == ENTRANCE_TYPE_RIDE_EXIT); + entranceExitCoords, direction, rideIndex, stationNum, placeType == ENTRANCE_TYPE_RIDE_EXIT); rideEntranceExitPlaceAction.SetFlags(GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_GHOST); auto res = GameActions::Execute(&rideEntranceExitPlaceAction); @@ -85,8 +85,8 @@ void ride_entrance_exit_place_provisional_ghost() if (_currentTrackSelectionFlags & TRACK_SELECTION_FLAG_ENTRANCE_OR_EXIT) { RideEntranceExitPlaceGhost( - _currentRideIndex, gRideEntranceExitGhostPosition.x, gRideEntranceExitGhostPosition.y, - gRideEntranceExitGhostPosition.direction, gRideEntranceExitPlaceType, gRideEntranceExitGhostStationIndex); + _currentRideIndex, gRideEntranceExitGhostPosition, gRideEntranceExitGhostPosition.direction, + gRideEntranceExitPlaceType, gRideEntranceExitGhostStationIndex); } } @@ -95,8 +95,8 @@ void ride_entrance_exit_remove_ghost() if (_currentTrackSelectionFlags & TRACK_SELECTION_FLAG_ENTRANCE_OR_EXIT) { auto rideEntranceExitRemove = RideEntranceExitRemoveAction( - { gRideEntranceExitGhostPosition.x, gRideEntranceExitGhostPosition.y }, _currentRideIndex, - gRideEntranceExitGhostStationIndex, gRideEntranceExitPlaceType == ENTRANCE_TYPE_RIDE_EXIT); + gRideEntranceExitGhostPosition, _currentRideIndex, gRideEntranceExitGhostStationIndex, + gRideEntranceExitPlaceType == ENTRANCE_TYPE_RIDE_EXIT); rideEntranceExitRemove.SetFlags(GAME_COMMAND_FLAG_GHOST | GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED); GameActions::Execute(&rideEntranceExitRemove); @@ -108,16 +108,16 @@ void ride_entrance_exit_remove_ghost() * rct2: 0x006CA28C */ money32 ride_entrance_exit_place_ghost( - Ride* ride, int32_t x, int32_t y, int32_t direction, int32_t placeType, int32_t stationNum) + Ride* ride, const CoordsXY& entranceExitCoords, int32_t direction, int32_t placeType, int32_t stationNum) { ride_construction_remove_ghosts(); - money32 result = RideEntranceExitPlaceGhost(ride->id, x, y, direction, placeType, stationNum); + money32 result = RideEntranceExitPlaceGhost(ride->id, entranceExitCoords, direction, placeType, stationNum); if (result != MONEY32_UNDEFINED) { _currentTrackSelectionFlags |= TRACK_SELECTION_FLAG_ENTRANCE_OR_EXIT; - gRideEntranceExitGhostPosition.x = x; - gRideEntranceExitGhostPosition.y = y; + gRideEntranceExitGhostPosition.x = entranceExitCoords.x; + gRideEntranceExitGhostPosition.y = entranceExitCoords.y; gRideEntranceExitGhostPosition.direction = direction; gRideEntranceExitGhostStationIndex = stationNum & 0xFF; } From 893086440c862eca875d6a94e37eb16338e12c11 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Mon, 13 Jan 2020 21:21:41 -0300 Subject: [PATCH 5/9] Use CoordsXYZ on park_entrance_get_index() --- src/openrct2-ui/windows/TileInspector.cpp | 2 +- src/openrct2/actions/ParkEntranceRemoveAction.hpp | 4 ++-- src/openrct2/world/Entrance.cpp | 4 ++-- src/openrct2/world/Park.h | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index 84bcb37a23..cc05988d1c 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -1974,7 +1974,7 @@ static void window_tile_inspector_paint(rct_window* w, rct_drawpixelinfo* dpi) { // TODO: Make this work with Left/Right park entrance parts int16_t parkEntranceIndex = park_entrance_get_index( - windowTileInspectorToolMap.x, windowTileInspectorToolMap.y, tileElement->GetBaseZ()); + { windowTileInspectorToolMap, tileElement->GetBaseZ() }); gfx_draw_string_left( dpi, STR_TILE_INSPECTOR_ENTRANCE_ENTRANCE_ID, &parkEntranceIndex, COLOUR_WHITE, x, y + 11); } diff --git a/src/openrct2/actions/ParkEntranceRemoveAction.hpp b/src/openrct2/actions/ParkEntranceRemoveAction.hpp index bb12ec4882..341e9fec27 100644 --- a/src/openrct2/actions/ParkEntranceRemoveAction.hpp +++ b/src/openrct2/actions/ParkEntranceRemoveAction.hpp @@ -52,7 +52,7 @@ public: res->Position = _loc; res->ErrorTitle = STR_CANT_REMOVE_THIS; - auto entranceIndex = park_entrance_get_index(_loc.x, _loc.y, _loc.z); + auto entranceIndex = park_entrance_get_index(_loc); if (entranceIndex == -1) { log_error("Could not find entrance at x = %d, y = %d, z = %d", _loc.x, _loc.y, _loc.z); @@ -68,7 +68,7 @@ public: res->Position = _loc; res->ErrorTitle = STR_CANT_REMOVE_THIS; - auto entranceIndex = park_entrance_get_index(_loc.x, _loc.y, _loc.z); + auto entranceIndex = park_entrance_get_index(_loc); if (entranceIndex == -1) { log_error("Could not find entrance at x = %d, y = %d, z = %d", _loc.x, _loc.y, _loc.z); diff --git a/src/openrct2/world/Entrance.cpp b/src/openrct2/world/Entrance.cpp index 35c5cc7455..e5650a8d9b 100644 --- a/src/openrct2/world/Entrance.cpp +++ b/src/openrct2/world/Entrance.cpp @@ -61,12 +61,12 @@ void park_entrance_remove_ghost() } } -int32_t park_entrance_get_index(int32_t x, int32_t y, int32_t z) +int32_t park_entrance_get_index(const CoordsXYZ& entrancePos) { int32_t i = 0; for (const auto& entrance : gParkEntrances) { - if (x == entrance.x && y == entrance.y && z == entrance.z) + if (entrancePos == entrance) { return i; } diff --git a/src/openrct2/world/Park.h b/src/openrct2/world/Park.h index 72d1ca9c8a..dd3e61463f 100644 --- a/src/openrct2/world/Park.h +++ b/src/openrct2/world/Park.h @@ -120,7 +120,7 @@ void update_park_fences_around_tile(CoordsXY coords); uint8_t calculate_guest_initial_happiness(uint8_t percentage); void park_set_open(bool open); -int32_t park_entrance_get_index(int32_t x, int32_t y, int32_t z); +int32_t park_entrance_get_index(const CoordsXYZ& entrancePos); void park_set_entrance_fee(money32 value); money16 park_get_entrance_fee(); From a3ecefcf89cf2fbd3d2ca42bd7b9dfa1c079c68e Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Mon, 13 Jan 2020 21:44:05 -0300 Subject: [PATCH 6/9] Use CoordsXYE on maze_entrance_hedge_replacement() --- .../actions/RideEntranceExitRemoveAction.hpp | 2 +- src/openrct2/ride/Ride.cpp | 2 +- src/openrct2/world/Entrance.cpp | 15 +++++++-------- src/openrct2/world/Entrance.h | 3 ++- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/openrct2/actions/RideEntranceExitRemoveAction.hpp b/src/openrct2/actions/RideEntranceExitRemoveAction.hpp index a1b2d86d79..149f56f7f9 100644 --- a/src/openrct2/actions/RideEntranceExitRemoveAction.hpp +++ b/src/openrct2/actions/RideEntranceExitRemoveAction.hpp @@ -171,7 +171,7 @@ public: res->Position.z = tile_element_height(res->Position); footpath_queue_chain_reset(); - maze_entrance_hedge_replacement(_loc.x, _loc.y, tileElement); + maze_entrance_hedge_replacement({ _loc, tileElement }); footpath_remove_edges_at(_loc, tileElement); tile_element_remove(tileElement); diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index e67db138eb..41fa100f82 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -7091,7 +7091,7 @@ void sub_6CB945(Ride* ride) if (shouldRemove) { footpath_queue_chain_reset(); - maze_entrance_hedge_replacement(location.x, location.y, tileElement); + maze_entrance_hedge_replacement({ location, tileElement }); footpath_remove_edges_at(location, tileElement); footpath_update_queue_chains(); map_invalidate_tile_full(location); diff --git a/src/openrct2/world/Entrance.cpp b/src/openrct2/world/Entrance.cpp index e5650a8d9b..0a650286e3 100644 --- a/src/openrct2/world/Entrance.cpp +++ b/src/openrct2/world/Entrance.cpp @@ -128,15 +128,14 @@ money32 ride_entrance_exit_place_ghost( * Replaces the outer hedge walls for an entrance placement removal. * rct2: 0x00666D6F */ -void maze_entrance_hedge_replacement(int32_t x, int32_t y, TileElement* tileElement) +void maze_entrance_hedge_replacement(const CoordsXYE& entrance) { - int32_t direction = tileElement->GetDirection(); - x += CoordsDirectionDelta[direction].x; - y += CoordsDirectionDelta[direction].y; - int32_t z = tileElement->GetBaseZ(); - ride_id_t rideIndex = tileElement->AsEntrance()->GetRideIndex(); + int32_t direction = entrance.element->GetDirection(); + auto hedgePos = entrance + CoordsDirectionDelta[direction]; + int32_t z = entrance.element->GetBaseZ(); + ride_id_t rideIndex = entrance.element->AsEntrance()->GetRideIndex(); - tileElement = map_get_first_element_at({ x, y }); + auto tileElement = map_get_first_element_at(hedgePos); if (tileElement == nullptr) return; do @@ -157,7 +156,7 @@ void maze_entrance_hedge_replacement(int32_t x, int32_t y, TileElement* tileElem // Add the bottom outer wall tileElement->AsTrack()->MazeEntryAdd(1 << ((mazeSection + 12) & 0x0F)); - map_invalidate_tile({ x, y, tileElement->GetBaseZ(), tileElement->GetClearanceZ() }); + map_invalidate_tile({ hedgePos, tileElement->GetBaseZ(), tileElement->GetClearanceZ() }); return; } while (!(tileElement++)->IsLastForTile()); } diff --git a/src/openrct2/world/Entrance.h b/src/openrct2/world/Entrance.h index c3c048a95c..25dbe90c18 100644 --- a/src/openrct2/world/Entrance.h +++ b/src/openrct2/world/Entrance.h @@ -12,6 +12,7 @@ #include "../common.h" #include "Location.hpp" +#include "Map.h" #include @@ -44,7 +45,7 @@ void park_entrance_remove_ghost(); money32 park_entrance_place_ghost(CoordsXYZD entranceLoc); void reset_park_entrance(); -void maze_entrance_hedge_replacement(int32_t x, int32_t y, TileElement* tileElement); +void maze_entrance_hedge_replacement(const CoordsXYE& entrance); void maze_entrance_hedge_removal(int32_t x, int32_t y, TileElement* tileElement); void fix_park_entrance_locations(); From c8097eab3a31ad3c5f0c245ccc1066aba548e2a9 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Mon, 13 Jan 2020 21:48:12 -0300 Subject: [PATCH 7/9] Use CoordsXYE on maze_entrance_hedge_removal() --- .../actions/RideEntranceExitPlaceAction.hpp | 2 +- src/openrct2/ride/Ride.cpp | 8 +++----- src/openrct2/world/Entrance.cpp | 15 +++++++-------- src/openrct2/world/Entrance.h | 2 +- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/openrct2/actions/RideEntranceExitPlaceAction.hpp b/src/openrct2/actions/RideEntranceExitPlaceAction.hpp index f24cca4dc0..1dffab2496 100644 --- a/src/openrct2/actions/RideEntranceExitPlaceAction.hpp +++ b/src/openrct2/actions/RideEntranceExitPlaceAction.hpp @@ -221,7 +221,7 @@ public: if (!(GetFlags() & GAME_COMMAND_FLAG_GHOST)) { - maze_entrance_hedge_removal(_loc.x, _loc.y, tileElement); + maze_entrance_hedge_removal({ _loc, tileElement }); } footpath_connect_edges(_loc, tileElement, GetFlags()); diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 41fa100f82..33807af8d1 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -4271,9 +4271,7 @@ static void ride_set_maze_entrance_exit_points(Ride* ride) // Enumerate entrance and exit positions for (position = positions; !(*position).isNull(); position++) { - int32_t x = (*position).x << 5; - int32_t y = (*position).y << 5; - int32_t z = (*position).z; + auto entranceExitMapPos = position->ToCoordsXYZ(); TileElement* tileElement = map_get_first_element_at(position->ToCoordsXY()); do @@ -4287,10 +4285,10 @@ static void ride_set_maze_entrance_exit_points(Ride* ride) { continue; } - if (tileElement->base_height != z) + if (tileElement->GetBaseZ() != entranceExitMapPos.z) continue; - maze_entrance_hedge_removal(x, y, tileElement); + maze_entrance_hedge_removal({ entranceExitMapPos, tileElement }); } while (!(tileElement++)->IsLastForTile()); } } diff --git a/src/openrct2/world/Entrance.cpp b/src/openrct2/world/Entrance.cpp index 0a650286e3..23161dc538 100644 --- a/src/openrct2/world/Entrance.cpp +++ b/src/openrct2/world/Entrance.cpp @@ -165,15 +165,14 @@ void maze_entrance_hedge_replacement(const CoordsXYE& entrance) * Removes the hedge walls for an entrance placement. * rct2: 0x00666CBE */ -void maze_entrance_hedge_removal(int32_t x, int32_t y, TileElement* tileElement) +void maze_entrance_hedge_removal(const CoordsXYE& entrance) { - int32_t direction = tileElement->GetDirection(); - x += CoordsDirectionDelta[direction].x; - y += CoordsDirectionDelta[direction].y; - int32_t z = tileElement->GetBaseZ(); - ride_id_t rideIndex = tileElement->AsEntrance()->GetRideIndex(); + int32_t direction = entrance.element->GetDirection(); + auto hedgePos = entrance + CoordsDirectionDelta[direction]; + int32_t z = entrance.element->GetBaseZ(); + ride_id_t rideIndex = entrance.element->AsEntrance()->GetRideIndex(); - tileElement = map_get_first_element_at({ x, y }); + auto tileElement = map_get_first_element_at(hedgePos); if (tileElement == nullptr) return; do @@ -200,7 +199,7 @@ void maze_entrance_hedge_removal(int32_t x, int32_t y, TileElement* tileElement) // Remove the bottom hedge section tileElement->AsTrack()->MazeEntrySubtract(1 << ((mazeSection + 15) & 0x0F)); - map_invalidate_tile({ x, y, tileElement->GetBaseZ(), tileElement->GetClearanceZ() }); + map_invalidate_tile({ hedgePos, tileElement->GetBaseZ(), tileElement->GetClearanceZ() }); return; } while (!(tileElement++)->IsLastForTile()); } diff --git a/src/openrct2/world/Entrance.h b/src/openrct2/world/Entrance.h index 25dbe90c18..1e1dc829f1 100644 --- a/src/openrct2/world/Entrance.h +++ b/src/openrct2/world/Entrance.h @@ -46,7 +46,7 @@ money32 park_entrance_place_ghost(CoordsXYZD entranceLoc); void reset_park_entrance(); void maze_entrance_hedge_replacement(const CoordsXYE& entrance); -void maze_entrance_hedge_removal(int32_t x, int32_t y, TileElement* tileElement); +void maze_entrance_hedge_removal(const CoordsXYE& entrance); void fix_park_entrance_locations(); From 0d88c73b90dbaf84927f42ec3addecc1a9316069 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Mon, 13 Jan 2020 22:11:26 -0300 Subject: [PATCH 8/9] Prefer std::array and COORDS defines on Fountain arrays --- src/openrct2/world/Fountain.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/openrct2/world/Fountain.cpp b/src/openrct2/world/Fountain.cpp index ff705a92b2..fa40463483 100644 --- a/src/openrct2/world/Fountain.cpp +++ b/src/openrct2/world/Fountain.cpp @@ -38,12 +38,25 @@ namespace FOUNTAIN_FLAG const uint32_t DIRECTION = 1 << 7; }; // namespace FOUNTAIN_FLAG -static constexpr const CoordsXY _fountainDirectionsNegative[] = { - { -32, 0 }, { -32, -32 }, { 0, 0 }, { -32, 0 }, { 0, 0 }, { 0, -32 }, { 0, -32 }, { -32, -32 }, +static constexpr const std::array _fountainDirectionsNegative = { + CoordsXY{ -COORDS_XY_STEP, 0 }, + CoordsXY{ -COORDS_XY_STEP, -COORDS_XY_STEP }, + CoordsXY{ 0, 0 }, + CoordsXY{ -COORDS_XY_STEP, 0 }, + CoordsXY{ 0, 0 }, + CoordsXY{ 0, -COORDS_XY_STEP }, + CoordsXY{ 0, -COORDS_XY_STEP }, + CoordsXY{ -COORDS_XY_STEP, -COORDS_XY_STEP }, }; -static constexpr const CoordsXY _fountainDirectionsPositive[] = { { 32, 0 }, { 0, 0 }, { 0, 32 }, { 32, 32 }, - { 32, 32 }, { 32, 0 }, { 0, 0 }, { 0, 32 } }; +static constexpr const std::array _fountainDirectionsPositive = { CoordsXY{ COORDS_XY_STEP, 0 }, + CoordsXY{ 0, 0 }, + CoordsXY{ 0, COORDS_XY_STEP }, + CoordsXY{ COORDS_XY_STEP, COORDS_XY_STEP }, + CoordsXY{ COORDS_XY_STEP, COORDS_XY_STEP }, + CoordsXY{ COORDS_XY_STEP, 0 }, + CoordsXY{ 0, 0 }, + CoordsXY{ 0, COORDS_XY_STEP } }; constexpr auto _FountainChanceOfStoppingEdgeMode = 0x3333; // 0.200 constexpr auto _FountainChanceOfStoppingRandomMode = 0x2000; // 0.125 @@ -192,7 +205,7 @@ void JumpingFountain::AdvanceAnimation() const CoordsXY newLoc = CoordsXY{ x, y } + CoordsDirectionDelta[direction]; int32_t availableDirections = 0; - for (int32_t i = 0; i < 8; i++) + for (uint32_t i = 0; i < _fountainDirectionsNegative.size(); i++) { if (IsJumpingFountain(newType, { newLoc + _fountainDirectionsNegative[i], z })) { From b7e9b36a2703e824b33b7ef879026dedc97c7f85 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Mon, 13 Jan 2020 22:22:04 -0300 Subject: [PATCH 9/9] Prefer std::array and COORDS defines on Map::CoordsDirectionDelta --- src/openrct2/world/Map.cpp | 14 ++++++++++++-- src/openrct2/world/Map.h | 2 +- test/testpaint/Compat.cpp | 18 +++++++++--------- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index 64ed9125cf..448fe69468 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -63,8 +63,18 @@ using namespace OpenRCT2; /** * Replaces 0x00993CCC, 0x00993CCE */ -const CoordsXY CoordsDirectionDelta[] = { { -32, 0 }, { 0, +32 }, { +32, 0 }, { 0, -32 }, - { -32, +32 }, { +32, +32 }, { +32, -32 }, { -32, -32 } }; +// clang-format off +const std::array CoordsDirectionDelta = { + CoordsXY{ -COORDS_XY_STEP, 0 }, + CoordsXY{ 0, +COORDS_XY_STEP }, + CoordsXY{ +COORDS_XY_STEP, 0 }, + CoordsXY{ 0, -COORDS_XY_STEP }, + CoordsXY{ -COORDS_XY_STEP, +COORDS_XY_STEP }, + CoordsXY{ +COORDS_XY_STEP, +COORDS_XY_STEP }, + CoordsXY{ +COORDS_XY_STEP, -COORDS_XY_STEP }, + CoordsXY{ -COORDS_XY_STEP, -COORDS_XY_STEP } +}; +// clang-format on const TileCoordsXY TileDirectionDelta[] = { { -1, 0 }, { 0, +1 }, { +1, 0 }, { 0, -1 }, { -1, +1 }, { +1, +1 }, { +1, -1 }, { -1, -1 } }; diff --git a/src/openrct2/world/Map.h b/src/openrct2/world/Map.h index 83239fc88a..56e2d11cc8 100644 --- a/src/openrct2/world/Map.h +++ b/src/openrct2/world/Map.h @@ -96,7 +96,7 @@ enum CREATE_CROSSING_MODE_PATH_OVER_TRACK, }; -extern const CoordsXY CoordsDirectionDelta[]; +extern const std::array CoordsDirectionDelta; extern const TileCoordsXY TileDirectionDelta[]; extern uint16_t gWidePathTileLoopX; diff --git a/test/testpaint/Compat.cpp b/test/testpaint/Compat.cpp index c6bc766a6c..addbfa9368 100644 --- a/test/testpaint/Compat.cpp +++ b/test/testpaint/Compat.cpp @@ -38,15 +38,15 @@ uint32_t gScenarioTicks; uint8_t gCurrentRotation; // clang-format off -const CoordsXY CoordsDirectionDelta[] = { - { -32, 0 }, - { 0, +32 }, - { +32, 0 }, - { 0, -32 }, - { -32, +32 }, - { +32, +32 }, - { +32, -32 }, - { -32, -32 }, +constexpr const std::array CoordsDirectionDelta = { + CoordsXY{ -COORDS_XY_STEP, 0 }, + CoordsXY{ 0, +COORDS_XY_STEP }, + CoordsXY{ +COORDS_XY_STEP, 0 }, + CoordsXY{ 0, -COORDS_XY_STEP }, + CoordsXY{ -COORDS_XY_STEP, +COORDS_XY_STEP }, + CoordsXY{ +COORDS_XY_STEP, +COORDS_XY_STEP }, + CoordsXY{ +COORDS_XY_STEP, -COORDS_XY_STEP }, + CoordsXY{ -COORDS_XY_STEP, -COORDS_XY_STEP }, }; const TileCoordsXY TileDirectionDelta[] = {