1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-29 01:35:06 +01:00

Refactor viewport_coord_to_map_coord to return a CoordXY

This commit is contained in:
duncanspumpkin
2019-10-30 20:24:13 +00:00
parent 9bf2cffbb7
commit 5ca553dd08
5 changed files with 27 additions and 30 deletions

View File

@@ -252,17 +252,17 @@ void footpath_get_coordinates_from_pos(
int32_t z = 0, interactionType;
TileElement* myTileElement;
rct_viewport* viewport;
LocationXY16 position = {};
LocationXY16 position16 = {};
get_map_coordinates_from_pos(
screenX, screenY, VIEWPORT_INTERACTION_MASK_FOOTPATH, &position.x, &position.y, &interactionType, &myTileElement,
screenX, screenY, VIEWPORT_INTERACTION_MASK_FOOTPATH, &position16.x, &position16.y, &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(
screenX, screenY, VIEWPORT_INTERACTION_MASK_FOOTPATH & VIEWPORT_INTERACTION_MASK_TERRAIN, &position.x, &position.y,
&interactionType, &myTileElement, &viewport);
screenX, screenY, VIEWPORT_INTERACTION_MASK_FOOTPATH & VIEWPORT_INTERACTION_MASK_TERRAIN, &position16.x,
&position16.y, &interactionType, &myTileElement, &viewport);
if (interactionType == VIEWPORT_INTERACTION_ITEM_NONE)
{
if (x != nullptr)
@@ -271,11 +271,11 @@ void footpath_get_coordinates_from_pos(
}
}
LocationXY16 minPosition = position;
LocationXY16 maxPosition = { int16_t(position.x + 31), int16_t(position.y + 31) };
CoordsXY position = { position16.x, position16.y };
auto minPosition = position;
auto maxPosition = position + CoordsXY{ 31, 31 };
position.x += 16;
position.y += 16;
position += CoordsXY{ 16, 16 };
if (interactionType == VIEWPORT_INTERACTION_ITEM_FOOTPATH)
{
@@ -292,7 +292,7 @@ void footpath_get_coordinates_from_pos(
{
if (interactionType != VIEWPORT_INTERACTION_ITEM_FOOTPATH)
{
z = tile_element_height({ position.x, position.y });
z = tile_element_height(position);
}
position = viewport_coord_to_map_coord(start_vp_pos.x, start_vp_pos.y, z);
position.x = std::clamp(position.x, minPosition.x, maxPosition.x);