- 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;
- }
- else
- {
- int i/*, l*/, k, c, row, numbits, bit, leafnum, numleafs;
- mleaf_t *leaf;
- msurface_t *surf, **mark, **endmark;
- model_t *model = cl.worldmodel;
- byte *in;
- // mportal_t *portal;
- glpoly_t *poly;
- tinyplane_t plane;
-
- // c_leafs++;
- // r_viewleaf->visframe = r_framecount;
- if (!r_testvis.value)
- r_portalframecount++;
-
- numleafs = model->numleafs;
- numbits = numleafs;
- k = 0;
- in = r_viewleaf->compressed_vis;
- row = (numbits + 7) >> 3;
- while (k < row)
- {
- c = *in++;
- if (c)
- {
- for (i = 0, bit = 1;c;i++, bit <<= 1)
- {
- if (c & bit)
- {
- leafnum = (k << 3)+i+1;
- if (leafnum > numleafs)
- return;
- c -= bit;
- leaf = &model->leafs[leafnum];
- if (R_NotCulledBox(leaf->mins, leaf->maxs))
- {
- //for (portal = leaf->portals;portal;portal = portal->next)
- // if (DotProduct(r_origin, portal->plane.normal) > portal->plane.dist)
- // R_Clip_AddPolygon((float *)portal->points, portal->numpoints, sizeof(mvertex_t), false, R_Portal_Callback, leaf, portal, portal->plane);
- //leaf->visframe = r_framecount;
- c_leafs++;
- if (leaf->nummarksurfaces)
- {
- mark = leaf->firstmarksurface;
- endmark = mark + leaf->nummarksurfaces;
- if (r_ser.value)
- {
- 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)
- {
- VectorNegate(surf->plane->normal, plane.normal);
- plane.dist = -surf->plane->dist;
- for (poly = surf->polys;poly;poly = poly->next)
- R_Clip_AddPolygon((float *)poly->verts, poly->numverts, VERTEXSIZE * sizeof(float), (surf->flags & SURF_CLIPSOLID) != 0, RSurf_Callback, surf, NULL, &plane);
- }
- }
- else
- {
- if (!(surf->flags & SURF_PLANEBACK))
- for (poly = surf->polys;poly;poly = poly->next)
- R_Clip_AddPolygon((float *)poly->verts, poly->numverts, VERTEXSIZE * sizeof(float), (surf->flags & SURF_CLIPSOLID) != 0, RSurf_Callback, surf, NULL, (tinyplane_t *)surf->plane);
- }
- }
- while (mark < endmark);
- }
- else
- {
- 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);
- }
- }
- }
- }