diff --git a/src/Cube.mm b/src/Cube.mm index 37a1635..6621caa 100644 --- a/src/Cube.mm +++ b/src/Cube.mm @@ -345,15 +345,6 @@ fatal(OFString *s, OFString *o) // failure exit [OFApplication terminateWithStatus:1]; } -void * -alloc(int s) // for some big chunks... most other allocs use the memory pool -{ - void *b = calloc(1, s); - if (!b) - fatal(@"out of memory!"); - return b; -} - void quit() // normal exit { diff --git a/src/clientgame.mm b/src/clientgame.mm index d7ff44d..e9045ae 100644 --- a/src/clientgame.mm +++ b/src/clientgame.mm @@ -100,7 +100,7 @@ spawnstate(dynent *d) // reset player state not persistent accross spawns dynent * newdynent() // create a new blank player or monster { - dynent *d = (dynent *)malloc(sizeof(dynent)); + dynent *d = (dynent *)OFAllocMemory(1, sizeof(dynent)); d->o.x = 0; d->o.y = 0; d->o.z = 0; @@ -185,8 +185,7 @@ arenarespawn() void zapdynent(dynent *&d) { - if (d) - free(d); + OFFreeMemory(d); d = NULL; } @@ -281,9 +280,9 @@ updateworld(int millis) // main game update loop lastmillis = millis; } +// brute force but effective way to find a free spawn spot in the map void -entinmap(dynent * - d) // brute force but effective way to find a free spawn spot in the map +entinmap(dynent *d) { loopi(100) // try max 100 times { diff --git a/src/editing.mm b/src/editing.mm index 7d0e2fe..1099b72 100644 --- a/src/editing.mm +++ b/src/editing.mm @@ -247,7 +247,7 @@ pruneundos(int maxremain) // bound memory { t += undos[i]->xs * undos[i]->ys * sizeof(sqr); if (t > maxremain) - free(undos.remove(i)); + OFFreeMemory(undos.remove(i)); } } @@ -268,7 +268,7 @@ editundo() } block *p = undos.pop(); blockpaste(*p); - free(p); + OFFreeMemory(p); } block *copybuf = NULL; @@ -278,7 +278,7 @@ copy() { EDITSELMP; if (copybuf) - free(copybuf); + OFFreeMemory(copybuf); copybuf = blockcopy(sel); } diff --git a/src/protos.h b/src/protos.h index 00f890f..441dae7 100644 --- a/src/protos.h +++ b/src/protos.h @@ -140,7 +140,6 @@ extern int isoccluded(float vx, float vy, float cx, float cy, float csize); // main extern void fatal(OFString *s, OFString *o = @""); -extern void *alloc(int s); // rendertext extern void draw_text(OFString *string, int left, int top, int gl_num); diff --git a/src/rendercubes.mm b/src/rendercubes.mm index 60ed42d..b5127fb 100644 --- a/src/rendercubes.mm +++ b/src/rendercubes.mm @@ -18,10 +18,9 @@ setarraypointers() void reallocv() { - verts = (vertex *)realloc(verts, (curmaxverts *= 2) * sizeof(vertex)); + verts = + (vertex *)OFResizeMemory(verts, (curmaxverts *= 2), sizeof(vertex)); curmaxverts -= 10; - if (!verts) - fatal(@"no vertex memory!"); setarraypointers(); } diff --git a/src/rendergl.mm b/src/rendergl.mm index 026ba5f..e582ee4 100644 --- a/src/rendergl.mm +++ b/src/rendergl.mm @@ -141,7 +141,7 @@ installtex(int tnum, OFIRI *IRI, int *xs, int *ys, bool clamp) if (*xs != s->w) { conoutf(@"warning: quality loss: scaling %@", IRI.string); // for voodoo cards under linux - scaledimg = alloc(*xs * *ys * 3); + scaledimg = OFAllocMemory(1, *xs * *ys * 3); gluScaleImage(GL_RGB, s->w, s->h, GL_UNSIGNED_BYTE, s->pixels, *xs, *ys, GL_UNSIGNED_BYTE, scaledimg); } diff --git a/src/serverutil.mm b/src/serverutil.mm index 2b454ad..38d34d4 100644 --- a/src/serverutil.mm +++ b/src/serverutil.mm @@ -108,8 +108,8 @@ sendmaps(int n, OFString *mapname, int mapsize, uchar *mapdata) copyname = mapname; copysize = mapsize; if (copydata) - free(copydata); - copydata = (uchar *)alloc(mapsize); + OFFreeMemory(copydata); + copydata = (uchar *)OFAllocMemory(1, mapsize); memcpy(copydata, mapdata, mapsize); } diff --git a/src/tools.h b/src/tools.h index 9ffd2cf..0cd74a5 100644 --- a/src/tools.h +++ b/src/tools.h @@ -25,6 +25,8 @@ # include #endif +#import + #ifdef NULL # undef NULL #endif @@ -127,7 +129,7 @@ template struct vector { vector() { alen = 8; - buf = (T *)malloc(alen * sizeof(T)); + buf = (T *)OFAllocMemory(alen, sizeof(T)); ulen = 0; } @@ -212,7 +214,7 @@ template struct vector { void realloc() { - buf = (T *)::realloc(buf, (alen *= 2) * sizeof(T)); + buf = (T *)OFResizeMemory(buf, (alen *= 2), sizeof(T)); } T diff --git a/src/world.mm b/src/world.mm index 8d97b7a..8850535 100644 --- a/src/world.mm +++ b/src/world.mm @@ -423,7 +423,7 @@ setupworld(int factor) ssize = 1 << (sfactor = factor); cubicsize = ssize * ssize; mipsize = cubicsize * 134 / 100; - sqr *w = world = (sqr *)alloc(mipsize * sizeof(sqr)); + sqr *w = world = (sqr *)OFAllocZeroedMemory(mipsize, sizeof(sqr)); loopi(LARGEST_FACTOR * 2) { wmip[i] = w; @@ -431,10 +431,10 @@ setupworld(int factor) } } +// main empty world creation routine, if passed factor -1 will enlarge old +// world by 1 void -empty_world( - int factor, bool force) // main empty world creation routine, if passed - // factor -1 will enlarge old world by 1 +empty_world(int factor, bool force) { if (!force && noteditmode()) return; @@ -495,7 +495,7 @@ empty_world( calclight(); startmap(@"base/unnamed"); if (oldworld) { - free(oldworld); + OFFreeMemory(oldworld); toggleedit(); execute(@"fullbright 1"); } diff --git a/src/worldlight.mm b/src/worldlight.mm index f6818b1..df447b1 100644 --- a/src/worldlight.mm +++ b/src/worldlight.mm @@ -238,7 +238,8 @@ dodynlight( block * blockcopy(block &s) { - block *b = (block *)alloc(sizeof(block) + s.xs * s.ys * sizeof(sqr)); + block *b = (block *)OFAllocZeroedMemory( + 1, sizeof(block) + s.xs * s.ys * sizeof(sqr)); *b = s; sqr *q = (sqr *)(b + 1); for (int x = s.x; x < s.xs + s.x; x++)