- Remove some uses of xs_Float.h functions in game-side code where overflow protection isn't needed.

* Went a little bit nuts and just used this everywhere back way back when.
This commit is contained in:
Mitchell Richters 2022-07-21 20:18:40 +10:00
parent 78fcf2b4f0
commit 00e12ea031
7 changed files with 34 additions and 41 deletions

View file

@ -558,7 +558,7 @@ void SetupView(int& cX, int& cY, int& cZ, binangle& cA, fixedhoriz& cH, sectorty
{
cZ += bobHeight;
}
cZ += xs_CRoundToInt(cH.asq16() / 6553.6);
cZ += int(cH.asq16() * (1. / 6553.6));
cameradist = -1;
cameraclock = PlayClock + MulScale(4, (int)gInterpolate, 16);
}

View file

@ -928,15 +928,8 @@ void DoPlayer(bool bSet, int lVar1, int lLabelID, int lVar2, DDukeActor* sActor,
break;
case PLAYER_RETURN_TO_CENTER:
if (bSet)
{
ps[iPlayer].sync.actions |= SB_CENTERVIEW;
}
else
{
auto center = ps[iPlayer].sync.actions & SB_CENTERVIEW ? abs(xs_CRoundToInt(ps[iPlayer].horizon.horiz.asq16() * (9. / gi->playerHorizMax()))) : 0;
SetGameVarID(lVar2, center, sActor, sPlayer);
}
if (bSet) ps[iPlayer].sync.actions |= SB_CENTERVIEW;
else SetGameVarID(lVar2, ps[iPlayer].sync.actions & SB_CENTERVIEW ? abs(int(ps[iPlayer].horizon.horiz.asq16() * (9. / gi->playerHorizMax()))) : 0, sActor, sPlayer);
break;
default:

View file

@ -930,7 +930,7 @@ void displayweapon_d(int snum, double smoothratio)
hud_drawpal(weapon_xoffset + 184 - look_anghalf,
looking_arc + 240 - gun_pos, SHRINKER + 2,
16 - xs_CRoundToInt(bsinf(random_club_frame, -10)),
16 - int(bsinf(random_club_frame, -10)),
o, 0);
hud_drawpal(weapon_xoffset + 188 - look_anghalf,
@ -1082,7 +1082,7 @@ void displayweapon_d(int snum, double smoothratio)
{
hud_drawpal(weapon_xoffset + 184 - look_anghalf,
looking_arc + 240 - gun_pos, SHRINKER + 2,
16 - xs_CRoundToInt(bsinf(random_club_frame, -10)),
16 - int(bsinf(random_club_frame, -10)),
o, 2);
hud_drawpal(weapon_xoffset + 188 - look_anghalf,
@ -1092,7 +1092,7 @@ void displayweapon_d(int snum, double smoothratio)
{
hud_drawpal(weapon_xoffset + 184 - look_anghalf,
looking_arc + 240 - gun_pos, SHRINKER + 2,
16 - xs_CRoundToInt(bsinf(random_club_frame, -10)),
16 - int(bsinf(random_club_frame, -10)),
o, 0);
hud_drawpal(weapon_xoffset + 188 - look_anghalf,

View file

@ -760,7 +760,7 @@ static void processVehicleInput(player_struct *p, ControlInfo* const hidInput, I
input.avel = (float)boatApplyTurn(p, hidInput, kbdLeft, kbdRight, scaleAdjust);
}
loc.fvel = clamp<int16_t>(xs_CRoundToInt(p->MotoSpeed), -(MAXVELMOTO >> 3), MAXVELMOTO);
loc.fvel = clamp<int16_t>(p->MotoSpeed, -(MAXVELMOTO >> 3), MAXVELMOTO);
input.avel *= BAngToDegree;
loc.avel += input.avel;
}

View file

@ -2132,7 +2132,7 @@ static void movement(int snum, ESyncBits actions, sectortype* psect, int fz, int
{
p->VBumpTarget = 80;
p->moto_bump_fast = 1;
p->vel.Z -= xs_CRoundToInt(gs.gravity * (p->MotoSpeed / 16.));
p->vel.Z -= int(gs.gravity * p->MotoSpeed * (1. / 16.));
p->MotoOnGround = 0;
if (S_CheckActorSoundPlaying(pact, 188))
S_StopSound(188, pact);
@ -2374,39 +2374,39 @@ void onMotorcycleMove(int snum, walltype* wal)
auto p = &ps[snum];
auto pact = p->GetActor();
int angleDelta = abs(p->angle.ang.asbuild() - getangle(wal->delta()));
int damageAmount;
double damageAmount = p->MotoSpeed * p->MotoSpeed;
p->angle.addadjustment(buildfang(p->MotoSpeed / (krand() & 1 ? -2 : 2)));
if (angleDelta >= 441 && angleDelta <= 581)
{
damageAmount = xs_CRoundToInt((p->MotoSpeed * p->MotoSpeed) / 256.);
damageAmount *= (1. / 256.);
p->MotoSpeed = 0;
if (S_CheckActorSoundPlaying(pact, 238) == 0)
S_PlayActorSound(238, pact);
}
else if (angleDelta >= 311 && angleDelta <= 711)
{
damageAmount = xs_CRoundToInt((p->MotoSpeed * p->MotoSpeed) / 2048.);
damageAmount *= (1. / 2048.);
p->MotoSpeed -= (p->MotoSpeed / 2.) + (p->MotoSpeed / 4.);
if (S_CheckActorSoundPlaying(pact, 238) == 0)
S_PlayActorSound(238, pact);
}
else if (angleDelta >= 111 && angleDelta <= 911)
{
damageAmount = xs_CRoundToInt((p->MotoSpeed * p->MotoSpeed) / 16384.);
damageAmount *= (1. / 16384.);
p->MotoSpeed -= p->MotoSpeed / 2.;
if (S_CheckActorSoundPlaying(pact, 239) == 0)
S_PlayActorSound(239, pact);
}
else
{
damageAmount = xs_CRoundToInt((p->MotoSpeed * p->MotoSpeed) / 32768.);
damageAmount *= (1. / 32768.);
p->MotoSpeed -= p->MotoSpeed / 8.;
if (S_CheckActorSoundPlaying(pact, 240) == 0)
S_PlayActorSound(240, pact);
}
pact->spr.extra -= damageAmount;
pact->spr.extra -= int(damageAmount);
if (pact->spr.extra <= 0)
{
S_PlayActorSound(SQUISHED, pact);
@ -2482,7 +2482,7 @@ void onMotorcycleHit(int snum, DDukeActor* victim)
else
victim->SetHitOwner(p->GetActor());
victim->attackertype = MOTOHIT;
victim->hitextra = xs_CRoundToInt(p->MotoSpeed / 2.);
victim->hitextra = int(p->MotoSpeed * 0.5);
p->MotoSpeed -= p->MotoSpeed / 4.;
p->TurbCount = 6;
}
@ -2542,7 +2542,7 @@ void onBoatHit(int snum, DDukeActor* victim)
else
victim->SetHitOwner(p->GetActor());
victim->attackertype = MOTOHIT;
victim->hitextra = xs_CRoundToInt(p->MotoSpeed / 4.);
victim->hitextra = int(p->MotoSpeed * 0.25);
p->MotoSpeed -= p->MotoSpeed / 4.;
p->TurbCount = 6;
}
@ -3455,6 +3455,16 @@ void processinput_r(int snum)
if (clz.type == kHitSprite)
{
auto doVehicleHit = [&]()
{
if (badguy(clz.actor()))
{
clz.actor()->attackertype = MOTOHIT;
clz.actor()->hitextra = int(2 + (p->MotoSpeed * 0.5));
p->MotoSpeed -= p->MotoSpeed * (1. / 16.);
}
};
if ((clz.actor()->spr.cstat & (CSTAT_SPRITE_ALIGNMENT_FLOOR| CSTAT_SPRITE_BLOCK)) == (CSTAT_SPRITE_ALIGNMENT_FLOOR | CSTAT_SPRITE_BLOCK))
{
psectlotag = 0;
@ -3462,20 +3472,10 @@ void processinput_r(int snum)
p->spritebridge = 1;
}
if (p->OnMotorcycle)
if (badguy(clz.actor()))
{
clz.actor()->attackertype = MOTOHIT;
clz.actor()->hitextra = xs_CRoundToInt(2 + (p->MotoSpeed / 2.));
p->MotoSpeed -= p->MotoSpeed / 16.;
}
doVehicleHit();
if (p->OnBoat)
{
if (badguy(clz.actor()))
{
clz.actor()->attackertype = MOTOHIT;
clz.actor()->hitextra = xs_CRoundToInt(2 + (p->MotoSpeed / 2.));
p->MotoSpeed -= p->MotoSpeed / 16.;
}
doVehicleHit();
}
else if (badguy(clz.actor()) && clz.actor()->spr.xrepeat > 24 && abs(pact->spr.pos.Z - clz.actor()->spr.pos.Z) < (84 << 8))
{

View file

@ -2189,7 +2189,7 @@ int SpawnShell(DSWActor* actor, int ShellNum)
if (actor->user.PlayerP)
{
actorNew->spr.pos.Z += xs_CRoundToInt(-MulScaleF(actor->user.PlayerP->horizon.horiz.asq16(), HORIZ_MULT / 3., 16));
actorNew->spr.pos.Z += int(-actor->user.PlayerP->horizon.horiz.asbuildf() * HORIZ_MULT * (1. / 3.));
}
switch (actorNew->user.ID)

View file

@ -14922,7 +14922,7 @@ int InitTracerUzi(PLAYER* pp)
return 0;
}
actorNew->spr.zvel = xs_CRoundToInt(-MulScaleF(pp->horizon.horiz.asq16(), actorNew->spr.xvel / 8., 16));
actorNew->spr.zvel = int(-pp->horizon.horiz.asbuildf() * actorNew->spr.xvel * (1. / 8.));
plActor->spr.clipdist = oclipdist;
@ -14971,7 +14971,7 @@ int InitTracerTurret(DSWActor* actor, DSWActor* Operator, fixed_t q16horiz)
actorNew->spr.cstat |= (CSTAT_SPRITE_YCENTER);
actorNew->spr.cstat |= (CSTAT_SPRITE_INVISIBLE);
actorNew->spr.zvel = xs_CRoundToInt(-MulScaleF(q16horiz, actorNew->spr.xvel / 8., 16));
actorNew->spr.zvel = int(-MulScaleF(q16horiz, actorNew->spr.xvel * (1. / 8.), 16));
WeaponAutoAim(actor, actorNew, 32, false);
@ -15392,7 +15392,7 @@ int InitTankShell(DSWActor* actor, PLAYER* pp)
actorNew->spr.cstat |= (CSTAT_SPRITE_YCENTER);
actorNew->spr.cstat |= (CSTAT_SPRITE_INVISIBLE);
actorNew->spr.zvel = xs_CRoundToInt(-MulScaleF(pp->horizon.horiz.asq16(), actorNew->spr.xvel / 8., 16));
actorNew->spr.zvel = int(-pp->horizon.horiz.asbuildf() * actorNew->spr.xvel * (1. / 8.));
WeaponAutoAim(actor, actorNew, 64, false);
// a bit of randomness
@ -15530,7 +15530,7 @@ int InitTurretRocket(DSWActor* actor, PLAYER* pp)
actorNew->user.Flags2 |= (SPR2_SO_MISSILE);
actorNew->spr.cstat |= (CSTAT_SPRITE_YCENTER);
actorNew->spr.zvel = xs_CRoundToInt(-MulScaleF(pp->horizon.horiz.asq16(), actorNew->spr.xvel / 8., 16));
actorNew->spr.zvel = int(-pp->horizon.horiz.asbuildf() * actorNew->spr.xvel * (1. / 8.));
WeaponAutoAim(actor, actorNew, 64, false);
// a bit of randomness
@ -15567,7 +15567,7 @@ int InitTurretFireball(DSWActor* actor, PLAYER* pp)
actorNew->user.Flags2 |= (SPR2_SO_MISSILE);
actorNew->spr.cstat |= (CSTAT_SPRITE_YCENTER);
actorNew->spr.zvel = xs_CRoundToInt(-MulScaleF(pp->horizon.horiz.asq16(), actorNew->spr.xvel / 8., 16));
actorNew->spr.zvel = int(-pp->horizon.horiz.asbuildf() * actorNew->spr.xvel * (1. / 8.));
WeaponAutoAim(actor, actorNew, 64, false);
// a bit of randomness