+ c = *in++;
+ if (c)
+ {
+ for (i = 0;i < 8;i++)
+ {
+ 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->numleafs)
+ return;
+ leaf = &model->leafs[leafnum];
+ if (leaf->visframe != r_framecount
+ || leaf->contents == CONTENTS_SOLID
+ || 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 (leaf->dlightframe != r_framecount)
+ {
+ // not dynamic until now
+ leaf->dlightbits[0] = leaf->dlightbits[1] = leaf->dlightbits[2] = leaf->dlightbits[3] = leaf->dlightbits[4] = leaf->dlightbits[5] = leaf->dlightbits[6] = leaf->dlightbits[7] = 0;
+ leaf->dlightframe = r_framecount;
+ }
+ leaf->dlightbits[bitindex] |= bit;
+ if ((m = leaf->nummarksurfaces))
+ {
+ mark = leaf->firstmarksurface;
+ do
+ {
+ surf = *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 (surf->visframe != r_framecount)
+ 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;
+
+ 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;
+
+#if 0
+ d = DotProduct (impact, surf->texinfo->vecs[0]) + surf->texinfo->vecs[0][3] - surf->texturemins[0];
+ if (d < 0)
+ {
+ dist2 += d * d;
+ if (dist2 > maxdist)
+ continue;
+ }
+ else
+ {
+ d -= surf->extents[0];
+ if (d < 0)
+ {
+ dist2 += d * d;
+ if (dist2 > maxdist)
+ continue;
+ }
+ }
+
+ d = DotProduct (impact, surf->texinfo->vecs[1]) + surf->texinfo->vecs[1][3] - surf->texturemins[1];
+ if (d < 0)
+ {
+ dist2 += d * d;
+ if (dist2 > maxdist)
+ continue;
+ }
+ else
+ {
+ d -= surf->extents[1];
+ if (d < 0)
+ {
+ dist2 += d * d;
+ if (dist2 > maxdist)
+ continue;
+ }
+ }
+
+#else
+
+ 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;
+
+#endif
+
+ 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;
+ }
+ }
+ while (--m);
+ }
+ }
+ }
+ k++;