Refactor simple rides / shops to use ImageId

This commit is contained in:
Ted John 2021-12-04 23:50:16 +00:00
parent 70506d2216
commit a4e0a5ab07
5 changed files with 80 additions and 132 deletions

View File

@ -16,11 +16,7 @@
#include "../Track.h"
#include "../TrackPaint.h"
/**
* rct2: 0x0077084A
*/
static void paint_circus_tent(
paint_session* session, const Ride* ride, uint8_t direction, int8_t al, int8_t cl, uint16_t height)
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<const TileElement*>(session->CurrentlyDrawnItem);
@ -38,23 +34,22 @@ static void paint_circus_tent(
session->CurrentlyDrawnItem = vehicle;
}
uint32_t imageColourFlags = session->TrackColours[SCHEME_MISC];
uint32_t imageId = rideEntry->vehicles[0].base_image_id + direction;
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);
}
auto imageIndex = rideEntry->vehicles[0].base_image_id + direction;
PaintAddImageAsParent(
session, imageId | imageColourFlags, { al, cl, height + 3 }, { 24, 24, 47 }, { al + 16, cl + 16, height + 3 });
session, imageTemplate.WithIndex(imageIndex), { al, cl, height + 3 }, { 24, 24, 47 }, { al + 16, cl + 16, height + 3 });
session->CurrentlyDrawnItem = savedTileElement;
session->InteractionType = ViewportInteractionItem::Ride;
}
/**
* rct2: 0x0076FAD4
*/
static void paint_circus(
static void PaintCircus(
paint_session* session, const Ride* ride, uint8_t trackSequence, uint8_t direction, int32_t height,
const TrackElement& trackElement)
{
@ -80,22 +75,22 @@ static void paint_circus(
switch (trackSequence)
{
case 1:
paint_circus_tent(session, ride, direction, 32, 32, height);
PaintCircusTent(session, ride, direction, 32, 32, height);
break;
case 3:
paint_circus_tent(session, ride, direction, 32, -32, height);
PaintCircusTent(session, ride, direction, 32, -32, height);
break;
case 5:
paint_circus_tent(session, ride, direction, 0, -32, height);
PaintCircusTent(session, ride, direction, 0, -32, height);
break;
case 6:
paint_circus_tent(session, ride, direction, -32, 32, height);
PaintCircusTent(session, ride, direction, -32, 32, height);
break;
case 7:
paint_circus_tent(session, ride, direction, -32, -32, height);
PaintCircusTent(session, ride, direction, -32, -32, height);
break;
case 8:
paint_circus_tent(session, ride, direction, -32, 0, height);
PaintCircusTent(session, ride, direction, -32, 0, height);
break;
}
@ -125,9 +120,6 @@ static void paint_circus(
paint_util_set_general_support_height(session, height + 128, 0x20);
}
/**
* rct2: 0x0076F8D4
*/
TRACK_PAINT_FUNCTION get_track_paint_function_circus(int32_t trackType)
{
if (trackType != TrackElemType::FlatTrack3x3)
@ -135,5 +127,5 @@ TRACK_PAINT_FUNCTION get_track_paint_function_circus(int32_t trackType)
return nullptr;
}
return paint_circus;
return PaintCircus;
}

View File

@ -49,7 +49,7 @@ static constexpr const rct_crooked_house_bound_box crooked_house_data[] = {
/**
* rct2: 0x0088ABA4
*/
static void paint_crooked_house_structure(
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<const TileElement*>(session->CurrentlyDrawnItem);
@ -72,14 +72,15 @@ static void paint_crooked_house_structure(
}
}
uint32_t image_id = (direction + rideEntry->vehicles[0].base_image_id) | session->TrackColours[SCHEME_MISC];
const rct_crooked_house_bound_box& boundBox = crooked_house_data[segment];
const auto& boundBox = crooked_house_data[segment];
auto imageTemplate = ImageId::FromUInt32(session->TrackColours[SCHEME_MISC]);
auto imageIndex = rideEntry->vehicles[0].base_image_id + direction;
PaintAddImageAsParent(
session, image_id, { x_offset, y_offset, height + 3 }, { boundBox.length, 127 }, { boundBox.offset, height + 3 });
session, imageTemplate.WithIndex(imageIndex), { x_offset, y_offset, height + 3 }, { boundBox.length, 127 },
{ boundBox.offset, height + 3 });
}
static void paint_crooked_house(
static void PaintCrookedHouse(
paint_session* session, const Ride* ride, uint8_t trackSequence, uint8_t direction, int32_t height,
const TrackElement& trackElement)
{
@ -105,16 +106,14 @@ static void paint_crooked_house(
switch (trackSequence)
{
case 3:
paint_crooked_house_structure(session, direction, 32, -32, 0, height);
PaintCrookedHouseStructure(session, direction, 32, -32, 0, height);
break;
// case 5: sub_88ABA4(direction, 0, -32, 1, height); break;
case 6:
paint_crooked_house_structure(session, direction, -32, 32, 4, height);
PaintCrookedHouseStructure(session, direction, -32, 32, 4, height);
break;
case 7:
paint_crooked_house_structure(session, direction, -32, -32, 2, height);
PaintCrookedHouseStructure(session, direction, -32, -32, 2, height);
break;
// case 8: sub_88ABA4(rideIndex, -32, 0, 3, height); break;
}
int32_t cornerSegments = 0;
@ -150,5 +149,5 @@ TRACK_PAINT_FUNCTION get_track_paint_function_crooked_house(int32_t trackType)
return nullptr;
}
return paint_crooked_house;
return PaintCrookedHouse;
}

View File

@ -23,16 +23,12 @@ struct haunted_house_bound_box
CoordsXY length;
};
/** rct2: 0x1428180 */
static constexpr haunted_house_bound_box haunted_house_data[] = {
{ { 6, 0 }, { 42, 24 } }, { { 0, 0 }, { 0, 0 } }, { { -16, -16 }, { 32, 32 } },
{ { 0, 0 }, { 0, 0 } }, { { 0, 6 }, { 24, 42 } }, { { 0, 0 }, { 0, 0 } },
};
/**
* rct2: 0x0076F72C
*/
static void paint_haunted_house_structure(
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<const TileElement*>(session->CurrentlyDrawnItem);
@ -46,8 +42,6 @@ static void paint_haunted_house_structure(
if (rideEntry == nullptr)
return;
uint32_t baseImageId = rideEntry->vehicles[0].base_image_id;
auto vehicle = GetEntity<Vehicle>(ride->vehicles[0]);
if (ride->lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK && vehicle != nullptr)
{
@ -56,44 +50,27 @@ static void paint_haunted_house_structure(
frameNum = vehicle->Pitch;
}
uint32_t imageId = (baseImageId + direction) | session->TrackColours[SCHEME_MISC];
const haunted_house_bound_box& boundBox = haunted_house_data[part];
const auto& boundBox = haunted_house_data[part];
auto imageTemplate = ImageId::FromUInt32(session->TrackColours[SCHEME_MISC]);
auto baseImageIndex = rideEntry->vehicles[0].base_image_id;
auto imageIndex = baseImageIndex + direction;
PaintAddImageAsParent(
session, imageId, { xOffset, yOffset, height }, { boundBox.length, 127 }, { boundBox.offset, height });
session, imageTemplate.WithIndex(imageIndex), { xOffset, yOffset, height }, { boundBox.length, 127 },
{ boundBox.offset, height });
rct_drawpixelinfo* dpi = &session->DPI;
if (dpi->zoom_level <= ZoomLevel{ 0 } && frameNum != 0)
if (session->DPI.zoom_level <= ZoomLevel{ 0 } && frameNum != 0)
{
switch (direction)
{
case 0:
imageId = baseImageId + 3 + frameNum;
break;
case 1:
imageId = baseImageId + 21 + frameNum;
break;
case 2:
imageId = baseImageId + 39 + frameNum;
break;
case 3:
imageId = baseImageId + 57 + frameNum;
break;
}
imageId = imageId | session->TrackColours[SCHEME_MISC];
imageIndex = baseImageIndex + 3 + ((direction & 3) * 18) + frameNum;
PaintAddImageAsChild(
session, imageId, xOffset, yOffset, boundBox.length.x, boundBox.length.y, 127, height, boundBox.offset.x,
boundBox.offset.y, height);
session, imageTemplate.WithIndex(imageIndex), { xOffset, yOffset, height },
{ boundBox.length.x, boundBox.length.y, 127 }, { boundBox.offset.x, boundBox.offset.y, height });
}
session->CurrentlyDrawnItem = savedTileElement;
session->InteractionType = ViewportInteractionItem::Ride;
}
/**
* rct2: 0x0076E9B0
*/
static void paint_haunted_house(
static void PaintHauntedHouse(
paint_session* session, const Ride* ride, uint8_t trackSequence, uint8_t direction, int32_t height,
const TrackElement& trackElement)
{
@ -119,13 +96,13 @@ static void paint_haunted_house(
switch (trackSequence)
{
case 3:
paint_haunted_house_structure(session, ride, direction, 32, -32, 0, height + 3);
PaintHauntedHouseStructure(session, ride, direction, 32, -32, 0, height + 3);
break;
case 6:
paint_haunted_house_structure(session, ride, direction, -32, 32, 4, height + 3);
PaintHauntedHouseStructure(session, ride, direction, -32, 32, 4, height + 3);
break;
case 7:
paint_haunted_house_structure(session, ride, direction, -32, -32, 2, height + 3);
PaintHauntedHouseStructure(session, ride, direction, -32, -32, 2, height + 3);
break;
}
@ -155,9 +132,6 @@ static void paint_haunted_house(
paint_util_set_general_support_height(session, height + 128, 0x20);
}
/**
* rct2: 0x0076E7B0
*/
TRACK_PAINT_FUNCTION get_track_paint_function_haunted_house(int32_t trackType)
{
if (trackType != TrackElemType::FlatTrack3x3)
@ -165,5 +139,5 @@ TRACK_PAINT_FUNCTION get_track_paint_function_haunted_house(int32_t trackType)
return nullptr;
}
return paint_haunted_house;
return PaintHauntedHouse;
}

View File

@ -17,14 +17,7 @@
#include "../Track.h"
#include "../TrackPaint.h"
/**
*
* rct2: 0x00763234
* rct2: 0x0076338C
* rct2: 0x00762F50
* rct2: 0x007630DE
*/
static void facility_paint_setup(
static void PaintFacility(
paint_session* session, const Ride* ride, uint8_t trackSequence, uint8_t direction, int32_t height,
const TrackElement& trackElement)
{
@ -41,42 +34,36 @@ static void facility_paint_setup(
if (firstVehicleEntry == nullptr)
return;
uint32_t imageId = session->TrackColours[SCHEME_TRACK];
imageId |= firstVehicleEntry->base_image_id;
imageId += (direction + 2) & 3;
auto lengthX = (direction & 1) == 0 ? 28 : 2;
auto lengthY = (direction & 1) == 0 ? 2 : 28;
CoordsXYZ offset(0, 0, height);
CoordsXYZ bbLength(lengthX, lengthY, 29);
CoordsXYZ bbOffset(direction == 3 ? 28 : 2, direction == 0 ? 28 : 2, height);
int32_t lengthX = (direction & 1) == 0 ? 28 : 2;
int32_t lengthY = (direction & 1) == 0 ? 2 : 28;
auto imageTemplate = ImageId::FromUInt32(session->TrackColours[SCHEME_TRACK]);
auto imageIndex = firstVehicleEntry->base_image_id + ((direction + 2) & 3);
auto imageId = imageTemplate.WithIndex(imageIndex);
if (hasSupports)
{
uint32_t foundationImageId = ((direction & 1) ? SPR_FLOOR_PLANKS_90_DEG : SPR_FLOOR_PLANKS)
| session->TrackColours[SCHEME_3];
PaintAddImageAsParent(
session, foundationImageId, { 0, 0, height }, { lengthX, lengthY, 29 },
{ direction == 3 ? 28 : 2, direction == 0 ? 28 : 2, height });
// Door image or base
PaintAddImageAsChild(
session, imageId, 0, 0, lengthX, lengthY, 29, height, direction == 3 ? 28 : 2, direction == 0 ? 28 : 2, height);
auto foundationImageTemplate = ImageId::FromUInt32(session->TrackColours[SCHEME_3]);
auto foundationImageIndex = (direction & 1) ? SPR_FLOOR_PLANKS_90_DEG : SPR_FLOOR_PLANKS;
auto foundationImageId = foundationImageTemplate.WithIndex(foundationImageIndex);
PaintAddImageAsParent(session, foundationImageId, offset, bbLength, bbOffset);
PaintAddImageAsChild(session, imageId, offset, bbLength, bbOffset);
}
else
{
// Door image or base
PaintAddImageAsParent(
session, imageId, { 0, 0, height }, { lengthX, lengthY, 29 },
{ direction == 3 ? 28 : 2, direction == 0 ? 28 : 2, height });
PaintAddImageAsParent(session, imageId, offset, bbLength, bbOffset);
}
// Base image if door was drawn
if (direction == 1)
{
imageId += 2;
PaintAddImageAsParent(session, imageId, { 0, 0, height }, { 2, 28, 29 }, { 28, 2, height });
PaintAddImageAsParent(session, imageId.WithIndexOffset(2), offset, { 2, 28, 29 }, { 28, 2, height });
}
else if (direction == 2)
{
imageId += 4;
PaintAddImageAsParent(session, imageId, { 0, 0, height }, { 28, 2, 29 }, { 2, 28, height });
PaintAddImageAsParent(session, imageId.WithIndexOffset(4), offset, { 28, 2, 29 }, { 2, 28, height });
}
paint_util_set_segment_support_height(session, SEGMENTS_ALL, 0xFFFF, 0);
@ -89,7 +76,7 @@ TRACK_PAINT_FUNCTION get_track_paint_function_facility(int32_t trackType)
switch (trackType)
{
case TrackElemType::FlatTrack1x1A:
return facility_paint_setup;
return PaintFacility;
}
return nullptr;
}

View File

@ -17,14 +17,7 @@
#include "../Track.h"
#include "../TrackPaint.h"
/**
*
* rct2: 0x00761378
* rct2: 0x007614DB
* rct2: 0x0076163F
* rct2: 0x007617A5
*/
static void shop_paint_setup(
static void PaintShop(
paint_session* session, const Ride* ride, uint8_t trackSequence, uint8_t direction, int32_t height,
const TrackElement& trackElement)
{
@ -41,39 +34,42 @@ static void shop_paint_setup(
if (firstVehicleEntry == nullptr)
return;
uint32_t imageId = session->TrackColours[SCHEME_TRACK];
if (imageId & IMAGE_TYPE_REMAP_2_PLUS)
{
imageId &= 0x60FFFFFF;
}
imageId += firstVehicleEntry->base_image_id;
imageId += direction;
CoordsXYZ offset(0, 0, height);
CoordsXYZ bbLength(28, 28, 45);
CoordsXYZ bbOffset(2, 2, height);
auto imageFlags = session->TrackColours[SCHEME_TRACK];
if (imageFlags & IMAGE_TYPE_REMAP_2_PLUS)
{
imageFlags &= ~IMAGE_TYPE_REMAP_2_PLUS;
imageFlags &= ~(31 << 24);
}
auto imageTemplate = ImageId::FromUInt32(imageFlags);
auto imageIndex = firstVehicleEntry->base_image_id + direction;
if (hasSupports)
{
uint32_t foundationImageId = ((direction & 1) ? SPR_FLOOR_PLANKS_90_DEG : SPR_FLOOR_PLANKS)
| session->TrackColours[SCHEME_3];
PaintAddImageAsParent(session, foundationImageId, { 0, 0, height }, { 28, 28, 45 }, { 2, 2, height });
PaintAddImageAsChild(session, imageId, 0, 0, 28, 28, 45, height, 2, 2, height);
auto foundationImageTemplate = ImageId::FromUInt32(session->TrackColours[SCHEME_3]);
auto foundationImageIndex = (direction & 1) ? SPR_FLOOR_PLANKS_90_DEG : SPR_FLOOR_PLANKS;
auto foundationImageId = foundationImageTemplate.WithIndex(foundationImageIndex);
PaintAddImageAsParent(session, foundationImageId, offset, bbLength, bbOffset);
PaintAddImageAsChild(session, imageTemplate.WithIndex(imageIndex), offset, bbLength, bbOffset);
}
else
{
PaintAddImageAsParent(session, imageId, { 0, 0, height }, { 28, 28, 45 }, { 2, 2, height });
PaintAddImageAsParent(session, imageTemplate.WithIndex(imageIndex), offset, bbLength, bbOffset);
}
paint_util_set_segment_support_height(session, SEGMENTS_ALL, 0xFFFF, 0);
paint_util_set_general_support_height(session, height + 48, 0x20);
}
/* 0x00761160 */
TRACK_PAINT_FUNCTION get_track_paint_function_shop(int32_t trackType)
{
switch (trackType)
{
case TrackElemType::FlatTrack1x1A:
case TrackElemType::FlatTrack1x1B:
return shop_paint_setup;
return PaintShop;
}
return nullptr;
}