From 1ac442a213ce910baa022506cfeee6277095b8ec Mon Sep 17 00:00:00 2001 From: Rafael Barreto Date: Sat, 24 Jul 2010 22:03:52 +0000 Subject: [PATCH] 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 --- source/src/geom.h | 29 +++++++++++++++++++++++++++++ source/src/server.cpp | 2 +- source/src/serverchecks.h | 4 ++-- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/source/src/geom.h b/source/src/geom.h index 2b694373..873d8b44 100644 --- a/source/src/geom.h +++ b/source/src/geom.h @@ -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 || xo.y+max || ystate; ts.dodamage(damage); actor->state.damage += damage != 1000 ? damage : 0; diff --git a/source/src/serverchecks.h b/source/src/serverchecks.h index 3a2b1448..08bbc2c9 100644 --- a/source/src/serverchecks.h +++ b/source/src/serverchecks.h @@ -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; }