]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - mathlib.c
moved ixtable definition and initialization code to mathlib (and added Mathlib_Init...
[xonotic/darkplaces.git] / mathlib.c
index 8a5de30ce4fa69059cf4d97da6e97ab4fddd1903..7fdda6b3a5f22f93441f48b1a25071e71e4a2f97 100644 (file)
--- a/mathlib.c
+++ b/mathlib.c
@@ -26,6 +26,7 @@ void Sys_Error (char *error, ...);
 
 vec3_t vec3_origin = {0,0,0};
 int nanmask = 255<<23;
+float ixtable[4096];
 
 /*-----------------------------------------------------------------*/
 
@@ -40,7 +41,7 @@ float m_bytenormals[NUMVERTEXNORMALS][3] =
 {0.295242, 0.000000, 0.955423}, {0.442863, 0.238856, 0.864188}, 
 {0.162460, 0.262866, 0.951056}, {-0.681718, 0.147621, 0.716567}, 
 {-0.809017, 0.309017, 0.500000}, {-0.587785, 0.425325, 0.688191}, 
-{-0.850651, 0.525731, 0.000000}, {-0.864188, 0.442863, 0.238856}, 
+{-0.850651, 0.525731, 0.000000}, {-0.864188, 0.442863, 0.238856},
 {-0.716567, 0.681718, 0.147621}, {-0.688191, 0.587785, 0.425325}, 
 {-0.500000, 0.809017, 0.309017}, {-0.238856, 0.864188, 0.442863}, 
 {-0.425325, 0.688191, 0.587785}, {-0.716567, 0.681718, -0.147621}, 
@@ -64,7 +65,7 @@ float m_bytenormals[NUMVERTEXNORMALS][3] =
 {0.850651, 0.000000, 0.525731}, {0.864188, 0.442863, -0.238856}, 
 {0.809017, 0.309017, -0.500000}, {0.951056, 0.162460, -0.262866}, 
 {0.525731, 0.000000, -0.850651}, {0.681718, 0.147621, -0.716567}, 
-{0.681718, -0.147621, -0.716567}, {0.850651, 0.000000, -0.525731}, 
+{0.681718, -0.147621, -0.716567}, {0.850651, 0.000000, -0.525731},
 {0.809017, -0.309017, -0.500000}, {0.864188, -0.442863, -0.238856}, 
 {0.951056, -0.162460, -0.262866}, {0.147621, 0.716567, -0.681718}, 
 {0.309017, 0.500000, -0.809017}, {0.425325, 0.688191, -0.587785}, 
@@ -82,7 +83,7 @@ float m_bytenormals[NUMVERTEXNORMALS][3] =
 {0.162460, -0.262866, -0.951056}, {0.238856, -0.864188, -0.442863}, 
 {0.500000, -0.809017, -0.309017}, {0.425325, -0.688191, -0.587785}, 
 {0.716567, -0.681718, -0.147621}, {0.688191, -0.587785, -0.425325}, 
-{0.587785, -0.425325, -0.688191}, {0.000000, -0.955423, -0.295242}, 
+{0.587785, -0.425325, -0.688191}, {0.000000, -0.955423, -0.295242},
 {0.000000, -1.000000, 0.000000}, {0.262866, -0.951056, -0.162460}, 
 {0.000000, -0.850651, 0.525731}, {0.000000, -0.955423, 0.295242}, 
 {0.238856, -0.864188, 0.442863}, {0.262866, -0.951056, 0.162460}, 
@@ -106,7 +107,7 @@ float m_bytenormals[NUMVERTEXNORMALS][3] =
 {-0.850651, 0.000000, 0.525731}, {-0.955423, -0.295242, 0.000000}, 
 {-0.951056, -0.162460, 0.262866}, {-0.864188, 0.442863, -0.238856}, 
 {-0.951056, 0.162460, -0.262866}, {-0.809017, 0.309017, -0.500000}, 
-{-0.864188, -0.442863, -0.238856}, {-0.951056, -0.162460, -0.262866}, 
+{-0.864188, -0.442863, -0.238856}, {-0.951056, -0.162460, -0.262866},
 {-0.809017, -0.309017, -0.500000}, {-0.681718, 0.147621, -0.716567}, 
 {-0.681718, -0.147621, -0.716567}, {-0.850651, 0.000000, -0.525731}, 
 {-0.688191, 0.587785, -0.425325}, {-0.587785, 0.425325, -0.688191}, 
@@ -689,6 +690,27 @@ vec_t Length(vec3_t v)
        return length;
 }
 
+/*
+// LordHavoc: fixme: do more research on gcc assembly so that qftol_minushalf and result will not be considered unused
+static double qftol_minushalf = -0.5;
+
+int qftol(double v)
+{
+       int result;
+#ifdef _MSC_VER
+       __asm
+       {
+               fld             v
+               fadd    qftol_minushalf
+               fistp   result
+       }
+#else // gcc hopefully
+       asm("fldl v\n\tfaddl qftol_minushalf\n\tfistpl result");
+#endif
+       return result;
+}
+*/
+
 // LordHavoc: renamed these to Length, and made the normal ones #define
 float VectorNormalizeLength (vec3_t v)
 {
@@ -867,3 +889,14 @@ int GreatestCommonDivisor (int i1, int i2)
                return GreatestCommonDivisor (i1, i2 % i1);
        }
 }
+
+
+void Mathlib_Init(void)
+{
+       int a;
+
+       // LordHavoc: setup 1.0f / N table for quick recipricols of integers
+       ixtable[0] = 0;
+       for (a = 1;a < 4096;a++)
+               ixtable[a] = 1.0f / a;
+}
\ No newline at end of file