From 89edde6a3ce30e249620507954009f6c5a26f44d Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sun, 12 Jan 2020 22:27:30 -0300 Subject: [PATCH] Use CoordsXY on footpath_bridge_get_info_from_pos() --- src/openrct2-ui/windows/Footpath.cpp | 24 ++++++++++-------------- src/openrct2-ui/windows/Map.cpp | 14 ++++++-------- src/openrct2/world/Footpath.cpp | 15 ++++----------- src/openrct2/world/Footpath.h | 3 +-- 4 files changed, 21 insertions(+), 35 deletions(-) diff --git a/src/openrct2-ui/windows/Footpath.cpp b/src/openrct2-ui/windows/Footpath.cpp index 90d1c98623..8301a5cdbc 100644 --- a/src/openrct2-ui/windows/Footpath.cpp +++ b/src/openrct2-ui/windows/Footpath.cpp @@ -788,15 +788,15 @@ static void window_footpath_set_provisional_path_at_point(ScreenCoordsXY screenC */ static void window_footpath_set_selection_start_bridge_at_point(ScreenCoordsXY screenCoords) { - int32_t x, y, direction; + int32_t direction; TileElement* tileElement; map_invalidate_selection_rect(); gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE; gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE_ARROW; - footpath_bridge_get_info_from_pos(screenCoords, &x, &y, &direction, &tileElement); - if (x == LOCATION_NULL) + auto mapCoords = footpath_bridge_get_info_from_pos(screenCoords, &direction, &tileElement); + if (mapCoords.isNull()) { return; } @@ -804,10 +804,8 @@ static void window_footpath_set_selection_start_bridge_at_point(ScreenCoordsXY s gMapSelectFlags |= MAP_SELECT_FLAG_ENABLE; gMapSelectFlags |= MAP_SELECT_FLAG_ENABLE_ARROW; gMapSelectType = MAP_SELECT_TYPE_FULL; - gMapSelectPositionA.x = x; - gMapSelectPositionB.x = x; - gMapSelectPositionA.y = y; - gMapSelectPositionB.y = y; + gMapSelectPositionA = mapCoords; + gMapSelectPositionB = mapCoords; int32_t z = tileElement->GetBaseZ(); @@ -822,7 +820,7 @@ static void window_footpath_set_selection_start_bridge_at_point(ScreenCoordsXY s z += PATH_HEIGHT_STEP; // Add another 2 for a steep slope } - gMapSelectArrowPosition = CoordsXYZ{ x, y, z }; + gMapSelectArrowPosition = CoordsXYZ{ mapCoords, z }; gMapSelectArrowDirection = direction; map_invalidate_selection_rect(); @@ -903,11 +901,11 @@ static void window_footpath_place_path_at_point(ScreenCoordsXY screenCoords) */ static void window_footpath_start_bridge_at_point(ScreenCoordsXY screenCoords) { - int32_t x, y, z, direction; + int32_t z, direction; TileElement* tileElement; - footpath_bridge_get_info_from_pos(screenCoords, &x, &y, &direction, &tileElement); - if (x == LOCATION_NULL) + auto mapCoords = footpath_bridge_get_info_from_pos(screenCoords, &direction, &tileElement); + if (mapCoords.isNull()) { return; } @@ -945,9 +943,7 @@ static void window_footpath_start_bridge_at_point(ScreenCoordsXY screenCoords) } tool_cancel(); - gFootpathConstructFromPosition.x = x; - gFootpathConstructFromPosition.y = y; - gFootpathConstructFromPosition.z = z; + gFootpathConstructFromPosition = { mapCoords, z }; gFootpathConstructDirection = direction; gFootpathProvisionalFlags = 0; _window_footpath_provisional_path_arrow_timer = 0; diff --git a/src/openrct2-ui/windows/Map.cpp b/src/openrct2-ui/windows/Map.cpp index f445fc3c75..ba64d475f8 100644 --- a/src/openrct2-ui/windows/Map.cpp +++ b/src/openrct2-ui/windows/Map.cpp @@ -1269,14 +1269,14 @@ static void window_map_place_park_entrance_tool_update(ScreenCoordsXY screenCoor */ static void window_map_set_peep_spawn_tool_update(ScreenCoordsXY screenCoords) { - int32_t mapX, mapY, mapZ, direction; + int32_t mapZ, direction; TileElement* tileElement; map_invalidate_selection_rect(); gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE; gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE_ARROW; - footpath_bridge_get_info_from_pos(screenCoords, &mapX, &mapY, &direction, &tileElement); - if ((mapX & 0xFFFF) == 0x8000) + auto mapCoords = footpath_bridge_get_info_from_pos(screenCoords, &direction, &tileElement); + if (mapCoords.isNull()) return; mapZ = tileElement->GetBaseZ(); @@ -1291,11 +1291,9 @@ static void window_map_set_peep_spawn_tool_update(ScreenCoordsXY screenCoords) gMapSelectFlags |= MAP_SELECT_FLAG_ENABLE; gMapSelectFlags |= MAP_SELECT_FLAG_ENABLE_ARROW; gMapSelectType = MAP_SELECT_TYPE_FULL; - gMapSelectPositionA.x = mapX; - gMapSelectPositionA.y = mapY; - gMapSelectPositionB.x = mapX; - gMapSelectPositionB.y = mapY; - gMapSelectArrowPosition = CoordsXYZ{ mapX, mapY, mapZ }; + gMapSelectPositionA = mapCoords; + gMapSelectPositionB = mapCoords; + gMapSelectArrowPosition = CoordsXYZ{ mapCoords, mapZ }; gMapSelectArrowDirection = direction_reverse(direction); map_invalidate_selection_rect(); } diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 35d3f2fbad..041cad16dc 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -339,8 +339,7 @@ CoordsXY footpath_get_coordinates_from_pos(ScreenCoordsXY screenCoords, int32_t* * direction: cl * tileElement: edx */ -void footpath_bridge_get_info_from_pos( - ScreenCoordsXY screenCoords, int32_t* x, int32_t* y, int32_t* direction, TileElement** tileElement) +CoordsXY footpath_bridge_get_info_from_pos(ScreenCoordsXY screenCoords, int32_t* direction, TileElement** tileElement) { // First check if we point at an entrance or exit. In that case, we would want the path coming from the entrance/exit. int32_t interactionType; @@ -349,8 +348,6 @@ void footpath_bridge_get_info_from_pos( CoordsXY map_pos = {}; get_map_coordinates_from_pos( screenCoords, VIEWPORT_INTERACTION_MASK_RIDE, map_pos, &interactionType, tileElement, &viewport); - *x = map_pos.x; - *y = map_pos.y; if (interactionType == VIEWPORT_INTERACTION_ITEM_RIDE && viewport->flags & (VIEWPORT_FLAG_UNDERGROUND_INSIDE | VIEWPORT_FLAG_HIDE_BASE | VIEWPORT_FLAG_HIDE_VERTICAL) @@ -364,15 +361,13 @@ void footpath_bridge_get_info_from_pos( bx &= 3; if (direction != nullptr) *direction = bx; - return; + return map_pos; } } get_map_coordinates_from_pos( screenCoords, VIEWPORT_INTERACTION_MASK_RIDE & VIEWPORT_INTERACTION_MASK_FOOTPATH & VIEWPORT_INTERACTION_MASK_TERRAIN, map_pos, &interactionType, tileElement, &viewport); - *x = map_pos.x; - *y = map_pos.y; if (interactionType == VIEWPORT_INTERACTION_ITEM_RIDE && (*tileElement)->GetType() == TILE_ELEMENT_TYPE_ENTRANCE) { int32_t directions = entrance_get_directions(*tileElement); @@ -381,14 +376,12 @@ void footpath_bridge_get_info_from_pos( int32_t bx = (*tileElement)->GetDirectionWithOffset(bitscanforward(directions)); if (direction != nullptr) *direction = bx; - return; + return map_pos; } } // We point at something else - auto coords = footpath_get_coordinates_from_pos(screenCoords, direction, tileElement); - *x = coords.x; - *y = coords.y; + return footpath_get_coordinates_from_pos(screenCoords, direction, tileElement); } /** diff --git a/src/openrct2/world/Footpath.h b/src/openrct2/world/Footpath.h index b73f0383f7..6b2a84862d 100644 --- a/src/openrct2/world/Footpath.h +++ b/src/openrct2/world/Footpath.h @@ -184,8 +184,7 @@ money32 footpath_provisional_set(int32_t type, CoordsXYZ footpathLoc, int32_t sl void footpath_provisional_remove(); void footpath_provisional_update(); CoordsXY footpath_get_coordinates_from_pos(ScreenCoordsXY screenCoords, int32_t* direction, TileElement** tileElement); -void footpath_bridge_get_info_from_pos( - ScreenCoordsXY screenCoords, int32_t* x, int32_t* y, int32_t* direction, TileElement** tileElement); +CoordsXY footpath_bridge_get_info_from_pos(ScreenCoordsXY screenCoords, int32_t* direction, TileElement** tileElement); void footpath_remove_litter(const CoordsXYZ& footpathPos); void footpath_connect_edges(const CoordsXY& footpathPos, TileElement* tileElement, int32_t flags); void footpath_update_queue_chains();