mirror of https://github.com/OpenRCT2/OpenRCT2.git
Refactor paint top spin to use ImageId
This commit is contained in:
parent
a8505dc689
commit
70506d2216
|
@ -19,17 +19,12 @@
|
|||
#include "../TrackPaint.h"
|
||||
#include "../Vehicle.h"
|
||||
|
||||
#include <iterator>
|
||||
|
||||
/** rct2: 0x014280BC */
|
||||
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,
|
||||
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)
|
||||
* 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,
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* rct2: 0x0076750D
|
||||
*/
|
||||
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)
|
||||
static void PaintTopSpinRiders(
|
||||
paint_session* session, const Vehicle& vehicle, ImageIndex seatImageIndex, const CoordsXYZ& seatCoords,
|
||||
const CoordsXYZ& bbLength, const CoordsXYZ& bbOffset)
|
||||
{
|
||||
if (ride == nullptr)
|
||||
if (session->DPI.zoom_level >= ZoomLevel{ 2 })
|
||||
return;
|
||||
|
||||
int32_t boundBoxOffsetX, boundBoxOffsetY, boundBoxOffsetZ;
|
||||
// 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)
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
session->InteractionType = ViewportInteractionItem::Entity;
|
||||
session->CurrentlyDrawnItem = vehicle;
|
||||
|
||||
armRotation = vehicle->Pitch;
|
||||
seatRotation = vehicle->bank_rotation;
|
||||
auto peepIndex = i * 2;
|
||||
if (vehicle.num_peeps > peepIndex)
|
||||
{
|
||||
auto imageIndex = seatImageIndex + ((i + 1) * 76);
|
||||
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;
|
||||
boundBoxOffsetY = cl + 16;
|
||||
boundBoxOffsetZ = height;
|
||||
static void PaintTopSpinSeat(
|
||||
paint_session* session, const Ride& ride, const rct_ride_entry& rideEntry, const Vehicle* vehicle, Direction direction,
|
||||
uint32_t armRotation, uint32_t seatRotation, const CoordsXYZ& offset, const CoordsXYZ& bbLength, const CoordsXYZ& bbOffset)
|
||||
{
|
||||
if (armRotation >= std::size(TopSpinSeatHeightOffset))
|
||||
return;
|
||||
|
||||
auto lengthX = 24;
|
||||
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;
|
||||
const auto& vehicleEntry = rideEntry.vehicles[0];
|
||||
|
||||
ImageIndex seatImageIndex;
|
||||
if (vehicle != nullptr && vehicle->restraints_position >= 64)
|
||||
{
|
||||
// Open Restraints
|
||||
image_id = (vehicle->restraints_position - 64) >> 6;
|
||||
image_id += direction * 3;
|
||||
image_id += rideEntry->vehicles[0].base_image_id;
|
||||
image_id += 64;
|
||||
seatImageId = image_id;
|
||||
seatImageIndex = vehicleEntry.base_image_id + 64;
|
||||
seatImageIndex += (vehicle->restraints_position - 64) >> 6;
|
||||
seatImageIndex += direction * 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
image_id = direction * 16;
|
||||
// Var_20 Rotation of seats
|
||||
image_id += seatRotation;
|
||||
image_id += rideEntry->vehicles[0].base_image_id;
|
||||
seatImageId = image_id;
|
||||
seatImageIndex = vehicleEntry.base_image_id;
|
||||
seatImageIndex += direction * 16;
|
||||
seatImageIndex += seatRotation;
|
||||
}
|
||||
|
||||
image_id = session->TrackColours[SCHEME_MISC];
|
||||
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;
|
||||
}
|
||||
auto seatCoords = offset;
|
||||
seatCoords.z += TopSpinSeatHeightOffset[armRotation];
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
case 0:
|
||||
|
@ -163,88 +100,92 @@ static void top_spin_paint_vehicle(
|
|||
break;
|
||||
}
|
||||
|
||||
PaintAddImageAsChild(
|
||||
session, image_id, static_cast<int8_t>(seatCoords.x), static_cast<int8_t>(seatCoords.y), lengthX, lengthY, 90,
|
||||
seatCoords.z, boundBoxOffsetX, boundBoxOffsetY, boundBoxOffsetZ);
|
||||
|
||||
rct_drawpixelinfo* dpi = &session->DPI;
|
||||
if (dpi->zoom_level < ZoomLevel{ 2 } && vehicle != nullptr && vehicle->num_peeps != 0)
|
||||
auto imageFlags = session->TrackColours[SCHEME_MISC];
|
||||
auto imageTemplate = ImageId(0, ride.vehicle_colours[0].Body, ride.vehicle_colours[0].Trim);
|
||||
if (imageFlags != IMAGE_TYPE_REMAP)
|
||||
{
|
||||
image_id = (seatImageId + (1 * 76))
|
||||
| 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);
|
||||
}
|
||||
imageTemplate = ImageId::FromUInt32(imageFlags);
|
||||
}
|
||||
|
||||
image_id = session->TrackColours[SCHEME_MISC];
|
||||
if (image_id == IMAGE_TYPE_REMAP)
|
||||
PaintAddImageAsChild(session, imageTemplate.WithIndex(seatImageIndex), seatCoords, bbLength, bbOffset);
|
||||
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;
|
||||
image_id += (direction & 1) * 48;
|
||||
image_id += rideEntry->vehicles[0].base_image_id;
|
||||
int32_t armImageOffset = armRotation;
|
||||
if (direction & 2)
|
||||
{
|
||||
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
|
||||
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
|
||||
image_id += 573;
|
||||
|
||||
PaintAddImageAsChild(
|
||||
session, image_id, al, cl, lengthX, lengthY, 90, height, boundBoxOffsetX, boundBoxOffsetY, boundBoxOffsetZ);
|
||||
imageIndex = vehicleEntry.base_image_id + 573 + ((direction & 1) << 1);
|
||||
PaintAddImageAsChild(session, supportImageTemplate.WithIndex(imageIndex), offset, bbLength, bbOffset);
|
||||
|
||||
session->CurrentlyDrawnItem = curTileElement;
|
||||
session->InteractionType = ViewportInteractionItem::Ride;
|
||||
}
|
||||
|
||||
/**
|
||||
* rct2: 0x0076679C
|
||||
*/
|
||||
static void paint_top_spin(
|
||||
static void PaintTopSpin(
|
||||
paint_session* session, const Ride* ride, uint8_t trackSequence, uint8_t direction, int32_t height,
|
||||
const TrackElement& trackElement)
|
||||
{
|
||||
|
@ -265,28 +206,28 @@ static void paint_top_spin(
|
|||
track_paint_util_paint_fences(
|
||||
session, edges, session->MapPosition, trackElement, ride, session->TrackColours[SCHEME_MISC], height,
|
||||
fenceSpritesRope, session->CurrentRotation);
|
||||
}
|
||||
|
||||
switch (trackSequence)
|
||||
{
|
||||
case 1:
|
||||
top_spin_paint_vehicle(session, 32, 32, ride, direction, height, trackElement);
|
||||
break;
|
||||
case 3:
|
||||
top_spin_paint_vehicle(session, 32, -32, ride, direction, height, trackElement);
|
||||
break;
|
||||
case 5:
|
||||
top_spin_paint_vehicle(session, 0, -32, ride, direction, height, trackElement);
|
||||
break;
|
||||
case 6:
|
||||
top_spin_paint_vehicle(session, -32, 32, ride, direction, height, trackElement);
|
||||
break;
|
||||
case 7:
|
||||
top_spin_paint_vehicle(session, -32, -32, ride, direction, height, trackElement);
|
||||
break;
|
||||
case 8:
|
||||
top_spin_paint_vehicle(session, -32, 0, ride, direction, height, trackElement);
|
||||
break;
|
||||
switch (trackSequence)
|
||||
{
|
||||
case 1:
|
||||
PaintTopSpinVehicle(session, 32, 32, *ride, direction, height, trackElement);
|
||||
break;
|
||||
case 3:
|
||||
PaintTopSpinVehicle(session, 32, -32, *ride, direction, height, trackElement);
|
||||
break;
|
||||
case 5:
|
||||
PaintTopSpinVehicle(session, 0, -32, *ride, direction, height, trackElement);
|
||||
break;
|
||||
case 6:
|
||||
PaintTopSpinVehicle(session, -32, 32, *ride, direction, height, trackElement);
|
||||
break;
|
||||
case 7:
|
||||
PaintTopSpinVehicle(session, -32, -32, *ride, direction, height, trackElement);
|
||||
break;
|
||||
case 8:
|
||||
PaintTopSpinVehicle(session, -32, 0, *ride, direction, height, trackElement);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t cornerSegments = 0;
|
||||
|
@ -315,7 +256,6 @@ static void paint_top_spin(
|
|||
paint_util_set_general_support_height(session, height + 112, 0x20);
|
||||
}
|
||||
|
||||
/* 0x0076659C */
|
||||
TRACK_PAINT_FUNCTION get_track_paint_function_topspin(int32_t trackType)
|
||||
{
|
||||
if (trackType != TrackElemType::FlatTrack3x3)
|
||||
|
@ -323,5 +263,5 @@ TRACK_PAINT_FUNCTION get_track_paint_function_topspin(int32_t trackType)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
return paint_top_spin;
|
||||
return PaintTopSpin;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue