Skip to content

Commit

Permalink
GFX: Improved dlight caching from fodquake
Browse files Browse the repository at this point in the history
A bit weird behaviour at places due to gl_rl_globe support for
instance... Leaving it be for the moment

This gave me ~100% fps boost on AMD GPU + OSS drivers on Linux

Thanks bigfoot
  • Loading branch information
jite committed Aug 30, 2016
1 parent 17e9a26 commit 59e32c8
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 326 deletions.
63 changes: 42 additions & 21 deletions cl_ents.c
Expand Up @@ -15,9 +15,6 @@ See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
$Id: cl_ents.c,v 1.58 2007-09-17 19:37:55 qqshka Exp $
*/

#include "quakedef.h"
Expand All @@ -38,6 +35,7 @@ extern cvar_t cl_predict_half;
extern cvar_t cl_model_bobbing;
extern cvar_t cl_nolerp, cl_lerp_monsters, cl_newlerp;
extern cvar_t r_drawvweps;
extern unsigned int cl_dlight_active[MAX_DLIGHTS/32];

static struct predicted_player {
int flags;
Expand Down Expand Up @@ -238,8 +236,10 @@ customlight_t *dlightColorEx(float f, char *str, dlighttype_t def, qbool random,
return l;
}

dlight_t *CL_AllocDlight (int key) {
int i;
dlight_t *CL_AllocDlight(int key)
{
unsigned int i;
unsigned int j;
dlight_t *dl;

// first look for an exact key match
Expand All @@ -249,24 +249,32 @@ dlight_t *CL_AllocDlight (int key) {
if (dl->key == key) {
memset (dl, 0, sizeof(*dl));
dl->key = key;
cl_dlight_active[i/32] |= (1<<(i%32));
return dl;
}
}
}

// then look for anything else
dl = cl_dlights;
for (i = 0; i < MAX_DLIGHTS; i++, dl++) {
if (dl->die < cl.time) {
memset (dl, 0, sizeof(*dl));
dl->key = key;
return dl;
for (i = 0; i < MAX_DLIGHTS/32; i++) {
if (cl_dlight_active[i] != 0xffffffff) {
for (j = 0; j < 32; j++) {
if (!(cl_dlight_active[i] & (1<<j)) && i*32+j < MAX_DLIGHTS) {
dl = cl_dlights + i * 32 + j;
memset(dl, 0, sizeof(*dl));
dl->key = key;
cl_dlight_active[i] |= 1<<j;
return dl;
}
}
}
}

dl = &cl_dlights[0];
memset (dl, 0, sizeof(*dl));
dl->key = key;
cl_dlight_active[0] |= 1;

return dl;
}

Expand Down Expand Up @@ -299,21 +307,34 @@ void CL_NewDlightEx (int key, vec3_t origin, float radius, float time, customlig
VectorCopy(l->color, dl->color);
}

void CL_DecayLights (void) {
int i;
void CL_DecayLights(void)
{
unsigned int i;
unsigned int j;
dlight_t *dl;

if (cls.state < ca_active)
if (cls.state < ca_active) {
return;
}

dl = cl_dlights;
for (i = 0; i < MAX_DLIGHTS; i++, dl++) {
if (dl->die < cl.time || !dl->radius)
continue;
for (i = 0; i < MAX_DLIGHTS/32; i++) {
if (cl_dlight_active[i]) {
for (j = 0; j < 32; j++) {
if ((cl_dlight_active[i]&(1<<j)) && i*32+j < MAX_DLIGHTS) {
dl = cl_dlights + i*32 + j;
dl->radius -= cls.frametime * dl->decay;

dl->radius -= cls.frametime * dl->decay;
if (dl->radius < 0)
dl->radius = 0;
if (dl->radius < 0) {
dl->radius = 0;
}

if (dl->die < cl.time || !dl->radius) {
cl_dlight_active[i] &= ~(1<<j);
continue;
}
}
}
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion cl_main.c
Expand Up @@ -224,6 +224,7 @@ efrag_t cl_efrags[MAX_EFRAGS];
entity_t cl_static_entities[MAX_STATIC_ENTITIES];
lightstyle_t cl_lightstyle[MAX_LIGHTSTYLES];
dlight_t cl_dlights[MAX_DLIGHTS];
unsigned int cl_dlight_active[MAX_DLIGHTS/32];

// refresh list
visentlist_t cl_firstpassents, cl_visents, cl_alphaents;
Expand Down Expand Up @@ -1241,7 +1242,7 @@ void CL_ClearState (void)

// Clear other arrays.
memset(cl_efrags, 0, sizeof(cl_efrags));
memset(cl_dlights, 0, sizeof(cl_dlights));
memset(cl_dlight_active, 0, sizeof(cl_dlight_active));
memset(cl_lightstyle, 0, sizeof(cl_lightstyle));
memset(cl_entities, 0, sizeof(cl_entities));

Expand Down
55 changes: 27 additions & 28 deletions client.h
Expand Up @@ -92,51 +92,48 @@ typedef struct
typedef struct player_info_s
{
int userid;
char userinfo[MAX_INFO_STRING];

// Scoreboard information.
char name[MAX_SCOREBOARDNAME];
float entertime;
int frags;
int ping;
byte pl;
unsigned char spectator;

// Skin information.
int topcolor;
int bottomcolor;
unsigned char topcolor;
unsigned char bottomcolor;

int _topcolor;
int _bottomcolor;
unsigned char _topcolor;
unsigned char _bottomcolor;

int real_topcolor;
int real_bottomcolor;
char team[MAX_INFO_STRING];
char _team[MAX_INFO_STRING];
unsigned char real_topcolor;
unsigned char real_bottomcolor;

int fps_msec;
int last_fps;
int fps; // > 0 - fps, < 0 - invalid, 0 - collecting
int fps_frames;
double fps_measure_time;
qbool isnear;
int fps_msec;
int last_fps;
int fps; // > 0 - fps, < 0 - invalid, 0 - collecting
int fps_frames;
double fps_measure_time;
qbool isnear;

int spectator;
byte translations[VID_GRADES*256];
skin_t *skin;

int stats[MAX_CL_STATS];


qbool dead;
qbool skin_refresh;
qbool ignored; // for ignore
qbool validated; // for authentication
char f_server[16]; // for f_server responses

// VULT DEATH EFFECT
// Better putting the dead flag here instead of on the entity so whats dead stays dead
qbool dead;

} player_info_t;
int stats[MAX_CL_STATS];
byte translations[VID_GRADES*256];
char userinfo[MAX_INFO_STRING];
char team[MAX_INFO_STRING];
char _team[MAX_INFO_STRING];
} __attribute__((aligned(64))) player_info_t;


typedef struct
Expand Down Expand Up @@ -237,6 +234,7 @@ typedef struct {
int bubble; // non zero means no flashblend bubble
dlighttype_t type;
byte color[3]; // use such color if type == lt_custom
byte unused[3];
} dlight_t;

typedef struct customlight_s {
Expand Down Expand Up @@ -658,11 +656,12 @@ extern cvar_t r_instagibtrail;
extern cvar_t r_powerupglow;

// FIXME, allocate dynamically
extern centity_t cl_entities[CL_MAX_EDICTS];
extern efrag_t cl_efrags[MAX_EFRAGS];
extern entity_t cl_static_entities[MAX_STATIC_ENTITIES];
extern lightstyle_t cl_lightstyle[MAX_LIGHTSTYLES];
extern dlight_t cl_dlights[MAX_DLIGHTS];
extern centity_t cl_entities[CL_MAX_EDICTS];
extern efrag_t cl_efrags[MAX_EFRAGS];
extern entity_t cl_static_entities[MAX_STATIC_ENTITIES];
extern lightstyle_t cl_lightstyle[MAX_LIGHTSTYLES];
extern dlight_t cl_dlights[MAX_DLIGHTS];
extern unsigned int cl_dlight_active[MAX_DLIGHTS/32];

extern byte *host_basepal;
extern byte *host_colormap;
Expand Down

0 comments on commit 59e32c8

Please sign in to comment.