- int d, impacts, impactt;
- float dist, dist2, impact[3];
- if (surf->visframe != r_framecount)
- continue;
- dist = ndist;
- if (surf->flags & SURF_PLANEBACK)
- dist = -dist;
-
- if (dist < -0.25f && !(surf->flags & SURF_LIGHTBOTHSIDES))
- continue;
-
- dist2 = dist * dist;
- if (dist2 >= maxdist)
- continue;
-
- if (node->plane->type < 3)
- {
- VectorCopy(rd->origin, impact);
- impact[node->plane->type] -= dist;
- }
- else
- {
- impact[0] = rd->origin[0] - surf->plane->normal[0] * dist;
- impact[1] = rd->origin[1] - surf->plane->normal[1] * dist;
- impact[2] = rd->origin[2] - surf->plane->normal[2] * dist;
- }
-
- impacts = DotProduct (impact, surf->texinfo->vecs[0]) + surf->texinfo->vecs[0][3] - surf->texturemins[0];
-
- d = bound(0, impacts, surf->extents[0] + 16) - impacts;
- dist2 += d * d;
- if (dist2 > maxdist)
- continue;
-
- impactt = DotProduct (impact, surf->texinfo->vecs[1]) + surf->texinfo->vecs[1][3] - surf->texturemins[1];
-
- d = bound(0, impactt, surf->extents[1] + 16) - impactt;
- dist2 += d * d;
- if (dist2 > maxdist)
- continue;
-
- if (surf->dlightframe != r_framecount) // not dynamic until now
- {
- surf->dlightbits[0] = surf->dlightbits[1] = surf->dlightbits[2] = surf->dlightbits[3] = surf->dlightbits[4] = surf->dlightbits[5] = surf->dlightbits[6] = surf->dlightbits[7] = 0;
- surf->dlightframe = r_framecount;
- }
- surf->dlightbits[bitindex] |= bit;
- }
-
- if (node->children[0]->contents >= 0)
- {
- if (node->children[1]->contents >= 0)
- {
- R_OldMarkLights (lightorigin, rd, bit, bitindex, node->children[0]);
- node = node->children[1];
- goto loc0;
- }
- else
- {
- node = node->children[0];
- goto loc0;
- }
- }
- else if (node->children[1]->contents >= 0)
- {
- node = node->children[1];
- goto loc0;
- }
-}
-
-
-static void R_VisMarkLights (rdlight_t *rd, int bit, int bitindex)
-{
- static int lightframe = 0;
- mleaf_t *pvsleaf;
- vec3_t lightorigin;
- model_t *model;
- int i, k, m, c, leafnum;
- msurface_t *surf, **mark;
- mleaf_t *leaf;
- qbyte *in;
- int row;
- float low[3], high[3], dist, maxdist;
-
- if (!r_dynamic.integer)
- return;
-
- model = currentrenderentity->model;
- softwareuntransform(rd->origin, lightorigin);
-
- if (!r_vismarklights.integer)
- {
- R_OldMarkLights(lightorigin, rd, bit, bitindex, model->nodes + model->hulls[0].firstclipnode);
- return;
- }
-
- pvsleaf = Mod_PointInLeaf (lightorigin, model);
- if (pvsleaf == NULL)
- {
- Con_Printf("R_VisMarkLights: NULL leaf??\n");
- R_OldMarkLights(lightorigin, rd, bit, bitindex, model->nodes + model->hulls[0].firstclipnode);
- return;
- }
-
- in = pvsleaf->compressed_vis;
- if (!in)
- {
- // no vis info, so make all visible
- R_OldMarkLights(lightorigin, rd, bit, bitindex, model->nodes + model->hulls[0].firstclipnode);
- return;
- }
-
- lightframe++;
-
- low[0] = lightorigin[0] - rd->cullradius;low[1] = lightorigin[1] - rd->cullradius;low[2] = lightorigin[2] - rd->cullradius;
- high[0] = lightorigin[0] + rd->cullradius;high[1] = lightorigin[1] + rd->cullradius;high[2] = lightorigin[2] + rd->cullradius;
-
- // for comparisons to minimum acceptable light
- maxdist = rd->cullradius2;
-
- row = (model->numleafs+7)>>3;
-
- k = 0;
- while (k < row)
- {
- c = *in++;
- if (c)