- Eliminate MulScaleF().

This commit is contained in:
Mitchell Richters 2022-09-30 20:51:50 +10:00 committed by Christoph Oelckers
parent d15e1017bd
commit 75047b6ad5
8 changed files with 19 additions and 33 deletions

View file

@ -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 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 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 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); } __forceinline constexpr int64_t DivScaleL(int64_t a, int64_t b, int shift) { return ((a << shift) / b); }

View file

@ -5633,7 +5633,7 @@ static void actCheckThings()
if (pXSector->panAlways || pXSector->state || pXSector->busy) if (pXSector->panAlways || pXSector->state || pXSector->busy)
{ {
speed = pXSector->panVel / 128.; 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(); if (pSector->floorstat & CSTAT_SECTOR_ALIGN) angle += pSector->firstWall()->normalAngle();
@ -6046,7 +6046,7 @@ static void actCheckDudes()
{ {
speed = pXSector->panVel / 128.; speed = pXSector->panVel / 128.;
if (!pXSector->panAlways && pXSector->busy) if (!pXSector->panAlways && pXSector->busy)
speed = MulScaleF(speed, pXSector->busy, 16); speed *= FixedToFloat(pXSector->busy);
} }
if (pSector->floorstat & CSTAT_SECTOR_ALIGN) if (pSector->floorstat & CSTAT_SECTOR_ALIGN)
angle += pSector->firstWall()->normalAngle(); angle += pSector->firstWall()->normalAngle();

View file

@ -599,7 +599,7 @@ inline int QRandom2(int a1)
inline double QRandom2F(double 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) inline int scale(int a1, int a2, int a3, int a4, int a5)

View file

@ -1304,7 +1304,7 @@ void nnExtProcessSuperSprites()
{ {
speed = pXSector->panVel / 128.; speed = pXSector->panVel / 128.;
if (!pXSector->panAlways && pXSector->busy) if (!pXSector->panAlways && pXSector->busy)
speed = MulScaleF(speed, pXSector->busy, 16); speed *= FixedToFloat(pXSector->busy);
} }
if (debrisactor->sector()->floorstat & CSTAT_SECTOR_ALIGN) if (debrisactor->sector()->floorstat & CSTAT_SECTOR_ALIGN)
angle += debrisactor->sector()->firstWall()->normalAngle(); angle += debrisactor->sector()->firstWall()->normalAngle();
@ -1325,7 +1325,7 @@ void nnExtProcessSuperSprites()
if (pact && pact->hit.hit.type == kHitSprite && pact->hit.hit.actor() == debrisactor) if (pact && pact->hit.hit.type == kHitSprite && pact->hit.hit.actor() == debrisactor)
{ {
double nSpeed = pact->vel.XY().Length(); double nSpeed = pact->vel.XY().Length();
nSpeed = max<double>(nSpeed - MulScaleF(nSpeed, mass, 6), FixedToFloat(0x9000 - (mass << 3))); // very messy math (TM)... nSpeed = max<double>(nSpeed - nSpeed * FixedToFloat<6>(mass), FixedToFloat(0x9000 - (mass << 3))); // very messy math (TM)...
debrisactor->vel += pPlayer->actor->spr.angle.ToVector() * nSpeed; debrisactor->vel += pPlayer->actor->spr.angle.ToVector() * nSpeed;
debrisactor->hit.hit.setSprite(pPlayer->actor); debrisactor->hit.hit.setSprite(pPlayer->actor);
@ -2192,28 +2192,16 @@ void trPlayerCtrlSetScreenEffect(int value, int timeval, PLAYER* pPlayer)
void trPlayerCtrlSetLookAngle(int value, PLAYER* pPlayer) void trPlayerCtrlSetLookAngle(int value, PLAYER* pPlayer)
{ {
double const upAngle = 289; static constexpr double upAngle = 289;
double const downAngle = -347; static constexpr double downAngle = -347;
double const lookStepUp = 4.0 * upAngle / 60.0; static constexpr double lookStepUp = 4.0 * upAngle / 60.0;
double const lookStepDown = -4.0 * downAngle / 60.0; static constexpr double lookStepDown = -4.0 * downAngle / 60.0;
double const look = value << 5;
double adjustment;
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();
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View file

@ -1409,8 +1409,8 @@ struct SECTOR_OBJECT
bob_amt; // bob amount max in z coord bob_amt; // bob amount max in z coord
// variables set by mappers for drivables // variables set by mappers for drivables
int drive_angspeed, double drive_angspeed;
drive_angslide, int drive_angslide,
drive_speed, drive_speed,
drive_slide, drive_slide,
flags; flags;

View file

@ -1553,7 +1553,7 @@ void DoPlayerTurnVehicle(PLAYER* pp, float avel, double zz, double floordist)
if (sop->drive_angspeed) if (sop->drive_angspeed)
{ {
float drive_oavel = pp->drive_avel; 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; avel = pp->drive_avel;
} }
@ -1587,7 +1587,7 @@ void DoPlayerTurnVehicleRect(PLAYER* pp, DVector2* pos, DVector2* opos)
if (sop->drive_angspeed) if (sop->drive_angspeed)
{ {
float drive_oavel = pp->drive_avel; 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; avel = pp->drive_avel;
} }
@ -1621,7 +1621,7 @@ void DoPlayerTurnTurret(PLAYER* pp, float avel)
if (sop->drive_angspeed) if (sop->drive_angspeed)
{ {
float drive_oavel = pp->drive_avel; 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; avel = pp->drive_avel;
} }

View file

@ -1150,8 +1150,7 @@ void SetupSectorObject(sectortype* sectp, short tag)
case SO_DRIVABLE_ATTRIB: case SO_DRIVABLE_ATTRIB:
sop->drive_angspeed = SP_TAG2(actor); sop->drive_angspeed = FixedToFloat<11>(SP_TAG2(actor));
sop->drive_angspeed <<= 5;
sop->drive_angslide = SP_TAG3(actor); sop->drive_angslide = SP_TAG3(actor);
if (sop->drive_angslide <= 0 || sop->drive_angslide == 32) if (sop->drive_angslide <= 0 || sop->drive_angslide == 32)
sop->drive_angslide = 1; sop->drive_angslide = 1;

View file

@ -17081,7 +17081,7 @@ int InitFireball(PLAYER* pp)
if (pp->Flags & (PF_DIVING) || SpriteInUnderwaterArea(actorNew)) if (pp->Flags & (PF_DIVING) || SpriteInUnderwaterArea(actorNew))
actorNew->user.Flags |= (SPR_UNDERWATER); actorNew->user.Flags |= (SPR_UNDERWATER);
if (TestMissileSetPos(actorNew, DoFireball, 1200, MulScaleF(zvel,44000, 16))) if (TestMissileSetPos(actorNew, DoFireball, 1200, zvel * (1375. / 2048.)))
{ {
RESTORE_CLIP;; RESTORE_CLIP;;
KillActor(actorNew); KillActor(actorNew);