Refactor paint top spin to use ImageId

This commit is contained in:
Ted John 2021-12-04 23:14:55 +00:00
parent a8505dc689
commit 70506d2216
1 changed files with 127 additions and 187 deletions

View File

@ -19,17 +19,12 @@
#include "../TrackPaint.h" #include "../TrackPaint.h"
#include "../Vehicle.h" #include "../Vehicle.h"
#include <iterator>
/** rct2: 0x014280BC */
static int16_t TopSpinSeatHeightOffset[] = { static int16_t TopSpinSeatHeightOffset[] = {
-10, -10, -9, -7, -4, -1, 2, 6, 11, 16, 21, 26, 31, 37, 42, 47, 52, 57, 61, 64, 67, 70, 72, 73, -10, -10, -9, -7, -4, -1, 2, 6, 11, 16, 21, 26, 31, 37, 42, 47, 52, 57, 61, 64, 67, 70, 72, 73,
73, 73, 72, 70, 67, 64, 61, 57, 52, 47, 42, 37, 31, 26, 21, 16, 11, 6, 2, -1, -4, -7, -9, -10, 73, 73, 72, 70, 67, 64, 61, 57, 52, 47, 42, 37, 31, 26, 21, 16, 11, 6, 2, -1, -4, -7, -9, -10,
}; };
/** /**
*
* rct2: 0x0142811C
* Can be calculated as Rounddown(34*sin(x)+0.5) * Can be calculated as Rounddown(34*sin(x)+0.5)
* where x is in 7.5 deg segments. * where x is in 7.5 deg segments.
*/ */
@ -38,115 +33,57 @@ static int8_t TopSpinSeatPositionOffset[] = {
0, -3, -8, -12, -16, -20, -23, -26, -28, -30, -32, -33, -33, -33, -32, -30, -28, -26, -23, -20, -16, -12, -8, -3, 0, -3, -8, -12, -16, -20, -23, -26, -28, -30, -32, -33, -33, -33, -32, -30, -28, -26, -23, -20, -16, -12, -8, -3,
}; };
/** static void PaintTopSpinRiders(
* paint_session* session, const Vehicle& vehicle, ImageIndex seatImageIndex, const CoordsXYZ& seatCoords,
* rct2: 0x0076750D const CoordsXYZ& bbLength, const CoordsXYZ& bbOffset)
*/
static void top_spin_paint_vehicle(
paint_session* session, int32_t al, int32_t cl, const Ride* ride, uint8_t direction, int32_t height,
const TrackElement& tileElement)
{ {
if (ride == nullptr) if (session->DPI.zoom_level >= ZoomLevel{ 2 })
return; return;
int32_t boundBoxOffsetX, boundBoxOffsetY, boundBoxOffsetZ; for (int i = 0; i < 4; i++)
// As we will be drawing a vehicle we need to backup the trackElement that
// is assigned to the drawings.
const TileElement* curTileElement = static_cast<const TileElement*>(session->CurrentlyDrawnItem);
height += 3;
rct_ride_entry* rideEntry = get_ride_entry(ride->subtype);
uint8_t seatRotation = 0;
int8_t armRotation = 0;
Vehicle* vehicle = GetEntity<Vehicle>(ride->vehicles[0]);
if (ride->lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK && vehicle != nullptr)
{ {
session->InteractionType = ViewportInteractionItem::Entity; auto peepIndex = i * 2;
session->CurrentlyDrawnItem = vehicle; if (vehicle.num_peeps > peepIndex)
{
armRotation = vehicle->Pitch; auto imageIndex = seatImageIndex + ((i + 1) * 76);
seatRotation = vehicle->bank_rotation; auto imageId = ImageId(
imageIndex, vehicle.peep_tshirt_colours[peepIndex], vehicle.peep_tshirt_colours[peepIndex + 1]);
PaintAddImageAsChild(session, imageId, seatCoords, bbLength, bbOffset);
}
else
{
break;
}
} }
}
boundBoxOffsetX = al + 16; static void PaintTopSpinSeat(
boundBoxOffsetY = cl + 16; paint_session* session, const Ride& ride, const rct_ride_entry& rideEntry, const Vehicle* vehicle, Direction direction,
boundBoxOffsetZ = height; uint32_t armRotation, uint32_t seatRotation, const CoordsXYZ& offset, const CoordsXYZ& bbLength, const CoordsXYZ& bbOffset)
{
if (armRotation >= std::size(TopSpinSeatHeightOffset))
return;
auto lengthX = 24; const auto& vehicleEntry = rideEntry.vehicles[0];
auto lengthY = 24;
uint32_t image_id = session->TrackColours[SCHEME_MISC];
if (image_id == IMAGE_TYPE_REMAP)
{
image_id = SPRITE_ID_PALETTE_COLOUR_2(ride->track_colour[0].main, ride->track_colour[0].supports);
}
image_id += (direction & 1) << 1;
image_id += rideEntry->vehicles[0].base_image_id;
// Left back bottom support
image_id += 572;
PaintAddImageAsParent(
session, image_id, { al, cl, height }, { lengthX, lengthY, 90 }, { boundBoxOffsetX, boundBoxOffsetY, boundBoxOffsetZ });
image_id = session->TrackColours[SCHEME_MISC];
if (image_id == IMAGE_TYPE_REMAP)
{
image_id = SPRITE_ID_PALETTE_COLOUR_2(ride->track_colour[0].main, ride->track_colour[0].additional);
}
int32_t var_1F = armRotation;
if (direction & 2)
{
var_1F = -var_1F;
if (var_1F != 0)
var_1F += 48;
}
image_id += var_1F;
image_id += (direction & 1) * 48;
image_id += rideEntry->vehicles[0].base_image_id;
// Left hand arm
image_id += 380;
PaintAddImageAsChild(
session, image_id, al, cl, lengthX, lengthY, 90, height, boundBoxOffsetX, boundBoxOffsetY, boundBoxOffsetZ);
uint32_t seatImageId;
ImageIndex seatImageIndex;
if (vehicle != nullptr && vehicle->restraints_position >= 64) if (vehicle != nullptr && vehicle->restraints_position >= 64)
{ {
// Open Restraints // Open Restraints
image_id = (vehicle->restraints_position - 64) >> 6; seatImageIndex = vehicleEntry.base_image_id + 64;
image_id += direction * 3; seatImageIndex += (vehicle->restraints_position - 64) >> 6;
image_id += rideEntry->vehicles[0].base_image_id; seatImageIndex += direction * 3;
image_id += 64;
seatImageId = image_id;
} }
else else
{ {
image_id = direction * 16;
// Var_20 Rotation of seats // Var_20 Rotation of seats
image_id += seatRotation; seatImageIndex = vehicleEntry.base_image_id;
image_id += rideEntry->vehicles[0].base_image_id; seatImageIndex += direction * 16;
seatImageId = image_id; seatImageIndex += seatRotation;
} }
image_id = session->TrackColours[SCHEME_MISC]; auto seatCoords = offset;
if (image_id == IMAGE_TYPE_REMAP)
{
image_id = SPRITE_ID_PALETTE_COLOUR_2(ride->vehicle_colours[0].Body, ride->vehicle_colours[0].Trim);
}
image_id += seatImageId;
CoordsXYZ seatCoords(al, cl, height);
if (armRotation >= static_cast<int8_t>(std::size(TopSpinSeatHeightOffset)))
{
return;
}
seatCoords.z += TopSpinSeatHeightOffset[armRotation]; seatCoords.z += TopSpinSeatHeightOffset[armRotation];
switch (direction) switch (direction)
{ {
case 0: case 0:
@ -163,88 +100,92 @@ static void top_spin_paint_vehicle(
break; break;
} }
PaintAddImageAsChild( auto imageFlags = session->TrackColours[SCHEME_MISC];
session, image_id, static_cast<int8_t>(seatCoords.x), static_cast<int8_t>(seatCoords.y), lengthX, lengthY, 90, auto imageTemplate = ImageId(0, ride.vehicle_colours[0].Body, ride.vehicle_colours[0].Trim);
seatCoords.z, boundBoxOffsetX, boundBoxOffsetY, boundBoxOffsetZ); if (imageFlags != IMAGE_TYPE_REMAP)
rct_drawpixelinfo* dpi = &session->DPI;
if (dpi->zoom_level < ZoomLevel{ 2 } && vehicle != nullptr && vehicle->num_peeps != 0)
{ {
image_id = (seatImageId + (1 * 76)) imageTemplate = ImageId::FromUInt32(imageFlags);
| SPRITE_ID_PALETTE_COLOUR_2(vehicle->peep_tshirt_colours[0], vehicle->peep_tshirt_colours[1]);
PaintAddImageAsChild(
session, image_id, static_cast<int8_t>(seatCoords.x), static_cast<int8_t>(seatCoords.y), lengthX, lengthY, 90,
seatCoords.z, boundBoxOffsetX, boundBoxOffsetY, boundBoxOffsetZ);
if (vehicle->num_peeps > 2)
{
image_id = (seatImageId + (2 * 76))
| SPRITE_ID_PALETTE_COLOUR_2(vehicle->peep_tshirt_colours[2], vehicle->peep_tshirt_colours[3]);
PaintAddImageAsChild(
session, image_id, static_cast<int8_t>(seatCoords.x), static_cast<int8_t>(seatCoords.y), lengthX, lengthY, 90,
seatCoords.z, boundBoxOffsetX, boundBoxOffsetY, boundBoxOffsetZ);
}
if (vehicle->num_peeps > 4)
{
image_id = (seatImageId + (3 * 76))
| SPRITE_ID_PALETTE_COLOUR_2(vehicle->peep_tshirt_colours[4], vehicle->peep_tshirt_colours[5]);
PaintAddImageAsChild(
session, image_id, static_cast<int8_t>(seatCoords.x), static_cast<int8_t>(seatCoords.y), lengthX, lengthY, 90,
seatCoords.z, boundBoxOffsetX, boundBoxOffsetY, boundBoxOffsetZ);
}
if (vehicle->num_peeps > 6)
{
image_id = (seatImageId + (4 * 76))
| SPRITE_ID_PALETTE_COLOUR_2(vehicle->peep_tshirt_colours[6], vehicle->peep_tshirt_colours[7]);
PaintAddImageAsChild(
session, image_id, static_cast<int8_t>(seatCoords.x), static_cast<int8_t>(seatCoords.y), lengthX, lengthY, 90,
seatCoords.z, boundBoxOffsetX, boundBoxOffsetY, boundBoxOffsetZ);
}
} }
image_id = session->TrackColours[SCHEME_MISC]; PaintAddImageAsChild(session, imageTemplate.WithIndex(seatImageIndex), seatCoords, bbLength, bbOffset);
if (image_id == IMAGE_TYPE_REMAP) if (vehicle != nullptr)
{ {
image_id = SPRITE_ID_PALETTE_COLOUR_2(ride->track_colour[0].main, ride->track_colour[0].additional); PaintTopSpinRiders(session, *vehicle, seatImageIndex, seatCoords, bbLength, bbOffset);
}
}
static void PaintTopSpinVehicle(
paint_session* session, int32_t al, int32_t cl, const Ride& ride, uint8_t direction, int32_t height,
const TrackElement& tileElement)
{
const auto* rideEntry = get_ride_entry(ride.subtype);
if (rideEntry == nullptr)
return;
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<const TileElement*>(session->CurrentlyDrawnItem);
height += 3;
uint8_t seatRotation = 0;
uint8_t armRotation = 0;
const auto* vehicle = GetEntity<Vehicle>(ride.vehicles[0]);
if (ride.lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK && vehicle != nullptr)
{
session->InteractionType = ViewportInteractionItem::Entity;
session->CurrentlyDrawnItem = vehicle;
armRotation = vehicle->Pitch;
seatRotation = vehicle->bank_rotation;
} }
image_id += var_1F; int32_t armImageOffset = armRotation;
image_id += (direction & 1) * 48; if (direction & 2)
image_id += rideEntry->vehicles[0].base_image_id; {
armImageOffset = -armImageOffset;
if (armImageOffset != 0)
armImageOffset += 48;
}
CoordsXYZ offset = { al, cl, height };
CoordsXYZ bbLength = { 24, 24, 90 };
CoordsXYZ bbOffset = { al + 16, cl + 16, height };
auto imageFlags = session->TrackColours[SCHEME_MISC];
auto supportImageTemplate = ImageId(0, ride.track_colour[0].main, ride.track_colour[0].supports);
auto armImageTemplate = ImageId(0, ride.track_colour[0].main, ride.track_colour[0].additional);
if (imageFlags != IMAGE_TYPE_REMAP)
{
supportImageTemplate = ImageId::FromUInt32(imageFlags);
armImageTemplate = supportImageTemplate;
}
// Left back bottom support
auto imageIndex = vehicleEntry.base_image_id + 572 + ((direction & 1) << 1);
PaintAddImageAsParent(session, supportImageTemplate.WithIndex(imageIndex), offset, bbLength, bbOffset);
// Left hand arm
imageIndex = vehicleEntry.base_image_id + 380 + armImageOffset + ((direction & 1) * 48);
PaintAddImageAsChild(session, armImageTemplate.WithIndex(imageIndex), offset, bbLength, bbOffset);
// Seat
PaintTopSpinSeat(session, ride, *rideEntry, vehicle, direction, armRotation, seatRotation, offset, bbLength, bbOffset);
// Right hand arm // Right hand arm
image_id += 476; imageIndex = vehicleEntry.base_image_id + 476 + armImageOffset + ((direction & 1) * 48);
PaintAddImageAsChild(session, armImageTemplate.WithIndex(imageIndex), offset, bbLength, bbOffset);
PaintAddImageAsChild(
session, image_id, al, cl, lengthX, lengthY, 90, height, boundBoxOffsetX, boundBoxOffsetY, boundBoxOffsetZ);
image_id = session->TrackColours[SCHEME_MISC];
if (image_id == IMAGE_TYPE_REMAP)
{
image_id = SPRITE_ID_PALETTE_COLOUR_2(ride->track_colour[0].main, ride->track_colour[0].supports);
}
image_id += (direction & 1) << 1;
image_id += rideEntry->vehicles[0].base_image_id;
// Right back bottom support // Right back bottom support
image_id += 573; imageIndex = vehicleEntry.base_image_id + 573 + ((direction & 1) << 1);
PaintAddImageAsChild(session, supportImageTemplate.WithIndex(imageIndex), offset, bbLength, bbOffset);
PaintAddImageAsChild(
session, image_id, al, cl, lengthX, lengthY, 90, height, boundBoxOffsetX, boundBoxOffsetY, boundBoxOffsetZ);
session->CurrentlyDrawnItem = curTileElement; session->CurrentlyDrawnItem = curTileElement;
session->InteractionType = ViewportInteractionItem::Ride; session->InteractionType = ViewportInteractionItem::Ride;
} }
/** static void PaintTopSpin(
* rct2: 0x0076679C
*/
static void paint_top_spin(
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)
{ {
@ -265,28 +206,28 @@ static void paint_top_spin(
track_paint_util_paint_fences( track_paint_util_paint_fences(
session, edges, session->MapPosition, trackElement, ride, session->TrackColours[SCHEME_MISC], height, session, edges, session->MapPosition, trackElement, ride, session->TrackColours[SCHEME_MISC], height,
fenceSpritesRope, session->CurrentRotation); fenceSpritesRope, session->CurrentRotation);
}
switch (trackSequence) switch (trackSequence)
{ {
case 1: case 1:
top_spin_paint_vehicle(session, 32, 32, ride, direction, height, trackElement); PaintTopSpinVehicle(session, 32, 32, *ride, direction, height, trackElement);
break; break;
case 3: case 3:
top_spin_paint_vehicle(session, 32, -32, ride, direction, height, trackElement); PaintTopSpinVehicle(session, 32, -32, *ride, direction, height, trackElement);
break; break;
case 5: case 5:
top_spin_paint_vehicle(session, 0, -32, ride, direction, height, trackElement); PaintTopSpinVehicle(session, 0, -32, *ride, direction, height, trackElement);
break; break;
case 6: case 6:
top_spin_paint_vehicle(session, -32, 32, ride, direction, height, trackElement); PaintTopSpinVehicle(session, -32, 32, *ride, direction, height, trackElement);
break; break;
case 7: case 7:
top_spin_paint_vehicle(session, -32, -32, ride, direction, height, trackElement); PaintTopSpinVehicle(session, -32, -32, *ride, direction, height, trackElement);
break; break;
case 8: case 8:
top_spin_paint_vehicle(session, -32, 0, ride, direction, height, trackElement); PaintTopSpinVehicle(session, -32, 0, *ride, direction, height, trackElement);
break; break;
}
} }
int32_t cornerSegments = 0; int32_t cornerSegments = 0;
@ -315,7 +256,6 @@ static void paint_top_spin(
paint_util_set_general_support_height(session, height + 112, 0x20); paint_util_set_general_support_height(session, height + 112, 0x20);
} }
/* 0x0076659C */
TRACK_PAINT_FUNCTION get_track_paint_function_topspin(int32_t trackType) TRACK_PAINT_FUNCTION get_track_paint_function_topspin(int32_t trackType)
{ {
if (trackType != TrackElemType::FlatTrack3x3) if (trackType != TrackElemType::FlatTrack3x3)
@ -323,5 +263,5 @@ TRACK_PAINT_FUNCTION get_track_paint_function_topspin(int32_t trackType)
return nullptr; return nullptr;
} }
return paint_top_spin; return PaintTopSpin;
} }