Commit 75633bde by James R.

Replace all instances of P_AproxDistance with FixedHypot

parent e19196a8
......@@ -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;
}
......
......@@ -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)
......
......@@ -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
......
......@@ -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);
}
......
......@@ -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;
......
......@@ -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)
......
......@@ -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);
......
......@@ -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;
......
......@@ -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;
......
......@@ -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...
......
......@@ -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 );
}
......
......@@ -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)
{
......
......@@ -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)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment