more anticheats compatibility, using fast sqrt (100% faster than sqrtf)
git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@5456 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
@@ -1,3 +1,28 @@
|
||||
// Fast Inverse Sqrt
|
||||
// http://www.gamedev.net/community/forums/topic.asp?topic_id=139956
|
||||
// http://www.lomont.org/Math/Papers/2003/InvSqrt.pdf
|
||||
// http://www.mceniry.net/papers/Fast%20Inverse%20Square%20Root.pdf
|
||||
// http://en.wikipedia.org/wiki/Fast_inverse_square_root
|
||||
|
||||
inline float fInvSqrt (float x)
|
||||
{
|
||||
union
|
||||
{
|
||||
int d;
|
||||
float f;
|
||||
} u;
|
||||
|
||||
u.f = x;
|
||||
u.d = 0x5f3759df - (u.d >> 1);
|
||||
// return u.f; // ultra-fast, about 3.5% of error
|
||||
return 0.5f * u.f * ( 3.00175f - x * u.f * u.f ); // about 0.1% of error
|
||||
}
|
||||
|
||||
inline float fSqrt (float x)
|
||||
{
|
||||
return x * fInvSqrt(x);
|
||||
}
|
||||
|
||||
struct vec
|
||||
{
|
||||
union
|
||||
@@ -34,12 +59,16 @@ struct vec
|
||||
float magnitude() const { return sqrtf(squaredlen()); }
|
||||
vec &normalize() { div(magnitude()); return *this; }
|
||||
|
||||
float fmag() const { return fSqrt(squaredlen()); }
|
||||
|
||||
float dist(const vec &e) const { vec t; return dist(e, t); }
|
||||
float dist(const vec &e, vec &t) const { t = *this; t.sub(e); return t.magnitude(); }
|
||||
|
||||
float distxy(const vec &e) const { float dx = e.x - x, dy = e.y - y; return sqrtf(dx*dx + dy*dy); }
|
||||
float magnitudexy() const { return sqrtf(x*x + y*y); }
|
||||
|
||||
float fmagxy() const { return fSqrt(x*x + y*y); }
|
||||
|
||||
bool reject(const vec &o, float max) const { return x>o.x+max || x<o.x-max || y>o.y+max || y<o.y-max; }
|
||||
|
||||
vec &cross(const vec &a, const vec &b) { x = a.y*b.z-a.z*b.y; y = a.z*b.x-a.x*b.z; z = a.x*b.y-a.y*b.x; return *this; }
|
||||
|
||||
@@ -1354,7 +1354,7 @@ void checkitemspawns(int diff)
|
||||
|
||||
void serverdamage(client *target, client *actor, int damage, int gun, bool gib, const vec &hitpush = vec(0, 0, 0))
|
||||
{
|
||||
if (!m_demo && !m_coop && !validdamage(target, actor, gun, gib)) return;
|
||||
if (!m_demo && !m_coop && !validdamage(target, actor, damage, gun, gib)) return;
|
||||
clientstate &ts = target->state;
|
||||
ts.dodamage(damage);
|
||||
actor->state.damage += damage != 1000 ? damage : 0;
|
||||
|
||||
@@ -596,10 +596,10 @@ inline void checkshoot (int & cn, gameevent & shot, int & hits)
|
||||
return;
|
||||
}
|
||||
|
||||
bool validdamage (client *&target, client *&actor, int &gun, bool &gib)
|
||||
bool validdamage (client *&target, client *&actor, int &damage, int &gun, bool &gib)
|
||||
{
|
||||
#ifdef ACAC
|
||||
if (!d_engine(target, actor, gun, gib)) return false;
|
||||
if (!d_engine(target, actor, damage, gun, gib)) return false;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user