Use WoodenBSupportsSetupRotated() for scenery supports drawing

This commit is contained in:
Gymnasiast 2023-11-12 19:07:09 +01:00
parent 3ab33d3ca9
commit f47cfa79c0
No known key found for this signature in database
GPG Key ID: DBFFF47AB2CA3EDD
4 changed files with 36 additions and 21 deletions

View File

@ -353,19 +353,19 @@ static constexpr UnkSupportsDescriptor Byte97B23C[] = {
{{{0, 0, 0}, {1, 1, 8}}, 0, 1},
{{{0, 0, 0}, {1, 1, 8}}, 0, 1},
{{{0, 0, 0}, {1, 1, 8}}, 0, 1},
{{{0, 0, 0}, {1, 1, 8}}, 0, 1}, // ?
{{{0, 0, 0}, {1, 1, 8}}, 0, 1},
{{{0, 0, 0}, {1, 1, 8}}, 0, 1},
{{{0, 0, 0}, {1, 1, 8}}, 0, 1},
{{{0, 0, 0}, {1, 1, 8}}, 0, 1}, // ?
{{{0, 0, 0}, {1, 1, 8}}, 0, 1},
{{{0, 0, 0}, {1, 1, 8}}, 0, 1},
{{{0, 0, 0}, {1, 1, 8}}, 0, 1},
{{{0, 0, 0}, {1, 1, 8}}, 0, 1}, // ?
{{{0, 0, 0}, {1, 1, 8}}, 0, 1},
{{{0, 0, 0}, {1, 1, 8}}, 0, 1},
{{{0, 0, 0}, {1, 1, 8}}, 0, 1},
{{{0, 0, 0}, {1, 1, 8}}, 0, 1},
{{{0, 0, 0}, {1, 1, 8}}, 0, 1},
{{{0, 0, 0}, {1, 1, 8}}, 0, 1},
{{{2, 2, 1}, {28, 28, 2}}, 0, 1},
{{{2, 2, 1}, {28, 28, 2}}, 0, 1}, // Large scenery (all directions)
{{{0, 0, 0}, {1, 1, 8}}, 0, 1}, // Flat to steep large 1
{{{0, 0, 0}, {1, 1, 8}}, 0, 1},
{{{0, 0, 0}, {1, 1, 8}}, 0, 1},
@ -680,16 +680,32 @@ bool WoodenASupportsPaintSetup(
return hasSupports;
}
static int32_t GetSpecialOffsetForTransitionType(WoodenSupportTransitionType transitionType, Direction direction)
{
if (transitionType == WoodenSupportTransitionType::None)
return 0;
// "Special" values are an offset into tables like Byte97B23C, plus 1.
// Save for WoodenSupportTransitionType::LargeScenery, there are four entries (one per direction) for every
// transition type. While these tables will have to be refactored in due course, we can only do so once all
// drawing functions use WoodenSupportTransitionType instead of passing the "special" value directly.
int32_t specialOffset = 0;
if (transitionType < WoodenSupportTransitionType::Scenery)
specialOffset = (EnumValue(transitionType) * NumOrthogonalDirections) + direction;
else if (transitionType == WoodenSupportTransitionType::Scenery)
specialOffset = (EnumValue(transitionType) * NumOrthogonalDirections);
else
specialOffset = (EnumValue(transitionType) * NumOrthogonalDirections) + direction - 3;
return specialOffset + 1;
}
bool WoodenASupportsPaintSetup(
PaintSession& session, WoodenSupportType supportType, WoodenSupportSubType subType, int32_t height, ImageId imageTemplate,
WoodenSupportTransitionType transitionType, Direction direction)
{
int32_t oldSupportType = (EnumValue(supportType) * 6) + EnumValue(subType);
int32_t special = 0;
if (transitionType != WoodenSupportTransitionType::None)
{
special = (EnumValue(transitionType) * NumOrthogonalDirections) + direction + 1;
}
int32_t special = GetSpecialOffsetForTransitionType(transitionType, direction);
return WoodenASupportsPaintSetup(session, oldSupportType, special, height, imageTemplate);
}
@ -829,11 +845,7 @@ bool WoodenBSupportsPaintSetup(
WoodenSupportTransitionType transitionType, Direction direction)
{
int32_t oldSupportType = (EnumValue(supportType) * 6) + EnumValue(subType);
int32_t special = 0;
if (transitionType != WoodenSupportTransitionType::None)
{
special = (EnumValue(transitionType) * NumOrthogonalDirections) + direction + 1;
}
int32_t special = GetSpecialOffsetForTransitionType(transitionType, direction);
return WoodenBSupportsPaintSetup(session, oldSupportType, special, height, imageTemplate);
}

View File

@ -42,6 +42,7 @@ enum class WoodenSupportTransitionType : uint8_t
Up25DegToUp60Deg = 3,
Up60DegToUp25Deg = 4,
Up60Deg = 5,
Scenery = 12,
};
// There are 13 types of metal supports. A graphic showing all of them is available here:

View File

@ -61,15 +61,16 @@ static void PaintLargeScenerySupports(
if (tile.flags & LARGE_SCENERY_TILE_FLAG_NO_SUPPORTS)
return;
auto special = 0;
auto transitionType = WoodenSupportTransitionType::None;
auto supportHeight = height;
if (supportHeight & 0xF)
{
supportHeight &= ~0xF;
special = 49;
transitionType = WoodenSupportTransitionType::Scenery;
}
WoodenBSupportsPaintSetup(session, (direction & 1), special, supportHeight, imageTemplate);
WoodenBSupportsPaintSetupRotated(
session, WoodenSupportType::Truss, WoodenSupportSubType::NeSw, direction, supportHeight, imageTemplate, transitionType);
int32_t clearanceHeight = Ceil2(tileElement.GetClearanceZ() + 15, 16);
if (tile.flags & LARGE_SCENERY_TILE_FLAG_ALLOW_SUPPORTS_ABOVE)

View File

@ -42,12 +42,12 @@ static void PaintSmallScenerySupports(
if (sceneryEntry.HasFlag(SMALL_SCENERY_FLAG_NO_SUPPORTS))
return;
auto special = 0;
auto transitionType = WoodenSupportTransitionType::None;
auto supportHeight = height;
if (supportHeight & 0xF)
{
supportHeight &= ~0xF;
special = 49;
transitionType = WoodenSupportTransitionType::Scenery;
}
auto supportImageTemplate = ImageId().WithRemap(0);
@ -60,8 +60,9 @@ static void PaintSmallScenerySupports(
supportImageTemplate = imageTemplate;
}
auto supportType = (direction & 1) ? 1 : 0;
WoodenBSupportsPaintSetup(session, supportType, special, supportHeight, supportImageTemplate);
WoodenBSupportsPaintSetupRotated(
session, WoodenSupportType::Truss, WoodenSupportSubType::NeSw, direction, supportHeight, supportImageTemplate,
transitionType);
}
static void SetSupportHeights(