From c5474436af67408342e8dce0ec996d62c9a4c21c Mon Sep 17 00:00:00 2001 From: Sally Coolatta <tehrealsalt@gmail.com> Date: Sat, 7 Nov 2020 19:47:50 -0500 Subject: [PATCH 1/3] Use FixedHypot over P_AproxDistance Not convinced that the small speed benefit from P_AproxDistance is worth the "aproximate"[sic] results it gives. Let's instead try a define to replace it with FixedHypot. In Lua, the function gives a deprecated warning. Inspired by the hyperwall fix for vanilla, except for everything. From little testing, actively improves waypoint checks, bumping, speed checks, wall collisions, Jawz targetting, Lightning Shield attacks, so on. The only way I see this as a potential downgrade is A_Look (and related functions) getting slower, which are barely used in Kart. --- src/lua_baselib.c | 3 ++- src/p_maputl.c | 13 ------------- src/p_maputl.h | 2 +- 3 files changed, 3 insertions(+), 15 deletions(-) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 515f6f0ba..7b2e42bd5 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -427,7 +427,8 @@ static int lib_pAproxDistance(lua_State *L) fixed_t dx = luaL_checkfixed(L, 1); fixed_t dy = luaL_checkfixed(L, 2); //HUDSAFE - lua_pushfixed(L, P_AproxDistance(dx, dy)); + LUA_Deprecated(L, "P_AproxDistance", "FixedHypot"); + lua_pushfixed(L, FixedHypot(dx, dy)); return 1; } diff --git a/src/p_maputl.c b/src/p_maputl.c index 90718a41c..83905a418 100644 --- a/src/p_maputl.c +++ b/src/p_maputl.c @@ -24,19 +24,6 @@ #include "p_slopes.h" #include "z_zone.h" -// -// P_AproxDistance -// Gives an estimation of distance (not exact) -// -fixed_t P_AproxDistance(fixed_t dx, fixed_t dy) -{ - dx = abs(dx); - dy = abs(dy); - if (dx < dy) - return dx + dy - (dx>>1); - return dx + dy - (dy>>1); -} - // // P_ClosestPointOnLine // Finds the closest point on a given line to the supplied point diff --git a/src/p_maputl.h b/src/p_maputl.h index 08b606833..df90ab4b4 100644 --- a/src/p_maputl.h +++ b/src/p_maputl.h @@ -41,7 +41,7 @@ typedef boolean (*traverser_t)(intercept_t *in); boolean P_PathTraverse(fixed_t px1, fixed_t py1, fixed_t px2, fixed_t py2, INT32 pflags, traverser_t ptrav); -FUNCMATH fixed_t P_AproxDistance(fixed_t dx, fixed_t dy); +#define P_AproxDistance(dx, dy) FixedHypot(dx, dy) void P_ClosestPointOnLine(fixed_t x, fixed_t y, line_t *line, vertex_t *result); void P_ClosestPointOnLine3D(const vector3_t *p, const vector3_t *line, vector3_t *result); INT32 P_PointOnLineSide(fixed_t x, fixed_t y, line_t *line); From e19196a86e5347edf7f25b335214cede978b91b8 Mon Sep 17 00:00:00 2001 From: Sally Coolatta <tehrealsalt@gmail.com> Date: Sat, 7 Nov 2020 23:56:46 -0500 Subject: [PATCH 2/3] Use R_PointToDist2 instead Apparently overflows less often Actually, lets just fix FixedHypot instead. Now FixedHypot uses the code from R_PointToDist2, and R_PointToDist2 just calls FixedHypot. Ultimately, this branch was intended to get rid of a redundant way to retrieve distance and replace it with the one that was actually good at its job. So consolidating FixedHypot and R_PointToDist2 together is just an extension of that. --- src/m_fixed.c | 40 ++++++++++++++++++++++++++++------------ src/r_main.c | 24 +----------------------- 2 files changed, 29 insertions(+), 35 deletions(-) diff --git a/src/m_fixed.c b/src/m_fixed.c index eb10fd5f8..09d6936f2 100644 --- a/src/m_fixed.c +++ b/src/m_fixed.c @@ -18,8 +18,10 @@ #define HAVE_SQRTF #endif #endif + #include "doomdef.h" #include "m_fixed.h" +#include "tables.h" // ANGLETOFINESHIFT #ifdef __USE_C_FIXEDMUL__ @@ -105,20 +107,34 @@ fixed_t FixedSqrt(fixed_t x) fixed_t FixedHypot(fixed_t x, fixed_t y) { - fixed_t ax, yx, yx2, yx1; - if (abs(y) > abs(x)) // |y|>|x| + // Moved the code from R_PointToDist2 to here, + // since R_PointToDist2 did the same thing, + // except less prone to overflowing. + + angle_t angle; + fixed_t dist; + + x = abs(x); + y = abs(y); + + if (y > x) { - ax = abs(y); // |y| => ax - yx = FixedDiv(x, y); // (x/y) + fixed_t temp; + + temp = x; + x = y; + y = temp; } - else // |x|>|y| - { - ax = abs(x); // |x| => ax - yx = FixedDiv(y, x); // (x/y) - } - yx2 = FixedMul(yx, yx); // (x/y)^2 - yx1 = FixedSqrt(1 * FRACUNIT + yx2); // (1 + (x/y)^2)^1/2 - return FixedMul(ax, yx1); // |x|*((1 + (x/y)^2)^1/2) + + if (!y) + return x; + + angle = (tantoangle[FixedDiv(y, x)>>DBITS] + ANGLE_90) >> ANGLETOFINESHIFT; + + // use as cosine + dist = FixedDiv(x, FINESINE(angle)); + + return dist; } vector2_t *FV2_Load(vector2_t *vec, fixed_t x, fixed_t y) diff --git a/src/r_main.c b/src/r_main.c index f82fb589e..f6c05e312 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -357,29 +357,7 @@ angle_t R_PointToAngle2(fixed_t pviewx, fixed_t pviewy, fixed_t x, fixed_t y) fixed_t R_PointToDist2(fixed_t px2, fixed_t py2, fixed_t px1, fixed_t py1) { - angle_t angle; - fixed_t dx, dy, dist; - - dx = abs(px1 - px2); - dy = abs(py1 - py2); - - if (dy > dx) - { - fixed_t temp; - - temp = dx; - dx = dy; - dy = temp; - } - if (!dy) - return dx; - - angle = (tantoangle[FixedDiv(dy, dx)>>DBITS] + ANGLE_90) >> ANGLETOFINESHIFT; - - // use as cosine - dist = FixedDiv(dx, FINESINE(angle)); - - return dist; + return FixedHypot(px1 - px2, py1 - py2); } // Little extra utility. Works in the same way as R_PointToAngle2 From 75633bde5039106c5f916ca2b4d1bde11d274be9 Mon Sep 17 00:00:00 2001 From: James R <justsomejames2@gmail.com> Date: Sat, 12 Dec 2020 14:53:54 -0800 Subject: [PATCH 3/3] Replace all instances of P_AproxDistance with FixedHypot --- src/b_bot.c | 10 +-- src/g_game.c | 2 +- src/p_ceilng.c | 4 +- src/p_enemy.c | 172 ++++++++++++++++++++++++------------------------ src/p_floor.c | 10 +-- src/p_inter.c | 20 +++--- src/p_map.c | 10 +-- src/p_maputl.h | 1 - src/p_mobj.c | 78 +++++++++++----------- src/p_polyobj.c | 2 +- src/p_setup.c | 2 +- src/p_slopes.c | 2 +- src/p_spec.c | 58 ++++++++-------- src/p_user.c | 56 ++++++++-------- src/r_things.c | 4 +- src/s_sound.c | 4 +- src/st_stuff.c | 2 +- 17 files changed, 218 insertions(+), 219 deletions(-) diff --git a/src/b_bot.c b/src/b_bot.c index d3635f32c..abe69caeb 100644 --- a/src/b_bot.c +++ b/src/b_bot.c @@ -54,11 +54,11 @@ static void B_BuildTailsTiccmd(mobj_t *sonic, mobj_t *tails, ticcmd_t *cmd) boolean _2d = (tails->flags2 & MF2_TWOD) || twodlevel; fixed_t scale = tails->scale; - fixed_t dist = P_AproxDistance(sonic->x - tails->x, sonic->y - tails->y); + fixed_t dist = FixedHypot(sonic->x - tails->x, sonic->y - tails->y); fixed_t zdist = flip * (sonic->z - tails->z); angle_t ang = sonic->angle; - fixed_t pmom = P_AproxDistance(sonic->momx, sonic->momy); - fixed_t bmom = P_AproxDistance(tails->momx, tails->momy); + fixed_t pmom = FixedHypot(sonic->momx, sonic->momy); + fixed_t bmom = FixedHypot(tails->momx, tails->momy); fixed_t followmax = 128 * 8 * scale; // Max follow distance before AI begins to enter "panic" state fixed_t followthres = 92 * scale; // Distance that AI will try to reach fixed_t followmin = 32 * scale; @@ -81,7 +81,7 @@ static void B_BuildTailsTiccmd(mobj_t *sonic, mobj_t *tails, ticcmd_t *cmd) if (tails->player->powers[pw_carry] == CR_MACESPIN || tails->player->powers[pw_carry] == CR_GENERIC) { boolean isrelevant = (sonic->player->powers[pw_carry] == CR_MACESPIN || sonic->player->powers[pw_carry] == CR_GENERIC); - dist = P_AproxDistance(tails->x-sonic->x, tails->y-sonic->y); + dist = FixedHypot(tails->x-sonic->x, tails->y-sonic->y); if (sonic->player->cmd.buttons & BT_JUMP && (sonic->player->pflags & PF_JUMPED) && isrelevant) cmd->buttons |= BT_JUMP; if (isrelevant) @@ -496,7 +496,7 @@ boolean B_CheckRespawn(player_t *player) } // If you can't see Sonic, I guess we should? - if (!P_CheckSight(sonic, tails) && P_AproxDistance(P_AproxDistance(tails->x-sonic->x, tails->y-sonic->y), tails->z-sonic->z) > FixedMul(1024*FRACUNIT, tails->scale)) + if (!P_CheckSight(sonic, tails) && FixedHypot(FixedHypot(tails->x-sonic->x, tails->y-sonic->y), tails->z-sonic->z) > FixedMul(1024*FRACUNIT, tails->scale)) return true; return false; } diff --git a/src/g_game.c b/src/g_game.c index 6171c7b72..3f8d573c8 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -1423,7 +1423,7 @@ void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer) newtarget = P_SpawnMobj(ticcmd_ztargetfocus[forplayer]->x, ticcmd_ztargetfocus[forplayer]->y, ticcmd_ztargetfocus[forplayer]->z, MT_LOCKON); // positioning, flip handled in P_SceneryThinker P_SetTarget(&newtarget->target, ticcmd_ztargetfocus[forplayer]); - if (P_AproxDistance( + if (FixedHypot( player->mo->x - ticcmd_ztargetfocus[forplayer]->x, player->mo->y - ticcmd_ztargetfocus[forplayer]->y ) > 50*player->mo->scale) diff --git a/src/p_ceilng.c b/src/p_ceilng.c index f12499d5c..2168d1d78 100644 --- a/src/p_ceilng.c +++ b/src/p_ceilng.c @@ -468,7 +468,7 @@ INT32 EV_DoCeiling(line_t *line, ceiling_e type) // Linedef executor excellence case moveCeilingByFrontSector: - ceiling->speed = P_AproxDistance(line->dx, line->dy); + ceiling->speed = FixedHypot(line->dx, line->dy); ceiling->speed = FixedDiv(ceiling->speed,8*FRACUNIT); if (line->frontsector->ceilingheight >= sec->ceilingheight) // Move up { @@ -547,7 +547,7 @@ INT32 EV_DoCeiling(line_t *line, ceiling_e type) */ case bounceCeiling: - ceiling->speed = P_AproxDistance(line->dx, line->dy); // same speed as elevateContinuous + ceiling->speed = FixedHypot(line->dx, line->dy); // same speed as elevateContinuous ceiling->speed = FixedDiv(ceiling->speed,4*FRACUNIT); ceiling->origspeed = ceiling->speed; if (line->frontsector->ceilingheight >= sec->ceilingheight) // Move up diff --git a/src/p_enemy.c b/src/p_enemy.c index 203e04af1..0d94f2a7e 100644 --- a/src/p_enemy.c +++ b/src/p_enemy.c @@ -334,7 +334,7 @@ boolean P_CheckMeleeRange(mobj_t *actor) return false; pl = actor->target; - dist = P_AproxDistance(pl->x-actor->x, pl->y-actor->y); + dist = FixedHypot(pl->x-actor->x, pl->y-actor->y); if (dist >= FixedMul(MELEERANGE - 20*FRACUNIT, actor->scale) + pl->radius) return false; @@ -360,7 +360,7 @@ boolean P_JetbCheckMeleeRange(mobj_t *actor) return false; pl = actor->target; - dist = P_AproxDistance(pl->x-actor->x, pl->y-actor->y); + dist = FixedHypot(pl->x-actor->x, pl->y-actor->y); if (dist >= (actor->radius + pl->radius)*2) return false; @@ -389,7 +389,7 @@ boolean P_FaceStabCheckMeleeRange(mobj_t *actor) return false; pl = actor->target; - dist = P_AproxDistance(pl->x-actor->x, pl->y-actor->y); + dist = FixedHypot(pl->x-actor->x, pl->y-actor->y); if (dist >= (actor->radius + pl->radius)*4) return false; @@ -413,7 +413,7 @@ boolean P_SkimCheckMeleeRange(mobj_t *actor) return false; pl = actor->target; - dist = P_AproxDistance(pl->x-actor->x, pl->y-actor->y); + dist = FixedHypot(pl->x-actor->x, pl->y-actor->y); if (dist >= FixedMul(MELEERANGE - 20*FRACUNIT, actor->scale) + pl->radius) return false; @@ -449,7 +449,7 @@ boolean P_CheckMissileRange(mobj_t *actor) return false; // OPTIMIZE: get this from a global checksight - dist = P_AproxDistance(actor->x-actor->target->x, actor->y-actor->target->y) - FixedMul(64*FRACUNIT, actor->scale); + dist = FixedHypot(actor->x-actor->target->x, actor->y-actor->target->y) - FixedMul(64*FRACUNIT, actor->scale); if (!actor->info->meleestate) dist -= FixedMul(128*FRACUNIT, actor->scale); // no melee attack, so fire more @@ -750,7 +750,7 @@ boolean P_LookForPlayers(mobj_t *actor, boolean allaround, boolean tracer, fixed continue; // Ignore uncontrolled bodies if (dist > 0 - && P_AproxDistance(P_AproxDistance(player->mo->x - actor->x, player->mo->y - actor->y), player->mo->z - actor->z) > dist) + && FixedHypot(FixedHypot(player->mo->x - actor->x, player->mo->y - actor->y), player->mo->z - actor->z) > dist) continue; // Too far away if (!allaround) @@ -758,7 +758,7 @@ boolean P_LookForPlayers(mobj_t *actor, boolean allaround, boolean tracer, fixed an = R_PointToAngle2(actor->x, actor->y, player->mo->x, player->mo->y) - actor->angle; if (an > ANGLE_90 && an < ANGLE_270) { - dist = P_AproxDistance(player->mo->x - actor->x, player->mo->y - actor->y); + dist = FixedHypot(player->mo->x - actor->x, player->mo->y - actor->y); // if real close, react anyway if (dist > FixedMul(MELEERANGE, actor->scale)) continue; // behind back @@ -821,7 +821,7 @@ static boolean P_LookForShield(mobj_t *actor) continue; if ((player->powers[pw_shield] & SH_PROTECTELECTRIC) - && (P_AproxDistance(P_AproxDistance(actor->x-player->mo->x, actor->y-player->mo->y), actor->z-player->mo->z) < FixedMul(RING_DIST, player->mo->scale))) + && (FixedHypot(FixedHypot(actor->x-player->mo->x, actor->y-player->mo->y), actor->z-player->mo->z) < FixedMul(RING_DIST, player->mo->scale))) { P_SetTarget(&actor->tracer, player->mo); @@ -1548,8 +1548,8 @@ void A_PointyThink(mobj_t *actor) } else { - if (P_AproxDistance(players[i].mo->x - actor->x, players[i].mo->y - actor->y) < - P_AproxDistance(player->mo->x - actor->x, player->mo->y - actor->y)) + if (FixedHypot(players[i].mo->x - actor->x, players[i].mo->y - actor->y) < + FixedHypot(player->mo->x - actor->x, player->mo->y - actor->y)) player = &players[i]; } } @@ -1561,7 +1561,7 @@ void A_PointyThink(mobj_t *actor) P_SetTarget(&actor->target, player->mo); A_FaceTarget(actor); - if (P_AproxDistance(player->mo->x - actor->x, player->mo->y - actor->y) < P_AproxDistance(player->mo->x + player->mo->momx - actor->x, player->mo->y + player->mo->momy - actor->y)) + if (FixedHypot(player->mo->x - actor->x, player->mo->y - actor->y) < FixedHypot(player->mo->x + player->mo->momx - actor->x, player->mo->y + player->mo->momy - actor->y)) sign = -1; // Player is moving away else sign = 1; // Player is moving closer @@ -1638,7 +1638,7 @@ static void P_ParabolicMove(mobj_t *actor, fixed_t x, fixed_t y, fixed_t z, fixe y -= actor->y; z -= actor->z; - dh = P_AproxDistance(x, y); + dh = FixedHypot(x, y); actor->momx = FixedMul(FixedDiv(x, dh), speed); actor->momy = FixedMul(FixedDiv(y, dh), speed); @@ -1706,7 +1706,7 @@ void A_HoodThink(mobj_t *actor) } dx = (actor->target->x - actor->x), dy = (actor->target->y - actor->y), dz = (actor->target->z - actor->z); - dm = P_AproxDistance(dx, dy); + dm = FixedHypot(dx, dy); // Target dangerously close to robohood, retreat then. if ((dm < 256<<FRACBITS) && (abs(dz) < 128<<FRACBITS)) { @@ -2094,7 +2094,7 @@ void A_CrushclawAim(mobj_t *actor) if (!crab->target || !crab->info->missilestate || (statenum_t)(crab->state-states) == crab->info->missilestate) return; - if (((ang + ANG1) < ANG2) || P_AproxDistance(crab->x - crab->target->x, crab->y - crab->target->y) < 333*crab->scale) + if (((ang + ANG1) < ANG2) || FixedHypot(crab->x - crab->target->x, crab->y - crab->target->y) < 333*crab->scale) P_SetMobjState(crab, crab->info->missilestate); } @@ -2703,7 +2703,7 @@ void A_LobShot(mobj_t *actor) shot->angle = an = actor->angle; an >>= ANGLETOFINESHIFT; - dist = P_AproxDistance(actor->target->x - shot->x, actor->target->y - shot->y); + dist = FixedHypot(actor->target->x - shot->x, actor->target->y - shot->y); horizontal = dist / airtime; vertical = FixedMul((gravity*airtime)/2, shot->scale); @@ -2721,7 +2721,7 @@ void A_LobShot(mobj_t *actor) diff = actor->z - actor->target->z; { - launchhyp = P_AproxDistance(horizontal, vertical); + launchhyp = FixedHypot(horizontal, vertical); orig = FixedMul(FixedDiv(vertical, horizontal), diff); @@ -3325,7 +3325,7 @@ void A_SkullAttack(mobj_t *actor) S_StartSound(actor, actor->info->activesound); A_FaceTarget(actor); - dist = P_AproxDistance(dest->x - actor->x, dest->y - actor->y); + dist = FixedHypot(dest->x - actor->x, dest->y - actor->y); if (locvar1 == 1) actor->angle += ANGLE_180; @@ -3443,7 +3443,7 @@ void A_BossZoom(mobj_t *actor) an = actor->angle >> ANGLETOFINESHIFT; actor->momx = FixedMul(FixedMul(actor->info->speed*5*FRACUNIT, actor->scale), FINECOSINE(an)); actor->momy = FixedMul(FixedMul(actor->info->speed*5*FRACUNIT, actor->scale), FINESINE(an)); - dist = P_AproxDistance(dest->x - actor->x, dest->y - actor->y); + dist = FixedHypot(dest->x - actor->x, dest->y - actor->y); dist = dist / FixedMul(actor->info->speed*5*FRACUNIT, actor->scale); if (dist < 1) @@ -3599,7 +3599,7 @@ void A_1upThinker(mobj_t *actor) if ((netgame || multiplayer) && players[i].playerstate != PST_LIVE) continue; - temp = P_AproxDistance(players[i].mo->x-actor->x, players[i].mo->y-actor->y); + temp = FixedHypot(players[i].mo->x-actor->x, players[i].mo->y-actor->y); if (temp < dist) { @@ -4144,8 +4144,8 @@ bossjustdie: // If this one's further then the last one, don't go for it. if (mo->target && - P_AproxDistance(P_AproxDistance(mo->x - mo2->x, mo->y - mo2->y), mo->z - mo2->z) > - P_AproxDistance(P_AproxDistance(mo->x - mo->target->x, mo->y - mo->target->y), mo->z - mo->target->z)) + FixedHypot(FixedHypot(mo->x - mo2->x, mo->y - mo2->y), mo->z - mo2->z) > + FixedHypot(FixedHypot(mo->x - mo->target->x, mo->y - mo->target->y), mo->z - mo->target->z)) continue; // Otherwise... Do! @@ -4536,7 +4536,7 @@ void A_BubbleSpawn(mobj_t *actor) // Don't spawn bubbles unless a player is relatively close by (var1). for (i = 0; i < MAXPLAYERS; ++i) if (playeringame[i] && players[i].mo - && P_AproxDistance(actor->x - players[i].mo->x, actor->y - players[i].mo->y) < (locvar1<<FRACBITS)) + && FixedHypot(actor->x - players[i].mo->x, actor->y - players[i].mo->y) < (locvar1<<FRACBITS)) break; // Stop looking. if (i == MAXPLAYERS) return; // don't make bubble! @@ -4584,7 +4584,7 @@ void A_FanBubbleSpawn(mobj_t *actor) // Don't spawn bubbles unless a player is relatively close by (var2). for (i = 0; i < MAXPLAYERS; ++i) if (playeringame[i] && players[i].mo - && P_AproxDistance(actor->x - players[i].mo->x, actor->y - players[i].mo->y) < (locvar1<<FRACBITS)) + && FixedHypot(actor->x - players[i].mo->x, actor->y - players[i].mo->y) < (locvar1<<FRACBITS)) break; // Stop looking. if (i == MAXPLAYERS) return; // don't make bubble! @@ -4759,7 +4759,7 @@ void A_DropMine(mobj_t *actor) if (!target) return; - dist = P_AproxDistance(actor->x-target->x, actor->y-target->y)>>FRACBITS; + dist = FixedHypot(actor->x-target->x, actor->y-target->y)>>FRACBITS; if (dist > FixedMul((locvar2 & 65535), actor->scale)) return; @@ -4800,7 +4800,7 @@ void A_FishJump(mobj_t *actor) // Don't spawn trail unless a player is nearby. for (i = 0; i < MAXPLAYERS; ++i) if (playeringame[i] && players[i].mo - && P_AproxDistance(actor->x - players[i].mo->x, actor->y - players[i].mo->y) < (actor->info->speed)) + && FixedHypot(actor->x - players[i].mo->x, actor->y - players[i].mo->y) < (actor->info->speed)) break; // Stop looking. if (i < MAXPLAYERS) { @@ -4905,7 +4905,7 @@ void A_ThrownRing(mobj_t *actor) // magnetic player. If he gets too far away, make // sure to stop the attraction! if ((!actor->tracer->health) || (actor->tracer->player && (actor->tracer->player->powers[pw_shield] & SH_PROTECTELECTRIC) - && P_AproxDistance(P_AproxDistance(actor->tracer->x-actor->x, + && FixedHypot(FixedHypot(actor->tracer->x-actor->x, actor->tracer->y-actor->y), actor->tracer->z-actor->z) > FixedMul(RING_DIST/4, actor->tracer->scale))) { P_SetTarget(&actor->tracer, NULL); @@ -4964,7 +4964,7 @@ void A_ThrownRing(mobj_t *actor) continue; } - dist = P_AproxDistance(P_AproxDistance(player->mo->x-actor->x, + dist = FixedHypot(FixedHypot(player->mo->x-actor->x, player->mo->y-actor->y), player->mo->z-actor->z); // check distance @@ -5345,7 +5345,7 @@ void A_JetChase(mobj_t *actor) return; // got a new target // If the player is over 3072 fracunits away, then look for another player - if (P_AproxDistance(P_AproxDistance(actor->target->x - actor->x, actor->target->y - actor->y), + if (FixedHypot(FixedHypot(actor->target->x - actor->x, actor->target->y - actor->y), actor->target->z - actor->z) > FixedMul(3072*FRACUNIT, actor->scale) && P_LookForPlayers(actor, true, false, FixedMul(3072*FRACUNIT, actor->scale))) { return; // got a new target @@ -5460,7 +5460,7 @@ void A_JetgShoot(mobj_t *actor) if (actor->reactiontime) return; - dist = P_AproxDistance(actor->target->x - actor->x, actor->target->y - actor->y); + dist = FixedHypot(actor->target->x - actor->x, actor->target->y - actor->y); if (dist > FixedMul(actor->info->painchance*FRACUNIT, actor->scale)) return; @@ -5497,7 +5497,7 @@ void A_ShootBullet(mobj_t *actor) if (!actor->target) return; - dist = P_AproxDistance(P_AproxDistance(actor->target->x - actor->x, actor->target->y - actor->y), actor->target->z - actor->z); + dist = FixedHypot(FixedHypot(actor->target->x - actor->x, actor->target->y - actor->y), actor->target->z - actor->z); if (dist > FixedMul(actor->info->painchance*FRACUNIT, actor->scale)) return; @@ -5522,7 +5522,7 @@ static boolean PIT_MinusCarry(mobj_t *thing) if (!(thing->flags & (MF_PUSHABLE|MF_ENEMY))) return true; - if (P_AproxDistance(minus->x - thing->x, minus->y - thing->y) >= minus->radius*3) + if (FixedHypot(minus->x - thing->x, minus->y - thing->y) >= minus->radius*3) return true; if (abs(thing->z - minus->z) > minus->height) @@ -5566,7 +5566,7 @@ void A_MinusDigging(mobj_t *actor) P_TryMove(par, x, y, false); // If close enough, prepare to attack - if (P_AproxDistance(actor->x - actor->target->x, actor->y - actor->target->y) < actor->radius*2) + if (FixedHypot(actor->x - actor->target->x, actor->y - actor->target->y) < actor->radius*2) { P_SetMobjState(actor, actor->info->meleestate); P_TryMove(actor, actor->target->x, actor->target->y, false); @@ -5858,7 +5858,7 @@ void A_DetonChase(mobj_t *actor) } }*/ // movedir is up/down angle: how much it has to go up as it goes over to the player - xydist = P_AproxDistance(actor->tracer->x - actor->x, actor->tracer->y - actor->y); + xydist = FixedHypot(actor->tracer->x - actor->x, actor->tracer->y - actor->y); exact = R_PointToAngle2(0, 0, xydist, actor->tracer->z - actor->z); actor->movedir = exact; /*if (exact != actor->movedir) @@ -5880,7 +5880,7 @@ void A_DetonChase(mobj_t *actor) // check for melee attack if (actor->tracer) { - if (P_AproxDistance(actor->tracer->x-actor->x, actor->tracer->y-actor->y) < actor->radius+actor->tracer->radius) + if (FixedHypot(actor->tracer->x-actor->x, actor->tracer->y-actor->y) < actor->radius+actor->tracer->radius) { if (!((actor->tracer->z > actor->z + actor->height) || (actor->z > actor->tracer->z + actor->tracer->height))) { @@ -5891,7 +5891,7 @@ void A_DetonChase(mobj_t *actor) } // chase towards player - if ((dist = P_AproxDistance(xydist, actor->tracer->z-actor->z)) + if ((dist = FixedHypot(xydist, actor->tracer->z-actor->z)) > FixedMul((actor->info->painchance << FRACBITS), actor->scale)) { P_SetTarget(&actor->tracer, NULL); // Too far away @@ -5933,7 +5933,7 @@ void A_DetonChase(mobj_t *actor) actor->momy = FixedMul(xyspeed, FINESINE(exact)); // Variable re-use - xyspeed = (P_AproxDistance(actor->tracer->x - actor->x, P_AproxDistance(actor->tracer->y - actor->y, actor->tracer->z - actor->z))>>(FRACBITS+6)); + xyspeed = (FixedHypot(actor->tracer->x - actor->x, FixedHypot(actor->tracer->y - actor->y, actor->tracer->z - actor->z))>>(FRACBITS+6)); if (xyspeed < 1) xyspeed = 1; @@ -6081,7 +6081,7 @@ void A_UnidusBall(mobj_t *actor) if (actor->movecount) { - if (P_AproxDistance(actor->momx, actor->momy) < FixedMul(actor->info->damage/2, actor->scale)) + if (FixedHypot(actor->momx, actor->momy) < FixedMul(actor->info->damage/2, actor->scale)) P_ExplodeMissile(actor); return; } @@ -6113,7 +6113,7 @@ void A_UnidusBall(mobj_t *actor) if (locvar1 == 1 && canthrow) { - if (P_AproxDistance(actor->target->target->x - actor->target->x, actor->target->target->y - actor->target->y) > FixedMul(MISSILERANGE>>1, actor->scale) + if (FixedHypot(actor->target->target->x - actor->target->x, actor->target->target->y - actor->target->y) > FixedMul(MISSILERANGE>>1, actor->scale) || !P_CheckSight(actor, actor->target->target)) return; @@ -6188,7 +6188,7 @@ void A_RockSpawn(mobj_t *actor) return; } - dist = P_AproxDistance(line->dx, line->dy)/16; + dist = FixedHypot(line->dx, line->dy)/16; if (dist < 1) dist = 1; @@ -6354,7 +6354,7 @@ void A_CrawlaCommanderThink(mobj_t *actor) return; } - dist = P_AproxDistance(actor->x - actor->target->x, actor->y - actor->target->y); + dist = FixedHypot(actor->x - actor->target->x, actor->y - actor->target->y); if (actor->target->player && (!hovermode || actor->reactiontime <= 2*TICRATE)) { @@ -6391,7 +6391,7 @@ void A_CrawlaCommanderThink(mobj_t *actor) { fixed_t mom; P_Thrust(actor, actor->angle, 2*actor->scale); - mom = P_AproxDistance(actor->momx, actor->momy); + mom = FixedHypot(actor->momx, actor->momy); if (mom > 20*actor->scale) { mom += 20*actor->scale; @@ -6479,7 +6479,7 @@ void A_RingExplode(mobj_t *actor) if (mo2 == actor) // Don't explode yourself! Endless loop! continue; - if (P_AproxDistance(P_AproxDistance(mo2->x - actor->x, mo2->y - actor->y), mo2->z - actor->z) > FixedMul(actor->info->painchance, actor->scale)) + if (FixedHypot(FixedHypot(mo2->x - actor->x, mo2->y - actor->y), mo2->z - actor->z) > FixedMul(actor->info->painchance, actor->scale)) continue; if (mo2->flags & MF_SHOOTABLE) @@ -7078,7 +7078,7 @@ nomissile: } // chase towards player - if (P_AproxDistance(actor->target->x-actor->x, actor->target->y-actor->y) > actor->radius+actor->target->radius) + if (FixedHypot(actor->target->x-actor->x, actor->target->y-actor->y) > actor->radius+actor->target->radius) { if (--actor->movecount < 0 || !P_Move(actor, actor->info->speed)) P_NewChaseDir(actor); @@ -7317,7 +7317,7 @@ void A_Boss7Chase(mobj_t *actor) // Self-adjust if stuck on the edge if (actor->tracer) { - if (P_AproxDistance(actor->x - actor->tracer->x, actor->y - actor->tracer->y) > 128*FRACUNIT - actor->radius) + if (FixedHypot(actor->x - actor->tracer->x, actor->y - actor->tracer->y) > 128*FRACUNIT - actor->radius) P_InstaThrust(actor, R_PointToAngle2(actor->x, actor->y, actor->tracer->x, actor->tracer->y), FRACUNIT); } @@ -7353,7 +7353,7 @@ void A_Boss7Chase(mobj_t *actor) if (players[i].mo->health <= 0) continue; - if (P_AproxDistance(players[i].mo->x - actor->x, players[i].mo->y - actor->y) > actor->radius) + if (FixedHypot(players[i].mo->x - actor->x, players[i].mo->y - actor->y) > actor->radius) continue; if (players[i].mo->z > actor->z + actor->height - 2*FRACUNIT @@ -7476,7 +7476,7 @@ void A_Boss2PogoSFX(mobj_t *actor) } // Boing! - if (P_AproxDistance(actor->x-actor->target->x, actor->y-actor->target->y) < FixedMul(256*FRACUNIT, actor->scale)) + if (FixedHypot(actor->x-actor->target->x, actor->y-actor->target->y) < FixedMul(256*FRACUNIT, actor->scale)) { actor->angle = R_PointToAngle2(actor->x, actor->y, actor->target->x, actor->target->y); P_InstaThrust(actor, actor->angle, FixedMul(actor->info->speed, actor->scale)); @@ -7509,7 +7509,7 @@ void A_Boss2PogoTarget(mobj_t *actor) return; if (!actor->target || !(actor->target->flags & MF_SHOOTABLE) || (actor->target->player && actor->target->player->powers[pw_flashing]) - || P_AproxDistance(actor->x-actor->target->x, actor->y-actor->target->y) >= FixedMul(512*FRACUNIT, actor->scale)) + || FixedHypot(actor->x-actor->target->x, actor->y-actor->target->y) >= FixedMul(512*FRACUNIT, actor->scale)) { // look for a new target if (P_LookForPlayers(actor, true, false, 512*FRACUNIT)) @@ -7530,7 +7530,7 @@ void A_Boss2PogoTarget(mobj_t *actor) P_InstaThrust(actor, actor->angle+ANGLE_180, FixedMul(FixedMul(actor->info->speed,(locvar2)), actor->scale)); // Move at wandering speed } // Try to land on top of the player. - else if (P_AproxDistance(actor->x-actor->target->x, actor->y-actor->target->y) < FixedMul(512*FRACUNIT, actor->scale)) + else if (FixedHypot(actor->x-actor->target->x, actor->y-actor->target->y) < FixedMul(512*FRACUNIT, actor->scale)) { fixed_t airtime, gravityadd, zoffs; @@ -7558,7 +7558,7 @@ void A_Boss2PogoTarget(mobj_t *actor) airtime = FixedDiv((-actor->momz - FixedSqrt(FixedMul(actor->momz,actor->momz)+zoffs)), gravityadd)<<1; // to try and land on their head rather than on their feet actor->angle = R_PointToAngle2(actor->x, actor->y, actor->target->x, actor->target->y); - P_InstaThrust(actor, actor->angle, FixedDiv(P_AproxDistance(actor->x - actor->target->x, actor->y - actor->target->y), airtime)); + P_InstaThrust(actor, actor->angle, FixedDiv(FixedHypot(actor->x - actor->target->x, actor->y - actor->target->y), airtime)); } // Wander semi-randomly towards the player to get closer. else @@ -7629,7 +7629,7 @@ void A_TurretFire(mobj_t *actor) while (P_SupermanLook4Players(actor) && count < MAXPLAYERS) { - if (P_AproxDistance(actor->x - actor->target->x, actor->y - actor->target->y) < dist) + if (FixedHypot(actor->x - actor->target->x, actor->y - actor->target->y) < dist) { actor->flags2 |= MF2_FIRING; actor->extravalue1 = locvar1; @@ -7667,7 +7667,7 @@ void A_SuperTurretFire(mobj_t *actor) while (P_SupermanLook4Players(actor) && count < MAXPLAYERS) { - if (P_AproxDistance(actor->x - actor->target->x, actor->y - actor->target->y) < dist) + if (FixedHypot(actor->x - actor->target->x, actor->y - actor->target->y) < dist) { actor->flags2 |= MF2_FIRING; actor->flags2 |= MF2_SUPERFIRE; @@ -7788,7 +7788,7 @@ void A_BuzzFly(mobj_t *actor) } // If the player is over 3072 fracunits away, then look for another player - if (P_AproxDistance(P_AproxDistance(actor->target->x - actor->x, actor->target->y - actor->y), + if (FixedHypot(FixedHypot(actor->target->x - actor->x, actor->target->y - actor->y), actor->target->z - actor->z) > FixedMul(3072*FRACUNIT, actor->scale)) { if (multiplayer || netgame) @@ -7807,7 +7807,7 @@ void A_BuzzFly(mobj_t *actor) else realspeed = FixedMul(actor->info->speed, actor->scale); - dist = P_AproxDistance(P_AproxDistance(actor->target->x - actor->x, + dist = FixedHypot(FixedHypot(actor->target->x - actor->x, actor->target->y - actor->y), actor->target->z - actor->z); if (dist < 1) @@ -8165,7 +8165,7 @@ void A_Boss3Path(mobj_t *actor) if (actor->target->x == actor->x && actor->target->y == actor->y) { - dist = P_AproxDistance(P_AproxDistance(actor->target->x - actor->x, actor->target->y - actor->y), actor->target->z + actor->movefactor - actor->z); + dist = FixedHypot(FixedHypot(actor->target->x - actor->x, actor->target->y - actor->y), actor->target->z + actor->movefactor - actor->z); if (dist < 1) dist = 1; @@ -9575,7 +9575,7 @@ void A_SetObjectTypeState(mobj_t *actor) if (mo2->type == (mobjtype_t)loc2lw) { - dist = P_AproxDistance(mo2->x - actor->x, mo2->y - actor->y); + dist = FixedHypot(mo2->x - actor->x, mo2->y - actor->y); if (mo2->health > 0) { @@ -10081,9 +10081,9 @@ void A_CheckRange(mobj_t *actor) return; if (!(locvar1 >> 16)) //target - dist = P_AproxDistance(actor->target->x - actor->x, actor->target->y - actor->y); + dist = FixedHypot(actor->target->x - actor->x, actor->target->y - actor->y); else //tracer - dist = P_AproxDistance(actor->tracer->x - actor->x, actor->tracer->y - actor->y); + dist = FixedHypot(actor->tracer->x - actor->x, actor->tracer->y - actor->y); if (dist <= FixedMul((locvar1 & 65535)*FRACUNIT, actor->scale)) P_SetMobjState(actor, locvar2); @@ -10145,16 +10145,16 @@ void A_CheckTrueRange(mobj_t *actor) if (!(locvar1 >> 16)) // target { height = actor->target->z - actor->z; - dist = P_AproxDistance(actor->target->x - actor->x, actor->target->y - actor->y); + dist = FixedHypot(actor->target->x - actor->x, actor->target->y - actor->y); } else // tracer { height = actor->tracer->z - actor->z; - dist = P_AproxDistance(actor->tracer->x - actor->x, actor->tracer->y - actor->y); + dist = FixedHypot(actor->tracer->x - actor->x, actor->tracer->y - actor->y); } - l = P_AproxDistance(dist, height); + l = FixedHypot(dist, height); if (l <= FixedMul((locvar1 & 65535)*FRACUNIT, actor->scale)) P_SetMobjState(actor, locvar2); @@ -10199,7 +10199,7 @@ void A_CheckThingCount(mobj_t *actor) if (mo2->type == (mobjtype_t)loc1up) { - dist = P_AproxDistance(mo2->x - actor->x, mo2->y - actor->y); + dist = FixedHypot(mo2->x - actor->x, mo2->y - actor->y); if (loc2up == 0) count++; @@ -10808,7 +10808,7 @@ void A_HomingChase(mobj_t *actor) actor->angle = R_PointToAngle2(actor->x, actor->y, dest->x, dest->y); - dist = P_AproxDistance(P_AproxDistance(dest->x - actor->x, dest->y - actor->y), dest->z - actor->z); + dist = FixedHypot(FixedHypot(dest->x - actor->x, dest->y - actor->y), dest->z - actor->z); if (dist < 1) dist = 1; @@ -11394,14 +11394,14 @@ void A_BrakLobShot(mobj_t *actor) g = gravity; // Look up distance between actor and its target - x = P_AproxDistance(actor->target->x - actor->x, actor->target->y - actor->y); + x = FixedHypot(actor->target->x - actor->x, actor->target->y - actor->y); if (!aimDirect) { // Distance should actually be a third of the way over x = FixedDiv(x, 3<<FRACBITS); newTargetX = actor->x + P_ReturnThrustX(actor, actor->angle, x); newTargetY = actor->y + P_ReturnThrustY(actor, actor->angle, x); - x = P_AproxDistance(newTargetX - actor->x, newTargetY - actor->y); + x = FixedHypot(newTargetX - actor->x, newTargetY - actor->y); // Look up height difference between actor and the ground 1/3 of the way to its target y = P_FloorzAtPos(newTargetX, newTargetY, actor->target->z, actor->target->height) - (actor->z + FixedMul(locvar2*FRACUNIT, actor->scale)); } @@ -11753,7 +11753,7 @@ void A_FlickyCenter(mobj_t *actor) P_LookForPlayers(actor, true, false, actor->extravalue1); - if (actor->target && P_AproxDistance(actor->target->x - originx, actor->target->y - originy) < actor->extravalue1) + if (actor->target && FixedHypot(actor->target->x - originx, actor->target->y - originy) < actor->extravalue1) { actor->extravalue2 = 1; P_TeleportMove(actor, actor->target->x, actor->target->y, actor->target->z); @@ -11809,7 +11809,7 @@ void A_FlickyAim(mobj_t *actor) if ((actor->momx == actor->momy && actor->momy == 0) || (actor->target && P_IsFlickyCenter(actor->target->type) && actor->target->extravalue1 && (actor->target->flags & MF_SLIDEME) - && P_AproxDistance(actor->x - actor->target->x, actor->y - actor->target->y) >= actor->target->extravalue1)) + && FixedHypot(actor->x - actor->target->x, actor->y - actor->target->y) >= actor->target->extravalue1)) flickyhitwall = true; P_InternalFlickyBubble(actor); @@ -11831,12 +11831,12 @@ void A_FlickyAim(mobj_t *actor) actor->movedir *= -1; posvar = ((R_PointToAngle2(actor->target->x, actor->target->y, actor->x, actor->y) + actor->movedir*locvar1) >> ANGLETOFINESHIFT) & FINEMASK; - chasevar = FixedSqrt(max(FRACUNIT, P_AproxDistance(actor->target->x - actor->x, actor->target->y - actor->y) - locvar2)) + locvar2; + chasevar = FixedSqrt(max(FRACUNIT, FixedHypot(actor->target->x - actor->x, actor->target->y - actor->y) - locvar2)) + locvar2; chasex = actor->target->x + FixedMul(FINECOSINE(posvar), chasevar); chasey = actor->target->y + FixedMul(FINESINE(posvar), chasevar); - if (P_AproxDistance(chasex - actor->x, chasey - actor->y)) + if (FixedHypot(chasex - actor->x, chasey - actor->y)) actor->angle = R_PointToAngle2(actor->x, actor->y, chasex, chasey); } else if (flickyhitwall) @@ -11878,7 +11878,7 @@ void P_InternalFlickyFly(mobj_t *actor, fixed_t flyspeed, fixed_t targetdist, fi targetdist = 16*FRACUNIT; //Default! if (actor->target && abs(chasez - actor->z) > targetdist) - targetdist = P_AproxDistance(actor->target->x - actor->x, actor->target->y - actor->y); + targetdist = FixedHypot(actor->target->x - actor->x, actor->target->y - actor->y); if (actor->target && P_IsFlickyCenter(actor->target->type) @@ -11956,7 +11956,7 @@ void A_FlickyCoast(mobj_t *actor) actor->momy = (11*actor->momy)/12; actor->momz = (11*actor->momz)/12; - if (P_AproxDistance(P_AproxDistance(actor->momx, actor->momy), actor->momz) < locvar1) + if (FixedHypot(FixedHypot(actor->momx, actor->momy), actor->momz) < locvar1) P_SetMobjState(actor, locvar2); return; @@ -12220,7 +12220,7 @@ void A_Boss5Jump(mobj_t *actor) g = gravity; // Look up distance between actor and its tracer - x = P_AproxDistance(actor->tracer->x - actor->x, actor->tracer->y - actor->y); + x = FixedHypot(actor->tracer->x - actor->x, actor->tracer->y - actor->y); // Look up height difference between actor and its tracer y = actor->tracer->z - actor->z; @@ -12341,7 +12341,7 @@ void A_MineExplode(mobj_t *actor) actor->z+P_RandomRange(((actor->eflags & MFE_UNDERWATER) ? -dist : 0), dist)*FRACUNIT, type); fixed_t dx = b->x - actor->x, dy = b->y - actor->y, dz = b->z - actor->z; - fixed_t dm = P_AproxDistance(dz, P_AproxDistance(dy, dx)); + fixed_t dm = FixedHypot(dz, FixedHypot(dy, dx)); b->momx = FixedDiv(dx, dm)*3; b->momy = FixedDiv(dy, dm)*3; b->momz = FixedDiv(dz, dm)*3; @@ -12373,7 +12373,7 @@ void A_MineRange(mobj_t *actor) if (!actor->target) return; - dm = P_AproxDistance(actor->z - actor->target->z, P_AproxDistance(actor->y - actor->target->y, actor->x - actor->target->x)); + dm = FixedHypot(actor->z - actor->target->z, FixedHypot(actor->y - actor->target->y, actor->x - actor->target->x)); if ((dm>>FRACBITS) < locvar1) P_SetMobjState(actor, actor->info->meleestate); } @@ -12499,7 +12499,7 @@ void A_MultiShotDist(mobj_t *actor) // Don't spawn dust unless a player is relatively close by (var1). for (i = 0; i < MAXPLAYERS; ++i) if (playeringame[i] && players[i].mo - && P_AproxDistance(actor->x - players[i].mo->x, actor->y - players[i].mo->y) < (1600<<FRACBITS)) + && FixedHypot(actor->x - players[i].mo->x, actor->y - players[i].mo->y) < (1600<<FRACBITS)) break; // Stop looking. if (i == MAXPLAYERS) return; // don't make bubble! @@ -12669,8 +12669,8 @@ void A_Boss5FindWaypoint(mobj_t *actor) // If this one's further then the last one, don't go for it. if (actor->tracer && - P_AproxDistance(P_AproxDistance(actor->x - mo2->x, actor->y - mo2->y), actor->z - mo2->z) > - P_AproxDistance(P_AproxDistance(actor->x - actor->tracer->x, actor->y - actor->tracer->y), actor->z - actor->tracer->z)) + FixedHypot(FixedHypot(actor->x - mo2->x, actor->y - mo2->y), actor->z - mo2->z) > + FixedHypot(FixedHypot(actor->x - actor->tracer->x, actor->y - actor->tracer->y), actor->z - actor->tracer->z)) continue; // Otherwise... Do! @@ -13047,7 +13047,7 @@ void A_Boss5CheckOnGround(mobj_t *actor) P_SetMobjState(actor, locvar1); } - if (actor->tracer && P_AproxDistance(actor->tracer->x - actor->x, actor->tracer->y - actor->y) < 2*actor->radius) + if (actor->tracer && FixedHypot(actor->tracer->x - actor->x, actor->tracer->y - actor->y) < 2*actor->radius) { actor->momx = (4*actor->momx)/5; actor->momy = (4*actor->momy)/5; @@ -13507,7 +13507,7 @@ static boolean PIT_TNTExplode(mobj_t *nearby) dx = nearby->x - barrel->x; dy = nearby->y - barrel->y; dz = nearby->z - barrel->z + (nearby->height - barrel->height/2)/2; - dm = P_AproxDistance(P_AproxDistance(dx, dy), dz); + dm = FixedHypot(FixedHypot(dx, dy), dz); if (dm >= exploderadius || !P_CheckSight(barrel, nearby)) // out of range or not visible return true; @@ -13910,7 +13910,7 @@ void A_SnapperThinker(mobj_t *actor) // Look for nearby, valid players to chase angrily at. if ((actor->target || P_LookForPlayers(actor, true, false, 1024*FRACUNIT)) - && P_AproxDistance(actor->target->x - xs, actor->target->y - ys) < 2048*FRACUNIT + && FixedHypot(actor->target->x - xs, actor->target->y - ys) < 2048*FRACUNIT && abs(actor->target->z - actor->z) < 80*FRACUNIT && P_CheckSight(actor, actor->target)) { @@ -13925,7 +13925,7 @@ void A_SnapperThinker(mobj_t *actor) y1 = ys; } - dist = P_AproxDistance(x1 - x0, y1 - y0); + dist = FixedHypot(x1 - x0, y1 - y0); // The snapper either chases what it considers to be a nearby player, or instead decides to go back to its spawnpoint. if (chasing || dist > 32*FRACUNIT) @@ -14110,7 +14110,7 @@ void A_LavafallRocks(mobj_t *actor) // Don't spawn rocks unless a player is relatively close by. for (i = 0; i < MAXPLAYERS; ++i) if (playeringame[i] && players[i].mo - && P_AproxDistance(actor->x - players[i].mo->x, actor->y - players[i].mo->y) < (actor->info->speed >> 1)) + && FixedHypot(actor->x - players[i].mo->x, actor->y - players[i].mo->y) < (actor->info->speed >> 1)) break; // Stop looking. if (i < MAXPLAYERS) @@ -14144,7 +14144,7 @@ void A_LavafallLava(mobj_t *actor) // Don't spawn lava unless a player is nearby. for (i = 0; i < MAXPLAYERS; ++i) if (playeringame[i] && players[i].mo - && P_AproxDistance(actor->x - players[i].mo->x, actor->y - players[i].mo->y) < (actor->info->speed)) + && FixedHypot(actor->x - players[i].mo->x, actor->y - players[i].mo->y) < (actor->info->speed)) break; // Stop looking. if (i >= MAXPLAYERS) @@ -14274,7 +14274,7 @@ void A_RolloutSpawn(mobj_t *actor) if (!(actor->target) || P_MobjWasRemoved(actor->target) - || P_AproxDistance(actor->x - actor->target->x, actor->y - actor->target->y) > locvar1) + || FixedHypot(actor->x - actor->target->x, actor->y - actor->target->y) > locvar1) { actor->target = P_SpawnMobj(actor->x, actor->y, actor->z, locvar2); actor->target->flags2 |= (actor->flags2 & (MF2_AMBUSH | MF2_OBJECTFLIP)) | MF2_SLIDEPUSH; @@ -14302,7 +14302,7 @@ void A_RolloutRock(mobj_t *actor) UINT8 maxframes = actor->info->reactiontime; // number of frames the mobj cycles through fixed_t pi = (22*FRACUNIT/7); fixed_t circumference = FixedMul(2 * pi, actor->radius); // used to calculate when to change frame - fixed_t speed = P_AproxDistance(actor->momx, actor->momy), topspeed = FixedMul(actor->info->speed, actor->scale); + fixed_t speed = FixedHypot(actor->momx, actor->momy), topspeed = FixedMul(actor->info->speed, actor->scale); boolean inwater = actor->eflags & (MFE_TOUCHWATER|MFE_UNDERWATER); if (LUA_CallAction(A_ROLLOUTROCK, actor)) @@ -14344,7 +14344,7 @@ void A_RolloutRock(mobj_t *actor) actor->momy = FixedMul(actor->momy, locvar1); } - speed = P_AproxDistance(actor->momx, actor->momy); // recalculate speed for visual rolling + speed = FixedHypot(actor->momx, actor->momy); // recalculate speed for visual rolling if (speed < actor->scale >> 1) // stop moving if speed is insignificant { @@ -14466,7 +14466,7 @@ void A_DragonSegment(mobj_t *actor) return; } - dist = P_AproxDistance(P_AproxDistance(actor->x - target->x, actor->y - target->y), actor->z - target->z); + dist = FixedHypot(FixedHypot(actor->x - target->x, actor->y - target->y), actor->z - target->z); radius = actor->radius + target->radius; hangle = R_PointToAngle2(target->x, target->y, actor->x, actor->y); zangle = R_PointToAngle2(0, target->z, dist, actor->z); diff --git a/src/p_floor.c b/src/p_floor.c index 7c26065b5..de8f5d4e8 100644 --- a/src/p_floor.c +++ b/src/p_floor.c @@ -1164,7 +1164,7 @@ void T_ThwompSector(thwomp_t *thwomp) if (players[i].mo->z > thwomp->sector->ceilingheight) continue; - if (P_AproxDistance(thwompx - players[i].mo->x, thwompy - players[i].mo->y) > 96*FRACUNIT) + if (FixedHypot(thwompx - players[i].mo->x, thwompy - players[i].mo->y) > 96*FRACUNIT) continue; thwomp->direction = -1; @@ -1892,7 +1892,7 @@ void EV_DoFloor(line_t *line, floor_e floortype) // Linedef executor command, linetype 106. // Line length = speed, front sector floor = destination height. case moveFloorByFrontSector: - dofloor->speed = P_AproxDistance(line->dx, line->dy); + dofloor->speed = FixedHypot(line->dx, line->dy); dofloor->speed = FixedDiv(dofloor->speed,8*FRACUNIT); dofloor->floordestheight = line->frontsector->floorheight; @@ -1958,7 +1958,7 @@ void EV_DoFloor(line_t *line, floor_e floortype) // Linetypes 2/3. // Move floor up and down indefinitely like the old elevators. case bounceFloor: - dofloor->speed = P_AproxDistance(line->dx, line->dy); // same speed as elevateContinuous + dofloor->speed = FixedHypot(line->dx, line->dy); // same speed as elevateContinuous dofloor->speed = FixedDiv(dofloor->speed,4*FRACUNIT); dofloor->origspeed = dofloor->speed; // it gets slowed down at the top and bottom dofloor->floordestheight = line->frontsector->floorheight; @@ -2104,7 +2104,7 @@ void EV_DoElevator(line_t *line, elevator_e elevtype, boolean customspeed) case elevateContinuous: if (customspeed) { - elevator->origspeed = P_AproxDistance(line->dx, line->dy); + elevator->origspeed = FixedHypot(line->dx, line->dy); elevator->origspeed = FixedDiv(elevator->origspeed,4*FRACUNIT); elevator->speed = elevator->origspeed; } @@ -2266,7 +2266,7 @@ void EV_CrumbleChain(sector_t *sec, ffloor_t *rover) if (flags & ML_EFFECT1) { - P_InstaThrust(spawned, R_PointToAngle2(sec->soundorg.x, sec->soundorg.y, a, b), FixedDiv(P_AproxDistance(a - sec->soundorg.x, b - sec->soundorg.y), widthfactor)); + P_InstaThrust(spawned, R_PointToAngle2(sec->soundorg.x, sec->soundorg.y, a, b), FixedDiv(FixedHypot(a - sec->soundorg.x, b - sec->soundorg.y), widthfactor)); P_SetObjectMomZ(spawned, FixedDiv((c - bottomz), heightfactor), false); } diff --git a/src/p_inter.c b/src/p_inter.c index e9a16a3dd..be4133af5 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -1002,7 +1002,7 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck) x = (x/count)<<FRACBITS; y = (y/count)<<FRACBITS; z = (z/count)<<FRACBITS; - gatherradius = P_AproxDistance(P_AproxDistance(special->x - x, special->y - y), special->z - z); + gatherradius = FixedHypot(FixedHypot(special->x - x, special->y - y), special->z - z); P_RemoveMobj(special); if (player->powers[pw_nights_superloop]) @@ -1028,7 +1028,7 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck) mo2 = (mobj_t *)th; - if (P_AproxDistance(P_AproxDistance(mo2->x - x, mo2->y - y), mo2->z - z) > gatherradius) + if (FixedHypot(FixedHypot(mo2->x - x, mo2->y - y), mo2->z - z) > gatherradius) continue; if (mo2->flags & MF_SHOOTABLE) @@ -1450,8 +1450,8 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck) fixed_t touchx, touchy, touchspeed; angle_t angle; - if (P_AproxDistance(toucher->x-special->x, toucher->y-special->y) > - P_AproxDistance((toucher->x-toucher->momx)-special->x, (toucher->y-toucher->momy)-special->y)) + if (FixedHypot(toucher->x-special->x, toucher->y-special->y) > + FixedHypot((toucher->x-toucher->momx)-special->x, (toucher->y-toucher->momy)-special->y)) { touchx = toucher->x + toucher->momx; touchy = toucher->y + toucher->momy; @@ -1463,7 +1463,7 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck) } angle = R_PointToAngle2(special->x, special->y, touchx, touchy); - touchspeed = P_AproxDistance(toucher->momx, toucher->momy); + touchspeed = FixedHypot(toucher->momx, toucher->momy); toucher->momx = P_ReturnThrustX(special, angle, touchspeed); toucher->momy = P_ReturnThrustY(special, angle, touchspeed); @@ -1509,7 +1509,7 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck) case MT_EGGSHIELD: { angle_t angle = R_PointToAngle2(special->x, special->y, toucher->x, toucher->y) - special->angle; - fixed_t touchspeed = P_AproxDistance(toucher->momx, toucher->momy); + fixed_t touchspeed = FixedHypot(toucher->momx, toucher->momy); if (touchspeed < special->scale) touchspeed = special->scale; @@ -1590,7 +1590,7 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck) { special->momx = toucher->momx; special->momy = toucher->momy; - special->momz = P_AproxDistance(toucher->momx, toucher->momy)/4; + special->momz = FixedHypot(toucher->momx, toucher->momy)/4; if (toucher->momz > 0) special->momz += toucher->momz/8; @@ -1762,7 +1762,7 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck) toucher->momx = toucher->tracer->momx/2; toucher->momy = toucher->tracer->momy/2; - toucher->momz = toucher->tracer->momz + P_AproxDistance(toucher->tracer->momx, toucher->tracer->momy)/2; + toucher->momz = toucher->tracer->momz + FixedHypot(toucher->tracer->momx, toucher->tracer->momy)/2; P_ResetPlayer(player); player->pflags &= ~PF_APPLYAUTOBRAKE; P_SetPlayerMobjState(toucher, S_PLAY_FALL); @@ -2666,7 +2666,7 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damaget case MT_BUGGLE: if (inflictor && inflictor->player // did a player kill you? Spawn relative to the player so they're bound to get it - && P_AproxDistance(inflictor->x - target->x, inflictor->y - target->y) <= inflictor->radius + target->radius + FixedMul(8*FRACUNIT, inflictor->scale) // close enough? + && FixedHypot(inflictor->x - target->x, inflictor->y - target->y) <= inflictor->radius + target->radius + FixedMul(8*FRACUNIT, inflictor->scale) // close enough? && inflictor->z <= target->z + target->height + FixedMul(8*FRACUNIT, inflictor->scale) && inflictor->z + inflictor->height >= target->z - FixedMul(8*FRACUNIT, inflictor->scale)) mo = P_SpawnMobj(inflictor->x + inflictor->momx, inflictor->y + inflictor->momy, inflictor->z + (inflictor->height / 2) + inflictor->momz, MT_EXTRALARGEBUBBLE); @@ -3305,7 +3305,7 @@ static void P_SuperDamage(player_t *player, mobj_t *inflictor, mobj_t *source, I // to recover if (inflictor->flags2 & MF2_SCATTER && source) { - fixed_t dist = P_AproxDistance(P_AproxDistance(source->x-player->mo->x, source->y-player->mo->y), source->z-player->mo->z); + fixed_t dist = FixedHypot(FixedHypot(source->x-player->mo->x, source->y-player->mo->y), source->z-player->mo->z); dist = FixedMul(128*FRACUNIT, inflictor->scale) - dist/4; diff --git a/src/p_map.c b/src/p_map.c index b934e3255..63fdebbbd 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -776,7 +776,7 @@ static boolean PIT_CheckThing(mobj_t *thing) if (thing->flags & MF_SOLID) S_StartSound(tmthing, thing->info->deathsound); for (iter = thing->subsector->sector->thinglist; iter; iter = iter->snext) - if (iter->type == thing->type && iter->health > 0 && iter->flags & MF_SOLID && (iter == thing || P_AproxDistance(P_AproxDistance(thing->x - iter->x, thing->y - iter->y), thing->z - iter->z) < 56*thing->scale))//FixedMul(56*FRACUNIT, thing->scale)) + if (iter->type == thing->type && iter->health > 0 && iter->flags & MF_SOLID && (iter == thing || FixedHypot(FixedHypot(thing->x - iter->x, thing->y - iter->y), thing->z - iter->z) < 56*thing->scale))//FixedMul(56*FRACUNIT, thing->scale)) P_KillMobj(iter, tmthing, tmthing, 0); } else @@ -815,7 +815,7 @@ static boolean PIT_CheckThing(mobj_t *thing) if (thing->flags & MF_SOLID) S_StartSound(tmthing, thing->info->deathsound); for (iter = thing->subsector->sector->thinglist; iter; iter = iter->snext) - if (iter->type == thing->type && iter->health > 0 && iter->flags & MF_SOLID && (iter == thing || P_AproxDistance(P_AproxDistance(thing->x - iter->x, thing->y - iter->y), thing->z - iter->z) < 56*thing->scale))//FixedMul(56*FRACUNIT, thing->scale)) + if (iter->type == thing->type && iter->health > 0 && iter->flags & MF_SOLID && (iter == thing || FixedHypot(FixedHypot(thing->x - iter->x, thing->y - iter->y), thing->z - iter->z) < 56*thing->scale))//FixedMul(56*FRACUNIT, thing->scale)) P_KillMobj(iter, tmthing, tmthing, 0); return true; } @@ -3061,7 +3061,7 @@ static void P_HitCameraSlideLine(line_t *ld, camera_t *thiscam) lineangle >>= ANGLETOFINESHIFT; deltaangle >>= ANGLETOFINESHIFT; - movelen = P_AproxDistance(tmxmove, tmymove); + movelen = FixedHypot(tmxmove, tmymove); newlen = FixedMul(movelen, FINECOSINE(deltaangle)); tmxmove = FixedMul(newlen, FINECOSINE(lineangle)); @@ -3147,7 +3147,7 @@ static void P_HitBounceLine(line_t *ld) lineangle >>= ANGLETOFINESHIFT; deltaangle >>= ANGLETOFINESHIFT; - movelen = P_AproxDistance(tmxmove, tmymove); + movelen = FixedHypot(tmxmove, tmymove); tmxmove = FixedMul(movelen, FINECOSINE(deltaangle)); tmymove = FixedMul(movelen, FINESINE(deltaangle)); @@ -4074,7 +4074,7 @@ static boolean PIT_RadiusAttack(mobj_t *thing) dy = abs(thing->y - bombspot->y); dz = abs(thing->z + (thing->height>>1) - bombspot->z); - dist = P_AproxDistance(P_AproxDistance(dx, dy), dz); + dist = FixedHypot(FixedHypot(dx, dy), dz); dist -= thing->radius; if (dist < 0) diff --git a/src/p_maputl.h b/src/p_maputl.h index df90ab4b4..9bc00fa17 100644 --- a/src/p_maputl.h +++ b/src/p_maputl.h @@ -41,7 +41,6 @@ typedef boolean (*traverser_t)(intercept_t *in); boolean P_PathTraverse(fixed_t px1, fixed_t py1, fixed_t px2, fixed_t py2, INT32 pflags, traverser_t ptrav); -#define P_AproxDistance(dx, dy) FixedHypot(dx, dy) void P_ClosestPointOnLine(fixed_t x, fixed_t y, line_t *line, vertex_t *result); void P_ClosestPointOnLine3D(const vector3_t *p, const vector3_t *line, vector3_t *result); INT32 P_PointOnLineSide(fixed_t x, fixed_t y, line_t *line); diff --git a/src/p_mobj.c b/src/p_mobj.c index a1edcfe77..c539db6d2 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -1736,7 +1736,7 @@ static void P_PushableCheckBustables(mobj_t *mo) // Run a linedef executor?? if (rover->master->flags & ML_EFFECT5) - P_LinedefExecute((INT16)(P_AproxDistance(rover->master->dx, rover->master->dy)>>FRACBITS), mo, node->m_sector); + P_LinedefExecute((INT16)(FixedHypot(rover->master->dx, rover->master->dy)>>FRACBITS), mo, node->m_sector); goto bustupdone; } @@ -2512,7 +2512,7 @@ boolean P_ZMovement(mobj_t *mo) // float down towards target if too close if (!(mo->flags2 & MF2_SKULLFLY) && !(mo->flags2 & MF2_INFLOAT)) { - dist = P_AproxDistance(mo->x - mo->target->x, mo->y - mo->target->y); + dist = FixedHypot(mo->x - mo->target->x, mo->y - mo->target->y); delta = (mo->target->z + (mo->height>>1)) - mo->z; @@ -3662,11 +3662,11 @@ boolean P_CameraThinker(player_t *player, camera_t *thiscam, boolean resetcalled P_ResetCamera(player, thiscam); else { - fixed_t camspeed = P_AproxDistance(thiscam->momx, thiscam->momy); + fixed_t camspeed = FixedHypot(thiscam->momx, thiscam->momy); P_SlideCameraMove(thiscam); - if (!resetcalled && P_AproxDistance(thiscam->momx, thiscam->momy) == camspeed) + if (!resetcalled && FixedHypot(thiscam->momx, thiscam->momy) == camspeed) { P_ResetCamera(player, thiscam); resetcalled = true; @@ -4149,7 +4149,7 @@ boolean P_BossTargetPlayer(mobj_t *actor, boolean closest) if (closest) { - dist = P_AproxDistance(actor->x - player->mo->x, actor->y - player->mo->y); + dist = FixedHypot(actor->x - player->mo->x, actor->y - player->mo->y); if (!lastdist || dist < lastdist) { lastdist = dist+1; @@ -4518,7 +4518,7 @@ static void P_Boss3Thinker(mobj_t *mobj) if (mobj->tracer->x == mobj->x && mobj->tracer->y == mobj->y) { // apply ambush for old routing, otherwise whack a mole only - dist = P_AproxDistance(P_AproxDistance(mobj->tracer->x - mobj->x, mobj->tracer->y - mobj->y), mobj->tracer->z + mobj->movefactor - mobj->z); + dist = FixedHypot(FixedHypot(mobj->tracer->x - mobj->x, mobj->tracer->y - mobj->y), mobj->tracer->z + mobj->movefactor - mobj->z); if (dist < 1) dist = 1; @@ -5042,7 +5042,7 @@ static void P_Boss5Thinker(mobj_t *mobj) } if (mobj->state == &states[mobj->info->xdeathstate]) mobj->momz -= (2*FRACUNIT)/3; - else if (mobj->tracer && P_AproxDistance(mobj->tracer->x - mobj->x, mobj->tracer->y - mobj->y) < 2*mobj->radius) + else if (mobj->tracer && FixedHypot(mobj->tracer->x - mobj->x, mobj->tracer->y - mobj->y) < 2*mobj->radius) mobj->flags &= ~MF_NOCLIP; } else @@ -5168,7 +5168,7 @@ static void P_Boss7Thinker(mobj_t *mobj) if (players[i].mo->health <= 0) continue; - if (P_AproxDistance(players[i].mo->x - mobj->x, players[i].mo->y - mobj->y) > (mobj->radius + players[i].mo->radius)) + if (FixedHypot(players[i].mo->x - mobj->x, players[i].mo->y - mobj->y) > (mobj->radius + players[i].mo->radius)) continue; if (players[i].mo->z > mobj->z + mobj->height - FRACUNIT @@ -5272,7 +5272,7 @@ static void P_Boss7Thinker(mobj_t *mobj) if (mobj->health <= mobj->info->damage && !(mo2->spawnpoint->options & 7)) continue; // don't jump to center - dist = P_AproxDistance(players[i].mo->x - mo2->x, players[i].mo->y - mo2->y); + dist = FixedHypot(players[i].mo->x - mo2->x, players[i].mo->y - mo2->y); if (!(closestNum == -1 || dist < closestdist)) continue; @@ -5345,7 +5345,7 @@ static void P_Boss7Thinker(mobj_t *mobj) an = mobj->angle; an >>= ANGLETOFINESHIFT; - dist = P_AproxDistance(hitspot->x - mobj->x, hitspot->y - mobj->y); + dist = FixedHypot(hitspot->x - mobj->x, hitspot->y - mobj->y); horizontal = dist / airtime; vertical = (gravity*airtime)/2; @@ -5396,7 +5396,7 @@ static void P_Boss7Thinker(mobj_t *mobj) if (players[i].mo->health <= 0) continue; - if (P_AproxDistance(players[i].mo->x - mobj->x, players[i].mo->y - mobj->y) > mobj->radius*4) + if (FixedHypot(players[i].mo->x - mobj->x, players[i].mo->y - mobj->y) > mobj->radius*4) continue; if (players[i].mo->z > mobj->z + 128*FRACUNIT) @@ -5650,14 +5650,14 @@ static void P_Boss9Thinker(mobj_t *mobj) // Spawn energy particles for (spawner = mobj->hnext; spawner; spawner = spawner->hnext) { - dist = P_AproxDistance(spawner->x - mobj->x, spawner->y - mobj->y); + dist = FixedHypot(spawner->x - mobj->x, spawner->y - mobj->y); if (P_RandomRange(1,(dist>>FRACBITS)/16) == 1) break; } if (spawner && dist) { mobj_t *missile = P_SpawnMissile(spawner, mobj, MT_MSGATHER); - missile->fuse = (dist/P_AproxDistance(missile->momx, missile->momy)); + missile->fuse = (dist/FixedHypot(missile->momx, missile->momy)); if (missile->fuse > mobj->fuse) P_RemoveMobj(missile); @@ -6089,7 +6089,7 @@ nodanger: mobj->flags2 |= MF2_INVERTAIMABLE; // Move normally: Approach the player using normal thrust and simulated friction. - dist = P_AproxDistance(mobj->x-mobj->target->x, mobj->y-mobj->target->y); + dist = FixedHypot(mobj->x-mobj->target->x, mobj->y-mobj->target->y); P_Thrust(mobj, R_PointToAngle2(0, 0, mobj->momx, mobj->momy), -3*FRACUNIT/8); if (dist < 64*FRACUNIT && !(mobj->target->player && mobj->target->player->homing)) P_Thrust(mobj, mobj->angle, -4*FRACUNIT); @@ -6097,7 +6097,7 @@ nodanger: P_Thrust(mobj, mobj->angle, FRACUNIT); else P_Thrust(mobj, mobj->angle + ANGLE_90, FINECOSINE((((angle_t)(leveltime*ANG1))>>ANGLETOFINESHIFT) & FINEMASK)>>1); - mobj->momz += P_AproxDistance(mobj->momx, mobj->momy)/12; // Move up higher the faster you're going. + mobj->momz += FixedHypot(mobj->momx, mobj->momy)/12; // Move up higher the faster you're going. } } } @@ -6303,7 +6303,7 @@ void P_SpawnParaloop(fixed_t x, fixed_t y, fixed_t z, fixed_t radius, INT32 numb mobj->angle = R_PointToAngle2(mobj->x, mobj->y, x, y); // change slope - dist = P_AproxDistance(P_AproxDistance(x - mobj->x, y - mobj->y), z - mobj->z); + dist = FixedHypot(FixedHypot(x - mobj->x, y - mobj->y), z - mobj->z); if (dist < 1) dist = 1; @@ -6377,7 +6377,7 @@ void P_Attract(mobj_t *source, mobj_t *dest, boolean nightsgrab) // Home in on y fixed_t tx = dest->x; fixed_t ty = dest->y; fixed_t tz = dest->z + (dest->height/2); // Aim for center - fixed_t xydist = P_AproxDistance(tx - source->x, ty - source->y); + fixed_t xydist = FixedHypot(tx - source->x, ty - source->y); if (!dest || dest->health <= 0 || !dest->player || !source->tracer) return; @@ -6386,7 +6386,7 @@ void P_Attract(mobj_t *source, mobj_t *dest, boolean nightsgrab) // Home in on y source->angle = R_PointToAngle2(source->x, source->y, tx, ty); // change slope - dist = P_AproxDistance(xydist, tz - source->z); + dist = FixedHypot(xydist, tz - source->z); if (dist < 1) dist = 1; @@ -6412,9 +6412,9 @@ void P_Attract(mobj_t *source, mobj_t *dest, boolean nightsgrab) // Home in on y else { if (nightsgrab) - speedmul = P_AproxDistance(dest->momx, dest->momy) + FixedMul(8*FRACUNIT, source->scale); + speedmul = FixedHypot(dest->momx, dest->momy) + FixedMul(8*FRACUNIT, source->scale); else - speedmul = P_AproxDistance(dest->momx, dest->momy) + FixedMul(source->info->speed, source->scale); + speedmul = FixedHypot(dest->momx, dest->momy) + FixedMul(source->info->speed, source->scale); source->momx = FixedMul(FixedDiv(tx - source->x, dist), speedmul); source->momy = FixedMul(FixedDiv(ty - source->y, dist), speedmul); @@ -6422,7 +6422,7 @@ void P_Attract(mobj_t *source, mobj_t *dest, boolean nightsgrab) // Home in on y } // Instead of just unsetting NOCLIP like an idiot, let's check the distance to our target. - ndist = P_AproxDistance(P_AproxDistance(tx - (source->x+source->momx), + ndist = FixedHypot(FixedHypot(tx - (source->x+source->momx), ty - (source->y+source->momy)), tz - (source->z+source->momz)); @@ -7073,7 +7073,7 @@ static void P_MaceSceneryThink(mobj_t *mobj) // The below is selected based on CEZ2's first room. I promise you it is a coincidence that it looks like the weed number. for (i = 0; i < MAXPLAYERS; ++i) if (playeringame[i] && players[i].mo - && P_AproxDistance(P_AproxDistance(mobj->x - players[i].mo->x, mobj->y - players[i].mo->y), mobj->z - players[i].mo->z) < (4200 << FRACBITS)) + && FixedHypot(FixedHypot(mobj->x - players[i].mo->x, mobj->y - players[i].mo->y), mobj->z - players[i].mo->z) < (4200 << FRACBITS)) break; // Stop looking. if (i == MAXPLAYERS) { @@ -8049,7 +8049,7 @@ static boolean P_MobjBossThink(mobj_t *mobj) { if (mobj->target) { - mobj->momz = FixedMul(FixedDiv(mobj->target->z - mobj->z, P_AproxDistance(mobj->x - mobj->target->x, mobj->y - mobj->target->y)), mobj->scale << 1); + mobj->momz = FixedMul(FixedDiv(mobj->target->z - mobj->z, FixedHypot(mobj->x - mobj->target->x, mobj->y - mobj->target->y)), mobj->scale << 1); mobj->angle = R_PointToAngle2(mobj->x, mobj->y, mobj->target->x, mobj->target->y); } else @@ -8293,7 +8293,7 @@ static void P_ArrowThink(mobj_t *mobj) 0------dist(momx,momy) */ - fixed_t dist = P_AproxDistance(mobj->momx, mobj->momy); + fixed_t dist = FixedHypot(mobj->momx, mobj->momy); angle_t angle = R_PointToAngle2(0, 0, dist, mobj->momz); if (angle > ANG20 && angle <= ANGLE_180) @@ -8575,7 +8575,7 @@ static boolean P_EggRobo1Think(mobj_t *mobj) continue; if (players[i].mo->z + players[i].mo->height < mobj->z - 8*mobj->scale) continue; - compdist = P_AproxDistance( + compdist = FixedHypot( players[i].mo->x + players[i].mo->momx - basex, players[i].mo->y + players[i].mo->momy - basey); if (compdist >= dist) @@ -8590,7 +8590,7 @@ static boolean P_EggRobo1Think(mobj_t *mobj) mobj->frame = 3 + ((leveltime & 2) >> 1); mobj->angle = R_PointToAngle2(mobj->x, mobj->y, mobj->target->x, mobj->target->y); - if (P_AproxDistance( + if (FixedHypot( mobj->x - basex, mobj->y - basey) < mobj->scale) @@ -8621,7 +8621,7 @@ static boolean P_EggRobo1Think(mobj_t *mobj) if (!didmove) { - if (P_AproxDistance(mobj->x - basex, mobj->y - basey) < mobj->scale) + if (FixedHypot(mobj->x - basex, mobj->y - basey) < mobj->scale) P_TeleportMove(mobj, basex, basey, mobj->z); else P_TeleportMove(mobj, @@ -9011,7 +9011,7 @@ static void P_PyreFlyThink(mobj_t *mobj) { //Aim for player z position. If too close to floor/ceiling, aim just above/below them. fixed_t destz = min(max(mobj->target->z, mobj->target->floorz + 70*FRACUNIT), mobj->target->ceilingz - 80*FRACUNIT - mobj->height); - fixed_t dist = P_AproxDistance(hdist, destz - mobj->z); + fixed_t dist = FixedHypot(hdist, destz - mobj->z); P_InstaThrust(mobj, R_PointToAngle2(mobj->x, mobj->y, mobj->target->x, mobj->target->y), 2*FRACUNIT); mobj->momz = FixedMul(FixedDiv(destz - mobj->z, dist), 2*FRACUNIT); } @@ -9113,7 +9113,7 @@ static void P_PterabyteThink(mobj_t *mobj) var1 = 2*mobj->info->speed; var2 = 1; A_HomingChase(mobj); - if (P_AproxDistance(mobj->x - mobj->tracer->x, mobj->y - mobj->tracer->y) <= mobj->info->speed) + if (FixedHypot(mobj->x - mobj->tracer->x, mobj->y - mobj->tracer->y) <= mobj->info->speed) { mobj->extravalue1 -= 2; mobj->momx = mobj->momy = mobj->momz = 0; @@ -9138,7 +9138,7 @@ static void P_DragonbomberThink(mobj_t *mobj) { mobj_t *mine = P_SpawnMobjFromMobj(segment, 0, 0, 0, segment->info->painchance); mine->angle = segment->angle; - P_InstaThrust(mine, mobj->angle, P_AproxDistance(mobj->momx, mobj->momy) >> 1); + P_InstaThrust(mine, mobj->angle, FixedHypot(mobj->momx, mobj->momy) >> 1); P_SetObjectMomZ(mine, -2*FRACUNIT, true); S_StartSound(mine, mine->info->seesound); P_SetMobjState(segment, segment->info->raisestate); @@ -9148,7 +9148,7 @@ static void P_DragonbomberThink(mobj_t *mobj) } if (mobj->target) // Are we chasing a player? { - fixed_t dist = P_AproxDistance(mobj->x - mobj->target->x, mobj->y - mobj->target->y); + fixed_t dist = FixedHypot(mobj->x - mobj->target->x, mobj->y - mobj->target->y); if (dist > 2000*mobj->scale) // Not anymore! P_SetTarget(&mobj->target, NULL); else @@ -9256,7 +9256,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj) mobj->eflags |= MFE_UNDERWATER; //P_MobjCheckWater(mobj); // solely for MFE_UNDERWATER for A_FlickySpawn { if (mobj->tracer && mobj->tracer->player && mobj->tracer->health > 0 - && P_AproxDistance(P_AproxDistance(mobj->tracer->x - mobj->x, mobj->tracer->y - mobj->y), mobj->tracer->z - mobj->z) <= mobj->radius*16) + && FixedHypot(FixedHypot(mobj->tracer->x - mobj->x, mobj->tracer->y - mobj->y), mobj->tracer->z - mobj->z) <= mobj->radius*16) { var1 = mobj->info->speed; var2 = 1; @@ -9391,7 +9391,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj) if (playeringame[i] && players[i].mo && players[i].mare == mobj->threshold && players[i].spheres > 0) { - fixed_t dist = P_AproxDistance(players[i].mo->x - mobj->x, players[i].mo->y - mobj->y); + fixed_t dist = FixedHypot(players[i].mo->x - mobj->x, players[i].mo->y - mobj->y); if (dist < shortest) { P_SetTarget(&mobj->target, players[i].mo); @@ -9422,7 +9422,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj) P_KoopaThinker(mobj); break; case MT_FIREBALL: - if (P_AproxDistance(mobj->momx, mobj->momy) <= 16*FRACUNIT) // Once fireballs lose enough speed, kill them + if (FixedHypot(mobj->momx, mobj->momy) <= 16*FRACUNIT) // Once fireballs lose enough speed, kill them { P_KillMobj(mobj, NULL, NULL, 0); return false; @@ -13530,7 +13530,7 @@ mobj_t *P_SpawnXYZMissile(mobj_t *source, mobj_t *dest, mobjtype_t type, th->momx = FixedMul(speed, FINECOSINE(an)); th->momy = FixedMul(speed, FINESINE(an)); - dist = P_AproxDistance(dest->x - x, dest->y - y); + dist = FixedHypot(dest->x - x, dest->y - y); dist = dist / speed; if (dist < 1) @@ -13592,7 +13592,7 @@ mobj_t *P_SpawnAlteredDirectionMissile(mobj_t *source, mobjtype_t type, fixed_t th->momx = FixedMul(speed, FINECOSINE(an)); th->momy = FixedMul(speed, FINESINE(an)); - dist = P_AproxDistance(source->momx*800, source->momy*800); + dist = FixedHypot(source->momx*800, source->momy*800); dist = dist / speed; if (dist < 1) @@ -13657,7 +13657,7 @@ mobj_t *P_SpawnPointMissile(mobj_t *source, fixed_t xa, fixed_t ya, fixed_t za, th->momx = FixedMul(speed, FINECOSINE(an)); th->momy = FixedMul(speed, FINESINE(an)); - dist = P_AproxDistance(xa - x, ya - y); + dist = FixedHypot(xa - x, ya - y); dist = dist / speed; if (dist < 1) @@ -13737,9 +13737,9 @@ mobj_t *P_SpawnMissile(mobj_t *source, mobj_t *dest, mobjtype_t type) th->momy = FixedMul(speed, FINESINE(an)); if (type == MT_TURRETLASER || type == MT_ENERGYBALL) // More accurate! - dist = P_AproxDistance(dest->x+(dest->momx*gsf) - source->x, dest->y+(dest->momy*gsf) - source->y); + dist = FixedHypot(dest->x+(dest->momx*gsf) - source->x, dest->y+(dest->momy*gsf) - source->y); else - dist = P_AproxDistance(dest->x - source->x, dest->y - source->y); + dist = FixedHypot(dest->x - source->x, dest->y - source->y); dist = dist / speed; diff --git a/src/p_polyobj.c b/src/p_polyobj.c index 874edbd50..95734ff86 100644 --- a/src/p_polyobj.c +++ b/src/p_polyobj.c @@ -1636,7 +1636,7 @@ void T_PolyObjWaypoint(polywaypoint_t *th) distx = target->x - pox; disty = target->y - poy; distz = target->z - poz; - dist = P_AproxDistance(P_AproxDistance(distx, disty), distz); + dist = FixedHypot(FixedHypot(distx, disty), distz); if (dist < 1) dist = 1; diff --git a/src/p_setup.c b/src/p_setup.c index 41d8822e2..2ee588fbb 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -232,7 +232,7 @@ mobj_t *P_GetClosestWaypoint(UINT8 sequence, mobj_t *mo) if (!mo2) continue; - curdist = P_AproxDistance(P_AproxDistance(mo->x - mo2->x, mo->y - mo2->y), mo->z - mo2->z); + curdist = FixedHypot(FixedHypot(mo->x - mo2->x, mo->y - mo2->y), mo->z - mo2->z); if (result && curdist > bestdist) continue; diff --git a/src/p_slopes.c b/src/p_slopes.c index aa46a8402..d77d0805f 100644 --- a/src/p_slopes.c +++ b/src/p_slopes.c @@ -885,7 +885,7 @@ void P_ButteredSlope(mobj_t *mo) } if (mo->momx || mo->momy) // Slightly increase thrust based on the object's speed - thrust = FixedMul(thrust, FRACUNIT+P_AproxDistance(mo->momx, mo->momy)/16); + thrust = FixedMul(thrust, FRACUNIT+FixedHypot(mo->momx, mo->momy)/16); // This makes it harder to zigzag up steep slopes, as well as allows greater top speed when rolling down // Let's get the gravity strength for the object... diff --git a/src/p_spec.c b/src/p_spec.c index 5b9e05c61..e696ad5d1 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -1240,7 +1240,7 @@ static boolean PolyFlag(line_t *line) polyflagdata_t pfd; pfd.polyObjNum = Tag_FGet(&line->tags); - pfd.speed = P_AproxDistance(line->dx, line->dy) >> FRACBITS; + pfd.speed = FixedHypot(line->dx, line->dy) >> FRACBITS; pfd.angle = R_PointToAngle2(line->v1->x, line->v1->y, line->v2->x, line->v2->y) >> ANGLETOFINESHIFT; pfd.momx = sides[line->sidenum[0]].textureoffset >> FRACBITS; @@ -1567,7 +1567,7 @@ static boolean P_CheckNightsTriggerLine(line_t *triggerline, mobj_t *actor) boolean P_RunTriggerLinedef(line_t *triggerline, mobj_t *actor, sector_t *caller) { sector_t *ctlsector; - fixed_t dist = P_AproxDistance(triggerline->dx, triggerline->dy)>>FRACBITS; + fixed_t dist = FixedHypot(triggerline->dx, triggerline->dy)>>FRACBITS; size_t i, linecnt, sectori; INT16 specialtype = triggerline->special; @@ -2629,7 +2629,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) sectors[secnum].lightlevel = line->backsector->lightlevel; flick = P_SpawnAdjustableFireFlicker(line->frontsector, §ors[secnum], - P_AproxDistance(line->dx, line->dy)>>FRACBITS); + FixedHypot(line->dx, line->dy)>>FRACBITS); // Make sure the starting light level is in range. if (reallightlevel < flick->minlight) @@ -2644,7 +2644,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) // Use front sector for min, target sector for max, // the same way linetype 61 does it. P_SpawnAdjustableFireFlicker(line->frontsector, §ors[secnum], - P_AproxDistance(line->dx, line->dy)>>FRACBITS); + FixedHypot(line->dx, line->dy)>>FRACBITS); } } break; @@ -2663,7 +2663,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) sectors[secnum].lightlevel = line->backsector->lightlevel; glow = P_SpawnAdjustableGlowingLight(line->frontsector, §ors[secnum], - P_AproxDistance(line->dx, line->dy)>>FRACBITS); + FixedHypot(line->dx, line->dy)>>FRACBITS); // Make sure the starting light level is in range. if (reallightlevel < glow->minlight) @@ -2678,7 +2678,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) // Use front sector for min, target sector for max, // the same way linetype 602 does it. P_SpawnAdjustableGlowingLight(line->frontsector, §ors[secnum], - P_AproxDistance(line->dx, line->dy)>>FRACBITS); + FixedHypot(line->dx, line->dy)>>FRACBITS); } } break; @@ -2760,7 +2760,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) ((line->sidenum[1] != 0xFFFF && !(sides[line->sidenum[0]].rowoffset>>FRACBITS)) ? max(min(sides[line->sidenum[1]].rowoffset>>FRACBITS, 255), 0) : max(min(sides[line->sidenum[0]].rowoffset>>FRACBITS, 255), 0)) - : abs(P_AproxDistance(line->dx, line->dy))>>FRACBITS, + : abs(FixedHypot(line->dx, line->dy))>>FRACBITS, (line->flags & ML_EFFECT4), (line->flags & ML_EFFECT5)); break; @@ -2795,7 +2795,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) else { P_SetTarget(&mo->player->awayviewmobj, altview); - mo->player->awayviewtics = P_AproxDistance(line->dx, line->dy)>>FRACBITS; + mo->player->awayviewtics = FixedHypot(line->dx, line->dy)>>FRACBITS; } @@ -2840,7 +2840,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) case 425: // Calls P_SetMobjState on calling mobj if (mo && !mo->player) - P_SetMobjState(mo, sides[line->sidenum[0]].toptexture); //P_AproxDistance(line->dx, line->dy)>>FRACBITS); + P_SetMobjState(mo, sides[line->sidenum[0]].toptexture); //FixedHypot(line->dx, line->dy)>>FRACBITS); break; case 426: // Moves the mobj to its sector's soundorg and on the floor, and stops it @@ -3026,7 +3026,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) case 438: // Set player scale if (mo) { - mo->destscale = FixedDiv(P_AproxDistance(line->dx, line->dy), 100<<FRACBITS); + mo->destscale = FixedDiv(FixedHypot(line->dx, line->dy), 100<<FRACBITS); if (mo->destscale < FRACUNIT/100) mo->destscale = FRACUNIT/100; if (mo->player && bot) @@ -3144,7 +3144,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) { quake.intensity = sides[line->sidenum[0]].textureoffset; quake.radius = sides[line->sidenum[0]].rowoffset; - quake.time = P_AproxDistance(line->dx, line->dy)>>FRACBITS; + quake.time = FixedHypot(line->dx, line->dy)>>FRACBITS; quake.epicenter = NULL; /// \todo @@ -3407,7 +3407,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) case 452: // Set FOF alpha { INT16 destvalue = line->sidenum[1] != 0xffff ? - (INT16)(sides[line->sidenum[1]].textureoffset>>FRACBITS) : (INT16)(P_AproxDistance(line->dx, line->dy)>>FRACBITS); + (INT16)(sides[line->sidenum[1]].textureoffset>>FRACBITS) : (INT16)(FixedHypot(line->dx, line->dy)>>FRACBITS); INT16 sectag = (INT16)(sides[line->sidenum[0]].textureoffset>>FRACBITS); INT16 foftag = (INT16)(sides[line->sidenum[0]].rowoffset>>FRACBITS); sector_t *sec; // Sector that the FOF is visible in @@ -4995,8 +4995,8 @@ DoneSection2: } else { - if (P_AproxDistance(P_AproxDistance(player->mo->x-resultlow.x, player->mo->y-resultlow.y), - player->mo->z-resultlow.z) < P_AproxDistance(P_AproxDistance(player->mo->x-resulthigh.x, + if (FixedHypot(FixedHypot(player->mo->x-resultlow.x, player->mo->y-resultlow.y), + player->mo->z-resultlow.z) < FixedHypot(FixedHypot(player->mo->x-resulthigh.x, player->mo->y-resulthigh.y), player->mo->z-resulthigh.z)) { // Line between Mid and Low is closer @@ -6314,7 +6314,7 @@ void P_SpawnSpecials(boolean fromnetsave) break; case 52: // Continuously Falling sector - EV_DoContinuousFall(lines[i].frontsector, lines[i].backsector, P_AproxDistance(lines[i].dx, lines[i].dy), (lines[i].flags & ML_NOCLIMB)); + EV_DoContinuousFall(lines[i].frontsector, lines[i].backsector, FixedHypot(lines[i].dx, lines[i].dy), (lines[i].flags & ML_NOCLIMB)); break; case 53: // New super cool and awesome moving floor and ceiling type @@ -6386,15 +6386,15 @@ void P_SpawnSpecials(boolean fromnetsave) case 66: // Displace floor by front sector TAG_ITER_SECTORS(0, tag, s) - P_AddPlaneDisplaceThinker(pd_floor, P_AproxDistance(lines[i].dx, lines[i].dy)>>8, sides[lines[i].sidenum[0]].sector-sectors, s, !!(lines[i].flags & ML_NOCLIMB)); + P_AddPlaneDisplaceThinker(pd_floor, FixedHypot(lines[i].dx, lines[i].dy)>>8, sides[lines[i].sidenum[0]].sector-sectors, s, !!(lines[i].flags & ML_NOCLIMB)); break; case 67: // Displace ceiling by front sector TAG_ITER_SECTORS(0, tag, s) - P_AddPlaneDisplaceThinker(pd_ceiling, P_AproxDistance(lines[i].dx, lines[i].dy)>>8, sides[lines[i].sidenum[0]].sector-sectors, s, !!(lines[i].flags & ML_NOCLIMB)); + P_AddPlaneDisplaceThinker(pd_ceiling, FixedHypot(lines[i].dx, lines[i].dy)>>8, sides[lines[i].sidenum[0]].sector-sectors, s, !!(lines[i].flags & ML_NOCLIMB)); break; case 68: // Displace both floor AND ceiling by front sector TAG_ITER_SECTORS(0, tag, s) - P_AddPlaneDisplaceThinker(pd_both, P_AproxDistance(lines[i].dx, lines[i].dy)>>8, sides[lines[i].sidenum[0]].sector-sectors, s, !!(lines[i].flags & ML_NOCLIMB)); + P_AddPlaneDisplaceThinker(pd_both, FixedHypot(lines[i].dx, lines[i].dy)>>8, sides[lines[i].sidenum[0]].sector-sectors, s, !!(lines[i].flags & ML_NOCLIMB)); break; case 100: // FOF (solid, opaque, shadows) @@ -6588,18 +6588,18 @@ void P_SpawnSpecials(boolean fromnetsave) case 150: // Air bobbing platform case 151: // Adjustable air bobbing platform { - fixed_t dist = (lines[i].special == 150) ? 16*FRACUNIT : P_AproxDistance(lines[i].dx, lines[i].dy); + fixed_t dist = (lines[i].special == 150) ? 16*FRACUNIT : FixedHypot(lines[i].dx, lines[i].dy); P_AddFakeFloorsByLine(i, FF_EXISTS|FF_SOLID|FF_RENDERALL|FF_CUTLEVEL, secthinkers); P_AddAirbob(lines[i].frontsector, tag, dist, false, !!(lines[i].flags & ML_NOCLIMB), false); break; } case 152: // Adjustable air bobbing platform in reverse P_AddFakeFloorsByLine(i, FF_EXISTS|FF_SOLID|FF_RENDERALL|FF_CUTLEVEL, secthinkers); - P_AddAirbob(lines[i].frontsector, tag, P_AproxDistance(lines[i].dx, lines[i].dy), true, !!(lines[i].flags & ML_NOCLIMB), false); + P_AddAirbob(lines[i].frontsector, tag, FixedHypot(lines[i].dx, lines[i].dy), true, !!(lines[i].flags & ML_NOCLIMB), false); break; case 153: // Dynamic Sinking Platform P_AddFakeFloorsByLine(i, FF_EXISTS|FF_SOLID|FF_RENDERALL|FF_CUTLEVEL, secthinkers); - P_AddAirbob(lines[i].frontsector, tag, P_AproxDistance(lines[i].dx, lines[i].dy), false, !!(lines[i].flags & ML_NOCLIMB), true); + P_AddAirbob(lines[i].frontsector, tag, FixedHypot(lines[i].dx, lines[i].dy), false, !!(lines[i].flags & ML_NOCLIMB), true); break; case 160: // Float/bob platform @@ -6678,7 +6678,7 @@ void P_SpawnSpecials(boolean fromnetsave) case 194: // Rising Platform 'Platform' - You can jump up through it case 195: // Rising Platform Translucent "platform" { - fixed_t speed = FixedDiv(P_AproxDistance(lines[i].dx, lines[i].dy), 4*FRACUNIT); + fixed_t speed = FixedDiv(FixedHypot(lines[i].dx, lines[i].dy), 4*FRACUNIT); fixed_t ceilingtop = P_FindHighestCeilingSurrounding(lines[i].frontsector); fixed_t ceilingbottom = P_FindLowestCeilingSurrounding(lines[i].frontsector); @@ -7003,14 +7003,14 @@ void P_SpawnSpecials(boolean fromnetsave) sec = sides[*lines[i].sidenum].sector - sectors; TAG_ITER_SECTORS(0, tag, s) P_SpawnAdjustableGlowingLight(§ors[sec], §ors[s], - P_AproxDistance(lines[i].dx, lines[i].dy)>>FRACBITS); + FixedHypot(lines[i].dx, lines[i].dy)>>FRACBITS); break; case 603: // Adjustable flickering light sec = sides[*lines[i].sidenum].sector - sectors; TAG_ITER_SECTORS(0, tag, s) P_SpawnAdjustableFireFlicker(§ors[sec], §ors[s], - P_AproxDistance(lines[i].dx, lines[i].dy)>>FRACBITS); + FixedHypot(lines[i].dx, lines[i].dy)>>FRACBITS); break; case 604: // Adjustable Blinking Light (unsynchronized) @@ -8416,9 +8416,9 @@ static void Add_Pusher(pushertype_e type, fixed_t x_mag, fixed_t y_mag, mobj_t * // "The right triangle of the square of the length of the hypotenuse is equal to the sum of the squares of the lengths of the other two sides." // "Bah! Stupid brains! Don't you know anything besides the Pythagorean Theorem?" - Earthworm Jim if (type == p_downcurrent || type == p_upcurrent || type == p_upwind || type == p_downwind) - p->magnitude = P_AproxDistance(p->x_mag,p->y_mag)<<(FRACBITS-PUSH_FACTOR); + p->magnitude = FixedHypot(p->x_mag,p->y_mag)<<(FRACBITS-PUSH_FACTOR); else - p->magnitude = P_AproxDistance(p->x_mag,p->y_mag); + p->magnitude = FixedHypot(p->x_mag,p->y_mag); if (source) // point source exist? { // where force goes to zero @@ -8469,14 +8469,14 @@ static inline boolean PIT_PushThing(mobj_t *thing) // don't fade wrt Z if health & 2 (mapthing has multi flag) if (tmpusher->source->health & 2) - dist = P_AproxDistance(thing->x - sx,thing->y - sy); + dist = FixedHypot(thing->x - sx,thing->y - sy); else { // Make sure the Z is in range if (thing->z < sz - tmpusher->radius || thing->z > sz + tmpusher->radius) return false; - dist = P_AproxDistance(P_AproxDistance(thing->x - sx, thing->y - sy), + dist = FixedHypot(FixedHypot(thing->x - sx, thing->y - sy), thing->z - sz); } @@ -8811,7 +8811,7 @@ void T_Pusher(pusher_t *p) // Tumbleweeds bounce a bit... if (thing->type == MT_LITTLETUMBLEWEED || thing->type == MT_BIGTUMBLEWEED) - thing->momz += P_AproxDistance(xspeed<<(FRACBITS-PUSH_FACTOR), yspeed<<(FRACBITS-PUSH_FACTOR)) >> 2; + thing->momz += FixedHypot(xspeed<<(FRACBITS-PUSH_FACTOR), yspeed<<(FRACBITS-PUSH_FACTOR)) >> 2; } if (moved) diff --git a/src/p_user.c b/src/p_user.c index 2dcc21009..84fc3e521 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1018,7 +1018,7 @@ void P_DoPlayerPain(player_t *player, mobj_t *source, mobj_t *inflictor) // to recover if ((inflictor->flags2 & MF2_SCATTER) && source) { - fixed_t dist = P_AproxDistance(P_AproxDistance(source->x-player->mo->x, source->y-player->mo->y), source->z-player->mo->z); + fixed_t dist = FixedHypot(FixedHypot(source->x-player->mo->x, source->y-player->mo->y), source->z-player->mo->z); dist = FixedMul(128*FRACUNIT, inflictor->scale) - dist/4; @@ -2701,7 +2701,7 @@ static void P_CheckBustableBlocks(player_t *player) // Run a linedef executor?? if (rover->master->flags & ML_EFFECT5) - P_LinedefExecute((INT16)(P_AproxDistance(rover->master->dx, rover->master->dy)>>FRACBITS), player->mo, node->m_sector); + P_LinedefExecute((INT16)(FixedHypot(rover->master->dx, rover->master->dy)>>FRACBITS), player->mo, node->m_sector); goto bustupdone; } @@ -2764,7 +2764,7 @@ static void P_CheckBouncySectors(player_t *player) if (player->mo->z + player->mo->height < bottomheight) continue; - bouncestrength = P_AproxDistance(rover->master->dx, rover->master->dy)/100; + bouncestrength = FixedHypot(rover->master->dx, rover->master->dy)/100; if (oldz < P_GetFOFTopZ(player->mo, node->m_sector, rover, oldx, oldy, NULL) && oldz + player->mo->height > P_GetFOFBottomZ(player->mo, node->m_sector, rover, oldx, oldy, NULL)) @@ -4981,7 +4981,7 @@ void P_Telekinesis(player_t *player, fixed_t thrust, fixed_t range) if (!((mo2->flags & MF_SHOOTABLE && mo2->flags & MF_ENEMY) || mo2->type == MT_EGGGUARD || mo2->player)) continue; - dist = P_AproxDistance(P_AproxDistance(player->mo->x-mo2->x, player->mo->y-mo2->y), player->mo->z-mo2->z); + dist = FixedHypot(FixedHypot(player->mo->x-mo2->x, player->mo->y-mo2->y), player->mo->z-mo2->z); if (range < dist) continue; @@ -6464,12 +6464,12 @@ static void P_NightsTransferPoints(player_t *player, fixed_t xspeed, fixed_t rad //CONS_Debug(DBG_NIGHTS, "T1 is at %d, %d\n", transfer1->x>>FRACBITS, transfer1->y>>FRACBITS); //CONS_Debug(DBG_NIGHTS, "T2 is at %d, %d\n", transfer2->x>>FRACBITS, transfer2->y>>FRACBITS); - //CONS_Debug(DBG_NIGHTS, "Distance from T1: %d\n", P_AproxDistance(transfer1->x - player->mo->x, transfer1->y - player->mo->y)>>FRACBITS); - //CONS_Debug(DBG_NIGHTS, "Distance from T2: %d\n", P_AproxDistance(transfer2->x - player->mo->x, transfer2->y - player->mo->y)>>FRACBITS); + //CONS_Debug(DBG_NIGHTS, "Distance from T1: %d\n", FixedHypot(transfer1->x - player->mo->x, transfer1->y - player->mo->y)>>FRACBITS); + //CONS_Debug(DBG_NIGHTS, "Distance from T2: %d\n", FixedHypot(transfer2->x - player->mo->x, transfer2->y - player->mo->y)>>FRACBITS); // Transfer1 is closer to the player than transfer2 - if (P_AproxDistance(transfer1->x - player->mo->x, transfer1->y - player->mo->y)>>FRACBITS - < P_AproxDistance(transfer2->x - player->mo->x, transfer2->y - player->mo->y)>>FRACBITS) + if (FixedHypot(transfer1->x - player->mo->x, transfer1->y - player->mo->y)>>FRACBITS + < FixedHypot(transfer2->x - player->mo->x, transfer2->y - player->mo->y)>>FRACBITS) { //CONS_Debug(DBG_NIGHTS, " must be < 0 to transfer\n"); @@ -7709,7 +7709,7 @@ void P_BlackOw(player_t *player) S_StartSound (player->mo, sfx_bkpoof); // Sound the BANG! for (i = 0; i < MAXPLAYERS; i++) - if (playeringame[i] && P_AproxDistance(player->mo->x - players[i].mo->x, + if (playeringame[i] && FixedHypot(player->mo->x - players[i].mo->x, player->mo->y - players[i].mo->y) < 1536*FRACUNIT) P_FlashPal(&players[i], PAL_NUKE, 10); @@ -7883,7 +7883,7 @@ static void P_SkidStuff(player_t *player) P_SpawnSkidDust(player, 0, false); } } - else if (P_AproxDistance(pmx, pmy) >= FixedMul(player->runspeed/2, player->mo->scale) // if you were moving faster than half your run speed last frame + else if (FixedHypot(pmx, pmy) >= FixedMul(player->runspeed/2, player->mo->scale) // if you were moving faster than half your run speed last frame && (player->mo->momx != pmx || player->mo->momy != pmy) // and you are moving differently this frame && P_GetPlayerControlDirection(player) == 2) // and your controls are pointing in the opposite direction to your movement { // check for skidding @@ -8514,7 +8514,7 @@ void P_MovePlayer(player_t *player) P_ResetScore(player); // Show the "THOK!" graphic when spinning quickly across the ground. (even applies to non-spinners, in the case of zoom tubes) - if (player->pflags & PF_SPINNING && P_AproxDistance(player->speed, player->mo->momz) > FixedMul(15<<FRACBITS, player->mo->scale) && !(player->pflags & PF_JUMPED)) + if (player->pflags & PF_SPINNING && FixedHypot(player->speed, player->mo->momz) > FixedMul(15<<FRACBITS, player->mo->scale) && !(player->pflags & PF_JUMPED)) { P_SpawnSpinMobj(player, player->spinitem); G_GhostAddSpin(); @@ -8735,7 +8735,7 @@ static void P_DoZoomTube(player_t *player) speed = abs(player->speed); // change slope - dist = P_AproxDistance(P_AproxDistance(player->mo->tracer->x - player->mo->x, player->mo->tracer->y - player->mo->y), player->mo->tracer->z - player->mo->z); + dist = FixedHypot(FixedHypot(player->mo->tracer->x - player->mo->x, player->mo->tracer->y - player->mo->y), player->mo->tracer->z - player->mo->z); if (dist < 1) dist = 1; @@ -8776,7 +8776,7 @@ static void P_DoZoomTube(player_t *player) // calculate MOMX/MOMY/MOMZ for next waypoint // change slope - dist = P_AproxDistance(P_AproxDistance(player->mo->tracer->x - player->mo->x, player->mo->tracer->y - player->mo->y), player->mo->tracer->z - player->mo->z); + dist = FixedHypot(FixedHypot(player->mo->tracer->x - player->mo->x, player->mo->tracer->y - player->mo->y), player->mo->tracer->z - player->mo->z); if (dist < 1) dist = 1; @@ -8829,7 +8829,7 @@ static void P_DoRopeHang(player_t *player) sequence = player->mo->tracer->threshold; // change slope - dist = P_AproxDistance(P_AproxDistance(player->mo->tracer->x - player->mo->x, player->mo->tracer->y - player->mo->y), player->mo->tracer->z - playerz); + dist = FixedHypot(FixedHypot(player->mo->tracer->x - player->mo->x, player->mo->tracer->y - player->mo->y), player->mo->tracer->z - playerz); if (dist < 1) dist = 1; @@ -8892,7 +8892,7 @@ static void P_DoRopeHang(player_t *player) // calculate MOMX/MOMY/MOMZ for next waypoint // change slope - dist = P_AproxDistance(P_AproxDistance(player->mo->tracer->x - player->mo->x, player->mo->tracer->y - player->mo->y), player->mo->tracer->z - playerz); + dist = FixedHypot(FixedHypot(player->mo->tracer->x - player->mo->x, player->mo->tracer->y - player->mo->y), player->mo->tracer->z - playerz); if (dist < 1) dist = 1; @@ -8993,7 +8993,7 @@ void P_NukeEnemies(mobj_t *inflictor, mobj_t *source, fixed_t radius) if (abs(inflictor->x - mo->x) > radius || abs(inflictor->y - mo->y) > radius || abs(inflictor->z - mo->z) > radius) continue; // Workaround for possible integer overflow in the below -Red - if (P_AproxDistance(P_AproxDistance(inflictor->x - mo->x, inflictor->y - mo->y), inflictor->z - mo->z) > radius) + if (FixedHypot(FixedHypot(inflictor->x - mo->x, inflictor->y - mo->y), inflictor->z - mo->z) > radius) continue; if (mo->type == MT_MINUS && !(mo->flags & (MF_SPECIAL|MF_SHOOTABLE))) @@ -9129,12 +9129,12 @@ mobj_t *P_LookForFocusTarget(player_t *player, mobj_t *exclude, SINT8 direction, { fixed_t zdist = (player->mo->z + player->mo->height/2) - (mo->z + mo->height/2); - dist = P_AproxDistance(player->mo->x-mo->x, player->mo->y-mo->y); + dist = FixedHypot(player->mo->x-mo->x, player->mo->y-mo->y); if (abs(zdist) > dist) continue; // Don't home outside of desired angle! - dist = P_AproxDistance(dist, zdist); + dist = FixedHypot(dist, zdist); if (dist > maxdist) continue; // out of range } @@ -9226,7 +9226,7 @@ mobj_t *P_LookForEnemies(player_t *player, boolean nonenemies, boolean bullet) { fixed_t zdist = (player->mo->z + player->mo->height/2) - (mo->z + mo->height/2); - dist = P_AproxDistance(player->mo->x-mo->x, player->mo->y-mo->y); + dist = FixedHypot(player->mo->x-mo->x, player->mo->y-mo->y); if (bullet) { if ((R_PointToAngle2(0, 0, dist, zdist) + span) > span*2) @@ -9243,7 +9243,7 @@ mobj_t *P_LookForEnemies(player_t *player, boolean nonenemies, boolean bullet) continue; } - dist = P_AproxDistance(dist, zdist); + dist = FixedHypot(dist, zdist); if (dist > maxdist) continue; // out of range } @@ -9303,7 +9303,7 @@ boolean P_HomingAttack(mobj_t *source, mobj_t *enemy) // Home in on your target // change slope zdist = ((P_MobjFlip(source) == -1) ? (enemy->z + enemy->height) - (source->z + source->height) : (enemy->z - source->z)); - dist = P_AproxDistance(P_AproxDistance(enemy->x - source->x, enemy->y - source->y), zdist); + dist = FixedHypot(FixedHypot(enemy->x - source->x, enemy->y - source->y), zdist); if (dist < 1) dist = 1; @@ -10352,7 +10352,7 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall // follow the player /*if (player->playerstate != PST_DEAD && (camspeed) != 0) { - if (P_AproxDistance(mo->x - thiscam->x, mo->y - thiscam->y) > (checkdist + P_AproxDistance(mo->momx, mo->momy)) * 4 + if (FixedHypot(mo->x - thiscam->x, mo->y - thiscam->y) > (checkdist + FixedHypot(mo->momx, mo->momy)) * 4 || abs(mo->z - thiscam->z) > checkdist * 3) { if (!resetcalled) @@ -10417,7 +10417,7 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall } /* check z distance too for orbital camera */ - if (P_AproxDistance(P_AproxDistance(vx - mo->x, vy - mo->y), + if (FixedHypot(FixedHypot(vx - mo->x, vy - mo->y), vz - ( mo->z + mo->height / 2 )) < FixedMul(48*FRACUNIT, mo->scale)) mo->flags2 |= MF2_SHADOW; else @@ -10902,7 +10902,7 @@ static void P_ParabolicMove(mobj_t *mo, fixed_t x, fixed_t y, fixed_t z, fixed_t fixed_t dx = x - mo->x; fixed_t dy = y - mo->y; fixed_t dz = z - mo->z; - fixed_t dh = P_AproxDistance(dx, dy); + fixed_t dh = FixedHypot(dx, dy); fixed_t c = FixedDiv(dx, dh); fixed_t s = FixedDiv(dy, dh); fixed_t fixConst = FixedDiv(speed, g); @@ -11774,7 +11774,7 @@ void P_PlayerThink(player_t *player) if (mo2->flags2 & MF2_NIGHTSPULL) continue; - if (P_AproxDistance(P_AproxDistance(mo2->x - x, mo2->y - y), mo2->z - z) > FixedMul(128*FRACUNIT, player->mo->scale)) + if (FixedHypot(FixedHypot(mo2->x - x, mo2->y - y), mo2->z - z) > FixedMul(128*FRACUNIT, player->mo->scale)) continue; // Yay! The thing's in reach! Pull it in! @@ -12010,7 +12010,7 @@ void P_PlayerThink(player_t *player) if (!currentlyonground) acceleration /= 2; // fake skidding! see P_SkidStuff for reference on conditionals - else if (!player->skidtime && !(player->mo->eflags & MFE_GOOWATER) && !(player->pflags & (PF_JUMPED|PF_SPINNING|PF_SLIDING)) && !(player->charflags & SF_NOSKID) && P_AproxDistance(player->mo->momx, player->mo->momy) >= FixedMul(player->runspeed, player->mo->scale)) // modified from player->runspeed/2 'cuz the skid was just TOO frequent ngl + else if (!player->skidtime && !(player->mo->eflags & MFE_GOOWATER) && !(player->pflags & (PF_JUMPED|PF_SPINNING|PF_SLIDING)) && !(player->charflags & SF_NOSKID) && FixedHypot(player->mo->momx, player->mo->momy) >= FixedMul(player->runspeed, player->mo->scale)) // modified from player->runspeed/2 'cuz the skid was just TOO frequent ngl { if (player->mo->state-states != S_PLAY_SKID) P_SetPlayerMobjState(player->mo, S_PLAY_SKID); @@ -12595,7 +12595,7 @@ void P_PlayerAfterThink(player_t *player) P_SetPlayerAngle(player, player->mo->angle); } - if (P_AproxDistance(player->mo->x - tails->x, player->mo->y - tails->y) > player->mo->radius) + if (FixedHypot(player->mo->x - tails->x, player->mo->y - tails->y) > player->mo->radius) player->powers[pw_carry] = CR_NONE; if (player->powers[pw_carry] != CR_NONE) @@ -12784,7 +12784,7 @@ void P_PlayerAfterThink(player_t *player) player->mo->momy = ptera->momy; player->mo->momz = ptera->momz; - if (P_AproxDistance(player->mo->x - ptera->x - ptera->watertop, player->mo->y - ptera->y - ptera->waterbottom) > player->mo->radius) + if (FixedHypot(player->mo->x - ptera->x - ptera->watertop, player->mo->y - ptera->y - ptera->waterbottom) > player->mo->radius) goto dropoff; ptera->watertop >>= 1; diff --git a/src/r_things.c b/src/r_things.c index 083373927..4e296bb1a 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -2991,7 +2991,7 @@ boolean R_ThingVisibleWithinDist (mobj_t *thing, if (! R_ThingVisible(thing)) return false; - approx_dist = P_AproxDistance(viewx-thing->x, viewy-thing->y); + approx_dist = FixedHypot(viewx-thing->x, viewy-thing->y); if (thing->sprite == SPR_HOOP) { @@ -3016,7 +3016,7 @@ boolean R_PrecipThingVisible (precipmobj_t *precipthing, if (( precipthing->precipflags & PCF_INVISIBLE )) return false; - approx_dist = P_AproxDistance(viewx-precipthing->x, viewy-precipthing->y); + approx_dist = FixedHypot(viewx-precipthing->x, viewy-precipthing->y); return ( approx_dist <= limit_dist ); } diff --git a/src/s_sound.c b/src/s_sound.c index 392a5b453..0085dc342 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -943,8 +943,8 @@ void S_UpdateSounds(void) const mobj_t *soundmobj = c->origin; fixed_t dist1, dist2; - dist1 = P_AproxDistance(listener.x-soundmobj->x, listener.y-soundmobj->y); - dist2 = P_AproxDistance(listener2.x-soundmobj->x, listener2.y-soundmobj->y); + dist1 = FixedHypot(listener.x-soundmobj->x, listener.y-soundmobj->y); + dist2 = FixedHypot(listener2.x-soundmobj->x, listener2.y-soundmobj->y); if (dist1 <= dist2) { diff --git a/src/st_stuff.c b/src/st_stuff.c index 649644620..15d1af396 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -2458,7 +2458,7 @@ num: static INT32 ST_drawEmeraldHuntIcon(mobj_t *hunt, patch_t **patches, INT32 offset) { INT32 interval, i; - UINT32 dist = ((UINT32)P_AproxDistance(P_AproxDistance(stplyr->mo->x - hunt->x, stplyr->mo->y - hunt->y), stplyr->mo->z - hunt->z))>>FRACBITS; + UINT32 dist = ((UINT32)FixedHypot(FixedHypot(stplyr->mo->x - hunt->x, stplyr->mo->y - hunt->y), stplyr->mo->z - hunt->z))>>FRACBITS; if (dist < 128) {