allocate memory for big temporary storage arrays rather than using the
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 21 Dec 2009 07:11:36 +0000 (07:11 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 21 Dec 2009 07:11:36 +0000 (07:11 +0000)
stack

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

14 files changed:
cl_collision.c
cl_particles.c
clvm_cmds.c
gl_draw.c
gl_rmain.c
gl_rsurf.c
meshqueue.c
model_brush.c
model_shared.c
protocol.c
r_explosion.c
sv_main.c
sv_phys.c
svvm_cmds.c

index 0ae9f27..e9fd16f 100644 (file)
@@ -246,7 +246,7 @@ trace_t CL_TracePoint(const vec3_t start, int type, prvm_edict_t *passedict, int
        dp_model_t *model;
        // list of entities to test for collisions
        int numtouchedicts;
-       prvm_edict_t *touchedicts[MAX_EDICTS];
+       static prvm_edict_t *touchedicts[MAX_EDICTS];
 
        if (hitnetworkentity)
                *hitnetworkentity = 0;
@@ -458,7 +458,7 @@ trace_t CL_TraceLine(const vec3_t start, const vec3_t end, int type, prvm_edict_
        dp_model_t *model;
        // list of entities to test for collisions
        int numtouchedicts;
-       prvm_edict_t *touchedicts[MAX_EDICTS];
+       static prvm_edict_t *touchedicts[MAX_EDICTS];
 #ifdef COLLISION_STUPID_TRACE_ENDPOS_IN_SOLID_WORKAROUND
        vec3_t end;
        vec_t len = 0;
@@ -696,7 +696,7 @@ trace_t CL_TraceBox(const vec3_t start, const vec3_t mins, const vec3_t maxs, co
        dp_model_t *model;
        // list of entities to test for collisions
        int numtouchedicts;
-       prvm_edict_t *touchedicts[MAX_EDICTS];
+       static prvm_edict_t *touchedicts[MAX_EDICTS];
 #ifdef COLLISION_STUPID_TRACE_ENDPOS_IN_SOLID_WORKAROUND
        vec3_t end;
        vec_t len = 0;
index 404ff84..f607fab 100644 (file)
@@ -1856,32 +1856,33 @@ void particletextureinvert(unsigned char *data)
 static void R_InitBloodTextures (unsigned char *particletexturedata)
 {
        int i, j, k, m;
-       unsigned char data[PARTICLETEXTURESIZE][PARTICLETEXTURESIZE][4];
+       unsigned char *data = Mem_Alloc(tempmempool, PARTICLETEXTURESIZE*PARTICLETEXTURESIZE*4);
 
        // blood particles
        for (i = 0;i < 8;i++)
        {
-               memset(&data[0][0][0], 255, sizeof(data));
+               memset(data, 255, sizeof(data));
                for (k = 0;k < 24;k++)
-                       particletextureblotch(&data[0][0][0], PARTICLETEXTURESIZE/16, 96, 0, 0, 160);
-               //particletextureclamp(&data[0][0][0], 32, 32, 32, 255, 255, 255);
-               particletextureinvert(&data[0][0][0]);
-               setuptex(tex_bloodparticle[i], &data[0][0][0], particletexturedata);
+                       particletextureblotch(data, PARTICLETEXTURESIZE/16, 96, 0, 0, 160);
+               //particletextureclamp(data, 32, 32, 32, 255, 255, 255);
+               particletextureinvert(data);
+               setuptex(tex_bloodparticle[i], data, particletexturedata);
        }
 
        // blood decals
        for (i = 0;i < 8;i++)
        {
-               memset(&data[0][0][0], 255, sizeof(data));
+               memset(data, 255, sizeof(data));
                m = 8;
                for (j = 1;j < 10;j++)
                        for (k = min(j, m - 1);k < m;k++)
-                               particletextureblotch(&data[0][0][0], (float)j*PARTICLETEXTURESIZE/64.0f, 96, 0, 0, 320 - j * 8);
-               //particletextureclamp(&data[0][0][0], 32, 32, 32, 255, 255, 255);
-               particletextureinvert(&data[0][0][0]);
-               setuptex(tex_blooddecal[i], &data[0][0][0], particletexturedata);
+                               particletextureblotch(data, (float)j*PARTICLETEXTURESIZE/64.0f, 96, 0, 0, 320 - j * 8);
+               //particletextureclamp(data, 32, 32, 32, 255, 255, 255);
+               particletextureinvert(data);
+               setuptex(tex_blooddecal[i], data, particletexturedata);
        }
 
+       Mem_Free(data);
 }
 
 //uncomment this to make engine save out particle font to a tga file when run
@@ -1922,7 +1923,9 @@ static void R_InitParticleTexture (void)
 #endif
        {
                unsigned char *particletexturedata = (unsigned char *)Mem_Alloc(tempmempool, PARTICLEFONTSIZE*PARTICLEFONTSIZE*4);
-               unsigned char data[PARTICLETEXTURESIZE][PARTICLETEXTURESIZE][4];
+               unsigned char *data = (unsigned char *)Mem_Alloc(tempmempool, PARTICLETEXTURESIZE*PARTICLETEXTURESIZE*4);
+               unsigned char *noise1 = (unsigned char *)Mem_Alloc(tempmempool, PARTICLETEXTURESIZE*2*PARTICLETEXTURESIZE*2);
+               unsigned char *noise2 = (unsigned char *)Mem_Alloc(tempmempool, PARTICLETEXTURESIZE*2*PARTICLETEXTURESIZE*2);
 
                particlefontwidth = particlefontheight = PARTICLEFONTSIZE;
                particlefontcellwidth = particlefontcellheight = PARTICLETEXTURESIZE;
@@ -1934,13 +1937,11 @@ static void R_InitParticleTexture (void)
                // smoke
                for (i = 0;i < 8;i++)
                {
-                       memset(&data[0][0][0], 255, sizeof(data));
+                       memset(data, 255, sizeof(data));
                        do
                        {
-                               unsigned char noise1[PARTICLETEXTURESIZE*2][PARTICLETEXTURESIZE*2], noise2[PARTICLETEXTURESIZE*2][PARTICLETEXTURESIZE*2];
-
-                               fractalnoise(&noise1[0][0], PARTICLETEXTURESIZE*2, PARTICLETEXTURESIZE/8);
-                               fractalnoise(&noise2[0][0], PARTICLETEXTURESIZE*2, PARTICLETEXTURESIZE/4);
+                               fractalnoise(noise1, PARTICLETEXTURESIZE*2, PARTICLETEXTURESIZE/8);
+                               fractalnoise(noise2, PARTICLETEXTURESIZE*2, PARTICLETEXTURESIZE/4);
                                m = 0;
                                for (y = 0;y < PARTICLETEXTURESIZE;y++)
                                {
@@ -1948,23 +1949,23 @@ static void R_InitParticleTexture (void)
                                        for (x = 0;x < PARTICLETEXTURESIZE;x++)
                                        {
                                                dx = (x - 0.5f*PARTICLETEXTURESIZE) / (PARTICLETEXTURESIZE*0.5f-1);
-                                               d = (noise2[y][x] - 128) * 3 + 192;
+                                               d = (noise2[y*PARTICLETEXTURESIZE*2+x] - 128) * 3 + 192;
                                                if (d > 0)
                                                        d = (int)(d * (1-(dx*dx+dy*dy)));
-                                               d = (d * noise1[y][x]) >> 7;
+                                               d = (d * noise1[y*PARTICLETEXTURESIZE*2+x]) >> 7;
                                                d = bound(0, d, 255);
-                                               data[y][x][3] = (unsigned char) d;
+                                               data[(y*PARTICLETEXTURESIZE+x)*4+3] = (unsigned char) d;
                                                if (m < d)
                                                        m = d;
                                        }
                                }
                        }
                        while (m < 224);
-                       setuptex(tex_smoke[i], &data[0][0][0], particletexturedata);
+                       setuptex(tex_smoke[i], data, particletexturedata);
                }
 
                // rain splash
-               memset(&data[0][0][0], 255, sizeof(data));
+               memset(data, 255, sizeof(data));
                for (y = 0;y < PARTICLETEXTURESIZE;y++)
                {
                        dy = (y - 0.5f*PARTICLETEXTURESIZE) / (PARTICLETEXTURESIZE*0.5f-1);
@@ -1972,13 +1973,13 @@ static void R_InitParticleTexture (void)
                        {
                                dx = (x - 0.5f*PARTICLETEXTURESIZE) / (PARTICLETEXTURESIZE*0.5f-1);
                                f = 255.0f * (1.0 - 4.0f * fabs(10.0f - sqrt(dx*dx+dy*dy)));
-                               data[y][x][3] = (int) (bound(0.0f, f, 255.0f));
+                               data[(y*PARTICLETEXTURESIZE+x)*4+3] = (int) (bound(0.0f, f, 255.0f));
                        }
                }
-               setuptex(tex_rainsplash, &data[0][0][0], particletexturedata);
+               setuptex(tex_rainsplash, data, particletexturedata);
 
                // normal particle
-               memset(&data[0][0][0], 255, sizeof(data));
+               memset(data, 255, sizeof(data));
                for (y = 0;y < PARTICLETEXTURESIZE;y++)
                {
                        dy = (y - 0.5f*PARTICLETEXTURESIZE) / (PARTICLETEXTURESIZE*0.5f-1);
@@ -1987,13 +1988,13 @@ static void R_InitParticleTexture (void)
                                dx = (x - 0.5f*PARTICLETEXTURESIZE) / (PARTICLETEXTURESIZE*0.5f-1);
                                d = (int)(256 * (1 - (dx*dx+dy*dy)));
                                d = bound(0, d, 255);
-                               data[y][x][3] = (unsigned char) d;
+                               data[(y*PARTICLETEXTURESIZE+x)*4+3] = (unsigned char) d;
                        }
                }
-               setuptex(tex_particle, &data[0][0][0], particletexturedata);
+               setuptex(tex_particle, data, particletexturedata);
 
                // rain
-               memset(&data[0][0][0], 255, sizeof(data));
+               memset(data, 255, sizeof(data));
                light[0] = 1;light[1] = 1;light[2] = 1;
                VectorNormalize(light);
                for (y = 0;y < PARTICLETEXTURESIZE;y++)
@@ -2010,13 +2011,13 @@ static void R_InitParticleTexture (void)
                                dx = (x - 0.5f*PARTICLETEXTURESIZE) / (PARTICLETEXTURESIZE*0.5f-1);
                                // shrink bubble width to half
                                dx *= 2.0f;
-                               data[y][x][3] = shadebubble(dx, dy, light);
+                               data[(y*PARTICLETEXTURESIZE+x)*4+3] = shadebubble(dx, dy, light);
                        }
                }
-               setuptex(tex_raindrop, &data[0][0][0], particletexturedata);
+               setuptex(tex_raindrop, data, particletexturedata);
 
                // bubble
-               memset(&data[0][0][0], 255, sizeof(data));
+               memset(data, 255, sizeof(data));
                light[0] = 1;light[1] = 1;light[2] = 1;
                VectorNormalize(light);
                for (y = 0;y < PARTICLETEXTURESIZE;y++)
@@ -2025,10 +2026,10 @@ static void R_InitParticleTexture (void)
                        for (x = 0;x < PARTICLETEXTURESIZE;x++)
                        {
                                dx = (x - 0.5f*PARTICLETEXTURESIZE) / (PARTICLETEXTURESIZE*0.5f-1);
-                               data[y][x][3] = shadebubble(dx, dy, light);
+                               data[(y*PARTICLETEXTURESIZE+x)*4+3] = shadebubble(dx, dy, light);
                        }
                }
-               setuptex(tex_bubble, &data[0][0][0], particletexturedata);
+               setuptex(tex_bubble, data, particletexturedata);
 
                // Blood particles and blood decals
                R_InitBloodTextures (particletexturedata);
@@ -2036,14 +2037,14 @@ static void R_InitParticleTexture (void)
                // bullet decals
                for (i = 0;i < 8;i++)
                {
-                       memset(&data[0][0][0], 255, sizeof(data));
+                       memset(data, 255, sizeof(data));
                        for (k = 0;k < 12;k++)
-                               particletextureblotch(&data[0][0][0], PARTICLETEXTURESIZE/16, 0, 0, 0, 128);
+                               particletextureblotch(data, PARTICLETEXTURESIZE/16, 0, 0, 0, 128);
                        for (k = 0;k < 3;k++)
-                               particletextureblotch(&data[0][0][0], PARTICLETEXTURESIZE/2, 0, 0, 0, 160);
-                       //particletextureclamp(&data[0][0][0], 64, 64, 64, 255, 255, 255);
-                       particletextureinvert(&data[0][0][0]);
-                       setuptex(tex_bulletdecal[i], &data[0][0][0], particletexturedata);
+                               particletextureblotch(data, PARTICLETEXTURESIZE/2, 0, 0, 0, 160);
+                       //particletextureclamp(data, 64, 64, 64, 255, 255, 255);
+                       particletextureinvert(data);
+                       setuptex(tex_bulletdecal[i], data, particletexturedata);
                }
 
 #ifdef DUMPPARTICLEFONT
@@ -2054,6 +2055,9 @@ static void R_InitParticleTexture (void)
                particlefonttexture = decalskinframe->base;
 
                Mem_Free(particletexturedata);
+               Mem_Free(data);
+               Mem_Free(noise1);
+               Mem_Free(noise2);
        }
        for (i = 0;i < MAX_PARTICLETEXTURES;i++)
        {
@@ -2176,6 +2180,7 @@ static void r_part_newmap(void)
 
 #define BATCHSIZE 256
 unsigned short particle_elements[BATCHSIZE*6];
+float particle_vertex3f[BATCHSIZE*12], particle_texcoord2f[BATCHSIZE*8], particle_color4f[BATCHSIZE*16];
 
 void R_Particles_Init (void)
 {
@@ -2363,7 +2368,6 @@ void R_DrawParticle_TransparentCallback(const entity_render_t *ent, const rtligh
        float up2[3], v[3], right[3], up[3], fog, ifog, size, len, lenfactor;
        float ambient[3], diffuse[3], diffusenormal[3];
        vec4_t colormultiplier;
-       float particle_vertex3f[BATCHSIZE*12], particle_texcoord2f[BATCHSIZE*8], particle_color4f[BATCHSIZE*16];
 
        RSurf_ActiveWorldEntity();
 
index af07499..9815a9d 100644 (file)
@@ -437,7 +437,7 @@ static void VM_CL_findradius (void)
        vec_t                   radius, radius2;
        vec3_t                  org, eorg, mins, maxs;
        int                             i, numtouchedicts;
-       prvm_edict_t    *touchedicts[MAX_EDICTS];
+       static prvm_edict_t     *touchedicts[MAX_EDICTS];
        int             chainfield;
 
        VM_SAFEPARMCOUNTRANGE(2, 3, VM_CL_findradius);
index 291bdc5..348b70a 100644 (file)
--- a/gl_draw.c
+++ b/gl_draw.c
@@ -51,53 +51,55 @@ static const unsigned char concharimage[FONT_FILESIZE] =
 static rtexture_t *draw_generateconchars(void)
 {
        int i;
-       unsigned char buffer[65536][4], *data = NULL;
+       unsigned char *data;
        double random;
+       rtexture_t *tex;
 
        data = LoadTGA_BGRA (concharimage, FONT_FILESIZE);
 // Gold numbers
        for (i = 0;i < 8192;i++)
        {
                random = lhrandom (0.0,1.0);
-               buffer[i][2] = 83 + (unsigned char)(random * 64);
-               buffer[i][1] = 71 + (unsigned char)(random * 32);
-               buffer[i][0] = 23 + (unsigned char)(random * 16);
-               buffer[i][3] = data[i*4+0];
+               data[i*4+3] = data[i*4+0];
+               data[i*4+2] = 83 + (unsigned char)(random * 64);
+               data[i*4+1] = 71 + (unsigned char)(random * 32);
+               data[i*4+0] = 23 + (unsigned char)(random * 16);
        }
 // White chars
        for (i = 8192;i < 32768;i++)
        {
                random = lhrandom (0.0,1.0);
-               buffer[i][2] = 95 + (unsigned char)(random * 64);
-               buffer[i][1] = 95 + (unsigned char)(random * 64);
-               buffer[i][0] = 95 + (unsigned char)(random * 64);
-               buffer[i][3] = data[i*4+0];
+               data[i*4+3] = data[i*4+0];
+               data[i*4+2] = 95 + (unsigned char)(random * 64);
+               data[i*4+1] = 95 + (unsigned char)(random * 64);
+               data[i*4+0] = 95 + (unsigned char)(random * 64);
        }
 // Gold numbers
        for (i = 32768;i < 40960;i++)
        {
                random = lhrandom (0.0,1.0);
-               buffer[i][2] = 83 + (unsigned char)(random * 64);
-               buffer[i][1] = 71 + (unsigned char)(random * 32);
-               buffer[i][0] = 23 + (unsigned char)(random * 16);
-               buffer[i][3] = data[i*4+0];
+               data[i*4+3] = data[i*4+0];
+               data[i*4+2] = 83 + (unsigned char)(random * 64);
+               data[i*4+1] = 71 + (unsigned char)(random * 32);
+               data[i*4+0] = 23 + (unsigned char)(random * 16);
        }
 // Red chars
        for (i = 40960;i < 65536;i++)
        {
                random = lhrandom (0.0,1.0);
-               buffer[i][2] = 96 + (unsigned char)(random * 64);
-               buffer[i][1] = 43 + (unsigned char)(random * 32);
-               buffer[i][0] = 27 + (unsigned char)(random * 32);
-               buffer[i][3] = data[i*4+0];
+               data[i*4+3] = data[i*4+0];
+               data[i*4+2] = 96 + (unsigned char)(random * 64);
+               data[i*4+1] = 43 + (unsigned char)(random * 32);
+               data[i*4+0] = 27 + (unsigned char)(random * 32);
        }
 
 #if 0
-       Image_WriteTGABGRA ("gfx/generated_conchars.tga", 256, 256, &buffer[0][0]);
+       Image_WriteTGABGRA ("gfx/generated_conchars.tga", 256, 256, data);
 #endif
 
+       tex = R_LoadTexture2D(drawtexturepool, "conchars", 256, 256, data, TEXTYPE_BGRA, TEXF_ALPHA | TEXF_PRECACHE, NULL);
        Mem_Free(data);
-       return R_LoadTexture2D(drawtexturepool, "conchars", 256, 256, &buffer[0][0], TEXTYPE_BGRA, TEXF_ALPHA | TEXF_PRECACHE, NULL);
+       return tex;
 }
 
 static rtexture_t *draw_generateditherpattern(void)
@@ -1014,9 +1016,9 @@ float DrawQ_String_Font(float startx, float starty, const char *text, size_t max
        float *av, *at, *ac;
        float color[4];
        int batchcount;
-       float vertex3f[QUADELEMENTS_MAXQUADS*4*3];
-       float texcoord2f[QUADELEMENTS_MAXQUADS*4*2];
-       float color4f[QUADELEMENTS_MAXQUADS*4*4];
+       static float vertex3f[QUADELEMENTS_MAXQUADS*4*3];
+       static float texcoord2f[QUADELEMENTS_MAXQUADS*4*2];
+       static float color4f[QUADELEMENTS_MAXQUADS*4*4];
        int ch;
        int tempcolorindex;
 
index d0c5fea..e7c97c0 100644 (file)
@@ -343,7 +343,8 @@ static void R_BuildNormalizationCube(void)
        vec3_t v;
        vec_t s, t, intensity;
 #define NORMSIZE 64
-       unsigned char data[6][NORMSIZE][NORMSIZE][4];
+       unsigned char *data;
+       data = Mem_Alloc(tempmempool, 6*NORMSIZE*NORMSIZE*4);
        for (side = 0;side < 6;side++)
        {
                for (y = 0;y < NORMSIZE;y++)
@@ -387,14 +388,15 @@ static void R_BuildNormalizationCube(void)
                                        break;
                                }
                                intensity = 127.0f / sqrt(DotProduct(v, v));
-                               data[side][y][x][2] = (unsigned char)(128.0f + intensity * v[0]);
-                               data[side][y][x][1] = (unsigned char)(128.0f + intensity * v[1]);
-                               data[side][y][x][0] = (unsigned char)(128.0f + intensity * v[2]);
-                               data[side][y][x][3] = 255;
+                               data[((side*64+y)*64+x)*4+2] = (unsigned char)(128.0f + intensity * v[0]);
+                               data[((side*64+y)*64+x)*4+1] = (unsigned char)(128.0f + intensity * v[1]);
+                               data[((side*64+y)*64+x)*4+0] = (unsigned char)(128.0f + intensity * v[2]);
+                               data[((side*64+y)*64+x)*4+3] = 255;
                        }
                }
        }
-       r_texture_normalizationcube = R_LoadTextureCubeMap(r_main_texturepool, "normalcube", NORMSIZE, &data[0][0][0][0], TEXTYPE_BGRA, TEXF_PRECACHE | TEXF_CLAMP | TEXF_PERSISTENT, NULL);
+       r_texture_normalizationcube = R_LoadTextureCubeMap(r_main_texturepool, "normalcube", NORMSIZE, data, TEXTYPE_BGRA, TEXF_PRECACHE | TEXF_CLAMP | TEXF_PERSISTENT, NULL);
+       Mem_Free(data);
 }
 
 static void R_BuildFogTexture(void)
@@ -7098,7 +7100,7 @@ void RSurf_DrawBatch_Simple(int texturenumsurfaces, const msurface_t **texturesu
        {
                #define MAXBATCHTRIANGLES 4096
                int batchtriangles = 0;
-               int batchelements[MAXBATCHTRIANGLES*3];
+               static int batchelements[MAXBATCHTRIANGLES*3];
                for (i = 0;i < texturenumsurfaces;i = j)
                {
                        surface = texturesurfacelist[i];
@@ -8210,7 +8212,7 @@ static void R_DrawSurface_TransparentCallback(const entity_render_t *ent, const
        int texturenumsurfaces, endsurface;
        texture_t *texture;
        const msurface_t *surface;
-       const msurface_t *texturesurfacelist[1024];
+       const msurface_t *texturesurfacelist[256];
 
        // if the model is static it doesn't matter what value we give for
        // wantnormals and wanttangents, so this logic uses only rules applicable
index 085eb1e..c3d6222 100644 (file)
@@ -724,7 +724,7 @@ static void R_Q1BSP_RecursiveGetLightInfo(r_q1bsp_getlightinfo_t *info, mnode_t
        {
                int i;
                mportal_t *portal;
-               double points[128][3];
+               static double points[128][3];
                for (portal = leaf->portals;portal;portal = portal->next)
                {
                        for (i = 0;i < portal->numpoints;i++)
index 7d5a9c3..a5510be 100644 (file)
@@ -61,7 +61,7 @@ void R_MeshQueue_RenderTransparent(void)
        const rtlight_t *rtlight;
        void (*callback)(const entity_render_t *ent, const rtlight_t *rtlight, int numsurfaces, int *surfaceindices);
        meshqueue_t *mqt;
-       meshqueue_t *hash[4096], **hashpointer[4096];
+       static meshqueue_t *hash[4096], **hashpointer[4096];
        int batchsurfaceindex[256];
        if (!mqt_count)
                return;
index f58d7a9..6fbad62 100644 (file)
@@ -3140,6 +3140,9 @@ static void RemovePortalFromNodes(portal_t *portal)
 }
 
 #define PORTAL_DIST_EPSILON (1.0 / 32.0)
+static double *portalpointsbuffer;
+static int portalpointsbufferoffset;
+static int portalpointsbuffersize;
 static void Mod_Q1BSP_RecursiveNodePortals(mnode_t *node)
 {
        int i, side;
@@ -3147,12 +3150,23 @@ static void Mod_Q1BSP_RecursiveNodePortals(mnode_t *node)
        mplane_t clipplane, *plane;
        portal_t *portal, *nextportal, *nodeportal, *splitportal, *temp;
        int numfrontpoints, numbackpoints;
-       double frontpoints[3*MAX_PORTALPOINTS], backpoints[3*MAX_PORTALPOINTS];
+       double *frontpoints, *backpoints;
 
        // if a leaf, we're done
        if (!node->plane)
                return;
 
+       // get some space for our clipping operations to use
+       if (portalpointsbuffersize < portalpointsbufferoffset + 6*MAX_PORTALPOINTS)
+       {
+               portalpointsbuffersize = portalpointsbufferoffset * 2;
+               portalpointsbuffer = Mem_Realloc(loadmodel->mempool, portalpointsbuffer, portalpointsbuffersize * sizeof(*portalpointsbuffer));
+       }
+       frontpoints = portalpointsbuffer + portalpointsbufferoffset;
+       portalpointsbufferoffset += 3*MAX_PORTALPOINTS;
+       backpoints = portalpointsbuffer + portalpointsbufferoffset;
+       portalpointsbufferoffset += 3*MAX_PORTALPOINTS;
+
        plane = node->plane;
 
        front = node->children[0];
@@ -3270,12 +3284,21 @@ static void Mod_Q1BSP_RecursiveNodePortals(mnode_t *node)
 
        Mod_Q1BSP_RecursiveNodePortals(front);
        Mod_Q1BSP_RecursiveNodePortals(back);
+
+       portalpointsbufferoffset -= 6*MAX_PORTALPOINTS;
 }
 
 static void Mod_Q1BSP_MakePortals(void)
 {
        Mem_ExpandableArray_NewArray(&portalarray, loadmodel->mempool, sizeof(portal_t), 1020*1024/sizeof(portal_t));
+       portalpointsbufferoffset = 0;
+       portalpointsbuffersize = 6*MAX_PORTALPOINTS*128;
+       portalpointsbuffer = Mem_Alloc(loadmodel->mempool, portalpointsbuffersize * sizeof(*portalpointsbuffer));
        Mod_Q1BSP_RecursiveNodePortals(loadmodel->brush.data_nodes + loadmodel->brushq1.hulls[0].firstclipnode);
+       Mem_Free(portalpointsbuffer);
+       portalpointsbuffer = NULL;
+       portalpointsbufferoffset = 0;
+       portalpointsbuffersize = 0;
        Mod_Q1BSP_FinalizePortals();
        Mem_ExpandableArray_FreeArray(&portalarray);
 }
index b9b140e..7697fa6 100644 (file)
@@ -655,12 +655,13 @@ void Mod_BuildTriangleNeighbors(int *neighbors, const int *elements, int numtria
                int element[2];
        }
        edgehashentry_t;
-       edgehashentry_t *edgehash[TRIANGLEEDGEHASH], *edgehashentries, edgehashentriesbuffer[TRIANGLEEDGEHASH*3], *hash;
+       static edgehashentry_t *edgehash[TRIANGLEEDGEHASH];
+       edgehashentry_t *edgehashentries, *hash;
+       if (!numtriangles)
+               return;
        memset(edgehash, 0, sizeof(edgehash));
-       edgehashentries = edgehashentriesbuffer;
        // if there are too many triangles for the stack array, allocate larger buffer
-       if (numtriangles > TRIANGLEEDGEHASH)
-               edgehashentries = (edgehashentry_t *)Mem_Alloc(tempmempool, numtriangles * 3 * sizeof(edgehashentry_t));
+       edgehashentries = (edgehashentry_t *)Mem_Alloc(tempmempool, numtriangles * 3 * sizeof(edgehashentry_t));
        // find neighboring triangles
        for (i = 0, e = elements, n = neighbors;i < numtriangles;i++, e += 3, n += 3)
        {
@@ -709,8 +710,7 @@ void Mod_BuildTriangleNeighbors(int *neighbors, const int *elements, int numtria
                CL_KeepaliveMessage(false);
        }
        // free the allocated buffer
-       if (edgehashentries != edgehashentriesbuffer)
-               Mem_Free(edgehashentries);
+       Mem_Free(edgehashentries);
 }
 #else
 // very slow but simple way
index da7085d..31c2e54 100644 (file)
@@ -302,7 +302,7 @@ void EntityFrameCSQC_LostFrame(client_t *client, int framenum)
        int i, j, n;
        qboolean valid;
        int ringfirst, ringlast;
-       int recoversendflags[MAX_EDICTS];
+       static int recoversendflags[MAX_EDICTS];
        csqcentityframedb_t *d;
 
        n = client->csqcnumedicts;
index 4a96596..0911135 100644 (file)
@@ -63,7 +63,7 @@ extern qboolean r_loadfog;
 static void r_explosion_start(void)
 {
        int x, y;
-       unsigned char noise1[128][128], noise2[128][128], noise3[128][128], data[128][128][4];
+       static unsigned char noise1[128][128], noise2[128][128], noise3[128][128], data[128][128][4];
        explosiontexturepool = R_AllocTexturePool();
        explosiontexture = NULL;
        explosiontexturefog = NULL;
index 497e680..a45dfc7 100644 (file)
--- a/sv_main.c
+++ b/sv_main.c
@@ -1354,7 +1354,7 @@ qboolean SV_CanSeeBox(int numtraces, vec_t enlarge, vec3_t eye, vec3_t entboxmin
        matrix4x4_t matrix, imatrix;
        dp_model_t *model;
        prvm_edict_t *touch;
-       prvm_edict_t *touchedicts[MAX_EDICTS];
+       static prvm_edict_t *touchedicts[MAX_EDICTS];
        vec3_t boxmins, boxmaxs;
        vec3_t clipboxmins, clipboxmaxs;
        vec3_t endpoints[MAX_LINEOFSIGHTTRACES];
index 7235fac..b3d9810 100644 (file)
--- a/sv_phys.c
+++ b/sv_phys.c
@@ -121,7 +121,7 @@ trace_t SV_TracePoint(const vec3_t start, int type, prvm_edict_t *passedict, int
        dp_model_t *model;
        // list of entities to test for collisions
        int numtouchedicts;
-       prvm_edict_t *touchedicts[MAX_EDICTS];
+       static prvm_edict_t *touchedicts[MAX_EDICTS];
 
        //return SV_TraceBox(start, vec3_origin, vec3_origin, end, type, passedict, hitsupercontentsmask);
 
@@ -266,7 +266,7 @@ trace_t SV_TraceLine(const vec3_t start, const vec3_t end, int type, prvm_edict_
        dp_model_t *model;
        // list of entities to test for collisions
        int numtouchedicts;
-       prvm_edict_t *touchedicts[MAX_EDICTS];
+       static prvm_edict_t *touchedicts[MAX_EDICTS];
 #ifdef COLLISION_STUPID_TRACE_ENDPOS_IN_SOLID_WORKAROUND
        vec3_t end;
        vec_t len = 0;
@@ -445,7 +445,7 @@ trace_t SV_TraceBox(const vec3_t start, const vec3_t mins, const vec3_t maxs, co
        dp_model_t *model;
        // list of entities to test for collisions
        int numtouchedicts;
-       prvm_edict_t *touchedicts[MAX_EDICTS];
+       static prvm_edict_t *touchedicts[MAX_EDICTS];
 #ifdef COLLISION_STUPID_TRACE_ENDPOS_IN_SOLID_WORKAROUND
        vec3_t end;
        vec_t len = 0;
@@ -636,7 +636,7 @@ int SV_PointSuperContents(const vec3_t point)
        int frame;
        // list of entities to test for collisions
        int numtouchedicts;
-       prvm_edict_t *touchedicts[MAX_EDICTS];
+       static prvm_edict_t *touchedicts[MAX_EDICTS];
 
        // get world supercontents at this point
        if (sv.worldmodel && sv.worldmodel->PointSuperContents)
@@ -713,7 +713,8 @@ void SV_LinkEdict_TouchAreaGrid_Call(prvm_edict_t *touch, prvm_edict_t *ent)
 void SV_LinkEdict_TouchAreaGrid(prvm_edict_t *ent)
 {
        int i, numtouchedicts, old_self, old_other;
-       prvm_edict_t *touch, *touchedicts[MAX_EDICTS];
+       prvm_edict_t *touch;
+       static prvm_edict_t *touchedicts[MAX_EDICTS];
 
        if (ent == prog->edicts)
                return;         // don't add the world
@@ -1555,7 +1556,7 @@ void SV_PushMove (prvm_edict_t *pusher, float movetime)
        dp_model_t *pushermodel;
        trace_t trace, trace2;
        matrix4x4_t pusherfinalmatrix, pusherfinalimatrix;
-       unsigned short moved_edicts[MAX_EDICTS];
+       static unsigned short moved_edicts[MAX_EDICTS];
 
        if (!pusher->fields.server->velocity[0] && !pusher->fields.server->velocity[1] && !pusher->fields.server->velocity[2] && !pusher->fields.server->avelocity[0] && !pusher->fields.server->avelocity[1] && !pusher->fields.server->avelocity[2])
        {
index f282df4..e0e5dc3 100644 (file)
@@ -922,7 +922,7 @@ static void VM_SV_findradius (void)
        vec3_t org, eorg, mins, maxs;
        int i;
        int numtouchedicts;
-       prvm_edict_t *touchedicts[MAX_EDICTS];
+       static prvm_edict_t *touchedicts[MAX_EDICTS];
        int chainfield;
 
        VM_SAFEPARMCOUNTRANGE(2, 3, VM_SV_findradius);