Might as well optimise it while its still present.

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@3275 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2009-07-14 15:13:12 +00:00
parent 91da30299d
commit 9ad2588aed

View file

@ -299,11 +299,18 @@ void Q1BSP_MarkLights (dlight_t *light, int bit, mnode_t *node)
msurface_t *surf; msurface_t *surf;
int i; int i;
float l, maxdist;
int j, s, t;
vec3_t impact;
if (node->contents < 0) if (node->contents < 0)
return; return;
splitplane = node->plane; splitplane = node->plane;
dist = DotProduct (light->origin, splitplane->normal) - splitplane->dist; if (splitplane->type < 3)
dist = light->origin[splitplane->type] - splitplane->dist;
else
dist = DotProduct (light->origin, splitplane->normal) - splitplane->dist;
if (dist > light->radius) if (dist > light->radius)
{ {
@ -316,16 +323,34 @@ void Q1BSP_MarkLights (dlight_t *light, int bit, mnode_t *node)
return; return;
} }
maxdist = light->radius*light->radius;
// mark the polygons // mark the polygons
surf = currentmodel->surfaces + node->firstsurface; surf = currentmodel->surfaces + node->firstsurface;
for (i=0 ; i<node->numsurfaces ; i++, surf++) for (i=0 ; i<node->numsurfaces ; i++, surf++)
{ {
if (surf->dlightframe != r_dlightframecount) //Yeah, you can blame LordHavoc for this alternate code here.
for (j=0 ; j<3 ; j++)
impact[j] = light->origin[j] - surf->plane->normal[j]*dist;
// clamp center of light to corner and check brightness
l = DotProduct (impact, surf->texinfo->vecs[0]) + surf->texinfo->vecs[0][3] - surf->texturemins[0];
s = l+0.5;if (s < 0) s = 0;else if (s > surf->extents[0]) s = surf->extents[0];
s = l - s;
l = DotProduct (impact, surf->texinfo->vecs[1]) + surf->texinfo->vecs[1][3] - surf->texturemins[1];
t = l+0.5;if (t < 0) t = 0;else if (t > surf->extents[1]) t = surf->extents[1];
t = l - t;
// compare to minimum light
if ((s*s+t*t+dist*dist) < maxdist)
{ {
surf->dlightbits = 0; if (surf->dlightframe != r_dlightframecount)
surf->dlightframe = r_dlightframecount; {
surf->dlightbits = bit;
surf->dlightframe = r_dlightframecount;
}
else
surf->dlightbits |= bit;
} }
surf->dlightbits |= bit;
} }
Q1BSP_MarkLights (light, bit, node->children[0]); Q1BSP_MarkLights (light, bit, node->children[0]);