1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-22 23:33:04 +01:00

Remove null TunnelType and refactor paint code accordingly (#24924)

This commit is contained in:
mix
2025-08-09 05:32:20 +01:00
committed by GitHub
parent 5d34752424
commit 0d64899fd3
5 changed files with 43 additions and 64 deletions

View File

@@ -149,10 +149,8 @@ struct PaintSessionCore
SupportHeight SupportSegments[9]; SupportHeight SupportSegments[9];
SupportHeight Support; SupportHeight Support;
uint16_t WaterHeight; uint16_t WaterHeight;
TunnelEntry LeftTunnels[kTunnelMaxCount]; sfl::static_vector<TunnelEntry, kTunnelMaxCount> LeftTunnels;
TunnelEntry RightTunnels[kTunnelMaxCount]; sfl::static_vector<TunnelEntry, kTunnelMaxCount> RightTunnels;
uint8_t LeftTunnelCount;
uint8_t RightTunnelCount;
uint8_t VerticalTunnelHeight; uint8_t VerticalTunnelHeight;
uint8_t CurrentRotation; uint8_t CurrentRotation;
uint8_t Flags; uint8_t Flags;

View File

@@ -197,7 +197,7 @@ static constexpr TunnelDescriptor kTunnels[] = {
{ 2, 3, -16, 4, TunnelType::Doors5, 96 }, // TunnelType::DoorsFlatTo25Deg5 { 2, 3, -16, 4, TunnelType::Doors5, 96 }, // TunnelType::DoorsFlatTo25Deg5
{ 2, 3, -16, 4, TunnelType::Doors6, 100 }, // TunnelType::DoorsFlatTo25Deg6 { 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 // clang-format on
// tunnel offset // tunnel offset
@@ -518,7 +518,6 @@ static void ViewportSurfaceDrawTileSideBottom(
CoordsXY tunnelBounds = { 1, 1 }; CoordsXY tunnelBounds = { 1, 1 };
CoordsXY tunnelTopBoundBoxOffset = { 0, 0 }; CoordsXY tunnelTopBoundBoxOffset = { 0, 0 };
const TunnelEntry* tunnelArray;
switch (edge) switch (edge)
{ {
case EDGE_BOTTOMLEFT: case EDGE_BOTTOMLEFT:
@@ -532,8 +531,6 @@ static void ViewportSurfaceDrawTileSideBottom(
bounds.y = 30; bounds.y = 30;
tunnelBounds.x = 32; tunnelBounds.x = 32;
tunnelTopBoundBoxOffset.y = 31; tunnelTopBoundBoxOffset.y = 31;
tunnelArray = session.LeftTunnels;
break; break;
case EDGE_BOTTOMRIGHT: case EDGE_BOTTOMRIGHT:
@@ -547,8 +544,6 @@ static void ViewportSurfaceDrawTileSideBottom(
bounds.x = 30; bounds.x = 30;
tunnelBounds.y = 32; tunnelBounds.y = 32;
tunnelTopBoundBoxOffset.x = 31; tunnelTopBoundBoxOffset.x = 31;
tunnelArray = session.RightTunnels;
break; break;
default: default:
@@ -618,50 +613,27 @@ static void ViewportSurfaceDrawTileSideBottom(
neighbourCornerHeight1 = cornerHeight2; neighbourCornerHeight1 = cornerHeight2;
for (auto tunnelIndex = 0; tunnelIndex < kTunnelMaxCount;) const auto lowestCornerHeight = std::min(cornerHeight1, cornerHeight2);
{
if (curHeight >= cornerHeight1 || curHeight >= cornerHeight2)
{
// If top of edge isn't straight, add a filler
uint32_t image_offset = 1;
if (curHeight >= cornerHeight1)
{
image_offset = 2;
if (curHeight >= cornerHeight2) const auto& tunnels = edge == EDGE_BOTTOMLEFT ? session.LeftTunnels : session.RightTunnels;
for (auto& tunnel : tunnels)
{ {
return; if (curHeight > tunnel.height || tunnel.height >= lowestCornerHeight)
}
}
auto imageId = baseImageId.WithIndexOffset(image_offset);
PaintAddImageAsParent(session, imageId, { offset, curHeight * kCoordsZPerTinyZ }, { bounds, 15 });
return;
}
if (curHeight != tunnelArray[tunnelIndex].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; continue;
} }
const auto tdOriginal = kTunnels[EnumValue(tunnel.type)];
// Draw land edges up to the bottom of the tunnel
while (curHeight < tunnel.height)
{
const auto boundBoxZ = curHeight == tunnel.height - 1 ? tdOriginal.lowerEdgeBoundingBoxZ : kCoordsZPerTinyZ - 1;
PaintAddImageAsParent(session, baseImageId, { offset, curHeight * kCoordsZPerTinyZ }, { bounds, boundBoxZ });
curHeight++;
} }
// Tunnels auto tunnelType = tunnel.type;
auto tunnelType = tunnelArray[tunnelIndex].type;
const auto tdOriginal = kTunnels[EnumValue(tunnelType)];
auto td = tdOriginal; auto td = tdOriginal;
uint8_t tunnelHeight = td.height; uint8_t tunnelHeight = td.height;
int16_t zOffset = curHeight; int16_t zOffset = curHeight;
@@ -704,7 +676,21 @@ static void ViewportSurfaceDrawTileSideBottom(
{ { tunnelTopBoundBoxOffset, boundBoxOffsetZ }, { tunnelBounds, boundBoxLength - 1 } }); { { tunnelTopBoundBoxOffset, boundBoxOffsetZ }, { tunnelBounds, boundBoxLength - 1 } });
curHeight += td.height; 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 });
} }
} }

View File

@@ -125,10 +125,8 @@ static void PaintTileElementBase(PaintSession& session, const CoordsXY& origCoor
return; return;
} }
session.LeftTunnelCount = 0; session.LeftTunnels.clear();
session.RightTunnelCount = 0; session.RightTunnels.clear();
session.LeftTunnels[0] = { 0xFF, TunnelType::Null };
session.RightTunnels[0] = { 0xFF, TunnelType::Null };
session.VerticalTunnelHeight = 0xFF; session.VerticalTunnelHeight = 0xFF;
session.MapPosition.x = coords.x; session.MapPosition.x = coords.x;
session.MapPosition.y = coords.y; session.MapPosition.y = coords.y;

View File

@@ -26,21 +26,17 @@ void TrackPaintUtilRightQuarterTurn3TilesTunnel(
void PaintUtilPushTunnelLeft(PaintSession& session, uint16_t height, TunnelType type) void PaintUtilPushTunnelLeft(PaintSession& session, uint16_t height, TunnelType type)
{ {
session.LeftTunnels[session.LeftTunnelCount] = { static_cast<uint8_t>((height / 16)), type }; if (!session.LeftTunnels.full())
if (session.LeftTunnelCount < kTunnelMaxCount - 1)
{ {
session.LeftTunnels[session.LeftTunnelCount + 1] = { 0xFF, TunnelType::Null }; session.LeftTunnels.emplace_back(height / kCoordsZPerTinyZ, type);
session.LeftTunnelCount++;
} }
} }
void PaintUtilPushTunnelRight(PaintSession& session, uint16_t height, TunnelType type) void PaintUtilPushTunnelRight(PaintSession& session, uint16_t height, TunnelType type)
{ {
session.RightTunnels[session.RightTunnelCount] = { static_cast<uint8_t>((height / 16)), type }; if (!session.RightTunnels.full())
if (session.RightTunnelCount < kTunnelMaxCount - 1)
{ {
session.RightTunnels[session.RightTunnelCount + 1] = { 0xFF, TunnelType::Null }; session.RightTunnels.emplace_back(height / kCoordsZPerTinyZ, type);
session.RightTunnelCount++;
} }
} }

View File

@@ -52,12 +52,9 @@ enum class TunnelType : uint8_t
DoorsFlatTo25Deg4 = 27, DoorsFlatTo25Deg4 = 27,
DoorsFlatTo25Deg5 = 28, DoorsFlatTo25Deg5 = 28,
DoorsFlatTo25Deg6 = 29, DoorsFlatTo25Deg6 = 29,
Count,
Null = 255,
}; };
constexpr uint8_t kRegularTunnelTypeCount = 16; constexpr uint8_t kRegularTunnelTypeCount = 16;
constexpr uint8_t kTunnelTypeCount = 30;
enum class TunnelGroup : uint8_t enum class TunnelGroup : uint8_t
{ {
@@ -81,6 +78,10 @@ struct TunnelEntry
{ {
uint8_t height; uint8_t height;
TunnelType type; TunnelType type;
constexpr TunnelEntry(const uint8_t _height, const TunnelType _type)
: height(_height)
, type(_type) {};
}; };
TunnelType GetTunnelType(TunnelGroup tunnelGroup, TunnelSubType tunnelSubType); TunnelType GetTunnelType(TunnelGroup tunnelGroup, TunnelSubType tunnelSubType);