From 29816355e7f02e7241bb63e43d2297b7b864f381 Mon Sep 17 00:00:00 2001 From: mix Date: Wed, 9 Jul 2025 00:47:19 +0100 Subject: [PATCH 01/18] Rename special parameter to heightExtra in metal support functions --- src/openrct2/paint/support/MetalSupports.cpp | 61 ++++++++++---------- src/openrct2/paint/support/MetalSupports.h | 11 ++-- 2 files changed, 37 insertions(+), 35 deletions(-) diff --git a/src/openrct2/paint/support/MetalSupports.cpp b/src/openrct2/paint/support/MetalSupports.cpp index 4a47374478..d99e7179b9 100644 --- a/src/openrct2/paint/support/MetalSupports.cpp +++ b/src/openrct2/paint/support/MetalSupports.cpp @@ -282,25 +282,25 @@ constexpr MetalSupportGraphic kMetalSupportGraphicRotated[kMetalSupportTypeCount }; static bool MetalASupportsPaintSetup( - PaintSession& session, MetalSupportGraphic supportTypeMember, MetalSupportPlace placement, int32_t special, int32_t height, - ImageId imageTemplate); + PaintSession& session, MetalSupportGraphic supportTypeMember, MetalSupportPlace placement, int32_t heightExtra, + int32_t height, ImageId imageTemplate); static bool MetalBSupportsPaintSetup( - PaintSession& session, MetalSupportGraphic supportTypeMember, MetalSupportPlace placement, int32_t special, int32_t height, - ImageId imageTemplate); + PaintSession& session, MetalSupportGraphic supportTypeMember, MetalSupportPlace placement, int32_t heightExtra, + int32_t height, ImageId imageTemplate); static inline MetalSupportGraphic RotateMetalSupportGraphic(MetalSupportType supportType, Direction direction); /** * Metal pole supports * @param supportType (edi) * @param segment (ebx) - * @param special (ax) + * @param heightExtra (ax) * @param height (edx) * @param imageTemplate (ebp) * rct2: 0x00663105 */ static bool MetalASupportsPaintSetup( - PaintSession& session, MetalSupportGraphic supportTypeMember, MetalSupportPlace placement, int32_t special, int32_t height, - ImageId imageTemplate) + PaintSession& session, MetalSupportGraphic supportTypeMember, MetalSupportPlace placement, int32_t heightExtra, + int32_t height, ImageId imageTemplate) { if (!(session.Flags & PaintSessionFlags::PassedSurface)) { @@ -444,17 +444,17 @@ static bool MetalASupportsPaintSetup( height = originalHeight; segment = originalSegment; - if (special == 0) + if (heightExtra == 0) return true; - if (special < 0) + if (heightExtra < 0) { - special = -special; + heightExtra = -heightExtra; height--; } CoordsXYZ boundBoxOffset = CoordsXYZ(kMetalSupportBoundBoxOffsets[segment], height); - const auto combinedHeight = height + special; + const auto combinedHeight = height + heightExtra; while (1) { @@ -484,20 +484,20 @@ static bool MetalASupportsPaintSetup( } bool MetalASupportsPaintSetup( - PaintSession& session, MetalSupportType supportType, MetalSupportPlace placement, int32_t special, int32_t height, + PaintSession& session, MetalSupportType supportType, MetalSupportPlace placement, int32_t heightExtra, int32_t height, ImageId imageTemplate) { auto supportGraphic = RotateMetalSupportGraphic(supportType, 0); - return MetalASupportsPaintSetup(session, supportGraphic, placement, special, height, imageTemplate); + return MetalASupportsPaintSetup(session, supportGraphic, placement, heightExtra, height, imageTemplate); } bool MetalASupportsPaintSetupRotated( - PaintSession& session, MetalSupportType supportType, MetalSupportPlace placement, Direction direction, int32_t special, + PaintSession& session, MetalSupportType supportType, MetalSupportPlace placement, Direction direction, int32_t heightExtra, int32_t height, ImageId imageTemplate) { auto supportGraphic = RotateMetalSupportGraphic(supportType, direction); placement = kMetalSupportPlacementRotated[EnumValue(placement)][direction]; - return MetalASupportsPaintSetup(session, supportGraphic, placement, special, height, imageTemplate); + return MetalASupportsPaintSetup(session, supportGraphic, placement, heightExtra, height, imageTemplate); } /** @@ -506,15 +506,15 @@ bool MetalASupportsPaintSetupRotated( * * @param supportType (edi) * @param segment (ebx) - * @param special (ax) + * @param heightExtra (ax) * @param height (edx) * @param imageTemplate (ebp) * * @return (Carry Flag) */ static bool MetalBSupportsPaintSetup( - PaintSession& session, MetalSupportGraphic supportTypeMember, MetalSupportPlace placement, int32_t special, int32_t height, - ImageId imageTemplate) + PaintSession& session, MetalSupportGraphic supportTypeMember, MetalSupportPlace placement, int32_t heightExtra, + int32_t height, ImageId imageTemplate) { if (!(session.Flags & PaintSessionFlags::PassedSurface)) { @@ -656,10 +656,10 @@ static bool MetalBSupportsPaintSetup( supportSegments[segment].height = unk9E3294; supportSegments[segment].slope = kTileSlopeAboveTrackOrScenery; - if (special != 0) + if (heightExtra != 0) { baseHeight = height; - const auto si2 = height + special; + const auto si2 = height + heightExtra; while (true) { endHeight = baseHeight + 16; @@ -686,20 +686,20 @@ static bool MetalBSupportsPaintSetup( } bool MetalBSupportsPaintSetup( - PaintSession& session, MetalSupportType supportType, MetalSupportPlace placement, int32_t special, int32_t height, + PaintSession& session, MetalSupportType supportType, MetalSupportPlace placement, int32_t heightExtra, int32_t height, ImageId imageTemplate) { auto supportGraphic = RotateMetalSupportGraphic(supportType, 0); - return MetalBSupportsPaintSetup(session, supportGraphic, placement, special, height, imageTemplate); + return MetalBSupportsPaintSetup(session, supportGraphic, placement, heightExtra, height, imageTemplate); } bool MetalBSupportsPaintSetupRotated( - PaintSession& session, MetalSupportType supportType, MetalSupportPlace placement, Direction direction, int32_t special, + PaintSession& session, MetalSupportType supportType, MetalSupportPlace placement, Direction direction, int32_t heightExtra, int32_t height, ImageId imageTemplate) { auto supportGraphic = RotateMetalSupportGraphic(supportType, direction); placement = kMetalSupportPlacementRotated[EnumValue(placement)][direction]; - return MetalBSupportsPaintSetup(session, supportGraphic, placement, special, height, imageTemplate); + return MetalBSupportsPaintSetup(session, supportGraphic, placement, heightExtra, height, imageTemplate); } static inline MetalSupportGraphic RotateMetalSupportGraphic(MetalSupportType supportType, Direction direction) @@ -709,19 +709,20 @@ static inline MetalSupportGraphic RotateMetalSupportGraphic(MetalSupportType sup } void DrawSupportsSideBySide( - PaintSession& session, Direction direction, uint16_t height, ImageId colour, MetalSupportType supportType, int32_t special) + PaintSession& session, Direction direction, uint16_t height, ImageId colour, MetalSupportType supportType, + int32_t heightExtra) { auto graphic = RotateMetalSupportGraphic(supportType, direction); if (direction & 1) { - MetalASupportsPaintSetup(session, graphic, MetalSupportPlace::topRightSide, special, height, colour); - MetalASupportsPaintSetup(session, graphic, MetalSupportPlace::bottomLeftSide, special, height, colour); + MetalASupportsPaintSetup(session, graphic, MetalSupportPlace::topRightSide, heightExtra, height, colour); + MetalASupportsPaintSetup(session, graphic, MetalSupportPlace::bottomLeftSide, heightExtra, height, colour); } else { - MetalASupportsPaintSetup(session, graphic, MetalSupportPlace::topLeftSide, special, height, colour); - MetalASupportsPaintSetup(session, graphic, MetalSupportPlace::bottomRightSide, special, height, colour); + MetalASupportsPaintSetup(session, graphic, MetalSupportPlace::topLeftSide, heightExtra, height, colour); + MetalASupportsPaintSetup(session, graphic, MetalSupportPlace::bottomRightSide, heightExtra, height, colour); } } @@ -730,7 +731,7 @@ void DrawSupportsSideBySide( * rct2: 0x006A326B * * @param segment (ebx) - * @param special (ax) + * @param heightExtra (ax) * @param height (dx) * @param imageTemplate (ebp) * @param railingsDescriptor (0x00F3EF6C) diff --git a/src/openrct2/paint/support/MetalSupports.h b/src/openrct2/paint/support/MetalSupports.h index 236ddf0dc7..37b446b19a 100644 --- a/src/openrct2/paint/support/MetalSupports.h +++ b/src/openrct2/paint/support/MetalSupports.h @@ -91,20 +91,21 @@ struct PaintSession; /** @deprecated */ bool MetalASupportsPaintSetup( - PaintSession& session, MetalSupportType supportType, MetalSupportPlace placement, int32_t special, int32_t height, + PaintSession& session, MetalSupportType supportType, MetalSupportPlace placement, int32_t heightExtra, int32_t height, ImageId imageTemplate); bool MetalASupportsPaintSetupRotated( - PaintSession& session, MetalSupportType supportType, MetalSupportPlace placement, Direction direction, int32_t special, + PaintSession& session, MetalSupportType supportType, MetalSupportPlace placement, Direction direction, int32_t heightExtra, int32_t height, ImageId imageTemplate); /** @deprecated */ bool MetalBSupportsPaintSetup( - PaintSession& session, MetalSupportType supportType, MetalSupportPlace placement, int32_t special, int32_t height, + PaintSession& session, MetalSupportType supportType, MetalSupportPlace placement, int32_t heightExtra, int32_t height, ImageId imageTemplate); bool MetalBSupportsPaintSetupRotated( - PaintSession& session, MetalSupportType supportType, MetalSupportPlace placement, Direction direction, int32_t special, + PaintSession& session, MetalSupportType supportType, MetalSupportPlace placement, Direction direction, int32_t heightExtra, int32_t height, ImageId imageTemplate); void DrawSupportsSideBySide( - PaintSession& session, Direction direction, uint16_t height, ImageId colour, MetalSupportType type, int32_t special = 0); + PaintSession& session, Direction direction, uint16_t height, ImageId colour, MetalSupportType type, + int32_t heightExtra = 0); bool PathPoleSupportsPaintSetup( PaintSession& session, MetalSupportPlace supportPlace, bool isSloped, int32_t height, ImageId imageTemplate, const FootpathPaintInfo& pathPaintInfo); From 8bb790ae22f5e27ae28ef6142199ec1e920acf49 Mon Sep 17 00:00:00 2001 From: mix Date: Wed, 9 Jul 2025 00:54:09 +0100 Subject: [PATCH 02/18] Add const to metal support function parameters --- src/openrct2/paint/support/MetalSupports.cpp | 34 ++++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/openrct2/paint/support/MetalSupports.cpp b/src/openrct2/paint/support/MetalSupports.cpp index d99e7179b9..26b477fe5e 100644 --- a/src/openrct2/paint/support/MetalSupports.cpp +++ b/src/openrct2/paint/support/MetalSupports.cpp @@ -299,7 +299,7 @@ static inline MetalSupportGraphic RotateMetalSupportGraphic(MetalSupportType sup * rct2: 0x00663105 */ static bool MetalASupportsPaintSetup( - PaintSession& session, MetalSupportGraphic supportTypeMember, MetalSupportPlace placement, int32_t heightExtra, + PaintSession& session, const MetalSupportGraphic supportTypeMember, const MetalSupportPlace placement, int32_t heightExtra, int32_t height, ImageId imageTemplate) { if (!(session.Flags & PaintSessionFlags::PassedSurface)) @@ -484,7 +484,7 @@ static bool MetalASupportsPaintSetup( } bool MetalASupportsPaintSetup( - PaintSession& session, MetalSupportType supportType, MetalSupportPlace placement, int32_t heightExtra, int32_t height, + PaintSession& session, MetalSupportType supportType, MetalSupportPlace placement, const int32_t heightExtra, int32_t height, ImageId imageTemplate) { auto supportGraphic = RotateMetalSupportGraphic(supportType, 0); @@ -492,8 +492,8 @@ bool MetalASupportsPaintSetup( } bool MetalASupportsPaintSetupRotated( - PaintSession& session, MetalSupportType supportType, MetalSupportPlace placement, Direction direction, int32_t heightExtra, - int32_t height, ImageId imageTemplate) + PaintSession& session, MetalSupportType supportType, MetalSupportPlace placement, Direction direction, + const int32_t heightExtra, int32_t height, ImageId imageTemplate) { auto supportGraphic = RotateMetalSupportGraphic(supportType, direction); placement = kMetalSupportPlacementRotated[EnumValue(placement)][direction]; @@ -513,8 +513,8 @@ bool MetalASupportsPaintSetupRotated( * @return (Carry Flag) */ static bool MetalBSupportsPaintSetup( - PaintSession& session, MetalSupportGraphic supportTypeMember, MetalSupportPlace placement, int32_t heightExtra, - int32_t height, ImageId imageTemplate) + PaintSession& session, const MetalSupportGraphic supportTypeMember, const MetalSupportPlace placement, + const int32_t heightExtra, const int32_t height, ImageId imageTemplate) { if (!(session.Flags & PaintSessionFlags::PassedSurface)) { @@ -686,31 +686,31 @@ static bool MetalBSupportsPaintSetup( } bool MetalBSupportsPaintSetup( - PaintSession& session, MetalSupportType supportType, MetalSupportPlace placement, int32_t heightExtra, int32_t height, - ImageId imageTemplate) + PaintSession& session, const MetalSupportType supportType, const MetalSupportPlace placement, const int32_t heightExtra, + int32_t height, const ImageId imageTemplate) { auto supportGraphic = RotateMetalSupportGraphic(supportType, 0); return MetalBSupportsPaintSetup(session, supportGraphic, placement, heightExtra, height, imageTemplate); } bool MetalBSupportsPaintSetupRotated( - PaintSession& session, MetalSupportType supportType, MetalSupportPlace placement, Direction direction, int32_t heightExtra, - int32_t height, ImageId imageTemplate) + PaintSession& session, const MetalSupportType supportType, const MetalSupportPlace placement, const Direction direction, + const int32_t heightExtra, const int32_t height, const ImageId imageTemplate) { auto supportGraphic = RotateMetalSupportGraphic(supportType, direction); - placement = kMetalSupportPlacementRotated[EnumValue(placement)][direction]; - return MetalBSupportsPaintSetup(session, supportGraphic, placement, heightExtra, height, imageTemplate); + const auto rotatedPlacement = kMetalSupportPlacementRotated[EnumValue(placement)][direction]; + return MetalBSupportsPaintSetup(session, supportGraphic, rotatedPlacement, heightExtra, height, imageTemplate); } -static inline MetalSupportGraphic RotateMetalSupportGraphic(MetalSupportType supportType, Direction direction) +static inline MetalSupportGraphic RotateMetalSupportGraphic(const MetalSupportType supportType, const Direction direction) { assert(direction < kNumOrthogonalDirections); return kMetalSupportGraphicRotated[EnumValue(supportType)][direction]; } void DrawSupportsSideBySide( - PaintSession& session, Direction direction, uint16_t height, ImageId colour, MetalSupportType supportType, - int32_t heightExtra) + PaintSession& session, const Direction direction, const uint16_t height, const ImageId colour, + const MetalSupportType supportType, const int32_t heightExtra) { auto graphic = RotateMetalSupportGraphic(supportType, direction); @@ -739,8 +739,8 @@ void DrawSupportsSideBySide( * @return Whether supports were drawn */ bool PathPoleSupportsPaintSetup( - PaintSession& session, MetalSupportPlace supportPlace, bool isSloped, int32_t height, ImageId imageTemplate, - const FootpathPaintInfo& pathPaintInfo) + PaintSession& session, const MetalSupportPlace supportPlace, const bool isSloped, const int32_t height, + ImageId imageTemplate, const FootpathPaintInfo& pathPaintInfo) { auto segment = EnumValue(supportPlace); From e794492f58add6b8dbe3658e5bbd7783d4001958 Mon Sep 17 00:00:00 2001 From: mix Date: Mon, 10 Mar 2025 21:36:02 +0000 Subject: [PATCH 03/18] Rename unk variable to segmentHeight in metal support paint --- src/openrct2/paint/support/MetalSupports.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/openrct2/paint/support/MetalSupports.cpp b/src/openrct2/paint/support/MetalSupports.cpp index 26b477fe5e..48f347b3a3 100644 --- a/src/openrct2/paint/support/MetalSupports.cpp +++ b/src/openrct2/paint/support/MetalSupports.cpp @@ -322,10 +322,10 @@ static bool MetalASupportsPaintSetup( int16_t originalHeight = height; const auto originalSegment = segment; - uint16_t unk9E3294 = 0xFFFF; + uint16_t segmentHeight = 0xFFFF; if (height < supportSegments[segment].height) { - unk9E3294 = height; + segmentHeight = height; height -= kMetalSupportTypeToHeight[supportType]; if (height < 0) @@ -439,7 +439,7 @@ static bool MetalASupportsPaintSetup( height += beamLength; } - supportSegments[segment].height = unk9E3294; + supportSegments[segment].height = segmentHeight; supportSegments[segment].slope = kTileSlopeAboveTrackOrScenery; height = originalHeight; @@ -533,12 +533,12 @@ static bool MetalBSupportsPaintSetup( const uint8_t segment = EnumValue(placement); auto supportType = EnumValue(supportTypeMember); SupportHeight* supportSegments = session.SupportSegments; - uint16_t unk9E3294 = 0xFFFF; + uint16_t segmentHeight = 0xFFFF; int32_t baseHeight = height; if (height < supportSegments[segment].height) { - unk9E3294 = height; + segmentHeight = height; baseHeight -= kMetalSupportTypeToHeight[supportType]; if (baseHeight < 0) @@ -653,7 +653,7 @@ static bool MetalBSupportsPaintSetup( i++; } - supportSegments[segment].height = unk9E3294; + supportSegments[segment].height = segmentHeight; supportSegments[segment].slope = kTileSlopeAboveTrackOrScenery; if (heightExtra != 0) From 8445a1bdb7a07270a1851c477a560f3145c5ca61 Mon Sep 17 00:00:00 2001 From: mix Date: Wed, 9 Jul 2025 00:59:09 +0100 Subject: [PATCH 04/18] Make MetalASupportsPaintSetup height parameter const --- src/openrct2/paint/support/MetalSupports.cpp | 63 ++++++++++---------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/src/openrct2/paint/support/MetalSupports.cpp b/src/openrct2/paint/support/MetalSupports.cpp index 48f347b3a3..6fc5941852 100644 --- a/src/openrct2/paint/support/MetalSupports.cpp +++ b/src/openrct2/paint/support/MetalSupports.cpp @@ -300,7 +300,7 @@ static inline MetalSupportGraphic RotateMetalSupportGraphic(MetalSupportType sup */ static bool MetalASupportsPaintSetup( PaintSession& session, const MetalSupportGraphic supportTypeMember, const MetalSupportPlace placement, int32_t heightExtra, - int32_t height, ImageId imageTemplate) + const int32_t height, ImageId imageTemplate) { if (!(session.Flags & PaintSessionFlags::PassedSurface)) { @@ -319,34 +319,34 @@ static bool MetalASupportsPaintSetup( uint8_t segment = EnumValue(placement); auto supportType = EnumValue(supportTypeMember); SupportHeight* supportSegments = session.SupportSegments; - int16_t originalHeight = height; + int32_t currentHeight = height; const auto originalSegment = segment; uint16_t segmentHeight = 0xFFFF; - if (height < supportSegments[segment].height) + if (currentHeight < supportSegments[segment].height) { - segmentHeight = height; + segmentHeight = currentHeight; - height -= kMetalSupportTypeToHeight[supportType]; - if (height < 0) + currentHeight -= kMetalSupportTypeToHeight[supportType]; + if (currentHeight < 0) return false; const uint8_t* esi = &(kMetalSupportSegmentOffsets[session.CurrentRotation * 2]); uint8_t newSegment = esi[segment * 8]; - if (height <= supportSegments[newSegment].height) + if (currentHeight <= supportSegments[newSegment].height) { esi += kMetalSupportSkip; newSegment = esi[segment * 8]; - if (height <= supportSegments[newSegment].height) + if (currentHeight <= supportSegments[newSegment].height) { esi += kMetalSupportSkip; newSegment = esi[segment * 8]; - if (height <= supportSegments[newSegment].height) + if (currentHeight <= supportSegments[newSegment].height) { esi += kMetalSupportSkip; newSegment = esi[segment * 8]; - if (height <= supportSegments[newSegment].height) + if (currentHeight <= supportSegments[newSegment].height) { return false; } @@ -356,7 +356,8 @@ static bool MetalASupportsPaintSetup( uint8_t ebp = esi[segment * 8 + 1]; - auto offset = CoordsXYZ{ kMetalSupportBoundBoxOffsets[segment] + kMetalSupportCrossBeamBoundBoxOffsets[ebp], height }; + auto offset = CoordsXYZ{ kMetalSupportBoundBoxOffsets[segment] + kMetalSupportCrossBeamBoundBoxOffsets[ebp], + currentHeight }; auto boundBoxLength = CoordsXYZ(kMetalSupportCrossBeamBoundBoxLengths[ebp], 1); auto image_id = imageTemplate.WithIndex(kMetalSupportTypeToCrossbeamImages[supportType][ebp]); @@ -364,11 +365,11 @@ static bool MetalASupportsPaintSetup( segment = newSegment; } - int16_t si = height; - if (supportSegments[segment].slope & kTileSlopeAboveTrackOrScenery || height - supportSegments[segment].height < 6 + int16_t si = currentHeight; + if (supportSegments[segment].slope & kTileSlopeAboveTrackOrScenery || currentHeight - supportSegments[segment].height < 6 || kSupportBasesAndBeams[supportType].base == kImageIndexUndefined) { - height = supportSegments[segment].height; + currentHeight = supportSegments[segment].height; } else { @@ -381,18 +382,18 @@ static bool MetalASupportsPaintSetup( PaintAddImageAsParent(session, image_id, { xOffset, yOffset, supportSegments[segment].height }, { 0, 0, 5 }); - height = supportSegments[segment].height + 6; + currentHeight = supportSegments[segment].height + 6; } // Work out if a small support segment required to bring support to normal // size (aka floor2(x, 16)) - int16_t heightDiff = floor2(height + 16, 16); + int16_t heightDiff = floor2(currentHeight + 16, 16); if (heightDiff > si) { heightDiff = si; } - heightDiff -= height; + heightDiff -= currentHeight; if (heightDiff > 0) { @@ -403,10 +404,10 @@ static bool MetalASupportsPaintSetup( imageIndex += heightDiff - 1; auto image_id = imageTemplate.WithIndex(imageIndex); - PaintAddImageAsParent(session, image_id, { xOffset, yOffset, height }, { 0, 0, heightDiff - 1 }); + PaintAddImageAsParent(session, image_id, { xOffset, yOffset, currentHeight }, { 0, 0, heightDiff - 1 }); } - height += heightDiff; + currentHeight += heightDiff; // 6632e6 for (uint8_t count = 0;; count++) @@ -414,13 +415,13 @@ static bool MetalASupportsPaintSetup( if (count >= 4) count = 0; - int16_t beamLength = height + 16; + int16_t beamLength = currentHeight + 16; if (beamLength > si) { beamLength = si; } - beamLength -= height; + beamLength -= currentHeight; if (beamLength <= 0) break; @@ -434,15 +435,15 @@ static bool MetalASupportsPaintSetup( imageIndex++; auto image_id = imageTemplate.WithIndex(imageIndex); - PaintAddImageAsParent(session, image_id, { xOffset, yOffset, height }, { 0, 0, beamLength - 1 }); + PaintAddImageAsParent(session, image_id, { xOffset, yOffset, currentHeight }, { 0, 0, beamLength - 1 }); - height += beamLength; + currentHeight += beamLength; } supportSegments[segment].height = segmentHeight; supportSegments[segment].slope = kTileSlopeAboveTrackOrScenery; - height = originalHeight; + currentHeight = height; segment = originalSegment; if (heightExtra == 0) return true; @@ -450,21 +451,21 @@ static bool MetalASupportsPaintSetup( if (heightExtra < 0) { heightExtra = -heightExtra; - height--; + currentHeight--; } - CoordsXYZ boundBoxOffset = CoordsXYZ(kMetalSupportBoundBoxOffsets[segment], height); - const auto combinedHeight = height + heightExtra; + CoordsXYZ boundBoxOffset = CoordsXYZ(kMetalSupportBoundBoxOffsets[segment], currentHeight); + const auto combinedHeight = currentHeight + heightExtra; while (1) { - int16_t beamLength = height + 16; + int16_t beamLength = currentHeight + 16; if (beamLength > combinedHeight) { beamLength = combinedHeight; } - beamLength -= height; + beamLength -= currentHeight; if (beamLength <= 0) break; @@ -475,9 +476,9 @@ static bool MetalASupportsPaintSetup( imageIndex += beamLength - 1; auto image_id = imageTemplate.WithIndex(imageIndex); - PaintAddImageAsParent(session, image_id, { xOffset, yOffset, height }, { boundBoxOffset, { 0, 0, 0 } }); + PaintAddImageAsParent(session, image_id, { xOffset, yOffset, currentHeight }, { boundBoxOffset, { 0, 0, 0 } }); - height += beamLength; + currentHeight += beamLength; } return true; From de630e167220baa1c7f1c6935cf91691e82481ce Mon Sep 17 00:00:00 2001 From: mix Date: Wed, 9 Jul 2025 01:01:39 +0100 Subject: [PATCH 05/18] Rename baseHeight to currentHeight in MetalBSupportsPaintSetup --- src/openrct2/paint/support/MetalSupports.cpp | 51 ++++++++++---------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/src/openrct2/paint/support/MetalSupports.cpp b/src/openrct2/paint/support/MetalSupports.cpp index 6fc5941852..abbb1f5c74 100644 --- a/src/openrct2/paint/support/MetalSupports.cpp +++ b/src/openrct2/paint/support/MetalSupports.cpp @@ -535,14 +535,14 @@ static bool MetalBSupportsPaintSetup( auto supportType = EnumValue(supportTypeMember); SupportHeight* supportSegments = session.SupportSegments; uint16_t segmentHeight = 0xFFFF; - int32_t baseHeight = height; + int32_t currentHeight = height; if (height < supportSegments[segment].height) { segmentHeight = height; - baseHeight -= kMetalSupportTypeToHeight[supportType]; - if (baseHeight < 0) + currentHeight -= kMetalSupportTypeToHeight[supportType]; + if (currentHeight < 0) { return false; // AND } @@ -550,19 +550,19 @@ static bool MetalBSupportsPaintSetup( uint16_t baseIndex = session.CurrentRotation * 2; uint8_t ebp = kMetalSupportSegmentOffsets[baseIndex + segment * 8]; - if (baseHeight <= supportSegments[ebp].height) + if (currentHeight <= supportSegments[ebp].height) { baseIndex += kMetalSupportSkip; // 9 segments, 4 directions, 2 values uint8_t ebp2 = kMetalSupportSegmentOffsets[baseIndex + segment * 8]; - if (baseHeight <= supportSegments[ebp2].height) + if (currentHeight <= supportSegments[ebp2].height) { baseIndex += kMetalSupportSkip; uint8_t ebp3 = kMetalSupportSegmentOffsets[baseIndex + segment * 8]; - if (baseHeight <= supportSegments[ebp3].height) + if (currentHeight <= supportSegments[ebp3].height) { baseIndex += kMetalSupportSkip; uint8_t ebp4 = kMetalSupportSegmentOffsets[baseIndex + segment * 8]; - if (baseHeight <= supportSegments[ebp4].height) + if (currentHeight <= supportSegments[ebp4].height) { return true; // STC } @@ -578,16 +578,17 @@ static bool MetalBSupportsPaintSetup( PaintAddImageAsParent( session, imageTemplate.WithIndex(kMetalSupportTypeToCrossbeamImages[supportType][ebp]), - { kMetalSupportBoundBoxOffsets[segment] + kMetalSupportCrossBeamBoundBoxOffsets[ebp], baseHeight }, + { kMetalSupportBoundBoxOffsets[segment] + kMetalSupportCrossBeamBoundBoxOffsets[ebp], currentHeight }, { kMetalSupportCrossBeamBoundBoxLengths[ebp], 1 }); } - int32_t si = baseHeight; + int32_t si = currentHeight; - if ((supportSegments[segment].slope & kTileSlopeAboveTrackOrScenery) || (baseHeight - supportSegments[segment].height < 6) + if ((supportSegments[segment].slope & kTileSlopeAboveTrackOrScenery) + || (currentHeight - supportSegments[segment].height < 6) || (kSupportBasesAndBeams[supportType].base == kImageIndexUndefined)) { - baseHeight = supportSegments[segment].height; + currentHeight = supportSegments[segment].height; } else { @@ -598,37 +599,37 @@ static bool MetalBSupportsPaintSetup( session, imageTemplate.WithIndex(imageId), { kMetalSupportBoundBoxOffsets[segment], supportSegments[segment].height }, { 0, 0, 5 }); - baseHeight = supportSegments[segment].height + 6; + currentHeight = supportSegments[segment].height + 6; } - int16_t heightDiff = floor2(baseHeight + 16, 16); + int16_t heightDiff = floor2(currentHeight + 16, 16); if (heightDiff > si) { heightDiff = si; } - heightDiff -= baseHeight; + heightDiff -= currentHeight; if (heightDiff > 0) { PaintAddImageAsParent( session, imageTemplate.WithIndex(kSupportBasesAndBeams[supportType].beamA + (heightDiff - 1)), - { kMetalSupportBoundBoxOffsets[segment], baseHeight }, { 0, 0, heightDiff - 1 }); + { kMetalSupportBoundBoxOffsets[segment], currentHeight }, { 0, 0, heightDiff - 1 }); } - baseHeight += heightDiff; + currentHeight += heightDiff; int16_t endHeight; int32_t i = 1; while (true) { - endHeight = baseHeight + 16; + endHeight = currentHeight + 16; if (endHeight > si) { endHeight = si; } - int16_t beamLength = endHeight - baseHeight; + int16_t beamLength = endHeight - currentHeight; if (beamLength <= 0) { @@ -647,10 +648,10 @@ static bool MetalBSupportsPaintSetup( } PaintAddImageAsParent( - session, imageTemplate.WithIndex(imageId), { kMetalSupportBoundBoxOffsets[segment], baseHeight }, + session, imageTemplate.WithIndex(imageId), { kMetalSupportBoundBoxOffsets[segment], currentHeight }, { 0, 0, beamLength - 1 }); - baseHeight += beamLength; + currentHeight += beamLength; i++; } @@ -659,17 +660,17 @@ static bool MetalBSupportsPaintSetup( if (heightExtra != 0) { - baseHeight = height; + currentHeight = height; const auto si2 = height + heightExtra; while (true) { - endHeight = baseHeight + 16; + endHeight = currentHeight + 16; if (endHeight > si2) { endHeight = si2; } - int16_t beamLength = endHeight - baseHeight; + int16_t beamLength = endHeight - currentHeight; if (beamLength <= 0) { break; @@ -677,9 +678,9 @@ static bool MetalBSupportsPaintSetup( uint32_t imageId = kSupportBasesAndBeams[supportType].beamA + (beamLength - 1); PaintAddImageAsParent( - session, imageTemplate.WithIndex(imageId), { kMetalSupportBoundBoxOffsets[segment], baseHeight }, + session, imageTemplate.WithIndex(imageId), { kMetalSupportBoundBoxOffsets[segment], currentHeight }, { { kMetalSupportBoundBoxOffsets[segment], height }, { 0, 0, 0 } }); - baseHeight += beamLength; + currentHeight += beamLength; } } From d7282e8ab6293a46b0f09af8917f525dadc2e09b Mon Sep 17 00:00:00 2001 From: mix Date: Wed, 9 Jul 2025 01:06:23 +0100 Subject: [PATCH 06/18] Rename MetalSupportsImages beamA and beamB to beamUncapped/Capped --- src/openrct2/paint/support/MetalSupports.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/openrct2/paint/support/MetalSupports.cpp b/src/openrct2/paint/support/MetalSupports.cpp index abbb1f5c74..36a4af2f99 100644 --- a/src/openrct2/paint/support/MetalSupports.cpp +++ b/src/openrct2/paint/support/MetalSupports.cpp @@ -189,8 +189,8 @@ static constexpr uint8_t kMetalSupportTypeToHeight[] = { struct MetalSupportsImages { ImageIndex base; - ImageIndex beamA; - ImageIndex beamB; + ImageIndex beamUncapped; + ImageIndex beamCapped; }; /** rct2: 0x0097B15C, 0x0097B190 */ @@ -400,7 +400,7 @@ static bool MetalASupportsPaintSetup( int8_t xOffset = kMetalSupportBoundBoxOffsets[segment].x; int8_t yOffset = kMetalSupportBoundBoxOffsets[segment].y; - uint32_t imageIndex = kSupportBasesAndBeams[supportType].beamA; + uint32_t imageIndex = kSupportBasesAndBeams[supportType].beamUncapped; imageIndex += heightDiff - 1; auto image_id = imageTemplate.WithIndex(imageIndex); @@ -428,7 +428,7 @@ static bool MetalASupportsPaintSetup( int8_t xOffset = kMetalSupportBoundBoxOffsets[segment].x; int8_t yOffset = kMetalSupportBoundBoxOffsets[segment].y; - uint32_t imageIndex = kSupportBasesAndBeams[supportType].beamA; + uint32_t imageIndex = kSupportBasesAndBeams[supportType].beamUncapped; imageIndex += beamLength - 1; if (count == 3 && beamLength == 0x10) @@ -472,7 +472,7 @@ static bool MetalASupportsPaintSetup( int8_t xOffset = kMetalSupportBoundBoxOffsets[segment].x; int8_t yOffset = kMetalSupportBoundBoxOffsets[segment].y; - auto imageIndex = kSupportBasesAndBeams[supportType].beamB; + auto imageIndex = kSupportBasesAndBeams[supportType].beamCapped; imageIndex += beamLength - 1; auto image_id = imageTemplate.WithIndex(imageIndex); @@ -612,7 +612,7 @@ static bool MetalBSupportsPaintSetup( if (heightDiff > 0) { PaintAddImageAsParent( - session, imageTemplate.WithIndex(kSupportBasesAndBeams[supportType].beamA + (heightDiff - 1)), + session, imageTemplate.WithIndex(kSupportBasesAndBeams[supportType].beamUncapped + (heightDiff - 1)), { kMetalSupportBoundBoxOffsets[segment], currentHeight }, { 0, 0, heightDiff - 1 }); } @@ -636,7 +636,7 @@ static bool MetalBSupportsPaintSetup( break; } - uint32_t imageId = kSupportBasesAndBeams[supportType].beamA + (beamLength - 1); + uint32_t imageId = kSupportBasesAndBeams[supportType].beamUncapped + (beamLength - 1); if (i % 4 == 0) { @@ -676,7 +676,7 @@ static bool MetalBSupportsPaintSetup( break; } - uint32_t imageId = kSupportBasesAndBeams[supportType].beamA + (beamLength - 1); + uint32_t imageId = kSupportBasesAndBeams[supportType].beamUncapped + (beamLength - 1); PaintAddImageAsParent( session, imageTemplate.WithIndex(imageId), { kMetalSupportBoundBoxOffsets[segment], currentHeight }, { { kMetalSupportBoundBoxOffsets[segment], height }, { 0, 0, 0 } }); From 199d9893c9abd37331914c707d8942861d489413 Mon Sep 17 00:00:00 2001 From: mix Date: Wed, 9 Jul 2025 01:10:19 +0100 Subject: [PATCH 07/18] Unify metal support type a and b extra height drawing --- src/openrct2/paint/support/MetalSupports.cpp | 72 ++++++-------------- 1 file changed, 21 insertions(+), 51 deletions(-) diff --git a/src/openrct2/paint/support/MetalSupports.cpp b/src/openrct2/paint/support/MetalSupports.cpp index 36a4af2f99..f3272fb083 100644 --- a/src/openrct2/paint/support/MetalSupports.cpp +++ b/src/openrct2/paint/support/MetalSupports.cpp @@ -443,40 +443,19 @@ static bool MetalASupportsPaintSetup( supportSegments[segment].height = segmentHeight; supportSegments[segment].slope = kTileSlopeAboveTrackOrScenery; - currentHeight = height; - segment = originalSegment; - if (heightExtra == 0) - return true; - - if (heightExtra < 0) + // Draw extra support segments above height with a zero height bounding box + currentHeight = heightExtra < 0 ? height - 1 : height; + const auto totalHeightExtra = heightExtra < 0 ? currentHeight + (-heightExtra) : currentHeight + heightExtra; + const CoordsXYZ boundBoxOffset = CoordsXYZ(kMetalSupportBoundBoxOffsets[originalSegment], currentHeight); + while (true) { - heightExtra = -heightExtra; - currentHeight--; - } - - CoordsXYZ boundBoxOffset = CoordsXYZ(kMetalSupportBoundBoxOffsets[segment], currentHeight); - const auto combinedHeight = currentHeight + heightExtra; - - while (1) - { - int16_t beamLength = currentHeight + 16; - if (beamLength > combinedHeight) - { - beamLength = combinedHeight; - } - - beamLength -= currentHeight; + const int16_t beamLength = std::min(currentHeight + 16, totalHeightExtra) - currentHeight; if (beamLength <= 0) break; - int8_t xOffset = kMetalSupportBoundBoxOffsets[segment].x; - int8_t yOffset = kMetalSupportBoundBoxOffsets[segment].y; - - auto imageIndex = kSupportBasesAndBeams[supportType].beamCapped; - imageIndex += beamLength - 1; - auto image_id = imageTemplate.WithIndex(imageIndex); - - PaintAddImageAsParent(session, image_id, { xOffset, yOffset, currentHeight }, { boundBoxOffset, { 0, 0, 0 } }); + PaintAddImageAsParent( + session, imageTemplate.WithIndex(kSupportBasesAndBeams[supportType].beamCapped + beamLength - 1), + { kMetalSupportBoundBoxOffsets[originalSegment], currentHeight }, { boundBoxOffset, { 0, 0, 0 } }); currentHeight += beamLength; } @@ -658,30 +637,21 @@ static bool MetalBSupportsPaintSetup( supportSegments[segment].height = segmentHeight; supportSegments[segment].slope = kTileSlopeAboveTrackOrScenery; - if (heightExtra != 0) + // Draw extra support segments above height with a zero height bounding box + currentHeight = heightExtra < 0 ? height - 1 : height; + const auto totalHeightExtra = heightExtra < 0 ? currentHeight + (-heightExtra) : currentHeight + heightExtra; + const CoordsXYZ boundBoxOffset = CoordsXYZ(kMetalSupportBoundBoxOffsets[segment], currentHeight); + while (true) { - currentHeight = height; - const auto si2 = height + heightExtra; - while (true) - { - endHeight = currentHeight + 16; - if (endHeight > si2) - { - endHeight = si2; - } + const int16_t beamLength = std::min(currentHeight + 16, totalHeightExtra) - currentHeight; + if (beamLength <= 0) + break; - int16_t beamLength = endHeight - currentHeight; - if (beamLength <= 0) - { - break; - } + PaintAddImageAsParent( + session, imageTemplate.WithIndex(kSupportBasesAndBeams[supportType].beamCapped + beamLength - 1), + { kMetalSupportBoundBoxOffsets[segment], currentHeight }, { boundBoxOffset, { 0, 0, 0 } }); - uint32_t imageId = kSupportBasesAndBeams[supportType].beamUncapped + (beamLength - 1); - PaintAddImageAsParent( - session, imageTemplate.WithIndex(imageId), { kMetalSupportBoundBoxOffsets[segment], currentHeight }, - { { kMetalSupportBoundBoxOffsets[segment], height }, { 0, 0, 0 } }); - currentHeight += beamLength; - } + currentHeight += beamLength; } return false; // AND From 72d7fbd81b26001dac1a98fff0600a834d049bb2 Mon Sep 17 00:00:00 2001 From: mix Date: Wed, 9 Jul 2025 01:13:17 +0100 Subject: [PATCH 08/18] Rename si to crossbeamHeight in metal support paint functions --- src/openrct2/paint/support/MetalSupports.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/openrct2/paint/support/MetalSupports.cpp b/src/openrct2/paint/support/MetalSupports.cpp index f3272fb083..ecaf71824f 100644 --- a/src/openrct2/paint/support/MetalSupports.cpp +++ b/src/openrct2/paint/support/MetalSupports.cpp @@ -365,7 +365,7 @@ static bool MetalASupportsPaintSetup( segment = newSegment; } - int16_t si = currentHeight; + const int16_t crossbeamHeight = currentHeight; if (supportSegments[segment].slope & kTileSlopeAboveTrackOrScenery || currentHeight - supportSegments[segment].height < 6 || kSupportBasesAndBeams[supportType].base == kImageIndexUndefined) { @@ -388,9 +388,9 @@ static bool MetalASupportsPaintSetup( // Work out if a small support segment required to bring support to normal // size (aka floor2(x, 16)) int16_t heightDiff = floor2(currentHeight + 16, 16); - if (heightDiff > si) + if (heightDiff > crossbeamHeight) { - heightDiff = si; + heightDiff = crossbeamHeight; } heightDiff -= currentHeight; @@ -416,9 +416,9 @@ static bool MetalASupportsPaintSetup( count = 0; int16_t beamLength = currentHeight + 16; - if (beamLength > si) + if (beamLength > crossbeamHeight) { - beamLength = si; + beamLength = crossbeamHeight; } beamLength -= currentHeight; @@ -561,7 +561,7 @@ static bool MetalBSupportsPaintSetup( { kMetalSupportCrossBeamBoundBoxLengths[ebp], 1 }); } - int32_t si = currentHeight; + const int32_t crossbeamHeight = currentHeight; if ((supportSegments[segment].slope & kTileSlopeAboveTrackOrScenery) || (currentHeight - supportSegments[segment].height < 6) @@ -582,9 +582,9 @@ static bool MetalBSupportsPaintSetup( } int16_t heightDiff = floor2(currentHeight + 16, 16); - if (heightDiff > si) + if (heightDiff > crossbeamHeight) { - heightDiff = si; + heightDiff = crossbeamHeight; } heightDiff -= currentHeight; @@ -603,9 +603,9 @@ static bool MetalBSupportsPaintSetup( while (true) { endHeight = currentHeight + 16; - if (endHeight > si) + if (endHeight > crossbeamHeight) { - endHeight = si; + endHeight = crossbeamHeight; } int16_t beamLength = endHeight - currentHeight; From 234631c32cad80ecc362f06700a41e58949926bc Mon Sep 17 00:00:00 2001 From: mix Date: Wed, 9 Jul 2025 01:15:20 +0100 Subject: [PATCH 09/18] Unify metal support type a and b main segment drawing --- src/openrct2/paint/support/MetalSupports.cpp | 64 ++++++-------------- 1 file changed, 18 insertions(+), 46 deletions(-) diff --git a/src/openrct2/paint/support/MetalSupports.cpp b/src/openrct2/paint/support/MetalSupports.cpp index ecaf71824f..efa02f00bb 100644 --- a/src/openrct2/paint/support/MetalSupports.cpp +++ b/src/openrct2/paint/support/MetalSupports.cpp @@ -408,34 +408,23 @@ static bool MetalASupportsPaintSetup( } currentHeight += heightDiff; - // 6632e6 - for (uint8_t count = 0;; count++) + const auto supportBeamImageIndex = kSupportBasesAndBeams[supportType].beamUncapped; + + // Draw main support segments + for (uint8_t count = 1;; count++) { - if (count >= 4) - count = 0; - - int16_t beamLength = currentHeight + 16; - if (beamLength > crossbeamHeight) - { - beamLength = crossbeamHeight; - } - - beamLength -= currentHeight; + const int16_t beamLength = std::min(currentHeight + 16, crossbeamHeight) - currentHeight; if (beamLength <= 0) break; - int8_t xOffset = kMetalSupportBoundBoxOffsets[segment].x; - int8_t yOffset = kMetalSupportBoundBoxOffsets[segment].y; - - uint32_t imageIndex = kSupportBasesAndBeams[supportType].beamUncapped; - imageIndex += beamLength - 1; - - if (count == 3 && beamLength == 0x10) + uint32_t imageIndex = supportBeamImageIndex + beamLength - 1; + if (count % 4 == 0 && beamLength == 16) imageIndex++; - auto image_id = imageTemplate.WithIndex(imageIndex); - PaintAddImageAsParent(session, image_id, { xOffset, yOffset, currentHeight }, { 0, 0, beamLength - 1 }); + PaintAddImageAsParent( + session, imageTemplate.WithIndex(imageIndex), { kMetalSupportBoundBoxOffsets[segment], currentHeight }, + { 0, 0, beamLength - 1 }); currentHeight += beamLength; } @@ -597,41 +586,24 @@ static bool MetalBSupportsPaintSetup( currentHeight += heightDiff; - int16_t endHeight; + const auto supportBeamImageIndex = kSupportBasesAndBeams[supportType].beamUncapped; - int32_t i = 1; - while (true) + // Draw main support segments + for (uint8_t count = 1;; count++) { - endHeight = currentHeight + 16; - if (endHeight > crossbeamHeight) - { - endHeight = crossbeamHeight; - } - - int16_t beamLength = endHeight - currentHeight; - + const int16_t beamLength = std::min(currentHeight + 16, crossbeamHeight) - currentHeight; if (beamLength <= 0) - { break; - } - uint32_t imageId = kSupportBasesAndBeams[supportType].beamUncapped + (beamLength - 1); - - if (i % 4 == 0) - { - // Each fourth run, draw a special image - if (beamLength == 16) - { - imageId += 1; - } - } + uint32_t imageIndex = supportBeamImageIndex + beamLength - 1; + if (count % 4 == 0 && beamLength == 16) + imageIndex++; PaintAddImageAsParent( - session, imageTemplate.WithIndex(imageId), { kMetalSupportBoundBoxOffsets[segment], currentHeight }, + session, imageTemplate.WithIndex(imageIndex), { kMetalSupportBoundBoxOffsets[segment], currentHeight }, { 0, 0, beamLength - 1 }); currentHeight += beamLength; - i++; } supportSegments[segment].height = segmentHeight; From 2380e151ab6055e5002ccdc2f57c8529100184de Mon Sep 17 00:00:00 2001 From: mix Date: Wed, 9 Jul 2025 01:18:54 +0100 Subject: [PATCH 10/18] Unify metal support type a and b base to main segment drawing --- src/openrct2/paint/support/MetalSupports.cpp | 38 ++++++-------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/src/openrct2/paint/support/MetalSupports.cpp b/src/openrct2/paint/support/MetalSupports.cpp index efa02f00bb..380b3b9ce2 100644 --- a/src/openrct2/paint/support/MetalSupports.cpp +++ b/src/openrct2/paint/support/MetalSupports.cpp @@ -385,32 +385,19 @@ static bool MetalASupportsPaintSetup( currentHeight = supportSegments[segment].height + 6; } - // Work out if a small support segment required to bring support to normal - // size (aka floor2(x, 16)) - int16_t heightDiff = floor2(currentHeight + 16, 16); - if (heightDiff > crossbeamHeight) - { - heightDiff = crossbeamHeight; - } - - heightDiff -= currentHeight; + const auto supportBeamImageIndex = kSupportBasesAndBeams[supportType].beamUncapped; + // Draw an initial support segment to get the main segment height to a multiple of 16 + const int16_t heightDiff = std::min(floor2(currentHeight + 16, 16), crossbeamHeight) - currentHeight; if (heightDiff > 0) { - int8_t xOffset = kMetalSupportBoundBoxOffsets[segment].x; - int8_t yOffset = kMetalSupportBoundBoxOffsets[segment].y; - - uint32_t imageIndex = kSupportBasesAndBeams[supportType].beamUncapped; - imageIndex += heightDiff - 1; - auto image_id = imageTemplate.WithIndex(imageIndex); - - PaintAddImageAsParent(session, image_id, { xOffset, yOffset, currentHeight }, { 0, 0, heightDiff - 1 }); + PaintAddImageAsParent( + session, imageTemplate.WithIndex(supportBeamImageIndex + heightDiff - 1), + { kMetalSupportBoundBoxOffsets[segment], currentHeight }, { 0, 0, heightDiff - 1 }); } currentHeight += heightDiff; - const auto supportBeamImageIndex = kSupportBasesAndBeams[supportType].beamUncapped; - // Draw main support segments for (uint8_t count = 1;; count++) { @@ -570,24 +557,19 @@ static bool MetalBSupportsPaintSetup( currentHeight = supportSegments[segment].height + 6; } - int16_t heightDiff = floor2(currentHeight + 16, 16); - if (heightDiff > crossbeamHeight) - { - heightDiff = crossbeamHeight; - } + const auto supportBeamImageIndex = kSupportBasesAndBeams[supportType].beamUncapped; - heightDiff -= currentHeight; + // Draw an initial support segment to get the main segment height to a multiple of 16 + const int16_t heightDiff = std::min(floor2(currentHeight + 16, 16), crossbeamHeight) - currentHeight; if (heightDiff > 0) { PaintAddImageAsParent( - session, imageTemplate.WithIndex(kSupportBasesAndBeams[supportType].beamUncapped + (heightDiff - 1)), + session, imageTemplate.WithIndex(supportBeamImageIndex + heightDiff - 1), { kMetalSupportBoundBoxOffsets[segment], currentHeight }, { 0, 0, heightDiff - 1 }); } currentHeight += heightDiff; - const auto supportBeamImageIndex = kSupportBasesAndBeams[supportType].beamUncapped; - // Draw main support segments for (uint8_t count = 1;; count++) { From 1455f7bf5e28b26d1ff63955985ce2e75f659a49 Mon Sep 17 00:00:00 2001 From: mix Date: Wed, 9 Jul 2025 01:25:38 +0100 Subject: [PATCH 11/18] Unify metal support type a and b base drawing --- src/openrct2/paint/support/MetalSupports.cpp | 40 ++++++++++---------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/openrct2/paint/support/MetalSupports.cpp b/src/openrct2/paint/support/MetalSupports.cpp index 380b3b9ce2..e1a1edf377 100644 --- a/src/openrct2/paint/support/MetalSupports.cpp +++ b/src/openrct2/paint/support/MetalSupports.cpp @@ -281,6 +281,8 @@ constexpr MetalSupportGraphic kMetalSupportGraphicRotated[kMetalSupportTypeCount MetalSupportGraphic::boxedCoated }, }; +constexpr const int32_t kMetalSupportBaseHeight = 6; + static bool MetalASupportsPaintSetup( PaintSession& session, MetalSupportGraphic supportTypeMember, MetalSupportPlace placement, int32_t heightExtra, int32_t height, ImageId imageTemplate); @@ -366,23 +368,23 @@ static bool MetalASupportsPaintSetup( segment = newSegment; } const int16_t crossbeamHeight = currentHeight; - if (supportSegments[segment].slope & kTileSlopeAboveTrackOrScenery || currentHeight - supportSegments[segment].height < 6 + + // Draw support bases + if (supportSegments[segment].slope & kTileSlopeAboveTrackOrScenery + || currentHeight - supportSegments[segment].height < kMetalSupportBaseHeight || kSupportBasesAndBeams[supportType].base == kImageIndexUndefined) { currentHeight = supportSegments[segment].height; } else { - int8_t xOffset = kMetalSupportBoundBoxOffsets[segment].x; - int8_t yOffset = kMetalSupportBoundBoxOffsets[segment].y; + const auto imageIndex = kSupportBasesAndBeams[supportType].base + + kMetalSupportsSlopeImageOffsetMap[supportSegments[segment].slope & kTileSlopeMask]; + PaintAddImageAsParent( + session, imageTemplate.WithIndex(imageIndex), + { kMetalSupportBoundBoxOffsets[segment], supportSegments[segment].height }, { 0, 0, kMetalSupportBaseHeight - 1 }); - auto imageIndex = kSupportBasesAndBeams[supportType].base; - imageIndex += kMetalSupportsSlopeImageOffsetMap[supportSegments[segment].slope & kTileSlopeMask]; - auto image_id = imageTemplate.WithIndex(imageIndex); - - PaintAddImageAsParent(session, image_id, { xOffset, yOffset, supportSegments[segment].height }, { 0, 0, 5 }); - - currentHeight = supportSegments[segment].height + 6; + currentHeight = supportSegments[segment].height + kMetalSupportBaseHeight; } const auto supportBeamImageIndex = kSupportBasesAndBeams[supportType].beamUncapped; @@ -539,22 +541,22 @@ static bool MetalBSupportsPaintSetup( const int32_t crossbeamHeight = currentHeight; - if ((supportSegments[segment].slope & kTileSlopeAboveTrackOrScenery) - || (currentHeight - supportSegments[segment].height < 6) - || (kSupportBasesAndBeams[supportType].base == kImageIndexUndefined)) + // Draw support bases + if (supportSegments[segment].slope & kTileSlopeAboveTrackOrScenery + || currentHeight - supportSegments[segment].height < kMetalSupportBaseHeight + || kSupportBasesAndBeams[supportType].base == kImageIndexUndefined) { currentHeight = supportSegments[segment].height; } else { - uint32_t imageOffset = kMetalSupportsSlopeImageOffsetMap[supportSegments[segment].slope & kTileSlopeMask]; - uint32_t imageId = kSupportBasesAndBeams[supportType].base + imageOffset; - + const auto imageIndex = kSupportBasesAndBeams[supportType].base + + kMetalSupportsSlopeImageOffsetMap[supportSegments[segment].slope & kTileSlopeMask]; PaintAddImageAsParent( - session, imageTemplate.WithIndex(imageId), - { kMetalSupportBoundBoxOffsets[segment], supportSegments[segment].height }, { 0, 0, 5 }); + session, imageTemplate.WithIndex(imageIndex), + { kMetalSupportBoundBoxOffsets[segment], supportSegments[segment].height }, { 0, 0, kMetalSupportBaseHeight - 1 }); - currentHeight = supportSegments[segment].height + 6; + currentHeight = supportSegments[segment].height + kMetalSupportBaseHeight; } const auto supportBeamImageIndex = kSupportBasesAndBeams[supportType].beamUncapped; From c3cd9da819f86aeabff328151b59f7a8dd0ff353 Mon Sep 17 00:00:00 2001 From: mix Date: Wed, 9 Jul 2025 01:32:56 +0100 Subject: [PATCH 12/18] Unify metal support type a and b function start setup --- src/openrct2/paint/support/MetalSupports.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/openrct2/paint/support/MetalSupports.cpp b/src/openrct2/paint/support/MetalSupports.cpp index e1a1edf377..285b7ba9fe 100644 --- a/src/openrct2/paint/support/MetalSupports.cpp +++ b/src/openrct2/paint/support/MetalSupports.cpp @@ -318,13 +318,13 @@ static bool MetalASupportsPaintSetup( imageTemplate = ImageId(0).WithTransparency(FilterPaletteID::PaletteDarken1); } - uint8_t segment = EnumValue(placement); - auto supportType = EnumValue(supportTypeMember); - SupportHeight* supportSegments = session.SupportSegments; int32_t currentHeight = height; - const auto originalSegment = segment; + const uint32_t supportType = EnumValue(supportTypeMember); + const uint8_t originalSegment = EnumValue(placement); + uint8_t segment = originalSegment; uint16_t segmentHeight = 0xFFFF; + SupportHeight* const supportSegments = session.SupportSegments; if (currentHeight < supportSegments[segment].height) { segmentHeight = currentHeight; @@ -476,7 +476,7 @@ static bool MetalBSupportsPaintSetup( { if (!(session.Flags & PaintSessionFlags::PassedSurface)) { - return false; // AND + return false; } if (session.ViewFlags & VIEWPORT_FLAG_HIDE_SUPPORTS) @@ -488,12 +488,13 @@ static bool MetalBSupportsPaintSetup( imageTemplate = ImageId(0).WithTransparency(FilterPaletteID::PaletteDarken1); } - const uint8_t segment = EnumValue(placement); - auto supportType = EnumValue(supportTypeMember); - SupportHeight* supportSegments = session.SupportSegments; - uint16_t segmentHeight = 0xFFFF; int32_t currentHeight = height; + const uint32_t supportType = EnumValue(supportTypeMember); + const uint8_t originalSegment = EnumValue(placement); + uint8_t segment = originalSegment; + uint16_t segmentHeight = 0xFFFF; + SupportHeight* const supportSegments = session.SupportSegments; if (height < supportSegments[segment].height) { segmentHeight = height; From 241bd81b836b6716fa71e3a74438ec5a50be5476 Mon Sep 17 00:00:00 2001 From: mix Date: Wed, 9 Jul 2025 01:36:19 +0100 Subject: [PATCH 13/18] Unify metal support type a and b offsetting and crossbeam drawing --- src/openrct2/paint/support/MetalSupports.cpp | 78 ++++++++++---------- 1 file changed, 38 insertions(+), 40 deletions(-) diff --git a/src/openrct2/paint/support/MetalSupports.cpp b/src/openrct2/paint/support/MetalSupports.cpp index 285b7ba9fe..6a624f6888 100644 --- a/src/openrct2/paint/support/MetalSupports.cpp +++ b/src/openrct2/paint/support/MetalSupports.cpp @@ -321,6 +321,7 @@ static bool MetalASupportsPaintSetup( int32_t currentHeight = height; const uint32_t supportType = EnumValue(supportTypeMember); + // Offset the support and draw a crossbeam if necessary const uint8_t originalSegment = EnumValue(placement); uint8_t segment = originalSegment; uint16_t segmentHeight = 0xFFFF; @@ -333,21 +334,20 @@ static bool MetalASupportsPaintSetup( if (currentHeight < 0) return false; - const uint8_t* esi = &(kMetalSupportSegmentOffsets[session.CurrentRotation * 2]); - - uint8_t newSegment = esi[segment * 8]; + uint16_t baseIndex = session.CurrentRotation * 2; + uint8_t newSegment = kMetalSupportSegmentOffsets[baseIndex + segment * 8]; if (currentHeight <= supportSegments[newSegment].height) { - esi += kMetalSupportSkip; - newSegment = esi[segment * 8]; + baseIndex += kMetalSupportSkip; + newSegment = kMetalSupportSegmentOffsets[baseIndex + segment * 8]; if (currentHeight <= supportSegments[newSegment].height) { - esi += kMetalSupportSkip; - newSegment = esi[segment * 8]; + baseIndex += kMetalSupportSkip; + newSegment = kMetalSupportSegmentOffsets[baseIndex + segment * 8]; if (currentHeight <= supportSegments[newSegment].height) { - esi += kMetalSupportSkip; - newSegment = esi[segment * 8]; + baseIndex += kMetalSupportSkip; + newSegment = kMetalSupportSegmentOffsets[baseIndex + segment * 8]; if (currentHeight <= supportSegments[newSegment].height) { return false; @@ -356,17 +356,16 @@ static bool MetalASupportsPaintSetup( } } - uint8_t ebp = esi[segment * 8 + 1]; + const uint8_t crossBeamIndex = kMetalSupportSegmentOffsets[baseIndex + segment * 8 + 1]; - auto offset = CoordsXYZ{ kMetalSupportBoundBoxOffsets[segment] + kMetalSupportCrossBeamBoundBoxOffsets[ebp], - currentHeight }; - auto boundBoxLength = CoordsXYZ(kMetalSupportCrossBeamBoundBoxLengths[ebp], 1); - - auto image_id = imageTemplate.WithIndex(kMetalSupportTypeToCrossbeamImages[supportType][ebp]); - PaintAddImageAsParent(session, image_id, offset, boundBoxLength); + PaintAddImageAsParent( + session, imageTemplate.WithIndex(kMetalSupportTypeToCrossbeamImages[supportType][crossBeamIndex]), + { kMetalSupportBoundBoxOffsets[segment] + kMetalSupportCrossBeamBoundBoxOffsets[crossBeamIndex], currentHeight }, + { kMetalSupportCrossBeamBoundBoxLengths[crossBeamIndex], 1 }); segment = newSegment; } + const int16_t crossbeamHeight = currentHeight; // Draw support bases @@ -491,53 +490,52 @@ static bool MetalBSupportsPaintSetup( int32_t currentHeight = height; const uint32_t supportType = EnumValue(supportTypeMember); + // Offset the support and draw a crossbeam if necessary const uint8_t originalSegment = EnumValue(placement); uint8_t segment = originalSegment; uint16_t segmentHeight = 0xFFFF; SupportHeight* const supportSegments = session.SupportSegments; - if (height < supportSegments[segment].height) + if (currentHeight < supportSegments[segment].height) { - segmentHeight = height; + segmentHeight = currentHeight; currentHeight -= kMetalSupportTypeToHeight[supportType]; if (currentHeight < 0) - { - return false; // AND - } + return false; uint16_t baseIndex = session.CurrentRotation * 2; - - uint8_t ebp = kMetalSupportSegmentOffsets[baseIndex + segment * 8]; - if (currentHeight <= supportSegments[ebp].height) + uint8_t newSegment = kMetalSupportSegmentOffsets[baseIndex + segment * 8]; + if (currentHeight <= supportSegments[newSegment].height) { - baseIndex += kMetalSupportSkip; // 9 segments, 4 directions, 2 values - uint8_t ebp2 = kMetalSupportSegmentOffsets[baseIndex + segment * 8]; - if (currentHeight <= supportSegments[ebp2].height) + baseIndex += kMetalSupportSkip; + newSegment = kMetalSupportSegmentOffsets[baseIndex + segment * 8]; + if (currentHeight <= supportSegments[newSegment].height) { baseIndex += kMetalSupportSkip; - uint8_t ebp3 = kMetalSupportSegmentOffsets[baseIndex + segment * 8]; - if (currentHeight <= supportSegments[ebp3].height) + newSegment = kMetalSupportSegmentOffsets[baseIndex + segment * 8]; + if (currentHeight <= supportSegments[newSegment].height) { baseIndex += kMetalSupportSkip; - uint8_t ebp4 = kMetalSupportSegmentOffsets[baseIndex + segment * 8]; - if (currentHeight <= supportSegments[ebp4].height) + newSegment = kMetalSupportSegmentOffsets[baseIndex + segment * 8]; + if (currentHeight <= supportSegments[newSegment].height) { - return true; // STC + return false; } } } } - ebp = kMetalSupportSegmentOffsets[baseIndex + segment * 8 + 1]; - if (ebp >= 4) - { - return true; // STC - } + const uint8_t crossBeamIndex = kMetalSupportSegmentOffsets[baseIndex + segment * 8 + 1]; + + if (crossBeamIndex >= 4) + return false; PaintAddImageAsParent( - session, imageTemplate.WithIndex(kMetalSupportTypeToCrossbeamImages[supportType][ebp]), - { kMetalSupportBoundBoxOffsets[segment] + kMetalSupportCrossBeamBoundBoxOffsets[ebp], currentHeight }, - { kMetalSupportCrossBeamBoundBoxLengths[ebp], 1 }); + session, imageTemplate.WithIndex(kMetalSupportTypeToCrossbeamImages[supportType][crossBeamIndex]), + { kMetalSupportBoundBoxOffsets[segment] + kMetalSupportCrossBeamBoundBoxOffsets[crossBeamIndex], currentHeight }, + { kMetalSupportCrossBeamBoundBoxLengths[crossBeamIndex], 1 }); + + segment = newSegment; } const int32_t crossbeamHeight = currentHeight; From ef224b49339a21274ad46057cd2df535ba886aa5 Mon Sep 17 00:00:00 2001 From: mix Date: Wed, 9 Jul 2025 01:42:08 +0100 Subject: [PATCH 14/18] Combine type a and b metal support paint functions to single function --- src/openrct2/paint/support/MetalSupports.cpp | 202 ++----------------- 1 file changed, 20 insertions(+), 182 deletions(-) diff --git a/src/openrct2/paint/support/MetalSupports.cpp b/src/openrct2/paint/support/MetalSupports.cpp index 6a624f6888..37941d9369 100644 --- a/src/openrct2/paint/support/MetalSupports.cpp +++ b/src/openrct2/paint/support/MetalSupports.cpp @@ -283,26 +283,12 @@ constexpr MetalSupportGraphic kMetalSupportGraphicRotated[kMetalSupportTypeCount constexpr const int32_t kMetalSupportBaseHeight = 6; -static bool MetalASupportsPaintSetup( - PaintSession& session, MetalSupportGraphic supportTypeMember, MetalSupportPlace placement, int32_t heightExtra, - int32_t height, ImageId imageTemplate); -static bool MetalBSupportsPaintSetup( - PaintSession& session, MetalSupportGraphic supportTypeMember, MetalSupportPlace placement, int32_t heightExtra, - int32_t height, ImageId imageTemplate); static inline MetalSupportGraphic RotateMetalSupportGraphic(MetalSupportType supportType, Direction direction); -/** - * Metal pole supports - * @param supportType (edi) - * @param segment (ebx) - * @param heightExtra (ax) - * @param height (edx) - * @param imageTemplate (ebp) - * rct2: 0x00663105 - */ -static bool MetalASupportsPaintSetup( - PaintSession& session, const MetalSupportGraphic supportTypeMember, const MetalSupportPlace placement, int32_t heightExtra, - const int32_t height, ImageId imageTemplate) +template +static bool MetalSupportsPaintSetupCommon( + PaintSession& session, const MetalSupportGraphic supportTypeMember, const MetalSupportPlace placement, + const int32_t heightExtra, const int32_t height, ImageId imageTemplate) { if (!(session.Flags & PaintSessionFlags::PassedSurface)) { @@ -357,6 +343,11 @@ static bool MetalASupportsPaintSetup( } const uint8_t crossBeamIndex = kMetalSupportSegmentOffsets[baseIndex + segment * 8 + 1]; + if constexpr (typeB) + { + if (crossBeamIndex >= 4) + return false; + } PaintAddImageAsParent( session, imageTemplate.WithIndex(kMetalSupportTypeToCrossbeamImages[supportType][crossBeamIndex]), @@ -422,6 +413,8 @@ static bool MetalASupportsPaintSetup( // Draw extra support segments above height with a zero height bounding box currentHeight = heightExtra < 0 ? height - 1 : height; + const auto extraSupportBeamImageIndex = typeB ? kSupportBasesAndBeams[supportType].beamUncapped + : kSupportBasesAndBeams[supportType].beamCapped; const auto totalHeightExtra = heightExtra < 0 ? currentHeight + (-heightExtra) : currentHeight + heightExtra; const CoordsXYZ boundBoxOffset = CoordsXYZ(kMetalSupportBoundBoxOffsets[originalSegment], currentHeight); while (true) @@ -431,7 +424,7 @@ static bool MetalASupportsPaintSetup( break; PaintAddImageAsParent( - session, imageTemplate.WithIndex(kSupportBasesAndBeams[supportType].beamCapped + beamLength - 1), + session, imageTemplate.WithIndex(extraSupportBeamImageIndex + beamLength - 1), { kMetalSupportBoundBoxOffsets[originalSegment], currentHeight }, { boundBoxOffset, { 0, 0, 0 } }); currentHeight += beamLength; @@ -445,7 +438,7 @@ bool MetalASupportsPaintSetup( ImageId imageTemplate) { auto supportGraphic = RotateMetalSupportGraphic(supportType, 0); - return MetalASupportsPaintSetup(session, supportGraphic, placement, heightExtra, height, imageTemplate); + return MetalSupportsPaintSetupCommon(session, supportGraphic, placement, heightExtra, height, imageTemplate); } bool MetalASupportsPaintSetupRotated( @@ -454,162 +447,7 @@ bool MetalASupportsPaintSetupRotated( { auto supportGraphic = RotateMetalSupportGraphic(supportType, direction); placement = kMetalSupportPlacementRotated[EnumValue(placement)][direction]; - return MetalASupportsPaintSetup(session, supportGraphic, placement, heightExtra, height, imageTemplate); -} - -/** - * Metal pole supports - * rct2: 0x00663584 - * - * @param supportType (edi) - * @param segment (ebx) - * @param heightExtra (ax) - * @param height (edx) - * @param imageTemplate (ebp) - * - * @return (Carry Flag) - */ -static bool MetalBSupportsPaintSetup( - PaintSession& session, const MetalSupportGraphic supportTypeMember, const MetalSupportPlace placement, - const int32_t heightExtra, const int32_t height, ImageId imageTemplate) -{ - if (!(session.Flags & PaintSessionFlags::PassedSurface)) - { - return false; - } - - if (session.ViewFlags & VIEWPORT_FLAG_HIDE_SUPPORTS) - { - if (session.ViewFlags & VIEWPORT_FLAG_INVISIBLE_SUPPORTS) - { - return false; - } - imageTemplate = ImageId(0).WithTransparency(FilterPaletteID::PaletteDarken1); - } - - int32_t currentHeight = height; - const uint32_t supportType = EnumValue(supportTypeMember); - - // Offset the support and draw a crossbeam if necessary - const uint8_t originalSegment = EnumValue(placement); - uint8_t segment = originalSegment; - uint16_t segmentHeight = 0xFFFF; - SupportHeight* const supportSegments = session.SupportSegments; - if (currentHeight < supportSegments[segment].height) - { - segmentHeight = currentHeight; - - currentHeight -= kMetalSupportTypeToHeight[supportType]; - if (currentHeight < 0) - return false; - - uint16_t baseIndex = session.CurrentRotation * 2; - uint8_t newSegment = kMetalSupportSegmentOffsets[baseIndex + segment * 8]; - if (currentHeight <= supportSegments[newSegment].height) - { - baseIndex += kMetalSupportSkip; - newSegment = kMetalSupportSegmentOffsets[baseIndex + segment * 8]; - if (currentHeight <= supportSegments[newSegment].height) - { - baseIndex += kMetalSupportSkip; - newSegment = kMetalSupportSegmentOffsets[baseIndex + segment * 8]; - if (currentHeight <= supportSegments[newSegment].height) - { - baseIndex += kMetalSupportSkip; - newSegment = kMetalSupportSegmentOffsets[baseIndex + segment * 8]; - if (currentHeight <= supportSegments[newSegment].height) - { - return false; - } - } - } - } - - const uint8_t crossBeamIndex = kMetalSupportSegmentOffsets[baseIndex + segment * 8 + 1]; - - if (crossBeamIndex >= 4) - return false; - - PaintAddImageAsParent( - session, imageTemplate.WithIndex(kMetalSupportTypeToCrossbeamImages[supportType][crossBeamIndex]), - { kMetalSupportBoundBoxOffsets[segment] + kMetalSupportCrossBeamBoundBoxOffsets[crossBeamIndex], currentHeight }, - { kMetalSupportCrossBeamBoundBoxLengths[crossBeamIndex], 1 }); - - segment = newSegment; - } - - const int32_t crossbeamHeight = currentHeight; - - // Draw support bases - if (supportSegments[segment].slope & kTileSlopeAboveTrackOrScenery - || currentHeight - supportSegments[segment].height < kMetalSupportBaseHeight - || kSupportBasesAndBeams[supportType].base == kImageIndexUndefined) - { - currentHeight = supportSegments[segment].height; - } - else - { - const auto imageIndex = kSupportBasesAndBeams[supportType].base - + kMetalSupportsSlopeImageOffsetMap[supportSegments[segment].slope & kTileSlopeMask]; - PaintAddImageAsParent( - session, imageTemplate.WithIndex(imageIndex), - { kMetalSupportBoundBoxOffsets[segment], supportSegments[segment].height }, { 0, 0, kMetalSupportBaseHeight - 1 }); - - currentHeight = supportSegments[segment].height + kMetalSupportBaseHeight; - } - - const auto supportBeamImageIndex = kSupportBasesAndBeams[supportType].beamUncapped; - - // Draw an initial support segment to get the main segment height to a multiple of 16 - const int16_t heightDiff = std::min(floor2(currentHeight + 16, 16), crossbeamHeight) - currentHeight; - if (heightDiff > 0) - { - PaintAddImageAsParent( - session, imageTemplate.WithIndex(supportBeamImageIndex + heightDiff - 1), - { kMetalSupportBoundBoxOffsets[segment], currentHeight }, { 0, 0, heightDiff - 1 }); - } - - currentHeight += heightDiff; - - // Draw main support segments - for (uint8_t count = 1;; count++) - { - const int16_t beamLength = std::min(currentHeight + 16, crossbeamHeight) - currentHeight; - if (beamLength <= 0) - break; - - uint32_t imageIndex = supportBeamImageIndex + beamLength - 1; - if (count % 4 == 0 && beamLength == 16) - imageIndex++; - - PaintAddImageAsParent( - session, imageTemplate.WithIndex(imageIndex), { kMetalSupportBoundBoxOffsets[segment], currentHeight }, - { 0, 0, beamLength - 1 }); - - currentHeight += beamLength; - } - - supportSegments[segment].height = segmentHeight; - supportSegments[segment].slope = kTileSlopeAboveTrackOrScenery; - - // Draw extra support segments above height with a zero height bounding box - currentHeight = heightExtra < 0 ? height - 1 : height; - const auto totalHeightExtra = heightExtra < 0 ? currentHeight + (-heightExtra) : currentHeight + heightExtra; - const CoordsXYZ boundBoxOffset = CoordsXYZ(kMetalSupportBoundBoxOffsets[segment], currentHeight); - while (true) - { - const int16_t beamLength = std::min(currentHeight + 16, totalHeightExtra) - currentHeight; - if (beamLength <= 0) - break; - - PaintAddImageAsParent( - session, imageTemplate.WithIndex(kSupportBasesAndBeams[supportType].beamCapped + beamLength - 1), - { kMetalSupportBoundBoxOffsets[segment], currentHeight }, { boundBoxOffset, { 0, 0, 0 } }); - - currentHeight += beamLength; - } - - return false; // AND + return MetalSupportsPaintSetupCommon(session, supportGraphic, placement, heightExtra, height, imageTemplate); } bool MetalBSupportsPaintSetup( @@ -617,7 +455,7 @@ bool MetalBSupportsPaintSetup( int32_t height, const ImageId imageTemplate) { auto supportGraphic = RotateMetalSupportGraphic(supportType, 0); - return MetalBSupportsPaintSetup(session, supportGraphic, placement, heightExtra, height, imageTemplate); + return MetalSupportsPaintSetupCommon(session, supportGraphic, placement, heightExtra, height, imageTemplate); } bool MetalBSupportsPaintSetupRotated( @@ -626,7 +464,7 @@ bool MetalBSupportsPaintSetupRotated( { auto supportGraphic = RotateMetalSupportGraphic(supportType, direction); const auto rotatedPlacement = kMetalSupportPlacementRotated[EnumValue(placement)][direction]; - return MetalBSupportsPaintSetup(session, supportGraphic, rotatedPlacement, heightExtra, height, imageTemplate); + return MetalSupportsPaintSetupCommon(session, supportGraphic, rotatedPlacement, heightExtra, height, imageTemplate); } static inline MetalSupportGraphic RotateMetalSupportGraphic(const MetalSupportType supportType, const Direction direction) @@ -643,13 +481,13 @@ void DrawSupportsSideBySide( if (direction & 1) { - MetalASupportsPaintSetup(session, graphic, MetalSupportPlace::topRightSide, heightExtra, height, colour); - MetalASupportsPaintSetup(session, graphic, MetalSupportPlace::bottomLeftSide, heightExtra, height, colour); + MetalSupportsPaintSetupCommon(session, graphic, MetalSupportPlace::topRightSide, heightExtra, height, colour); + MetalSupportsPaintSetupCommon(session, graphic, MetalSupportPlace::bottomLeftSide, heightExtra, height, colour); } else { - MetalASupportsPaintSetup(session, graphic, MetalSupportPlace::topLeftSide, heightExtra, height, colour); - MetalASupportsPaintSetup(session, graphic, MetalSupportPlace::bottomRightSide, heightExtra, height, colour); + MetalSupportsPaintSetupCommon(session, graphic, MetalSupportPlace::topLeftSide, heightExtra, height, colour); + MetalSupportsPaintSetupCommon(session, graphic, MetalSupportPlace::bottomRightSide, heightExtra, height, colour); } } From a1a9acc6d7d0d57916c09932fbf81515acc42538 Mon Sep 17 00:00:00 2001 From: mix Date: Wed, 9 Jul 2025 01:47:08 +0100 Subject: [PATCH 15/18] Add max section height constant for metal support functions --- src/openrct2/paint/support/MetalSupports.cpp | 21 ++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/openrct2/paint/support/MetalSupports.cpp b/src/openrct2/paint/support/MetalSupports.cpp index 37941d9369..c715dd1c6b 100644 --- a/src/openrct2/paint/support/MetalSupports.cpp +++ b/src/openrct2/paint/support/MetalSupports.cpp @@ -282,6 +282,7 @@ constexpr MetalSupportGraphic kMetalSupportGraphicRotated[kMetalSupportTypeCount }; constexpr const int32_t kMetalSupportBaseHeight = 6; +constexpr const int32_t kMetalSupportMaxSectionHeight = 16; static inline MetalSupportGraphic RotateMetalSupportGraphic(MetalSupportType supportType, Direction direction); @@ -379,8 +380,11 @@ static bool MetalSupportsPaintSetupCommon( const auto supportBeamImageIndex = kSupportBasesAndBeams[supportType].beamUncapped; - // Draw an initial support segment to get the main segment height to a multiple of 16 - const int16_t heightDiff = std::min(floor2(currentHeight + 16, 16), crossbeamHeight) - currentHeight; + // Draw an initial support segment to get the main segment height to a multiple of kMetalSupportMaxSectionHeight + const int16_t heightDiff = std::min( + floor2(currentHeight + kMetalSupportMaxSectionHeight, kMetalSupportMaxSectionHeight), + crossbeamHeight) + - currentHeight; if (heightDiff > 0) { PaintAddImageAsParent( @@ -393,12 +397,13 @@ static bool MetalSupportsPaintSetupCommon( // Draw main support segments for (uint8_t count = 1;; count++) { - const int16_t beamLength = std::min(currentHeight + 16, crossbeamHeight) - currentHeight; + const int16_t beamLength = std::min(currentHeight + kMetalSupportMaxSectionHeight, crossbeamHeight) + - currentHeight; if (beamLength <= 0) break; uint32_t imageIndex = supportBeamImageIndex + beamLength - 1; - if (count % 4 == 0 && beamLength == 16) + if (count % 4 == 0 && beamLength == kMetalSupportMaxSectionHeight) imageIndex++; PaintAddImageAsParent( @@ -419,7 +424,7 @@ static bool MetalSupportsPaintSetupCommon( const CoordsXYZ boundBoxOffset = CoordsXYZ(kMetalSupportBoundBoxOffsets[originalSegment], currentHeight); while (true) { - const int16_t beamLength = std::min(currentHeight + 16, totalHeightExtra) - currentHeight; + const int16_t beamLength = std::min(currentHeight + kMetalSupportMaxSectionHeight, totalHeightExtra) - currentHeight; if (beamLength <= 0) break; @@ -551,7 +556,7 @@ bool PathPoleSupportsPaintSetup( // si = height // dx = baseHeight - int16_t heightDiff = floor2(baseHeight + 16, 16); + int16_t heightDiff = floor2(baseHeight + kMetalSupportMaxSectionHeight, kMetalSupportMaxSectionHeight); if (heightDiff > height) { heightDiff = height; @@ -575,7 +580,7 @@ bool PathPoleSupportsPaintSetup( for (int32_t i = 0; i < 4; ++i) { - z = baseHeight + 16; + z = baseHeight + kMetalSupportMaxSectionHeight; if (z > height) { z = height; @@ -607,7 +612,7 @@ bool PathPoleSupportsPaintSetup( } ImageIndex imageIndex = pathPaintInfo.BridgeImageId + 20 + (z - 1); - if (z == 16) + if (z == kMetalSupportMaxSectionHeight) { imageIndex += 1; } From 15238bcd53aefe8e73315730b47b04234ee8b9c9 Mon Sep 17 00:00:00 2001 From: mix Date: Wed, 9 Jul 2025 01:49:09 +0100 Subject: [PATCH 16/18] Add changelog entry for fixed offset type b metal supports --- distribution/changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index a0093f18d3..f4b04645e5 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -6,6 +6,7 @@ - Improved: [#24921] The command line sprite build command now prints out the images table entry for the compiled sprite file. - Improved: [#24953] Opening the Scenario Editor, Track Designer or Track Designs Manager now display the progress bar. - Fix: [#16988] AppImage version does not show changelog. +- Fix: [#24001] Sloped diagonal metal supports that are offset with a crossbeam draw incorrectly. - Fix: [#24173] Allow all game speeds between 1 and 8 if developer mode is on. - Fix: [#24745] Potential crash when lighting effects are enabled and loading a save or a new scenario. - Fix: [#24915] LIM Launched (original bug), Corkscrew and Twister Roller Coaster inline twists have some incorrect tunnels. From ed59336da2240fda2ba419f6dac90ffca09101d5 Mon Sep 17 00:00:00 2001 From: mix Date: Fri, 15 Aug 2025 06:40:59 +0100 Subject: [PATCH 17/18] Change metal support joint interval magic number to const --- src/openrct2/paint/support/MetalSupports.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/openrct2/paint/support/MetalSupports.cpp b/src/openrct2/paint/support/MetalSupports.cpp index c715dd1c6b..8cb59522a8 100644 --- a/src/openrct2/paint/support/MetalSupports.cpp +++ b/src/openrct2/paint/support/MetalSupports.cpp @@ -283,6 +283,7 @@ constexpr MetalSupportGraphic kMetalSupportGraphicRotated[kMetalSupportTypeCount constexpr const int32_t kMetalSupportBaseHeight = 6; constexpr const int32_t kMetalSupportMaxSectionHeight = 16; +constexpr const int32_t kMetalSupportJointInterval = 4; static inline MetalSupportGraphic RotateMetalSupportGraphic(MetalSupportType supportType, Direction direction); @@ -403,7 +404,7 @@ static bool MetalSupportsPaintSetupCommon( break; uint32_t imageIndex = supportBeamImageIndex + beamLength - 1; - if (count % 4 == 0 && beamLength == kMetalSupportMaxSectionHeight) + if (count % kMetalSupportJointInterval == 0 && beamLength == kMetalSupportMaxSectionHeight) imageIndex++; PaintAddImageAsParent( From 2c1e838844dece036ce171acca2dd698492e46cd Mon Sep 17 00:00:00 2001 From: mix Date: Fri, 15 Aug 2025 07:07:36 +0100 Subject: [PATCH 18/18] Change metal support type b crossbeam offset index magic num to const --- src/openrct2/paint/support/MetalSupports.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/openrct2/paint/support/MetalSupports.cpp b/src/openrct2/paint/support/MetalSupports.cpp index 8cb59522a8..3e859d125b 100644 --- a/src/openrct2/paint/support/MetalSupports.cpp +++ b/src/openrct2/paint/support/MetalSupports.cpp @@ -284,6 +284,7 @@ constexpr MetalSupportGraphic kMetalSupportGraphicRotated[kMetalSupportTypeCount constexpr const int32_t kMetalSupportBaseHeight = 6; constexpr const int32_t kMetalSupportMaxSectionHeight = 16; constexpr const int32_t kMetalSupportJointInterval = 4; +constexpr const int32_t kMetalSupportCrossbeamTwoSegmentOffsetIndex = 4; static inline MetalSupportGraphic RotateMetalSupportGraphic(MetalSupportType supportType, Direction direction); @@ -347,7 +348,7 @@ static bool MetalSupportsPaintSetupCommon( const uint8_t crossBeamIndex = kMetalSupportSegmentOffsets[baseIndex + segment * 8 + 1]; if constexpr (typeB) { - if (crossBeamIndex >= 4) + if (crossBeamIndex >= kMetalSupportCrossbeamTwoSegmentOffsetIndex) return false; }