Refactor StationObject image indices (#26042)

* Refactor StationObject image indices

* Minor rewrite to avoid kNumOrthogonalDirections

* Return early in StationObject::Load if there are no images

* Unset all indices when unloading a station object
This commit is contained in:
Aaron van Geffen authored and GitHub committed 2026-02-23 23:53:56 +01:00
1 parent 6c7e5f8f10
commit 8a0fef3d9b
5 files changed
+104 -57

No files matched your search

+6 -5
View File
@@ -4977,22 +4977,23 @@ namespace OpenRCT2::Ui::Windows
void ColourOnDrawEntrancePreview(RenderTarget& rt, const Ride* ride, const Widget& widget)
{
auto stationObj = ride->getStationObject();
if (stationObj == nullptr && stationObj->BaseImageId == kImageIndexUndefined)
if (stationObj == nullptr && stationObj->entranceBackIndex == kImageIndexUndefined)
return;
auto trackColour = ride->trackColours[0];
auto imageId = ImageId(stationObj->BaseImageId, trackColour.main, trackColour.additional);
// Back
GfxDrawSprite(rt, imageId, { 34, 20 });
auto backImageId = ImageId(stationObj->entranceBackIndex, trackColour.main, trackColour.additional);
GfxDrawSprite(rt, backImageId, { 34, 20 });
// Front
GfxDrawSprite(rt, imageId.WithIndexOffset(4), { 34, 20 });
auto frontImageId = ImageId(stationObj->entranceFrontIndex, trackColour.main, trackColour.additional);
GfxDrawSprite(rt, frontImageId, { 34, 20 });
// Glass
if (stationObj->Flags & StationObjectFlags::isTransparent)
{
auto glassImageId = ImageId(stationObj->BaseImageId + 20).WithTransparency(trackColour.main);
auto glassImageId = ImageId(stationObj->entranceFrontGlassIndex).WithTransparency(trackColour.main);
GfxDrawSprite(rt, glassImageId, { 34, 20 });
}
}
+51 -24
View File
@@ -24,16 +24,36 @@ namespace OpenRCT2
NameStringId = LanguageAllocateObjectString(GetName());
auto numImages = GetImageTable().GetCount();
if (numImages != 0)
{
BaseImageId = LoadImages();
if (numImages == 0)
return;
uint32_t shelterOffset = (Flags & StationObjectFlags::isTransparent) ? 32 : 16;
if (numImages > shelterOffset)
{
ShelterImageId = BaseImageId + shelterOffset;
}
baseImageIndex = LoadImages();
entranceBackIndex = baseImageIndex;
entranceFrontIndex = entranceBackIndex + 4;
exitBackIndex = entranceBackIndex + 8;
exitFrontIndex = entranceBackIndex + 12;
if (!(Flags & StationObjectFlags::isTransparent))
{
if (numImages > 16)
shelterIndex = entranceBackIndex + 16;
return;
}
entranceBackGlassIndex = entranceBackIndex + 16;
entranceFrontGlassIndex = entranceBackIndex + 20;
exitBackGlassIndex = entranceBackIndex + 24;
exitFrontGlassIndex = entranceBackIndex + 28;
if (numImages > 32)
shelterIndex = entranceBackIndex + 32;
if (numImages > 44)
shelterGlassIndex = entranceBackIndex + 44;
}
void StationObject::Unload()
@@ -42,8 +62,20 @@ namespace OpenRCT2
UnloadImages();
NameStringId = 0;
BaseImageId = kImageIndexUndefined;
ShelterImageId = kImageIndexUndefined;
baseImageIndex = kImageIndexUndefined;
entranceBackIndex = kImageIndexUndefined;
entranceFrontIndex = kImageIndexUndefined;
exitBackIndex = kImageIndexUndefined;
exitFrontIndex = kImageIndexUndefined;
entranceBackGlassIndex = kImageIndexUndefined;
entranceFrontGlassIndex = kImageIndexUndefined;
exitBackGlassIndex = kImageIndexUndefined;
exitFrontGlassIndex = kImageIndexUndefined;
shelterIndex = kImageIndexUndefined;
shelterGlassIndex = kImageIndexUndefined;
}
void StationObject::DrawPreview(Drawing::RenderTarget& rt, int32_t width, int32_t height) const
@@ -54,27 +86,22 @@ namespace OpenRCT2
auto colour1 = Drawing::Colour::bordeauxRed;
auto tcolour0 = colour0;
auto imageId = ImageId(BaseImageId);
auto tImageId = ImageId(BaseImageId + 16).WithTransparency(tcolour0);
if (Flags & StationObjectFlags::hasPrimaryColour)
{
imageId = imageId.WithPrimary(colour0);
}
if (Flags & StationObjectFlags::hasSecondaryColour)
{
imageId = imageId.WithSecondary(colour1);
}
GfxDrawSprite(rt, imageId, screenCoords);
// Draw back sprite
auto backImageId = ImageId(entranceBackIndex, colour0, colour1);
GfxDrawSprite(rt, backImageId, screenCoords);
if (Flags & StationObjectFlags::isTransparent)
{
auto tImageId = ImageId(entranceBackGlassIndex).WithTransparency(tcolour0);
GfxDrawSprite(rt, tImageId, screenCoords);
}
GfxDrawSprite(rt, imageId.WithIndexOffset(4), screenCoords);
// Draw front sprite
auto frontImageId = ImageId(entranceFrontIndex, colour0, colour1);
GfxDrawSprite(rt, frontImageId, screenCoords);
if (Flags & StationObjectFlags::isTransparent)
{
GfxDrawSprite(rt, tImageId.WithIndexOffset(4), screenCoords);
auto frontGlassImageId = ImageId(entranceFrontGlassIndex).WithTransparency(tcolour0);
GfxDrawSprite(rt, frontGlassImageId, screenCoords);
}
}
+28 -3
View File
@@ -20,17 +20,42 @@ namespace OpenRCT2
const uint32_t hasSecondaryColour = 1 << 1;
const uint32_t isTransparent = 1 << 2;
const uint32_t noPlatforms = 1 << 3;
const uint32_t hasShelter = (1 << 4);
const uint32_t hasShelter = 1 << 4;
} // namespace StationObjectFlags
enum
{
SPR_STATION_COVER_OFFSET_NE_SW_BACK_0 = 0,
SPR_STATION_COVER_OFFSET_NE_SW_BACK_1,
SPR_STATION_COVER_OFFSET_NE_SW_FRONT,
SPR_STATION_COVER_OFFSET_SE_NW_BACK_0,
SPR_STATION_COVER_OFFSET_SE_NW_BACK_1,
SPR_STATION_COVER_OFFSET_SE_NW_FRONT,
SPR_STATION_COVER_OFFSET_TALL
};
class StationObject final : public Object
{
public:
static constexpr ObjectType kObjectType = ObjectType::station;
StringId NameStringId{};
ImageIndex BaseImageId = kImageIndexUndefined;
ImageIndex ShelterImageId = kImageIndexUndefined;
ImageIndex baseImageIndex = kImageIndexUndefined;
ImageIndex entranceBackIndex = kImageIndexUndefined;
ImageIndex entranceFrontIndex = kImageIndexUndefined;
ImageIndex exitBackIndex = kImageIndexUndefined;
ImageIndex exitFrontIndex = kImageIndexUndefined;
ImageIndex entranceBackGlassIndex = kImageIndexUndefined;
ImageIndex entranceFrontGlassIndex = kImageIndexUndefined;
ImageIndex exitBackGlassIndex = kImageIndexUndefined;
ImageIndex exitFrontGlassIndex = kImageIndexUndefined;
ImageIndex shelterIndex = kImageIndexUndefined;
ImageIndex shelterGlassIndex = kImageIndexUndefined;
uint32_t Flags{};
int32_t Height{};
uint8_t ScrollingMode{};
@@ -119,7 +119,7 @@ static void PaintRideEntranceExit(PaintSession& session, uint8_t direction, int3
}
auto stationObj = ride->getStationObject();
if (stationObj == nullptr || stationObj->BaseImageId == kImageIndexUndefined)
if (stationObj == nullptr || stationObj->baseImageIndex == kImageIndexUndefined)
{
return;
}
@@ -167,27 +167,30 @@ static void PaintRideEntranceExit(PaintSession& session, uint8_t direction, int3
auto isExit = entranceEl.GetEntranceType() == ENTRANCE_TYPE_RIDE_EXIT;
// Back
ImageIndex imageIndex = isExit ? stationObj->BaseImageId + direction + 8 : stationObj->BaseImageId + direction;
ImageIndex glassImageIndex = isExit ? stationObj->BaseImageId + direction + 24 : stationObj->BaseImageId + direction + 16;
ImageIndex backImageIndex = (isExit ? stationObj->exitBackIndex : stationObj->entranceBackIndex) + direction;
PaintAddImageAsParentRotated(
session, direction, imageTemplate.WithIndex(imageIndex), { 0, 0, height }, { { 2, 2, height }, { 28, 8, 30 } });
session, direction, imageTemplate.WithIndex(backImageIndex), { 0, 0, height }, { { 2, 2, height }, { 28, 8, 30 } });
if (hasGlass)
{
ImageIndex backGlassImageIndex = (isExit ? stationObj->exitBackGlassIndex : stationObj->entranceBackGlassIndex)
+ direction;
PaintAddImageAsChildRotated(
session, direction, glassImageTemplate.WithIndex(glassImageIndex), { 0, 0, height },
session, direction, glassImageTemplate.WithIndex(backGlassImageIndex), { 0, 0, height },
{ { 2, 2, height }, { 28, 8, 30 } });
}
// Front
const auto frontBoundBoxZ = isExit ? 1 : 17;
imageIndex += 4;
ImageIndex frontImageIndex = (isExit ? stationObj->exitFrontIndex : stationObj->entranceFrontIndex) + direction;
PaintAddImageAsParent(
session, imageTemplate.WithIndex(imageIndex), { 0, 0, height }, { { 2, 2, height + 30 }, { 28, 28, frontBoundBoxZ } });
session, imageTemplate.WithIndex(frontImageIndex), { 0, 0, height },
{ { 2, 2, height + 30 }, { 28, 28, frontBoundBoxZ } });
if (hasGlass)
{
glassImageIndex += 4;
ImageIndex frontGlassImageIndex = (isExit ? stationObj->exitFrontGlassIndex : stationObj->entranceFrontGlassIndex)
+ direction;
PaintAddImageAsChild(
session, glassImageTemplate.WithIndex(glassImageIndex), { 0, 0, height },
session, glassImageTemplate.WithIndex(frontGlassImageIndex), { 0, 0, height },
{ { 2, 2, height + 30 }, { 28, 28, frontBoundBoxZ } });
}
+7 -16
View File
@@ -85,17 +85,6 @@ static constexpr uint32_t trackSpritesGhostTrainSpinningTunnel[2][2][4] = {
},
};
enum
{
SPR_STATION_COVER_OFFSET_NE_SW_BACK_0 = 0,
SPR_STATION_COVER_OFFSET_NE_SW_BACK_1,
SPR_STATION_COVER_OFFSET_NE_SW_FRONT,
SPR_STATION_COVER_OFFSET_SE_NW_BACK_0,
SPR_STATION_COVER_OFFSET_SE_NW_BACK_1,
SPR_STATION_COVER_OFFSET_SE_NW_FRONT,
SPR_STATION_COVER_OFFSET_TALL
};
bool TrackPaintUtilHasFence(
enum edge_t edge, const CoordsXY& position, const TrackElement& trackElement, const Ride& ride, uint8_t rotation)
{
@@ -670,8 +659,8 @@ bool TrackPaintUtilDrawStationCovers2(
return false;
}
auto baseImageIndex = stationObject->ShelterImageId;
if (baseImageIndex == kImageIndexUndefined)
auto shelterImageIndex = stationObject->shelterIndex;
if (shelterImageIndex == kImageIndexUndefined)
return false;
static constexpr int16_t heights[][2] = {
@@ -708,10 +697,10 @@ bool TrackPaintUtilDrawStationCovers2(
imageOffset += SPR_STATION_COVER_OFFSET_TALL;
}
auto imageId = session.TrackColours.WithIndex(baseImageIndex + imageOffset);
auto imageId = session.TrackColours.WithIndex(shelterImageIndex + imageOffset);
if (!session.TrackColours.IsRemap())
{
imageId = ImageId(baseImageIndex + imageOffset);
imageId = ImageId(shelterImageIndex + imageOffset);
if (stationObject->Flags & StationObjectFlags::hasPrimaryColour)
imageId = imageId.WithPrimary(session.TrackColours.GetPrimary());
if (stationObject->Flags & StationObjectFlags::hasSecondaryColour)
@@ -723,7 +712,8 @@ bool TrackPaintUtilDrawStationCovers2(
// Glass
if (colour == TrackStationColour && (stationObject->Flags & StationObjectFlags::isTransparent))
{
imageId = ImageId(baseImageIndex + imageOffset + 12).WithTransparency(session.TrackColours.GetPrimary());
auto shelterGlassImageIndex = stationObject->shelterGlassIndex;
imageId = ImageId(shelterGlassImageIndex + imageOffset).WithTransparency(session.TrackColours.GetPrimary());
PaintAddImageAsChild(session, imageId, offset, boundBox);
}
return true;
@@ -737,6 +727,7 @@ bool TrackPaintUtilDrawNarrowStationPlatform(
const auto* stationObj = ride.getStationObject();
if (stationObj != nullptr && stationObj->Flags & StationObjectFlags::noPlatforms)
return false;
auto colour = GetStationColourScheme(session, trackElement);
if (direction & 1)
{