]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
reduced uninitialized memory a bit more
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 7 May 2007 08:46:37 +0000 (08:46 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 7 May 2007 08:46:37 +0000 (08:46 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7246 d7cf8633-e32d-0410-b094-e92efae38249

client.h
gl_rsurf.c

index 83e488466986fbaf4e41a9e59278295b342cf02f..78392e93066097a80b317e213951818cb3e37715 100644 (file)
--- a/client.h
+++ b/client.h
@@ -999,6 +999,11 @@ typedef struct client_state_s
        // this is updated to cl.movement_origin whenever health is < 1
        // used by %d print in say/say_team messages if cl_locs_enable is on
        vec3_t lastdeathorigin;
+
+       // processing buffer used by R_BuildLightMap, reallocated as needed,
+       // freed on each level change
+       size_t buildlightmapmemorysize;
+       unsigned char *buildlightmapmemory;
 }
 client_state_t;
 
index 0cc320018e7401d9a4641a6195f9efc7a68f04a7..cd0c3c9575176caba2915db98b4292e04c7c7c8f 100644 (file)
@@ -44,16 +44,30 @@ void R_BuildLightMap (const entity_render_t *ent, msurface_t *surface)
        int *bl, scale;
        unsigned char *lightmap, *out, *stain;
        model_t *model = ent->model;
-       static int intblocklights[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE*3]; // LordHavoc: *3 for colored lighting
-       static unsigned char templight[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE*4];
-
-       // update cached lighting info
-       surface->cached_dlight = 0;
+       int *intblocklights;
+       unsigned char *templight;
 
        smax = (surface->lightmapinfo->extents[0]>>4)+1;
        tmax = (surface->lightmapinfo->extents[1]>>4)+1;
        size = smax*tmax;
        size3 = size*3;
+
+       if (cl.buildlightmapmemorysize < size*sizeof(int[3]))
+       {
+               cl.buildlightmapmemorysize = size*sizeof(int[3]);
+               if (cl.buildlightmapmemory)
+                       Mem_Free(cl.buildlightmapmemory);
+               cl.buildlightmapmemory = Mem_Alloc(cls.levelmempool, cl.buildlightmapmemorysize);
+       }
+
+       // these both point at the same buffer, templight is only used for final
+       // processing and can replace the intblocklights data as it goes
+       intblocklights = (int *)cl.buildlightmapmemory;
+       templight = (unsigned char *)cl.buildlightmapmemory;
+
+       // update cached lighting info
+       surface->cached_dlight = 0;
+
        lightmap = surface->lightmapinfo->samples;
 
 // set to full bright if no light data