From 0d64899fd307becb5248d135f05a839762ef363f Mon Sep 17 00:00:00 2001 From: mix <167040362+mixiate@users.noreply.github.com> Date: Sat, 9 Aug 2025 05:32:20 +0100 Subject: [PATCH] Remove null TunnelType and refactor paint code accordingly (#24924) --- src/openrct2/paint/Paint.h | 6 +- .../paint/tile_element/Paint.Surface.cpp | 74 ++++++++----------- .../paint/tile_element/Paint.TileElement.cpp | 6 +- .../paint/tile_element/Paint.Tunnel.cpp | 12 +-- .../paint/tile_element/Paint.Tunnel.h | 9 ++- 5 files changed, 43 insertions(+), 64 deletions(-) diff --git a/src/openrct2/paint/Paint.h b/src/openrct2/paint/Paint.h index 17ce7e1720..48fa451fee 100644 --- a/src/openrct2/paint/Paint.h +++ b/src/openrct2/paint/Paint.h @@ -149,10 +149,8 @@ struct PaintSessionCore SupportHeight SupportSegments[9]; SupportHeight Support; uint16_t WaterHeight; - TunnelEntry LeftTunnels[kTunnelMaxCount]; - TunnelEntry RightTunnels[kTunnelMaxCount]; - uint8_t LeftTunnelCount; - uint8_t RightTunnelCount; + sfl::static_vector LeftTunnels; + sfl::static_vector RightTunnels; uint8_t VerticalTunnelHeight; uint8_t CurrentRotation; uint8_t Flags; diff --git a/src/openrct2/paint/tile_element/Paint.Surface.cpp b/src/openrct2/paint/tile_element/Paint.Surface.cpp index 5dac893ee7..aff64a7d69 100644 --- a/src/openrct2/paint/tile_element/Paint.Surface.cpp +++ b/src/openrct2/paint/tile_element/Paint.Surface.cpp @@ -197,7 +197,7 @@ static constexpr TunnelDescriptor kTunnels[] = { { 2, 3, -16, 4, TunnelType::Doors5, 96 }, // TunnelType::DoorsFlatTo25Deg5 { 2, 3, -16, 4, TunnelType::Doors6, 100 }, // TunnelType::DoorsFlatTo25Deg6 }; -static_assert(std::size(kTunnels) == EnumValue(TunnelType::Count)); +static_assert(std::size(kTunnels) == kTunnelTypeCount); // clang-format on // tunnel offset @@ -518,7 +518,6 @@ static void ViewportSurfaceDrawTileSideBottom( CoordsXY tunnelBounds = { 1, 1 }; CoordsXY tunnelTopBoundBoxOffset = { 0, 0 }; - const TunnelEntry* tunnelArray; switch (edge) { case EDGE_BOTTOMLEFT: @@ -532,8 +531,6 @@ static void ViewportSurfaceDrawTileSideBottom( bounds.y = 30; tunnelBounds.x = 32; tunnelTopBoundBoxOffset.y = 31; - - tunnelArray = session.LeftTunnels; break; case EDGE_BOTTOMRIGHT: @@ -547,8 +544,6 @@ static void ViewportSurfaceDrawTileSideBottom( bounds.x = 30; tunnelBounds.y = 32; tunnelTopBoundBoxOffset.x = 31; - - tunnelArray = session.RightTunnels; break; default: @@ -618,50 +613,27 @@ static void ViewportSurfaceDrawTileSideBottom( neighbourCornerHeight1 = cornerHeight2; - for (auto tunnelIndex = 0; tunnelIndex < kTunnelMaxCount;) + const auto lowestCornerHeight = std::min(cornerHeight1, cornerHeight2); + + const auto& tunnels = edge == EDGE_BOTTOMLEFT ? session.LeftTunnels : session.RightTunnels; + for (auto& tunnel : tunnels) { - if (curHeight >= cornerHeight1 || curHeight >= cornerHeight2) + if (curHeight > tunnel.height || tunnel.height >= lowestCornerHeight) { - // If top of edge isn't straight, add a filler - uint32_t image_offset = 1; - if (curHeight >= cornerHeight1) - { - image_offset = 2; - - if (curHeight >= cornerHeight2) - { - return; - } - } - - auto imageId = baseImageId.WithIndexOffset(image_offset); - PaintAddImageAsParent(session, imageId, { offset, curHeight * kCoordsZPerTinyZ }, { bounds, 15 }); - - return; + continue; } - if (curHeight != tunnelArray[tunnelIndex].height) + const auto tdOriginal = kTunnels[EnumValue(tunnel.type)]; + + // Draw land edges up to the bottom of the tunnel + while (curHeight < tunnel.height) { - // Normal walls - while (curHeight > tunnelArray[tunnelIndex].height) - { - tunnelIndex++; - } - - if (isWater || curHeight != tunnelArray[tunnelIndex].height) - { - const auto td = kTunnels[EnumValue(tunnelArray[tunnelIndex].type)]; - const auto boundBoxZ = curHeight == tunnelArray[tunnelIndex].height - 1 ? td.lowerEdgeBoundingBoxZ : 15; - PaintAddImageAsParent(session, baseImageId, { offset, curHeight * kCoordsZPerTinyZ }, { bounds, boundBoxZ }); - - curHeight++; - continue; - } + const auto boundBoxZ = curHeight == tunnel.height - 1 ? tdOriginal.lowerEdgeBoundingBoxZ : kCoordsZPerTinyZ - 1; + PaintAddImageAsParent(session, baseImageId, { offset, curHeight * kCoordsZPerTinyZ }, { bounds, boundBoxZ }); + curHeight++; } - // Tunnels - auto tunnelType = tunnelArray[tunnelIndex].type; - const auto tdOriginal = kTunnels[EnumValue(tunnelType)]; + auto tunnelType = tunnel.type; auto td = tdOriginal; uint8_t tunnelHeight = td.height; int16_t zOffset = curHeight; @@ -704,7 +676,21 @@ static void ViewportSurfaceDrawTileSideBottom( { { tunnelTopBoundBoxOffset, boundBoxOffsetZ }, { tunnelBounds, boundBoxLength - 1 } }); curHeight += td.height; - tunnelIndex++; + } + + // Draw land edges up to the lowest corner + while (curHeight < lowestCornerHeight) + { + PaintAddImageAsParent(session, baseImageId, { offset, curHeight * kCoordsZPerTinyZ }, { bounds, kCoordsZPerTinyZ - 1 }); + curHeight++; + } + + // Draw filler edges if the top edge is not straight + if (curHeight < cornerHeight1 || curHeight < cornerHeight2) + { + const uint32_t imageOffset = curHeight >= cornerHeight1 ? 2 : 1; + const auto imageId = baseImageId.WithIndexOffset(imageOffset); + PaintAddImageAsParent(session, imageId, { offset, curHeight * kCoordsZPerTinyZ }, { bounds, kCoordsZPerTinyZ - 1 }); } } diff --git a/src/openrct2/paint/tile_element/Paint.TileElement.cpp b/src/openrct2/paint/tile_element/Paint.TileElement.cpp index 6c1ec4ad0d..e09fce2e58 100644 --- a/src/openrct2/paint/tile_element/Paint.TileElement.cpp +++ b/src/openrct2/paint/tile_element/Paint.TileElement.cpp @@ -125,10 +125,8 @@ static void PaintTileElementBase(PaintSession& session, const CoordsXY& origCoor return; } - session.LeftTunnelCount = 0; - session.RightTunnelCount = 0; - session.LeftTunnels[0] = { 0xFF, TunnelType::Null }; - session.RightTunnels[0] = { 0xFF, TunnelType::Null }; + session.LeftTunnels.clear(); + session.RightTunnels.clear(); session.VerticalTunnelHeight = 0xFF; session.MapPosition.x = coords.x; session.MapPosition.y = coords.y; diff --git a/src/openrct2/paint/tile_element/Paint.Tunnel.cpp b/src/openrct2/paint/tile_element/Paint.Tunnel.cpp index 37899f48c8..8d301629a4 100644 --- a/src/openrct2/paint/tile_element/Paint.Tunnel.cpp +++ b/src/openrct2/paint/tile_element/Paint.Tunnel.cpp @@ -26,21 +26,17 @@ void TrackPaintUtilRightQuarterTurn3TilesTunnel( void PaintUtilPushTunnelLeft(PaintSession& session, uint16_t height, TunnelType type) { - session.LeftTunnels[session.LeftTunnelCount] = { static_cast((height / 16)), type }; - if (session.LeftTunnelCount < kTunnelMaxCount - 1) + if (!session.LeftTunnels.full()) { - session.LeftTunnels[session.LeftTunnelCount + 1] = { 0xFF, TunnelType::Null }; - session.LeftTunnelCount++; + session.LeftTunnels.emplace_back(height / kCoordsZPerTinyZ, type); } } void PaintUtilPushTunnelRight(PaintSession& session, uint16_t height, TunnelType type) { - session.RightTunnels[session.RightTunnelCount] = { static_cast((height / 16)), type }; - if (session.RightTunnelCount < kTunnelMaxCount - 1) + if (!session.RightTunnels.full()) { - session.RightTunnels[session.RightTunnelCount + 1] = { 0xFF, TunnelType::Null }; - session.RightTunnelCount++; + session.RightTunnels.emplace_back(height / kCoordsZPerTinyZ, type); } } diff --git a/src/openrct2/paint/tile_element/Paint.Tunnel.h b/src/openrct2/paint/tile_element/Paint.Tunnel.h index 9d2beeb4a2..eac8ab7048 100644 --- a/src/openrct2/paint/tile_element/Paint.Tunnel.h +++ b/src/openrct2/paint/tile_element/Paint.Tunnel.h @@ -52,12 +52,9 @@ enum class TunnelType : uint8_t DoorsFlatTo25Deg4 = 27, DoorsFlatTo25Deg5 = 28, DoorsFlatTo25Deg6 = 29, - - Count, - - Null = 255, }; constexpr uint8_t kRegularTunnelTypeCount = 16; +constexpr uint8_t kTunnelTypeCount = 30; enum class TunnelGroup : uint8_t { @@ -81,6 +78,10 @@ struct TunnelEntry { uint8_t height; TunnelType type; + + constexpr TunnelEntry(const uint8_t _height, const TunnelType _type) + : height(_height) + , type(_type) {}; }; TunnelType GetTunnelType(TunnelGroup tunnelGroup, TunnelSubType tunnelSubType);