+ if (!(surf->flags & SURF_PLANEBACK) && !R_CullBox (surf->poly_mins, surf->poly_maxs))
+ surfacevisframes[surfnum] = r_framecount;
+ }
+#else
+ if (!R_CullBox (surf->poly_mins, surf->poly_maxs))
+ surfacevisframes[surfnum] = r_framecount;
+#endif
+ }
+}
+
+static void R_PortalWorldNode(entity_render_t *ent, mleaf_t *viewleaf)
+{
+ int c, leafstackpos, *mark, *surfacevisframes;
+#if WORLDNODECULLBACKFACES
+ int n;
+ msurface_t *surf;
+#endif
+ mleaf_t *leaf, *leafstack[8192];
+ mportal_t *p;
+ vec3_t modelorg;
+ msurface_t *surfaces;
+ // 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
+ surfaces = ent->model->surfaces;
+ surfacevisframes = ent->model->surfacevisframes;
+ Matrix4x4_Transform(&ent->inversematrix, r_origin, modelorg);
+ viewleaf->worldnodeframe = r_framecount;
+ leafstack[0] = viewleaf;
+ leafstackpos = 1;
+ while (leafstackpos)
+ {
+ c_leafs++;
+ leaf = leafstack[--leafstackpos];
+ leaf->visframe = r_framecount;
+ // draw any surfaces bounding this leaf
+ if (leaf->nummarksurfaces)
+ {
+ for (c = leaf->nummarksurfaces, mark = leaf->firstmarksurface;c;c--)
+ {
+#if WORLDNODECULLBACKFACES
+ n = *mark++;
+ if (surfacevisframes[n] != r_framecount)
+ {
+ surf = surfaces + n;
+ if (PlaneDist(modelorg, surf->plane) < surf->plane->dist)
+ {
+ if ((surf->flags & SURF_PLANEBACK))
+ surfacevisframes[n] = r_framecount;
+ }
+ else
+ {
+ if (!(surf->flags & SURF_PLANEBACK))
+ surfacevisframes[n] = r_framecount;
+ }
+ }
+#else
+ surfacevisframes[*mark++] = r_framecount;
+#endif
+ }