From 11dc8202fa9f109f6ff8c41feade2c8e7ab9d1e0 Mon Sep 17 00:00:00 2001 From: ac-stef Date: Thu, 4 Jun 2015 23:23:38 +0200 Subject: [PATCH] cleanup --- source/src/clientgame.cpp | 2 +- source/src/geom.h | 54 --------------------------------------- source/src/physics.cpp | 2 +- source/src/server.cpp | 2 +- source/src/tools.h | 2 ++ 5 files changed, 5 insertions(+), 57 deletions(-) diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index 4cc9e3e7..d1ec43ad 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -1112,7 +1112,7 @@ void showmapstats() conoutf(" The mean height is: %.2f", Mh); if (Hhits) conoutf(" Height check is: %d", Hhits); if (MA) conoutf(" The max area is: %d (of %d)", MA, Ma); - if (m_flags && F2F < 1000) conoutf(" Flag-to-flag distance is: %d", (int)fSqrt(F2F)); + if (m_flags && F2F < 1000) conoutf(" Flag-to-flag distance is: %d", (int)sqrtf(F2F)); if (item_fail) conoutf(" There are one or more items too close to each other in this map"); } COMMAND(showmapstats, ""); diff --git a/source/src/geom.h b/source/src/geom.h index 87391f2d..af182fef 100644 --- a/source/src/geom.h +++ b/source/src/geom.h @@ -1,51 +1,3 @@ -// 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 -#define UFINVSQRT(x) union { int d; float f; } u; u.f = x; u.d = 0x5f3759df - (u.d >> 1) -inline float ufInvSqrt (float x) { UFINVSQRT(x); return u.f; } // about 3.5% of error -inline float fInvSqrt (float x) { UFINVSQRT(x); 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); } -inline float ufSqrt (float x) { return x * ufInvSqrt(x); } -inline float fACos( float x ) -{ - int s = 1; - float y, r = 0; - if ( x < 0 ) - { - s = -1; - r = 2.0f; - y = 1.0f + x; - } - else y = 1.0f - x; - UFINVSQRT(y); - u.f = 0.5f * u.f * ( 3.0f - y * u.f * u.f ); - u.f = y * 0.5f * u.f * ( 3.0f - y * u.f * u.f ); - return 1.57079632f * ( r + s * u.f * ( 0.9003163f + y * ( 0.07782684f + y * ( 0.006777598f + y * 0.015079262f ) ) ) ); -} -#undef UFINVSQRT - -template inline T pow2(T x) { return x*x; } - -// Fast Cosine -// inspired after http://www.devmaster.net/forums/showthread.php?t=5784 -#define FCOS \ - x = fabs(x); \ - int s = 1; \ - if ( x > 1.0f ) \ - { \ - int n = 0.5f * ( x + 1.0f ); \ - x -= 2 * n; \ - s = 1 - 2 * (n%2); \ - } \ - float y = ( 1.0f - x*x ); \ - return s * y * ( 0.7853982f + y * 0.2146018f ) -inline float fCos(float x) { x *= 0.636619772f; FCOS; } -inline float fSin(float x) { x *= 0.636619772f; x -= 1.0f; FCOS; } -#undef FCOS - -inline float ufS2C(float x) { x *= x; return x < 1.0f ? ufSqrt(1.0f - x) : 0.0f; } struct vec { @@ -86,12 +38,6 @@ struct vec float magnitude() const { return sqrtf(squaredlen()); } vec &normalize() { div(magnitude()); return *this; } - // should NOT be used - float fmag() const { return fSqrt(squaredlen()); } - float ufmag() const { return ufSqrt(squaredlen()); } - float fmagxy() const { return fSqrt(x*x + y*y); } - float ufmagxy() const { return ufSqrt(x*x + y*y); } - 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(); } diff --git a/source/src/physics.cpp b/source/src/physics.cpp index 564987a6..1b92fe89 100644 --- a/source/src/physics.cpp +++ b/source/src/physics.cpp @@ -610,7 +610,7 @@ void moveplayer(physent *pl, int moveres, bool local, int curtime) if(pl->type!=ENT_BOUNCE && hitplayer) { vec dr(hitplayer->o.x-pl->o.x,hitplayer->o.y-pl->o.y,0); - float invdist = ufInvSqrt(dr.sqrxy()), + float invdist = 1.0f / dr.magnitudexy(), push = (invdist < 10.0f ? dr.dotxy(d)*1.1f*invdist : dr.dotxy(d) * 11.0f); pl->o.x -= f*d.x*push; diff --git a/source/src/server.cpp b/source/src/server.cpp index 2f8878f5..fc85de6e 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -1674,7 +1674,7 @@ int calcscores() // skill eval loopv(clients) if(clients[i]->type!=ST_EMPTY) { clientstate &cs = clients[i]->state; - sum += clients[i]->at3_score = cs.points > 0 ? ufSqrt((float)cs.points) : -ufSqrt((float)-cs.points); + sum += clients[i]->at3_score = cs.points > 0 ? sqrtf((float)cs.points) : -sqrtf((float)-cs.points); } return sum; } diff --git a/source/src/tools.h b/source/src/tools.h index e4d473cf..b58f54ba 100644 --- a/source/src/tools.h +++ b/source/src/tools.h @@ -55,6 +55,8 @@ static inline T min(T a, T b) return a < b ? a : b; } +template inline T pow2(T x) { return x*x; } + static inline float round(float x) { return floor(x + 0.5f); } #define clamp(x,minval,maxval) (max(minval, min(x, maxval)))