diff --git a/src/openrct2-ui/interface/ViewportInteraction.cpp b/src/openrct2-ui/interface/ViewportInteraction.cpp index bd4d02ac52..d44e1988cb 100644 --- a/src/openrct2-ui/interface/ViewportInteraction.cpp +++ b/src/openrct2-ui/interface/ViewportInteraction.cpp @@ -660,16 +660,15 @@ static Peep* viewport_interaction_get_closest_peep(ScreenCoordsXY screenCoords, */ CoordsXY sub_68A15E(ScreenCoordsXY screenCoords) { - int16_t mapX, mapY; + CoordsXY mapCoords; CoordsXY initialPos{}; int32_t interactionType; TileElement* tileElement; rct_viewport* viewport; get_map_coordinates_from_pos( - screenCoords.x, screenCoords.y, VIEWPORT_INTERACTION_MASK_TERRAIN & VIEWPORT_INTERACTION_MASK_WATER, &mapX, &mapY, - &interactionType, &tileElement, &viewport); - initialPos.x = mapX; - initialPos.y = mapY; + screenCoords, VIEWPORT_INTERACTION_MASK_TERRAIN & VIEWPORT_INTERACTION_MASK_WATER, mapCoords, &interactionType, + &tileElement, &viewport); + initialPos = mapCoords; if (interactionType == VIEWPORT_INTERACTION_ITEM_NONE) { diff --git a/src/openrct2-ui/windows/Footpath.cpp b/src/openrct2-ui/windows/Footpath.cpp index d64ddd965e..f78662d7aa 100644 --- a/src/openrct2-ui/windows/Footpath.cpp +++ b/src/openrct2-ui/windows/Footpath.cpp @@ -715,10 +715,10 @@ static void window_footpath_set_provisional_path_at_point(ScreenCoordsXY screenC int32_t interactionType{}; TileElement* tileElement{}; - LocationXY16 mapCoord = {}; + CoordsXY mapCoord = {}; get_map_coordinates_from_pos( - screenCoords.x, screenCoords.y, VIEWPORT_INTERACTION_MASK_FOOTPATH & VIEWPORT_INTERACTION_MASK_TERRAIN, &mapCoord.x, - &mapCoord.y, &interactionType, &tileElement, nullptr); + screenCoords, VIEWPORT_INTERACTION_MASK_FOOTPATH & VIEWPORT_INTERACTION_MASK_TERRAIN, mapCoord, &interactionType, + &tileElement, nullptr); if (interactionType == VIEWPORT_INTERACTION_ITEM_NONE || tileElement == nullptr) { @@ -849,10 +849,10 @@ static void window_footpath_place_path_at_point(ScreenCoordsXY screenCoords) footpath_provisional_update(); - LocationXY16 mapCoord = {}; + CoordsXY mapCoord = {}; get_map_coordinates_from_pos( - screenCoords.x, screenCoords.y, VIEWPORT_INTERACTION_MASK_FOOTPATH & VIEWPORT_INTERACTION_MASK_TERRAIN, &mapCoord.x, - &mapCoord.y, &interactionType, &tileElement, nullptr); + screenCoords, VIEWPORT_INTERACTION_MASK_FOOTPATH & VIEWPORT_INTERACTION_MASK_TERRAIN, mapCoord, &interactionType, + &tileElement, nullptr); if (interactionType == VIEWPORT_INTERACTION_ITEM_NONE) { diff --git a/src/openrct2-ui/windows/Guest.cpp b/src/openrct2-ui/windows/Guest.cpp index 0e991917e7..a0ff3b520f 100644 --- a/src/openrct2-ui/windows/Guest.cpp +++ b/src/openrct2-ui/windows/Guest.cpp @@ -1246,8 +1246,9 @@ void window_guest_overview_tool_update(rct_window* w, rct_widgetindex widgetInde gPickupPeepImage = UINT32_MAX; int32_t interactionType; + CoordsXY unusedCoords; get_map_coordinates_from_pos( - screenCoords.x, screenCoords.y, VIEWPORT_INTERACTION_MASK_NONE, nullptr, nullptr, &interactionType, nullptr, nullptr); + screenCoords, VIEWPORT_INTERACTION_MASK_NONE, unusedCoords, &interactionType, nullptr, nullptr); if (interactionType == VIEWPORT_INTERACTION_ITEM_NONE) return; diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index 66e0ae8b0c..6113602bbb 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -4397,9 +4397,8 @@ static void window_ride_set_track_colour_scheme(rct_window* w, int32_t x, int32_ newColourScheme = (uint8_t)w->ride_colour; - LocationXY16 mapCoord = {}; - get_map_coordinates_from_pos( - x, y, VIEWPORT_INTERACTION_MASK_RIDE, &mapCoord.x, &mapCoord.y, &interactionType, &tileElement, nullptr); + CoordsXY mapCoord = {}; + get_map_coordinates_from_pos({ x, y }, VIEWPORT_INTERACTION_MASK_RIDE, mapCoord, &interactionType, &tileElement, nullptr); x = mapCoord.x; y = mapCoord.y; @@ -5574,14 +5573,14 @@ static void window_ride_measurements_update(rct_window* w) static void window_ride_measurements_tooldown(rct_window* w, rct_widgetindex widgetIndex, ScreenCoordsXY screenCoords) { TileElement* tileElement; - int16_t mapX, mapY; + CoordsXY mapCoords; int32_t interactionType; _lastSceneryX = screenCoords.x; _lastSceneryY = screenCoords.y; _collectTrackDesignScenery = true; // Default to true in case user does not select anything valid - get_map_coordinates_from_pos(screenCoords.x, screenCoords.y, 0xFCCF, &mapX, &mapY, &interactionType, &tileElement, nullptr); + get_map_coordinates_from_pos(screenCoords, 0xFCCF, mapCoords, &interactionType, &tileElement, nullptr); switch (interactionType) { case VIEWPORT_INTERACTION_ITEM_SCENERY: @@ -5589,7 +5588,7 @@ static void window_ride_measurements_tooldown(rct_window* w, rct_widgetindex wid case VIEWPORT_INTERACTION_ITEM_WALL: case VIEWPORT_INTERACTION_ITEM_FOOTPATH: _collectTrackDesignScenery = !track_design_save_contains_tile_element(tileElement); - track_design_save_select_tile_element(interactionType, { mapX, mapY }, tileElement, _collectTrackDesignScenery); + track_design_save_select_tile_element(interactionType, mapCoords, tileElement, _collectTrackDesignScenery); break; } } @@ -5602,17 +5601,17 @@ static void window_ride_measurements_tooldrag(rct_window* w, rct_widgetindex wid _lastSceneryY = screenCoords.y; TileElement* tileElement; - int16_t mapX, mapY; + CoordsXY mapCoords; int32_t interactionType; - get_map_coordinates_from_pos(screenCoords.x, screenCoords.y, 0xFCCF, &mapX, &mapY, &interactionType, &tileElement, nullptr); + get_map_coordinates_from_pos(screenCoords, 0xFCCF, mapCoords, &interactionType, &tileElement, nullptr); switch (interactionType) { case VIEWPORT_INTERACTION_ITEM_SCENERY: case VIEWPORT_INTERACTION_ITEM_LARGE_SCENERY: case VIEWPORT_INTERACTION_ITEM_WALL: case VIEWPORT_INTERACTION_ITEM_FOOTPATH: - track_design_save_select_tile_element(interactionType, { mapX, mapY }, tileElement, _collectTrackDesignScenery); + track_design_save_select_tile_element(interactionType, mapCoords, tileElement, _collectTrackDesignScenery); break; } } diff --git a/src/openrct2-ui/windows/Staff.cpp b/src/openrct2-ui/windows/Staff.cpp index 2d938d58fb..deef0e72ad 100644 --- a/src/openrct2-ui/windows/Staff.cpp +++ b/src/openrct2-ui/windows/Staff.cpp @@ -1162,8 +1162,9 @@ void window_staff_overview_tool_update(rct_window* w, rct_widgetindex widgetInde gPickupPeepImage = UINT32_MAX; int32_t interactionType; + CoordsXY unusedCoords; get_map_coordinates_from_pos( - screenCoords.x, screenCoords.y, VIEWPORT_INTERACTION_MASK_NONE, nullptr, nullptr, &interactionType, nullptr, nullptr); + screenCoords, VIEWPORT_INTERACTION_MASK_NONE, unusedCoords, &interactionType, nullptr, nullptr); if (interactionType == VIEWPORT_INTERACTION_ITEM_NONE) return; diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index cb9749e91b..99ee1fa44f 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -1222,27 +1222,23 @@ static void window_tile_inspector_tool_update(rct_window* w, rct_widgetindex wid gMapSelectFlags |= MAP_SELECT_FLAG_ENABLE; - int16_t mapX = 0; - int16_t mapY = 0; + CoordsXY mapCoords; TileElement* clickedElement = nullptr; if (input_test_place_object_modifier(PLACE_OBJECT_MODIFIER_COPY_Z)) { - get_map_coordinates_from_pos( - screenCoords.x, screenCoords.y, ViewportInteractionFlags, &mapX, &mapY, nullptr, &clickedElement, nullptr); + get_map_coordinates_from_pos(screenCoords, ViewportInteractionFlags, mapCoords, nullptr, &clickedElement, nullptr); } // Even if Ctrl was pressed, fall back to normal selection when there was nothing under the cursor if (clickedElement == nullptr) { - CoordsXY mapCoords = screen_pos_to_map_pos(screenCoords, nullptr); - mapX = mapCoords.x; - mapY = mapCoords.y; + mapCoords = screen_pos_to_map_pos(screenCoords, nullptr); } - if (mapX != LOCATION_NULL) + if (mapCoords.x != LOCATION_NULL) { - gMapSelectPositionA.x = gMapSelectPositionB.x = mapX; - gMapSelectPositionA.y = gMapSelectPositionB.y = mapY; + gMapSelectPositionA.x = gMapSelectPositionB.x = mapCoords.x; + gMapSelectPositionA.y = gMapSelectPositionB.y = mapCoords.y; } else if (windowTileInspectorTileSelected) { @@ -1273,19 +1269,17 @@ static void window_tile_inspector_update_selected_tile(rct_window* w, ScreenCoor windowTileInspectorToolMouseY = screenCoords.y; windowTileInspectorToolCtrlDown = ctrlIsHeldDown; - int16_t mapX = 0; - int16_t mapY = 0; + CoordsXY mapCoords{}; TileElement* clickedElement = nullptr; if (ctrlIsHeldDown) { - get_map_coordinates_from_pos( - screenCoords.x, screenCoords.y, ViewportInteractionFlags, &mapX, &mapY, nullptr, &clickedElement, nullptr); + get_map_coordinates_from_pos(screenCoords, ViewportInteractionFlags, mapCoords, nullptr, &clickedElement, nullptr); } // Even if Ctrl was pressed, fall back to normal selection when there was nothing under the cursor if (clickedElement == nullptr) { - CoordsXY mapCoords = screen_pos_to_map_pos(screenCoords, nullptr); + mapCoords = screen_pos_to_map_pos(screenCoords, nullptr); if (mapCoords.x == LOCATION_NULL) { @@ -1298,15 +1292,12 @@ static void window_tile_inspector_update_selected_tile(rct_window* w, ScreenCoor { return; } - mapX = mapCoords.x; - mapY = mapCoords.y; } windowTileInspectorTileSelected = true; - windowTileInspectorToolMap.x = mapX; - windowTileInspectorToolMap.y = mapY; - windowTileInspectorTileX = mapX >> 5; - windowTileInspectorTileY = mapY >> 5; + windowTileInspectorToolMap = mapCoords; + windowTileInspectorTileX = mapCoords.x >> 5; + windowTileInspectorTileY = mapCoords.y >> 5; window_tile_inspector_load_tile(w, clickedElement); } diff --git a/src/openrct2-ui/windows/TopToolbar.cpp b/src/openrct2-ui/windows/TopToolbar.cpp index 65c64ea582..5110f791c1 100644 --- a/src/openrct2-ui/windows/TopToolbar.cpp +++ b/src/openrct2-ui/windows/TopToolbar.cpp @@ -1017,7 +1017,6 @@ static void window_top_toolbar_paint(rct_window* w, rct_drawpixelinfo* dpi) static void repaint_scenery_tool_down(int16_t x, int16_t y, rct_widgetindex widgetIndex) { // ax, cx, bl - int16_t grid_x, grid_y; int32_t type; // edx TileElement* tile_element; @@ -1027,7 +1026,8 @@ static void repaint_scenery_tool_down(int16_t x, int16_t y, rct_widgetindex widg // not used rct_viewport* viewport; - get_map_coordinates_from_pos(x, y, flags, &grid_x, &grid_y, &type, &tile_element, &viewport); + CoordsXY gridCoords; + get_map_coordinates_from_pos({ x, y }, flags, gridCoords, &type, &tile_element, &viewport); switch (type) { @@ -1042,8 +1042,8 @@ static void repaint_scenery_tool_down(int16_t x, int16_t y, rct_widgetindex widg uint8_t quadrant = tile_element->AsSmallScenery()->GetSceneryQuadrant(); auto repaintScenery = SmallScenerySetColourAction( - { grid_x, grid_y, tile_element->base_height * 8 }, quadrant, tile_element->AsSmallScenery()->GetEntryIndex(), - gWindowSceneryPrimaryColour, gWindowScenerySecondaryColour); + { gridCoords.x, gridCoords.y, tile_element->base_height * 8 }, quadrant, + tile_element->AsSmallScenery()->GetEntryIndex(), gWindowSceneryPrimaryColour, gWindowScenerySecondaryColour); GameActions::Execute(&repaintScenery); break; @@ -1057,8 +1057,8 @@ static void repaint_scenery_tool_down(int16_t x, int16_t y, rct_widgetindex widg return; auto repaintScenery = WallSetColourAction( - { grid_x, grid_y, tile_element->base_height * 8, tile_element->GetDirection() }, gWindowSceneryPrimaryColour, - gWindowScenerySecondaryColour, gWindowSceneryTertiaryColour); + { gridCoords.x, gridCoords.y, tile_element->base_height * 8, tile_element->GetDirection() }, + gWindowSceneryPrimaryColour, gWindowScenerySecondaryColour, gWindowSceneryTertiaryColour); GameActions::Execute(&repaintScenery); break; @@ -1072,7 +1072,7 @@ static void repaint_scenery_tool_down(int16_t x, int16_t y, rct_widgetindex widg return; auto repaintScenery = LargeScenerySetColourAction( - { grid_x, grid_y, tile_element->base_height * 8, tile_element->GetDirection() }, + { gridCoords.x, gridCoords.y, tile_element->base_height * 8, tile_element->GetDirection() }, tile_element->AsLargeScenery()->GetSequenceIndex(), gWindowSceneryPrimaryColour, gWindowScenerySecondaryColour); GameActions::Execute(&repaintScenery); @@ -1087,7 +1087,7 @@ static void repaint_scenery_tool_down(int16_t x, int16_t y, rct_widgetindex widg if (scenery_entry->banner.flags & BANNER_ENTRY_FLAG_HAS_PRIMARY_COLOUR) { auto repaintScenery = BannerSetColourAction( - { grid_x, grid_y, tile_element->base_height * 8, tile_element->AsBanner()->GetPosition() }, + { gridCoords.x, gridCoords.y, tile_element->base_height * 8, tile_element->AsBanner()->GetPosition() }, gWindowSceneryPrimaryColour); GameActions::Execute(&repaintScenery); @@ -1105,11 +1105,11 @@ static void scenery_eyedropper_tool_down(int16_t x, int16_t y, rct_widgetindex w auto flags = VIEWPORT_INTERACTION_MASK_SCENERY & VIEWPORT_INTERACTION_MASK_WALL & VIEWPORT_INTERACTION_MASK_LARGE_SCENERY & VIEWPORT_INTERACTION_MASK_BANNER & VIEWPORT_INTERACTION_MASK_FOOTPATH_ITEM; - int16_t gridX, gridY; int32_t type; TileElement* tileElement; rct_viewport* viewport; - get_map_coordinates_from_pos(x, y, flags, &gridX, &gridY, &type, &tileElement, &viewport); + CoordsXY unusedCoords; + get_map_coordinates_from_pos({ x, y }, flags, unusedCoords, &type, &tileElement, &viewport); switch (type) { @@ -1278,7 +1278,8 @@ static void sub_6E1F34( & VIEWPORT_INTERACTION_MASK_SCENERY & VIEWPORT_INTERACTION_MASK_FOOTPATH & VIEWPORT_INTERACTION_MASK_WALL & VIEWPORT_INTERACTION_MASK_LARGE_SCENERY; int32_t interaction_type; - get_map_coordinates_from_pos(x, y, flags, nullptr, nullptr, &interaction_type, &tile_element, nullptr); + CoordsXY unusedCoords; + get_map_coordinates_from_pos({ x, y }, flags, unusedCoords, &interaction_type, &tile_element, nullptr); if (interaction_type != VIEWPORT_INTERACTION_ITEM_NONE) { @@ -1428,8 +1429,11 @@ static void sub_6E1F34( auto flags = VIEWPORT_INTERACTION_MASK_TERRAIN & VIEWPORT_INTERACTION_MASK_WATER; int32_t interaction_type = 0; TileElement* tile_element; + CoordsXY gridCoords; - get_map_coordinates_from_pos(x, y, flags, grid_x, grid_y, &interaction_type, &tile_element, nullptr); + get_map_coordinates_from_pos({ x, y }, flags, gridCoords, &interaction_type, &tile_element, nullptr); + *grid_x = gridCoords.x; + *grid_y = gridCoords.y; if (interaction_type == VIEWPORT_INTERACTION_ITEM_NONE) { @@ -1503,8 +1507,11 @@ static void sub_6E1F34( auto flags = VIEWPORT_INTERACTION_MASK_FOOTPATH & VIEWPORT_INTERACTION_MASK_FOOTPATH_ITEM; int32_t interaction_type = 0; TileElement* tile_element; + CoordsXY gridCoords; - get_map_coordinates_from_pos(x, y, flags, grid_x, grid_y, &interaction_type, &tile_element, nullptr); + get_map_coordinates_from_pos({ x, y }, flags, gridCoords, &interaction_type, &tile_element, nullptr); + *grid_x = gridCoords.x; + *grid_y = gridCoords.y; if (interaction_type == VIEWPORT_INTERACTION_ITEM_NONE) { @@ -1666,8 +1673,11 @@ static void sub_6E1F34( auto flags = VIEWPORT_INTERACTION_MASK_FOOTPATH & VIEWPORT_INTERACTION_MASK_FOOTPATH_ITEM; int32_t interaction_type = 0; TileElement* tile_element; + CoordsXY gridCoords; - get_map_coordinates_from_pos(x, y, flags, grid_x, grid_y, &interaction_type, &tile_element, nullptr); + get_map_coordinates_from_pos({ x, y }, flags, gridCoords, &interaction_type, &tile_element, nullptr); + *grid_x = gridCoords.x; + *grid_y = gridCoords.y; if (interaction_type == VIEWPORT_INTERACTION_ITEM_NONE) { @@ -2347,11 +2357,11 @@ static void top_toolbar_tool_update_water(int16_t x, int16_t y) gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE; - LocationXY16 mapTile = {}; + CoordsXY mapTile = {}; int32_t interaction_type = 0; get_map_coordinates_from_pos( - x, y, VIEWPORT_INTERACTION_MASK_TERRAIN & VIEWPORT_INTERACTION_MASK_WATER, &mapTile.x, &mapTile.y, &interaction_type, - nullptr, nullptr); + { x, y }, VIEWPORT_INTERACTION_MASK_TERRAIN & VIEWPORT_INTERACTION_MASK_WATER, mapTile, &interaction_type, nullptr, + nullptr); if (interaction_type == VIEWPORT_INTERACTION_ITEM_NONE) { diff --git a/src/openrct2-ui/windows/Viewport.cpp b/src/openrct2-ui/windows/Viewport.cpp index c36c6954b7..3eac76e2dc 100644 --- a/src/openrct2-ui/windows/Viewport.cpp +++ b/src/openrct2-ui/windows/Viewport.cpp @@ -124,7 +124,6 @@ static void window_viewport_anchor_border_widgets(rct_window* w) static void window_viewport_mouseup(rct_window* w, rct_widgetindex widgetIndex) { rct_window* mainWindow; - int16_t x, y; switch (widgetIndex) { @@ -149,10 +148,11 @@ static void window_viewport_mouseup(rct_window* w, rct_widgetindex widgetIndex) mainWindow = window_get_main(); if (mainWindow != nullptr) { + CoordsXY mapCoords; get_map_coordinates_from_pos( - w->x + (w->width / 2), w->y + (w->height / 2), VIEWPORT_INTERACTION_MASK_NONE, &x, &y, nullptr, nullptr, - nullptr); - window_scroll_to_location(mainWindow, x, y, tile_element_height({ x, y })); + { w->x + (w->width / 2), w->y + (w->height / 2) }, VIEWPORT_INTERACTION_MASK_NONE, mapCoords, nullptr, + nullptr, nullptr); + window_scroll_to_location(mainWindow, mapCoords.x, mapCoords.y, tile_element_height(mapCoords)); } break; } diff --git a/src/openrct2/interface/InteractiveConsole.cpp b/src/openrct2/interface/InteractiveConsole.cpp index d167a80a99..f4599bd1e0 100644 --- a/src/openrct2/interface/InteractiveConsole.cpp +++ b/src/openrct2/interface/InteractiveConsole.cpp @@ -649,11 +649,11 @@ static int32_t cc_get(InteractiveConsole& console, const arguments_t& argv) { int32_t interactionType; TileElement* tileElement; - LocationXY16 mapCoord = {}; + CoordsXY mapCoord = {}; rct_viewport* viewport = window_get_viewport(w); get_map_coordinates_from_pos( - viewport->view_width / 2, viewport->view_height / 2, VIEWPORT_INTERACTION_MASK_TERRAIN, &mapCoord.x, - &mapCoord.y, &interactionType, &tileElement, nullptr); + { viewport->view_width / 2, viewport->view_height / 2 }, VIEWPORT_INTERACTION_MASK_TERRAIN, mapCoord, + &interactionType, &tileElement, nullptr); mapCoord.x -= 16; mapCoord.x /= 32; mapCoord.y -= 16; @@ -1689,7 +1689,7 @@ static constexpr const console_command console_command_table[] = { { "replay_stop", cc_replay_stop, "Stops the replay", "replay_stop"}, { "replay_normalise", cc_replay_normalise, "Normalises the replay to remove all gaps", "replay_normalise "}, { "mp_desync", cc_mp_desync, "Forces a multiplayer desync", "cc_mp_desync [desync_type, 0 = Random t-shirt color on random peep, 1 = Remove random peep ]"}, - + }; // clang-format on diff --git a/src/openrct2/interface/Viewport.cpp b/src/openrct2/interface/Viewport.cpp index 95a12f4c6e..b2478044d2 100644 --- a/src/openrct2/interface/Viewport.cpp +++ b/src/openrct2/interface/Viewport.cpp @@ -1628,20 +1628,6 @@ void get_map_coordinates_from_pos( get_map_coordinates_from_pos_window(window, screenCoords, flags, mapCoords, interactionType, tileElement, viewport); } -void get_map_coordinates_from_pos( - int32_t screenX, int32_t screenY, int32_t flags, int16_t* x, int16_t* y, int32_t* interactionType, - TileElement** tileElement, rct_viewport** viewport) -{ - ScreenCoordsXY screenCoords{ screenX, screenY }; - CoordsXY mapCoords; - get_map_coordinates_from_pos(screenCoords, flags, mapCoords, interactionType, tileElement, viewport); - - if (x != nullptr) - *x = mapCoords.x; - if (y != nullptr) - *y = mapCoords.y; -} - void get_map_coordinates_from_pos_window( rct_window* window, ScreenCoordsXY screenCoords, int32_t flags, CoordsXY& mapCoords, int32_t* interactionType, TileElement** tileElement, rct_viewport** viewport) @@ -1769,32 +1755,31 @@ static rct_viewport* viewport_find_from_point(ScreenCoordsXY screenCoords) */ CoordsXY screen_get_map_xy(ScreenCoordsXY screenCoords, rct_viewport** viewport) { - int16_t my_x, my_y; int32_t interactionType; rct_viewport* myViewport = nullptr; + CoordsXY map_pos; get_map_coordinates_from_pos( - screenCoords.x, screenCoords.y, VIEWPORT_INTERACTION_MASK_TERRAIN, &my_x, &my_y, &interactionType, nullptr, - &myViewport); + screenCoords, VIEWPORT_INTERACTION_MASK_TERRAIN, map_pos, &interactionType, nullptr, &myViewport); if (interactionType == VIEWPORT_INTERACTION_ITEM_NONE) { return { LOCATION_NULL, 0 }; } LocationXY16 start_vp_pos = screen_coord_to_viewport_coord(myViewport, screenCoords); - CoordsXY map_pos = { my_x + 16, my_y + 16 }; + CoordsXY modifiedPos = { map_pos.x + 16, map_pos.y + 16 }; for (int32_t i = 0; i < 5; i++) { int32_t z = tile_element_height(map_pos); - map_pos = viewport_coord_to_map_coord(start_vp_pos.x, start_vp_pos.y, z); - map_pos.x = std::clamp(map_pos.x, my_x, my_x + 31); - map_pos.y = std::clamp(map_pos.y, my_y, my_y + 31); + modifiedPos = viewport_coord_to_map_coord(start_vp_pos.x, start_vp_pos.y, z); + modifiedPos.x = std::clamp(modifiedPos.x, map_pos.x, map_pos.x + 31); + modifiedPos.y = std::clamp(modifiedPos.y, map_pos.y, map_pos.y + 31); } if (viewport != nullptr) *viewport = myViewport; - return map_pos; + return modifiedPos; } /** diff --git a/src/openrct2/interface/Viewport.h b/src/openrct2/interface/Viewport.h index 4c4432c123..62e0b0a7c0 100644 --- a/src/openrct2/interface/Viewport.h +++ b/src/openrct2/interface/Viewport.h @@ -152,9 +152,6 @@ void show_construction_rights(); void hide_construction_rights(); void viewport_set_visibility(uint8_t mode); -void get_map_coordinates_from_pos( - int32_t screenX, int32_t screenY, int32_t flags, int16_t* x, int16_t* y, int32_t* interactionType, - TileElement** tileElement, rct_viewport** viewport); void get_map_coordinates_from_pos( ScreenCoordsXY screenCoords, int32_t flags, CoordsXY& mapCoords, int32_t* interactionType, TileElement** tileElement, rct_viewport** viewport); diff --git a/src/openrct2/interface/Window.cpp b/src/openrct2/interface/Window.cpp index 8fbad85760..4d31742a37 100644 --- a/src/openrct2/interface/Window.cpp +++ b/src/openrct2/interface/Window.cpp @@ -957,12 +957,13 @@ void window_viewport_get_map_coords_by_cursor( context_get_cursor_position_scaled(&mouse_x, &mouse_y); // Compute map coordinate by mouse position. - get_map_coordinates_from_pos(mouse_x, mouse_y, VIEWPORT_INTERACTION_MASK_NONE, map_x, map_y, nullptr, nullptr, nullptr); + CoordsXY mapCoords; + get_map_coordinates_from_pos({ mouse_x, mouse_y }, VIEWPORT_INTERACTION_MASK_NONE, mapCoords, nullptr, nullptr, nullptr); // Get viewport coordinates centring around the tile. - int32_t z = tile_element_height({ *map_x, *map_y }); + int32_t z = tile_element_height(mapCoords); - auto centreLoc = centre_2d_coordinates({ *map_x, *map_y, z }, w->viewport); + auto centreLoc = centre_2d_coordinates({ mapCoords.x, mapCoords.y, z }, w->viewport); if (!centreLoc) { log_error("Invalid location."); @@ -976,6 +977,8 @@ void window_viewport_get_map_coords_by_cursor( // Compute cursor offset relative to tile. *offset_x = (w->saved_view_x - (centreLoc->x + rebased_x)) * (1 << w->viewport->zoom); *offset_y = (w->saved_view_y - (centreLoc->y + rebased_y)) * (1 << w->viewport->zoom); + *map_x = centreLoc->x; + *map_y = centreLoc->y; } void window_viewport_centre_tile_around_cursor(rct_window* w, int16_t map_x, int16_t map_y, int16_t offset_x, int16_t offset_y) diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index fedee9e735..634201701f 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -6185,8 +6185,8 @@ CoordsXYZD ride_get_entrance_or_exit_position_from_screen_position(ScreenCoordsX CoordsXYZD entranceExitCoords{}; gRideEntranceExitPlaceDirection = 255; - get_map_coordinates_from_pos( - screenCoords.x, screenCoords.y, 0xFFFB, nullptr, nullptr, &interactionType, &tileElement, &viewport); + CoordsXY unusedCoords; + get_map_coordinates_from_pos(screenCoords, 0xFFFB, unusedCoords, &interactionType, &tileElement, &viewport); if (interactionType != 0) { if (tileElement->GetType() == TILE_ELEMENT_TYPE_TRACK) diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 78f3cf13fc..f01f47383c 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -252,17 +252,16 @@ void footpath_get_coordinates_from_pos( int32_t z = 0, interactionType; TileElement* myTileElement; rct_viewport* viewport; - LocationXY16 position16 = {}; + CoordsXY position = {}; get_map_coordinates_from_pos( - screenCoords.x, screenCoords.y, VIEWPORT_INTERACTION_MASK_FOOTPATH, &position16.x, &position16.y, &interactionType, - &myTileElement, &viewport); + screenCoords, VIEWPORT_INTERACTION_MASK_FOOTPATH, position, &interactionType, &myTileElement, &viewport); if (interactionType != VIEWPORT_INTERACTION_ITEM_FOOTPATH || !(viewport->flags & (VIEWPORT_FLAG_UNDERGROUND_INSIDE | VIEWPORT_FLAG_HIDE_BASE | VIEWPORT_FLAG_HIDE_VERTICAL))) { get_map_coordinates_from_pos( - screenCoords.x, screenCoords.y, VIEWPORT_INTERACTION_MASK_FOOTPATH & VIEWPORT_INTERACTION_MASK_TERRAIN, - &position16.x, &position16.y, &interactionType, &myTileElement, &viewport); + screenCoords, VIEWPORT_INTERACTION_MASK_FOOTPATH & VIEWPORT_INTERACTION_MASK_TERRAIN, position, &interactionType, + &myTileElement, &viewport); if (interactionType == VIEWPORT_INTERACTION_ITEM_NONE) { if (x != nullptr) @@ -271,7 +270,6 @@ void footpath_get_coordinates_from_pos( } } - CoordsXY position = { position16.x, position16.y }; auto minPosition = position; auto maxPosition = position + CoordsXY{ 31, 31 }; @@ -352,10 +350,9 @@ void footpath_bridge_get_info_from_pos( int32_t interactionType; rct_viewport* viewport; - LocationXY16 map_pos = {}; + CoordsXY map_pos = {}; get_map_coordinates_from_pos( - screenCoords.x, screenCoords.y, VIEWPORT_INTERACTION_MASK_RIDE, &map_pos.x, &map_pos.y, &interactionType, tileElement, - &viewport); + screenCoords, VIEWPORT_INTERACTION_MASK_RIDE, map_pos, &interactionType, tileElement, &viewport); *x = map_pos.x; *y = map_pos.y; @@ -376,9 +373,8 @@ void footpath_bridge_get_info_from_pos( } get_map_coordinates_from_pos( - screenCoords.x, screenCoords.y, - VIEWPORT_INTERACTION_MASK_RIDE & VIEWPORT_INTERACTION_MASK_FOOTPATH & VIEWPORT_INTERACTION_MASK_TERRAIN, &map_pos.x, - &map_pos.y, &interactionType, tileElement, &viewport); + 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)