From dc857aec3d35a33fa29ddd678e0a58f77258a7df Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Tue, 18 Apr 2023 15:04:58 +1000 Subject: [PATCH] - Exhumed: Tidy up remainder of `DrawWeapons()`. --- source/games/exhumed/src/aistuff.h | 2 +- source/games/exhumed/src/gun.cpp | 101 ++++++++++---------------- source/games/exhumed/src/sequence.cpp | 82 ++++++++------------- source/games/exhumed/src/sequence.h | 4 +- source/games/exhumed/src/view.cpp | 2 +- 5 files changed, 73 insertions(+), 118 deletions(-) diff --git a/source/games/exhumed/src/aistuff.h b/source/games/exhumed/src/aistuff.h index 33efc5c47..f18f76a56 100644 --- a/source/games/exhumed/src/aistuff.h +++ b/source/games/exhumed/src/aistuff.h @@ -138,7 +138,7 @@ void SetNewWeaponIfBetter(int nPlayer, int nWeapon); void SelectNewWeapon(int nPlayer); void CheckClip(int nPlayer); void MoveWeapons(int nPlayer); -void DrawWeapons(double interpfrac); +void DrawWeapons(Player* const pPlayer, double interpfrac); // items diff --git a/source/games/exhumed/src/gun.cpp b/source/games/exhumed/src/gun.cpp index 35856f53d..fc92aada3 100644 --- a/source/games/exhumed/src/gun.cpp +++ b/source/games/exhumed/src/gun.cpp @@ -26,6 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include #include "v_2ddrawer.h" #include "sequence.h" +#include "gamehud.h" BEGIN_PS_NS @@ -900,26 +901,22 @@ loc_flag: // //--------------------------------------------------------------------------- -void DrawWeapons(double interpfrac) +void DrawWeapons(Player* const pPlayer, double interpfrac) { - if (bCamera) { - return; - } + const auto pPlayerActor = pPlayer->pActor; + const int nWeapon = pPlayer->nCurrentWeapon; - int nWeapon = PlayerList[nLocalPlayer].nCurrentWeapon; - if (nWeapon < -1) { + if (bCamera || nWeapon < -1) return; - } - int nState = PlayerList[nLocalPlayer].nState; + const int nState = pPlayer->nState; + const int nShade = nWeapon < 0 ? pPlayerActor->spr.shade : pPlayerActor->sector()->ceilingshade; + const double nAlpha = pPlayer->nInvisible ? 0.3 : 1; const auto weapSeqs = getFileSeqs(WeaponInfo[nWeapon].nSeqFile); - int8_t nShade = PlayerList[nLocalPlayer].pActor->sector()->ceilingshade; - - int nDouble = PlayerList[nLocalPlayer].nDouble; int nPal = kPalNormal; - if (nDouble) + if (pPlayer->nDouble) { if (isRed) { nPal = kPalRedBrite; @@ -930,63 +927,55 @@ void DrawWeapons(double interpfrac) nPal = RemapPLU(nPal); - double xOffset = 0, yOffset = 0; - bool screenalign = false; + const auto weaponOffsets = pPlayer->Angles.getWeaponOffsets(interpfrac); + const auto nAngle = weaponOffsets.second; + double xPos = 160 + weaponOffsets.first.X; + double yPos = 100 + weaponOffsets.first.Y; if (cl_weaponsway) { - double nBobAngle, nVal; + double nBobAngle = bobangle, nTotalVel = pPlayer->totalvel; if (cl_hudinterpolation) { nBobAngle = interpolatedvalue(obobangle, bobangle, interpfrac); - nVal = interpolatedvalue(PlayerList[nLocalPlayer].ototalvel, PlayerList[nLocalPlayer].totalvel, interpfrac); - } - else - { - nBobAngle = bobangle; - nVal = PlayerList[nLocalPlayer].totalvel; + nTotalVel = interpolatedvalue(pPlayer->ototalvel, pPlayer->totalvel, interpfrac); } - yOffset = nVal * fabs(BobVal(nBobAngle)) * (1. / 16.); - - if (nState == 1) - { - xOffset = nVal * BobVal(nBobAngle + 512) * (1. / 8.); - } + xPos += nTotalVel * BobVal(nBobAngle + 512) * (1. / 8.) * (nState == 1); + yPos += nTotalVel * fabs(BobVal(nBobAngle)) * (1. / 16.); } else { obobangle = bobangle = 512; } - if (nWeapon == 3 && nState == 1) { - seq_DrawPilotLightSeq(xOffset, yOffset); + int nStat = false; + + if (nWeapon == 3 && nState == 1) + { + if (!(pPlayer->pPlayerViewSect->Flag & kSectUnderwater)) + { + seq_DrawPilotLightSeq(xPos, yPos, pPlayerActor->spr.Angles.Yaw.Normalized180().Degrees() * 2.); + } } else if (nWeapon == 8 || nWeapon == 9) { - screenalign = true; + nStat |= RS_ALIGN_R; } - if (nWeapon < 0) { - nShade = PlayerList[nLocalPlayer].pActor->spr.shade; - } + int nSeqOffset = WeaponInfo[nWeapon].b[nState]; + int nFrame = pPlayer->nWeapFrame; - const auto weaponOffsets = PlayerList[nLocalPlayer].Angles.getWeaponOffsets(interpfrac); - const auto angle = weaponOffsets.second; - xOffset += weaponOffsets.first.X; - yOffset += weaponOffsets.first.Y; + seq_DrawGunSequence(weapSeqs->operator[](nSeqOffset).frames[nFrame], xPos, yPos, nShade, nPal, nAngle, nAlpha, nStat); - seq_DrawGunSequence(weapSeqs->operator[](WeaponInfo[nWeapon].b[nState]), PlayerList[nLocalPlayer].nWeapFrame, xOffset, yOffset, nShade, nPal, angle, screenalign); + int nClip = pPlayer->nPlayerClip; - if (nWeapon != kWeaponM60) + if (nWeapon != kWeaponM60 || nClip <= 0) return; switch (nState) { - default: - return; - case 0: case 5: { @@ -997,13 +986,6 @@ void DrawWeapons(double interpfrac) const auto& offsets = offsetTable[nState == 5]; - int nClip = PlayerList[nLocalPlayer].nPlayerClip; - - if (nClip <= 0) - return; - - int nSeqOffset; - if (nClip <= 3) { nSeqOffset = offsets[0]; @@ -1021,42 +1003,37 @@ void DrawWeapons(double interpfrac) nSeqOffset = offsets[3]; } - seq_DrawGunSequence(weapSeqs->operator[](nSeqOffset), PlayerList[nLocalPlayer].nWeapFrame, xOffset, yOffset, nShade, nPal, angle); + seq_DrawGunSequence(weapSeqs->operator[](nSeqOffset).frames[nFrame], xPos, yPos, nShade, nPal, nAngle, nAlpha); return; } case 1: case 2: { - int nClip = PlayerList[nLocalPlayer].nPlayerClip; - int nFrame = nState == 1 ? (nClip % 3) * 4 : PlayerList[nLocalPlayer].nWeapFrame; + if (nState == 1) + nFrame = (nClip % 3) * 4; - if (nClip <= 0) { - return; - } - - seq_DrawGunSequence(weapSeqs->operator[](8), nFrame, xOffset, yOffset, nShade, nPal, angle); + seq_DrawGunSequence(weapSeqs->operator[](8).frames[nFrame], xPos, yPos, nShade, nPal, nAngle, nAlpha); if (nClip <= 3) { return; } - seq_DrawGunSequence(weapSeqs->operator[](9), nFrame, xOffset, yOffset, nShade, nPal, angle); + seq_DrawGunSequence(weapSeqs->operator[](9).frames[nFrame], xPos, yPos, nShade, nPal, nAngle, nAlpha); if (nClip <= 6) { return; } - seq_DrawGunSequence(weapSeqs->operator[](10), nFrame, xOffset, yOffset, nShade, nPal, angle); + seq_DrawGunSequence(weapSeqs->operator[](10).frames[nFrame], xPos, yPos, nShade, nPal, nAngle, nAlpha); if (nClip <= 25) { return; } - seq_DrawGunSequence(weapSeqs->operator[](11), nFrame, xOffset, yOffset, nShade, nPal, angle); + seq_DrawGunSequence(weapSeqs->operator[](11).frames[nFrame], xPos, yPos, nShade, nPal, nAngle, nAlpha); return; } - case 3: - case 4: + default: { return; } diff --git a/source/games/exhumed/src/sequence.cpp b/source/games/exhumed/src/sequence.cpp index d5361ee29..fd4ba24a1 100644 --- a/source/games/exhumed/src/sequence.cpp +++ b/source/games/exhumed/src/sequence.cpp @@ -341,23 +341,17 @@ void seq_LoadSequences() // //--------------------------------------------------------------------------- -void seq_DrawPilotLightSeq(double xOffset, double yOffset) +void seq_DrawPilotLightSeq(double xPos, double yPos, double nAngle) { - auto pSect = PlayerList[nLocalPlayer].pPlayerViewSect; + const auto& seqFrameChunks = getSequence("flamer", 3).frames[0].chunks; - if (!(pSect->Flag & kSectUnderwater)) + for (unsigned i = 0; i < seqFrameChunks.Size(); i++) { - const auto& pilotlightSeq = getSequence("flamer", 3); - const auto& seqFrame = pilotlightSeq.frames[0]; + const auto& frameChunk = seqFrameChunks[i]; + const double x = xPos + frameChunk.xpos; + const double y = yPos + frameChunk.ypos; - for (unsigned i = 0; i < seqFrame.chunks.Size(); i++) - { - const auto& frameChunk = seqFrame.chunks[i]; - const double x = frameChunk.xpos + (160 + xOffset); - const double y = frameChunk.ypos + (100 + yOffset); - - hud_drawsprite(x, y, 65536, PlayerList[nLocalPlayer].pActor->spr.Angles.Yaw.Normalized180().Degrees() * 2., legacyTileNum(frameChunk.tex), 0, 0, 1); - } + hud_drawsprite(x, y, 65536, nAngle, legacyTileNum(frameChunk.tex), 0, 0, 1); } } @@ -367,35 +361,19 @@ void seq_DrawPilotLightSeq(double xOffset, double yOffset) // //--------------------------------------------------------------------------- -void seq_DrawGunSequence(const Seq& weapSeq, int16_t frameIndex, double xOffs, double yOffs, int nShade, int nPal, DAngle angle, bool align) +void seq_DrawGunSequence(const SeqFrame& seqFrame, double xPos, double yPos, int nShade, int nPal, DAngle nAngle, double nAlpha, int nStat) { - const auto& seqFrame = weapSeq.frames[frameIndex]; - if (seqFrame.flags & 4) nShade = -100; for (unsigned i = 0; i < seqFrame.chunks.Size(); i++) { const auto& frameChunk = seqFrame.chunks[i]; + const double x = xPos + frameChunk.xpos; + const double y = yPos + frameChunk.ypos; + const int frameStat = nStat | (RS_XFLIPHUD * !!(frameChunk.flags & 1)) | (RS_YFLIPHUD * !!(frameChunk.flags & 2)); - int x = frameChunk.xpos + 160; - int y = frameChunk.ypos + 100; - - int stat = 0; - if (frameChunk.flags & 1) - stat |= RS_XFLIPHUD; - - if (frameChunk.flags & 2) - stat |= RS_YFLIPHUD; - - if (align) stat |= RS_ALIGN_R; - - double alpha = 1; - if (PlayerList[nLocalPlayer].nInvisible) { - alpha = 0.3; - } - - hud_drawsprite(x + xOffs, y + yOffs, 65536, angle.Degrees(), legacyTileNum(frameChunk.tex), nShade, nPal, stat, alpha); + hud_drawsprite(x, y, 65536, nAngle.Degrees(), legacyTileNum(frameChunk.tex), nShade, nPal, frameStat, nAlpha); } } @@ -415,18 +393,20 @@ void seq_PlotArrowSequence(const int nSprite, const FName seqFile, const int16_t const auto& seqFrame = getSequence(seqFile, seqIndex + seqOffset).frames[frameIndex]; const auto& frameChunk = seqFrame.chunks[0]; - auto nStat = pTSprite->cstat | CSTAT_SPRITE_YCENTER; + if (seqFrame.flags & 4) + pTSprite->shade -= 100; - if (seqOffset & 3) { - nStat |= CSTAT_SPRITE_ALIGNMENT_WALL | CSTAT_SPRITE_YFLIP; - } - else { - nStat &= ~(CSTAT_SPRITE_ALIGNMENT_WALL | CSTAT_SPRITE_YFLIP); - } - - pTSprite->cstat = nStat; - pTSprite->shade = (seqFrame.flags & 4) ? pTSprite->shade - 100 : pTSprite->shade; pTSprite->statnum = seqFrame.chunks.Size(); + pTSprite->cstat |= CSTAT_SPRITE_YCENTER; + + if (seqOffset & 3) + { + pTSprite->cstat |= CSTAT_SPRITE_ALIGNMENT_WALL | CSTAT_SPRITE_YFLIP; + } + else + { + pTSprite->cstat &= ~(CSTAT_SPRITE_ALIGNMENT_WALL | CSTAT_SPRITE_YFLIP); + } if (frameChunk.flags & 1) { @@ -461,16 +441,15 @@ void seq_PlotSequence(const int nSprite, const FName seqFile, const int16_t seqI } const auto fileSeqs = getFileSeqs(seqFile); - const auto& baseFrame = fileSeqs->operator[](seqIndex).frames[frameIndex]; - const auto& drawFrame = fileSeqs->operator[](seqIndex + seqOffset).frames[frameIndex]; - const auto chunkCount = drawFrame.chunks.Size(); + const auto& seqFrame = fileSeqs->operator[](seqIndex + seqOffset).frames[frameIndex]; + const auto chunkCount = seqFrame.chunks.Size(); - const auto nShade = (baseFrame.flags & 4) ? pTSprite->shade - 100 : pTSprite->shade; + const auto nShade = pTSprite->shade - (100 * !!(fileSeqs->operator[](seqIndex).frames[frameIndex].flags & 4)); const auto nStatnum = (nFlags & 0x100) ? -3 : 100; for (unsigned i = 0; i < chunkCount; i++) { - const auto& seqFrameChunk = drawFrame.chunks[i]; + const auto& seqFrameChunk = seqFrame.chunks[i]; tspritetype* tsp = mytspriteArray->newTSprite(); tsp->pos = pTSprite->pos; @@ -513,11 +492,10 @@ void seq_PlotSequence(const int nSprite, const FName seqFile, const int16_t seqI } else { - pTSprite->setspritetexture(nShadowPic); - - const auto nTexWidth = (int)TexMan.GetGameTexture(drawFrame.getFirstChunkTexture())->GetDisplayWidth(); + const auto nTexWidth = (int)TexMan.GetGameTexture(seqFrame.getFirstChunkTexture())->GetDisplayWidth(); const auto nScale = max(((nTexWidth << 5) / nShadowWidth) - int16_t((nFloorZ - pTSprite->pos.Z) * 2.), 1) * REPEAT_SCALE; + pTSprite->setspritetexture(nShadowPic); pTSprite->cstat = CSTAT_SPRITE_ALIGNMENT_FLOOR | CSTAT_SPRITE_TRANSLUCENT; pTSprite->pos.Z = pSector->floorz; pTSprite->scale = DVector2(nScale, nScale); diff --git a/source/games/exhumed/src/sequence.h b/source/games/exhumed/src/sequence.h index 744d8ea37..f62d57c5c 100644 --- a/source/games/exhumed/src/sequence.h +++ b/source/games/exhumed/src/sequence.h @@ -79,10 +79,10 @@ extern int16_t nPilotLightFrame; extern int16_t nPilotLightCount; void seq_LoadSequences(); -void seq_DrawGunSequence(const Seq& weapSeq, int16_t frameIndex, double xOffs, double yOffs, int nShade, int nPal, DAngle angle, bool align = false); +void seq_DrawGunSequence(const SeqFrame& seqFrame, double xPos, double yPos, int nShade, int nPal, DAngle nAngle, double nAlpha, int nStat = 0); void seq_PlotSequence(const int nSprite, const FName seqFile, const int16_t seqIndex, const int16_t frameIndex, const int16_t nFlags); void seq_PlotArrowSequence(const int nSprite, const FName seqFile, const int16_t seqIndex, const int frameIndex); -void seq_DrawPilotLightSeq(double xOffset, double yOffset); +void seq_DrawPilotLightSeq(double xPos, double yPos, double nAngle); TArray* getFileSeqs(const FName nSeqFile); diff --git a/source/games/exhumed/src/view.cpp b/source/games/exhumed/src/view.cpp index 2c59fd497..a19c702bb 100644 --- a/source/games/exhumed/src/view.cpp +++ b/source/games/exhumed/src/view.cpp @@ -184,7 +184,7 @@ void DrawView(double interpfrac, bool sceneonly) } if (!nFreeze && !sceneonly) - DrawWeapons(interpfrac); + DrawWeapons(pPlayer, interpfrac); render_drawrooms(nullptr, nCamerapos, pSector, nCameraangles, interpfrac); if (HavePLURemap())