- split the sprite animation code for CON-based actors into a separate function.

Like the shadow code this is virtually identical for Duke and RR.
This commit is contained in:
Christoph Oelckers 2022-12-03 19:33:13 +01:00
parent 0d7288c543
commit 5b34917f62
4 changed files with 110 additions and 171 deletions

View file

@ -78,4 +78,105 @@ void drawshadows(tspriteArray& tsprites, tspritetype* t, DDukeActor* h)
} }
} }
} }
void applyanimations(tspritetype* t, DDukeActor* h, const DVector2& viewVec, DAngle viewang)
{
if (gs.actorinfo[h->spr.picnum].scriptaddress && !actorflag(h, SFLAG2_DONTANIMATE) && (t->cstat & CSTAT_SPRITE_ALIGNMENT_MASK) != CSTAT_SPRITE_ALIGNMENT_SLAB)
{
DAngle kang;
int t4 = h->temp_data[4];
int k = 0, l = 0;
if (t4)
{
l = ScriptCode[t4 + 2];
if (hw_models && modelManager.CheckModel(h->spr.picnum, h->spr.pal))
{
k = 0;
t->cstat &= ~CSTAT_SPRITE_XFLIP;
}
else switch (l)
{
case 2:
k = angletorotation1(h->spr.Angles.Yaw, viewang, 8, 1);
break;
case 3:
case 4:
k = angletorotation1(h->spr.Angles.Yaw, viewang, 7);
if (k > 3)
{
t->cstat |= CSTAT_SPRITE_XFLIP;
k = 7 - k;
}
else t->cstat &= ~CSTAT_SPRITE_XFLIP;
break;
case 5:
kang = (h->spr.pos - viewVec).Angle();
k = angletorotation1(h->spr.Angles.Yaw, kang);
if (k > 4)
{
k = 8 - k;
t->cstat |= CSTAT_SPRITE_XFLIP;
}
else t->cstat &= ~CSTAT_SPRITE_XFLIP;
break;
case 7:
kang = (h->spr.pos - viewVec).Angle();
k = angletorotation2(h->spr.Angles.Yaw, kang);
if (k > 6)
{
k = 12 - k;
t->cstat |= CSTAT_SPRITE_XFLIP;
}
else t->cstat &= ~CSTAT_SPRITE_XFLIP;
break;
case 8:
k = angletorotation1(h->spr.Angles.Yaw, viewang);
t->cstat &= ~CSTAT_SPRITE_XFLIP;
break;
default:
if (isRR())
{
bool bg = badguy(h);
if (bg && h->spr.statnum == 2 && h->spr.extra > 0)
{
kang = (h->spr.pos - viewVec).Angle();
k = angletorotation1(h->spr.Angles.Yaw, kang);
if (k > 4)
{
k = 8 - k;
t->cstat |= CSTAT_SPRITE_XFLIP;
}
else t->cstat &= ~CSTAT_SPRITE_XFLIP;
break;
}
k = 0;
bg = 0;
break;
}
}
t->picnum += k + ScriptCode[t4] + l * h->temp_data[3];
if (l > 0)
{
while (t->picnum >= 0 && t->picnum < MAXTILES && !tileGetTexture(t->picnum)->isValid())
t->picnum -= l; //Hack, for actors
}
if (t->picnum < 0 || t->picnum >= MAXTILES)
{
t->picnum = 0;
t->scale = DVector2(0, 0);
}
if (h->dispicnum >= 0)
h->dispicnum = t->picnum;
}
else if (display_mirror == 1)
t->cstat |= CSTAT_SPRITE_XFLIP;
}
}
END_DUKE_NS END_DUKE_NS

View file

@ -47,9 +47,8 @@ BEGIN_DUKE_NS
void animatesprites_d(tspriteArray& tsprites, const DVector2& viewVec, DAngle viewang, double interpfrac) void animatesprites_d(tspriteArray& tsprites, const DVector2& viewVec, DAngle viewang, double interpfrac)
{ {
DAngle kang;
int k, p; int k, p;
int l, t1, t3, t4; int t1, t3, t4;
tspritetype* t; tspritetype* t;
DDukeActor* h; DDukeActor* h;
@ -301,77 +300,7 @@ void animatesprites_d(tspriteArray& tsprites, const DVector2& viewVec, DAngle vi
break; break;
} }
if (gs.actorinfo[h->spr.picnum].scriptaddress && !actorflag(h, SFLAG2_DONTANIMATE)) applyanimations(t, h, viewVec, viewang);
{
if (t4)
{
l = ScriptCode[t4 + 2];
if (hw_models && modelManager.CheckModel(h->spr.picnum, h->spr.pal))
{
k = 0;
t->cstat &= ~CSTAT_SPRITE_XFLIP;
}
else switch (l)
{
case 2:
k = angletorotation1(h->spr.Angles.Yaw, viewang, 8, 1);
break;
case 3:
case 4:
k = angletorotation1(h->spr.Angles.Yaw, viewang, 7);
if (k > 3)
{
t->cstat |= CSTAT_SPRITE_XFLIP;
k = 7 - k;
}
else t->cstat &= ~CSTAT_SPRITE_XFLIP;
break;
case 5:
kang = (h->spr.pos - viewVec).Angle();
k = angletorotation1(h->spr.Angles.Yaw, kang);
if (k > 4)
{
k = 8 - k;
t->cstat |= CSTAT_SPRITE_XFLIP;
}
else t->cstat &= ~CSTAT_SPRITE_XFLIP;
break;
case 7:
kang = (h->spr.pos - viewVec).Angle();
k = angletorotation2(h->spr.Angles.Yaw, kang);
if (k > 6)
{
k = 12 - k;
t->cstat |= CSTAT_SPRITE_XFLIP;
}
else t->cstat &= ~CSTAT_SPRITE_XFLIP;
break;
case 8:
k = angletorotation1(h->spr.Angles.Yaw, viewang);
t->cstat &= ~CSTAT_SPRITE_XFLIP;
break;
default:
k = 0;
break;
}
t->picnum += k + ScriptCode[t4] + l * t3;
if (l > 0)
{
while (t->picnum >= 0 && t->picnum < MAXTILES && !tileGetTexture(t->picnum)->isValid())
t->picnum -= l; //Hack, for actors
}
if (h->dispicnum >= 0)
h->dispicnum = t->picnum;
}
else if (display_mirror == 1)
t->cstat |= CSTAT_SPRITE_XFLIP;
}
if (h->spr.statnum == STAT_DUMMYPLAYER || badguy(h) || (h->isPlayer() && h->GetOwner())) if (h->spr.statnum == STAT_DUMMYPLAYER || badguy(h) || (h->isPlayer() && h->GetOwner()))
{ {

View file

@ -348,101 +348,7 @@ void animatesprites_r(tspriteArray& tsprites, const DVector2& viewVec, DAngle vi
copyfloorpal(t, sectp); copyfloorpal(t, sectp);
break; break;
} }
applyanimations(t, h, viewVec, viewang);
if (gs.actorinfo[h->spr.picnum].scriptaddress && (t->cstat & CSTAT_SPRITE_ALIGNMENT_MASK) != CSTAT_SPRITE_ALIGNMENT_SLAB)
{
if (t4)
{
l = ScriptCode[t4 + 2];
if (hw_models && modelManager.CheckModel(h->spr.picnum, h->spr.pal))
{
k = 0;
t->cstat &= ~CSTAT_SPRITE_XFLIP;
}
else switch (l)
{
case 2:
k = angletorotation1(h->spr.Angles.Yaw, viewang, 8, 1);
break;
case 3:
case 4:
k = angletorotation1(h->spr.Angles.Yaw, viewang, 7);
if (k > 3)
{
t->cstat |= CSTAT_SPRITE_XFLIP;
k = 7 - k;
}
else t->cstat &= ~CSTAT_SPRITE_XFLIP;
break;
case 5:
kang = (h->spr.pos - viewVec).Angle();
k = angletorotation1(h->spr.Angles.Yaw, kang);
if (k > 4)
{
k = 8 - k;
t->cstat |= CSTAT_SPRITE_XFLIP;
}
else t->cstat &= ~CSTAT_SPRITE_XFLIP;
break;
case 7:
kang = (h->spr.pos - viewVec).Angle();
k = angletorotation2(h->spr.Angles.Yaw, kang);
if (k > 6)
{
k = 12 - k;
t->cstat |= CSTAT_SPRITE_XFLIP;
}
else t->cstat &= ~CSTAT_SPRITE_XFLIP;
break;
case 8:
k = angletorotation1(h->spr.Angles.Yaw, viewang);
t->cstat &= ~CSTAT_SPRITE_XFLIP;
break;
default:
bg = badguy(h);
if (bg && h->spr.statnum == 2 && h->spr.extra > 0)
{
kang = (h->spr.pos - viewVec).Angle();
k = angletorotation1(h->spr.Angles.Yaw, kang);
if (k > 4)
{
k = 8 - k;
t->cstat |= CSTAT_SPRITE_XFLIP;
}
else t->cstat &= ~CSTAT_SPRITE_XFLIP;
break;
}
k = 0;
bg = 0;
break;
}
t->picnum += k + ScriptCode[t4] + l * t3;
if (l > 0)
{
while (t->picnum >= 0 && t->picnum < MAXTILES && !tileGetTexture(t->picnum)->isValid())
t->picnum -= l; //Hack, for actors
}
if (t->picnum < 0 || t->picnum >= MAXTILES)
{
t->picnum = 0;
t->scale = DVector2(0, 0);
}
if (h->dispicnum >= 0)
h->dispicnum = t->picnum;
}
else if (display_mirror == 1)
t->cstat |= CSTAT_SPRITE_XFLIP;
}
if (!isRRRA() && h->spr.picnum == SBMOVE)
t->shade = -127;
if (h->spr.statnum == STAT_DUMMYPLAYER || badguy(h) || (h->isPlayer() && h->GetOwner())) if (h->spr.statnum == STAT_DUMMYPLAYER || badguy(h) || (h->isPlayer() && h->GetOwner()))
{ {
@ -450,11 +356,13 @@ void animatesprites_r(tspriteArray& tsprites, const DVector2& viewVec, DAngle vi
} }
switch (h->spr.picnum) switch (h->spr.picnum)
{ {
if (!isRRRA()) break; case SBMOVE:
[[fallthrough]]; if (!isRRRA())
t->shade = -127;
break;
case EXPLOSION2: case EXPLOSION2:
case ATOMICHEALTH: case ATOMICHEALTH:
case CHAINGUN: case CHAINGUN:

View file

@ -218,6 +218,7 @@ void loadcons();
void DrawStatusBar(); void DrawStatusBar();
void drawshadows(tspriteArray& tsprites, tspritetype* t, DDukeActor* h); void drawshadows(tspriteArray& tsprites, tspritetype* t, DDukeActor* h);
void applyanimations(tspritetype* t, DDukeActor* h, const DVector2& viewVec, DAngle viewang);
inline int32_t krand(void) inline int32_t krand(void)
{ {