diff --git a/source/common/utility/m_fixed.h b/source/common/utility/m_fixed.h index bf7778e79..09d297693 100644 --- a/source/common/utility/m_fixed.h +++ b/source/common/utility/m_fixed.h @@ -7,7 +7,6 @@ __forceinline constexpr int32_t MulScale(int32_t a, int32_t b, int32_t shift) { return (int32_t)(((int64_t)a * b) >> shift); } -__forceinline constexpr double MulScaleF(double a, double b, int32_t shift) { return (a * b) * (1. / (uint32_t(1) << shift)); } __forceinline constexpr int32_t DMulScale(int32_t a, int32_t b, int32_t c, int32_t d, int32_t shift) { return (int32_t)(((int64_t)a * b + (int64_t)c * d) >> shift); } __forceinline constexpr int32_t DivScale(int32_t a, int32_t b, int shift) { return (int32_t)(((int64_t)a << shift) / b); } __forceinline constexpr int64_t DivScaleL(int64_t a, int64_t b, int shift) { return ((a << shift) / b); } diff --git a/source/games/blood/src/actor.cpp b/source/games/blood/src/actor.cpp index aa9c59021..0d4aee806 100644 --- a/source/games/blood/src/actor.cpp +++ b/source/games/blood/src/actor.cpp @@ -5633,7 +5633,7 @@ static void actCheckThings() if (pXSector->panAlways || pXSector->state || pXSector->busy) { speed = pXSector->panVel / 128.; - if (!pXSector->panAlways && pXSector->busy) speed = MulScaleF(speed, pXSector->busy, 16); + if (!pXSector->panAlways && pXSector->busy) speed *= FixedToFloat(pXSector->busy); } if (pSector->floorstat & CSTAT_SECTOR_ALIGN) angle += pSector->firstWall()->normalAngle(); @@ -6046,7 +6046,7 @@ static void actCheckDudes() { speed = pXSector->panVel / 128.; if (!pXSector->panAlways && pXSector->busy) - speed = MulScaleF(speed, pXSector->busy, 16); + speed *= FixedToFloat(pXSector->busy); } if (pSector->floorstat & CSTAT_SECTOR_ALIGN) angle += pSector->firstWall()->normalAngle(); diff --git a/source/games/blood/src/common_game.h b/source/games/blood/src/common_game.h index 63404b222..52ddef86a 100644 --- a/source/games/blood/src/common_game.h +++ b/source/games/blood/src/common_game.h @@ -599,7 +599,7 @@ inline int QRandom2(int a1) inline double QRandom2F(double a1) { - return MulScaleF(qrand(), a1, 14) - a1; + return (qrand() * (1. / 16384.) * a1) - a1; } inline int scale(int a1, int a2, int a3, int a4, int a5) diff --git a/source/games/blood/src/nnexts.cpp b/source/games/blood/src/nnexts.cpp index cb30109bd..672cf1bec 100644 --- a/source/games/blood/src/nnexts.cpp +++ b/source/games/blood/src/nnexts.cpp @@ -1304,7 +1304,7 @@ void nnExtProcessSuperSprites() { speed = pXSector->panVel / 128.; if (!pXSector->panAlways && pXSector->busy) - speed = MulScaleF(speed, pXSector->busy, 16); + speed *= FixedToFloat(pXSector->busy); } if (debrisactor->sector()->floorstat & CSTAT_SECTOR_ALIGN) angle += debrisactor->sector()->firstWall()->normalAngle(); @@ -1325,7 +1325,7 @@ void nnExtProcessSuperSprites() if (pact && pact->hit.hit.type == kHitSprite && pact->hit.hit.actor() == debrisactor) { double nSpeed = pact->vel.XY().Length(); - nSpeed = max(nSpeed - MulScaleF(nSpeed, mass, 6), FixedToFloat(0x9000 - (mass << 3))); // very messy math (TM)... + nSpeed = max(nSpeed - nSpeed * FixedToFloat<6>(mass), FixedToFloat(0x9000 - (mass << 3))); // very messy math (TM)... debrisactor->vel += pPlayer->actor->spr.angle.ToVector() * nSpeed; debrisactor->hit.hit.setSprite(pPlayer->actor); @@ -2192,28 +2192,16 @@ void trPlayerCtrlSetScreenEffect(int value, int timeval, PLAYER* pPlayer) void trPlayerCtrlSetLookAngle(int value, PLAYER* pPlayer) { - double const upAngle = 289; - double const downAngle = -347; - double const lookStepUp = 4.0 * upAngle / 60.0; - double const lookStepDown = -4.0 * downAngle / 60.0; - double const look = value << 5; - double adjustment; + static constexpr double upAngle = 289; + static constexpr double downAngle = -347; + static constexpr double lookStepUp = 4.0 * upAngle / 60.0; + static constexpr double lookStepDown = -4.0 * downAngle / 60.0; - if (look > 0) + if (const double adjustment = clamp(value * 0.125 * (value > 0 ? lookStepUp : lookStepDown), downAngle, upAngle)) { - adjustment = min(MulScaleF(lookStepUp, look, 8), upAngle); + pPlayer->horizon.settarget(maphoriz(-100. * tan(adjustment * pi::pi() * (1. / 1024.)))); + pPlayer->horizon.lockinput(); } - else if (look < 0) - { - adjustment = -max(MulScaleF(lookStepDown, abs(look), 8), downAngle); - } - else - { - adjustment = 0; - } - - pPlayer->horizon.settarget(maphoriz(100. * tan(adjustment * pi::pi() * (1. / 1024.)))); - pPlayer->horizon.lockinput(); } //--------------------------------------------------------------------------- diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index fd93d7b5b..c46a5e8d5 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -1409,8 +1409,8 @@ struct SECTOR_OBJECT bob_amt; // bob amount max in z coord // variables set by mappers for drivables - int drive_angspeed, - drive_angslide, + double drive_angspeed; + int drive_angslide, drive_speed, drive_slide, flags; diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index 8b0d74c23..dc7f69094 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -1553,7 +1553,7 @@ void DoPlayerTurnVehicle(PLAYER* pp, float avel, double zz, double floordist) if (sop->drive_angspeed) { float drive_oavel = pp->drive_avel; - pp->drive_avel = float((MulScaleF(avel, sop->drive_angspeed, 16) + (drive_oavel * (sop->drive_angslide - 1))) / sop->drive_angslide); + pp->drive_avel = float((avel * sop->drive_angspeed + (drive_oavel * (sop->drive_angslide - 1))) / sop->drive_angslide); avel = pp->drive_avel; } @@ -1587,7 +1587,7 @@ void DoPlayerTurnVehicleRect(PLAYER* pp, DVector2* pos, DVector2* opos) if (sop->drive_angspeed) { float drive_oavel = pp->drive_avel; - pp->drive_avel = float((MulScaleF(pp->input.avel, sop->drive_angspeed, 16) + (drive_oavel * (sop->drive_angslide - 1))) / sop->drive_angslide); + pp->drive_avel = float((pp->input.avel * sop->drive_angspeed + (drive_oavel * (sop->drive_angslide - 1))) / sop->drive_angslide); avel = pp->drive_avel; } @@ -1621,7 +1621,7 @@ void DoPlayerTurnTurret(PLAYER* pp, float avel) if (sop->drive_angspeed) { float drive_oavel = pp->drive_avel; - pp->drive_avel = float((MulScaleF(avel, sop->drive_angspeed, 16) + (drive_oavel * (sop->drive_angslide - 1))) / sop->drive_angslide); + pp->drive_avel = float((avel * sop->drive_angspeed + (drive_oavel * (sop->drive_angslide - 1))) / sop->drive_angslide); avel = pp->drive_avel; } diff --git a/source/games/sw/src/track.cpp b/source/games/sw/src/track.cpp index ad4bed574..ec7aed30c 100644 --- a/source/games/sw/src/track.cpp +++ b/source/games/sw/src/track.cpp @@ -1150,8 +1150,7 @@ void SetupSectorObject(sectortype* sectp, short tag) case SO_DRIVABLE_ATTRIB: - sop->drive_angspeed = SP_TAG2(actor); - sop->drive_angspeed <<= 5; + sop->drive_angspeed = FixedToFloat<11>(SP_TAG2(actor)); sop->drive_angslide = SP_TAG3(actor); if (sop->drive_angslide <= 0 || sop->drive_angslide == 32) sop->drive_angslide = 1; diff --git a/source/games/sw/src/weapon.cpp b/source/games/sw/src/weapon.cpp index 35e634897..27af21171 100644 --- a/source/games/sw/src/weapon.cpp +++ b/source/games/sw/src/weapon.cpp @@ -17081,7 +17081,7 @@ int InitFireball(PLAYER* pp) if (pp->Flags & (PF_DIVING) || SpriteInUnderwaterArea(actorNew)) actorNew->user.Flags |= (SPR_UNDERWATER); - if (TestMissileSetPos(actorNew, DoFireball, 1200, MulScaleF(zvel,44000, 16))) + if (TestMissileSetPos(actorNew, DoFireball, 1200, zvel * (1375. / 2048.))) { RESTORE_CLIP;; KillActor(actorNew);