From: havoc Date: Mon, 21 Dec 2009 07:11:36 +0000 (+0000) Subject: allocate memory for big temporary storage arrays rather than using the X-Git-Tag: xonotic-v0.1.0preview~1034 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=79d25017219944e264aadc7ab556c86d3955e4b2;p=xonotic%2Fdarkplaces.git allocate memory for big temporary storage arrays rather than using the stack git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9614 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/cl_collision.c b/cl_collision.c index 0ae9f27a..e9fd16fc 100644 --- a/cl_collision.c +++ b/cl_collision.c @@ -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; diff --git a/cl_particles.c b/cl_particles.c index 404ff845..f607fab8 100644 --- a/cl_particles.c +++ b/cl_particles.c @@ -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(); diff --git a/clvm_cmds.c b/clvm_cmds.c index af074998..9815a9d2 100644 --- a/clvm_cmds.c +++ b/clvm_cmds.c @@ -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); diff --git a/gl_draw.c b/gl_draw.c index 291bdc53..348b70af 100644 --- 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; diff --git a/gl_rmain.c b/gl_rmain.c index d0c5fea8..e7c97c03 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -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 diff --git a/gl_rsurf.c b/gl_rsurf.c index 085eb1e3..c3d62225 100644 --- a/gl_rsurf.c +++ b/gl_rsurf.c @@ -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++) diff --git a/meshqueue.c b/meshqueue.c index 7d5a9c3a..a5510be7 100644 --- a/meshqueue.c +++ b/meshqueue.c @@ -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; diff --git a/model_brush.c b/model_brush.c index f58d7a94..6fbad625 100644 --- a/model_brush.c +++ b/model_brush.c @@ -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); } diff --git a/model_shared.c b/model_shared.c index b9b140e0..7697fa6e 100644 --- a/model_shared.c +++ b/model_shared.c @@ -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 diff --git a/protocol.c b/protocol.c index da7085d7..31c2e54c 100644 --- a/protocol.c +++ b/protocol.c @@ -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; diff --git a/r_explosion.c b/r_explosion.c index 4a965964..09111357 100644 --- a/r_explosion.c +++ b/r_explosion.c @@ -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; diff --git a/sv_main.c b/sv_main.c index 497e6807..a45dfc7a 100644 --- 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]; diff --git a/sv_phys.c b/sv_phys.c index 7235fac7..b3d98100 100644 --- 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]) { diff --git a/svvm_cmds.c b/svvm_cmds.c index f282df49..e0e5dc36 100644 --- a/svvm_cmds.c +++ b/svvm_cmds.c @@ -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);