Merge pull request #10221 from tupaschoal/viewport-return-more-coords

Receive ScreenCoordsXY and return CoordsXY in Viewport
This commit is contained in:
Duncan 2019-11-14 06:36:09 +00:00 committed by GitHub
commit 7babeb47d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 74 additions and 81 deletions

View File

@ -683,7 +683,7 @@ void sub_68A15E(int32_t screenX, int32_t screenY, int16_t* x, int16_t* y)
waterHeight = tileElement->AsSurface()->GetWaterHeight() << 4;
}
LocationXY16 initialVPPos = screen_coord_to_viewport_coord(viewport, screenX, screenY);
LocationXY16 initialVPPos = screen_coord_to_viewport_coord(viewport, { screenX, screenY });
CoordsXY mapPos = initialPos + CoordsXY{ 16, 16 };
for (int32_t i = 0; i < 5; i++)

View File

@ -295,8 +295,7 @@ static void window_land_rights_tool_update_land_rights(int16_t x, int16_t y)
map_invalidate_selection_rect();
gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE;
LocationXY16 mapTile = {};
screen_get_map_xy(x, y, &mapTile.x, &mapTile.y, nullptr);
CoordsXY mapTile = screen_get_map_xy({ x, y }, nullptr);
if (mapTile.x == LOCATION_NULL)
{

View File

@ -1158,13 +1158,12 @@ static void window_map_paint_hud_rectangle(rct_drawpixelinfo* dpi)
*/
static void window_map_set_land_rights_tool_update(int32_t x, int32_t y)
{
int16_t mapX, mapY;
rct_viewport* viewport;
map_invalidate_selection_rect();
gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE;
screen_get_map_xy(x, y, &mapX, &mapY, &viewport);
if (mapX == LOCATION_NULL)
CoordsXY mapCoords = screen_get_map_xy({ x, y }, &viewport);
if (mapCoords.x == LOCATION_NULL)
return;
gMapSelectFlags |= MAP_SELECT_FLAG_ENABLE;
@ -1176,12 +1175,12 @@ static void window_map_set_land_rights_tool_update(int32_t x, int32_t y)
int32_t size = (landRightsToolSize * 32) - 32;
int32_t radius = (landRightsToolSize * 16) - 16;
mapX = (mapX - radius) & 0xFFE0;
mapY = (mapY - radius) & 0xFFE0;
gMapSelectPositionA.x = mapX;
gMapSelectPositionA.y = mapY;
gMapSelectPositionB.x = mapX + size;
gMapSelectPositionB.y = mapY + size;
mapCoords.x = (mapCoords.x - radius) & 0xFFE0;
mapCoords.y = (mapCoords.y - radius) & 0xFFE0;
gMapSelectPositionA.x = mapCoords.x;
gMapSelectPositionA.y = mapCoords.y;
gMapSelectPositionB.x = mapCoords.x + size;
gMapSelectPositionB.y = mapCoords.y + size;
map_invalidate_selection_rect();
}

View File

@ -1222,8 +1222,8 @@ static void window_tile_inspector_tool_update(rct_window* w, rct_widgetindex wid
gMapSelectFlags |= MAP_SELECT_FLAG_ENABLE;
int16_t mapX = screenCoords.x;
int16_t mapY = screenCoords.y;
int16_t mapX = 0;
int16_t mapY = 0;
TileElement* clickedElement = nullptr;
if (input_test_place_object_modifier(PLACE_OBJECT_MODIFIER_COPY_Z))
{
@ -1234,7 +1234,7 @@ static void window_tile_inspector_tool_update(rct_window* w, rct_widgetindex wid
// 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(mapX, mapY, nullptr);
CoordsXY mapCoords = screen_pos_to_map_pos(screenCoords, nullptr);
mapX = mapCoords.x;
mapY = mapCoords.y;
}
@ -1273,8 +1273,8 @@ static void window_tile_inspector_update_selected_tile(rct_window* w, int32_t x,
windowTileInspectorToolMouseY = y;
windowTileInspectorToolCtrlDown = ctrlIsHeldDown;
int16_t mapX = x;
int16_t mapY = y;
int16_t mapX = 0;
int16_t mapY = 0;
TileElement* clickedElement = nullptr;
if (ctrlIsHeldDown)
{
@ -1284,7 +1284,7 @@ static void window_tile_inspector_update_selected_tile(rct_window* w, int32_t x,
// 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(mapX, mapY, nullptr);
CoordsXY mapCoords = screen_pos_to_map_pos({ x, y }, nullptr);
if (mapCoords.x == LOCATION_NULL)
{

View File

@ -1345,7 +1345,9 @@ static void sub_6E1F34(
// If CTRL not pressed
if (!gSceneryCtrlPressed)
{
screen_get_map_xy_quadrant(x, y, grid_x, grid_y, &cl);
CoordsXY gridCoords = screen_get_map_xy_quadrant({ x, y }, &cl);
*grid_x = gridCoords.x;
*grid_y = gridCoords.y;
if (*grid_x == LOCATION_NULL)
return;
@ -1522,7 +1524,9 @@ static void sub_6E1F34(
// If CTRL not pressed
if (!gSceneryCtrlPressed)
{
screen_get_map_xy_side(x, y, grid_x, grid_y, &cl);
CoordsXY gridCoords = screen_get_map_xy_side({ x, y }, &cl);
*grid_x = gridCoords.x;
*grid_y = gridCoords.y;
if (*grid_x == LOCATION_NULL)
return;
@ -1968,8 +1972,7 @@ static uint8_t top_toolbar_tool_update_land_paint(int16_t x, int16_t y)
map_invalidate_selection_rect();
gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE;
LocationXY16 mapTile = {};
screen_get_map_xy(x, y, &mapTile.x, &mapTile.y, nullptr);
CoordsXY mapTile = screen_get_map_xy({ x, y }, nullptr);
if (mapTile.x == LOCATION_NULL)
{
@ -2080,7 +2083,7 @@ static void top_toolbar_tool_update_land(int16_t x, int16_t y)
}
int16_t tool_size = gLandToolSize;
LocationXY16 mapTile;
CoordsXY mapTile;
uint8_t side;
gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE;
@ -2088,9 +2091,8 @@ static void top_toolbar_tool_update_land(int16_t x, int16_t y)
{
int32_t selectionType;
// Get selection type and map coordinates from mouse x,y position
CoordsXY mapCoords = screen_pos_to_map_pos(x, y, &selectionType);
mapTile = { static_cast<int16_t>(mapCoords.x), static_cast<int16_t>(mapCoords.y) };
screen_get_map_xy_side(x, y, &mapTile.x, &mapTile.y, &side);
screen_pos_to_map_pos({ x, y }, &selectionType);
mapTile = screen_get_map_xy_side({ x, y }, &side);
if (mapTile.x == LOCATION_NULL)
{
@ -2167,7 +2169,7 @@ static void top_toolbar_tool_update_land(int16_t x, int16_t y)
}
// Get map coordinates and the side of the tile that is being hovered over
screen_get_map_xy_side(x, y, &mapTile.x, &mapTile.y, &side);
mapTile = screen_get_map_xy_side({ x, y }, &side);
if (mapTile.x == LOCATION_NULL)
{

View File

@ -318,7 +318,7 @@ static void window_view_clipping_tool_update(rct_window* w, rct_widgetindex widg
}
int32_t direction;
CoordsXY mapCoords = screen_pos_to_map_pos(screenCoords.x, screenCoords.y, &direction);
CoordsXY mapCoords = screen_pos_to_map_pos(screenCoords, &direction);
if (mapCoords.x != LOCATION_NULL)
{
gMapSelectFlags |= MAP_SELECT_FLAG_ENABLE;
@ -333,7 +333,7 @@ static void window_view_clipping_tool_update(rct_window* w, rct_widgetindex widg
static void window_view_clipping_tool_down(rct_window* w, rct_widgetindex widgetIndex, ScreenCoordsXY screenCoords)
{
int32_t direction;
CoordsXY mapCoords = screen_pos_to_map_pos(screenCoords.x, screenCoords.y, &direction);
CoordsXY mapCoords = screen_pos_to_map_pos(screenCoords, &direction);
if (mapCoords.x != LOCATION_NULL)
{
_dragging = true;
@ -349,7 +349,7 @@ static void window_view_clipping_tool_drag(rct_window* w, rct_widgetindex widget
}
int32_t direction;
CoordsXY mapCoords = screen_pos_to_map_pos(screenCoords.x, screenCoords.y, &direction);
CoordsXY mapCoords = screen_pos_to_map_pos(screenCoords, &direction);
if (mapCoords.x != LOCATION_NULL)
{
map_invalidate_selection_rect();

View File

@ -995,16 +995,12 @@ static void viewport_paint_weather_gloom(rct_drawpixelinfo* dpi)
*
* rct2: 0x0068958D
*/
CoordsXY screen_pos_to_map_pos(int16_t x, int16_t y, int32_t* direction)
CoordsXY screen_pos_to_map_pos(ScreenCoordsXY screenCoords, int32_t* direction)
{
int16_t mapX = 0;
int16_t mapY = 0;
screen_get_map_xy(x, y, &mapX, &mapY, nullptr);
if (mapX == LOCATION_NULL)
CoordsXY mapCoords = screen_get_map_xy(screenCoords, nullptr);
if (mapCoords.x == LOCATION_NULL)
return {};
CoordsXY mapCoords = { mapX, mapY };
int32_t my_direction;
int32_t dist_from_centre_x = abs(mapCoords.x % 32);
int32_t dist_from_centre_y = abs(mapCoords.y % 32);
@ -1047,11 +1043,11 @@ CoordsXY screen_pos_to_map_pos(int16_t x, int16_t y, int32_t* direction)
return mapCoords;
}
LocationXY16 screen_coord_to_viewport_coord(rct_viewport* viewport, uint16_t x, uint16_t y)
LocationXY16 screen_coord_to_viewport_coord(rct_viewport* viewport, ScreenCoordsXY screenCoords)
{
LocationXY16 ret;
ret.x = ((x - viewport->x) << viewport->zoom) + viewport->view_x;
ret.y = ((y - viewport->y) << viewport->zoom) + viewport->view_y;
ret.x = ((screenCoords.x - viewport->x) << viewport->zoom) + viewport->view_x;
ret.y = ((screenCoords.y - viewport->y) << viewport->zoom) + viewport->view_y;
return ret;
}
@ -1771,20 +1767,20 @@ static rct_viewport* viewport_find_from_point(int32_t screenX, int32_t screenY)
* tile_element: edx ?
* viewport: edi
*/
void screen_get_map_xy(int32_t screenX, int32_t screenY, int16_t* x, int16_t* y, rct_viewport** viewport)
CoordsXY screen_get_map_xy(ScreenCoordsXY screenCoords, rct_viewport** viewport)
{
int16_t my_x, my_y;
int32_t interactionType;
rct_viewport* myViewport = nullptr;
get_map_coordinates_from_pos(
screenX, screenY, VIEWPORT_INTERACTION_MASK_TERRAIN, &my_x, &my_y, &interactionType, nullptr, &myViewport);
screenCoords.x, screenCoords.y, VIEWPORT_INTERACTION_MASK_TERRAIN, &my_x, &my_y, &interactionType, nullptr,
&myViewport);
if (interactionType == VIEWPORT_INTERACTION_ITEM_NONE)
{
*x = LOCATION_NULL;
return;
return { LOCATION_NULL, 0 };
}
LocationXY16 start_vp_pos = screen_coord_to_viewport_coord(myViewport, screenX, screenY);
LocationXY16 start_vp_pos = screen_coord_to_viewport_coord(myViewport, screenCoords);
CoordsXY map_pos = { my_x + 16, my_y + 16 };
for (int32_t i = 0; i < 5; i++)
@ -1795,11 +1791,10 @@ void screen_get_map_xy(int32_t screenX, int32_t screenY, int16_t* x, int16_t* y,
map_pos.y = std::clamp<int16_t>(map_pos.y, my_y, my_y + 31);
}
*x = map_pos.x;
*y = map_pos.y;
if (viewport != nullptr)
*viewport = myViewport;
return map_pos;
}
/**
@ -1833,15 +1828,14 @@ void screen_get_map_xy_with_z(int16_t screenX, int16_t screenY, int16_t z, int16
*
* rct2: 0x00689604
*/
void screen_get_map_xy_quadrant(int16_t screenX, int16_t screenY, int16_t* mapX, int16_t* mapY, uint8_t* quadrant)
CoordsXY screen_get_map_xy_quadrant(ScreenCoordsXY screenCoords, uint8_t* quadrant)
{
screen_get_map_xy(screenX, screenY, mapX, mapY, nullptr);
if (*mapX == LOCATION_NULL)
return;
CoordsXY mapCoords = screen_get_map_xy(screenCoords, nullptr);
if (mapCoords.x == LOCATION_NULL)
return mapCoords;
*quadrant = map_get_tile_quadrant(*mapX, *mapY);
*mapX = floor2(*mapX, 32);
*mapY = floor2(*mapY, 32);
*quadrant = map_get_tile_quadrant(mapCoords.x, mapCoords.y);
return { floor2(mapCoords.x, 32), floor2(mapCoords.y, 32) };
}
/**
@ -1864,15 +1858,14 @@ void screen_get_map_xy_quadrant_with_z(
*
* rct2: 0x00689692
*/
void screen_get_map_xy_side(int16_t screenX, int16_t screenY, int16_t* mapX, int16_t* mapY, uint8_t* side)
CoordsXY screen_get_map_xy_side(ScreenCoordsXY screenCoords, uint8_t* side)
{
screen_get_map_xy(screenX, screenY, mapX, mapY, nullptr);
if (*mapX == LOCATION_NULL)
return;
CoordsXY mapCoords = screen_get_map_xy(screenCoords, nullptr);
if (mapCoords.x == LOCATION_NULL)
return mapCoords;
*side = map_get_tile_side(*mapX, *mapY);
*mapX = floor2(*mapX, 32);
*mapY = floor2(*mapY, 32);
*side = map_get_tile_side(mapCoords.x, mapCoords.y);
return { floor2(mapCoords.x, 32), floor2(mapCoords.y, 32) };
}
/**

View File

@ -139,9 +139,9 @@ void viewport_paint(
void viewport_adjust_for_map_height(int16_t* x, int16_t* y, int16_t* z);
LocationXY16 screen_coord_to_viewport_coord(rct_viewport* viewport, uint16_t x, uint16_t y);
LocationXY16 screen_coord_to_viewport_coord(rct_viewport* viewport, ScreenCoordsXY screenCoords);
CoordsXY viewport_coord_to_map_coord(int32_t x, int32_t y, int32_t z);
CoordsXY screen_pos_to_map_pos(int16_t x, int16_t y, int32_t* direction);
CoordsXY screen_pos_to_map_pos(ScreenCoordsXY screenCoords, int32_t* direction);
void show_gridlines();
void hide_gridlines();
@ -173,12 +173,12 @@ void sub_68B2B7(paint_session* session, int32_t x, int32_t y);
void viewport_invalidate(rct_viewport* viewport, int32_t left, int32_t top, int32_t right, int32_t bottom);
void screen_get_map_xy(int32_t screenX, int32_t screenY, int16_t* x, int16_t* y, rct_viewport** viewport);
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);
void screen_get_map_xy_quadrant(int16_t screenX, int16_t screenY, int16_t* mapX, int16_t* mapY, uint8_t* quadrant);
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);
void screen_get_map_xy_side(int16_t screenX, int16_t screenY, int16_t* mapX, int16_t* mapY, uint8_t* side);
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);
uint8_t get_current_rotation();

View File

@ -916,26 +916,27 @@ void window_rotate_camera(rct_window* w, int32_t direction)
// has something to do with checking if middle of the viewport is obstructed
rct_viewport* other;
screen_get_map_xy(x, y, &x, &y, &other);
CoordsXY coords = screen_get_map_xy({ x, y }, &other);
// other != viewport probably triggers on viewports in ride or guest window?
// x is LOCATION_NULL if middle of viewport is obstructed by another window?
if (x == LOCATION_NULL || other != viewport)
if (coords.x == LOCATION_NULL || other != viewport)
{
x = (viewport->view_width >> 1) + viewport->view_x;
y = (viewport->view_height >> 1) + viewport->view_y;
int16_t view_x = (viewport->view_width >> 1) + viewport->view_x;
int16_t view_y = (viewport->view_height >> 1) + viewport->view_y;
viewport_adjust_for_map_height(&x, &y, &z);
viewport_adjust_for_map_height(&view_x, &view_y, &z);
coords = { view_x, view_y };
}
else
{
z = tile_element_height({ x, y });
z = tile_element_height(coords);
}
gCurrentRotation = (get_current_rotation() + direction) & 3;
int32_t new_x, new_y;
centre_2d_coordinates(x, y, z, &new_x, &new_y, viewport);
centre_2d_coordinates(coords.x, coords.y, z, &new_x, &new_y, viewport);
w->saved_view_x = new_x;
w->saved_view_y = new_y;

View File

@ -286,7 +286,7 @@ void footpath_get_coordinates_from_pos(
}
}
LocationXY16 start_vp_pos = screen_coord_to_viewport_coord(viewport, screenCoords.x, screenCoords.y);
LocationXY16 start_vp_pos = screen_coord_to_viewport_coord(viewport, screenCoords);
for (int32_t i = 0; i < 5; i++)
{

View File

@ -77,7 +77,7 @@ void rct_money_effect::CreateAt(money32 value, int32_t x, int32_t y, int32_t z,
*/
void rct_money_effect::Create(money32 value)
{
LocationXYZ16 mapPosition = { gCommandPosition.x, gCommandPosition.y, gCommandPosition.z };
CoordsXYZ mapPosition = { gCommandPosition.x, gCommandPosition.y, gCommandPosition.z };
if (mapPosition.x == LOCATION_NULL)
{
@ -94,13 +94,12 @@ void rct_money_effect::Create(money32 value)
return;
rct_viewport* mainViewport = window_get_viewport(mainWindow);
screen_get_map_xy(
mainViewport->x + (mainViewport->width / 2), mainViewport->y + (mainViewport->height / 2), &mapPosition.x,
&mapPosition.y, nullptr);
if (mapPosition.x == LOCATION_NULL)
CoordsXY mapPositionXY = screen_get_map_xy(
{ mainViewport->x + (mainViewport->width / 2), mainViewport->y + (mainViewport->height / 2) }, nullptr);
if (mapPositionXY.x == LOCATION_NULL)
return;
mapPosition.z = tile_element_height({ mapPosition.x, mapPosition.y });
mapPosition = { mapPositionXY, tile_element_height(mapPositionXY) };
}
mapPosition.z += 10;
CreateAt(-value, mapPosition.x, mapPosition.y, mapPosition.z, false);