Skip to content

Commit

Permalink
Merge pull request #10574 from tupaschoal/footpath-direction-delta
Browse files Browse the repository at this point in the history
Prefer CoordsDirectionDelta on footpath_update_path_wide_flags()
  • Loading branch information
Gymnasiast committed Jan 19, 2020
2 parents 7f4d35f + ad89319 commit 1892a3d
Showing 1 changed file with 29 additions and 43 deletions.
72 changes: 29 additions & 43 deletions src/openrct2/world/Footpath.cpp
Expand Up @@ -1714,32 +1714,18 @@ void footpath_update_path_wide_flags(const CoordsXY& footpathPos)

// pathList is a list of elements, set by sub_6A8ACF adjacent to x,y
// Spanned from 0x00F3EFA8 to 0x00F3EFC7 (8 elements) in the original
TileElement* pathList[8];

// TODO: Use DirectionDelta
auto pathPos = footpathPos - CoordsXY{ COORDS_XY_STEP, COORDS_XY_STEP };
pathList[0] = footpath_can_be_wide(pathPos, height);
pathPos.y += COORDS_XY_STEP;
pathList[1] = footpath_can_be_wide(pathPos, height);
pathPos.y += COORDS_XY_STEP;
pathList[2] = footpath_can_be_wide(pathPos, height);
pathPos.x += COORDS_XY_STEP;
pathList[3] = footpath_can_be_wide(pathPos, height);
pathPos.x += COORDS_XY_STEP;
pathList[4] = footpath_can_be_wide(pathPos, height);
pathPos.y -= COORDS_XY_STEP;
pathList[5] = footpath_can_be_wide(pathPos, height);
pathPos.y -= COORDS_XY_STEP;
pathList[6] = footpath_can_be_wide(pathPos, height);
pathPos.x -= COORDS_XY_STEP;
pathList[7] = footpath_can_be_wide(pathPos, height);
pathPos.y += COORDS_XY_STEP;
std::array<TileElement*, 8> pathList;

for (int32_t direction = 0; direction < 8; ++direction)
{
pathList[direction] = footpath_can_be_wide(footpathPos + CoordsDirectionDelta[direction], height);
}

uint8_t pathConnections = 0;
if (tileElement->AsPath()->GetEdges() & EDGE_NW)
{
pathConnections |= FOOTPATH_CONNECTION_NW;
if (pathList[7] != nullptr && pathList[7]->AsPath()->IsWide())
if (pathList[3] != nullptr && pathList[3]->AsPath()->IsWide())
{
pathConnections &= ~FOOTPATH_CONNECTION_NW;
}
Expand All @@ -1748,7 +1734,7 @@ void footpath_update_path_wide_flags(const CoordsXY& footpathPos)
if (tileElement->AsPath()->GetEdges() & EDGE_NE)
{
pathConnections |= FOOTPATH_CONNECTION_NE;
if (pathList[1] != nullptr && pathList[1]->AsPath()->IsWide())
if (pathList[0] != nullptr && pathList[0]->AsPath()->IsWide())
{
pathConnections &= ~FOOTPATH_CONNECTION_NE;
}
Expand All @@ -1758,12 +1744,12 @@ void footpath_update_path_wide_flags(const CoordsXY& footpathPos)
{
pathConnections |= FOOTPATH_CONNECTION_SE;
/* In the following:
* footpath_element_is_wide(pathList[3])
* footpath_element_is_wide(pathList[1])
* is always false due to the tile update order
* in combination with reset tiles.
* Commented out since it will never occur. */
// if (pathList[3] != nullptr) {
// if (footpath_element_is_wide(pathList[3])) {
// if (pathList[1] != nullptr) {
// if (footpath_element_is_wide(pathList[1])) {
// pathConnections &= ~FOOTPATH_CONNECTION_SE;
// }
//}
Expand All @@ -1773,65 +1759,65 @@ void footpath_update_path_wide_flags(const CoordsXY& footpathPos)
{
pathConnections |= FOOTPATH_CONNECTION_SW;
/* In the following:
* footpath_element_is_wide(pathList[5])
* footpath_element_is_wide(pathList[2])
* is always false due to the tile update order
* in combination with reset tiles.
* Commented out since it will never occur. */
// if (pathList[5] != nullptr) {
// if (footpath_element_is_wide(pathList[5])) {
// if (pathList[2] != nullptr) {
// if (footpath_element_is_wide(pathList[2])) {
// pathConnections &= ~FOOTPATH_CONNECTION_SW;
// }
//}
}

if ((pathConnections & FOOTPATH_CONNECTION_NW) && pathList[7] != nullptr && !pathList[7]->AsPath()->IsWide())
if ((pathConnections & FOOTPATH_CONNECTION_NW) && pathList[3] != nullptr && !pathList[3]->AsPath()->IsWide())
{
constexpr uint8_t edgeMask1 = EDGE_SE | EDGE_SW;
if ((pathConnections & FOOTPATH_CONNECTION_NE) && pathList[0] != nullptr && !pathList[0]->AsPath()->IsWide()
&& (pathList[0]->AsPath()->GetEdges() & edgeMask1) == edgeMask1 && pathList[1] != nullptr
&& !pathList[1]->AsPath()->IsWide())
if ((pathConnections & FOOTPATH_CONNECTION_NE) && pathList[7] != nullptr && !pathList[7]->AsPath()->IsWide()
&& (pathList[7]->AsPath()->GetEdges() & edgeMask1) == edgeMask1 && pathList[0] != nullptr
&& !pathList[0]->AsPath()->IsWide())
{
pathConnections |= FOOTPATH_CONNECTION_S;
}

/* In the following:
* footpath_element_is_wide(pathList[5])
* footpath_element_is_wide(pathList[2])
* is always false due to the tile update order
* in combination with reset tiles.
* Short circuit the logic appropriately. */
constexpr uint8_t edgeMask2 = EDGE_NE | EDGE_SE;
if ((pathConnections & FOOTPATH_CONNECTION_SW) && pathList[6] != nullptr && !(pathList[6])->AsPath()->IsWide()
&& (pathList[6]->AsPath()->GetEdges() & edgeMask2) == edgeMask2 && pathList[5] != nullptr)
&& (pathList[6]->AsPath()->GetEdges() & edgeMask2) == edgeMask2 && pathList[2] != nullptr)
{
pathConnections |= FOOTPATH_CONNECTION_E;
}
}

/* In the following:
* footpath_element_is_wide(pathList[2])
* footpath_element_is_wide(pathList[3])
* footpath_element_is_wide(pathList[4])
* footpath_element_is_wide(pathList[1])
* are always false due to the tile update order
* in combination with reset tiles.
* Short circuit the logic appropriately. */
if ((pathConnections & FOOTPATH_CONNECTION_SE) && pathList[3] != nullptr)
if ((pathConnections & FOOTPATH_CONNECTION_SE) && pathList[1] != nullptr)
{
constexpr uint8_t edgeMask1 = EDGE_SW | EDGE_NW;
if ((pathConnections & FOOTPATH_CONNECTION_NE) && (pathList[2] != nullptr)
&& (pathList[2]->AsPath()->GetEdges() & edgeMask1) == edgeMask1 && pathList[1] != nullptr
&& !pathList[1]->AsPath()->IsWide())
if ((pathConnections & FOOTPATH_CONNECTION_NE) && (pathList[4] != nullptr)
&& (pathList[4]->AsPath()->GetEdges() & edgeMask1) == edgeMask1 && pathList[0] != nullptr
&& !pathList[0]->AsPath()->IsWide())
{
pathConnections |= FOOTPATH_CONNECTION_W;
}

/* In the following:
* footpath_element_is_wide(pathList[4])
* footpath_element_is_wide(pathList[5])
* footpath_element_is_wide(pathList[2])
* are always false due to the tile update order
* in combination with reset tiles.
* Short circuit the logic appropriately. */
constexpr uint8_t edgeMask2 = EDGE_NE | EDGE_NW;
if ((pathConnections & FOOTPATH_CONNECTION_SW) && pathList[4] != nullptr
&& (pathList[4]->AsPath()->GetEdges() & edgeMask2) == edgeMask2 && pathList[5] != nullptr)
if ((pathConnections & FOOTPATH_CONNECTION_SW) && pathList[5] != nullptr
&& (pathList[5]->AsPath()->GetEdges() & edgeMask2) == edgeMask2 && pathList[2] != nullptr)
{
pathConnections |= FOOTPATH_CONNECTION_N;
}
Expand Down

0 comments on commit 1892a3d

Please sign in to comment.