From 5b447a4f32380cae914d94fcc89f993ea850ccfa Mon Sep 17 00:00:00 2001 From: havoc Date: Thu, 9 Jun 2005 11:57:24 +0000 Subject: [PATCH] replaced uses of VectorNormalizeFast with VectorNormalize as it was broken on x86_64 (probably just because it used long * casts of floats) and was never much faster on modern CPUs anyway made a lot of internal functions in portals.c static, and replaced two vector subtracts and a crossproduct with TriangleNormal git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@5414 d7cf8633-e32d-0410-b094-e92efae38249 --- cg_math.h | 11 ----------- cl_particles.c | 13 ++++++------- mathlib.c | 13 +------------ mathlib.h | 11 ----------- portals.c | 26 +++++++++++--------------- r_shadow.c | 4 ++-- 6 files changed, 20 insertions(+), 58 deletions(-) diff --git a/cg_math.h b/cg_math.h index e3dcece6..d8c539e1 100644 --- a/cg_math.h +++ b/cg_math.h @@ -80,17 +80,6 @@ extern vec3_t vec3_origin; #define VectorScale(in, scale, out) ((out)[0] = (in)[0] * (scale),(out)[1] = (in)[1] * (scale),(out)[2] = (in)[2] * (scale)) #define VectorCompare(a,b) (((a)[0]==(b)[0])&&((a)[1]==(b)[1])&&((a)[2]==(b)[2])) #define VectorMA(a, scale, b, c) ((c)[0] = (a)[0] + (scale) * (b)[0],(c)[1] = (a)[1] + (scale) * (b)[1],(c)[2] = (a)[2] + (scale) * (b)[2]) -#define VectorNormalizeFast(_v)\ -{\ - float _y, _number;\ - _number = DotProduct(_v, _v);\ - if (_number != 0.0)\ - {\ - *((long *)&_y) = 0x5f3759df - ((* (long *) &_number) >> 1);\ - _y = _y * (1.5f - (_number * 0.5f * _y * _y));\ - VectorScale(_v, _y, _v);\ - }\ -} #define VectorRandom(v) {do{(v)[0] = CGVM_RandomRange(-1, 1);(v)[1] = CGVM_RandomRange(-1, 1);(v)[2] = CGVM_RandomRange(-1, 1);}while(DotProduct(v, v) > 1);} void AngleVectors (vec3_t angles, vec3_t forward, vec3_t right, vec3_t up); diff --git a/cl_particles.c b/cl_particles.c index 90f6fda6..2e5d5259 100644 --- a/cl_particles.c +++ b/cl_particles.c @@ -25,7 +25,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define NUMVERTEXNORMALS 162 siextern float r_avertexnormals[NUMVERTEXNORMALS][3]; #define m_bytenormals r_avertexnormals -#define VectorNormalizeFast VectorNormalize #define CL_PointQ1Contents(v) (Mod_PointInLeaf(v,cl.worldmodel)->contents) typedef unsigned char qbyte; #define cl_stainmaps.integer 0 @@ -46,16 +45,16 @@ void R_CalcBeam_Vertex3f (float *vert, vec3_t org1, vec3_t org2, float width) vec3_t right1, right2, diff, normal; VectorSubtract (org2, org1, normal); - VectorNormalizeFast (normal); + VectorNormalize (normal); // calculate 'right' vector for start VectorSubtract (r_vieworigin, org1, diff); - VectorNormalizeFast (diff); + VectorNormalize (diff); CrossProduct (normal, diff, right1); // calculate 'right' vector for end VectorSubtract (r_vieworigin, org2, diff); - VectorNormalizeFast (diff); + VectorNormalize (diff); CrossProduct (normal, diff, right2); vert[ 0] = org1[0] + width * right1[0]; @@ -145,7 +144,7 @@ void VectorVectors(const vec3_t forward, vec3_t right, vec3_t up) right[0] -= d * forward[0]; right[1] -= d * forward[1]; right[2] -= d * forward[2]; - VectorNormalizeFast(right); + VectorNormalize(right); CrossProduct(right, forward, up); } #if QW @@ -977,7 +976,7 @@ void CL_Stardust (vec3_t mins, vec3_t maxs, int count) o[1] = lhrandom(mins[1], maxs[1]); o[2] = lhrandom(mins[2], maxs[2]); VectorSubtract(o, center, v); - VectorNormalizeFast(v); + VectorNormalize(v); VectorScale(v, 100, v); v[2] += sv_gravity.value * 0.15f; particle(particletype + pt_static, 0x903010, 0xFFD030, tex_particle, 1.5, lhrandom(64, 128) / cl_particles_quality.value, 128 / cl_particles_quality.value, 1, 0, o[0], o[1], o[2], v[0], v[1], v[2], 0.2); @@ -2011,7 +2010,7 @@ void R_DrawParticleCallback(const void *calldata1, int calldata2) { R_CalcBeam_Vertex3f(particle_vertex3f, p->org, p->vel, size); VectorSubtract(p->vel, p->org, up); - VectorNormalizeFast(up); + VectorNormalize(up); v[0] = DotProduct(p->org, up) * (1.0f / 64.0f); v[1] = DotProduct(p->vel, up) * (1.0f / 64.0f); particle_texcoord2f[0] = 1;particle_texcoord2f[1] = v[0]; diff --git a/mathlib.c b/mathlib.c index 60a1a29d..cdbe0364 100644 --- a/mathlib.c +++ b/mathlib.c @@ -141,17 +141,6 @@ void ByteToNormal(qbyte num, vec3_t n) VectorClear(n); // FIXME: complain? } -float Q_RSqrt(float number) -{ - float y; - - if (number == 0.0f) - return 0.0f; - - *((int *)&y) = 0x5f3759df - ((* (int *) &number) >> 1); - return y * (1.5f - (number * 0.5f * y * y)); -} - // assumes "src" is normalized void PerpendicularVector( vec3_t dst, const vec3_t src ) { @@ -216,7 +205,7 @@ void VectorVectors(const vec3_t forward, vec3_t right, vec3_t up) d = DotProduct(forward, right); VectorMA(right, -d, forward, right); - VectorNormalizeFast(right); + VectorNormalize(right); CrossProduct(right, forward, up); } diff --git a/mathlib.h b/mathlib.h index 30d5b1d7..d5f6ee07 100644 --- a/mathlib.h +++ b/mathlib.h @@ -83,17 +83,6 @@ extern vec3_t vec3_origin; #define VectorMAM(scale1, b1, scale2, b2, c) ((c)[0] = (scale1) * (b1)[0] + (scale2) * (b2)[0],(c)[1] = (scale1) * (b1)[1] + (scale2) * (b2)[1],(c)[2] = (scale1) * (b1)[2] + (scale2) * (b2)[2]) #define VectorMAMAM(scale1, b1, scale2, b2, scale3, b3, c) ((c)[0] = (scale1) * (b1)[0] + (scale2) * (b2)[0] + (scale3) * (b3)[0],(c)[1] = (scale1) * (b1)[1] + (scale2) * (b2)[1] + (scale3) * (b3)[1],(c)[2] = (scale1) * (b1)[2] + (scale2) * (b2)[2] + (scale3) * (b3)[2]) #define VectorMAMAMAM(scale1, b1, scale2, b2, scale3, b3, scale4, b4, c) ((c)[0] = (scale1) * (b1)[0] + (scale2) * (b2)[0] + (scale3) * (b3)[0] + (scale4) * (b4)[0],(c)[1] = (scale1) * (b1)[1] + (scale2) * (b2)[1] + (scale3) * (b3)[1] + (scale4) * (b4)[1],(c)[2] = (scale1) * (b1)[2] + (scale2) * (b2)[2] + (scale3) * (b3)[2] + (scale4) * (b4)[2]) -#define VectorNormalizeFast(_v)\ -{\ - float _y, _number;\ - _number = DotProduct(_v, _v);\ - if (_number != 0.0)\ - {\ - *((long *)&_y) = 0x5f3759df - ((* (long *) &_number) >> 1);\ - _y = _y * (1.5f - (_number * 0.5f * _y * _y));\ - VectorScale(_v, _y, _v);\ - }\ -} #define VectorRandom(v) do{(v)[0] = lhrandom(-1, 1);(v)[1] = lhrandom(-1, 1);(v)[2] = lhrandom(-1, 1);}while(DotProduct(v, v) > 1) #define VectorLerp(v1,lerp,v2,c) ((c)[0] = (v1)[0] + (lerp) * ((v2)[0] - (v1)[0]), (c)[1] = (v1)[1] + (lerp) * ((v2)[1] - (v1)[1]), (c)[2] = (v1)[2] + (lerp) * ((v2)[2] - (v1)[2])) #define VectorReflect(a,r,b,c) do{double d;d = DotProduct((a), (b)) * -(1.0 + (r));VectorMA((a), (d), (b), (c));}while(0) diff --git a/portals.c b/portals.c index 88896dd7..6df89426 100644 --- a/portals.c +++ b/portals.c @@ -13,7 +13,7 @@ static float portaltemppoints2[256][3]; static int portal_markid = 0; static float boxpoints[4*3]; -int Portal_PortalThroughPortalPlanes(tinyplane_t *clipplanes, int clipnumplanes, float *targpoints, int targnumpoints, float *out, int maxpoints) +static int Portal_PortalThroughPortalPlanes(tinyplane_t *clipplanes, int clipnumplanes, float *targpoints, int targnumpoints, float *out, int maxpoints) { int numpoints, i; if (targnumpoints < 3) @@ -35,7 +35,7 @@ int Portal_PortalThroughPortalPlanes(tinyplane_t *clipplanes, int clipnumplanes, return numpoints; } -int Portal_RecursiveFlowSearch (mleaf_t *leaf, vec3_t eye, int firstclipplane, int numclipplanes) +static int Portal_RecursiveFlowSearch (mleaf_t *leaf, vec3_t eye, int firstclipplane, int numclipplanes) { mportal_t *p; int newpoints, i, prev; @@ -71,7 +71,7 @@ int Portal_RecursiveFlowSearch (mleaf_t *leaf, vec3_t eye, int firstclipplane, i VectorSubtract(eye, portaltemppoints2[i], v1); VectorSubtract(portaltemppoints2[prev], portaltemppoints2[i], v2); CrossProduct(v1, v2, newplanes[i].normal); - VectorNormalizeFast(newplanes[i].normal); + VectorNormalize(newplanes[i].normal); newplanes[i].dist = DotProduct(eye, newplanes[i].normal); if (DotProduct(newplanes[i].normal, center) <= newplanes[i].dist) { @@ -96,7 +96,7 @@ int Portal_RecursiveFlowSearch (mleaf_t *leaf, vec3_t eye, int firstclipplane, i return false; } -void Portal_PolygonRecursiveMarkLeafs(mnode_t *node, float *polypoints, int numpoints) +static void Portal_PolygonRecursiveMarkLeafs(mnode_t *node, float *polypoints, int numpoints) { int i, front; float *p; @@ -158,7 +158,7 @@ int Portal_CheckPolygon(model_t *model, vec3_t eye, float *polypoints, int numpo VectorSubtract(eye, (&polypoints[i * 3]), v1); VectorSubtract((&polypoints[prev * 3]), (&polypoints[i * 3]), v2); CrossProduct(v1, v2, portalplanes[i].normal); - VectorNormalizeFast(portalplanes[i].normal); + VectorNormalize(portalplanes[i].normal); portalplanes[i].dist = DotProduct(eye, portalplanes[i].normal); if (DotProduct(portalplanes[i].normal, center) <= portalplanes[i].dist) { @@ -265,8 +265,6 @@ int Portal_CheckBox(model_t *model, vec3_t eye, vec3_t a, vec3_t b) return false; } -vec3_t trianglepoints[3]; - typedef struct portalrecursioninfo_s { int exact; @@ -286,7 +284,7 @@ typedef struct portalrecursioninfo_s } portalrecursioninfo_t; -void Portal_RecursiveFlow (portalrecursioninfo_t *info, mleaf_t *leaf, int firstclipplane, int numclipplanes) +static void Portal_RecursiveFlow (portalrecursioninfo_t *info, mleaf_t *leaf, int firstclipplane, int numclipplanes) { mportal_t *p; int newpoints, i, prev; @@ -382,18 +380,16 @@ void Portal_RecursiveFlow (portalrecursioninfo_t *info, mleaf_t *leaf, int first VectorAdd(center, portaltemppoints2[i], center); // ixtable is a 1.0f / N table VectorScale(center, ixtable[newpoints], center); - // calculate the planes, and make sure the polygon can see it's own center + // calculate the planes, and make sure the polygon can see its own center newplanes = &portalplanes[firstclipplane + numclipplanes]; for (prev = newpoints - 1, i = 0;i < newpoints;prev = i, i++) { - VectorSubtract(portaltemppoints2[prev], portaltemppoints2[i], v1); - VectorSubtract(info->eye, portaltemppoints2[i], v2); - CrossProduct(v1, v2, newplanes[i].normal); - VectorNormalizeFast(newplanes[i].normal); + TriangleNormal(portaltemppoints2[prev], portaltemppoints2[i], info->eye, newplanes[i].normal); + VectorNormalize(newplanes[i].normal); newplanes[i].dist = DotProduct(info->eye, newplanes[i].normal); if (DotProduct(newplanes[i].normal, center) <= newplanes[i].dist) { - // polygon can't see it's own center, discard and use parent portal + // polygon can't see its own center, discard and use parent portal break; } } @@ -406,7 +402,7 @@ void Portal_RecursiveFlow (portalrecursioninfo_t *info, mleaf_t *leaf, int first } } -void Portal_RecursiveFindLeafForFlow(portalrecursioninfo_t *info, mnode_t *node) +static void Portal_RecursiveFindLeafForFlow(portalrecursioninfo_t *info, mnode_t *node) { if (node->plane) { diff --git a/r_shadow.c b/r_shadow.c index 523457a0..b6f15c8d 100644 --- a/r_shadow.c +++ b/r_shadow.c @@ -1556,9 +1556,9 @@ static void R_Shadow_GenTexCoords_Specular_NormalCubeMap(float *out3f, int numve for (i = 0;i < numverts;i++, vertex3f += 3, svector3f += 3, tvector3f += 3, normal3f += 3, out3f += 3) { VectorSubtract(vertex3f, relativelightorigin, lightdir); - VectorNormalizeFast(lightdir); + VectorNormalize(lightdir); VectorSubtract(vertex3f, relativeeyeorigin, eyedir); - VectorNormalizeFast(eyedir); + VectorNormalize(eyedir); VectorAdd(lightdir, eyedir, halfdir); // the cubemap normalizes this for us out3f[0] = DotProduct(svector3f, halfdir); -- 2.39.2