-/*
-=============================================================
-
- WORLD MODEL
-
-=============================================================
-*/
-
-static void R_SolidWorldNode (entity_render_t *ent)
-{
- if (r_viewleaf->contents != CONTENTS_SOLID)
- {
- int portalstack;
- mportal_t *p, *pstack[8192];
- msurface_t *surf, **mark, **endmark;
- mleaf_t *leaf;
- // LordHavoc: portal-passage worldnode; follows portals leading
- // outward from viewleaf, if a portal leads offscreen it is not
- // followed, in indoor maps this can often cull a great deal of
- // geometry away when pvs data is not present (useful with pvs as well)
-
- leaf = r_viewleaf;
- leaf->worldnodeframe = r_framecount;
- portalstack = 0;
- loc0:
- c_leafs++;
-
- leaf->visframe = r_framecount;
-
- if (leaf->nummarksurfaces)
- {
- mark = leaf->firstmarksurface;
- endmark = mark + leaf->nummarksurfaces;
- do
- {
- surf = *mark++;
- // make sure surfaces are only processed once
- if (surf->worldnodeframe == r_framecount)
- continue;
- surf->worldnodeframe = r_framecount;
- if (PlaneDist(r_origin, surf->plane) < surf->plane->dist)
- {
- if (surf->flags & SURF_PLANEBACK)
- surf->visframe = r_framecount;
- }
- else
- {
- if (!(surf->flags & SURF_PLANEBACK))
- surf->visframe = r_framecount;
- }
- }
- while (mark < endmark);
- }
-
- // follow portals into other leafs
- p = leaf->portals;
- for (;p;p = p->next)
- {
- if (DotProduct(r_origin, p->plane.normal) < p->plane.dist)
- {
- leaf = p->past;
- if (leaf->worldnodeframe != r_framecount)
- {
- leaf->worldnodeframe = r_framecount;
- if (leaf->contents != CONTENTS_SOLID)
- {
- if (R_NotCulledBox(leaf->mins, leaf->maxs))
- {
- p->visframe = r_framecount;
- pstack[portalstack++] = p;
- goto loc0;
-
- loc1:
- p = pstack[--portalstack];
- }
- }
- }
- }
- }
-
- if (portalstack)
- goto loc1;
- }
- else
- {
- mnode_t *nodestack[8192], *node = cl.worldmodel->nodes;
- int nodestackpos = 0;
- // LordHavoc: recursive descending worldnode; if portals are not
- // available, this is a good last resort, can cull large amounts of
- // geometry, but is more time consuming than portal-passage and renders
- // things behind walls
-
-loc2:
- if (R_NotCulledBox(node->mins, node->maxs))
- {
- if (node->numsurfaces)
- {
- msurface_t *surf = cl.worldmodel->surfaces + node->firstsurface, *surfend = surf + node->numsurfaces;
- if (PlaneDiff (r_origin, node->plane) < 0)
- {
- for (;surf < surfend;surf++)
- {
- if (surf->flags & SURF_PLANEBACK)
- surf->visframe = r_framecount;
- }
- }
- else
- {
- for (;surf < surfend;surf++)
- {
- if (!(surf->flags & SURF_PLANEBACK))
- surf->visframe = r_framecount;
- }
- }
- }
-
- // recurse down the children
- if (node->children[0]->contents >= 0)
- {
- if (node->children[1]->contents >= 0)
- {
- if (nodestackpos < 8192)
- nodestack[nodestackpos++] = node->children[1];
- node = node->children[0];
- goto loc2;
- }
- else
- ((mleaf_t *)node->children[1])->visframe = r_framecount;
- node = node->children[0];
- goto loc2;
- }
- else
- {
- ((mleaf_t *)node->children[0])->visframe = r_framecount;
- if (node->children[1]->contents >= 0)
- {
- node = node->children[1];
- goto loc2;
- }
- else if (nodestackpos > 0)
- {
- ((mleaf_t *)node->children[1])->visframe = r_framecount;
- node = nodestack[--nodestackpos];
- goto loc2;
- }
- }
- }
- else if (nodestackpos > 0)
- {
- node = nodestack[--nodestackpos];
- goto loc2;
- }
- }
-}
-
-static void R_PVSWorldNode()
-{
- int portalstack, i;
- mportal_t *p, *pstack[8192];
- msurface_t *surf, **mark, **endmark;
- mleaf_t *leaf;
- qbyte *worldvis;
-
- worldvis = Mod_LeafPVS (r_viewleaf, cl.worldmodel);
-
- leaf = r_viewleaf;
- leaf->worldnodeframe = r_framecount;
- portalstack = 0;
-loc0:
- c_leafs++;
-
- leaf->visframe = r_framecount;
-
- if (leaf->nummarksurfaces)
- {
- mark = leaf->firstmarksurface;
- endmark = mark + leaf->nummarksurfaces;
- do
- {
- surf = *mark++;
- // make sure surfaces are only processed once
- if (surf->worldnodeframe == r_framecount)
- continue;
- surf->worldnodeframe = r_framecount;
- if (PlaneDist(r_origin, surf->plane) < surf->plane->dist)
- {
- if (surf->flags & SURF_PLANEBACK)
- surf->visframe = r_framecount;
- }
- else
- {
- if (!(surf->flags & SURF_PLANEBACK))
- surf->visframe = r_framecount;
- }
- }
- while (mark < endmark);
- }
-
- // follow portals into other leafs
- for (p = leaf->portals;p;p = p->next)
- {
- if (DotProduct(r_origin, p->plane.normal) < p->plane.dist)
- {
- leaf = p->past;
- if (leaf->worldnodeframe != r_framecount)
- {
- leaf->worldnodeframe = r_framecount;
- if (leaf->contents != CONTENTS_SOLID)
- {
- i = (leaf - cl.worldmodel->leafs) - 1;
- if (worldvis[i>>3] & (1<<(i&7)))
- {
- if (R_NotCulledBox(leaf->mins, leaf->maxs))
- {
- pstack[portalstack++] = p;
- goto loc0;
-
-loc1:
- p = pstack[--portalstack];
- }
- }
- }
- }
- }
- }
-
- if (portalstack)
- goto loc1;
-}
-