From 97fb10ceb1059a51f78593109e6834da04cbb456 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Mon, 29 Jan 2024 23:03:40 +0100 Subject: [PATCH] Refactor signatures of Path{Box,Pole}SupportsPaintSetup() --- src/openrct2/paint/Supports.cpp | 44 +++++++------------ src/openrct2/paint/Supports.h | 6 +-- .../paint/tile_element/Paint.Path.cpp | 32 ++++++-------- 3 files changed, 32 insertions(+), 50 deletions(-) diff --git a/src/openrct2/paint/Supports.cpp b/src/openrct2/paint/Supports.cpp index 3c1ccca707..a168ceac71 100644 --- a/src/openrct2/paint/Supports.cpp +++ b/src/openrct2/paint/Supports.cpp @@ -1252,13 +1252,10 @@ bool MetalBSupportsPaintSetup( * @return Whether supports were drawn */ bool PathBoxSupportsPaintSetup( - PaintSession& session, int32_t supportType, int32_t special, int32_t height, ImageId imageTemplate, - const FootpathPaintInfo& pathPaintInfo, bool* underground) + PaintSession& session, WoodenSupportSubType supportType, bool isSloped, Direction slopeRotation, int32_t height, + ImageId imageTemplate, const FootpathPaintInfo& pathPaintInfo) { - if (underground != nullptr) - { - *underground = false; // AND - } + auto supportOrientationOffset = (supportType == WoodenSupportSubType::NwSe) ? 24 : 0; if (!(session.Flags & PaintSessionFlags::PassedSurface)) { @@ -1278,8 +1275,6 @@ bool PathBoxSupportsPaintSetup( int32_t supportLength = height - baseHeight; if (supportLength < 0) { - if (underground != nullptr) - *underground = true; // STC return false; } @@ -1299,12 +1294,10 @@ bool PathBoxSupportsPaintSetup( heightSteps -= 2; if (heightSteps < 0) { - if (underground != nullptr) - *underground = true; // STC return false; } - uint32_t imageId = (supportType * 24) + word_97B3C4[session.Support.slope & TILE_ELEMENT_SURFACE_SLOPE_MASK] + uint32_t imageId = supportOrientationOffset + word_97B3C4[session.Support.slope & TILE_ELEMENT_SURFACE_SLOPE_MASK] + pathPaintInfo.BridgeImageId; PaintAddImageAsParent( @@ -1322,12 +1315,10 @@ bool PathBoxSupportsPaintSetup( heightSteps -= 1; if (heightSteps < 0) { - if (underground != nullptr) - *underground = true; // STC return false; } - uint32_t ebx = (supportType * 24) + word_97B3C4[session.Support.slope & TILE_ELEMENT_SURFACE_SLOPE_MASK] + uint32_t ebx = supportOrientationOffset + word_97B3C4[session.Support.slope & TILE_ELEMENT_SURFACE_SLOPE_MASK] + pathPaintInfo.BridgeImageId; PaintAddImageAsParent( @@ -1341,7 +1332,7 @@ bool PathBoxSupportsPaintSetup( { if (baseHeight & 0x10 || heightSteps == 1 || baseHeight + WATER_HEIGHT_STEP == session.WaterHeight) { - uint32_t imageId = (supportType * 24) + pathPaintInfo.BridgeImageId + 23; + uint32_t imageId = supportOrientationOffset + pathPaintInfo.BridgeImageId + 23; PaintAddImageAsParent( session, imageTemplate.WithIndex(imageId), { 0, 0, baseHeight }, { 32, 32, ((heightSteps == 1) ? 7 : 12) }); @@ -1351,7 +1342,7 @@ bool PathBoxSupportsPaintSetup( } else { - uint32_t imageId = (supportType * 24) + pathPaintInfo.BridgeImageId + 22; + uint32_t imageId = supportOrientationOffset + pathPaintInfo.BridgeImageId + 22; PaintAddImageAsParent( session, imageTemplate.WithIndex(imageId), { 0, 0, baseHeight }, { 32, 32, ((heightSteps == 2) ? 23 : 28) }); @@ -1361,13 +1352,11 @@ bool PathBoxSupportsPaintSetup( } } - if (special != 0) + if (isSloped) { - uint16_t specialIndex = (special - 1) & 0xFFFF; + ImageIndex imageIndex = pathPaintInfo.BridgeImageId + 55 + slopeRotation; - ImageIndex imageIndex = pathPaintInfo.BridgeImageId + 55 + specialIndex; - - const UnkSupportsDescriptor& supportsDesc = Byte98D8D4[specialIndex]; + const UnkSupportsDescriptor& supportsDesc = Byte98D8D4[slopeRotation]; auto boundBox = supportsDesc.bounding_box; boundBox.offset.z += baseHeight; @@ -1388,9 +1377,6 @@ bool PathBoxSupportsPaintSetup( } } - if (underground != nullptr) - *underground = false; // AND - return hasSupports; } @@ -1407,9 +1393,11 @@ bool PathBoxSupportsPaintSetup( * @return Whether supports were drawn */ bool PathPoleSupportsPaintSetup( - PaintSession& session, int32_t segment, int32_t special, int32_t height, ImageId imageTemplate, + PaintSession& session, MetalSupportPlace supportPlace, bool isSloped, int32_t height, ImageId imageTemplate, const FootpathPaintInfo& pathPaintInfo) { + auto segment = EnumValue(supportPlace); + SupportHeight* supportSegments = session.SupportSegments; if (!(session.Flags & PaintSessionFlags::PassedSurface)) @@ -1523,13 +1511,13 @@ bool PathPoleSupportsPaintSetup( supportSegments[segment].height = 0xFFFF; supportSegments[segment].slope = 0x20; - if (special != 0) + if (isSloped) { - int16_t si = special + baseHeight; + int16_t si = baseHeight + COORDS_Z_STEP; while (true) { - int16_t z = baseHeight + 16; + int16_t z = baseHeight + (2 * COORDS_Z_STEP); if (z > si) { z = si; diff --git a/src/openrct2/paint/Supports.h b/src/openrct2/paint/Supports.h index e5514792f3..42e5f471bc 100644 --- a/src/openrct2/paint/Supports.h +++ b/src/openrct2/paint/Supports.h @@ -146,10 +146,10 @@ bool MetalBSupportsPaintSetup( PaintSession& session, MetalSupportType supportTypeMember, MetalSupportPlace placement, int32_t special, int32_t height, ImageId imageTemplate); bool PathBoxSupportsPaintSetup( - PaintSession& session, int32_t supportType, int32_t special, int32_t height, ImageId imageTemplate, - const FootpathPaintInfo& pathPaintInfo, bool* underground); + PaintSession& session, WoodenSupportSubType supportType, bool isSloped, Direction slopeRotation, int32_t height, + ImageId imageTemplate, const FootpathPaintInfo& pathPaintInfo); bool PathPoleSupportsPaintSetup( - PaintSession& session, int32_t segment, int32_t special, int32_t height, ImageId imageTemplate, + PaintSession& session, MetalSupportPlace supportPlace, bool isSloped, int32_t height, ImageId imageTemplate, const FootpathPaintInfo& pathPaintInfo); void DrawSupportsSideBySide( PaintSession& session, Direction direction, uint16_t height, ImageId colour, MetalSupportType type, int32_t special = 0); diff --git a/src/openrct2/paint/tile_element/Paint.Path.cpp b/src/openrct2/paint/tile_element/Paint.Path.cpp index 4dc3df883b..af5c653d32 100644 --- a/src/openrct2/paint/tile_element/Paint.Path.cpp +++ b/src/openrct2/paint/tile_element/Paint.Path.cpp @@ -82,8 +82,8 @@ static constexpr BoundBoxXY stru_98D804[] = { { { 0, 0 }, { 32, 32 } }, }; -static constexpr uint8_t Byte98D8A4[] = { - 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0 +static constexpr WoodenSupportSubType PathSupportOrientation[] = { + WoodenSupportSubType::NeSw, WoodenSupportSubType::NeSw, WoodenSupportSubType::NwSe, WoodenSupportSubType::NeSw, WoodenSupportSubType::NeSw, WoodenSupportSubType::NeSw, WoodenSupportSubType::NwSe, WoodenSupportSubType::NeSw, WoodenSupportSubType::NwSe, WoodenSupportSubType::NwSe, WoodenSupportSubType::NwSe, WoodenSupportSubType::NwSe, WoodenSupportSubType::NeSw, WoodenSupportSubType::NeSw, WoodenSupportSubType::NwSe, WoodenSupportSubType::NeSw, }; // clang-format on @@ -955,7 +955,7 @@ void PathPaintBoxSupport( } else { - bridgeBaseImageIndex = Byte98D8A4[edges] + pathPaintInfo.BridgeImageId + 49; + bridgeBaseImageIndex = EnumValue(PathSupportOrientation[edges]) + pathPaintInfo.BridgeImageId + 49; } PaintAddImageAsParent(session, imageTemplate.WithIndex(bridgeBaseImageIndex), { 0, 0, height }, boundbox); @@ -968,14 +968,14 @@ void PathPaintBoxSupport( Sub6A3F61(session, pathElement, edi, height, pathPaintInfo, imageTemplate, sceneryImageTemplate, hasSupports); - uint16_t ax = 0; + Direction slopeDirection{}; if (pathElement.IsSloped()) { - ax = ((pathElement.GetSlopeDirection() + session.CurrentRotation) & 0x3) + 1; + slopeDirection = ((pathElement.GetSlopeDirection() + session.CurrentRotation) & 0x3); } - auto supportType = Byte98D8A4[edges] == 0 ? 0 : 1; - PathBoxSupportsPaintSetup(session, supportType, ax, height, imageTemplate, pathPaintInfo, nullptr); + PathBoxSupportsPaintSetup( + session, PathSupportOrientation[edges], pathElement.IsSloped(), slopeDirection, height, imageTemplate, pathPaintInfo); PathPaintSegmentSupportHeight(session, pathElement, height, edges, hasSupports); } @@ -1024,17 +1024,11 @@ void PathPaintPoleSupport( session, pathElement, edi, height, pathPaintInfo, imageTemplate, sceneryImageTemplate, hasSupports); // TODO: arguments - uint16_t ax = 0; - if (pathElement.IsSloped()) - { - ax = 8; - } - - uint8_t supports[] = { - 6, - 8, - 7, - 5, + MetalSupportPlace supports[] = { + MetalSupportPlace::TopRightSide, + MetalSupportPlace::BottomRightSide, + MetalSupportPlace::BottomLeftSide, + MetalSupportPlace::TopLeftSide, }; for (int8_t i = 3; i > -1; --i) @@ -1047,7 +1041,7 @@ void PathPaintPoleSupport( { imageTemplate = ImageId().WithPrimary(supportColour); } - PathPoleSupportsPaintSetup(session, supports[i], ax, height, imageTemplate, pathPaintInfo); + PathPoleSupportsPaintSetup(session, supports[i], pathElement.IsSloped(), height, imageTemplate, pathPaintInfo); } }