Skip to content

Commit

Permalink
Merge pull request #14271 from ZehMatt/refactor/paint-coords
Browse files Browse the repository at this point in the history
Refactor uses of PaintAddImageAsParent
  • Loading branch information
ZehMatt committed Jun 5, 2021
2 parents c34079a + e289e21 commit c87860b
Show file tree
Hide file tree
Showing 24 changed files with 619 additions and 570 deletions.
29 changes: 15 additions & 14 deletions src/openrct2/paint/Paint.cpp
@@ -1,4 +1,4 @@
/*****************************************************************************
/*****************************************************************************
* Copyright (c) 2014-2020 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
Expand Down Expand Up @@ -694,9 +694,7 @@ void PaintSessionFree([[maybe_unused]] paint_session* session)
paint_struct* PaintAddImageAsParent(
paint_session* session, uint32_t image_id, const CoordsXYZ& offset, const CoordsXYZ& boundBoxSize)
{
return PaintAddImageAsParent(
session, image_id, offset.x, offset.y, boundBoxSize.x, boundBoxSize.y, boundBoxSize.z, offset.z, offset.x, offset.y,
offset.z);
return PaintAddImageAsParent(session, image_id, offset, boundBoxSize, offset);
}

paint_struct* PaintAddImageAsParent(
Expand Down Expand Up @@ -724,17 +722,12 @@ paint_struct* PaintAddImageAsParent(
*/
// Track Pieces, Shops.
paint_struct* PaintAddImageAsParent(
paint_session* session, uint32_t image_id, int8_t x_offset, int8_t y_offset, int16_t bound_box_length_x,
int16_t bound_box_length_y, int8_t bound_box_length_z, int16_t z_offset, int16_t bound_box_offset_x,
int16_t bound_box_offset_y, int16_t bound_box_offset_z)
paint_session* session, uint32_t image_id, const CoordsXYZ& offset, const CoordsXYZ& boundBoxSize,
const CoordsXYZ& boundBoxOffset)
{
session->LastPS = nullptr;
session->LastAttachedPS = nullptr;

CoordsXYZ offset = { x_offset, y_offset, z_offset };
CoordsXYZ boundBoxSize = { bound_box_length_x, bound_box_length_y, bound_box_length_z };
CoordsXYZ boundBoxOffset = { bound_box_offset_x, bound_box_offset_y, bound_box_offset_z };

auto* ps = CreateNormalPaintStruct(session, image_id, offset, boundBoxSize, boundBoxOffset);
if (ps == nullptr)
{
Expand All @@ -746,6 +739,16 @@ paint_struct* PaintAddImageAsParent(
return ps;
}

paint_struct* PaintAddImageAsParent(
paint_session* session, uint32_t image_id, int8_t x_offset, int8_t y_offset, int16_t bound_box_length_x,
int16_t bound_box_length_y, int8_t bound_box_length_z, int16_t z_offset, int16_t bound_box_offset_x,
int16_t bound_box_offset_y, int16_t bound_box_offset_z)
{
return PaintAddImageAsParent(
session, image_id, { x_offset, y_offset, z_offset }, { bound_box_length_x, bound_box_length_y, bound_box_length_z },
{ bound_box_offset_x, bound_box_offset_y, bound_box_offset_z });
}

/**
*
* rct2: 0x00686EF0, 0x00687056, 0x006871C8, 0x0068733C, 0x0098198C
Expand Down Expand Up @@ -811,9 +814,7 @@ paint_struct* PaintAddImageAsChild(
paint_struct* parentPS = session->LastPS;
if (parentPS == nullptr)
{
return PaintAddImageAsParent(
session, image_id, offset.x, offset.y, boundBoxLength.x, boundBoxLength.y, boundBoxLength.z, offset.z,
boundBoxOffset.x, boundBoxOffset.y, boundBoxOffset.z);
return PaintAddImageAsParent(session, image_id, offset, boundBoxLength, boundBoxOffset);
}

auto* ps = CreateNormalPaintStruct(session, image_id, offset, boundBoxLength, boundBoxOffset);
Expand Down
3 changes: 3 additions & 0 deletions src/openrct2/paint/Paint.h
Expand Up @@ -298,6 +298,9 @@ paint_struct* PaintAddImageAsParent(
paint_session* session, uint32_t image_id, int8_t x_offset, int8_t y_offset, int16_t bound_box_length_x,
int16_t bound_box_length_y, int8_t bound_box_length_z, int16_t z_offset, int16_t bound_box_offset_x,
int16_t bound_box_offset_y, int16_t bound_box_offset_z);
paint_struct* PaintAddImageAsParent(
paint_session* session, uint32_t image_id, const CoordsXYZ& offset, const CoordsXYZ& boundBoxSize,
const CoordsXYZ& boundBoxOffset);
[[nodiscard]] paint_struct* PaintAddImageAsOrphan(
paint_session* session, uint32_t image_id, int8_t x_offset, int8_t y_offset, int16_t bound_box_length_x,
int16_t bound_box_length_y, int8_t bound_box_length_z, int16_t z_offset, int16_t bound_box_offset_x,
Expand Down
36 changes: 19 additions & 17 deletions src/openrct2/paint/Supports.cpp
Expand Up @@ -521,9 +521,9 @@ bool wooden_a_supports_paint_setup(
{
imageId += word_97B3C4[slope & TILE_ELEMENT_SURFACE_SLOPE_MASK];
imageId |= imageColourFlags;
PaintAddImageAsParent(session, imageId, 0, 0, 32, 32, 11, z, 0, 0, z + 2);
PaintAddImageAsParent(session, imageId, { 0, 0, z }, { 32, 32, 11 }, { 0, 0, z + 2 });

PaintAddImageAsParent(session, imageId + 4, 0, 0, 32, 32, 11, z + 16, 0, 0, z + 16 + 2);
PaintAddImageAsParent(session, imageId + 4, { 0, 0, z + 16 }, { 32, 32, 11 }, { 0, 0, z + 16 + 2 });

hasSupports = true;
}
Expand Down Expand Up @@ -552,7 +552,7 @@ bool wooden_a_supports_paint_setup(
imageId += word_97B3C4[slope & TILE_ELEMENT_SURFACE_SLOPE_MASK];
imageId |= imageColourFlags;

PaintAddImageAsParent(session, imageId, 0, 0, 32, 32, 11, z, 0, 0, z + 2);
PaintAddImageAsParent(session, imageId, { 0, 0, z }, { 32, 32, 11 }, { 0, 0, z + 2 });
hasSupports = true;
}
z += 16;
Expand All @@ -562,7 +562,7 @@ bool wooden_a_supports_paint_setup(
if (drawFlatPiece)
{
int32_t imageId = WoodenSupportImageIds[supportType].flat | imageColourFlags;
PaintAddImageAsParent(session, imageId, 0, 0, 32, 32, 0, z - 2);
PaintAddImageAsParent(session, imageId, { 0, 0, z - 2 }, { 32, 32, 0 });
hasSupports = true;
}

Expand All @@ -574,7 +574,7 @@ bool wooden_a_supports_paint_setup(
// Full support
int32_t imageId = WoodenSupportImageIds[supportType].full | imageColourFlags;
uint8_t ah = height == 2 ? 23 : 28;
PaintAddImageAsParent(session, imageId, 0, 0, 32, 32, ah, z);
PaintAddImageAsParent(session, imageId, { 0, 0, z }, { 32, 32, ah });
hasSupports = true;
z += 32;
height -= 2;
Expand All @@ -584,7 +584,7 @@ bool wooden_a_supports_paint_setup(
// Half support
int32_t imageId = WoodenSupportImageIds[supportType].half | imageColourFlags;
uint8_t ah = height == 1 ? 7 : 12;
PaintAddImageAsParent(session, imageId, 0, 0, 32, 32, ah, z);
PaintAddImageAsParent(session, imageId, { 0, 0, z }, { 32, 32, ah });
hasSupports = true;
z += 16;
height -= 1;
Expand Down Expand Up @@ -697,7 +697,8 @@ bool wooden_b_supports_paint_setup(
{
imageId += word_97B3C4[session->Support.slope & TILE_ELEMENT_SURFACE_SLOPE_MASK];

PaintAddImageAsParent(session, imageId | imageColourFlags, 0, 0, 32, 32, 11, baseHeight, 0, 0, baseHeight + 2);
PaintAddImageAsParent(
session, imageId | imageColourFlags, { 0, 0, baseHeight }, { 32, 32, 11 }, { 0, 0, baseHeight + 2 });
baseHeight += 16;

PaintAddImageAsParent(session, (imageId + 4) | imageColourFlags, 0, 0, 32, 32, 3, baseHeight, 0, 0, baseHeight + 2);
Expand Down Expand Up @@ -726,7 +727,8 @@ bool wooden_b_supports_paint_setup(
{
imageId += word_97B3C4[session->Support.slope & TILE_ELEMENT_SURFACE_SLOPE_MASK];

PaintAddImageAsParent(session, imageId | imageColourFlags, 0, 0, 32, 32, 3, baseHeight, 0, 0, baseHeight + 2);
PaintAddImageAsParent(
session, imageId | imageColourFlags, { 0, 0, baseHeight }, { 32, 32, 3 }, { 0, 0, baseHeight + 2 });
baseHeight += 16;

_9E32B1 = true;
Expand All @@ -743,7 +745,7 @@ bool wooden_b_supports_paint_setup(
else
{
PaintAddImageAsParent(
session, WoodenSupportImageIds[supportType].flat | imageColourFlags, 0, 0, 32, 32, 0, baseHeight - 2);
session, WoodenSupportImageIds[supportType].flat | imageColourFlags, { 0, 0, baseHeight - 2 }, { 32, 32, 0 });
_9E32B1 = true;
}
}
Expand Down Expand Up @@ -885,7 +887,7 @@ bool metal_a_supports_paint_setup(

uint32_t image_id = _metalSupportTypeToCrossbeamImages[supportType][ebp];
image_id |= imageColourFlags;
PaintAddImageAsParent(session, image_id, xOffset, yOffset, boundBoxLengthX, boundBoxLengthY, 1, height);
PaintAddImageAsParent(session, image_id, { xOffset, yOffset, height }, { boundBoxLengthX, boundBoxLengthY, 1 });

segment = newSegment;
}
Expand All @@ -904,7 +906,7 @@ bool metal_a_supports_paint_setup(
image_id += metal_supports_slope_image_map[supportSegments[segment].slope & TILE_ELEMENT_SURFACE_SLOPE_MASK];
image_id |= imageColourFlags;

PaintAddImageAsParent(session, image_id, xOffset, yOffset, 0, 0, 5, supportSegments[segment].height);
PaintAddImageAsParent(session, image_id, { xOffset, yOffset, supportSegments[segment].height }, { 0, 0, 5 });

height = supportSegments[segment].height + 6;
}
Expand All @@ -928,7 +930,7 @@ bool metal_a_supports_paint_setup(
image_id += heightDiff - 1;
image_id |= imageColourFlags;

PaintAddImageAsParent(session, image_id, xOffset, yOffset, 0, 0, heightDiff - 1, height);
PaintAddImageAsParent(session, image_id, { xOffset, yOffset, height }, { 0, 0, heightDiff - 1 });
}

height += heightDiff;
Expand Down Expand Up @@ -959,7 +961,7 @@ bool metal_a_supports_paint_setup(
if (count == 3 && z == 0x10)
image_id++;

PaintAddImageAsParent(session, image_id, xOffset, yOffset, 0, 0, z - 1, height);
PaintAddImageAsParent(session, image_id, { xOffset, yOffset, height }, { 0, 0, z - 1 });

height += z;
}
Expand Down Expand Up @@ -1000,8 +1002,7 @@ bool metal_a_supports_paint_setup(
image_id += z - 1;
image_id |= imageColourFlags;

PaintAddImageAsParent(
session, image_id, xOffset, yOffset, 0, 0, 0, height, boundBoxOffset.x, boundBoxOffset.y, boundBoxOffset.z);
PaintAddImageAsParent(session, image_id, { xOffset, yOffset, height }, { 0, 0, 0 }, boundBoxOffset);

height += z;
}
Expand Down Expand Up @@ -1252,7 +1253,8 @@ bool path_a_supports_paint_setup(
uint32_t imageId = (supportType * 24) + word_97B3C4[session->Support.slope & TILE_ELEMENT_SURFACE_SLOPE_MASK]
+ railingEntry->bridge_image;

PaintAddImageAsParent(session, imageId | imageColourFlags, 0, 0, 32, 32, 11, baseHeight, 0, 0, baseHeight + 2);
PaintAddImageAsParent(
session, imageId | imageColourFlags, { 0, 0, baseHeight }, { 32, 32, 11 }, { 0, 0, baseHeight + 2 });
baseHeight += 16;

PaintAddImageAsParent(session, (imageId + 4) | imageColourFlags, 0, 0, 32, 32, 11, baseHeight, 0, 0, baseHeight + 2);
Expand All @@ -1273,7 +1275,7 @@ bool path_a_supports_paint_setup(
uint32_t ebx = (supportType * 24) + word_97B3C4[session->Support.slope & TILE_ELEMENT_SURFACE_SLOPE_MASK]
+ railingEntry->bridge_image;

PaintAddImageAsParent(session, ebx | imageColourFlags, 0, 0, 32, 32, 11, baseHeight, 0, 0, baseHeight + 2);
PaintAddImageAsParent(session, ebx | imageColourFlags, { 0, 0, baseHeight }, { 32, 32, 11 }, { 0, 0, baseHeight + 2 });

hasSupports = true;
baseHeight += 16;
Expand Down
11 changes: 6 additions & 5 deletions src/openrct2/paint/VirtualFloor.cpp
Expand Up @@ -366,37 +366,38 @@ void virtual_floor_paint(paint_session* session)
uint8_t dullEdges = 0xF & ~occupiedEdges & ~litEdges;
uint8_t paintEdges = ((weAreOccupied || weAreLit) && weAreOwned) ? ~dullEdges : 0xF;

const auto virtualFloorOffset = CoordsXYZ{ 0, 0, _virtualFloorHeight };
if (paintEdges & EDGE_NE)
{
PaintAddImageAsParent(
session,
SPR_G2_SELECTION_EDGE_NE
| (!(occupiedEdges & EDGE_NE) ? ((litEdges & EDGE_NE) ? remap_lit : remap_base) : remap_edge),
0, 0, 0, 0, 1, _virtualFloorHeight, 5, 5, _virtualFloorHeight + ((dullEdges & EDGE_NE) ? -2 : 0));
virtualFloorOffset, { 0, 0, 1 }, { 5, 5, _virtualFloorHeight + ((dullEdges & EDGE_NE) ? -2 : 0) });
}
if (paintEdges & EDGE_SE)
{
PaintAddImageAsParent(
session,
SPR_G2_SELECTION_EDGE_SE
| (!(occupiedEdges & EDGE_SE) ? ((litEdges & EDGE_SE) ? remap_lit : remap_base) : remap_edge),
0, 0, 1, 1, 1, _virtualFloorHeight, 16, 27, _virtualFloorHeight + ((dullEdges & EDGE_SE) ? -2 : 0));
virtualFloorOffset, { 1, 1, 1 }, { 16, 27, _virtualFloorHeight + ((dullEdges & EDGE_SE) ? -2 : 0) });
}
if (paintEdges & EDGE_SW)
{
PaintAddImageAsParent(
session,
SPR_G2_SELECTION_EDGE_SW
| (!(occupiedEdges & EDGE_SW) ? ((litEdges & EDGE_SW) ? remap_lit : remap_base) : remap_edge),
0, 0, 1, 1, 1, _virtualFloorHeight, 27, 16, _virtualFloorHeight + ((dullEdges & EDGE_SW) ? -2 : 0));
virtualFloorOffset, { 1, 1, 1 }, { 27, 16, _virtualFloorHeight + ((dullEdges & EDGE_SW) ? -2 : 0) });
}
if (paintEdges & EDGE_NW)
{
PaintAddImageAsParent(
session,
SPR_G2_SELECTION_EDGE_NW
| (!(occupiedEdges & EDGE_NW) ? ((litEdges & EDGE_NW) ? remap_lit : remap_base) : remap_edge),
0, 0, 0, 0, 1, _virtualFloorHeight, 5, 5, _virtualFloorHeight + ((dullEdges & EDGE_NW) ? -2 : 0));
virtualFloorOffset, { 0, 0, 1 }, { 5, 5, _virtualFloorHeight + ((dullEdges & EDGE_NW) ? -2 : 0) });
}

if (gConfigGeneral.virtual_floor_style != VirtualFloorStyles::Glassy)
Expand All @@ -406,7 +407,7 @@ void virtual_floor_paint(paint_session* session)
{
int32_t imageColourFlats = SPR_G2_SURFACE_GLASSY_RECOLOURABLE | IMAGE_TYPE_REMAP | IMAGE_TYPE_TRANSPARENT
| EnumValue(FilterPaletteID::PaletteWater) << 19;
PaintAddImageAsParent(session, imageColourFlats, 0, 0, 30, 30, 0, _virtualFloorHeight, 2, 2, _virtualFloorHeight - 3);
PaintAddImageAsParent(session, imageColourFlats, virtualFloorOffset, { 30, 30, 0 }, { 2, 2, _virtualFloorHeight - 3 });
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/openrct2/paint/sprite/Paint.Misc.cpp
Expand Up @@ -32,7 +32,7 @@ const uint32_t vehicle_particle_base_sprites[] = {
template<> void PaintEntity(paint_session* session, const SteamParticle* particle, int32_t imageDirection)
{
uint32_t imageId = 22637 + (particle->frame / 256);
PaintAddImageAsParent(session, imageId, 0, 0, 1, 1, 0, particle->z);
PaintAddImageAsParent(session, imageId, { 0, 0, particle->z }, { 1, 1, 0 });
}

template<> void PaintEntity(paint_session* session, const MoneyEffect* moneyEffect, int32_t imageDirection)
Expand Down Expand Up @@ -63,23 +63,23 @@ template<> void PaintEntity(paint_session* session, const VehicleCrashParticle*
return;
uint32_t imageId = vehicle_particle_base_sprites[particle->crashed_sprite_base] + particle->frame / 256;
imageId = imageId | (particle->colour[0] << 19) | (particle->colour[1] << 24) | IMAGE_TYPE_REMAP | IMAGE_TYPE_REMAP_2_PLUS;
PaintAddImageAsParent(session, imageId, 0, 0, 1, 1, 0, particle->z);
PaintAddImageAsParent(session, imageId, { 0, 0, particle->z }, { 1, 1, 0 });
}

template<> void PaintEntity(paint_session* session, const ExplosionCloud* particle, int32_t imageDirection)
{
if (particle == nullptr)
return;
uint32_t imageId = 22878 + (particle->frame / 256);
PaintAddImageAsParent(session, imageId, 0, 0, 1, 1, 0, particle->z);
PaintAddImageAsParent(session, imageId, { 0, 0, particle->z }, { 1, 1, 0 });
}

template<> void PaintEntity(paint_session* session, const CrashSplashParticle* crashSplash, int32_t imageDirection)
{
if (crashSplash == nullptr)
return;
uint32_t imageId = 22927 + (crashSplash->frame / 256);
PaintAddImageAsParent(session, imageId, 0, 0, 1, 1, 0, crashSplash->z);
PaintAddImageAsParent(session, imageId, { 0, 0, crashSplash->z }, { 1, 1, 0 });
}

template<> void PaintEntity(paint_session* session, const ExplosionFlare* flare, int32_t imageDirection)
Expand All @@ -88,7 +88,7 @@ template<> void PaintEntity(paint_session* session, const ExplosionFlare* flare,
if (flare == nullptr)
return;
uint32_t imageId = 22896 + (flare->frame / 256);
PaintAddImageAsParent(session, imageId, 0, 0, 1, 1, 0, flare->z);
PaintAddImageAsParent(session, imageId, { 0, 0, flare->z }, { 1, 1, 0 });
}

constexpr uint32_t JumpingFountainSnowBaseImage = 23037;
Expand Down Expand Up @@ -141,7 +141,7 @@ template<> void PaintEntity(paint_session* session, const Balloon* balloon, int3
}

imageId = imageId | (balloon->colour << 19) | IMAGE_TYPE_REMAP;
PaintAddImageAsParent(session, imageId, 0, 0, 1, 1, 0, balloon->z);
PaintAddImageAsParent(session, imageId, { 0, 0, balloon->z }, { 1, 1, 0 });
}

template<> void PaintEntity(paint_session* session, const Duck* duck, int32_t imageDirection)
Expand All @@ -154,7 +154,7 @@ template<> void PaintEntity(paint_session* session, const Duck* duck, int32_t im
uint32_t imageId = duck->GetFrameImage(imageDirection);
if (imageId != 0)
{
PaintAddImageAsParent(session, imageId, 0, 0, 1, 1, 0, duck->z);
PaintAddImageAsParent(session, imageId, { 0, 0, duck->z }, { 1, 1, 0 });
}
}
}
6 changes: 3 additions & 3 deletions src/openrct2/paint/sprite/Paint.Peep.cpp
Expand Up @@ -87,21 +87,21 @@ template<> void PaintEntity(paint_session* session, const Peep* peep, int32_t im
if (baseImageId >= 10717 && baseImageId < 10749)
{
imageId = (baseImageId + 32) | guest->HatColour << 19 | IMAGE_TYPE_REMAP;
PaintAddImageAsChild(session, imageId, 0, 0, 1, 1, 11, peep->z, 0, 0, peep->z + 5);
PaintAddImageAsChild(session, imageId, { 0, 0, peep->z }, { 1, 1, 11 }, { 0, 0, peep->z + 5 });
return;
}

if (baseImageId >= 10781 && baseImageId < 10813)
{
imageId = (baseImageId + 32) | guest->BalloonColour << 19 | IMAGE_TYPE_REMAP;
PaintAddImageAsChild(session, imageId, 0, 0, 1, 1, 11, peep->z, 0, 0, peep->z + 5);
PaintAddImageAsChild(session, imageId, { 0, 0, peep->z }, { 1, 1, 11 }, { 0, 0, peep->z + 5 });
return;
}

if (baseImageId >= 11197 && baseImageId < 11229)
{
imageId = (baseImageId + 32) | guest->UmbrellaColour << 19 | IMAGE_TYPE_REMAP;
PaintAddImageAsChild(session, imageId, 0, 0, 1, 1, 11, peep->z, 0, 0, peep->z + 5);
PaintAddImageAsChild(session, imageId, { 0, 0, peep->z }, { 1, 1, 11 }, { 0, 0, peep->z + 5 });
return;
}
}
Expand Down

0 comments on commit c87860b

Please sign in to comment.