Refactor paint swinging inverter to use ImageId

This commit is contained in:
Ted John 2021-12-05 13:32:16 +00:00
parent f628f53e3f
commit 8a4929a240
1 changed files with 35 additions and 47 deletions

View File

@ -19,7 +19,7 @@
#include "../Vehicle.h" #include "../Vehicle.h"
/** rct2: 0x01428010 */ /** rct2: 0x01428010 */
static constexpr const uint32_t swinging_inverter_ship_base_sprite_offset[] = { static constexpr const uint32_t SwingingInverterShipBaseSpriteOffset[] = {
0, 0,
16, 16,
0, 0,
@ -27,7 +27,7 @@ static constexpr const uint32_t swinging_inverter_ship_base_sprite_offset[] = {
}; };
/** rct2: 0x01428020 */ /** rct2: 0x01428020 */
static constexpr const uint32_t swinging_inverter_ship_animating_base_sprite_offset[] = { static constexpr const uint32_t SwingingInverterShipAnimatingBaseSpriteOffset[] = {
32, 32,
33, 33,
32, 32,
@ -58,14 +58,14 @@ enum
SPR_SWINGING_INVERTER_SHIP_FRAME_3 = 22001, SPR_SWINGING_INVERTER_SHIP_FRAME_3 = 22001,
}; };
static constexpr const uint32_t swinging_inverter_ship_frame_sprites[] = { static constexpr const uint32_t SwingingInverterShipFrameSprites[] = {
SPR_SWINGING_INVERTER_SHIP_FRAME_0, SPR_SWINGING_INVERTER_SHIP_FRAME_0,
SPR_SWINGING_INVERTER_SHIP_FRAME_1, SPR_SWINGING_INVERTER_SHIP_FRAME_1,
SPR_SWINGING_INVERTER_SHIP_FRAME_2, SPR_SWINGING_INVERTER_SHIP_FRAME_2,
SPR_SWINGING_INVERTER_SHIP_FRAME_3, SPR_SWINGING_INVERTER_SHIP_FRAME_3,
}; };
static void paint_swinging_inverter_ship_structure( static void PaintSwingingInverterShipStructure(
paint_session* session, const Ride& ride, uint8_t direction, int8_t axisOffset, uint16_t height) paint_session* session, const Ride& ride, uint8_t direction, int8_t axisOffset, uint16_t height)
{ {
const TileElement* savedTileElement = static_cast<const TileElement*>(session->CurrentlyDrawnItem); const TileElement* savedTileElement = static_cast<const TileElement*>(session->CurrentlyDrawnItem);
@ -74,28 +74,29 @@ static void paint_swinging_inverter_ship_structure(
if (rideEntry == nullptr) if (rideEntry == nullptr)
return; return;
const auto& boundBox = swinging_inverter_ship_bounds[direction];
CoordsXYZ offset((direction & 1) ? 0 : axisOffset, (direction & 1) ? axisOffset : 0, height);
CoordsXYZ bbLength(boundBox.length_x, boundBox.length_y, 127);
CoordsXYZ bbOffset(boundBox.offset_x, boundBox.offset_y, height);
Vehicle* vehicle = nullptr; Vehicle* vehicle = nullptr;
if (ride.lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK)
int8_t xOffset = !(direction & 1) ? axisOffset : 0;
int8_t yOffset = (direction & 1) ? axisOffset : 0;
if (ride.lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK && ride.vehicles[0] != SPRITE_INDEX_NULL)
{ {
vehicle = GetEntity<Vehicle>(ride.vehicles[0]); vehicle = GetEntity<Vehicle>(ride.vehicles[0]);
if (vehicle != nullptr)
{
session->InteractionType = ViewportInteractionItem::Entity; session->InteractionType = ViewportInteractionItem::Entity;
session->CurrentlyDrawnItem = vehicle; session->CurrentlyDrawnItem = vehicle;
} }
}
uint32_t vehicleImageId = rideEntry->vehicles[0].base_image_id + swinging_inverter_ship_base_sprite_offset[direction]; ImageIndex vehicleImageIndex = rideEntry->vehicles[0].base_image_id + SwingingInverterShipBaseSpriteOffset[direction];
if (vehicle != nullptr) if (vehicle != nullptr)
{ {
int32_t rotation = static_cast<int8_t>(vehicle->Pitch); int32_t rotation = static_cast<int8_t>(vehicle->Pitch);
if (rotation != 0) if (rotation != 0)
{ {
vehicleImageId = rideEntry->vehicles[0].base_image_id vehicleImageIndex = rideEntry->vehicles[0].base_image_id + SwingingInverterShipAnimatingBaseSpriteOffset[direction];
+ swinging_inverter_ship_animating_base_sprite_offset[direction];
if (direction & 2) if (direction & 2)
{ {
rotation = -rotation; rotation = -rotation;
@ -104,46 +105,36 @@ static void paint_swinging_inverter_ship_structure(
{ {
rotation += 72; rotation += 72;
} }
vehicleImageIndex += (rotation - 1) << 1;
vehicleImageId += (rotation - 1) << 1;
} }
} }
uint32_t colourFlags = session->TrackColours[SCHEME_MISC]; auto vehicleImageTemplate = ImageId(0, ride.vehicle_colours[0].Body, ride.vehicle_colours[0].Trim);
if (colourFlags == IMAGE_TYPE_REMAP) auto imageFlags = session->TrackColours[SCHEME_MISC];
if (imageFlags != IMAGE_TYPE_REMAP)
{ {
colourFlags = SPRITE_ID_PALETTE_COLOUR_2(ride.vehicle_colours[0].Body, ride.vehicle_colours[0].Trim); vehicleImageTemplate = ImageId::FromUInt32(imageFlags);
} }
auto frameImageTemplate = ImageId::FromUInt32(session->TrackColours[SCHEME_TRACK]);
swinging_inverter_ship_bound_box boundBox = swinging_inverter_ship_bounds[direction]; auto vehicleImageId = vehicleImageTemplate.WithIndex(vehicleImageIndex);
vehicleImageId = vehicleImageId | colourFlags; auto frameImageId = frameImageTemplate.WithIndex(SwingingInverterShipFrameSprites[direction]);
uint32_t frameImageId = swinging_inverter_ship_frame_sprites[direction] | session->TrackColours[SCHEME_TRACK];
if (direction & 2) if (direction & 2)
{ {
PaintAddImageAsParent( PaintAddImageAsParent(session, vehicleImageId, offset, bbLength, bbOffset);
session, vehicleImageId, { xOffset, yOffset, height }, { boundBox.length_x, boundBox.length_y, 127 }, PaintAddImageAsChild(session, frameImageId, offset, bbLength, bbOffset);
{ boundBox.offset_x, boundBox.offset_y, height });
PaintAddImageAsChild(
session, frameImageId, xOffset, yOffset, boundBox.length_x, boundBox.length_y, 127, height, boundBox.offset_x,
boundBox.offset_y, height);
} }
else else
{ {
PaintAddImageAsParent( PaintAddImageAsParent(session, frameImageId, offset, bbLength, bbOffset);
session, frameImageId, { xOffset, yOffset, height }, { boundBox.length_x, boundBox.length_y, 127 }, PaintAddImageAsChild(session, vehicleImageId, offset, bbLength, bbOffset);
{ boundBox.offset_x, boundBox.offset_y, height });
PaintAddImageAsChild(
session, vehicleImageId, xOffset, yOffset, boundBox.length_x, boundBox.length_y, 127, height, boundBox.offset_x,
boundBox.offset_y, height);
} }
session->CurrentlyDrawnItem = savedTileElement; session->CurrentlyDrawnItem = savedTileElement;
session->InteractionType = ViewportInteractionItem::Ride; session->InteractionType = ViewportInteractionItem::Ride;
} }
/** rct2: 0x00760260 */ static void PaintSwingingInverterShip(
static void paint_swinging_inverter_ship(
paint_session* session, const Ride* ride, uint8_t trackSequence, uint8_t direction, int32_t height, paint_session* session, const Ride* ride, uint8_t trackSequence, uint8_t direction, int32_t height,
const TrackElement& trackElement) const TrackElement& trackElement)
{ {
@ -199,16 +190,16 @@ static void paint_swinging_inverter_ship(
switch (relativeTrackSequence) switch (relativeTrackSequence)
{ {
case 1: case 1:
paint_swinging_inverter_ship_structure(session, *ride, direction, 48, height + 7); PaintSwingingInverterShipStructure(session, *ride, direction, 48, height + 7);
break; break;
case 2: case 2:
paint_swinging_inverter_ship_structure(session, *ride, direction, 16, height + 7); PaintSwingingInverterShipStructure(session, *ride, direction, 16, height + 7);
break; break;
case 0: case 0:
paint_swinging_inverter_ship_structure(session, *ride, direction, -16, height + 7); PaintSwingingInverterShipStructure(session, *ride, direction, -16, height + 7);
break; break;
case 3: case 3:
paint_swinging_inverter_ship_structure(session, *ride, direction, -48, height + 7); PaintSwingingInverterShipStructure(session, *ride, direction, -48, height + 7);
break; break;
} }
} }
@ -217,9 +208,6 @@ static void paint_swinging_inverter_ship(
paint_util_set_general_support_height(session, height + 176, 0x20); paint_util_set_general_support_height(session, height + 176, 0x20);
} }
/**
* rct2: 0x00760070
*/
TRACK_PAINT_FUNCTION get_track_paint_function_swinging_inverter_ship(int32_t trackType) TRACK_PAINT_FUNCTION get_track_paint_function_swinging_inverter_ship(int32_t trackType)
{ {
if (trackType != TrackElemType::FlatTrack1x4B) if (trackType != TrackElemType::FlatTrack1x4B)
@ -227,5 +215,5 @@ TRACK_PAINT_FUNCTION get_track_paint_function_swinging_inverter_ship(int32_t tra
return nullptr; return nullptr;
} }
return paint_swinging_inverter_ship; return PaintSwingingInverterShip;
} }