added R_BoxVisible (used instead of VIS_CullBox)
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 8 Mar 2005 15:20:07 +0000 (15:20 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 8 Mar 2005 15:20:07 +0000 (15:20 +0000)
rewrote portions of R_MarkEntities to be more efficient and more sane (and to use R_BoxVisible obviously)

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@5065 d7cf8633-e32d-0410-b094-e92efae38249

gl_rmain.c
render.h

index 72dd022..253ad26 100644 (file)
@@ -418,16 +418,67 @@ int R_CullBox(const vec3_t mins, const vec3_t maxs)
        return false;
 }
 
+int R_BoxVisible(const vec3_t mins, const vec3_t maxs)
+{
+       int side, nodestackindex = 0;
+       mnode_t *node, *nodestack[1024];
+       if (R_CullBox(mins, maxs))
+               return false;
+       if (!r_refdef.worldmodel || !r_refdef.worldmodel->brush.data_nodes)
+               return true;
+       node = r_refdef.worldmodel->brush.data_nodes;
+       for (;;)
+       {
+               if (node->plane)
+               {
+                       // node - recurse down the BSP tree
+                       side = BoxOnPlaneSide(mins, maxs, node->plane) - 1;
+                       if (side < 2)
+                       {
+                               // box is on one side of plane, take that path
+                               node = node->children[side];
+                       }
+                       else
+                       {
+                               // box crosses plane, take one path and remember the other
+                               if (nodestackindex < 1024)
+                                       nodestack[nodestackindex++] = node->children[0];
+                               node = node->children[1];
+                       }
+               }
+               else
+               {
+                       // leaf - check leaf visibility
+                       if (r_worldleafvisible[(mleaf_t *)node - r_refdef.worldmodel->brush.data_leafs])
+                       {
+                               // it is visible, return immediately with the news
+                               return true;
+                       }
+                       else
+                       {
+                               // nothing to see here, try another path we didn't take earlier
+                               if (nodestackindex == 0)
+                                       break;
+                               node = nodestack[--nodestackindex];
+                       }
+               }
+       }
+       // it is not visible
+       return false;
+}
+
+
 //==================================================================================
 
 static void R_MarkEntities (void)
 {
-       int i;
+       int i, renderimask;
        entity_render_t *ent;
 
        if (!r_drawentities.integer)
                return;
 
+       renderimask = envmap ? (RENDER_EXTERIORMODEL | RENDER_VIEWMODEL) : (chase_active.integer ? 0 : RENDER_EXTERIORMODEL);
        for (i = 0;i < r_refdef.numentities;i++)
        {
                ent = r_refdef.entities[i];
@@ -436,11 +487,11 @@ static void R_MarkEntities (void)
                Matrix4x4_OriginFromMatrix(&ent->matrix, ent->origin);
                // some of the renderer still relies on scale...
                ent->scale = Matrix4x4_ScaleFromMatrix(&ent->matrix);
-               R_UpdateEntLights(ent);
-               if ((chase_active.integer || !(ent->flags & RENDER_EXTERIORMODEL))
-                && (!VIS_CullBox(ent->mins, ent->maxs) || (ent->effects & EF_NODEPTHTEST))
-                && (!envmap || !(ent->flags & (RENDER_VIEWMODEL | RENDER_EXTERIORMODEL))))
+               if (!(ent->flags & renderimask) && ((ent->effects & EF_NODEPTHTEST) ? R_CullBox(ent->mins, ent->maxs) : R_BoxVisible(ent->mins, ent->maxs)))
+               {
+                       R_UpdateEntLights(ent);
                        ent->visframe = r_framecount;
+               }
        }
 }
 
index f0169a8..268d170 100644 (file)
--- a/render.h
+++ b/render.h
@@ -149,7 +149,7 @@ void R_DrawExplosions(void);
 #define gl_alpha_format 4
 
 int R_CullBox(const vec3_t mins, const vec3_t maxs);
-#define VIS_CullBox(mins,maxs) (R_CullBox((mins), (maxs)) || (r_refdef.worldmodel && r_refdef.worldmodel->brush.BoxTouchingPVS && !r_refdef.worldmodel->brush.BoxTouchingPVS(r_refdef.worldmodel, r_pvsbits, (mins), (maxs))))
+int R_BoxVisible(const vec3_t mins, const vec3_t maxs);
 
 extern qboolean fogenabled;
 extern vec3_t fogcolor;