]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
speedups to R_WorldNode, and some shrinkage on the surface struct
authorlordhavoc <lordhavoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 17 Nov 2000 10:33:37 +0000 (10:33 +0000)
committerlordhavoc <lordhavoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 17 Nov 2000 10:33:37 +0000 (10:33 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@78 d7cf8633-e32d-0410-b094-e92efae38249

gl_rmain.c
gl_rsurf.c
glquake.h
model_brush.h

index e880dbd5dfcef5e92b96301a7d0c340540a39778..94cf4e36b94a8056e34c5eb404a8ee80f4da0717 100644 (file)
@@ -63,7 +63,7 @@ mleaf_t               *r_viewleaf, *r_oldviewleaf;
 
 texture_t      *r_notexture_mip;
 
 
 texture_t      *r_notexture_mip;
 
-int            d_lightstylevalue[256]; // 8.8 fraction of base light value
+unsigned short d_lightstylevalue[256]; // 8.8 fraction of base light value
 
 
 void R_MarkLeaves (void);
 
 
 void R_MarkLeaves (void);
index be07117ce096a3366b1ecc6e6ee739c88983d029..3d0b4c2d5fd086b5f081d648bf8ff40731a3a4ff 100644 (file)
@@ -821,6 +821,12 @@ e->angles[0] = -e->angles[0];      // stupid quake bug
 
 void R_StoreEfrags (efrag_t **ppefrag);
 
 
 void R_StoreEfrags (efrag_t **ppefrag);
 
+struct nodestack_s
+{
+       int side;
+       mnode_t *node;
+} nodestack[8192];
+
 /*
 ================
 R_WorldNode
 /*
 ================
 R_WorldNode
@@ -828,14 +834,14 @@ R_WorldNode
 */
 void R_WorldNode ()
 {
 */
 void R_WorldNode ()
 {
-       int             c, side, s = 0;
-       double  dot;
-       struct
-       {
-               double dot;
-               mnode_t *node;
-       } nodestack[8192];
+       int side, texsort, vertex;
+       struct nodestack_s *nstack;
        mnode_t *node;
        mnode_t *node;
+       mleaf_t *pleaf;
+       msurface_t *surf, *endsurf, **mark, **endmark;
+       nstack = nodestack;
+       texsort = gl_texsort.value;
+       vertex = gl_vertex.value;
 
        if (!(node = cl.worldmodel->nodes))
                return;
 
        if (!(node = cl.worldmodel->nodes))
                return;
@@ -847,19 +853,19 @@ void R_WorldNode ()
                {
                        if (node->contents != CONTENTS_SOLID)
                        {
                {
                        if (node->contents != CONTENTS_SOLID)
                        {
-                               mleaf_t         *pleaf;
                                pleaf = (mleaf_t *)node;
 
                                c_leafs++;
                                pleaf = (mleaf_t *)node;
 
                                c_leafs++;
-                               if ((c = pleaf->nummarksurfaces))
+                               if (pleaf->nummarksurfaces)
                                {
                                {
-                                       msurface_t      **mark;
                                        mark = pleaf->firstmarksurface;
                                        mark = pleaf->firstmarksurface;
+                                       endmark = mark + pleaf->nummarksurfaces;
                                        do
                                        {
                                                (*mark)->visframe = r_framecount;
                                                mark++;
                                        do
                                        {
                                                (*mark)->visframe = r_framecount;
                                                mark++;
-                                       } while (--c);
+                                       }
+                                       while (mark < endmark);
                                }
 
                                // deal with model fragments in this leaf
                                }
 
                                // deal with model fragments in this leaf
@@ -867,69 +873,89 @@ void R_WorldNode ()
                                        R_StoreEfrags (&pleaf->efrags);
                        }
 
                                        R_StoreEfrags (&pleaf->efrags);
                        }
 
-                       if (!s)
+                       if (nstack <= nodestack)
                                break;
                                break;
-                       node = nodestack[--s].node;
-                       dot = nodestack[s].dot;
+                       nstack--;
+                       node = nstack->node;
+                       side = nstack->side;
                        goto loc0;
                }
 
                c_nodes++;
 
                        goto loc0;
                }
 
                c_nodes++;
 
-       // node is just a decision point, so go down the apropriate sides
+               // node is just a decision point, so go down the apropriate sides
 
 
-       // find which side of the node we are on
-               dot = (node->plane->type < 3 ? modelorg[node->plane->type] : DotProduct (modelorg, node->plane->normal)) - node->plane->dist;
+               // find which side of the node we are on
+               side = PlaneDist(modelorg, node->plane) < node->plane->dist;
 
 
-       // recurse down the children, front side first
-               side = dot < 0;
+               // recurse down the children, front side first
                if (node->children[side]->visframe == r_visframecount && R_NotCulledBox(node->children[side]->minmaxs, node->children[side]->minmaxs+3))
                {
                if (node->children[side]->visframe == r_visframecount && R_NotCulledBox(node->children[side]->minmaxs, node->children[side]->minmaxs+3))
                {
-                       nodestack[s].node = node;
-                       nodestack[s++].dot = dot;
+                       nstack->node = node;
+                       nstack->side = !side; // go down back side when we come back up
+                       nstack++;
                        node = node->children[side];
                        continue;
                }
                        node = node->children[side];
                        continue;
                }
+               side = !side;
 loc0:
 
 loc0:
 
-               // backside
-               side = dot >= 0;
        // draw stuff
        // draw stuff
-               if ((c = node->numsurfaces))
+               if (node->numsurfaces)
                {
                {
-                       msurface_t      *surf;
                        surf = cl.worldmodel->surfaces + node->firstsurface;
                        surf = cl.worldmodel->surfaces + node->firstsurface;
+                       endsurf = surf + node->numsurfaces;
 
 
-                       if (side)
+                       if (texsort)
                        {
                        {
-                               for (;c;c--, surf++)
+                               if (side)
                                {
                                {
-                                       if (surf->visframe == r_framecount && !(surf->flags & SURF_PLANEBACK))
+                                       do
                                        {
                                        {
-                                               if (gl_texsort.value)
+                                               if (surf->visframe == r_framecount && !(surf->flags & SURF_PLANEBACK))
                                                {
                                                        surf->texturechain = surf->texinfo->texture->texturechain;
                                                        surf->texinfo->texture->texturechain = surf;
                                                }
                                                {
                                                        surf->texturechain = surf->texinfo->texture->texturechain;
                                                        surf->texinfo->texture->texturechain = surf;
                                                }
-                                               else
-                                                       R_DrawSurf(surf, false, gl_vertex.value);
+                                               surf++;
                                        }
                                        }
+                                       while (surf < endsurf);
                                }
                                }
-                       }
-                       else
-                       {
-                               for (;c;c--, surf++)
+                               else
                                {
                                {
-                                       if (surf->visframe == r_framecount && (surf->flags & SURF_PLANEBACK))
+                                       do
                                        {
                                        {
-                                               if (gl_texsort.value)
+                                               if (surf->visframe == r_framecount && (surf->flags & SURF_PLANEBACK))
                                                {
                                                        surf->texturechain = surf->texinfo->texture->texturechain;
                                                        surf->texinfo->texture->texturechain = surf;
                                                }
                                                {
                                                        surf->texturechain = surf->texinfo->texture->texturechain;
                                                        surf->texinfo->texture->texturechain = surf;
                                                }
-                                               else
-                                                       R_DrawSurf(surf, false, gl_vertex.value);
+                                               surf++;
+                                       }
+                                       while (surf < endsurf);
+                               }
+                       }
+                       else
+                       {
+                               if (side)
+                               {
+                                       do
+                                       {
+                                               if (surf->visframe == r_framecount && !(surf->flags & SURF_PLANEBACK))
+                                                       R_DrawSurf(surf, false, vertex);
+                                               surf++;
+                                       }
+                                       while (surf < endsurf);
+                               }
+                               else
+                               {
+                                       do
+                                       {
+                                               if (surf->visframe == r_framecount && (surf->flags & SURF_PLANEBACK))
+                                                       R_DrawSurf(surf, false, vertex);
+                                               surf++;
                                        }
                                        }
+                                       while (surf < endsurf);
                                }
                        }
                }
                                }
                        }
                }
@@ -941,10 +967,11 @@ loc0:
                        continue;
                }
 
                        continue;
                }
 
-               if (!s)
+               if (nstack <= nodestack)
                        break;
                        break;
-               node = nodestack[--s].node;
-               dot = nodestack[s].dot;
+               nstack--;
+               node = nstack->node;
+               side = nstack->side;
                goto loc0;
        }
 }
                goto loc0;
        }
 }
@@ -1048,7 +1075,7 @@ void R_MarkLeaves (void)
 */
 
 // returns a texture number and the position inside it
 */
 
 // returns a texture number and the position inside it
-int AllocBlock (int w, int h, int *x, int *y)
+int AllocBlock (int w, int h, short *x, short *y)
 {
        int             i, j;
        int             best, best2;
 {
        int             i, j;
        int             best, best2;
index bab055b6509632a3b976c0aee5b4c548682a1c16..d58f2be504e07e5ada8ef806eb730fc6b16d892f 100644 (file)
--- a/glquake.h
+++ b/glquake.h
@@ -100,7 +100,7 @@ extern      vec3_t  r_origin;
 extern refdef_t        r_refdef;
 extern mleaf_t         *r_viewleaf, *r_oldviewleaf;
 extern texture_t       *r_notexture_mip;
 extern refdef_t        r_refdef;
 extern mleaf_t         *r_viewleaf, *r_oldviewleaf;
 extern texture_t       *r_notexture_mip;
-extern int             d_lightstylevalue[256]; // 8.8 fraction of base light value
+extern unsigned short  d_lightstylevalue[256]; // 8.8 fraction of base light value
 
 extern qboolean        envmap;
 
 
 extern qboolean        envmap;
 
index 49db6dae69ba88cf68b96d85bb2a6e23803fd86a..ec31becdfda2d75e5ee1400cf58b1a159fad3b25 100644 (file)
@@ -118,7 +118,7 @@ typedef struct msurface_s
        short           texturemins[2];
        short           extents[2];
 
        short           texturemins[2];
        short           extents[2];
 
-       int                     light_s, light_t;       // gl lightmap coordinates
+       short           light_s, light_t;       // gl lightmap coordinates
 
        glpoly_t        *polys;                         // multiple if warped
        struct  msurface_s      *texturechain;
 
        glpoly_t        *polys;                         // multiple if warped
        struct  msurface_s      *texturechain;
@@ -133,9 +133,8 @@ typedef struct msurface_s
 
        int                     lightmaptexturenum;
        byte            styles[MAXLIGHTMAPS];
 
        int                     lightmaptexturenum;
        byte            styles[MAXLIGHTMAPS];
-       int                     cached_light[MAXLIGHTMAPS];     // values currently used in lightmap
-//     qboolean        cached_dlight;                          // true if dynamic light in cache
-       qboolean        cached_lighthalf;                       // LordHavoc: to cause lightmap to be rerendered when lighthalf changes
+       unsigned short  cached_light[MAXLIGHTMAPS];     // values currently used in lightmap
+       int                     cached_lighthalf;                       // LordHavoc: to cause lightmap to be rerendered when lighthalf changes
        float           cached_ambient;                         // LordHavoc: rerender lightmaps when r_ambient changes
        byte            *samples;               // [numstyles*surfsize]
 } msurface_t;
        float           cached_ambient;                         // LordHavoc: rerender lightmaps when r_ambient changes
        byte            *samples;               // [numstyles*surfsize]
 } msurface_t;