-}
-
-/*
-=============================================================================
-
-DYNAMIC LIGHTS
-
-=============================================================================
-*/
-
-/*
-=============
-R_MarkLights
-=============
-*/
-static void R_OldMarkLights (entity_render_t *ent, vec3_t lightorigin, rdlight_t *rd, int bit, int bitindex, mnode_t *node)
-{
- float ndist, maxdist;
- msurface_t *surf;
- int i, *surfacepvsframes;
- int d, impacts, impactt;
- float dist, dist2, impact[3];
-
- if (!r_dynamic.integer)
- return;
-
- // for comparisons to minimum acceptable light
- maxdist = rd->cullradius2;
-
- surfacepvsframes = ent->model->surfacepvsframes;
-loc0:
- if (node->contents < 0)
- return;
-
- ndist = PlaneDiff(lightorigin, node->plane);
-
- if (ndist > rd->cullradius)
- {
- node = node->children[0];
- goto loc0;
- }
- if (ndist < -rd->cullradius)
- {
- node = node->children[1];
- goto loc0;
- }
-
-// mark the polygons
- surf = ent->model->surfaces + node->firstsurface;
- for (i = 0;i < node->numsurfaces;i++, surf++)
- {
- if (surfacepvsframes[surf->number] != ent->model->pvsframecount)
- 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(lightorigin, impact);
- impact[node->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;
- }
-
- if (node->children[0]->contents >= 0)
- {
- if (node->children[1]->contents >= 0)
- {
- R_OldMarkLights (ent, 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 (entity_render_t *ent, 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, *surfacepvsframes, *mark;
- msurface_t *surf;
- mleaf_t *leaf;
- qbyte *in;
- int row;
- float low[3], high[3], dist, maxdist;
-
- if (!r_dynamic.integer)
- return;
-
- Matrix4x4_Transform(&ent->inversematrix, rd->origin, lightorigin);
-
- model = ent->model;
- pvsleaf = Mod_PointInLeaf (lightorigin, model);
- if (pvsleaf == NULL)
- return;
-
- in = pvsleaf->compressed_vis;
- if (!r_vismarklights.integer || !in)
- {
- // told not to use pvs, or there's no pvs to use
- R_OldMarkLights(ent, 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;
- surfacepvsframes = model->surfacepvsframes;
-
- k = 0;
- while (k < row)