Eliminated OOInvSqrtf and OOFastInvSqrtf (which wasn't faster), and various - mostly unused - fast_foo functions that depended on OOFastInvSqrtf being fast.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@4721 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Jens Ayton 2012-01-08 18:16:26 +00:00
parent d0b7235ecf
commit 418953b4a0
6 changed files with 5 additions and 95 deletions

View File

@ -2626,7 +2626,7 @@ static void hudDrawReticleOnTarget(Entity* target, PlayerEntity* player1, GLfloa
p1 = vector_subtract([target position], [player1 viewpointPosition]);
double rdist = fast_magnitude(p1);
double rdist = magnitude(p1);
double rsize = [target collisionRadius];
if (rsize < rdist * ONE_SIXTYFOURTH)

View File

@ -37,10 +37,6 @@ MA 02110-1301, USA.
#endif
/* Inverse square root and approximation of same. */
OOINLINE float OOInvSqrtf(float x) INLINE_CONST_FUNC;
OOINLINE float OOFastInvSqrtf(float x) INLINE_CONST_FUNC;
/* Round integer up to nearest power of 2. */
OOINLINE uint32_t OORoundUpToPowerOf2(uint32_t x) INLINE_CONST_FUNC;
@ -54,30 +50,6 @@ OOINLINE double OOClamp_0_max_d(double value, double max) INLINE_CONST_FUNC;
OOINLINE float OOLerp(float v0, float v1, float fraction) INLINE_CONST_FUNC;
OOINLINE float OOInvSqrtf(float x)
{
return 1.0f/sqrtf(x);
}
OOINLINE float OOFastInvSqrtf(float x)
{
/* This appears to have been responsible for a lack of laser accuracy, as
well as not working at all under Windows. Disabled for now.
*/
#if FASTINVSQRT_ENABLED
float xhalf = 0.5f * x;
int i = *(int*)&x;
i = 0x5f375a86 - (i>>1);
x = *(float*)&i;
x = x * (1.5f - xhalf * x * x);
return x;
#else
return OOInvSqrtf(x);
#endif
}
#ifdef __GNUC__
OOINLINE uint32_t OORoundUpToPowerOf2(uint32_t value)
{

View File

@ -41,5 +41,5 @@ OOINLINE NSPoint PtRotACW(NSPoint p)
OOINLINE NSPoint PtFastNormal(NSPoint p)
{
return PtScale(p, OOFastInvSqrtf(PtDot(p, p)));
return PtScale(p, 1.0f / sqrtf(PtDot(p, p)));
}

View File

@ -158,23 +158,7 @@ OOINLINE void quaternion_normalize(Quaternion *quat)
OOScalar y = quat->y;
OOScalar z = quat->z;
OOScalar lv = OOInvSqrtf(w*w + x*x + y*y + z*z);
quat->w = lv * w;
quat->x = lv * x;
quat->y = lv * y;
quat->z = lv * z;
}
OOINLINE void fast_quaternion_normalize(Quaternion *quat)
{
OOScalar w = quat->w;
OOScalar x = quat->x;
OOScalar y = quat->y;
OOScalar z = quat->z;
OOScalar lv = OOFastInvSqrtf(w*w + x*x + y*y + z*z);
OOScalar lv = 1.0f / sqrtf(w*w + x*x + y*y + z*z);
quat->w = lv * w;
quat->x = lv * x;

View File

@ -244,22 +244,11 @@ OOINLINE OOScalar magnitude(Vector vec)
}
OOINLINE OOScalar fast_magnitude(Vector vec)
{
#if FASTINVSQRT_ENABLED || OO_PPC
OOScalar mag2 = magnitude2(vec);
return mag2 * OOFastInvSqrtf(mag2); /* x = sqrt(x) * sqrt(x); x * 1/sqrt(x) = (sqrt(x) * sqrt(x))/sqrt(x) = sqrt(x). */
#else
return magnitude(vec);
#endif
}
OOINLINE Vector vector_normal_or_fallback(Vector vec, Vector fallback)
{
OOScalar mag2 = magnitude2(vec);
if (EXPECT_NOT(mag2 == 0.0f)) return fallback;
return vector_multiply_scalar(vec, OOInvSqrtf(mag2));
return vector_multiply_scalar(vec, 1.0f / sqrtf(mag2));
}
@ -287,20 +276,6 @@ OOINLINE Vector vector_normal(Vector vec)
}
OOINLINE Vector fast_vector_normal_or_fallback(Vector vec, Vector fallback)
{
OOScalar mag2 = magnitude2(vec);
if (EXPECT_NOT(mag2 == 0.0f)) return fallback;
return vector_multiply_scalar(vec, OOFastInvSqrtf(mag2));
}
OOINLINE Vector fast_vector_normal(Vector vec)
{
return fast_vector_normal_or_fallback(vec, kZeroVector);
}
OOINLINE OOScalar distance2(Vector v1, Vector v2)
{
return magnitude2(vector_subtract(v1, v2));
@ -313,12 +288,6 @@ OOINLINE OOScalar distance(Vector v1, Vector v2)
}
OOINLINE OOScalar fast_distance(Vector v1, Vector v2)
{
return fast_magnitude(vector_subtract(v1, v2));
}
OOINLINE Vector true_cross_product(Vector first, Vector second)
{
Vector result;
@ -335,12 +304,6 @@ OOINLINE Vector cross_product(Vector first, Vector second)
}
OOINLINE Vector fast_cross_product(Vector first, Vector second)
{
return fast_vector_normal(true_cross_product(first, second));
}
OOINLINE OOScalar dot_product (Vector a, Vector b)
{
return (a.x * b.x) + (a.y * b.y) + (a.z * b.z);
@ -362,13 +325,4 @@ OOINLINE Vector normal_to_surface(Vector v1, Vector v2, Vector v3)
}
OOINLINE Vector fast_normal_to_surface(Vector v1, Vector v2, Vector v3)
{
Vector d0, d1;
d0 = vector_subtract(v2, v1);
d1 = vector_subtract(v3, v2);
return fast_cross_product(d0, d1);
}
#endif /* INCLUDED_OOMATHS_h */

View File

@ -9107,7 +9107,7 @@ static void PreloadOneSound(NSString *soundName)
Vector v_route1 = vector_subtract(p1_pos, h1_pos);
v_route1.x -= h1_pos.x; v_route1.y -= h1_pos.y; v_route1.z -= h1_pos.z;
double d_route1 = fast_magnitude(v_route1) - 60000.0; // -60km to avoid planet
double d_route1 = magnitude(v_route1) - 60000.0; // -60km to avoid planet
v_route1 = vector_normal_or_fallback(v_route1, kBasisZVector);