- // LordHavoc: portal-passage worldnode with PVS;
- // follows portals leading outward from viewleaf, does not venture
- // offscreen or into leafs that are not visible, faster than Quake's
- // RecursiveWorldNode
- leafstack[0] = viewleaf;
- leafstackpos = 1;
- memset(leafvisited, 0, r_refdef.worldmodel->brushq1.num_leafs);
- while (leafstackpos)
- {
- c_leafs++;
- leaf = leafstack[--leafstackpos];
- leafvisited[leaf - r_refdef.worldmodel->brushq1.data_leafs] = 1;
- // draw any surfaces bounding this leaf
- if (leaf->nummarksurfaces)
- for (i = 0, mark = leaf->firstmarksurface;i < leaf->nummarksurfaces;i++, mark++)
- r_worldsurfacevisible[*mark] = true;
- // follow portals into other leafs
- for (p = leaf->portals;p;p = p->next)
- if (DotProduct(r_vieworigin, p->plane.normal) < (p->plane.dist + 1) && !leafvisited[p->past - r_refdef.worldmodel->brushq1.data_leafs] && CHECKPVSBIT(r_pvsbits, p->past->clusterindex) && !R_CullBox(p->mins, p->maxs))
- leafstack[leafstackpos++] = p->past;
+ int i, j, *mark;
+ mleaf_t *leaf;
+ mleaf_t *viewleaf;
+ int leafstackpos;
+ mportal_t *p;
+ mleaf_t *leafstack[8192];
+ qbyte leafvisited[32768];
+
+ viewleaf = model->brushq1.PointInLeaf(model, r_vieworigin);
+ if (!viewleaf)
+ return;
+
+ memset(r_worldsurfacevisible, 0, r_refdef.worldmodel->brushq1.numsurfaces);
+ if (viewleaf->clusterindex < 0 || r_surfaceworldnode.integer)
+ {
+ // equivilant to quake's RecursiveWorldNode but faster and more effective
+ for (j = 0, leaf = model->brushq1.data_leafs;j < model->brushq1.num_leafs;j++, leaf++)
+ {
+ if (CHECKPVSBIT(r_pvsbits, leaf->clusterindex) && !R_CullBox (leaf->mins, leaf->maxs))
+ {
+ c_leafs++;
+ if (leaf->nummarksurfaces)
+ for (i = 0, mark = leaf->firstmarksurface;i < leaf->nummarksurfaces;i++, mark++)
+ r_worldsurfacevisible[*mark] = true;
+ }
+ }
+ }
+ else
+ {
+ // LordHavoc: portal-passage worldnode with PVS;
+ // follows portals leading outward from viewleaf, does not venture
+ // offscreen or into leafs that are not visible, faster than Quake's
+ // RecursiveWorldNode
+ leafstack[0] = viewleaf;
+ leafstackpos = 1;
+ memset(leafvisited, 0, r_refdef.worldmodel->brushq1.num_leafs);
+ while (leafstackpos)
+ {
+ c_leafs++;
+ leaf = leafstack[--leafstackpos];
+ leafvisited[leaf - r_refdef.worldmodel->brushq1.data_leafs] = 1;
+ // draw any surfaces bounding this leaf
+ if (leaf->nummarksurfaces)
+ for (i = 0, mark = leaf->firstmarksurface;i < leaf->nummarksurfaces;i++, mark++)
+ r_worldsurfacevisible[*mark] = true;
+ // follow portals into other leafs
+ for (p = leaf->portals;p;p = p->next)
+ if (DotProduct(r_vieworigin, p->plane.normal) < (p->plane.dist + 1) && !leafvisited[p->past - r_refdef.worldmodel->brushq1.data_leafs] && CHECKPVSBIT(r_pvsbits, p->past->clusterindex) && !R_CullBox(p->mins, p->maxs))
+ leafstack[leafstackpos++] = p->past;
+ }