From 7b05beeb75097d53ef103fdd53ba54c4f1946237 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 5 Sep 2022 00:57:40 +0200 Subject: [PATCH] - floatified several Distance calls --- source/games/sw/src/coolie.cpp | 2 +- source/games/sw/src/player.cpp | 36 +++++++++++++++++---------------- source/games/sw/src/ripper.cpp | 4 ++-- source/games/sw/src/ripper2.cpp | 4 ++-- source/games/sw/src/rotator.cpp | 5 ++--- source/games/sw/src/sector.cpp | 9 +++------ source/games/sw/src/sprite.cpp | 3 ++- source/games/sw/src/weapon.cpp | 15 ++++---------- 8 files changed, 35 insertions(+), 43 deletions(-) diff --git a/source/games/sw/src/coolie.cpp b/source/games/sw/src/coolie.cpp index 5174351ed..ac03b0894 100644 --- a/source/games/sw/src/coolie.cpp +++ b/source/games/sw/src/coolie.cpp @@ -598,7 +598,7 @@ int DoCoolieMove(DSWActor* actor) return 0; } - if (DistanceI(actor->spr.pos, actor->user.targetActor->spr.pos) < 1200) + if ((actor->spr.pos.XY() - actor->user.targetActor->spr.pos.XY()).Length() < 75) { UpdateSinglePlayKills(actor); DoActorDie(actor, actor, 0); diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index 6c1bd2db1..e9d7240a3 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -1697,33 +1697,27 @@ void DoPlayerHorizon(PLAYER* pp, float const horz, double const scaleAdjust) void DoPlayerBob(PLAYER* pp) { - int dist; - int amt; + double amt; - dist = 0; + double dist = (pp->pos.XY() - pp->oldpos.XY()).Length(); - dist = DistanceI(pp->pos, pp->oldpos); - - if (dist > 512) + if (dist > 32) dist = 0; // if running make a longer stride if (pp->input.actions & SB_RUN) { - //amt = 10; - amt = 12; - amt = MulScale(amt, dist<<8, 16); - dist = MulScale(dist, 26000, 16); + amt = dist * (12. / 16.); + dist *= FixedToFloat(26000); } else { - amt = 5; - amt = MulScale(amt, dist<<9, 16); - dist = MulScale(dist, 32000, 16); + amt = dist * (5. / 8.); + dist *= FixedToFloat(32000); } // controls how fast you move through the sin table - pp->bcnt += dist; + pp->bcnt += int(dist * 16); // wrap bcnt pp->bcnt &= 2047; @@ -1748,6 +1742,12 @@ void DoPlayerBeginRecoil(PLAYER* pp, short pix_amt) pp->recoil_ohorizoff = pp->recoil_horizoff = 0; } +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + void DoPlayerRecoil(PLAYER* pp) { // controls how fast you move through the sin table @@ -3481,7 +3481,9 @@ int DoPlayerWadeSuperJump(PLAYER* pp) if (hit.hitSector != nullptr && abs(hit.hitSector->int_floorz() - pp->int_ppos().Z) < Z(50)) { - if (Distance(pp->int_ppos().X, pp->int_ppos().Y, hit.int_hitpos().X, hit.int_hitpos().Y) < ((((int)pp->actor->spr.clipdist)<<2) + 256)) + double dist = (pp->pos.XY() - hit.hitpos.XY()).Length(); + double comp = ((((int)pp->actor->spr.clipdist)<<2) + 256) * inttoworld; + if (dist < comp) return true; } } @@ -3714,14 +3716,14 @@ void DoPlayerFly(PLAYER* pp) DSWActor* FindNearSprite(DSWActor* actor, short stat) { int fs; - int dist, near_dist = 15000; + double dist, near_dist = 937.5; DSWActor* near_fp = nullptr; SWStatIterator it(stat); while (auto itActor = it.Next()) { - dist = DistanceI(actor->spr.pos, itActor->spr.pos); + dist = (actor->spr.pos.XY() - itActor->spr.pos.XY()).Length(); if (dist < near_dist) { diff --git a/source/games/sw/src/ripper.cpp b/source/games/sw/src/ripper.cpp index b0cdebec0..6cf2525dd 100644 --- a/source/games/sw/src/ripper.cpp +++ b/source/games/sw/src/ripper.cpp @@ -928,9 +928,9 @@ int InitRipperHang(DSWActor* actor) if (hit.hitSector == nullptr) continue; - int dist = DistanceI(actor->spr.pos, hit.hitpos); + double dist = (actor->spr.pos.XY() - hit.hitpos.XY()).Length(); - if (hit.hitWall == nullptr || dist < 2000 || dist > 7000) + if (hit.hitWall == nullptr || dist < 125 || dist > 437.5) { continue; } diff --git a/source/games/sw/src/ripper2.cpp b/source/games/sw/src/ripper2.cpp index 2fef9a4b2..b0fafc225 100644 --- a/source/games/sw/src/ripper2.cpp +++ b/source/games/sw/src/ripper2.cpp @@ -941,9 +941,9 @@ int InitRipper2Hang(DSWActor* actor) if (hit.hitSector == nullptr) continue; - int dist = DistanceI(actor->spr.pos, hit.hitpos); + double dist = (actor->spr.pos.XY() - hit.hitpos.XY()).Length(); - if (hit.hitWall == nullptr || dist < 2000 || dist > 7000) + if (hit.hitWall == nullptr || dist < 125 || dist > 437.5) { continue; } diff --git a/source/games/sw/src/rotator.cpp b/source/games/sw/src/rotator.cpp index 1e4da295d..d61d3aaf7 100644 --- a/source/games/sw/src/rotator.cpp +++ b/source/games/sw/src/rotator.cpp @@ -245,7 +245,6 @@ int DoRotator(DSWActor* actor) short ndx,w,startwall,endwall; DSWActor* pivot = nullptr; vec2_t nxy; - int dist,closest; bool kill = false; r = actor->user.rotator.Data(); @@ -320,13 +319,13 @@ int DoRotator(DSWActor* actor) kill = true; } - closest = 99999; + double closest = 99999; SWStatIterator it(STAT_ROTATOR_PIVOT); while (auto itActor = it.Next()) { if (itActor->spr.lotag == actor->spr.lotag) { - dist = DistanceI(actor->spr.pos, itActor->spr.pos); + double dist = (actor->spr.pos.XY() - itActor->spr.pos.XY()).Length(); if (dist < closest) { closest = dist; diff --git a/source/games/sw/src/sector.cpp b/source/games/sw/src/sector.cpp index 6da029038..7c3d32322 100644 --- a/source/games/sw/src/sector.cpp +++ b/source/games/sw/src/sector.cpp @@ -1832,17 +1832,14 @@ void OperateTripTrigger(PLAYER* pp) case TAG_TRIGGER_ACTORS: { - int dist; - int i; - - dist = sectp->hitag; + double dist = sectp->hitag * maptoworld; SWStatIterator it(STAT_ENEMY); while (auto actor = it.Next()) { if (actor->user.Flags & (SPR_WAIT_FOR_TRIGGER)) { - if (Distance(actor->int_pos().X, actor->int_pos().Y, pp->int_ppos().X, pp->int_ppos().Y) < dist) + if ((actor->spr.pos.XY() - pp->pos.XY()).Length() < dist) { actor->user.targetActor = pp->actor; actor->user.Flags &= ~(SPR_WAIT_FOR_TRIGGER); @@ -1982,7 +1979,7 @@ bool NearThings(PLAYER* pp) if (hit.hitSector == nullptr) return false; - if (Distance(hit.int_hitpos().X, hit.int_hitpos().Y, pp->int_ppos().X, pp->int_ppos().Y) > 1500) + if ((hit.hitpos.XY() - pp->pos.XY()).Length() > 93.75) return false; // hit a sprite? diff --git a/source/games/sw/src/sprite.cpp b/source/games/sw/src/sprite.cpp index b4b47be50..7373cfb01 100644 --- a/source/games/sw/src/sprite.cpp +++ b/source/games/sw/src/sprite.cpp @@ -4239,7 +4239,8 @@ int NewStateGroup(DSWActor* actor, STATE* StateGroup[]) bool SpriteOverlap(DSWActor* actor_a, DSWActor* actor_b) { if (!actor_a->hasU() || !actor_b->hasU()) return false; - if ((unsigned)DistanceI(actor_a->spr.pos, actor_b->spr.pos) > actor_a->user.Radius + actor_b->user.Radius) + double dist = (actor_a->spr.pos.XY() - actor_b->spr.pos.XY()).Length(); + if (dist > (actor_a->user.Radius + actor_b->user.Radius) * inttoworld) { return false; } diff --git a/source/games/sw/src/weapon.cpp b/source/games/sw/src/weapon.cpp index c3bae4f51..00d3e49b0 100644 --- a/source/games/sw/src/weapon.cpp +++ b/source/games/sw/src/weapon.cpp @@ -11621,7 +11621,7 @@ int InitSwordAttack(PLAYER* pp) if (!(itActor->spr.extra & SPRX_PLAYER_OR_ENEMY)) continue; - dist = Distance(pp->int_ppos().X, pp->int_ppos().Y, itActor->int_pos().X, itActor->int_pos().Y); + dist = DistanceI(pp->pos, itActor->spr.pos); reach = 1000; // !JIM! was 800 face = 200; @@ -11786,7 +11786,7 @@ int InitFistAttack(PLAYER* pp) if (!(itActor->spr.extra & SPRX_PLAYER_OR_ENEMY)) continue; - dist = Distance(pp->int_ppos().X, pp->int_ppos().Y, itActor->int_pos().X, itActor->int_pos().Y); + dist = DistanceI(pp->pos, itActor->spr.pos); if (pp->InventoryActive[2]) // Shadow Bombs give you demon fist { @@ -12171,13 +12171,6 @@ int WeaponAutoAimZvel(DSWActor* actor, DSWActor* missileActor, int *zvel, short { int dist; -#if 0 - //formula for leading a player - dist = Distance(actor->int_pos().X, actor->int_pos().Y, hp->pos.X, hp->pos.Y); - time_to_target = dist/missileActor->int_xvel(); - lead_dist = time_to_target*hp->vel; -#endif - if (actor->hasU() && actor->user.PlayerP) { if (!Autoaim(actor->user.PlayerP->pnum)) @@ -17124,8 +17117,8 @@ DSWActor* QueueWallBlood(DSWActor* actor, DAngle bang) if (hit.hitSector == nullptr) return nullptr; - const int WALLBLOOD_DIST_MAX = 2500; - if (DistanceI(hit.hitpos, actor->spr.pos) > WALLBLOOD_DIST_MAX) + const double WALLBLOOD_DIST_MAX = 156.25; + if ((hit.hitpos.XY(), actor->spr.pos.XY()).Length() > WALLBLOOD_DIST_MAX) return nullptr; // hit a sprite?