From b759f9ab3991cc5dd3a6f90df91752385a4adfec Mon Sep 17 00:00:00 2001 From: Ted John Date: Sun, 5 Dec 2021 01:38:56 +0000 Subject: [PATCH] Refactor paint motion simulator to use ImageId --- src/openrct2/ride/thrill/MotionSimulator.cpp | 126 +++++++------------ 1 file changed, 43 insertions(+), 83 deletions(-) diff --git a/src/openrct2/ride/thrill/MotionSimulator.cpp b/src/openrct2/ride/thrill/MotionSimulator.cpp index 0aced31623..d3ed8a4fa1 100644 --- a/src/openrct2/ride/thrill/MotionSimulator.cpp +++ b/src/openrct2/ride/thrill/MotionSimulator.cpp @@ -29,110 +29,71 @@ enum SPR_MOTION_SIMULATOR_STAIRS_RAIL_R3 = 22161, }; -/** - * - * rct2: 0x0076522A - */ -static void paint_motionsimulator_vehicle( - paint_session* session, const Ride* ride, int8_t offsetX, int8_t offsetY, uint8_t direction, int32_t height, +static void PaintMotionSimulatorVehicle( + paint_session* session, const Ride& ride, int8_t offsetX, int8_t offsetY, uint8_t direction, int32_t height, const TrackElement& trackElement) { - if (ride == nullptr) - return; - - auto rideEntry = ride->GetRideEntry(); + auto rideEntry = ride.GetRideEntry(); if (rideEntry == nullptr) return; const TileElement* savedTileElement = static_cast(session->CurrentlyDrawnItem); + CoordsXYZ offset(offsetX, offsetY, height + 2); Vehicle* vehicle = nullptr; - if (ride->lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK) + if (ride.lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK) { - uint16_t spriteIndex = ride->vehicles[0]; - if (spriteIndex != SPRITE_INDEX_NULL) + vehicle = GetEntity(ride.vehicles[0]); + if (vehicle != nullptr) { - vehicle = GetEntity(spriteIndex); session->InteractionType = ViewportInteractionItem::Entity; session->CurrentlyDrawnItem = vehicle; } } - uint32_t simulatorImageId = rideEntry->vehicles[0].base_image_id + direction; + auto imageIndex = rideEntry->vehicles[0].base_image_id + direction; if (vehicle != nullptr) { if (vehicle->restraints_position >= 64) { - simulatorImageId += (vehicle->restraints_position >> 6) << 2; + imageIndex += (vehicle->restraints_position >> 6) << 2; } else { - simulatorImageId += vehicle->Pitch * 4; + imageIndex += vehicle->Pitch * 4; } } - uint32_t imageColourFlags = session->TrackColours[SCHEME_MISC]; - if (imageColourFlags == IMAGE_TYPE_REMAP) + auto imageTemplate = ImageId(0, ride.vehicle_colours[0].Body, ride.vehicle_colours[0].Trim); + auto imageFlags = session->TrackColours[SCHEME_MISC]; + if (imageFlags != IMAGE_TYPE_REMAP) { - imageColourFlags = SPRITE_ID_PALETTE_COLOUR_2(ride->vehicle_colours[0].Body, ride->vehicle_colours[0].Trim); + imageTemplate = ImageId::FromUInt32(imageFlags); } - simulatorImageId |= imageColourFlags; - - int16_t offsetZ = height + 2; - uint32_t imageId; + auto simulatorImageId = imageTemplate.WithIndex(imageIndex); + auto stairsImageId = imageTemplate.WithIndex(SPR_MOTION_SIMULATOR_STAIRS_R0 + direction); + auto stairsRailImageId = imageTemplate.WithIndex(SPR_MOTION_SIMULATOR_STAIRS_RAIL_R0 + direction); switch (direction) { case 0: - // Simulator - imageId = simulatorImageId; - PaintAddImageAsParent( - session, imageId, { offsetX, offsetY, offsetZ }, { 20, 20, 44 }, { offsetX, offsetY, offsetZ }); - // Stairs - imageId = (SPR_MOTION_SIMULATOR_STAIRS_R0 + direction) | session->TrackColours[SCHEME_MISC]; - PaintAddImageAsChild(session, imageId, offsetX, offsetY, 20, 20, 44, offsetZ, offsetX, offsetY, offsetZ); - // Stairs (rail) - imageId = (SPR_MOTION_SIMULATOR_STAIRS_RAIL_R0 + direction) | session->TrackColours[SCHEME_MISC]; - PaintAddImageAsParent( - session, imageId, { offsetX, offsetY, offsetZ }, { 20, 2, 44 }, { offsetX, offsetY + 32, offsetZ }); + PaintAddImageAsParent(session, simulatorImageId, offset, { 20, 20, 44 }, offset); + PaintAddImageAsChild(session, stairsImageId, offset, { 20, 20, 44 }, offset); + PaintAddImageAsParent(session, stairsRailImageId, offset, { 20, 2, 44 }, { offset.x, offset.y + 32, offset.z }); break; case 1: - // Simulator - imageId = simulatorImageId; - PaintAddImageAsParent( - session, imageId, { offsetX, offsetY, offsetZ }, { 20, 20, 44 }, { offsetX, offsetY, offsetZ }); - // Stairs - imageId = (SPR_MOTION_SIMULATOR_STAIRS_R0 + direction) | session->TrackColours[SCHEME_MISC]; - PaintAddImageAsChild(session, imageId, offsetX, offsetY, 20, 20, 44, offsetZ, offsetX, offsetY, offsetZ); - // Stairs (rail) - imageId = (SPR_MOTION_SIMULATOR_STAIRS_RAIL_R0 + direction) | session->TrackColours[SCHEME_MISC]; - PaintAddImageAsParent( - session, imageId, { offsetX, offsetY, offsetZ }, { 2, 20, 44 }, { offsetX + 34, offsetY, offsetZ }); + PaintAddImageAsParent(session, simulatorImageId, offset, { 20, 20, 44 }, offset); + PaintAddImageAsChild(session, stairsImageId, offset, { 20, 20, 44 }, offset); + PaintAddImageAsParent(session, stairsRailImageId, offset, { 2, 20, 44 }, { offset.x + 34, offset.y, offset.z }); break; case 2: - // Stairs (rail) - imageId = (SPR_MOTION_SIMULATOR_STAIRS_RAIL_R0 + direction) | session->TrackColours[SCHEME_MISC]; - PaintAddImageAsParent( - session, imageId, { offsetX, offsetY, offsetZ }, { 20, 2, 44 }, { offsetX, offsetY - 10, offsetZ }); - // Stairs - imageId = (SPR_MOTION_SIMULATOR_STAIRS_R0 + direction) | session->TrackColours[SCHEME_MISC]; - PaintAddImageAsParent( - session, imageId, { offsetX, offsetY, offsetZ }, { 20, 20, 44 }, { offsetX, offsetY + 5, offsetZ }); - // Simulator - imageId = simulatorImageId; - PaintAddImageAsChild(session, imageId, offsetX, offsetY, 20, 20, 44, offsetZ, offsetX, offsetY + 5, offsetZ); + PaintAddImageAsParent(session, stairsRailImageId, offset, { 20, 2, 44 }, { offset.x, offset.y - 10, offset.z }); + PaintAddImageAsParent(session, stairsImageId, offset, { 20, 20, 44 }, { offset.x, offset.y + 5, offset.z }); + PaintAddImageAsChild(session, simulatorImageId, offset, { 20, 20, 44 }, { offset.x, offset.y + 5, offset.z }); break; case 3: - // Stairs (rail) - imageId = (SPR_MOTION_SIMULATOR_STAIRS_RAIL_R0 + direction) | session->TrackColours[SCHEME_MISC]; - PaintAddImageAsParent( - session, imageId, { offsetX, offsetY, offsetZ }, { 2, 20, 44 }, { offsetX - 10, offsetY, offsetZ }); - // Stairs - imageId = (SPR_MOTION_SIMULATOR_STAIRS_R0 + direction) | session->TrackColours[SCHEME_MISC]; - PaintAddImageAsParent( - session, imageId, { offsetX, offsetY, offsetZ }, { 20, 20, 44 }, { offsetX + 5, offsetY, offsetZ }); - // Simulator - imageId = simulatorImageId; - PaintAddImageAsChild(session, imageId, offsetX, offsetY, 20, 20, 44, offsetZ, offsetX + 5, offsetY, offsetZ); + PaintAddImageAsParent(session, stairsRailImageId, offset, { 2, 20, 44 }, { offset.x - 10, offset.y, offset.z }); + PaintAddImageAsParent(session, stairsImageId, offset, { 20, 20, 44 }, { offset.x + 5, offset.y, offset.z }); + PaintAddImageAsChild(session, simulatorImageId, offset, { 20, 20, 44 }, { offset.x + 5, offset.y, offset.z }); break; } @@ -140,8 +101,7 @@ static void paint_motionsimulator_vehicle( session->InteractionType = ViewportInteractionItem::Ride; } -/** rct2: 0x008A85C4 */ -static void paint_motionsimulator( +static void PaintMotionSimulator( paint_session* session, const Ride* ride, uint8_t trackSequence, uint8_t direction, int32_t height, const TrackElement& trackElement) { @@ -162,19 +122,19 @@ static void paint_motionsimulator( track_paint_util_paint_fences( session, edges, session->MapPosition, trackElement, ride, session->TrackColours[SCHEME_SUPPORTS], height, fenceSpritesRope, session->CurrentRotation); - } - switch (trackSequence) - { - case 1: - paint_motionsimulator_vehicle(session, ride, 16, -16, direction, height, trackElement); - break; - case 2: - paint_motionsimulator_vehicle(session, ride, -16, 16, direction, height, trackElement); - break; - case 3: - paint_motionsimulator_vehicle(session, ride, -16, -16, direction, height, trackElement); - break; + switch (trackSequence) + { + case 1: + PaintMotionSimulatorVehicle(session, *ride, 16, -16, direction, height, trackElement); + break; + case 2: + PaintMotionSimulatorVehicle(session, *ride, -16, 16, direction, height, trackElement); + break; + case 3: + PaintMotionSimulatorVehicle(session, *ride, -16, -16, direction, height, trackElement); + break; + } } paint_util_set_segment_support_height(session, SEGMENTS_ALL, 0xFFFF, 0); @@ -190,7 +150,7 @@ TRACK_PAINT_FUNCTION get_track_paint_function_motionsimulator(int32_t trackType) switch (trackType) { case TrackElemType::FlatTrack2x2: - return paint_motionsimulator; + return PaintMotionSimulator; } return nullptr; }