Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash with drawing swipe #3662

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions config/fxdata/creature.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,8 @@ RangeMax = 0
; 3,4 will only target other players, 5,6 only own player.
; 7 will target traps.
PrimaryTarget = 0
; Instance used by creature "going postal" while working in a room
; Creature will only use available instances with the highest priority,
; If multiple instances have the same PostalPriority, one is chosen randomly
; 0 disables the instance for beeing used while "going postal".
; Instance used when the creature is 'going postal' in a room. It will use the instance with the highest priority.
; If multiple have the same priority, one is chosen randomly. 0 disables the instance.
PostalPriority = 0
; Instance properties flags:
; REPEAT_TRIGGER allows player to hold down the mouse button to cast.
Expand Down
29 changes: 20 additions & 9 deletions src/thing_creature.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,51 +375,62 @@ void draw_swipe_graphic(void)
if (thing_is_creature(thing))
{
struct CreatureControl* cctrl = creature_control_get_from_thing(thing);
if (instance_draws_possession_swipe(cctrl->instance_id))
if ((instance_draws_possession_swipe(cctrl->instance_id)) && (cctrl->inst_total_turns > 0))
{
lbDisplay.DrawFlags = Lb_SPRITE_TRANSPAR4;
long n = (int)cctrl->inst_turn * (5 << 8) / cctrl->inst_total_turns;
long allwidth = 0;
long i = (abs(n) >> 8) -1;
if (i >= SWIPE_SPRITE_FRAMES)
{
i = SWIPE_SPRITE_FRAMES-1;
// FIXME: sprites may not be adjacent in the future, causing code below incorrect sprites and possibly crash
}
// FIXME: sprites may not be adjacent in the future, causing code below incorrect sprites and possibly crash.
const struct TbSprite* sprlist = get_sprite(swipe_sprites, SWIPE_SPRITES_X * SWIPE_SPRITES_Y * i);
const struct TbSprite* startspr = &sprlist[1];
const struct TbSprite* endspr = &sprlist[1];
for (n=0; n < SWIPE_SPRITES_X; n++)
for (n = 0; n < SWIPE_SPRITES_X; n++)
{
allwidth += endspr->SWidth;
endspr++;
}
if (allwidth == 0)
{
return; // No point trying to draw a zero-width sprite.
}
int units_per_px = (LbScreenWidth() * 59 / 64) * 16 / allwidth;
if (units_per_px == 0)
{
return;
}
int scrpos_y = (MyScreenHeight * 16 / units_per_px - (startspr->SHeight + endspr->SHeight)) / 2;
const struct TbSprite *spr;
int scrpos_x;
if (myplyr->swipe_sprite_drawLR)
{
int delta_y = sprlist[1].SHeight;
for (i=0; i < SWIPE_SPRITES_X*SWIPE_SPRITES_Y; i+=SWIPE_SPRITES_X)
for (i = 0; i < SWIPE_SPRITES_X*SWIPE_SPRITES_Y; i += SWIPE_SPRITES_X)
{
spr = &startspr[i];
scrpos_x = (MyScreenWidth * 16 / units_per_px - allwidth) / 2;
for (n=0; n < SWIPE_SPRITES_X; n++)
for (n = 0; n < SWIPE_SPRITES_X; n++)
{
LbSpriteDrawResized(scrpos_x * units_per_px / 16, scrpos_y * units_per_px / 16, units_per_px, spr);
scrpos_x += spr->SWidth;
spr++;
}
scrpos_y += delta_y;
}
} else
}
else
{
lbDisplay.DrawFlags = Lb_SPRITE_TRANSPAR4 | Lb_SPRITE_FLIP_HORIZ;
for (i=0; i < SWIPE_SPRITES_X*SWIPE_SPRITES_Y; i+=SWIPE_SPRITES_X)
for (i = 0; i < SWIPE_SPRITES_X*SWIPE_SPRITES_Y; i += SWIPE_SPRITES_X)
{
spr = &sprlist[SWIPE_SPRITES_X+i];
int delta_y = spr->SHeight;
scrpos_x = (MyScreenWidth * 16 / units_per_px - allwidth) / 2;
for (n=0; n < SWIPE_SPRITES_X; n++)
for (n = 0; n < SWIPE_SPRITES_X; n++)
{
LbSpriteDrawResized(scrpos_x * units_per_px / 16, scrpos_y * units_per_px / 16, units_per_px, spr);
scrpos_x += spr->SWidth;
Expand All @@ -432,7 +443,7 @@ void draw_swipe_graphic(void)
return;
}
}
// we get here many times a second when in possession mode and not attacking: to randomise the swipe direction
// We get here many times a second when in possession mode and not attacking: to randomise the swipe direction.
randomise_swipe_graphic_direction();
}

Expand Down
Loading