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.
This commit is contained in:
Sally Coolatta 2020-11-07 19:47:50 -05:00
parent 4c2b6de02c
commit d6c497065e
3 changed files with 3 additions and 15 deletions

View file

@ -238,7 +238,8 @@ static int lib_pAproxDistance(lua_State *L)
fixed_t dx = luaL_checkfixed(L, 1); fixed_t dx = luaL_checkfixed(L, 1);
fixed_t dy = luaL_checkfixed(L, 2); fixed_t dy = luaL_checkfixed(L, 2);
//HUDSAFE //HUDSAFE
lua_pushfixed(L, P_AproxDistance(dx, dy)); LUA_Deprecated(L, "P_AproxDistance", "FixedHypot");
lua_pushfixed(L, FixedHypot(dx, dy));
return 1; return 1;
} }

View file

@ -23,19 +23,6 @@
#include "p_slopes.h" #include "p_slopes.h"
#include "z_zone.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 // P_ClosestPointOnLine
// Finds the closest point on a given line to the supplied point // Finds the closest point on a given line to the supplied point

View file

@ -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, boolean P_PathTraverse(fixed_t px1, fixed_t py1, fixed_t px2, fixed_t py2,
INT32 pflags, traverser_t ptrav); 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_ClosestPointOnLine(fixed_t x, fixed_t y, line_t *line, vertex_t *result);
void P_ClosestPointOnLine3D(fixed_t x, fixed_t y, fixed_t z, line_t *line, vertex_t *result); void P_ClosestPointOnLine3D(fixed_t x, fixed_t y, fixed_t z, line_t *line, vertex_t *result);
INT32 P_PointOnLineSide(fixed_t x, fixed_t y, line_t *line); INT32 P_PointOnLineSide(fixed_t x, fixed_t y, line_t *line);