From a60c55e866cab3ab1d8aee69c6bdd6280d45728b Mon Sep 17 00:00:00 2001 From: Lactozilla Date: Mon, 13 Nov 2023 13:24:18 -0300 Subject: [PATCH] Refactor this code into P_ApplySuperFlagToSprite2 --- src/hardware/hw_md2.c | 18 ++---------------- src/p_mobj.c | 29 ++++++----------------------- src/r_skins.c | 21 +++++++++++++++++++++ src/r_skins.h | 1 + 4 files changed, 30 insertions(+), 39 deletions(-) diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 077a90f38..c31705441 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -1565,22 +1565,8 @@ boolean HWR_DrawModel(gl_vissprite_t *spr) { UINT16 next_spr2 = P_GetStateSprite2(&states[spr->mobj->state->nextstate]); - // Add/Remove SPR2F_SUPER based on certain conditions - if (spr->mobj->player) - { - if (spr->mobj->player->charflags & SF_NOSUPERSPRITES) - next_spr2 &= ~SPR2F_SUPER; - else if (spr->mobj->player->powers[pw_super]) - next_spr2 |= SPR2F_SUPER; - } - - if (next_spr2 & SPR2F_SUPER) - { - if (spr->mobj->eflags & MFE_FORCENOSUPER) - next_spr2 &= ~SPR2F_SUPER; - } - else if (spr->mobj->eflags & MFE_FORCESUPER) - next_spr2 |= SPR2F_SUPER; + // Add or remove SPR2F_SUPER based on certain conditions + next_spr2 = P_ApplySuperFlagToSprite2(next_spr2, spr->mobj); if (HWR_CanInterpolateSprite2(spr2frames) && (spr->mobj->frame & FF_ANIMATE diff --git a/src/p_mobj.c b/src/p_mobj.c index 0ff83a347..e756420b3 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -411,21 +411,10 @@ boolean P_SetPlayerMobjState(mobj_t *mobj, statenum_t state) { spr2 = P_GetStateSprite2(st); - // Add/Remove SPR2F_SUPER based on certain conditions - if (player->charflags & SF_NOSUPERSPRITES) - spr2 &= ~SPR2F_SUPER; - else if (player->powers[pw_super]) - spr2 |= SPR2F_SUPER; + // Add or remove SPR2F_SUPER based on certain conditions + spr2 = P_ApplySuperFlagToSprite2(spr2, mobj); - if (spr2 & SPR2F_SUPER) - { - if (mobj->eflags & MFE_FORCENOSUPER) - spr2 &= ~SPR2F_SUPER; - } - else if (mobj->eflags & MFE_FORCESUPER) - spr2 |= SPR2F_SUPER; - - // Get the sprite2 and frame number + // Get the needed sprite2 and frame number spr2 = P_GetSkinSprite2(skin, spr2, mobj->player); spritedef_t *sprdef = P_GetSkinSpritedef(skin, spr2); @@ -568,16 +557,10 @@ boolean P_SetMobjState(mobj_t *mobj, statenum_t state) { spr2 = P_GetStateSprite2(st); - // Add/Remove SPR2F_SUPER based on certain conditions - if (spr2 & SPR2F_SUPER) - { - if (mobj->eflags & MFE_FORCENOSUPER) - spr2 &= ~SPR2F_SUPER; - } - else if (mobj->eflags & MFE_FORCESUPER) - spr2 |= SPR2F_SUPER; + // Add or remove SPR2F_SUPER based on certain conditions + spr2 = P_ApplySuperFlagToSprite2(spr2, mobj); - // Get the sprite2 and frame number + // Get the needed sprite2 and frame number spr2 = P_GetSkinSprite2(skin, spr2, NULL); spritedef_t *sprdef = P_GetSkinSpritedef(skin, spr2); diff --git a/src/r_skins.c b/src/r_skins.c index e32e8b8fd..1502e765a 100644 --- a/src/r_skins.c +++ b/src/r_skins.c @@ -76,6 +76,27 @@ boolean P_IsStateSprite2Super(state_t *state) return false; } +UINT16 P_ApplySuperFlagToSprite2(UINT16 spr2, mobj_t *mobj) +{ + if (mobj->player) + { + if (mobj->player->charflags & SF_NOSUPERSPRITES) + spr2 &= ~SPR2F_SUPER; + else if (mobj->player->powers[pw_super]) + spr2 |= SPR2F_SUPER; + } + + if (spr2 & SPR2F_SUPER) + { + if (mobj->eflags & MFE_FORCENOSUPER) + spr2 &= ~SPR2F_SUPER; + } + else if (mobj->eflags & MFE_FORCESUPER) + spr2 |= SPR2F_SUPER; + + return spr2; +} + // // P_GetSkinSprite2 // For non-super players, tries each sprite2's immediate predecessor until it finds one with a number of frames or ends up at standing. diff --git a/src/r_skins.h b/src/r_skins.h index 06004ca0f..f1ac88e9b 100644 --- a/src/r_skins.h +++ b/src/r_skins.h @@ -108,6 +108,7 @@ void R_PatchSkins(UINT16 wadnum, boolean mainfile); UINT16 P_GetStateSprite2(state_t *state); UINT16 P_GetSprite2StateFrame(state_t *state); UINT16 P_GetSkinSprite2(skin_t *skin, UINT16 spr2, player_t *player); +UINT16 P_ApplySuperFlagToSprite2(UINT16 spr2, mobj_t *mobj); spritedef_t *P_GetSkinSpritedef(skin_t *skin, UINT16 spr2); spriteinfo_t *P_GetSkinSpriteInfo(skin_t *skin, UINT16 spr2); boolean P_IsValidSprite2(skin_t *skin, UINT16 spr2);