diff --git a/src/openrct2/interface/Viewport.cpp b/src/openrct2/interface/Viewport.cpp index f5f550e0a3..1299878974 100644 --- a/src/openrct2/interface/Viewport.cpp +++ b/src/openrct2/interface/Viewport.cpp @@ -65,6 +65,7 @@ static uint32_t _currentImageType; InteractionInfo::InteractionInfo(const paint_struct* ps) : Loc(ps->map_x, ps->map_y) , Element(ps->tileElement) + , Entity(ps->entity) , SpriteType(ps->sprite_type) { } diff --git a/src/openrct2/interface/Viewport.h b/src/openrct2/interface/Viewport.h index 6347512325..542b76d1f8 100644 --- a/src/openrct2/interface/Viewport.h +++ b/src/openrct2/interface/Viewport.h @@ -84,11 +84,8 @@ struct InteractionInfo InteractionInfo() = default; InteractionInfo(const paint_struct* ps); CoordsXY Loc; - union - { - TileElement* Element = nullptr; - EntityBase* Entity; - }; + TileElement* Element{}; + EntityBase* Entity{}; ViewportInteractionItem SpriteType = ViewportInteractionItem::None; }; diff --git a/src/openrct2/paint/Paint.Entity.cpp b/src/openrct2/paint/Paint.Entity.cpp index e1296bd394..ebe828793e 100644 --- a/src/openrct2/paint/Paint.Entity.cpp +++ b/src/openrct2/paint/Paint.Entity.cpp @@ -55,7 +55,7 @@ void EntityPaintSetup(paint_session& session, const CoordsXY& pos) const bool highlightPathIssues = (session.ViewFlags & VIEWPORT_FLAG_HIGHLIGHT_PATH_ISSUES); - for (const auto* spr : EntityTileList(pos)) + for (auto* spr : EntityTileList(pos)) { if (highlightPathIssues) { @@ -73,17 +73,6 @@ void EntityPaintSetup(paint_session& session, const CoordsXY& pos) } } - if ((session.ViewFlags & VIEWPORT_FLAG_INVISIBLE_VEHICLES) && spr->Type == EntityType::Vehicle) - { - const auto veh = spr->As(); - if (veh != nullptr) - { - auto ride = get_ride(veh->ride); - if (ride != nullptr) - return; - } - } - const auto entityPos = spr->GetLocation(); // Only paint sprites that are below the clip height and inside the clip selection. @@ -119,7 +108,7 @@ void EntityPaintSetup(paint_session& session, const CoordsXY& pos) image_direction += spr->sprite_direction; image_direction &= 0x1F; - session.CurrentlyDrawnItem = spr; + session.CurrentlyDrawnEntity = spr; session.SpritePosition.x = entityPos.x; session.SpritePosition.y = entityPos.y; session.InteractionType = ViewportInteractionItem::Entity; diff --git a/src/openrct2/paint/Paint.cpp b/src/openrct2/paint/Paint.cpp index 2b3067c0e5..f9f4739bd6 100644 --- a/src/openrct2/paint/Paint.cpp +++ b/src/openrct2/paint/Paint.cpp @@ -57,7 +57,8 @@ static void PaintAttachedPS(rct_drawpixelinfo* dpi, paint_struct* ps, uint32_t v static void PaintPSImageWithBoundingBoxes(rct_drawpixelinfo* dpi, paint_struct* ps, ImageId imageId, int32_t x, int32_t y); static void PaintPSImage(rct_drawpixelinfo* dpi, paint_struct* ps, ImageId imageId, int32_t x, int32_t y); static ImageId PaintPSColourifyImage( - ImageId imageId, ViewportInteractionItem spriteType, EntityType entityType, uint32_t viewFlags); + ImageId imageId, ViewportInteractionItem spriteType, uint32_t viewFlags, const TileElement* tileElement, + const EntityBase* entity); static int32_t RemapPositionToQuadrant(const paint_struct& ps, uint8_t rotation) { @@ -193,7 +194,8 @@ static paint_struct* CreateNormalPaintStruct( ps->sprite_type = session.InteractionType; ps->map_x = session.MapPosition.x; ps->map_y = session.MapPosition.y; - ps->tileElement = reinterpret_cast(const_cast(session.CurrentlyDrawnItem)); + ps->tileElement = session.CurrentlyDrawnTileElement; + ps->entity = session.CurrentlyDrawnEntity; return ps; } @@ -483,17 +485,6 @@ void PaintSessionArrange(PaintSessionCore& session) Guard::Assert(false); } -static EntityType GetEntityTypeFromPaintSession(const paint_struct* ps) -{ - auto entityType = EntityType::Null; - auto* entity = reinterpret_cast(ps->tileElement); - if (entity != nullptr) - { - entityType = entity->Type; - } - return entityType; -} - static void PaintDrawStruct(paint_session& session, paint_struct* ps) { rct_drawpixelinfo* dpi = &session.DPI; @@ -515,8 +506,7 @@ static void PaintDrawStruct(paint_session& session, paint_struct* ps) } } - auto entityType = GetEntityTypeFromPaintSession(ps); - auto imageId = PaintPSColourifyImage(ps->image_id, ps->sprite_type, entityType, session.ViewFlags); + auto imageId = PaintPSColourifyImage(ps->image_id, ps->sprite_type, session.ViewFlags, ps->tileElement, ps->entity); if (gPaintBoundingBoxes && dpi->zoom_level == ZoomLevel{ 0 }) { PaintPSImageWithBoundingBoxes(dpi, ps, imageId, x, y); @@ -566,8 +556,7 @@ static void PaintAttachedPS(rct_drawpixelinfo* dpi, paint_struct* ps, uint32_t v { auto screenCoords = ScreenCoordsXY{ attached_ps->x + ps->x, attached_ps->y + ps->y }; - auto entityType = GetEntityTypeFromPaintSession(ps); - auto imageId = PaintPSColourifyImage(attached_ps->image_id, ps->sprite_type, entityType, viewFlags); + auto imageId = PaintPSColourifyImage(attached_ps->image_id, ps->sprite_type, viewFlags, ps->tileElement, ps->entity); if (attached_ps->flags & PAINT_STRUCT_FLAG_IS_MASKED) { gfx_draw_sprite_raw_masked(dpi, screenCoords, imageId, attached_ps->colour_image_id); @@ -676,19 +665,20 @@ static void PaintPSImage(rct_drawpixelinfo* dpi, paint_struct* ps, ImageId image } static ImageId PaintPSColourifyImage( - ImageId imageId, ViewportInteractionItem spriteType, EntityType entityType, uint32_t viewFlags) + ImageId imageId, ViewportInteractionItem spriteType, uint32_t viewFlags, const TileElement* tileElement, + const EntityBase* entity) { auto seeThrough = imageId.WithTransparancy(FilterPaletteID::PaletteDarken1); if (viewFlags & VIEWPORT_FLAG_SEETHROUGH_RIDES) { if (spriteType == ViewportInteractionItem::Ride) { - return seeThrough; + return (viewFlags & VIEWPORT_FLAG_INVISIBLE_RIDES) ? ImageId() : seeThrough; } } if (viewFlags & VIEWPORT_FLAG_SEETHROUGH_VEHICLES) { - if (spriteType == ViewportInteractionItem::Entity && entityType == EntityType::Vehicle) + if (spriteType == ViewportInteractionItem::Entity && (entity != nullptr && entity->Type == EntityType::Vehicle)) { return (viewFlags & VIEWPORT_FLAG_INVISIBLE_VEHICLES) ? ImageId() : seeThrough; } diff --git a/src/openrct2/paint/Paint.h b/src/openrct2/paint/Paint.h index 4053ebc4dc..19cfde643a 100644 --- a/src/openrct2/paint/Paint.h +++ b/src/openrct2/paint/Paint.h @@ -19,6 +19,7 @@ #include #include +struct EntityBase; struct TileElement; enum class RailingEntrySupportType : uint8_t; enum class ViewportInteractionItem : uint8_t; @@ -50,6 +51,7 @@ struct paint_struct paint_struct* children; paint_struct* next_quadrant_ps; TileElement* tileElement; + EntityBase* entity; ImageId image_id; ImageId colour_image_id; int32_t x; @@ -192,7 +194,8 @@ struct PaintSessionCore paint_string_struct* LastPSString; attached_paint_struct* LastAttachedPS; const TileElement* SurfaceElement; - const void* CurrentlyDrawnItem; + EntityBase* CurrentlyDrawnEntity; + TileElement* CurrentlyDrawnTileElement; const TileElement* PathElementOnSameHeight; const TileElement* TrackElementOnSameHeight; paint_struct* WoodenSupportsPrependTo; diff --git a/src/openrct2/paint/Painter.cpp b/src/openrct2/paint/Painter.cpp index ab5a59349c..3f9289a6e8 100644 --- a/src/openrct2/paint/Painter.cpp +++ b/src/openrct2/paint/Painter.cpp @@ -165,7 +165,8 @@ paint_session* Painter::CreateSession(rct_drawpixelinfo* dpi, uint32_t viewFlags session->PSStringHead = nullptr; session->LastPSString = nullptr; session->WoodenSupportsPrependTo = nullptr; - session->CurrentlyDrawnItem = nullptr; + session->CurrentlyDrawnEntity = nullptr; + session->CurrentlyDrawnTileElement = nullptr; session->SurfaceElement = nullptr; return session; diff --git a/src/openrct2/paint/Supports.cpp b/src/openrct2/paint/Supports.cpp index ce7279a5a1..9a409c7105 100644 --- a/src/openrct2/paint/Supports.cpp +++ b/src/openrct2/paint/Supports.cpp @@ -481,13 +481,12 @@ bool wooden_a_supports_paint_setup( return false; } - if (session.ViewFlags & VIEWPORT_FLAG_INVISIBLE_SUPPORTS) - { - return false; - } - if (session.ViewFlags & VIEWPORT_FLAG_SEETHROUGH_SUPPORTS) { + if (session.ViewFlags & VIEWPORT_FLAG_INVISIBLE_SUPPORTS) + { + return false; + } imageTemplate = ImageId().WithTransparancy(FilterPaletteID::PaletteDarken1); } @@ -643,13 +642,12 @@ bool wooden_b_supports_paint_setup( return false; } - if (session.ViewFlags & VIEWPORT_FLAG_INVISIBLE_SUPPORTS) - { - return false; - } - if (session.ViewFlags & VIEWPORT_FLAG_SEETHROUGH_SUPPORTS) { + if (session.ViewFlags & VIEWPORT_FLAG_INVISIBLE_SUPPORTS) + { + return false; + } imageTemplate = ImageId().WithTransparancy(FilterPaletteID::PaletteDarken1); } @@ -818,13 +816,12 @@ bool metal_a_supports_paint_setup( return false; } - if (session.ViewFlags & VIEWPORT_FLAG_INVISIBLE_SUPPORTS) - { - return false; - } - if (session.ViewFlags & VIEWPORT_FLAG_SEETHROUGH_SUPPORTS) { + if (session.ViewFlags & VIEWPORT_FLAG_INVISIBLE_SUPPORTS) + { + return false; + } imageColourFlags = ImageId(0).WithTransparancy(FilterPaletteID::PaletteDarken1).ToUInt32(); } @@ -1022,13 +1019,12 @@ bool metal_b_supports_paint_setup( return false; // AND } - if (session.ViewFlags & VIEWPORT_FLAG_INVISIBLE_SUPPORTS) - { - return false; - } - if (session.ViewFlags & VIEWPORT_FLAG_SEETHROUGH_SUPPORTS) { + if (session.ViewFlags & VIEWPORT_FLAG_INVISIBLE_SUPPORTS) + { + return false; + } imageColourFlags = ImageId(0).WithTransparancy(FilterPaletteID::PaletteDarken1).ToUInt32(); } @@ -1207,13 +1203,12 @@ bool path_a_supports_paint_setup( return false; } - if (session.ViewFlags & VIEWPORT_FLAG_INVISIBLE_SUPPORTS) - { - return false; - } - if (session.ViewFlags & VIEWPORT_FLAG_SEETHROUGH_SUPPORTS) { + if (session.ViewFlags & VIEWPORT_FLAG_INVISIBLE_SUPPORTS) + { + return false; + } imageTemplate = ImageId().WithTransparancy(FilterPaletteID::PaletteDarken1); } @@ -1362,13 +1357,12 @@ bool path_b_supports_paint_setup( return false; } - if (session.ViewFlags & VIEWPORT_FLAG_INVISIBLE_SUPPORTS) - { - return false; - } - if (session.ViewFlags & VIEWPORT_FLAG_SEETHROUGH_SUPPORTS) { + if (session.ViewFlags & VIEWPORT_FLAG_INVISIBLE_SUPPORTS) + { + return false; + } imageTemplate = ImageId().WithTransparancy(FilterPaletteID::PaletteDarken1); } diff --git a/src/openrct2/paint/tile_element/Paint.Entrance.cpp b/src/openrct2/paint/tile_element/Paint.Entrance.cpp index 12f7623e8f..c30394c164 100644 --- a/src/openrct2/paint/tile_element/Paint.Entrance.cpp +++ b/src/openrct2/paint/tile_element/Paint.Entrance.cpp @@ -125,9 +125,6 @@ static void PaintRideEntranceExit(paint_session& session, uint8_t direction, int return; } - if ((session.ViewFlags & VIEWPORT_FLAG_SEETHROUGH_RIDES) && (session.ViewFlags & VIEWPORT_FLAG_INVISIBLE_RIDES)) - return; - auto stationObj = ride->GetStationObject(); if (stationObj == nullptr || stationObj->BaseImageId == ImageIndexUndefined) { diff --git a/src/openrct2/paint/tile_element/Paint.TileElement.cpp b/src/openrct2/paint/tile_element/Paint.TileElement.cpp index 9a3e93dc7d..d1ad543fc0 100644 --- a/src/openrct2/paint/tile_element/Paint.TileElement.cpp +++ b/src/openrct2/paint/tile_element/Paint.TileElement.cpp @@ -140,7 +140,7 @@ static void PaintTileElementBase(paint_session& session, const CoordsXY& origCoo session.MapPosition.x = coords.x; session.MapPosition.y = coords.y; - const TileElement* tile_element = map_get_first_element_at(session.MapPosition); + auto* tile_element = map_get_first_element_at(session.MapPosition); if (tile_element == nullptr) return; uint8_t rotation = session.CurrentRotation; @@ -263,7 +263,7 @@ static void PaintTileElementBase(paint_session& session, const CoordsXY& origCoo } CoordsXY mapPosition = session.MapPosition; - session.CurrentlyDrawnItem = tile_element; + session.CurrentlyDrawnTileElement = tile_element; // Setup the painting of for example: the underground, signs, rides, scenery, etc. switch (tile_element->GetType()) { diff --git a/src/openrct2/ride/TrackPaint.cpp b/src/openrct2/ride/TrackPaint.cpp index 41d6ddd55f..04fac377a4 100644 --- a/src/openrct2/ride/TrackPaint.cpp +++ b/src/openrct2/ride/TrackPaint.cpp @@ -2195,9 +2195,6 @@ void PaintTrack(paint_session& session, Direction direction, int32_t height, con return; } - if ((session.ViewFlags & VIEWPORT_FLAG_SEETHROUGH_RIDES) && (session.ViewFlags & VIEWPORT_FLAG_INVISIBLE_RIDES)) - return; - if ((!gTrackDesignSaveMode || rideIndex == gTrackDesignSaveRideIndex) && !(session.ViewFlags & VIEWPORT_FLAG_HIGHLIGHT_PATH_ISSUES)) { diff --git a/src/openrct2/ride/gentle/Circus.cpp b/src/openrct2/ride/gentle/Circus.cpp index 57b5c48add..20d09ea45c 100644 --- a/src/openrct2/ride/gentle/Circus.cpp +++ b/src/openrct2/ride/gentle/Circus.cpp @@ -11,6 +11,7 @@ #include "../../interface/Viewport.h" #include "../../paint/Paint.h" #include "../../paint/Supports.h" +#include "../../ride/Vehicle.h" #include "../Ride.h" #include "../RideEntry.h" #include "../Track.h" @@ -18,8 +19,6 @@ static void PaintCircusTent(paint_session& session, const Ride& ride, uint8_t direction, int8_t al, int8_t cl, uint16_t height) { - const TileElement* savedTileElement = static_cast(session.CurrentlyDrawnItem); - auto rideEntry = ride.GetRideEntry(); if (rideEntry == nullptr) return; @@ -28,7 +27,7 @@ static void PaintCircusTent(paint_session& session, const Ride& ride, uint8_t di if (ride.lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK && vehicle != nullptr) { session.InteractionType = ViewportInteractionItem::Entity; - session.CurrentlyDrawnItem = vehicle; + session.CurrentlyDrawnEntity = vehicle; } auto imageTemplate = ImageId(0, ride.vehicle_colours[0].Body, ride.vehicle_colours[0].Trim); @@ -42,7 +41,7 @@ static void PaintCircusTent(paint_session& session, const Ride& ride, uint8_t di PaintAddImageAsParent( session, imageTemplate.WithIndex(imageIndex), { al, cl, height + 3 }, { 24, 24, 47 }, { al + 16, cl + 16, height + 3 }); - session.CurrentlyDrawnItem = savedTileElement; + session.CurrentlyDrawnEntity = nullptr; session.InteractionType = ViewportInteractionItem::Ride; } diff --git a/src/openrct2/ride/gentle/CrookedHouse.cpp b/src/openrct2/ride/gentle/CrookedHouse.cpp index 43fbe1fc18..b133a461d2 100644 --- a/src/openrct2/ride/gentle/CrookedHouse.cpp +++ b/src/openrct2/ride/gentle/CrookedHouse.cpp @@ -11,6 +11,7 @@ #include "../../interface/Viewport.h" #include "../../paint/Paint.h" #include "../../paint/Supports.h" +#include "../../ride/Vehicle.h" #include "../Ride.h" #include "../RideEntry.h" #include "../Track.h" @@ -52,9 +53,11 @@ static constexpr const rct_crooked_house_bound_box crooked_house_data[] = { static void PaintCrookedHouseStructure( paint_session& session, uint8_t direction, int32_t x_offset, int32_t y_offset, uint32_t segment, int32_t height) { - const TileElement* original_tile_element = static_cast(session.CurrentlyDrawnItem); + const auto* tileElement = session.CurrentlyDrawnTileElement; + if (tileElement == nullptr) + return; - auto ride = get_ride(original_tile_element->AsTrack()->GetRideIndex()); + auto ride = get_ride(tileElement->AsTrack()->GetRideIndex()); if (ride == nullptr) return; @@ -68,7 +71,7 @@ static void PaintCrookedHouseStructure( if (vehicle != nullptr) { session.InteractionType = ViewportInteractionItem::Entity; - session.CurrentlyDrawnItem = vehicle; + session.CurrentlyDrawnEntity = vehicle; } } @@ -78,6 +81,8 @@ static void PaintCrookedHouseStructure( PaintAddImageAsParent( session, imageTemplate.WithIndex(imageIndex), { x_offset, y_offset, height + 3 }, { boundBox.length, 127 }, { boundBox.offset, height + 3 }); + + session.CurrentlyDrawnEntity = nullptr; } static void PaintCrookedHouse( diff --git a/src/openrct2/ride/gentle/FerrisWheel.cpp b/src/openrct2/ride/gentle/FerrisWheel.cpp index 89714ca3ea..fdfbd1d899 100644 --- a/src/openrct2/ride/gentle/FerrisWheel.cpp +++ b/src/openrct2/ride/gentle/FerrisWheel.cpp @@ -66,8 +66,6 @@ static void PaintFerrisWheelRiders( static void PaintFerrisWheelStructure( paint_session& session, const Ride& ride, uint8_t direction, int8_t axisOffset, uint16_t height) { - const TileElement* savedTileElement = static_cast(session.CurrentlyDrawnItem); - auto rideEntry = ride.GetRideEntry(); if (rideEntry == nullptr) return; @@ -76,7 +74,7 @@ static void PaintFerrisWheelStructure( if (ride.lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK && vehicle != nullptr) { session.InteractionType = ViewportInteractionItem::Entity; - session.CurrentlyDrawnItem = vehicle; + session.CurrentlyDrawnEntity = vehicle; } const auto& boundBox = FerrisWheelData[direction]; @@ -105,7 +103,7 @@ static void PaintFerrisWheelStructure( } PaintAddImageAsChild(session, rightSupportImageId, offset, bbLength, bbOffset); - session.CurrentlyDrawnItem = savedTileElement; + session.CurrentlyDrawnEntity = nullptr; session.InteractionType = ViewportInteractionItem::Ride; } diff --git a/src/openrct2/ride/gentle/HauntedHouse.cpp b/src/openrct2/ride/gentle/HauntedHouse.cpp index 1c580ed9ba..be20b24dda 100644 --- a/src/openrct2/ride/gentle/HauntedHouse.cpp +++ b/src/openrct2/ride/gentle/HauntedHouse.cpp @@ -31,8 +31,6 @@ static constexpr haunted_house_bound_box haunted_house_data[] = { static void PaintHauntedHouseStructure( paint_session& session, const Ride& ride, uint8_t direction, int8_t xOffset, int8_t yOffset, uint8_t part, uint16_t height) { - const TileElement* savedTileElement = static_cast(session.CurrentlyDrawnItem); - uint8_t frameNum = 0; auto rideEntry = ride.GetRideEntry(); @@ -43,7 +41,7 @@ static void PaintHauntedHouseStructure( if (ride.lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK && vehicle != nullptr) { session.InteractionType = ViewportInteractionItem::Entity; - session.CurrentlyDrawnItem = vehicle; + session.CurrentlyDrawnEntity = vehicle; frameNum = vehicle->Pitch; } @@ -63,7 +61,7 @@ static void PaintHauntedHouseStructure( { boundBox.length.x, boundBox.length.y, 127 }, { boundBox.offset.x, boundBox.offset.y, height }); } - session.CurrentlyDrawnItem = savedTileElement; + session.CurrentlyDrawnEntity = nullptr; session.InteractionType = ViewportInteractionItem::Ride; } diff --git a/src/openrct2/ride/gentle/MerryGoRound.cpp b/src/openrct2/ride/gentle/MerryGoRound.cpp index a5292ebad1..e85f702888 100644 --- a/src/openrct2/ride/gentle/MerryGoRound.cpp +++ b/src/openrct2/ride/gentle/MerryGoRound.cpp @@ -53,7 +53,6 @@ static void PaintRiders( static void PaintCarousel( paint_session& session, const Ride& ride, uint8_t direction, int8_t xOffset, int8_t yOffset, uint16_t height) { - const TileElement* savedTileElement = static_cast(session.CurrentlyDrawnItem); height += 7; auto rideEntry = ride.GetRideEntry(); @@ -64,7 +63,7 @@ static void PaintCarousel( if (ride.lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK && vehicle != nullptr) { session.InteractionType = ViewportInteractionItem::Entity; - session.CurrentlyDrawnItem = vehicle; + session.CurrentlyDrawnEntity = vehicle; if (ride.lifecycle_flags & (RIDE_LIFECYCLE_BREAKDOWN_PENDING | RIDE_LIFECYCLE_BROKEN_DOWN) && ride.breakdown_reason_pending == BREAKDOWN_CONTROL_FAILURE && ride.breakdown_sound_modifier >= 128) @@ -96,7 +95,7 @@ static void PaintCarousel( PaintRiders(session, ride, *rideEntry, *vehicle, rotationOffset, offset, bbLength, bbOffset); - session.CurrentlyDrawnItem = savedTileElement; + session.CurrentlyDrawnEntity = nullptr; session.InteractionType = ViewportInteractionItem::Ride; } diff --git a/src/openrct2/ride/gentle/SpaceRings.cpp b/src/openrct2/ride/gentle/SpaceRings.cpp index cb8b51957d..d992e2b89b 100644 --- a/src/openrct2/ride/gentle/SpaceRings.cpp +++ b/src/openrct2/ride/gentle/SpaceRings.cpp @@ -36,8 +36,6 @@ static constexpr const uint32_t space_rings_fence_sprites[] = { static void paint_space_rings_structure( paint_session& session, const Ride& ride, uint8_t direction, uint32_t segment, int32_t height) { - const TileElement* savedTileElement = static_cast(session.CurrentlyDrawnItem); - uint32_t vehicleIndex = (segment - direction) & 0x3; if (ride.num_stations == 0 || vehicleIndex < ride.num_vehicles) @@ -51,7 +49,7 @@ static void paint_space_rings_structure( if (ride.lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK && vehicle != nullptr) { session.InteractionType = ViewportInteractionItem::Entity; - session.CurrentlyDrawnItem = vehicle; + session.CurrentlyDrawnEntity = vehicle; frameNum += static_cast(vehicle->Pitch) * 4; } @@ -82,7 +80,7 @@ static void paint_space_rings_structure( } } - session.CurrentlyDrawnItem = savedTileElement; + session.CurrentlyDrawnEntity = nullptr; session.InteractionType = ViewportInteractionItem::Ride; } diff --git a/src/openrct2/ride/thrill/3dCinema.cpp b/src/openrct2/ride/thrill/3dCinema.cpp index 5be7aadac0..1444f0e039 100644 --- a/src/openrct2/ride/thrill/3dCinema.cpp +++ b/src/openrct2/ride/thrill/3dCinema.cpp @@ -15,12 +15,11 @@ #include "../RideEntry.h" #include "../Track.h" #include "../TrackPaint.h" +#include "../Vehicle.h" static void Paint3dCinemaDome( paint_session& session, const Ride& ride, uint8_t direction, int8_t xOffset, int8_t yOffset, uint16_t height) { - const TileElement* savedTileElement = static_cast(session.CurrentlyDrawnItem); - auto rideEntry = ride.GetRideEntry(); if (rideEntry == nullptr) return; @@ -28,7 +27,7 @@ static void Paint3dCinemaDome( if (ride.lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK && !ride.vehicles[0].IsNull()) { session.InteractionType = ViewportInteractionItem::Entity; - session.CurrentlyDrawnItem = GetEntity(ride.vehicles[0]); + session.CurrentlyDrawnEntity = GetEntity(ride.vehicles[0]); } auto imageTemplate = ImageId(0, ride.vehicle_colours[0].Body, ride.vehicle_colours[0].Trim); @@ -42,7 +41,7 @@ static void Paint3dCinemaDome( PaintAddImageAsParent( session, imageId, { xOffset, yOffset, height + 3 }, { 24, 24, 47 }, { xOffset + 16, yOffset + 16, height + 3 }); - session.CurrentlyDrawnItem = savedTileElement; + session.CurrentlyDrawnEntity = nullptr; session.InteractionType = ViewportInteractionItem::Ride; } diff --git a/src/openrct2/ride/thrill/Enterprise.cpp b/src/openrct2/ride/thrill/Enterprise.cpp index 5cb2646d33..c00bf57e35 100644 --- a/src/openrct2/ride/thrill/Enterprise.cpp +++ b/src/openrct2/ride/thrill/Enterprise.cpp @@ -44,7 +44,6 @@ static void PaintEnterpriseRiders( static void PaintEnterpriseStructure( paint_session& session, const Ride& ride, int8_t xOffset, int8_t yOffset, uint16_t height, const TrackElement& trackElement) { - const TileElement* savedTileElement = static_cast(session.CurrentlyDrawnItem); const auto* rideEntry = get_ride_entry(ride.subtype); if (rideEntry == nullptr) return; @@ -56,7 +55,7 @@ static void PaintEnterpriseStructure( if (vehicle != nullptr) { session.InteractionType = ViewportInteractionItem::Entity; - session.CurrentlyDrawnItem = vehicle; + session.CurrentlyDrawnEntity = vehicle; } } @@ -84,7 +83,7 @@ static void PaintEnterpriseStructure( PaintEnterpriseRiders(session, *rideEntry, *vehicle, imageOffset, offset, bbLength, bbOffset); } - session.CurrentlyDrawnItem = savedTileElement; + session.CurrentlyDrawnEntity = nullptr; session.InteractionType = ViewportInteractionItem::Ride; } diff --git a/src/openrct2/ride/thrill/MagicCarpet.cpp b/src/openrct2/ride/thrill/MagicCarpet.cpp index b0a3c32dd6..8406e95ee7 100644 --- a/src/openrct2/ride/thrill/MagicCarpet.cpp +++ b/src/openrct2/ride/thrill/MagicCarpet.cpp @@ -94,7 +94,7 @@ static ImageIndex GetMagicCarpetPendulumImage(Plane plane, Direction direction, return imageIndex; } -static const Vehicle* GetFirstVehicle(const Ride& ride) +static Vehicle* GetFirstVehicle(const Ride& ride) { if (ride.lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK) { @@ -193,15 +193,13 @@ static void PaintMagicCarpetVehicle( static void PaintMagicCarpetStructure( paint_session& session, const Ride& ride, uint8_t direction, int8_t axisOffset, uint16_t height) { - const TileElement* savedTileElement = static_cast(session.CurrentlyDrawnItem); - auto swing = 0; auto* vehicle = GetFirstVehicle(ride); if (vehicle != nullptr) { swing = vehicle->Pitch; session.InteractionType = ViewportInteractionItem::Entity; - session.CurrentlyDrawnItem = vehicle; + session.CurrentlyDrawnEntity = vehicle; } bound_box bb = MagicCarpetBounds[direction]; @@ -222,8 +220,8 @@ static void PaintMagicCarpetStructure( PaintMagicCarpetPendulum(session, Plane::Front, swing, direction, offset, bbOffset, bbSize); PaintMagicCarpetFrame(session, Plane::Front, direction, offset, bbOffset, bbSize); + session.CurrentlyDrawnEntity = nullptr; session.InteractionType = ViewportInteractionItem::Ride; - session.CurrentlyDrawnItem = savedTileElement; } static void PaintMagicCarpet( diff --git a/src/openrct2/ride/thrill/MotionSimulator.cpp b/src/openrct2/ride/thrill/MotionSimulator.cpp index aa7128709f..cb31c5520b 100644 --- a/src/openrct2/ride/thrill/MotionSimulator.cpp +++ b/src/openrct2/ride/thrill/MotionSimulator.cpp @@ -37,7 +37,6 @@ static void PaintMotionSimulatorVehicle( if (rideEntry == nullptr) return; - const TileElement* savedTileElement = static_cast(session.CurrentlyDrawnItem); CoordsXYZ offset(offsetX, offsetY, height + 2); Vehicle* vehicle = nullptr; @@ -47,7 +46,7 @@ static void PaintMotionSimulatorVehicle( if (vehicle != nullptr) { session.InteractionType = ViewportInteractionItem::Entity; - session.CurrentlyDrawnItem = vehicle; + session.CurrentlyDrawnEntity = vehicle; } } @@ -97,7 +96,7 @@ static void PaintMotionSimulatorVehicle( break; } - session.CurrentlyDrawnItem = savedTileElement; + session.CurrentlyDrawnEntity = nullptr; session.InteractionType = ViewportInteractionItem::Ride; } diff --git a/src/openrct2/ride/thrill/SwingingInverterShip.cpp b/src/openrct2/ride/thrill/SwingingInverterShip.cpp index cdd959e53a..d57836bc69 100644 --- a/src/openrct2/ride/thrill/SwingingInverterShip.cpp +++ b/src/openrct2/ride/thrill/SwingingInverterShip.cpp @@ -68,8 +68,6 @@ static constexpr const uint32_t SwingingInverterShipFrameSprites[] = { static void PaintSwingingInverterShipStructure( paint_session& session, const Ride& ride, uint8_t direction, int8_t axisOffset, uint16_t height) { - const TileElement* savedTileElement = static_cast(session.CurrentlyDrawnItem); - rct_ride_entry* rideEntry = get_ride_entry(ride.subtype); if (rideEntry == nullptr) return; @@ -86,7 +84,7 @@ static void PaintSwingingInverterShipStructure( if (vehicle != nullptr) { session.InteractionType = ViewportInteractionItem::Entity; - session.CurrentlyDrawnItem = vehicle; + session.CurrentlyDrawnEntity = vehicle; } } @@ -130,7 +128,7 @@ static void PaintSwingingInverterShipStructure( PaintAddImageAsChild(session, vehicleImageId, offset, bbLength, bbOffset); } - session.CurrentlyDrawnItem = savedTileElement; + session.CurrentlyDrawnEntity = nullptr; session.InteractionType = ViewportInteractionItem::Ride; } diff --git a/src/openrct2/ride/thrill/SwingingShip.cpp b/src/openrct2/ride/thrill/SwingingShip.cpp index 9b1c613fbc..d7aba79122 100644 --- a/src/openrct2/ride/thrill/SwingingShip.cpp +++ b/src/openrct2/ride/thrill/SwingingShip.cpp @@ -94,8 +94,6 @@ static void PaintSwingingShipRiders( static void PaintSwingingShipStructure( paint_session& session, const Ride& ride, uint8_t direction, int8_t axisOffset, uint16_t height) { - const TileElement* savedTileElement = static_cast(session.CurrentlyDrawnItem); - rct_ride_entry* rideEntry = get_ride_entry(ride.subtype); if (rideEntry == nullptr) return; @@ -105,7 +103,7 @@ static void PaintSwingingShipStructure( { vehicle = GetEntity(ride.vehicles[0]); session.InteractionType = ViewportInteractionItem::Entity; - session.CurrentlyDrawnItem = vehicle; + session.CurrentlyDrawnEntity = vehicle; } const auto& bounds = SwingingShipData[direction]; @@ -157,7 +155,7 @@ static void PaintSwingingShipStructure( imageId = supportsImageTemplate.WithIndex(SwingingShipFrameSprites[(direction & 1)][1]); PaintAddImageAsChild(session, imageId, offset, bbLength, bbOffset); - session.CurrentlyDrawnItem = savedTileElement; + session.CurrentlyDrawnEntity = nullptr; session.InteractionType = ViewportInteractionItem::Ride; } diff --git a/src/openrct2/ride/thrill/TopSpin.cpp b/src/openrct2/ride/thrill/TopSpin.cpp index 5d53d8ef8a..ea818c6a61 100644 --- a/src/openrct2/ride/thrill/TopSpin.cpp +++ b/src/openrct2/ride/thrill/TopSpin.cpp @@ -124,18 +124,14 @@ static void PaintTopSpinVehicle( const auto& vehicleEntry = rideEntry->vehicles[0]; - // As we will be drawing a vehicle we need to backup the trackElement that - // is assigned to the drawings. - const TileElement* curTileElement = static_cast(session.CurrentlyDrawnItem); - height += 3; uint8_t seatRotation = 0; uint8_t armRotation = 0; - const auto* vehicle = GetEntity(ride.vehicles[0]); + auto* vehicle = GetEntity(ride.vehicles[0]); if (ride.lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK && vehicle != nullptr) { session.InteractionType = ViewportInteractionItem::Entity; - session.CurrentlyDrawnItem = vehicle; + session.CurrentlyDrawnEntity = vehicle; armRotation = vehicle->Pitch; seatRotation = vehicle->bank_rotation; @@ -181,7 +177,7 @@ static void PaintTopSpinVehicle( imageIndex = vehicleEntry.base_image_id + 573 + ((direction & 1) << 1); PaintAddImageAsChild(session, supportImageTemplate.WithIndex(imageIndex), offset, bbLength, bbOffset); - session.CurrentlyDrawnItem = curTileElement; + session.CurrentlyDrawnEntity = nullptr; session.InteractionType = ViewportInteractionItem::Ride; } diff --git a/src/openrct2/ride/thrill/Twist.cpp b/src/openrct2/ride/thrill/Twist.cpp index bff5fa967e..af5222a014 100644 --- a/src/openrct2/ride/thrill/Twist.cpp +++ b/src/openrct2/ride/thrill/Twist.cpp @@ -22,8 +22,6 @@ static void paint_twist_structure( paint_session& session, const Ride& ride, uint8_t direction, int8_t xOffset, int8_t yOffset, uint16_t height) { - const TileElement* savedTileElement = static_cast(session.CurrentlyDrawnItem); - rct_ride_entry* rideEntry = get_ride_entry(ride.subtype); Vehicle* vehicle = nullptr; @@ -39,7 +37,7 @@ static void paint_twist_structure( vehicle = GetEntity(ride.vehicles[0]); session.InteractionType = ViewportInteractionItem::Entity; - session.CurrentlyDrawnItem = vehicle; + session.CurrentlyDrawnEntity = vehicle; } uint32_t frameNum = (direction * 88) % 216; @@ -75,7 +73,7 @@ static void paint_twist_structure( } } - session.CurrentlyDrawnItem = savedTileElement; + session.CurrentlyDrawnEntity = nullptr; session.InteractionType = ViewportInteractionItem::Ride; } diff --git a/src/openrct2/ride/water/SplashBoats.cpp b/src/openrct2/ride/water/SplashBoats.cpp index 6f1df3e7f1..bebc25d7e1 100644 --- a/src/openrct2/ride/water/SplashBoats.cpp +++ b/src/openrct2/ride/water/SplashBoats.cpp @@ -1268,23 +1268,17 @@ void vehicle_visual_splash_boats_or_water_coaster( paint_session& session, int32_t x, int32_t imageDirection, int32_t y, int32_t z, const Vehicle* vehicle, const rct_ride_entry_vehicle* vehicleEntry) { - if (vehicle->IsHead()) - { - vehicle = GetEntity(vehicle->next_vehicle_on_ride); - } - else - { - vehicle = GetEntity(vehicle->prev_vehicle_on_ride); - } - if (vehicle == nullptr) + auto* vehicleToPaint = vehicle->IsHead() ? GetEntity(vehicle->next_vehicle_on_ride) + : GetEntity(vehicle->prev_vehicle_on_ride); + if (vehicleToPaint == nullptr) { return; } - session.CurrentlyDrawnItem = vehicle; - imageDirection = ((session.CurrentRotation * 8) + vehicle->sprite_direction) & 0x1F; - session.SpritePosition.x = vehicle->x; - session.SpritePosition.y = vehicle->y; - vehicle->Paint(session, imageDirection); + session.CurrentlyDrawnEntity = vehicleToPaint; + imageDirection = ((session.CurrentRotation * 8) + vehicle->sprite_direction) & 0x1F; + session.SpritePosition.x = vehicleToPaint->x; + session.SpritePosition.y = vehicleToPaint->y; + vehicleToPaint->Paint(session, imageDirection); } #endif diff --git a/test/testpaint/TestTrack.cpp b/test/testpaint/TestTrack.cpp index 6753fab615..b37ab30907 100644 --- a/test/testpaint/TestTrack.cpp +++ b/test/testpaint/TestTrack.cpp @@ -273,7 +273,7 @@ static uint8_t TestTrackElementPaintCalls(uint8_t rideType, uint8_t trackType, u gSurfaceElement = &surfaceElement; gDidPassSurface = true; - gPaintSession.CurrentlyDrawnItem = &tileElement; + gPaintSession.CurrentlyDrawnTileElement = &tileElement; gPaintSession.SurfaceElement = &surfaceElement; gPaintSession.DidPassSurface = true; @@ -436,7 +436,7 @@ static uint8_t TestTrackElementSegmentSupportHeight( gSurfaceElement = &surfaceElement; gDidPassSurface = true; - gPaintSession.CurrentlyDrawnItem = &tileElement; + gPaintSession.CurrentlyDrawnTileElement = &tileElement; gPaintSession.SurfaceElement = &surfaceElement; gPaintSession.DidPassSurface = true; @@ -523,7 +523,7 @@ static uint8_t TestTrackElementGeneralSupportHeight( gSurfaceElement = &surfaceElement; gDidPassSurface = true; - gPaintSession.CurrentlyDrawnItem = &tileElement; + gPaintSession.CurrentlyDrawnTileElement = &tileElement; gPaintSession.SurfaceElement = &surfaceElement; gPaintSession.DidPassSurface = true; @@ -624,7 +624,7 @@ static uint8_t TestTrackElementSideTunnels(uint8_t rideType, uint8_t trackType, gSurfaceElement = &surfaceElement; gDidPassSurface = true; - gPaintSession.CurrentlyDrawnItem = &tileElement; + gPaintSession.CurrentlyDrawnTileElement = &tileElement; gPaintSession.SurfaceElement = &surfaceElement; gPaintSession.DidPassSurface = true; @@ -752,7 +752,7 @@ static uint8_t TestTrackElementVerticalTunnels(uint8_t rideType, uint8_t trackTy gSurfaceElement = &surfaceElement; gDidPassSurface = true; - gPaintSession.CurrentlyDrawnItem = &tileElement; + gPaintSession.CurrentlyDrawnTileElement = &tileElement; gPaintSession.SurfaceElement = &surfaceElement; gPaintSession.DidPassSurface = true;