]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
optimized SHOWLMP code (only used by Nehahra) to not eat any CPU time
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 12 Nov 2007 13:06:59 +0000 (13:06 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 12 Nov 2007 13:06:59 +0000 (13:06 +0000)
anymore

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7688 d7cf8633-e32d-0410-b094-e92efae38249

cl_main.c
cl_screen.c
cl_screen.h
client.h
render.h
todo

index 96188f11e33c04ae8aa8c0941d45bada4da69549..79a6a1f2f87d3e97c8be8b02523cbb184c2f6784 100644 (file)
--- 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 <number> 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++)
index f905af34ab9063301f45bad951be43d314de1856..ab5bafc644bc67ae2e466fb8693e9b33db39028c 100644 (file)
@@ -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();
 }
index 9083ee313968237096b7ec68cb0dacc2f423b914..b5f62e72367d83f1fb3aa9b4b82a62b14edb3269 100644 (file)
@@ -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;
index d03688352ab526c6c24c420911323b377b36e266..559d0e94c3a38a4584d41f72ed4b0faf5bac357c 100644 (file)
--- 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;
 
index a582433b755b6d6f9234708cbf5edb5650de7ef8..830666f7ce5f4dc48d9b5942c0bacfde73b32b7b 100644 (file)
--- 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 9b417894338dd81af572db2c6c6ef21a1f017f58..128f8eeb908ac406b15773180c926de7e57ab0dd 100644 (file)
--- 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)