- if (c & (1<<i))
- {
- // warning to the clumsy: numleafs is one less than it should be, it only counts leafs with vis bits (skips leaf 0)
- leafnum = (k << 3)+i+1;
- if (leafnum > model->brushq1.numleafs)
- return;
- leaf = &model->brushq1.leafs[leafnum];
- if (leaf->mins[0] > high[0] || leaf->maxs[0] < low[0]
- || leaf->mins[1] > high[1] || leaf->maxs[1] < low[1]
- || leaf->mins[2] > high[2] || leaf->maxs[2] < low[2])
- continue;
- if ((m = leaf->nummarksurfaces))
- {
- mark = leaf->firstmarksurface;
- do
- {
- surf = model->brushq1.surfaces + *mark++;
- // if not visible in current frame, or already marked because it was in another leaf we passed, skip
- if (surf->lightframe == lightframe)
- continue;
- surf->lightframe = lightframe;
- if (surfacepvsframes[surf->number] != model->brushq1.pvsframecount)
- continue;
- dist = PlaneDiff(lightorigin, surf->plane);
- if (surf->flags & SURF_PLANEBACK)
- dist = -dist;
- // LordHavoc: make sure it is infront of the surface and not too far away
- if (dist < rd->cullradius && (dist > -0.25f || ((surf->flags & SURF_LIGHTBOTHSIDES) && dist > -rd->cullradius)))
- {
- int d;
- int impacts, impactt;
- float dist2, impact[3];
-
- dist2 = dist * dist;
-
- if (surf->plane->type < 3)
- {
- VectorCopy(lightorigin, impact);
- impact[surf->plane->type] -= dist;
- }
- else
- {
- impact[0] = lightorigin[0] - surf->plane->normal[0] * dist;
- impact[1] = lightorigin[1] - surf->plane->normal[1] * dist;
- impact[2] = lightorigin[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;
- if (r_dlightmap.integer)
- surf->cached_dlight = true;
- }
- surf->dlightbits[bitindex] |= bit;
- }
- }
- while (--m);
- }
- }