From 5b34917f62290187e039dc7327a3affb47788d22 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 3 Dec 2022 19:33:13 +0100 Subject: [PATCH] - 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. --- source/games/duke/src/animatesprites.cpp | 101 ++++++++++++++++++++ source/games/duke/src/animatesprites_d.cpp | 75 +-------------- source/games/duke/src/animatesprites_r.cpp | 104 ++------------------- source/games/duke/src/funct.h | 1 + 4 files changed, 110 insertions(+), 171 deletions(-) diff --git a/source/games/duke/src/animatesprites.cpp b/source/games/duke/src/animatesprites.cpp index f926610c8..f34af7c9f 100644 --- a/source/games/duke/src/animatesprites.cpp +++ b/source/games/duke/src/animatesprites.cpp @@ -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 diff --git a/source/games/duke/src/animatesprites_d.cpp b/source/games/duke/src/animatesprites_d.cpp index 5f690cb90..383f73d5c 100644 --- a/source/games/duke/src/animatesprites_d.cpp +++ b/source/games/duke/src/animatesprites_d.cpp @@ -47,9 +47,8 @@ BEGIN_DUKE_NS void animatesprites_d(tspriteArray& tsprites, const DVector2& viewVec, DAngle viewang, double interpfrac) { - DAngle kang; int k, p; - int l, t1, t3, t4; + int t1, t3, t4; tspritetype* t; DDukeActor* h; @@ -301,77 +300,7 @@ void animatesprites_d(tspriteArray& tsprites, const DVector2& viewVec, DAngle vi break; } - if (gs.actorinfo[h->spr.picnum].scriptaddress && !actorflag(h, SFLAG2_DONTANIMATE)) - { - 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; - } + applyanimations(t, h, viewVec, viewang); if (h->spr.statnum == STAT_DUMMYPLAYER || badguy(h) || (h->isPlayer() && h->GetOwner())) { diff --git a/source/games/duke/src/animatesprites_r.cpp b/source/games/duke/src/animatesprites_r.cpp index d104eba45..76ea9cb1d 100644 --- a/source/games/duke/src/animatesprites_r.cpp +++ b/source/games/duke/src/animatesprites_r.cpp @@ -348,101 +348,7 @@ void animatesprites_r(tspriteArray& tsprites, const DVector2& viewVec, DAngle vi copyfloorpal(t, sectp); break; } - - 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; + applyanimations(t, h, viewVec, viewang); 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) { - if (!isRRRA()) break; - [[fallthrough]]; + case SBMOVE: + if (!isRRRA()) + t->shade = -127; + break; + case EXPLOSION2: case ATOMICHEALTH: case CHAINGUN: diff --git a/source/games/duke/src/funct.h b/source/games/duke/src/funct.h index dd3cca659..b1a308848 100644 --- a/source/games/duke/src/funct.h +++ b/source/games/duke/src/funct.h @@ -218,6 +218,7 @@ void loadcons(); void DrawStatusBar(); void drawshadows(tspriteArray& tsprites, tspritetype* t, DDukeActor* h); +void applyanimations(tspritetype* t, DDukeActor* h, const DVector2& viewVec, DAngle viewang); inline int32_t krand(void) {