1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-10 09:32:29 +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 Support;
uint16_t WaterHeight;
TunnelEntry LeftTunnels[kTunnelMaxCount];
TunnelEntry RightTunnels[kTunnelMaxCount];
uint8_t LeftTunnelCount;
uint8_t RightTunnelCount;
sfl::static_vector<TunnelEntry, kTunnelMaxCount> LeftTunnels;
sfl::static_vector<TunnelEntry, kTunnelMaxCount> RightTunnels;
uint8_t VerticalTunnelHeight;
uint8_t CurrentRotation;
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::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 });
}
}

View File

@@ -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;

View File

@@ -26,21 +26,17 @@ void TrackPaintUtilRightQuarterTurn3TilesTunnel(
void PaintUtilPushTunnelLeft(PaintSession& session, uint16_t height, TunnelType type)
{
session.LeftTunnels[session.LeftTunnelCount] = { static_cast<uint8_t>((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<uint8_t>((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);
}
}

View File

@@ -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);