optimization to dlights, slight FPS increase

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@2274 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
TimeServ 2006-05-11 03:14:41 +00:00
parent 181592a0e3
commit 15fac4ad44
12 changed files with 47 additions and 42 deletions

View File

@ -770,15 +770,8 @@ static long CG_SystemCallsEx(void *offset, unsigned int mask, int fn, const long
case CG_R_CLEARSCENE: //clear scene
cl_numvisedicts=0;
{
int i;
for (i = 0; i < MAX_DLIGHTS; i++)
{
if (cl_dlights[i].isstatic)
continue;
cl_dlights[i].radius = 0;
}
}
dlights_running=0;
dlights_software=0;
break;
case CG_R_ADDPOLYTOSCENE:
// ...

View File

@ -95,7 +95,7 @@ dlight_t *CL_AllocDlight (int key)
if (key)
{
dl = cl_dlights;
for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
for (i=0 ; i<dlights_running ; i++, dl++)
{
if (dl->key == key)
{
@ -107,15 +107,15 @@ dlight_t *CL_AllocDlight (int key)
}
// then look for anything else
dl = cl_dlights;
for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
if (dlights_running < MAX_DLIGHTS)
{
if (!dl->radius)
{
memset (dl, 0, sizeof(*dl));
dl->key = key;
return dl;
}
dl = &cl_dlights[dlights_running];
memset (dl, 0, sizeof(*dl));
dl->key = key;
dlights_running++;
if (dlights_software < MAX_SWLIGHTS)
dlights_software++;
return dl;
}
dl = &cl_dlights[0];
@ -186,13 +186,14 @@ CL_DecayLights
void CL_DecayLights (void)
{
int i;
int lastrunning = -1;
dlight_t *dl;
if (cl.paused) //DON'T DO IT!!!
return;
dl = cl_dlights;
for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
for (i=0 ; i<dlights_running ; i++, dl++)
{
if (!dl->radius)
continue;
@ -205,7 +206,11 @@ void CL_DecayLights (void)
dl->radius -= host_frametime*dl->decay;
if (dl->radius < 0)
{
dl->radius = 0;
continue;
}
lastrunning = i;
if (dl->channelfade[0])
{
@ -228,6 +233,10 @@ void CL_DecayLights (void)
dl->color[2] = 0;
}
}
dlights_running = lastrunning+1;
dlights_software = dlights_running;
if (dlights_software > MAX_SWLIGHTS)
dlights_software = MAX_SWLIGHTS;
}

View File

@ -155,6 +155,8 @@ lightstyle_t cl_lightstyle[MAX_LIGHTSTYLES];
//lightstyle_t cl_lightstyle[MAX_LIGHTSTYLES];
dlight_t cl_dlights[MAX_DLIGHTS];
int dlights_running, dlights_software;
// refresh list
// this is double buffered so the last frame
// can be scanned for oldorigins of trailing objects
@ -972,9 +974,11 @@ void CL_ClearState (void)
// clear other arrays
memset (cl_efrags, 0, sizeof(cl_efrags));
memset (cl_dlights, 0, sizeof(cl_dlights));
// memset (cl_dlights, 0, sizeof(cl_dlights));
memset (cl_lightstyle, 0, sizeof(cl_lightstyle));
dlights_running = 0;
for (i = 0; i < MAX_EDICTS; i++)
{
memcpy(&cl_baselines[i], &nullentitystate, sizeof(cl_baselines[i]));

View File

@ -645,6 +645,8 @@ extern trailstate_t *cl_static_emit[MAX_STATIC_ENTITIES];
extern lightstyle_t cl_lightstyle[MAX_LIGHTSTYLES];
extern dlight_t cl_dlights[MAX_DLIGHTS];
extern int dlights_running, dlights_software;
extern qboolean nomaster;
extern float server_version; // version of server we connected to

View File

@ -724,7 +724,7 @@ static void R_GAliasApplyLighting(mesh_t *mesh, vec3_t org, vec3_t angles, float
if (r_vertexdlights.value && mesh->colors_array)
{
for (l=0 ; l<MAX_DLIGHTS ; l++)
for (l=0 ; l<dlights_running ; l++)
{
if (cl_dlights[l].radius)
{
@ -1668,7 +1668,7 @@ void R_DrawGAliasModel (entity_t *e)
if (!r_vertexdlights.value)
{
for (i=0 ; i<MAX_DLIGHTS ; i++)
for (i=0 ; i<dlights_running ; i++)
{
if (cl_dlights[i].radius)
{

View File

@ -1874,7 +1874,7 @@ void PPL_BaseBModelTextures(entity_t *e)
{
if (currentmodel->nummodelsurfaces != 0 && r_dynamic.value)
{
for (k=0 ; k<MAX_SWLIGHTS ; k++)
for (k=0 ; k<dlights_software ; k++)
{
if (!cl_dlights[k].radius)
continue;
@ -4958,7 +4958,7 @@ void PPL_DrawWorld (void)
if (cl.worldmodel->fromgame == fg_quake || cl.worldmodel->fromgame == fg_halflife || cl.worldmodel->fromgame == fg_quake2 /*|| cl.worldmodel->fromgame == fg_quake3*/)
{
// lc = NULL;
for (l = cl_dlights, i=0 ; i<MAX_DLIGHTS ; i++, l++)
for (l = cl_dlights, i=0 ; i<dlights_running ; i++, l++)
{
if (!l->radius || l->noppl)
continue;

View File

@ -181,7 +181,7 @@ void R_RenderDlights (void)
}
l = cl_dlights;
for (i=0 ; i<MAX_DLIGHTS ; i++, l++)
for (i=0 ; i<dlights_running ; i++, l++)
{
if (!l->radius || l->noflash)
continue;
@ -386,7 +386,7 @@ void GLR_PushDlights (void)
currentmodel = cl.worldmodel;
l = cl_dlights;
for (i=0 ; i<MAX_SWLIGHTS ; i++, l++)
for (i=0 ; i<dlights_software ; i++, l++)
{
if (!l->radius || l->nodynamic)
continue;

View File

@ -956,7 +956,6 @@ void R_LoadRTLights(void)
char fname[MAX_QPATH];
char *file;
char *end;
int i;
int style;
vec3_t org;
@ -964,10 +963,8 @@ void R_LoadRTLights(void)
vec3_t rgb;
//delete all old lights
for (i=0 ; i<MAX_DLIGHTS ; i++)
{
cl_dlights[i].radius = 0;
}
dlights_running = 0;
dlights_software = 0;
COM_StripExtension(cl.worldmodel->name, fname, sizeof(fname));
strncat(fname, ".rtlights", MAX_QPATH-1);

View File

@ -379,7 +379,7 @@ void GLR_AddDynamicLights (msurface_t *surf)
tmax = (surf->extents[1]>>4)+1;
tex = surf->texinfo;
for (lnum=0 ; lnum<MAX_SWLIGHTS ; lnum++)
for (lnum=0 ; lnum<dlights_software ; lnum++)
{
if ( !(surf->dlightbits & (1<<lnum) ) )
continue; // not lit by this light
@ -447,7 +447,7 @@ void GLR_AddDynamicLightNorms (msurface_t *surf)
tmax = (surf->extents[1]>>4)+1;
tex = surf->texinfo;
for (lnum=0 ; lnum<MAX_SWLIGHTS ; lnum++)
for (lnum=0 ; lnum<dlights_software ; lnum++)
{
if ( !(surf->dlightbits & (1<<lnum) ) )
continue; // not lit by this light
@ -521,7 +521,7 @@ void GLR_AddDynamicLightsColours (msurface_t *surf)
tmax = (surf->extents[1]>>4)+1;
tex = surf->texinfo;
for (lnum=0 ; lnum<MAX_SWLIGHTS ; lnum++)
for (lnum=0 ; lnum<dlights_software ; lnum++)
{
if ( !(surf->dlightbits & (1<<lnum) ) )
continue; // not lit by this light
@ -2733,7 +2733,7 @@ static void R_DrawBrushModel (entity_t *e)
// instanced model
if (currentmodel->firstmodelsurface != 0 && !r_flashblend.value)
{
for (k=0 ; k<MAX_SWLIGHTS ; k++)
for (k=0 ; k<dlights_software ; k++)
{
if ((cl_dlights[k].die < cl.time) ||
(!cl_dlights[k].radius))

View File

@ -180,7 +180,7 @@ void SWR_PushDlights (void)
if (cl.worldmodel->fromgame == fg_quake2)
{
for (i=0 ; i<MAX_SWLIGHTS ; i++, l++)
for (i=0 ; i<dlights_software ; i++, l++)
{
if (!l->radius)
continue;
@ -190,7 +190,7 @@ void SWR_PushDlights (void)
}
else
{
for (i=0 ; i<MAX_SWLIGHTS ; i++, l++)
for (i=0 ; i<dlights_software ; i++, l++)
{
if (!l->radius)
continue;

View File

@ -777,7 +777,7 @@ void SWR_DrawEntitiesOnList (void)
lighting.plightvec = lightvec;
for (lnum=0 ; lnum<MAX_DLIGHTS ; lnum++)
for (lnum=0 ; lnum<dlights_running ; lnum++)
{
if (cl_dlights[lnum].radius)
{
@ -868,7 +868,7 @@ void SWR_DrawViewModel (void)
r_viewlighting.shadelight = j;
// add dynamic lights
for (lnum=0 ; lnum<MAX_DLIGHTS ; lnum++)
for (lnum=0 ; lnum<dlights_running ; lnum++)
{
dl = &cl_dlights[lnum];
if (!dl->radius)
@ -1206,7 +1206,7 @@ void R_DrawBEntitiesOnList (void)
// instanced model
if (clmodel->firstmodelsurface != 0)
{
for (k=0 ; k<MAX_SWLIGHTS ; k++)
for (k=0 ; k<dlights_software ; k++)
{
if ((cl_dlights[k].die < cl.time) ||
(!cl_dlights[k].radius))

View File

@ -633,7 +633,7 @@ void SWR_AddDynamicLights (void)
tmax = (surf->extents[1]>>4)+1;
tex = surf->texinfo;
for (lnum=0 ; lnum<MAX_SWLIGHTS ; lnum++)
for (lnum=0 ; lnum<dlights_software ; lnum++)
{
if ( !(surf->dlightbits & (1<<lnum) ) )
continue; // not lit by this light
@ -699,7 +699,7 @@ void SWR_AddDynamicLightsRGB (void)
tmax = (surf->extents[1]>>4)+1;
tex = surf->texinfo;
for (lnum=0 ; lnum<MAX_SWLIGHTS ; lnum++)
for (lnum=0 ; lnum<dlights_software ; lnum++)
{
if ( !(surf->dlightbits & (1<<lnum) ) )
continue; // not lit by this light