moved ixtable definition and initialization code to mathlib (and added Mathlib_Init...
[xonotic/darkplaces.git] / gl_rmain.c
index 37052fd939e2e81255159cc6fc8b8370479d5d91..f11072eb68f8b08172ad354c7dd510e7c50c0c52 100644 (file)
@@ -32,7 +32,7 @@ mplane_t      frustum[4];
 
 int                    c_brush_polys, c_alias_polys, c_light_polys, c_faces, c_nodes, c_leafs, c_models, c_bmodels, c_sprites, c_particles, c_dlights;
 
-qboolean       envmap;                         // true during envmap command capture 
+qboolean       envmap;                         // true during envmap command capture
 
 // LordHavoc: moved all code related to particles into r_part.c
 //int                  particletexture;        // little dot for particles
@@ -58,34 +58,34 @@ mleaf_t             *r_viewleaf, *r_oldviewleaf;
 
 unsigned short d_lightstylevalue[256]; // 8.8 fraction of base light value
 
-float ixtable[4096];
-
 void R_MarkLeaves (void);
 
-//cvar_t       r_norefresh = {"r_norefresh","0"};
-cvar_t r_drawentities = {"r_drawentities","1"};
-cvar_t r_drawviewmodel = {"r_drawviewmodel","1"};
-cvar_t r_speeds = {"r_speeds","0"};
-cvar_t r_speeds2 = {"r_speeds2","0"};
-cvar_t r_fullbright = {"r_fullbright","0"};
-//cvar_t       r_lightmap = {"r_lightmap","0"};
-cvar_t r_wateralpha = {"r_wateralpha","1"};
-cvar_t r_dynamic = {"r_dynamic","1"};
-cvar_t r_waterripple = {"r_waterripple","0"};
-cvar_t r_fullbrights = {"r_fullbrights", "1"};
-
-cvar_t gl_lightmode = {"gl_lightmode", "1", true}; // LordHavoc: overbright lighting
-//cvar_t       r_dynamicbothsides = {"r_dynamicbothsides", "1"}; // LordHavoc: can disable dynamic lighting of backfaces, but quake maps are weird so it doesn't always work right...
-cvar_t r_farclip = {"r_farclip", "6144"};
-
-cvar_t gl_fogenable = {"gl_fogenable", "0"};
-cvar_t gl_fogdensity = {"gl_fogdensity", "0.25"};
-cvar_t gl_fogred = {"gl_fogred","0.3"};
-cvar_t gl_foggreen = {"gl_foggreen","0.3"};
-cvar_t gl_fogblue = {"gl_fogblue","0.3"};
-cvar_t gl_fogstart = {"gl_fogstart", "0"};
-cvar_t gl_fogend = {"gl_fogend","0"};
-cvar_t glfog = {"glfog", "0"};
+//cvar_t       r_norefresh = {0, "r_norefresh","0"};
+cvar_t r_drawentities = {0, "r_drawentities","1"};
+cvar_t r_drawviewmodel = {0, "r_drawviewmodel","1"};
+cvar_t r_speeds = {0, "r_speeds","0"};
+cvar_t r_speeds2 = {0, "r_speeds2","0"};
+cvar_t r_fullbright = {0, "r_fullbright","0"};
+//cvar_t       r_lightmap = {0, "r_lightmap","0"};
+cvar_t r_wateralpha = {CVAR_SAVE, "r_wateralpha","1"};
+cvar_t r_dynamic = {CVAR_SAVE, "r_dynamic","1"};
+cvar_t r_waterripple = {CVAR_SAVE, "r_waterripple","0"};
+cvar_t r_fullbrights = {CVAR_SAVE, "r_fullbrights", "1"};
+
+cvar_t gl_lightmode = {CVAR_SAVE, "gl_lightmode", "1"}; // LordHavoc: overbright lighting
+//cvar_t       r_dynamicbothsides = {CVAR_SAVE, "r_dynamicbothsides", "1"}; // LordHavoc: can disable dynamic lighting of backfaces, but quake maps are weird so it doesn't always work right...
+cvar_t r_farclip = {0, "r_farclip", "6144"}; // FIXME: make this go away (calculate based on farthest visible object/polygon)
+
+cvar_t gl_fogenable = {0, "gl_fogenable", "0"};
+cvar_t gl_fogdensity = {0, "gl_fogdensity", "0.25"};
+cvar_t gl_fogred = {0, "gl_fogred","0.3"};
+cvar_t gl_foggreen = {0, "gl_foggreen","0.3"};
+cvar_t gl_fogblue = {0, "gl_fogblue","0.3"};
+cvar_t gl_fogstart = {0, "gl_fogstart", "0"};
+cvar_t gl_fogend = {0, "gl_fogend","0"};
+cvar_t glfog = {0, "glfog", "0"};
+
+cvar_t r_ser = {CVAR_SAVE, "r_ser", "1"};
 
 /*
 int R_VisibleCullBox (vec3_t mins, vec3_t maxs)
@@ -109,9 +109,9 @@ loc0:
                node = nodestack[--stack];
                goto loc0;
        }
-       
+
        sides = BOX_ON_PLANE_SIDE(mins, maxs, node->plane);
-       
+
 // recurse down the contacted sides
        if (sides & 1)
        {
@@ -244,7 +244,7 @@ void FOG_registercvars(void)
                Cvar_RegisterVariable (&gl_fogenable);
                Cvar_RegisterVariable (&gl_fogdensity);
                Cvar_RegisterVariable (&gl_fogred);
-               Cvar_RegisterVariable (&gl_foggreen); 
+               Cvar_RegisterVariable (&gl_foggreen);
                Cvar_RegisterVariable (&gl_fogblue);
                Cvar_RegisterVariable (&gl_fogstart);
                Cvar_RegisterVariable (&gl_fogend);
@@ -265,12 +265,7 @@ void gl_main_newmap(void)
 
 void GL_Main_Init(void)
 {
-       int a;
        FOG_registercvars();
-       // 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;
        Cvar_RegisterVariable (&r_drawentities);
        Cvar_RegisterVariable (&r_drawviewmodel);
        Cvar_RegisterVariable (&r_speeds);
@@ -288,6 +283,7 @@ void GL_Main_Init(void)
 //     if (gl_vendor && strstr(gl_vendor, "3Dfx"))
 //             gl_lightmode.value = 0;
        Cvar_RegisterVariable (&r_fullbright);
+       Cvar_RegisterVariable (&r_ser);
        R_RegisterModule("GL_Main", gl_main_start, gl_main_shutdown, gl_main_newmap);
 }
 
@@ -304,6 +300,7 @@ extern void R_Particles_Init(void);
 extern void R_Explosion_Init(void);
 extern void CL_Effects_Init(void);
 extern void R_Clip_Init(void);
+extern void ui_init(void);
 
 void Render_Init(void)
 {
@@ -322,6 +319,7 @@ void Render_Init(void)
        R_Explosion_Init();
        CL_Effects_Init();
        R_Decals_Init();
+       ui_init();
        R_Modules_Start();
 }
 
@@ -474,13 +472,26 @@ void R_AddModelEntities (void)
                {
                        VectorAdd(currententity->render.origin, currententity->render.model->mins, mins);
                        VectorAdd(currententity->render.origin, currententity->render.model->maxs, maxs);
-                       R_Clip_AddBox(mins, maxs, R_Entity_Callback, currententity, NULL);
+                       if (r_ser.value)
+                               R_Clip_AddBox(mins, maxs, R_Entity_Callback, currententity, NULL);
+                       else if (R_NotCulledBox(mins, maxs))
+                               currententity->render.visframe = r_framecount;
                }
                else if (currententity->render.model->type == mod_sprite)
                {
                        R_LerpUpdate(currententity);
-                       R_LerpAnimation(currententity->render.model, currententity->render.frame1, currententity->render.frame2, currententity->render.frame1start, currententity->render.frame2start, currententity->render.framelerp, blend);
-                       R_ClipSprite(currententity, blend);
+                       if (r_ser.value)
+                       {
+                               R_LerpAnimation(currententity->render.model, currententity->render.frame1, currententity->render.frame2, currententity->render.frame1start, currententity->render.frame2start, currententity->render.framelerp, blend);
+                               R_ClipSprite(currententity, blend);
+                       }
+                       else
+                       {
+                               VectorAdd(currententity->render.origin, currententity->render.model->mins, mins);
+                               VectorAdd(currententity->render.origin, currententity->render.model->maxs, maxs);
+                               if (R_NotCulledBox(mins, maxs))
+                                       currententity->render.visframe = r_framecount;
+                       }
                }
        }
 }