From: havoc Date: Mon, 12 Nov 2007 13:06:59 +0000 (+0000) Subject: optimized SHOWLMP code (only used by Nehahra) to not eat any CPU time X-Git-Tag: xonotic-v0.1.0preview~2793 X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=commitdiff_plain;h=8688df8a88c8f14d8f11fe73a151e5b53f94407c;ds=sidebyside optimized SHOWLMP code (only used by Nehahra) to not eat any CPU time anymore git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7688 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/cl_main.c b/cl_main.c index 96188f11..79a6a1f2 100644 --- a/cl_main.c +++ b/cl_main.c @@ -134,6 +134,7 @@ void CL_ClearState(void) cl.max_lightstyle = MAX_LIGHTSTYLES; cl.max_brushmodel_entities = MAX_EDICTS; cl.max_particles = MAX_PARTICLES; + cl.max_showlmps = 0; // COMMANDLINEOPTION: Client: -particles changes maximum number of particles at once, default 32768 i = COM_CheckParm ("-particles"); @@ -158,6 +159,7 @@ void CL_ClearState(void) cl.lightstyle = (lightstyle_t *)Mem_Alloc(cls.levelmempool, cl.max_lightstyle * sizeof(lightstyle_t)); cl.brushmodel_entities = (int *)Mem_Alloc(cls.levelmempool, cl.max_brushmodel_entities * sizeof(int)); cl.particles = (particle_t *) Mem_Alloc(cls.levelmempool, cl.max_particles * sizeof(particle_t)); + cl.showlmps = NULL; // LordHavoc: have to set up the baseline info for alpha and other stuff for (i = 0;i < cl.max_entities;i++) diff --git a/cl_screen.c b/cl_screen.c index f905af34..ab5bafc6 100644 --- a/cl_screen.c +++ b/cl_screen.c @@ -1707,36 +1707,22 @@ static void R_Envmap_f (void) //============================================================================= -// LordHavoc: SHOWLMP stuff -#define SHOWLMP_MAXLABELS 256 -typedef struct showlmp_s -{ - qboolean isactive; - float x; - float y; - char label[32]; - char pic[128]; -} -showlmp_t; - -showlmp_t showlmp[SHOWLMP_MAXLABELS]; - void SHOWLMP_decodehide(void) { int i; char *lmplabel; lmplabel = MSG_ReadString(); - for (i = 0;i < SHOWLMP_MAXLABELS;i++) - if (showlmp[i].isactive && strcmp(showlmp[i].label, lmplabel) == 0) + for (i = 0;i < cl.num_showlmps;i++) + if (cl.showlmps[i].isactive && strcmp(cl.showlmps[i].label, lmplabel) == 0) { - showlmp[i].isactive = false; + cl.showlmps[i].isactive = false; return; } } void SHOWLMP_decodeshow(void) { - int i, k; + int k; char lmplabel[256], picname[256]; float x, y; strlcpy (lmplabel,MSG_ReadString(), sizeof (lmplabel)); @@ -1751,41 +1737,37 @@ void SHOWLMP_decodeshow(void) x = MSG_ReadShort(); y = MSG_ReadShort(); } - k = -1; - for (i = 0;i < SHOWLMP_MAXLABELS;i++) - if (showlmp[i].isactive) - { - if (strcmp(showlmp[i].label, lmplabel) == 0) - { - k = i; - break; // drop out to replace it - } - } - else if (k < 0) // find first empty one to replace - k = i; - if (k < 0) - return; // none found to replace - // change existing one - showlmp[k].isactive = true; - strlcpy (showlmp[k].label, lmplabel, sizeof (showlmp[k].label)); - strlcpy (showlmp[k].pic, picname, sizeof (showlmp[k].pic)); - showlmp[k].x = x; - showlmp[k].y = y; + if (!cl.showlmps || cl.num_showlmps >= cl.max_showlmps) + { + showlmp_t *oldshowlmps = cl.showlmps; + cl.max_showlmps += 16; + cl.showlmps = Mem_Alloc(cls.levelmempool, cl.max_showlmps * sizeof(showlmp_t)); + if (cl.num_showlmps) + memcpy(cl.showlmps, oldshowlmps, cl.num_showlmps * sizeof(showlmp_t)); + if (oldshowlmps) + Mem_Free(oldshowlmps); + } + for (k = 0;k < cl.max_showlmps;k++) + if (cl.showlmps[k].isactive && !strcmp(cl.showlmps[k].label, lmplabel)) + break; + if (k == cl.max_showlmps) + for (k = 0;k < cl.max_showlmps;k++) + if (!cl.showlmps[k].isactive) + break; + cl.showlmps[k].isactive = true; + strlcpy (cl.showlmps[k].label, lmplabel, sizeof (cl.showlmps[k].label)); + strlcpy (cl.showlmps[k].pic, picname, sizeof (cl.showlmps[k].pic)); + cl.showlmps[k].x = x; + cl.showlmps[k].y = y; + cl.num_showlmps = max(cl.num_showlmps, k + 1); } void SHOWLMP_drawall(void) { int i; - for (i = 0;i < SHOWLMP_MAXLABELS;i++) - if (showlmp[i].isactive) - DrawQ_Pic(showlmp[i].x, showlmp[i].y, Draw_CachePic(showlmp[i].pic, true), 0, 0, 1, 1, 1, 1, 0); -} - -void SHOWLMP_clear(void) -{ - int i; - for (i = 0;i < SHOWLMP_MAXLABELS;i++) - showlmp[i].isactive = false; + for (i = 0;i < cl.num_showlmps;i++) + if (cl.showlmps[i].isactive) + DrawQ_Pic(cl.showlmps[i].x, cl.showlmps[i].y, Draw_CachePic(cl.showlmps[i].pic, true), 0, 0, 1, 1, 1, 1, 0); } /* @@ -2223,5 +2205,4 @@ void CL_UpdateScreen(void) void CL_Screen_NewMap(void) { - SHOWLMP_clear(); } diff --git a/cl_screen.h b/cl_screen.h index 9083ee31..b5f62e72 100644 --- a/cl_screen.h +++ b/cl_screen.h @@ -5,7 +5,6 @@ void SHOWLMP_decodehide(void); void SHOWLMP_decodeshow(void); void SHOWLMP_drawall(void); -void SHOWLMP_clear(void); extern cvar_t vid_conwidth; extern cvar_t vid_conheight; diff --git a/client.h b/client.h index d0368835..559d0e94 100644 --- a/client.h +++ b/client.h @@ -679,6 +679,16 @@ typedef struct cl_locnode_s } cl_locnode_t; +typedef struct showlmp_s +{ + qboolean isactive; + float x; + float y; + char label[32]; + char pic[128]; +} +showlmp_t; + // // the client_state_t structure is wiped completely at every // server signon @@ -903,6 +913,7 @@ typedef struct client_state_s int max_lightstyle; int max_brushmodel_entities; int max_particles; + int max_showlmps; entity_t *entities; unsigned char *entities_active; @@ -914,6 +925,7 @@ typedef struct client_state_s lightstyle_t *lightstyle; int *brushmodel_entities; particle_t *particles; + showlmp_t *showlmps; int num_entities; int num_static_entities; @@ -923,6 +935,7 @@ typedef struct client_state_s int num_beams; int num_dlights; int num_particles; + int num_showlmps; int free_particle; diff --git a/render.h b/render.h index a582433b..830666f7 100644 --- a/render.h +++ b/render.h @@ -43,7 +43,6 @@ extern void R_ResetSkyBox(void); extern void SHOWLMP_decodehide(void); extern void SHOWLMP_decodeshow(void); extern void SHOWLMP_drawall(void); -extern void SHOWLMP_clear(void); // render profiling stuff extern char r_speeds_string[1024]; diff --git a/todo b/todo index 9b417894..128f8eeb 100644 --- a/todo +++ b/todo @@ -15,6 +15,7 @@ 0 bug darkplaces loader: mcbsp hull selection is ignoring the custom hulls supported by mcbsp (div0) 0 bug darkplaces loader: q1bsp loader computes wrong submodel size for submodels with no surfaces, such as a func_wall comprised entirely of SKIP or CAULK brushes (neg|ke) 0 bug darkplaces memory: memstats doesn't account for memory used by VBO/EBO buffers in models +0 bug darkplaces menu: load/save game menus show files that are not in the highest priority gamedir, such as id1 saves showing up when playing dpmod (Dooomer) 0 bug darkplaces qc FRIK_FILE: when opening a file for writing that already has the data/ prefix in its path, it should not add another data/ prefix (daemon) 0 bug darkplaces readme: it would be a very good idea to add documentation of sv_gameplayfix_* cvars in the readme as a means to run broken mods (xaGe) 0 bug darkplaces readme: readme says that q3 shaders are not supported, this is not true, describe the working features in detail (qqshka)