From 57faa437c0b9a0d5f0890639496d43a12a5839fc Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Tue, 14 Jan 2020 21:41:15 -0300 Subject: [PATCH 1/3] Prefer CoordsDirectionDelta on footpath_update_path_wide_flags() --- src/openrct2/world/Footpath.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index b722759ddd..aa0c21d6fb 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -1716,24 +1716,23 @@ void footpath_update_path_wide_flags(const CoordsXY& footpathPos) // 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 }; + auto pathPos = footpathPos + CoordsDirectionDelta[7]; pathList[0] = footpath_can_be_wide(pathPos, height); - pathPos.y += COORDS_XY_STEP; + pathPos += CoordsDirectionDelta[1]; pathList[1] = footpath_can_be_wide(pathPos, height); - pathPos.y += COORDS_XY_STEP; + pathPos += CoordsDirectionDelta[1]; pathList[2] = footpath_can_be_wide(pathPos, height); - pathPos.x += COORDS_XY_STEP; + pathPos += CoordsDirectionDelta[2]; pathList[3] = footpath_can_be_wide(pathPos, height); - pathPos.x += COORDS_XY_STEP; + pathPos += CoordsDirectionDelta[2]; pathList[4] = footpath_can_be_wide(pathPos, height); - pathPos.y -= COORDS_XY_STEP; + pathPos += CoordsDirectionDelta[3]; pathList[5] = footpath_can_be_wide(pathPos, height); - pathPos.y -= COORDS_XY_STEP; + pathPos += CoordsDirectionDelta[3]; pathList[6] = footpath_can_be_wide(pathPos, height); - pathPos.x -= COORDS_XY_STEP; + pathPos += CoordsDirectionDelta[0]; pathList[7] = footpath_can_be_wide(pathPos, height); - pathPos.y += COORDS_XY_STEP; + pathPos += CoordsDirectionDelta[1]; uint8_t pathConnections = 0; if (tileElement->AsPath()->GetEdges() & EDGE_NW) From 132ab424f7e57f6fb8162b93f0e8bd20f686ceee Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Tue, 14 Jan 2020 21:51:38 -0300 Subject: [PATCH 2/3] Use loop on footpath_update_path_wide() to iterate with CoordsDirectionDelta --- src/openrct2/world/Footpath.cpp | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index aa0c21d6fb..0dc9719e86 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -1717,22 +1717,16 @@ void footpath_update_path_wide_flags(const CoordsXY& footpathPos) TileElement* pathList[8]; auto pathPos = footpathPos + CoordsDirectionDelta[7]; - pathList[0] = footpath_can_be_wide(pathPos, height); - pathPos += CoordsDirectionDelta[1]; - pathList[1] = footpath_can_be_wide(pathPos, height); - pathPos += CoordsDirectionDelta[1]; - pathList[2] = footpath_can_be_wide(pathPos, height); - pathPos += CoordsDirectionDelta[2]; - pathList[3] = footpath_can_be_wide(pathPos, height); - pathPos += CoordsDirectionDelta[2]; - pathList[4] = footpath_can_be_wide(pathPos, height); - pathPos += CoordsDirectionDelta[3]; - pathList[5] = footpath_can_be_wide(pathPos, height); - pathPos += CoordsDirectionDelta[3]; - pathList[6] = footpath_can_be_wide(pathPos, height); - pathPos += CoordsDirectionDelta[0]; - pathList[7] = footpath_can_be_wide(pathPos, height); - pathPos += CoordsDirectionDelta[1]; + Direction direction = 1; + int32_t i = 0; + while (i < 8) + { + pathList[i++] = footpath_can_be_wide(pathPos, height); + pathPos += CoordsDirectionDelta[direction]; + pathList[i++] = footpath_can_be_wide(pathPos, height); + pathPos += CoordsDirectionDelta[direction]; + direction = direction_next(direction); + } uint8_t pathConnections = 0; if (tileElement->AsPath()->GetEdges() & EDGE_NW) From ad89319918e1fb1d3d0b39af9380d7d796235d28 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sat, 18 Jan 2020 11:00:01 -0300 Subject: [PATCH 3/3] Simplify loop on footpath_update_path_wide() --- src/openrct2/world/Footpath.cpp | 59 +++++++++++++++------------------ 1 file changed, 26 insertions(+), 33 deletions(-) diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 0dc9719e86..b685a18e73 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -1714,25 +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]; + std::array pathList; - auto pathPos = footpathPos + CoordsDirectionDelta[7]; - Direction direction = 1; - int32_t i = 0; - while (i < 8) + for (int32_t direction = 0; direction < 8; ++direction) { - pathList[i++] = footpath_can_be_wide(pathPos, height); - pathPos += CoordsDirectionDelta[direction]; - pathList[i++] = footpath_can_be_wide(pathPos, height); - pathPos += CoordsDirectionDelta[direction]; - direction = direction_next(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; } @@ -1741,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; } @@ -1751,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; // } //} @@ -1766,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; }