Codechange: Unify structures with sprite sub-tile bounds and simplify bounding boxes. (#14424)
Lots of different structs contain variations on sub-tile bounds with different naming. Unify into a single struct that can be inherited and passed directly to AddSortableSpriteToDraw. At the same time, offsets now work more logically: sub-tile bounds now specify the bounding box, and an offset can be applied to the sprite.
This commit is contained in:
@@ -660,12 +660,17 @@ static void AddCombinedSprite(SpriteID image, PaletteID pal, int x, int y, int z
|
||||
* @param bb_offset_z bounding box extent towards negative Z (world)
|
||||
* @param sub Only draw a part of the sprite.
|
||||
*/
|
||||
void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int w, int h, int dz, int z, bool transparent, int bb_offset_x, int bb_offset_y, int bb_offset_z, const SubSprite *sub)
|
||||
void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int z, const SpriteBounds &bounds, bool transparent, const SubSprite *sub)
|
||||
{
|
||||
int32_t left, right, top, bottom;
|
||||
|
||||
assert((image & SPRITE_MASK) < MAX_SPRITES);
|
||||
|
||||
/* Move to bounding box. */
|
||||
x += bounds.origin.x;
|
||||
y += bounds.origin.y;
|
||||
z += bounds.origin.z;
|
||||
|
||||
/* make the sprites transparent with the right palette */
|
||||
if (transparent) {
|
||||
SetBit(image, PALETTE_MODIFIER_TRANSPARENT);
|
||||
@@ -673,21 +678,21 @@ void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int w,
|
||||
}
|
||||
|
||||
if (_vd.combine_sprites == SPRITE_COMBINE_ACTIVE) {
|
||||
AddCombinedSprite(image, pal, x, y, z, sub);
|
||||
AddCombinedSprite(image, pal, x + bounds.offset.x, y + bounds.offset.y, z + bounds.offset.z, sub);
|
||||
return;
|
||||
}
|
||||
|
||||
_vd.last_child = LAST_CHILD_NONE;
|
||||
|
||||
Point pt = RemapCoords(x, y, z);
|
||||
Point pt = RemapCoords(x + bounds.offset.x, y + bounds.offset.y, z + bounds.offset.z);
|
||||
int tmp_left, tmp_top, tmp_x = pt.x, tmp_y = pt.y;
|
||||
|
||||
/* Compute screen extents of sprite */
|
||||
if (image == SPR_EMPTY_BOUNDING_BOX) {
|
||||
left = tmp_left = RemapCoords(x + w , y + bb_offset_y, z + bb_offset_z).x;
|
||||
right = RemapCoords(x + bb_offset_x, y + h , z + bb_offset_z).x + 1;
|
||||
top = tmp_top = RemapCoords(x + bb_offset_x, y + bb_offset_y, z + dz ).y;
|
||||
bottom = RemapCoords(x + w , y + h , z + bb_offset_z).y + 1;
|
||||
left = tmp_left = RemapCoords(x + bounds.extent.x, y, z).x;
|
||||
right = RemapCoords(x, y + bounds.extent.y, z).x + 1;
|
||||
top = tmp_top = RemapCoords(x, y, z + bounds.extent.z).y;
|
||||
bottom = RemapCoords(x + bounds.extent.x, y + bounds.extent.y, z).y + 1;
|
||||
} else {
|
||||
const Sprite *spr = GetSprite(image & SPRITE_MASK, SpriteType::Normal);
|
||||
left = tmp_left = (pt.x += spr->x_offs);
|
||||
@@ -698,10 +703,10 @@ void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int w,
|
||||
|
||||
if (_draw_bounding_boxes && (image != SPR_EMPTY_BOUNDING_BOX)) {
|
||||
/* Compute maximal extents of sprite and its bounding box */
|
||||
left = std::min(left , RemapCoords(x + w , y + bb_offset_y, z + bb_offset_z).x);
|
||||
right = std::max(right , RemapCoords(x + bb_offset_x, y + h , z + bb_offset_z).x + 1);
|
||||
top = std::min(top , RemapCoords(x + bb_offset_x, y + bb_offset_y, z + dz ).y);
|
||||
bottom = std::max(bottom, RemapCoords(x + w , y + h , z + bb_offset_z).y + 1);
|
||||
left = std::min(left , RemapCoords(x + bounds.extent.x, y, z).x);
|
||||
right = std::max(right , RemapCoords(x, y + bounds.extent.y, z).x + 1);
|
||||
top = std::min(top , RemapCoords(x, y, z + bounds.extent.z).y);
|
||||
bottom = std::max(bottom, RemapCoords(x + bounds.extent.x, y + bounds.extent.y, z).y + 1);
|
||||
}
|
||||
|
||||
/* Do not add the sprite to the viewport, if it is outside */
|
||||
@@ -722,14 +727,14 @@ void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int w,
|
||||
ps.image = image;
|
||||
ps.pal = pal;
|
||||
ps.sub = sub;
|
||||
ps.xmin = x + bb_offset_x;
|
||||
ps.xmax = x + std::max(bb_offset_x, w) - 1;
|
||||
ps.xmin = x;
|
||||
ps.xmax = x + bounds.extent.x - 1;
|
||||
|
||||
ps.ymin = y + bb_offset_y;
|
||||
ps.ymax = y + std::max(bb_offset_y, h) - 1;
|
||||
ps.ymin = y;
|
||||
ps.ymax = y + bounds.extent.y - 1;
|
||||
|
||||
ps.zmin = z + bb_offset_z;
|
||||
ps.zmax = z + std::max(bb_offset_z, dz) - 1;
|
||||
ps.zmin = z;
|
||||
ps.zmax = z + bounds.extent.z - 1;
|
||||
|
||||
ps.first_child = LAST_CHILD_NONE;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user