mirror of
https://github.com/OpenRCT2/OpenRCT2.git
synced 2025-01-23 19:02:04 -05:00
Merge pull request #10238 from duncanspumpkin/viewport_get_xy_z
Refactor screen_get_map_xy_with_z to use CoordsXY structs
This commit is contained in:
commit
463ef9d218
5 changed files with 46 additions and 50 deletions
|
@ -2111,15 +2111,14 @@ static void window_ride_construction_update(rct_window* w)
|
|||
static std::optional<CoordsXY> ride_get_place_position_from_screen_position(ScreenCoordsXY screenCoords)
|
||||
{
|
||||
CoordsXY mapCoords;
|
||||
int16_t mapZ;
|
||||
int32_t interactionType;
|
||||
rct_viewport* viewport = nullptr;
|
||||
|
||||
if (!_trackPlaceCtrlState)
|
||||
{
|
||||
if (gInputPlaceObjectModifier & PLACE_OBJECT_MODIFIER_COPY_Z)
|
||||
{
|
||||
TileElement* tileElement;
|
||||
rct_viewport* viewport = nullptr;
|
||||
int32_t interactionType;
|
||||
get_map_coordinates_from_pos(screenCoords, 0xFCCA, mapCoords, &interactionType, &tileElement, &viewport);
|
||||
if (interactionType != 0)
|
||||
{
|
||||
|
@ -2184,7 +2183,7 @@ static std::optional<CoordsXY> ride_get_place_position_from_screen_position(Scre
|
|||
auto surfaceElement = map_get_surface_element_at(mapCoords.x >> 5, mapCoords.y >> 5);
|
||||
if (surfaceElement == nullptr)
|
||||
return std::nullopt;
|
||||
mapZ = floor2(surfaceElement->base_height * 8, 16);
|
||||
auto mapZ = floor2(surfaceElement->base_height * 8, 16);
|
||||
mapZ += _trackPlaceShiftZ;
|
||||
mapZ = std::max<int16_t>(mapZ, 16);
|
||||
_trackPlaceZ = mapZ;
|
||||
|
@ -2192,10 +2191,9 @@ static std::optional<CoordsXY> ride_get_place_position_from_screen_position(Scre
|
|||
}
|
||||
else
|
||||
{
|
||||
int16_t mapX, mapY;
|
||||
mapZ = _trackPlaceCtrlZ;
|
||||
screen_get_map_xy_with_z(screenCoords.x, screenCoords.y, mapZ, &mapX, &mapY);
|
||||
mapCoords = { mapX, mapY };
|
||||
auto mapZ = _trackPlaceCtrlZ;
|
||||
mapCoords = screen_get_map_xy_with_z(screenCoords, mapZ);
|
||||
|
||||
if (_trackPlaceShiftState != 0)
|
||||
{
|
||||
mapZ += _trackPlaceShiftZ;
|
||||
|
|
|
@ -1456,8 +1456,9 @@ static void sub_6E1F34(
|
|||
else
|
||||
{
|
||||
int16_t z = gSceneryCtrlPressZ;
|
||||
screen_get_map_xy_with_z(x, y, z, grid_x, grid_y);
|
||||
|
||||
auto coords = screen_get_map_xy_with_z({ x, y }, z);
|
||||
*grid_x = coords.x;
|
||||
*grid_y = coords.y;
|
||||
// If SHIFT pressed
|
||||
if (gSceneryShiftPressed)
|
||||
{
|
||||
|
@ -1616,7 +1617,9 @@ static void sub_6E1F34(
|
|||
else
|
||||
{
|
||||
int16_t z = gSceneryCtrlPressZ;
|
||||
screen_get_map_xy_with_z(x, y, z, grid_x, grid_y);
|
||||
auto coords = screen_get_map_xy_with_z({ x, y }, z);
|
||||
*grid_x = coords.x;
|
||||
*grid_y = coords.y;
|
||||
|
||||
// If SHIFT pressed
|
||||
if (gSceneryShiftPressed)
|
||||
|
|
|
@ -1742,9 +1742,9 @@ void viewport_invalidate(rct_viewport* viewport, int32_t left, int32_t top, int3
|
|||
}
|
||||
}
|
||||
|
||||
static rct_viewport* viewport_find_from_point(int32_t screenX, int32_t screenY)
|
||||
static rct_viewport* viewport_find_from_point(ScreenCoordsXY screenCoords)
|
||||
{
|
||||
rct_window* w = window_find_from_point(ScreenCoordsXY(screenX, screenY));
|
||||
rct_window* w = window_find_from_point(screenCoords);
|
||||
if (w == nullptr)
|
||||
return nullptr;
|
||||
|
||||
|
@ -1752,9 +1752,9 @@ static rct_viewport* viewport_find_from_point(int32_t screenX, int32_t screenY)
|
|||
if (viewport == nullptr)
|
||||
return nullptr;
|
||||
|
||||
if (screenX < viewport->x || screenY < viewport->y)
|
||||
if (screenCoords.x < viewport->x || screenCoords.y < viewport->y)
|
||||
return nullptr;
|
||||
if (screenX >= viewport->x + viewport->width || screenY >= viewport->y + viewport->height)
|
||||
if (screenCoords.x >= viewport->x + viewport->width || screenCoords.y >= viewport->y + viewport->height)
|
||||
return nullptr;
|
||||
|
||||
return viewport;
|
||||
|
@ -1806,27 +1806,23 @@ CoordsXY screen_get_map_xy(ScreenCoordsXY screenCoords, rct_viewport** viewport)
|
|||
*
|
||||
* rct2: 0x006894D4
|
||||
*/
|
||||
void screen_get_map_xy_with_z(int16_t screenX, int16_t screenY, int16_t z, int16_t* mapX, int16_t* mapY)
|
||||
CoordsXY screen_get_map_xy_with_z(ScreenCoordsXY screenCoords, int16_t z)
|
||||
{
|
||||
rct_viewport* viewport = viewport_find_from_point(screenX, screenY);
|
||||
CoordsXY ret{ LOCATION_NULL, 0 };
|
||||
rct_viewport* viewport = viewport_find_from_point(screenCoords);
|
||||
if (viewport == nullptr)
|
||||
{
|
||||
*mapX = LOCATION_NULL;
|
||||
return;
|
||||
return ret;
|
||||
}
|
||||
|
||||
screenX = viewport->view_x + ((screenX - viewport->x) << viewport->zoom);
|
||||
screenY = viewport->view_y + ((screenY - viewport->y) << viewport->zoom);
|
||||
|
||||
auto mapPosition = viewport_coord_to_map_coord(screenX, screenY + z, 0);
|
||||
if (mapPosition.x < 0 || mapPosition.x >= (256 * 32) || mapPosition.y < 0 || mapPosition.y > (256 * 32))
|
||||
auto vpCoords = screen_coord_to_viewport_coord(viewport, screenCoords);
|
||||
auto mapPosition = viewport_coord_to_map_coord(vpCoords.x, vpCoords.y, z);
|
||||
if (!map_is_location_valid(mapPosition))
|
||||
{
|
||||
*mapX = LOCATION_NULL;
|
||||
return;
|
||||
return ret;
|
||||
}
|
||||
|
||||
*mapX = mapPosition.x;
|
||||
*mapY = mapPosition.y;
|
||||
return mapPosition;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1850,13 +1846,13 @@ CoordsXY screen_get_map_xy_quadrant(ScreenCoordsXY screenCoords, uint8_t* quadra
|
|||
void screen_get_map_xy_quadrant_with_z(
|
||||
int16_t screenX, int16_t screenY, int16_t z, int16_t* mapX, int16_t* mapY, uint8_t* quadrant)
|
||||
{
|
||||
screen_get_map_xy_with_z(screenX, screenY, z, mapX, mapY);
|
||||
if (*mapX == LOCATION_NULL)
|
||||
auto coords = screen_get_map_xy_with_z({ screenX, screenY }, z);
|
||||
if (coords.x == LOCATION_NULL)
|
||||
return;
|
||||
|
||||
*quadrant = map_get_tile_quadrant(*mapX, *mapY);
|
||||
*mapX = floor2(*mapX, 32);
|
||||
*mapY = floor2(*mapY, 32);
|
||||
*quadrant = map_get_tile_quadrant(coords.x, coords.y);
|
||||
*mapX = floor2(coords.x, 32);
|
||||
*mapY = floor2(coords.y, 32);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1879,13 +1875,13 @@ CoordsXY screen_get_map_xy_side(ScreenCoordsXY screenCoords, uint8_t* side)
|
|||
*/
|
||||
void screen_get_map_xy_side_with_z(int16_t screenX, int16_t screenY, int16_t z, int16_t* mapX, int16_t* mapY, uint8_t* side)
|
||||
{
|
||||
screen_get_map_xy_with_z(screenX, screenY, z, mapX, mapY);
|
||||
if (*mapX == LOCATION_NULL)
|
||||
auto coords = screen_get_map_xy_with_z({ screenX, screenY }, z);
|
||||
if (coords.x == LOCATION_NULL)
|
||||
return;
|
||||
|
||||
*side = map_get_tile_side(*mapX, *mapY);
|
||||
*mapX = floor2(*mapX, 32);
|
||||
*mapY = floor2(*mapY, 32);
|
||||
*side = map_get_tile_side(coords.x, coords.y);
|
||||
*mapX = floor2(coords.x, 32);
|
||||
*mapY = floor2(coords.y, 32);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -174,7 +174,7 @@ void sub_68B2B7(paint_session* session, CoordsXY mapCoords);
|
|||
void viewport_invalidate(rct_viewport* viewport, int32_t left, int32_t top, int32_t right, int32_t bottom);
|
||||
|
||||
CoordsXY screen_get_map_xy(ScreenCoordsXY screenCoords, rct_viewport** viewport);
|
||||
void screen_get_map_xy_with_z(int16_t screenX, int16_t screenY, int16_t z, int16_t* mapX, int16_t* mapY);
|
||||
CoordsXY screen_get_map_xy_with_z(ScreenCoordsXY screenCoords, int16_t z);
|
||||
CoordsXY screen_get_map_xy_quadrant(ScreenCoordsXY screenCoords, uint8_t* quadrant);
|
||||
void screen_get_map_xy_quadrant_with_z(
|
||||
int16_t screenX, int16_t screenY, int16_t z, int16_t* mapX, int16_t* mapY, uint8_t* quadrant);
|
||||
|
|
|
@ -6176,7 +6176,6 @@ static int32_t loc_6CD18E(
|
|||
*/
|
||||
CoordsXYZD ride_get_entrance_or_exit_position_from_screen_position(ScreenCoordsXY screenCoords)
|
||||
{
|
||||
int16_t mapX, mapY;
|
||||
int16_t entranceMinX, entranceMinY, entranceMaxX, entranceMaxY, word_F4418C, word_F4418E;
|
||||
int32_t interactionType, stationDirection;
|
||||
uint8_t stationHeight;
|
||||
|
@ -6187,7 +6186,7 @@ CoordsXYZD ride_get_entrance_or_exit_position_from_screen_position(ScreenCoordsX
|
|||
|
||||
gRideEntranceExitPlaceDirection = 255;
|
||||
get_map_coordinates_from_pos(
|
||||
screenCoords.x, screenCoords.y, 0xFFFB, &mapX, &mapY, &interactionType, &tileElement, &viewport);
|
||||
screenCoords.x, screenCoords.y, 0xFFFB, nullptr, nullptr, &interactionType, &tileElement, &viewport);
|
||||
if (interactionType != 0)
|
||||
{
|
||||
if (tileElement->GetType() == TILE_ELEMENT_TYPE_TRACK)
|
||||
|
@ -6218,17 +6217,17 @@ CoordsXYZD ride_get_entrance_or_exit_position_from_screen_position(ScreenCoordsX
|
|||
|
||||
stationHeight = ride->stations[gRideEntranceExitPlaceStationIndex].Height;
|
||||
|
||||
screen_get_map_xy_with_z(screenCoords.x, screenCoords.y, stationHeight * 8, &mapX, &mapY);
|
||||
if (mapX == LOCATION_NULL)
|
||||
auto coords = screen_get_map_xy_with_z(screenCoords, stationHeight * 8);
|
||||
if (coords.x == LOCATION_NULL)
|
||||
{
|
||||
entranceExitCoords.x = LOCATION_NULL;
|
||||
return entranceExitCoords;
|
||||
}
|
||||
|
||||
word_F4418C = mapX;
|
||||
word_F4418E = mapY;
|
||||
word_F4418C = coords.x;
|
||||
word_F4418E = coords.y;
|
||||
|
||||
entranceExitCoords = { floor2(mapX, 32), floor2(mapY, 32), stationHeight, INVALID_DIRECTION };
|
||||
entranceExitCoords = { floor2(coords.x, 32), floor2(coords.y, 32), stationHeight, INVALID_DIRECTION };
|
||||
|
||||
if (ride->type == RIDE_TYPE_NULL)
|
||||
{
|
||||
|
@ -6245,8 +6244,8 @@ CoordsXYZD ride_get_entrance_or_exit_position_from_screen_position(ScreenCoordsX
|
|||
|
||||
if (ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_3))
|
||||
{
|
||||
mapX = (word_F4418C & 0x1F) - 16;
|
||||
mapY = (word_F4418E & 0x1F) - 16;
|
||||
auto mapX = (word_F4418C & 0x1F) - 16;
|
||||
auto mapY = (word_F4418E & 0x1F) - 16;
|
||||
if (std::abs(mapX) < std::abs(mapY))
|
||||
{
|
||||
entranceExitCoords.direction = mapY < 0 ? 3 : 1;
|
||||
|
@ -6300,8 +6299,8 @@ CoordsXYZD ride_get_entrance_or_exit_position_from_screen_position(ScreenCoordsX
|
|||
}
|
||||
else
|
||||
{
|
||||
mapX = stationStart.x * 32;
|
||||
mapY = stationStart.y * 32;
|
||||
auto mapX = stationStart.x * 32;
|
||||
auto mapY = stationStart.y * 32;
|
||||
entranceMinX = mapX;
|
||||
entranceMinY = mapY;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue