Change ChildScreenSpriteToDraw relative flag to an enum

Use separate modes for prior and upstream non-relative modes
pull/441/head
Jonathan G Rennison 1 year ago
parent 14f4f6d104
commit 87056562e5

@ -171,7 +171,7 @@ struct ChildScreenSpriteToDraw {
const SubSprite *sub; ///< only draw a rectangular part of the sprite
int32 x;
int32 y;
bool relative;
ChildScreenSpritePositionMode position_mode;
int next; ///< next child to draw (-1 at the end)
};
@ -950,7 +950,7 @@ static void AddChildSpriteToFoundation(SpriteID image, PaletteID pal, const SubS
int *old_child = _vd.last_child;
_vd.last_child = _vd.last_foundation_child[foundation_part];
AddChildSpriteScreen(image, pal, offs.x + extra_offs_x, offs.y + extra_offs_y, false, sub, false, false);
AddChildSpriteScreen(image, pal, offs.x + extra_offs_x, offs.y + extra_offs_y, false, sub, false, ChildScreenSpritePositionMode::NON_RELATIVE);
/* Switch back to last ChildSprite list */
_vd.last_child = old_child;
@ -1051,7 +1051,7 @@ static void AddCombinedSprite(SpriteID image, PaletteID pal, int x, int y, int z
bottom <= _vdd->dpi.top)
return;
AddChildSpriteScreen(image, pal, pt.x, pt.y, false, sub, false, false);
AddChildSpriteScreen(image, pal, pt.x, pt.y, false, sub, false, ChildScreenSpritePositionMode::ABSOLUTE);
if (left < _vd.combine_left) _vd.combine_left = left;
if (right > _vd.combine_right) _vd.combine_right = right;
if (top < _vd.combine_top) _vd.combine_top = top;
@ -1265,9 +1265,9 @@ static bool IsInsideSelectedRectangle(int x, int y)
* @param transparent if true, switch the palette between the provided palette and the transparent palette,
* @param sub Only draw a part of the sprite.
* @param scale if true, scale offsets to base zoom level.
* @param relative if true, draw sprite relative to parent sprite offsets.
* @param position_mode position mode.
*/
void AddChildSpriteScreen(SpriteID image, PaletteID pal, int x, int y, bool transparent, const SubSprite *sub, bool scale, bool relative)
void AddChildSpriteScreen(SpriteID image, PaletteID pal, int x, int y, bool transparent, const SubSprite *sub, bool scale, ChildScreenSpritePositionMode position_mode)
{
dbg_assert((image & SPRITE_MASK) < MAX_SPRITES);
@ -1288,7 +1288,7 @@ void AddChildSpriteScreen(SpriteID image, PaletteID pal, int x, int y, bool tran
cs.sub = sub;
cs.x = scale ? x * ZOOM_LVL_BASE : x;
cs.y = scale ? y * ZOOM_LVL_BASE : y;
cs.relative = relative;
cs.position_mode = position_mode;
cs.next = -1;
/* Append the sprite to the active ChildSprite list.
@ -2049,11 +2049,22 @@ static void ViewportDrawParentSprites(const ViewportDrawerDynamic *vdd, const Dr
while (child_idx >= 0) {
const ChildScreenSpriteToDraw *cs = csstdv->data() + child_idx;
child_idx = cs->next;
if (cs->relative) {
DrawSpriteViewport(vdd->sprite_data, dpi, cs->image, cs->pal, ps->left + cs->x, ps->top + cs->y, cs->sub);
} else {
DrawSpriteViewport(vdd->sprite_data, dpi, cs->image, cs->pal, ps->x + cs->x, ps->y + cs->y, cs->sub);
int x = cs->x;
int y = cs->y;
switch (cs->position_mode) {
case ChildScreenSpritePositionMode::RELATIVE:
x += ps->left;
y += ps->top;
break;
case ChildScreenSpritePositionMode::NON_RELATIVE:
x += ps->x;
y += ps->y;
break;
case ChildScreenSpritePositionMode::ABSOLUTE:
/* No adjustment */
break;
}
DrawSpriteViewport(vdd->sprite_data, dpi, cs->image, cs->pal, x, y, cs->sub);
}
}
}

@ -70,7 +70,7 @@ void OffsetGroundSprite(int x, int y);
void DrawGroundSprite(SpriteID image, PaletteID pal, const SubSprite *sub = nullptr, int extra_offs_x = 0, int extra_offs_y = 0);
void DrawGroundSpriteAt(SpriteID image, PaletteID pal, int32 x, int32 y, int z, const SubSprite *sub = nullptr, int extra_offs_x = 0, int extra_offs_y = 0);
void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int w, int h, int dz, int z, bool transparent = false, int bb_offset_x = 0, int bb_offset_y = 0, int bb_offset_z = 0, const SubSprite *sub = nullptr);
void AddChildSpriteScreen(SpriteID image, PaletteID pal, int x, int y, bool transparent = false, const SubSprite *sub = nullptr, bool scale = true, bool relative = true);
void AddChildSpriteScreen(SpriteID image, PaletteID pal, int x, int y, bool transparent = false, const SubSprite *sub = nullptr, bool scale = true, ChildScreenSpritePositionMode position_mode = ChildScreenSpritePositionMode::RELATIVE);
void ViewportAddString(ViewportDrawerDynamic *vdd, const DrawPixelInfo *dpi, ZoomLevel small_from, const ViewportSign *sign, StringID string_normal, StringID string_small, StringID string_small_shadow, uint64 params_1, uint64 params_2 = 0, Colours colour = INVALID_COLOUR);

@ -221,4 +221,10 @@ enum ViewportMarkDirtyFlags : byte {
};
DECLARE_ENUM_AS_BIT_SET(ViewportMarkDirtyFlags)
enum class ChildScreenSpritePositionMode : uint8 {
RELATIVE,
NON_RELATIVE,
ABSOLUTE,
};
#endif /* VIEWPORT_TYPE_H */

Loading…
Cancel
Save