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 case CG_R_CLEARSCENE: //clear scene
cl_numvisedicts=0; cl_numvisedicts=0;
{ dlights_running=0;
int i; dlights_software=0;
for (i = 0; i < MAX_DLIGHTS; i++)
{
if (cl_dlights[i].isstatic)
continue;
cl_dlights[i].radius = 0;
}
}
break; break;
case CG_R_ADDPOLYTOSCENE: case CG_R_ADDPOLYTOSCENE:
// ... // ...

View file

@ -95,7 +95,7 @@ dlight_t *CL_AllocDlight (int key)
if (key) if (key)
{ {
dl = cl_dlights; dl = cl_dlights;
for (i=0 ; i<MAX_DLIGHTS ; i++, dl++) for (i=0 ; i<dlights_running ; i++, dl++)
{ {
if (dl->key == key) if (dl->key == key)
{ {
@ -107,15 +107,15 @@ dlight_t *CL_AllocDlight (int key)
} }
// then look for anything else // then look for anything else
dl = cl_dlights; if (dlights_running < MAX_DLIGHTS)
for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
{ {
if (!dl->radius) dl = &cl_dlights[dlights_running];
{ memset (dl, 0, sizeof(*dl));
memset (dl, 0, sizeof(*dl)); dl->key = key;
dl->key = key; dlights_running++;
return dl; if (dlights_software < MAX_SWLIGHTS)
} dlights_software++;
return dl;
} }
dl = &cl_dlights[0]; dl = &cl_dlights[0];
@ -186,13 +186,14 @@ CL_DecayLights
void CL_DecayLights (void) void CL_DecayLights (void)
{ {
int i; int i;
int lastrunning = -1;
dlight_t *dl; dlight_t *dl;
if (cl.paused) //DON'T DO IT!!! if (cl.paused) //DON'T DO IT!!!
return; return;
dl = cl_dlights; dl = cl_dlights;
for (i=0 ; i<MAX_DLIGHTS ; i++, dl++) for (i=0 ; i<dlights_running ; i++, dl++)
{ {
if (!dl->radius) if (!dl->radius)
continue; continue;
@ -205,7 +206,11 @@ void CL_DecayLights (void)
dl->radius -= host_frametime*dl->decay; dl->radius -= host_frametime*dl->decay;
if (dl->radius < 0) if (dl->radius < 0)
{
dl->radius = 0; dl->radius = 0;
continue;
}
lastrunning = i;
if (dl->channelfade[0]) if (dl->channelfade[0])
{ {
@ -228,6 +233,10 @@ void CL_DecayLights (void)
dl->color[2] = 0; 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]; //lightstyle_t cl_lightstyle[MAX_LIGHTSTYLES];
dlight_t cl_dlights[MAX_DLIGHTS]; dlight_t cl_dlights[MAX_DLIGHTS];
int dlights_running, dlights_software;
// refresh list // refresh list
// this is double buffered so the last frame // this is double buffered so the last frame
// can be scanned for oldorigins of trailing objects // can be scanned for oldorigins of trailing objects
@ -972,9 +974,11 @@ void CL_ClearState (void)
// clear other arrays // clear other arrays
memset (cl_efrags, 0, sizeof(cl_efrags)); 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)); memset (cl_lightstyle, 0, sizeof(cl_lightstyle));
dlights_running = 0;
for (i = 0; i < MAX_EDICTS; i++) for (i = 0; i < MAX_EDICTS; i++)
{ {
memcpy(&cl_baselines[i], &nullentitystate, sizeof(cl_baselines[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 lightstyle_t cl_lightstyle[MAX_LIGHTSTYLES];
extern dlight_t cl_dlights[MAX_DLIGHTS]; extern dlight_t cl_dlights[MAX_DLIGHTS];
extern int dlights_running, dlights_software;
extern qboolean nomaster; extern qboolean nomaster;
extern float server_version; // version of server we connected to 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) 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) if (cl_dlights[l].radius)
{ {
@ -1668,7 +1668,7 @@ void R_DrawGAliasModel (entity_t *e)
if (!r_vertexdlights.value) if (!r_vertexdlights.value)
{ {
for (i=0 ; i<MAX_DLIGHTS ; i++) for (i=0 ; i<dlights_running ; i++)
{ {
if (cl_dlights[i].radius) if (cl_dlights[i].radius)
{ {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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