]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
dynamically grow maxtempentities
authorvortex <vortex@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 19 Mar 2011 20:23:39 +0000 (20:23 +0000)
committervortex <vortex@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 19 Mar 2011 20:23:39 +0000 (20:23 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10935 d7cf8633-e32d-0410-b094-e92efae38249

cl_main.c
client.h

index cc3315f2c9414f2b77a50626244cac16da3d352a..e5f6fef1cd9c2166375966332043f379e6e7968a 100644 (file)
--- a/cl_main.c
+++ b/cl_main.c
@@ -630,6 +630,14 @@ static float CL_LerpPoint(void)
 void CL_ClearTempEntities (void)
 {
        r_refdef.scene.numtempentities = 0;
+       // grow tempentities buffer on request
+       if (r_refdef.scene.expandtempentities)
+       {
+               Con_Printf("CL_NewTempEntity: grow maxtempentities from %i to %i\n", r_refdef.scene.maxtempentities, r_refdef.scene.maxtempentities * 2);
+               r_refdef.scene.maxtempentities *= 2;
+               r_refdef.scene.tempentities = (entity_render_t *)Mem_Realloc(cls.permanentmempool, r_refdef.scene.tempentities, sizeof(entity_render_t) * r_refdef.scene.maxtempentities);
+               r_refdef.scene.expandtempentities = false;
+       }
 }
 
 entity_render_t *CL_NewTempEntity(double shadertime)
@@ -639,7 +647,10 @@ entity_render_t *CL_NewTempEntity(double shadertime)
        if (r_refdef.scene.numentities >= r_refdef.scene.maxentities)
                return NULL;
        if (r_refdef.scene.numtempentities >= r_refdef.scene.maxtempentities)
+       {
+               r_refdef.scene.expandtempentities = true; // will be reallocated next frame since current frame may have pointers set already
                return NULL;
+       }
        render = &r_refdef.scene.tempentities[r_refdef.scene.numtempentities++];
        memset (render, 0, sizeof(*render));
        r_refdef.scene.entities[r_refdef.scene.numentities++] = render;
@@ -1881,7 +1892,7 @@ void CL_UpdateWorld(void)
        r_refdef.scene.numlights = 0;
        r_refdef.view.matrix = identitymatrix;
        r_refdef.view.quality = 1;
-
+               
        cl.num_brushmodel_entities = 0;
 
        if (cls.state == ca_connected && cls.signon == SIGNONS)
@@ -2361,7 +2372,6 @@ CL_Init
 */
 void CL_Init (void)
 {
-       int i;
 
        cls.levelmempool = Mem_AllocPool("client (per-level memory)", 0, NULL);
        cls.permanentmempool = Mem_AllocPool("client (long term memory)", 0, NULL);
@@ -2372,12 +2382,7 @@ void CL_Init (void)
        r_refdef.scene.entities = (entity_render_t **)Mem_Alloc(cls.permanentmempool, sizeof(entity_render_t *) * r_refdef.scene.maxentities);
 
        // max temp entities
-       // FIXME: make this grow
-       i = COM_CheckParm("-maxtempents");
-       if (i)
-               r_refdef.scene.maxtempentities = atof(com_argv[i + 1]);
-       else
-               r_refdef.scene.maxtempentities = MAX_TEMPENTITIES;
+       r_refdef.scene.maxtempentities = MAX_TEMPENTITIES;
        r_refdef.scene.tempentities = (entity_render_t *)Mem_Alloc(cls.permanentmempool, sizeof(entity_render_t) * r_refdef.scene.maxtempentities);
 
        CL_InitInput ();
index 54c637b2d64aa514b8bd65dfc84eac9d6e2e22c1..b9077cc4b6b82bc0c80baf17da2e18a91f4003b0 100644 (file)
--- a/client.h
+++ b/client.h
@@ -1732,6 +1732,7 @@ typedef struct r_refdef_scene_s {
        entity_render_t *tempentities;
        int numtempentities;
        int maxtempentities;
+       qboolean expandtempentities;
 
        // renderable dynamic lights
        rtlight_t *lights[MAX_DLIGHTS];