diff --git a/polymer/eduke32/Makefile.msvc b/polymer/eduke32/Makefile.msvc index d0eef1ec2..e878ceac2 100644 --- a/polymer/eduke32/Makefile.msvc +++ b/polymer/eduke32/Makefile.msvc @@ -43,7 +43,7 @@ CFLAGS= /MT /J /nologo $(flags_cl) \ LIBS=user32.lib gdi32.lib shell32.lib dxguid.lib winmm.lib wsock32.lib comctl32.lib \ /NODEFAULTLIB:glu32.lib /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcrtd.lib -LIBS=vorbisfile_static.lib vorbis_static.lib ogg_static.lib dsound.lib $(LIBS) +LIBS=vorbisfile_static.lib vorbis_static.lib ogg_static.lib dsound.lib advapi32.lib $(LIBS) ASFLAGS=/nologo /coff /c EXESUFFIX=.exe @@ -95,6 +95,9 @@ GAMEOBJS=$(OBJ)\game.$o \ EDITOROBJS=$(OBJ)\astub.$o \ $(OBJ)\mathutil.$o \ + $(OBJ)\m32def.$o \ + $(OBJ)\m32vars.$o \ + $(OBJ)\m32exec.$o \ $(OBJ)\sounds_mapster32.$o \ $(OBJ)\buildres.res \ $(AUDIOLIB_FX) \ diff --git a/polymer/eduke32/build/include/baselayer.h b/polymer/eduke32/build/include/baselayer.h index 664313be2..29e781003 100644 --- a/polymer/eduke32/build/include/baselayer.h +++ b/polymer/eduke32/build/include/baselayer.h @@ -12,7 +12,7 @@ extern "C" { #endif -#define SYSTEM_POOL_SIZE (256 * 1048576) +#define SYSTEM_POOL_SIZE (64 * 1048576) extern int32_t _buildargc; extern const char **_buildargv; diff --git a/polymer/eduke32/build/include/compat.h b/polymer/eduke32/build/include/compat.h index 15220a832..c4df038af 100644 --- a/polymer/eduke32/build/include/compat.h +++ b/polymer/eduke32/build/include/compat.h @@ -37,7 +37,7 @@ #define USE_ALLOCATOR 1 #define REPLACE_SYSTEM_ALLOCATOR 1 -#define USE_MAGIC_HEADERS 1 +#define USE_MAGIC_HEADERS 0 #include "nedmalloc.h" #ifndef TRUE @@ -379,10 +379,10 @@ int32_t Bclosedir(BDIR *dir); #ifdef __compat_h_macrodef__ # define Brand rand # define Balloca alloca -# define Bmalloc malloc -# define Bcalloc calloc -# define Brealloc realloc -# define Bfree free +# define Bmalloc nedmalloc +# define Bcalloc nedcalloc +# define Brealloc nedrealloc +# define Bfree nedfree # define Bopen open # define Bclose close # define Bwrite write @@ -405,11 +405,7 @@ int32_t Bclosedir(BDIR *dir); # define Bfread fread # define Bfwrite fwrite # define Bfprintf fprintf -# if defined(_MSC_VER) -# define Bstrdup _strdup -# else -# define Bstrdup strdup -# endif +# define Bstrdup nedstrdup # define Bstrcpy strcpy # define Bstrncpy strncpy # define Bstrcmp strcmp diff --git a/polymer/eduke32/build/include/m32script.h b/polymer/eduke32/build/include/m32script.h index db3b52519..1d91e72cf 100644 --- a/polymer/eduke32/build/include/m32script.h +++ b/polymer/eduke32/build/include/m32script.h @@ -25,7 +25,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef _m32script_h_ #define _m32script_h_ -#include #include "compat.h" #include "build.h" #include "editor.h" diff --git a/polymer/eduke32/build/include/malloc.c.h b/polymer/eduke32/build/include/malloc.c.h index ebb72ee95..649ea5d2f 100644 --- a/polymer/eduke32/build/include/malloc.c.h +++ b/polymer/eduke32/build/include/malloc.c.h @@ -502,6 +502,7 @@ MAX_RELEASE_CHECK_RATE default: 4095 unless not HAVE_MMAP */ /* Version identifier to allow people to support multiple versions */ + #ifndef DLMALLOC_VERSION #define DLMALLOC_VERSION 20804 #endif /* DLMALLOC_VERSION */ @@ -1638,6 +1639,11 @@ static FORCEINLINE void* win32mmap(size_t size) { void* baseaddress = 0; void* ptr = 0; #ifdef ENABLE_LARGE_PAGES + +#ifndef MEM_LARGE_PAGES + #define MEM_LARGE_PAGES 0x20000000 +#endif + /* Note that large pages are *always* allocated on a large page boundary. If however granularity is small then don't waste a kernel call if size isn't around the size of a large page */ @@ -3093,7 +3099,7 @@ static size_t traverse_and_check(mstate m); /* ---------------------------- setting mparams -------------------------- */ -#ifdef ENABLE_LARGE_PAGES +#if defined(ENABLE_LARGE_PAGES) && defined(WIN32) typedef size_t (WINAPI *GetLargePageMinimum_t)(void); #endif @@ -3122,7 +3128,7 @@ static int init_mparams(void) { DEFAULT_GRANULARITY : system_info.dwAllocationGranularity); #ifdef ENABLE_LARGE_PAGES { - GetLargePageMinimum_t GetLargePageMinimum_ = (GetLargePageMinimum_t) GetProcAddress(GetModuleHandle(__T("kernel32.dll")), "GetLargePageMinimum"); + GetLargePageMinimum_t GetLargePageMinimum_ = (GetLargePageMinimum_t) GetProcAddress(GetModuleHandle("kernel32.dll"), "GetLargePageMinimum"); if(GetLargePageMinimum_) { size_t largepagesize = GetLargePageMinimum_(); if(largepagesize) { diff --git a/polymer/eduke32/build/include/nedmalloc.h b/polymer/eduke32/build/include/nedmalloc.h index f228a96ae..94c95e1d8 100644 --- a/polymer/eduke32/build/include/nedmalloc.h +++ b/polymer/eduke32/build/include/nedmalloc.h @@ -94,7 +94,7 @@ USE_ALLOCATOR can be one of these settings: #if USE_ALLOCATOR==0 #error Cannot combine using the system allocator with replacing the system allocator #endif - #ifndef WIN32 /* We have a dedidicated patcher for Windows */ + #ifndef _WIN32 /* We have a dedidicated patcher for Windows */ #define nedmalloc malloc #define nedcalloc calloc #define nedrealloc realloc @@ -107,9 +107,6 @@ USE_ALLOCATOR can be one of these settings: #define nedmalloc_footprint malloc_footprint #define nedindependent_calloc independent_calloc #define nedindependent_comalloc independent_comalloc - #ifdef _MSC_VER - #define nedblksize _msize - #endif #endif #endif @@ -225,7 +222,7 @@ NEDMALLOCEXTSPEC void nedpmalloc_stats(nedpool *p) THROWSPEC; NEDMALLOCEXTSPEC size_t nedpmalloc_footprint(nedpool *p) THROWSPEC; NEDMALLOCEXTSPEC NEDMALLOCPTRATTR void **nedpindependent_calloc(nedpool *p, size_t elemsno, size_t elemsize, void **chunks) THROWSPEC; NEDMALLOCEXTSPEC NEDMALLOCPTRATTR void **nedpindependent_comalloc(nedpool *p, size_t elems, size_t *sizes, void **chunks) THROWSPEC; - +NEDMALLOCEXTSPEC NEDMALLOCPTRATTR char * nedstrdup(const char *str) THROWSPEC; #if defined(__cplusplus) } #endif diff --git a/polymer/eduke32/build/include/polymer.h b/polymer/eduke32/build/include/polymer.h index 6b68eac50..48be3aaf7 100644 --- a/polymer/eduke32/build/include/polymer.h +++ b/polymer/eduke32/build/include/polymer.h @@ -155,7 +155,7 @@ typedef struct s_prprogrambit { } _prprogrambit; // LIGHTS -#define PR_MAXLIGHTS 256 +#define PR_MAXLIGHTS 1024 #define SHADOW_DEPTH_OFFSET 30 #define PR_MAXLIGHTPRIORITY 6 @@ -290,8 +290,10 @@ typedef struct s_pranimatespritesinfo { } _pranimatespritesinfo; // MEMORY POOL -#define POLYMER_POOL_SIZE 67108864 +/* +#define POLYMER_POOL_SIZE (128 * 1048576) extern nedpool* polymer_pool; +*/ // EXTERNAL FUNCTIONS int32_t polymer_init(void); @@ -317,7 +319,6 @@ static void polymer_drawplane(_prplane* plane); static inline void polymer_inb4mirror(GLfloat* buffer, GLfloat* plane); static void polymer_animatesprites(void); static void polymer_freeboard(void); -static void polymer_editorselect(void); // SECTORS static int32_t polymer_initsector(int16_t sectnum); static int32_t polymer_updatesector(int16_t sectnum); diff --git a/polymer/eduke32/build/src/cache1d.c b/polymer/eduke32/build/src/cache1d.c index 2a1650614..516ce1d21 100644 --- a/polymer/eduke32/build/src/cache1d.c +++ b/polymer/eduke32/build/src/cache1d.c @@ -278,15 +278,15 @@ int32_t addsearchpath(const char *p) } if (!(st.st_mode & BS_IFDIR)) return -1; - srch = (searchpath_t*)malloc(sizeof(searchpath_t)); + srch = (searchpath_t*)Bmalloc(sizeof(searchpath_t)); if (!srch) return -1; srch->next = searchpathhead; srch->pathlen = strlen(p)+1; - srch->path = (char*)malloc(srch->pathlen + 1); + srch->path = (char*)Bmalloc(srch->pathlen + 1); if (!srch->path) { - free(srch); + Bfree(srch); return -1; } strcpy(srch->path, p); @@ -316,13 +316,13 @@ int32_t findfrompath(const char *fn, char **where) // test unmolested filename first if (access(fn, F_OK) >= 0) { - *where = strdup(fn); + *where = Bstrdup(fn); return 0; } } for (pfn = (char*)fn; toupperlookup[*pfn] == '/'; pfn++); - ffn = strdup(pfn); + ffn = Bstrdup(pfn); if (!ffn) return -1; Bcorrectfilename(ffn,0); // compress relative paths @@ -330,15 +330,15 @@ int32_t findfrompath(const char *fn, char **where) allocsiz += strlen(ffn); allocsiz += 1; // a nul - pfn = (char *)malloc(allocsiz); - if (!pfn) { free(ffn); return -1; } + pfn = (char *)Bmalloc(allocsiz); + if (!pfn) { Bfree(ffn); return -1; } strcpy(pfn, "./"); strcat(pfn, ffn); if (access(pfn, F_OK) >= 0) { *where = pfn; - free(ffn); + Bfree(ffn); return 0; } @@ -350,11 +350,11 @@ int32_t findfrompath(const char *fn, char **where) if (access(pfn, F_OK) >= 0) { *where = pfn; - free(ffn); + Bfree(ffn); return 0; } } - free(pfn); free(ffn); + Bfree(pfn); Bfree(ffn); return -1; } @@ -365,7 +365,7 @@ int32_t openfrompath(const char *fn, int32_t flags, int32_t mode) if (findfrompath(fn, &pfn) < 0) return -1; h = Bopen(pfn, flags, mode); - free(pfn); + Bfree(pfn); return h; } @@ -461,17 +461,17 @@ int32_t initgroupfile(char *filename) // check to see if the file passed is a ZIP and pass it on to kplib if it is i = Bopen(zfn,BO_BINARY|BO_RDONLY,BS_IREAD); - if (i < 0) { free(zfn); return -1; } + if (i < 0) { Bfree(zfn); return -1; } Bread(i, buf, 4); if (buf[0] == 0x50 && buf[1] == 0x4B && buf[2] == 0x03 && buf[3] == 0x04) { Bclose(i); j = kzaddstack(zfn); - free(zfn); + Bfree(zfn); return j; } - free(zfn); + Bfree(zfn); if (numgroupfiles >= MAXGROUPFILES) return(-1); @@ -850,7 +850,7 @@ static int32_t klistaddentry(CACHE1D_FIND_REC **rec, char *name, int32_t type, i return 0; } - r = (CACHE1D_FIND_REC *)malloc(sizeof(CACHE1D_FIND_REC)+strlen(name)+1); + r = (CACHE1D_FIND_REC *)Bmalloc(sizeof(CACHE1D_FIND_REC)+strlen(name)+1); if (!r) return -1; r->name = (char*)r + sizeof(CACHE1D_FIND_REC); strcpy(r->name, name); r->type = type; @@ -882,7 +882,7 @@ void klistfree(CACHE1D_FIND_REC *rec) while (rec) { n = rec->next; - free(rec); + Bfree(rec); rec = n; } } @@ -895,7 +895,7 @@ CACHE1D_FIND_REC *klistpath(const char *_path, const char *mask, int32_t type) // pathsearchmode == 0: enumerates a path in the virtual filesystem // pathsearchmode == 1: enumerates the system filesystem path passed in - path = strdup(_path); + path = Bstrdup(_path); if (!path) return NULL; // we don't need any leading dots and slashes or trailing slashes either @@ -1079,18 +1079,18 @@ CACHE1D_FIND_REC *klistpath(const char *_path, const char *mask, int32_t type) { if (klistaddentry(&rec, drp, CACHE1D_FIND_DRIVE, CACHE1D_SOURCE_DRIVE) < 0) { - free(drives); + Bfree(drives); goto failure; } } - free(drives); + Bfree(drives); } } - free(path); + Bfree(path); return rec; failure: - free(path); + Bfree(path); klistfree(rec); return NULL; } diff --git a/polymer/eduke32/build/src/compat.c b/polymer/eduke32/build/src/compat.c index 6085a3bc7..a8712754f 100644 --- a/polymer/eduke32/build/src/compat.c +++ b/polymer/eduke32/build/src/compat.c @@ -52,12 +52,12 @@ int32_t Brand(void) void *Bmalloc(bsize_t size) { - return malloc(size); + return nedmalloc(size); } void Bfree(void *ptr) { - free(ptr); + nedfree(ptr); } int32_t Bopen(const char *pathname, int32_t flags, uint32_t mode) @@ -155,7 +155,7 @@ bsize_t Bfwrite(const void *ptr, bsize_t size, bsize_t nmemb, BFILE *stream) char *Bstrdup(const char *s) { - return strdup(s); + return nedstrdup(s); } char *Bstrcpy(char *dest, const char *src) @@ -355,7 +355,7 @@ char *Bgethomedir(void) { if (loaded) FreeLibrary(hShell32); - return strdup(appdata); + return Bstrdup(appdata); } if (loaded) @@ -374,13 +374,13 @@ char *Bgethomedir(void) CFRelease(base); if (!str) return NULL; s = (char*)CFStringGetCStringPtr(str,CFStringGetSystemEncoding()); - if (s) s = strdup(s); + if (s) s = Bstrdup(s); CFRelease(str); return s; #else char *e = getenv("HOME"); if (!e) return NULL; - return strdup(e); + return Bstrdup(e); #endif } @@ -404,7 +404,7 @@ char *Bgetsupportdir(int32_t global) CFRelease(base); if (!str) return NULL; s = (char*)CFStringGetCStringPtr(str,CFStringGetSystemEncoding()); - if (s) s = strdup(s); + if (s) s = Bstrdup(s); CFRelease(str); return s; #endif @@ -416,7 +416,7 @@ int32_t Bcorrectfilename(char *filename, int32_t removefn) char *tokarr[64], *first, *next = NULL, *token; int32_t i, ntok = 0, leadslash = 0, trailslash = 0; - fn = strdup(filename); + fn = Bstrdup(filename); if (!fn) return -1; for (first=fn; *first; first++) @@ -529,7 +529,7 @@ char *Bgetsystemdrives(void) number++; } - str = p = (char *)malloc(1 + (3*number)); + str = p = (char *)Bmalloc(1 + (3*number)); if (!str) return NULL; number = 0; @@ -576,15 +576,15 @@ BDIR* Bopendir(const char *name) BDIR_real *dirr; #ifdef _MSC_VER char *t,*tt; - t = (char*)malloc(strlen(name)+1+4); + t = (char*)Bmalloc(strlen(name)+1+4); if (!t) return NULL; #endif - dirr = (BDIR_real*)malloc(sizeof(BDIR_real) + strlen(name)); + dirr = (BDIR_real*)Bmalloc(sizeof(BDIR_real) + strlen(name)); if (!dirr) { #ifdef _MSC_VER - free(t); + Bfree(t); #endif return NULL; } @@ -600,17 +600,17 @@ BDIR* Bopendir(const char *name) *(++tt) = 0; dirr->dir = _findfirst(t,&dirr->fid); - free(t); + Bfree(t); if (dirr->dir == -1) { - free(dirr); + Bfree(dirr); return NULL; } #else dirr->dir = opendir(name); if (dirr->dir == NULL) { - free(dirr); + Bfree(dirr); return NULL; } #endif @@ -662,7 +662,7 @@ struct Bdirent* Breaddir(BDIR *dir) dirr->info.size = 0; dirr->info.mtime = 0; - fn = (char *)malloc(strlen(dirr->name) + 1 + dirr->info.namlen + 1); + fn = (char *)Bmalloc(strlen(dirr->name) + 1 + dirr->info.namlen + 1); if (fn) { Bsprintf(fn,"%s/%s",dirr->name,dirr->info.name); @@ -672,7 +672,7 @@ struct Bdirent* Breaddir(BDIR *dir) dirr->info.size = st.st_size; dirr->info.mtime = st.st_mtime; } - free(fn); + Bfree(fn); } return &dirr->info; @@ -687,7 +687,7 @@ int32_t Bclosedir(BDIR *dir) #else closedir(dirr->dir); #endif - free(dirr); + Bfree(dirr); return 0; } diff --git a/polymer/eduke32/build/src/engine.c b/polymer/eduke32/build/src/engine.c index a881799bc..6bb926104 100644 --- a/polymer/eduke32/build/src/engine.c +++ b/polymer/eduke32/build/src/engine.c @@ -6643,6 +6643,7 @@ int32_t loadboard(char *filename, char fromwhere, int32_t *daposx, int32_t *dapo clearbufbyte(&sprite, sizeof(sprite), 0); */ + nedtrimthreadcache(0, 0); initspritelists(); diff --git a/polymer/eduke32/build/src/glbuild.c b/polymer/eduke32/build/src/glbuild.c index 08c10c0eb..b3363aa3f 100644 --- a/polymer/eduke32/build/src/glbuild.c +++ b/polymer/eduke32/build/src/glbuild.c @@ -342,7 +342,7 @@ int32_t loadgldriver(const char *driver) hGLDLL = LoadLibrary(driver); if (!hGLDLL) return -1; #endif - gldriver = strdup(driver); + gldriver = Bstrdup(driver); #ifdef RENDERTYPEWIN bwglCreateContext = GETPROC("wglCreateContext"); @@ -624,7 +624,7 @@ int32_t unloadgldriver(void) if (!hGLDLL) return 0; #endif - free(gldriver); + Bfree(gldriver); gldriver = NULL; #ifdef RENDERTYPEWIN @@ -930,7 +930,7 @@ int32_t loadglulibrary(const char *driver) gluhandle = dlopen(driver, RTLD_NOW|RTLD_GLOBAL); if (!gluhandle) return -1; #endif - glulibrary = strdup(driver); + glulibrary = Bstrdup(driver); bgluTessBeginContour = GLUGETPROC("gluTessBeginContour"); bgluTessBeginPolygon = GLUGETPROC("gluTessBeginPolygon"); @@ -959,7 +959,7 @@ int32_t unloadglulibrary(void) if (!hGLUDLL) return 0; #endif - free(glulibrary); + Bfree(glulibrary); glulibrary = NULL; #ifdef RENDERTYPEWIN diff --git a/polymer/eduke32/build/src/hightile.c b/polymer/eduke32/build/src/hightile.c index e8561fe54..d154e2a33 100644 --- a/polymer/eduke32/build/src/hightile.c +++ b/polymer/eduke32/build/src/hightile.c @@ -81,13 +81,13 @@ void hicinit(void) { if (hr->skybox->face[j]) { - free(hr->skybox->face[j]); + Bfree(hr->skybox->face[j]); } } - free(hr->skybox); + Bfree(hr->skybox); } - if (hr->filename) free(hr->filename); - free(hr); + if (hr->filename) Bfree(hr->filename); + Bfree(hr); hr = next; } @@ -137,20 +137,20 @@ int32_t hicsetsubsttex(int32_t picnum, int32_t palnum, char *filen, float alphac if (!hr) { // no replacement yet defined - hrn = (hicreplctyp *)calloc(1,sizeof(hicreplctyp)); + hrn = (hicreplctyp *)Bcalloc(1,sizeof(hicreplctyp)); if (!hrn) return -1; hrn->palnum = palnum; } else hrn = hr; // store into hicreplc the details for this replacement - if (hrn->filename) free(hrn->filename); + if (hrn->filename) Bfree(hrn->filename); - hrn->filename = strdup(filen); + hrn->filename = Bstrdup(filen); if (!hrn->filename) { if (hrn->skybox) return -1; // don't free the base structure if there's a skybox defined - if (hr == NULL) free(hrn); // not yet a link in the chain + if (hr == NULL) Bfree(hrn); // not yet a link in the chain return -1; } hrn->ignore = 0; @@ -195,7 +195,7 @@ int32_t hicsetskybox(int32_t picnum, int32_t palnum, char *faces[6]) if (!hr) { // no replacement yet defined - hrn = (hicreplctyp *)calloc(1,sizeof(hicreplctyp)); + hrn = (hicreplctyp *)Bcalloc(1,sizeof(hicreplctyp)); if (!hrn) return -1; hrn->palnum = palnum; @@ -204,10 +204,10 @@ int32_t hicsetskybox(int32_t picnum, int32_t palnum, char *faces[6]) if (!hrn->skybox) { - hrn->skybox = (struct hicskybox_t *)calloc(1,sizeof(struct hicskybox_t)); + hrn->skybox = (struct hicskybox_t *)Bcalloc(1,sizeof(struct hicskybox_t)); if (!hrn->skybox) { - if (hr == NULL) free(hrn); // not yet a link in the chain + if (hr == NULL) Bfree(hrn); // not yet a link in the chain return -1; } } @@ -216,21 +216,21 @@ int32_t hicsetskybox(int32_t picnum, int32_t palnum, char *faces[6]) for (j=5; j>=0; j--) { if (hrn->skybox->face[j]) - free(hrn->skybox->face[j]); + Bfree(hrn->skybox->face[j]); } } // store each face's filename for (j=0; j<6; j++) { - hrn->skybox->face[j] = strdup(faces[j]); + hrn->skybox->face[j] = Bstrdup(faces[j]); if (!hrn->skybox->face[j]) { for (--j; j>=0; --j) // free any previous faces - free(hrn->skybox->face[j]); - free(hrn->skybox); + Bfree(hrn->skybox->face[j]); + Bfree(hrn->skybox); hrn->skybox = NULL; - if (hr == NULL) free(hrn); + if (hr == NULL) Bfree(hrn); return -1; } } @@ -265,19 +265,19 @@ int32_t hicclearsubst(int32_t picnum, int32_t palnum) if (!hr) return 0; - if (hr->filename) free(hr->filename); + if (hr->filename) Bfree(hr->filename); if (hr->skybox) { int32_t i; for (i=5; i>=0; i--) if (hr->skybox->face[i]) - free(hr->skybox->face[i]); - free(hr->skybox); + Bfree(hr->skybox->face[i]); + Bfree(hr->skybox); } if (hrn) hrn->next = hr->next; else hicreplc[picnum] = hr->next; - free(hr); + Bfree(hr); return 0; } diff --git a/polymer/eduke32/build/src/kplib.c b/polymer/eduke32/build/src/kplib.c index 3bb86e8c6..dcead14e4 100644 --- a/polymer/eduke32/build/src/kplib.c +++ b/polymer/eduke32/build/src/kplib.c @@ -1520,9 +1520,9 @@ static int32_t kpegrend(const char *kfilebuf, int32_t kfilength, kfileptr += leng; break; case 0xda: - if ((xdim <= 0) || (ydim <= 0)) { if (dctbuf) free(dctbuf); return(-1); } + if ((xdim <= 0) || (ydim <= 0)) { if (dctbuf) Bfree(dctbuf); return(-1); } - lnumcomponents = (int32_t)(*kfileptr++); if (!lnumcomponents) { if (dctbuf) free(dctbuf); return(-1); } + lnumcomponents = (int32_t)(*kfileptr++); if (!lnumcomponents) { if (dctbuf) Bfree(dctbuf); return(-1); } if (lnumcomponents > 1) coltype = 2; for (z=0; z= xres) || (min(globxoffs+xdim,xres) <= 0) || (max(globyoffs,0) >= yres) || (min(globyoffs+ydim,yres) <= 0)) - { if (dctbuf) free(dctbuf); return(0); } + { if (dctbuf) Bfree(dctbuf); return(0); } Alut[0] = (1< kzhashsiz) //Make sure string fits in kzhashbuf { i = kzhashsiz; do { i <<= 1; } while (kzhashpos+siz > i); - kzhashbuf = (char *)realloc(kzhashbuf,i); if (!kzhashbuf) return(0); + kzhashbuf = (char *)Brealloc(kzhashbuf,i); if (!kzhashbuf) return(0); kzhashsiz = i; } return(1); @@ -2647,7 +2647,7 @@ static int32_t kzcheckhash(const char *filnam, char **zipnam, int32_t *fileoffs, void kzuninit() { - if (kzhashbuf) { free(kzhashbuf); kzhashbuf = 0; } + if (kzhashbuf) { Bfree(kzhashbuf); kzhashbuf = 0; } kzhashpos = kzhashsiz = 0; kzdirnamhead = -1; } @@ -3282,14 +3282,14 @@ void kpzload(const char *filnam, intptr_t *pic, int32_t *bpl, int32_t *xsiz, int (*pic) = 0; if (handle < 0) return; leng = kfilelength(handle); - buf = (char *)malloc(leng); if (!buf) return; + buf = (char *)Bmalloc(leng); if (!buf) return; kread(handle,buf,leng); kclose(handle); kpgetdim(buf,leng,xsiz,ysiz); (*bpl) = ((*xsiz)<<2); - (*pic) = (intptr_t)malloc((*ysiz)*(*bpl)); if (!(*pic)) { free(buf); return; } - if (kprender(buf,leng,*pic,*bpl,*xsiz,*ysiz,0,0) < 0) { free(buf); free((void *)*pic); (*pic) = 0; return; } - free(buf); + (*pic) = (intptr_t)Bmalloc((*ysiz)*(*bpl)); if (!(*pic)) { Bfree(buf); return; } + if (kprender(buf,leng,*pic,*bpl,*xsiz,*ysiz,0,0) < 0) { Bfree(buf); Bfree((void *)*pic); (*pic) = 0; return; } + Bfree(buf); } //====================== HANDY PICTURE function ends ========================= diff --git a/polymer/eduke32/build/src/lzwnew.c b/polymer/eduke32/build/src/lzwnew.c index 234a7fc55..89a9053e1 100644 --- a/polymer/eduke32/build/src/lzwnew.c +++ b/polymer/eduke32/build/src/lzwnew.c @@ -18,11 +18,11 @@ int32_t lzwcompress(char *ucompbuf, int32_t ucompleng, char *compbuf) #endif char *nodev, *cptr, *eptr; - nodev = (char *)malloc((ucompleng+256)*sizeof(uint8_t)); if (!nodev) return(0); - child = (int32_t *)malloc((ucompleng+256)*sizeof(int32_t)); if (!child) { free(nodev); return(0); } - sibly = (int32_t *)malloc((ucompleng+256)*sizeof(int32_t)); if (!sibly) { free(child); free(nodev); return(0); } + nodev = (char *)Bmalloc((ucompleng+256)*sizeof(uint8_t)); if (!nodev) return(0); + child = (int32_t *)Bmalloc((ucompleng+256)*sizeof(int32_t)); if (!child) { Bfree(nodev); return(0); } + sibly = (int32_t *)Bmalloc((ucompleng+256)*sizeof(int32_t)); if (!sibly) { Bfree(child); Bfree(nodev); return(0); } #if USENEW - sibry = (int32_t *)malloc((ucompleng+256)*sizeof(int32_t)); if (!sibry) { free(sibly); free(child); free(nodev); return(0); } + sibry = (int32_t *)Bmalloc((ucompleng+256)*sizeof(int32_t)); if (!sibry) { Bfree(sibly); Bfree(child); Bfree(nodev); return(0); } #endif for (i=255; i>=0; i--) { nodev[i] = i; child[i] = -1; } @@ -66,10 +66,10 @@ lzwcompbreak2b: while ((cptr < eptr) && (bitcnt < (ucompleng<<3))); #if USENEW - free(sibry); + Bfree(sibry); #endif - free(sibly); - free(child); free(nodev); + Bfree(sibly); + Bfree(child); Bfree(nodev); lptr = (int32_t *)compbuf; if (((bitcnt+7)>>3) < ucompleng) { lptr[0] = LSWAPIB(numnodes); return((bitcnt+7)>>3); } @@ -86,8 +86,8 @@ int32_t lzwuncompress(char *compbuf, int32_t compleng, char *ucompbuf, int32_t u totnodes = LSWAPIB(((int32_t *)compbuf)[0]); if (totnodes <= 0 || totnodes >= ucompleng+256) return 0; - prefix = (int32_t *)malloc(totnodes*sizeof(int32_t)); if (!prefix) return 0; - suffix = (char *)malloc(totnodes*sizeof(uint8_t)); if (!suffix) { free(prefix); return 0; } + prefix = (int32_t *)Bmalloc(totnodes*sizeof(int32_t)); if (!prefix) return 0; + suffix = (char *)Bmalloc(totnodes*sizeof(uint8_t)); if (!suffix) { Bfree(prefix); return 0; } numnodes = 256; bitcnt = (4<<3); nbits = 8; oneupnbits = (1<<8); hmask = ((oneupnbits>>1)-1); do @@ -115,7 +115,7 @@ int32_t lzwuncompress(char *compbuf, int32_t compleng, char *ucompbuf, int32_t u while (numnodes < totnodes); bail: - free(suffix); free(prefix); + Bfree(suffix); Bfree(prefix); return (int32_t)ucompbuf-ucomp; } diff --git a/polymer/eduke32/build/src/mdsprite.c b/polymer/eduke32/build/src/mdsprite.c index fd41fd0d6..c93e74275 100644 --- a/polymer/eduke32/build/src/mdsprite.c +++ b/polymer/eduke32/build/src/mdsprite.c @@ -19,8 +19,9 @@ voxmodel_t *voxmodels[MAXVOXELS]; int32_t curextra=MAXTILES; -nedpool *model_data_pool; -#define MODEL_POOL_SIZE 20971520 +// nedpool *model_data_pool; +// #define MODEL_POOL_SIZE 20971520 +#define model_data_pool (nedpool *) 0 // take it out of the system pool int32_t addtileP(int32_t model,int32_t tile,int32_t pallet) { @@ -117,11 +118,13 @@ void freeallmodels() } freevbos(); +/* if (model_data_pool) { neddestroypool(model_data_pool); model_data_pool = NULL; } +*/ } void clearskins() @@ -175,8 +178,8 @@ void mdinit() { memset(hudmem,0,sizeof(hudmem)); freeallmodels(); - if (!model_data_pool) - model_data_pool = nedcreatepool(MODEL_POOL_SIZE, 0); +// if (!model_data_pool) +// model_data_pool = nedcreatepool(MODEL_POOL_SIZE, 0); mdinited = 1; } diff --git a/polymer/eduke32/build/src/mmulti.c b/polymer/eduke32/build/src/mmulti.c index 4993004e3..a33d9a5a2 100644 --- a/polymer/eduke32/build/src/mmulti.c +++ b/polymer/eduke32/build/src/mmulti.c @@ -464,7 +464,7 @@ int32_t initmultiplayersparms(int32_t argc, char **argv) else if ((argv[i][1] == 'P') || (argv[i][1] == 'p')) continue; } - st = strdup(argv[i]); if (!st) break; + st = Bstrdup(argv[i]); if (!st) break; if (isvalidipaddress(st)) { if ((danetmode == 1) && (daindex == myconnectindex)) daindex++; @@ -496,7 +496,7 @@ int32_t initmultiplayersparms(int32_t argc, char **argv) } else printf("mmulti: Failed resolving %s\n",argv[i]); } - free(st); + Bfree(st); } if ((danetmode == 255) && (daindex)) { numplayers = 2; danetmode = 0; } //an IP w/o /n# defaults to /n0 if ((numplayers >= 2) && (daindex) && (!danetmode)) myconnectindex = 1; diff --git a/polymer/eduke32/build/src/mmulti_unstable.c b/polymer/eduke32/build/src/mmulti_unstable.c index b7c6e11e1..c49105220 100644 --- a/polymer/eduke32/build/src/mmulti_unstable.c +++ b/polymer/eduke32/build/src/mmulti_unstable.c @@ -864,7 +864,7 @@ static char *read_whole_file(const char *cfgfile) } len = kfilelength(handle); - buf = (char *) malloc(len + 2); + buf = (char *) Bmalloc(len + 2); if (!buf) { kclose(handle); @@ -875,7 +875,7 @@ static char *read_whole_file(const char *cfgfile) kclose(handle); if (rc != len) { - free(buf); + Bfree(buf); return(NULL); } @@ -1857,7 +1857,7 @@ static int32_t parse_udp_config(int32_t argc, char **argv, gcomtype *gcom) else if ((argv[i][1] == 'P') || (argv[i][1] == 'p')) continue; } - st = strdup(argv[i]); + st = Bstrdup(argv[i]); if (!st) break; if (isvalidipaddress(st)) { @@ -1885,7 +1885,7 @@ static int32_t parse_udp_config(int32_t argc, char **argv, gcomtype *gcom) } else initprintf("network: Failed resolving %s\n",argv[i]); } - free(st); + Bfree(st); } if ((danetmode == 255) && (daindex)) { gcom->numplayers = 2; udpmode = udpmode_client; } //an IP w/o /n# defaults to /n0 // if ((numplayers >= 2) && (daindex) && (!danetmode)) myconnectindex = 1; @@ -1980,7 +1980,7 @@ static int32_t parse_udp_config(int32_t argc, char **argv, gcomtype *gcom) initprintf("bogus token! [%s]\n", tok); } - free(buf); + Bfree(buf); } if (open_udp_socket(ip, udpport)) @@ -2012,7 +2012,7 @@ gcomtype *init_network_transport(int32_t argc, char **argv) srand(time(NULL)); - retval = (gcomtype *)malloc(sizeof(gcomtype)); + retval = (gcomtype *)Bmalloc(sizeof(gcomtype)); if (retval != NULL) { int32_t rc; @@ -2028,7 +2028,7 @@ gcomtype *init_network_transport(int32_t argc, char **argv) if (!rc) { - free(retval); + Bfree(retval); deinit_network_transport(NULL); return(NULL); } @@ -2046,7 +2046,7 @@ void deinit_network_transport(gcomtype *gcom) if (gcom != NULL) { initprintf(" ...freeing gcom structure...\n"); - free(gcom); + Bfree(gcom); } if ((signed)udpsocket != -1) diff --git a/polymer/eduke32/build/src/nedmalloc.c b/polymer/eduke32/build/src/nedmalloc.c index 45a1a2cdd..4d9065b36 100644 --- a/polymer/eduke32/build/src/nedmalloc.c +++ b/polymer/eduke32/build/src/nedmalloc.c @@ -38,10 +38,16 @@ DEALINGS IN THE SOFTWARE. /*#define FULLSANITYCHECKS*/ #define USE_ALLOCATOR 1 #define REPLACE_SYSTEM_ALLOCATOR 1 -#define USE_MAGIC_HEADERS 1 +#define USE_MAGIC_HEADERS 0 +#define MAXTHREADSINPOOL 1 +#define FINEGRAINEDBINS 1 + +#ifndef UNREFERENCED_PARAMETER +#define UNREFERENCED_PARAMETER(x) x=x +#endif #include "nedmalloc.h" -#ifdef WIN32 +#ifdef _WIN32 #include #include #endif @@ -79,6 +85,7 @@ DEALINGS IN THE SOFTWARE. /*#define FORCEINLINE*/ +#define ENABLE_LARGE_PAGES #include "malloc.c.h" #ifdef NDEBUG /* Disable assert checking on release builds */ #undef DEBUG @@ -97,22 +104,21 @@ DEALINGS IN THE SOFTWARE. #endif /* The maximum size to be allocated from the thread cache */ #ifndef THREADCACHEMAX -#define THREADCACHEMAX 65536 +#define THREADCACHEMAX 32768 #endif -#if 1 +#ifdef FINEGRAINEDBINS /* The number of cache entries for finer grained bins. This is (topbitpos(THREADCACHEMAX)-4)*2 */ -#define THREADCACHEMAXBINS ((16-4)*2) +#define THREADCACHEMAXBINS ((15-4)*2) #else /* The number of cache entries. This is (topbitpos(THREADCACHEMAX)-4) */ -#define THREADCACHEMAXBINS (16-4) +#define THREADCACHEMAXBINS (15-4) #endif /* Point at which the free space in a thread cache is garbage collected */ #ifndef THREADCACHEMAXFREESPACE -#define THREADCACHEMAXFREESPACE (512*1024*8) +#define THREADCACHEMAXFREESPACE (512*1024*4) #endif - -#ifdef WIN32 +#ifdef _WIN32 #define TLSVAR DWORD #define TLSALLOC(k) (*(k)=TlsAlloc(), TLS_OUT_OF_INDEXES==*(k)) #define TLSFREE(k) (!TlsFree(k)) @@ -144,6 +150,7 @@ extern "C" { #endif #endif +#if USE_ALLOCATOR==0 static void *unsupported_operation(const char *opname) THROWSPEC { fprintf(stderr, "nedmalloc: The operation %s is not supported under this build configuration\n", opname); @@ -151,10 +158,12 @@ static void *unsupported_operation(const char *opname) THROWSPEC return 0; } static size_t mspacecounter=(size_t) 0xdeadbeef; +#endif static FORCEINLINE void *CallMalloc(void *mspace, size_t size, size_t alignment) THROWSPEC { void *ret=0; + UNREFERENCED_PARAMETER(alignment); #if USE_MAGIC_HEADERS size_t *_ret=0; size+=alignment+3*sizeof(size_t); @@ -179,6 +188,7 @@ static FORCEINLINE void *CallMalloc(void *mspace, size_t size, size_t alignment) static FORCEINLINE void *CallCalloc(void *mspace, size_t no, size_t size, size_t alignment) THROWSPEC { void *ret=0; + UNREFERENCED_PARAMETER(alignment); #if USE_MAGIC_HEADERS size_t *_ret=0; size+=alignment+3*sizeof(size_t); @@ -279,7 +289,7 @@ size_t nedblksize(void *mem) THROWSPEC size_t *_mem=(size_t *) mem-3; if(_mem[0]==*(size_t *) "NEDMALOC") { - mstate mspace=(mstate) _mem[1]; +// mstate mspace=(mstate) _mem[1]; size_t size=_mem[2]; return size-3*sizeof(size_t); } @@ -289,7 +299,7 @@ size_t nedblksize(void *mem) THROWSPEC /* Fail everything */ return 0; #elif USE_ALLOCATOR==1 -#ifdef WIN32 +#ifdef _MSC_VER __try #endif { @@ -313,7 +323,7 @@ size_t nedblksize(void *mem) THROWSPEC if(ok_magic(fm)) return chunksize(p)-overhead_for(p); } -#ifdef WIN32 +#ifdef _MSC_VER __except(1) { } #endif #endif @@ -459,6 +469,7 @@ static void tcfullsanitycheck(threadcache *tc) THROWSPEC static NOINLINE void RemoveCacheEntries(nedpool *p, threadcache *tc, unsigned int age) THROWSPEC { + UNREFERENCED_PARAMETER(p); #ifdef FULLSANITYCHECKS tcfullsanitycheck(tc); #endif @@ -553,12 +564,13 @@ static void *threadcache_malloc(nedpool *p, threadcache *tc, size_t *size) THROW unsigned int idx=size2binidx(*size); size_t blksize=0; threadcacheblk *blk, **binsptr; + UNREFERENCED_PARAMETER(p); #ifdef FULLSANITYCHECKS tcfullsanitycheck(tc); #endif /* Calculate best fit bin size */ bestsize=1<<(idx+4); -#if 0 +#ifdef FINEGRAINEDBINS /* Finer grained bin fit */ idx<<=1; if(*size>bestsize) @@ -636,6 +648,7 @@ static NOINLINE void ReleaseFreeInCache(nedpool *p, threadcache *tc, int mymspac { unsigned int age=THREADCACHEMAXFREESPACE/8192; /*ACQUIRE_LOCK(&p->m[mymspace]->mutex);*/ + UNREFERENCED_PARAMETER(mymspace); while(age && tc->freeInCache>=THREADCACHEMAXFREESPACE) { RemoveCacheEntries(p, tc, age); @@ -659,12 +672,12 @@ static void threadcache_free(nedpool *p, threadcache *tc, int mymspace, void *me #endif /* Calculate best fit bin size */ bestsize=1<<(idx+4); -#if 0 +#ifdef FINEGRAINEDBINS /* Finer grained bin fit */ idx<<=1; if(size>bestsize) { - unsigned int biggerbestsize=bestsize+bestsize<<1; + unsigned int biggerbestsize=bestsize+(bestsize<<1); if(size>=biggerbestsize) { idx++; @@ -847,9 +860,9 @@ void neddestroysyspool() THROWSPEC } /* Render syspool unusable */ for(n=0; ncaches[n]=(threadcache *)(size_t)(sizeof(size_t)>4 ? 0xdeadbeefdeadbeef : 0xdeadbeef); + p->caches[n]=(threadcache *)0xdeadbeef; for(n=0; nm[n]=(mstate)(size_t)(sizeof(size_t)>4 ? 0xdeadbeefdeadbeef : 0xdeadbeef); + p->m[n]=(mstate)0xdeadbeef; if(TLSFREE(p->mycache)) abort(); RELEASE_LOCK(&p->mutex); } @@ -859,6 +872,7 @@ void nedpsetvalue(nedpool *p, void *v) THROWSPEC if(!p) { p=&syspool; if(!syspool.threads) InitPool(&syspool, 0, -1); } p->uservalue=v; } + void *nedgetvalue(nedpool **p, void *mem) THROWSPEC { nedpool *np=0; @@ -1065,7 +1079,7 @@ void nedpfree(nedpool *p, void *mem) THROWSPEC if(!mem) { /* You'd be surprised the number of times this happens as so many allocators are non-conformant here */ - fprintf(stderr, "nedmalloc: WARNING nedpfree() called with zero. This is not portable behaviour!\n"); +// fprintf(stderr, "nedmalloc: WARNING nedpfree() called with zero. This is not portable behaviour!\n"); return; } GetThreadCache(&p, &tc, &mymspace, 0); @@ -1101,7 +1115,7 @@ NEDMALLOCPTRATTR void * nedpmemalign(nedpool *p, size_t alignment, size_t bytes) struct mallinfo nedpmallinfo(nedpool *p) THROWSPEC { int n; - struct mallinfo ret={0}; + struct mallinfo ret={0,0,0,0,0,0,0,0,0,0}; if(!p) { p=&syspool; if(!syspool.threads) InitPool(&syspool, 0, -1); } for(n=0; p->m[n]; n++) { @@ -1121,6 +1135,7 @@ struct mallinfo nedpmallinfo(nedpool *p) THROWSPEC #endif int nedpmallopt(nedpool *p, int parno, int value) THROWSPEC { + UNREFERENCED_PARAMETER(p); #if USE_ALLOCATOR==1 return mspace_mallopt(parno, value); #else @@ -1210,6 +1225,15 @@ NEDMALLOCPTRATTR void **nedpindependent_comalloc(nedpool *p, size_t elems, size_ return ret; } +// cheap replacement for strdup so we aren't feeding system allocated blocks into nedmalloc + +NEDMALLOCPTRATTR char *nedstrdup(const char *str) THROWSPEC +{ + int n = strlen(str) + 1; + char *dup = nedmalloc(n); + return dup ? memcpy(dup, str, n) : NULL; +} + #if defined(__cplusplus) } #endif diff --git a/polymer/eduke32/build/src/osd.c b/polymer/eduke32/build/src/osd.c index 1bb74cfc2..ce1bb9a17 100644 --- a/polymer/eduke32/build/src/osd.c +++ b/polymer/eduke32/build/src/osd.c @@ -1628,7 +1628,7 @@ int32_t OSD_Dispatch(const char *cmd) if (wp[0] == '/' && wp[1] == '/') // cheap hack { - free(workbuf); + Bfree(workbuf); return -1; } @@ -1636,7 +1636,7 @@ int32_t OSD_Dispatch(const char *cmd) if (!symb) { OSD_Printf(OSDTEXT_RED "Error: \"%s\" is not a valid command or cvar\n", wp); - free(workbuf); + Bfree(workbuf); return -1; } @@ -1667,7 +1667,7 @@ int32_t OSD_Dispatch(const char *cmd) } while (wtp && restart); - free(workbuf); + Bfree(workbuf); return 0; } diff --git a/polymer/eduke32/build/src/polymer.c b/polymer/eduke32/build/src/polymer.c index 7cc0c5f25..66bd46b01 100644 --- a/polymer/eduke32/build/src/polymer.c +++ b/polymer/eduke32/build/src/polymer.c @@ -572,7 +572,9 @@ int8_t curskyshade; _pranimatespritesinfo asi; // MEMORY POOL -nedpool* polymer_pool = NULL; +// nedpool* polymer_pool = NULL; + +#define polymer_pool (nedpool *) 0 // take it out of the system pool void polymer_alt_editorselect(void); static int32_t m32_numdrawnsprites = 0; @@ -606,7 +608,10 @@ int32_t polymer_init(void) return (0); } - polymer_pool = nedcreatepool(POLYMER_POOL_SIZE, 0); +/* + if (!polymer_pool) + polymer_pool = nedcreatepool(POLYMER_POOL_SIZE, 0); +*/ Bmemset(&prsectors[0], 0, sizeof(prsectors[0]) * MAXSECTORS); Bmemset(&prwalls[0], 0, sizeof(prwalls[0]) * MAXWALLS); @@ -659,8 +664,10 @@ int32_t polymer_init(void) void polymer_uninit(void) { polymer_freeboard(); +/* if (polymer_pool) neddestroypool(polymer_pool); +*/ } void polymer_glinit(void) @@ -715,6 +722,7 @@ void polymer_loadboard(void) int32_t i; polymer_freeboard(); + nedtrimthreadcache(polymer_pool, 0); i = 0; while (i < numsectors) @@ -2747,8 +2755,10 @@ finish: void PR_CALLBACK polymer_tesserror(GLenum error) { - // This callback is called by the tesselator whenever it raises an error. - if (pr_verbosity >= 1) OSD_Printf("PR : Tesselation error number %i reported : %s.\n", error, bgluErrorString(errno)); + /* This callback is called by the tesselator whenever it raises an error. + GLU_TESS_ERROR6 is the "no error"/"null" error spam in e1l1 and others. */ + + if (pr_verbosity >= 1 && error != GLU_TESS_ERROR6) OSD_Printf("PR : Tesselation error number %i reported : %s.\n", error, bgluErrorString(errno)); } void PR_CALLBACK polymer_tessedgeflag(GLenum error) @@ -2931,15 +2941,13 @@ static void polymer_updatewall(int16_t wallnum) // yes, this function is messy and unefficient // it also works, bitches - wal = &wall[wallnum]; - nwallnum = wal->nextwall; + sec = §or[sectofwall]; - if (sectofwall < 0 || sectofwall > numsectors || wallnum < 0 || wallnum > numwalls) + if (sectofwall < 0 || sectofwall > numsectors || wallnum < 0 || wallnum > numwalls || sec->wallptr > wallnum) return; // yay, corrupt map - sec = §or[sectofwall]; - if (sec->wallptr > wallnum) - return; // the map is horribly corrupt + wal = &wall[wallnum]; + nwallnum = wal->nextwall; w = prwalls[wallnum]; s = prsectors[sectofwall]; @@ -5135,7 +5143,7 @@ static void polymer_processspotlight(_prlight* light) // get the texture handle for the lightmap light->lightmap = 0; - if (light->tilenum) + if (light->tilenum > 0) { if (!waloff[light->tilenum]) loadtile(light->tilenum); diff --git a/polymer/eduke32/build/src/polymost.c b/polymer/eduke32/build/src/polymost.c index 261bf2abd..ef0c62175 100644 --- a/polymer/eduke32/build/src/polymost.c +++ b/polymer/eduke32/build/src/polymost.c @@ -297,8 +297,6 @@ pthtyp *gltexcachead[GLTEXCACHEADSIZ]; int32_t drawingskybox = 0; -pthtyp *pichead; - int32_t gloadtile_art(int32_t,int32_t,int32_t,pthtyp*,int32_t); int32_t gloadtile_hi(int32_t,int32_t,int32_t,hicreplctyp*,int32_t,pthtyp*,int32_t,char); static int32_t hicprecaching = 0; @@ -310,11 +308,11 @@ pthtyp * gltexcache(int32_t dapicnum, int32_t dapalnum, int32_t dameth) j = (dapicnum&(GLTEXCACHEADSIZ-1)); - if (usehightile) si = hicfindsubst(dapicnum,dapalnum,drawingskybox); - else si = NULL; + si = usehightile ? hicfindsubst(dapicnum,dapalnum,drawingskybox) : NULL; + if (!si) { - if (drawingskybox) return NULL; + if (drawingskybox || dapalnum >= (MAXPALOOKUPS - RESERVEDPALS)) return NULL; goto tryart; } @@ -324,9 +322,8 @@ pthtyp * gltexcache(int32_t dapicnum, int32_t dapalnum, int32_t dameth) * effects are applied to the palette 0 texture if it exists */ - pichead=gltexcachead[j]; // for palmaps // load a replacement - for (pth=pichead; pth; pth=pth->next) + for (pth=gltexcachead[j]; pth; pth=pth->next) { if (pth->picnum == dapicnum && pth->palnum == si->palnum && @@ -350,7 +347,7 @@ pthtyp * gltexcache(int32_t dapicnum, int32_t dapalnum, int32_t dameth) } - pth = (pthtyp *)calloc(1,sizeof(pthtyp)); + pth = (pthtyp *)Bcalloc(1,sizeof(pthtyp)); if (!pth) return NULL; // possibly fetch an already loaded multitexture :_) @@ -374,7 +371,7 @@ pthtyp * gltexcache(int32_t dapicnum, int32_t dapalnum, int32_t dameth) if (gloadtile_hi(dapicnum,dapalnum,drawingskybox,si,dameth,pth,1, (si->palnum>0) ? 0 : hictinting[dapalnum].f)) { - free(pth); + Bfree(pth); if (drawingskybox) return NULL; goto tryart; // failed, so try for ART } @@ -401,12 +398,12 @@ tryart: return(pth); } - pth = (pthtyp *)calloc(1,sizeof(pthtyp)); + pth = (pthtyp *)Bcalloc(1,sizeof(pthtyp)); if (!pth) return NULL; if (gloadtile_art(dapicnum,dapalnum,dameth,pth,1)) { - free(pth); + Bfree(pth); return NULL; } pth->next = gltexcachead[j]; @@ -586,10 +583,10 @@ void polymost_glreset() if (pth->flags & 16) // fullbright textures { bglDeleteTextures(1,&pth->ofb->glpic); - free(pth->ofb); + Bfree(pth->ofb); } bglDeleteTextures(1,&pth->glpic); - free(pth); + Bfree(pth); pth = next; } gltexcachead[i] = NULL; @@ -1081,7 +1078,7 @@ int32_t gloadtile_art(int32_t dapic, int32_t dapal, int32_t dameth, pthtyp *pth, } } - pic = (coltype *)malloc(xsiz*ysiz*sizeof(coltype)); + pic = (coltype *)Bmalloc(xsiz*ysiz*sizeof(coltype)); if (!pic) return 1; if (!waloff[dapic]) @@ -1173,7 +1170,7 @@ int32_t gloadtile_art(int32_t dapic, int32_t dapal, int32_t dameth, pthtyp *pth, bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,glinfo.clamptoedge?GL_CLAMP_TO_EDGE:GL_CLAMP); } - if (pic) free(pic); + if (pic) Bfree(pic); pth->picnum = dapic; pth->palnum = dapal; @@ -1185,7 +1182,7 @@ int32_t gloadtile_art(int32_t dapic, int32_t dapal, int32_t dameth, pthtyp *pth, { // load the ONLY texture that'll be assembled with the regular one to make the final texture with fullbright pixels fullbrightloadingpass = 1; - pth->ofb = (pthtyp *)calloc(1,sizeof(pthtyp)); + pth->ofb = (pthtyp *)Bcalloc(1,sizeof(pthtyp)); if (!pth->ofb) return 1; pth->flags |= (hasfullbright<<4); if (gloadtile_art(dapic, dapal, dameth, pth->ofb, 1)) return 1; @@ -1400,14 +1397,14 @@ void writexcache(char *fn, int32_t len, int32_t dameth, char effect, texcachehea if (alloclen < miplen) { - void *picc = realloc(pic, miplen); + void *picc = Brealloc(pic, miplen); if (!picc) goto failure; else pic = picc; alloclen = miplen; - picc = realloc(packbuf, alloclen+16); + picc = Brealloc(packbuf, alloclen+16); if (!picc) goto failure; else packbuf = picc; - picc = realloc(midbuf, miplen); + picc = Brealloc(midbuf, miplen); if (!picc) goto failure; else midbuf = picc; } @@ -1463,9 +1460,9 @@ failure: Bmemset(curcacheindex->name,0,sizeof(curcacheindex->name)); success: - if (midbuf) free(midbuf); - if (pic) free(pic); - if (packbuf) free(packbuf); + if (midbuf) Bfree(midbuf); + if (pic) Bfree(pic); + if (packbuf) Bfree(packbuf); } int32_t gloadtile_cached(int32_t fil, texcacheheader *head, int32_t *doalloc, pthtyp *pth,int32_t dapalnum) @@ -1505,14 +1502,14 @@ int32_t gloadtile_cached(int32_t fil, texcacheheader *head, int32_t *doalloc, pt if (alloclen < pict.size) { - void *picc = realloc(pic, pict.size); + void *picc = Brealloc(pic, pict.size); if (!picc) goto failure; else pic = picc; alloclen = pict.size; - picc = realloc(packbuf, alloclen+16); + picc = Brealloc(packbuf, alloclen+16); if (!picc) goto failure; else packbuf = picc; - picc = realloc(midbuf, pict.size); + picc = Brealloc(midbuf, pict.size); if (!picc) goto failure; else midbuf = picc; } @@ -1536,15 +1533,15 @@ int32_t gloadtile_cached(int32_t fil, texcacheheader *head, int32_t *doalloc, pt } - if (midbuf) free(midbuf); - if (pic) free(pic); - if (packbuf) free(packbuf); + if (midbuf) Bfree(midbuf); + if (pic) Bfree(pic); + if (packbuf) Bfree(packbuf); return 0; failure: initprintf("failure!!!\n"); - if (midbuf) free(midbuf); - if (pic) free(pic); - if (packbuf) free(packbuf); + if (midbuf) Bfree(midbuf); + if (pic) Bfree(pic); + if (packbuf) Bfree(packbuf); return -1; } // --------------------------------------------------- JONOF'S COMPRESSED TEXTURE CACHE STUFF @@ -1600,7 +1597,7 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp if ((filh = kopen4load(fn, 0)) < 0) return -1; - picfil = (char *)malloc(picfillen+1); if (!picfil) { kclose(filh); return 1; } + picfil = (char *)Bmalloc(picfillen+1); if (!picfil) { kclose(filh); return 1; } kread(filh, picfil, picfillen); kclose(filh); @@ -1608,7 +1605,7 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp // xsiz/y = 2^x size of replacement kpgetdim(picfil,picfillen,&tsizx,&tsizy); - if (tsizx == 0 || tsizy == 0) { free(picfil); return -1; } + if (tsizx == 0 || tsizy == 0) { Bfree(picfil); return -1; } pth->sizx = tsizx; pth->sizy = tsizy; @@ -1622,9 +1619,9 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp xsiz = tsizx; ysiz = tsizy; } - pic = (coltype *)calloc(xsiz,ysiz*sizeof(coltype)); if (!pic) { free(picfil); return 1; } + pic = (coltype *)Bcalloc(xsiz,ysiz*sizeof(coltype)); if (!pic) { Bfree(picfil); return 1; } - if (kprender(picfil,picfillen,(intptr_t)pic,xsiz*sizeof(coltype),xsiz,ysiz,0,0)) { free(picfil); free(pic); return -2; } + if (kprender(picfil,picfillen,(intptr_t)pic,xsiz*sizeof(coltype),xsiz,ysiz,0,0)) { Bfree(picfil); Bfree(pic); return -2; } r=(glinfo.bgra)?hictinting[dapalnum].r:hictinting[dapalnum].b; g=hictinting[dapalnum].g; @@ -1688,7 +1685,7 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp } } else texfmt = GL_BGRA; - free(picfil); picfil = 0; + Bfree(picfil); picfil = 0; if (tsizx>>r_downsize <= tilesizx[dapic] || tsizy>>r_downsize <= tilesizy[dapic]) hicr->flags |= 17; @@ -1739,7 +1736,7 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,glinfo.clamptoedge?GL_CLAMP_TO_EDGE:GL_CLAMP); } - if (pic) free(pic); + if (pic) Bfree(pic); if (tsizx>>r_downsize <= tilesizx[dapic] || tsizy>>r_downsize <= tilesizy[dapic]) hicr->flags |= 17; @@ -2268,7 +2265,7 @@ void drawpoly(double *dpx, double *dpy, int32_t n, int32_t method) { zbufbpl = bytesperline; zbufysiz = ydim; - zbufmem = (intptr_t)realloc((void *)zbufmem,zbufbpl*zbufysiz*4); + zbufmem = (intptr_t)Brealloc((void *)zbufmem,zbufbpl*zbufysiz*4); } zbufoff = (int32_t *)(zbufmem-(frameplace<<2)); #endif @@ -5415,9 +5412,9 @@ static void tessectrap(float *px, float *py, int32_t *point2, int32_t numpoints) if (numpoints+16 > allocpoints) //16 for safety { allocpoints = numpoints+16; - rst = (raster*)realloc(rst,allocpoints*sizeof(raster)); - slist = (int32_t*)realloc(slist,allocpoints*sizeof(int32_t)); - npoint2 = (int32_t*)realloc(npoint2,allocpoints*sizeof(int32_t)); + rst = (raster*)Brealloc(rst,allocpoints*sizeof(raster)); + slist = (int32_t*)Brealloc(slist,allocpoints*sizeof(int32_t)); + npoint2 = (int32_t*)Brealloc(npoint2,allocpoints*sizeof(int32_t)); } //Remove unnecessary collinear points: @@ -5744,7 +5741,7 @@ int32_t polymost_printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t ba bglTexImage2D(GL_TEXTURE_2D,0,GL_ALPHA,256,128,0,GL_ALPHA,GL_UNSIGNED_BYTE,(GLvoid*)tbuf); bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); - free(tbuf); + Bfree(tbuf); } else bglBindTexture(GL_TEXTURE_2D, polymosttext); diff --git a/polymer/eduke32/build/src/scriptfile.c b/polymer/eduke32/build/src/scriptfile.c index 699f33f0f..36df27a5a 100644 --- a/polymer/eduke32/build/src/scriptfile.c +++ b/polymer/eduke32/build/src/scriptfile.c @@ -213,7 +213,7 @@ void scriptfile_preparse(scriptfile *sf, char *tx, int32_t flen) } sf->linenum = numcr; - sf->lineoffs = (int32_t *)malloc(sf->linenum*sizeof(int32_t)); + sf->lineoffs = (int32_t *)Bmalloc(sf->linenum*sizeof(int32_t)); //Preprocess file for comments (// and /*...*/, and convert all whitespace to single spaces) nflen = 0; ws = 0; cs = 0; numcr = 0; inquote = 0; @@ -272,18 +272,18 @@ scriptfile *scriptfile_fromfile(char *fn) if (fp<0) return NULL; flen = kfilelength(fp); - tx = (char *) malloc(flen + 2); + tx = (char *) Bmalloc(flen + 2); if (!tx) { kclose(fp); return NULL; } - sf = (scriptfile*) malloc(sizeof(scriptfile)); + sf = (scriptfile*) Bmalloc(sizeof(scriptfile)); if (!sf) { kclose(fp); - free(tx); + Bfree(tx); return NULL; } @@ -293,7 +293,7 @@ scriptfile *scriptfile_fromfile(char *fn) kclose(fp); scriptfile_preparse(sf,tx,flen); - sf->filename = strdup(fn); + sf->filename = Bstrdup(fn); return sf; } @@ -308,13 +308,13 @@ scriptfile *scriptfile_fromstring(char *string) flen = strlen(string); - tx = (char *) malloc(flen + 2); + tx = (char *) Bmalloc(flen + 2); if (!tx) return NULL; - sf = (scriptfile*) malloc(sizeof(scriptfile)); + sf = (scriptfile*) Bmalloc(sizeof(scriptfile)); if (!sf) { - free(tx); + Bfree(tx); return NULL; } @@ -330,12 +330,12 @@ scriptfile *scriptfile_fromstring(char *string) void scriptfile_close(scriptfile *sf) { if (!sf) return; - if (sf->lineoffs) free(sf->lineoffs); - if (sf->textbuf) free(sf->textbuf); - if (sf->filename) free(sf->filename); + if (sf->lineoffs) Bfree(sf->lineoffs); + if (sf->textbuf) Bfree(sf->textbuf); + if (sf->filename) Bfree(sf->filename); sf->textbuf = NULL; sf->filename = NULL; - free(sf); + Bfree(sf); } int32_t scriptfile_eof(scriptfile *sf) @@ -357,7 +357,7 @@ static char * getsymbtabspace(int32_t reqd) if (symbtablength + reqd > symbtaballoclength) { for (i=max(symbtaballoclength,SYMBTABSTARTSIZE); symbtablength+reqd>i; i<<=1); - np = (char *)realloc(symbtab, i); if (!np) return NULL; + np = (char *)Brealloc(symbtab, i); if (!np) return NULL; symbtab = np; symbtaballoclength = i; } @@ -415,7 +415,7 @@ int32_t scriptfile_addsymbolvalue(char *name, int32_t val) void scriptfile_clearsymbols(void) { - if (symbtab) free(symbtab); + if (symbtab) Bfree(symbtab); symbtab = NULL; symbtablength = 0; symbtaballoclength = 0; diff --git a/polymer/eduke32/build/src/winlayer.c b/polymer/eduke32/build/src/winlayer.c index fd13bc348..0b900ba10 100644 --- a/polymer/eduke32/build/src/winlayer.c +++ b/polymer/eduke32/build/src/winlayer.c @@ -134,6 +134,8 @@ static char key_names[256][24]; static uint32_t lastKeyDown = 0; static uint32_t lastKeyTime = 0; +static OSVERSIONINFO osv; + void (*keypresscallback)(int32_t,int32_t) = 0; void (*mousepresscallback)(int32_t,int32_t) = 0; void (*joypresscallback)(int32_t,int32_t) = 0; @@ -274,21 +276,42 @@ int32_t WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, in FILE *fp; HDC hdc; - nedcreatepool(SYSTEM_POOL_SIZE, -1); - atexit(neddestroysyspool); - - UNREFERENCED_PARAMETER(lpCmdLine); - UNREFERENCED_PARAMETER(nCmdShow); - hInstance = hInst; if (CheckWinVersion() || hPrevInst) { - MessageBox(0, "This application must be run under Windows 95/98/Me or Windows 2000/XP or better.", - apptitle, MB_OK|MB_ICONSTOP); + MessageBox(0, "This application requires Windows 2000/XP or better to run.", + apptitle, MB_OK|MB_ICONSTOP); return -1; } + /* Attempt to enable SeLockMemoryPrivilege, Vista/7 only */ + if (osv.dwMajorVersion == 6) + { + HANDLE token; + if(OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &token)) + { + TOKEN_PRIVILEGES privs; + privs.PrivilegeCount = 1; + if(LookupPrivilegeValue(NULL, SE_LOCK_MEMORY_NAME, &privs.Privileges[0].Luid)) + { + privs.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED; + if(!AdjustTokenPrivileges(token, FALSE, &privs, 0, NULL, NULL) || GetLastError()!=S_OK) + { + // failure... no large page support for us + } + } + CloseHandle(token); + } + } + + nedcreatepool(SYSTEM_POOL_SIZE, -1); + + atexit(neddestroysyspool); + + UNREFERENCED_PARAMETER(lpCmdLine); + UNREFERENCED_PARAMETER(nCmdShow); + hdc = GetDC(NULL); r = GetDeviceCaps(hdc, BITSPIXEL); ReleaseDC(NULL, hdc); @@ -300,7 +323,7 @@ int32_t WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, in } // carve up the commandline into more recognizable pieces - argvbuf = strdup(GetCommandLine()); + argvbuf = Bstrdup(GetCommandLine()); _buildargc = 0; if (argvbuf) { @@ -362,7 +385,7 @@ int32_t WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, in } *wp = 0; - _buildargv = (const char**)malloc(sizeof(char*)*_buildargc); + _buildargv = (const char**)Bmalloc(sizeof(char*)*_buildargc); wp = argvbuf; for (i=0; i<_buildargc; i++,wp++) { @@ -420,7 +443,7 @@ int32_t WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, in startwin_close(); if (instanceflag) CloseHandle(instanceflag); - if (argvbuf) free(argvbuf); + if (argvbuf) Bfree(argvbuf); return r; } @@ -469,14 +492,10 @@ static int32_t set_windowpos(const osdfuncparm_t *parm) static void print_os_version(void) { - OSVERSIONINFO osv; const char *ver = NULL; // I was going to call this 'windows_9x_is_awful', but I couldn't justify ever setting it to 0 int32_t awful_windows_9x = 0; - osv.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - GetVersionEx(&osv); - switch (osv.dwPlatformId) { case VER_PLATFORM_WIN32_NT: @@ -508,7 +527,7 @@ static void print_os_version(void) ver = "7"; break; default: - ver = "Unknown Post-2010 Product"; + ver = ""; break; } break; @@ -525,17 +544,13 @@ static void print_os_version(void) break; default: - initprintf("OS: Unknown OS\n"); - return; + ver = ""; + break; } if (ver != NULL) - { initprintf("OS: Windows %s (%lu.%lu.%lu) %s\n", ver, osv.dwMajorVersion, osv.dwMinorVersion, awful_windows_9x?osv.dwBuildNumber&0xffff:osv.dwBuildNumber,osv.szCSDVersion); -// if (osv.szCSDVersion[0]) - // initprintf(" - %s\n", osv.szCSDVersion); - } } @@ -570,7 +585,7 @@ int32_t initsystem(void) #if defined(USE_OPENGL) && defined(POLYMOST) if (loadgldriver(getenv("BUILD_GLDRV"))) { - initprintf("Failed loading OpenGL driver. GL modes will be unavailable.\n"); + initprintf("Failure loading OpenGL. GL modes are unavailable.\n"); nogl = 1; } #endif @@ -1507,18 +1522,18 @@ static void UninitDirectInput(void) if (axisdefs) { - for (i=joynumaxes-1; i>=0; i--) if (axisdefs[i].name) free((void*)axisdefs[i].name); - free(axisdefs); axisdefs = NULL; + for (i=joynumaxes-1; i>=0; i--) if (axisdefs[i].name) Bfree((void*)axisdefs[i].name); + Bfree(axisdefs); axisdefs = NULL; } if (buttondefs) { - for (i=joynumbuttons-1; i>=0; i--) if (buttondefs[i].name) free((void*)buttondefs[i].name); - free(buttondefs); buttondefs = NULL; + for (i=joynumbuttons-1; i>=0; i--) if (buttondefs[i].name) Bfree((void*)buttondefs[i].name); + Bfree(buttondefs); buttondefs = NULL; } if (hatdefs) { - for (i=joynumhats-1; i>=0; i--) if (hatdefs[i].name) free((void*)hatdefs[i].name); - free(hatdefs); hatdefs = NULL; + for (i=joynumhats-1; i>=0; i--) if (hatdefs[i].name) Bfree((void*)hatdefs[i].name); + Bfree(hatdefs); hatdefs = NULL; } for (devn = 0; devn < NUM_INPUTS; devn++) @@ -2650,7 +2665,7 @@ int32_t setpalette(int32_t start, int32_t num) } SetDIBColorTable(hDCSection, start, num, rgb); - free(rgb); + Bfree(rgb); } if (desktopbpp > 8) return 0; // only if an 8bit desktop do we do what follows @@ -3028,7 +3043,7 @@ static void ReleaseDirectDrawSurfaces(void) if (lpOffscreen) { // initprintf(" - Freeing offscreen buffer\n"); - free(lpOffscreen); + Bfree(lpOffscreen); lpOffscreen = NULL; } } @@ -3073,7 +3088,7 @@ static int32_t SetupDirectDraw(int32_t width, int32_t height) } // initprintf(" - Allocating offscreen buffer\n"); - lpOffscreen = (char *)malloc((width|1)*height); + lpOffscreen = (char *)Bmalloc((width|1)*height); if (!lpOffscreen) { ShowErrorBox("Failure allocating offscreen buffer"); @@ -4147,10 +4162,9 @@ static void ShowErrorBox(const char *m) // static BOOL CheckWinVersion(void) { - OSVERSIONINFO osv; - ZeroMemory(&osv, sizeof(osv)); osv.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + if (!GetVersionEx(&osv)) return TRUE; // haha, yeah, like it will work on Win32s diff --git a/polymer/eduke32/source/actors.c b/polymer/eduke32/source/actors.c index 3cb587774..c827cad5f 100644 --- a/polymer/eduke32/source/actors.c +++ b/polymer/eduke32/source/actors.c @@ -7643,7 +7643,7 @@ static void G_MoveEffectors(void) //STATNUM 3 mylight.horiz = SH; mylight.minshade = sprite[i].xoffset; mylight.maxshade = sprite[i].yoffset; - mylight.tilenum = 0; + mylight.tilenum = ActorExtra[i].picnum; if (CS & 2) { @@ -7696,6 +7696,7 @@ static void G_MoveEffectors(void) //STATNUM 3 ActorExtra[i].lightptr->horiz = SH; ActorExtra[i].lightptr->flags.invalidate = 1; } + ActorExtra[i].lightptr->tilenum = ActorExtra[i].picnum; } break; diff --git a/polymer/eduke32/source/astub.c b/polymer/eduke32/source/astub.c index a1f46bb04..7f4ac62d3 100644 --- a/polymer/eduke32/source/astub.c +++ b/polymer/eduke32/source/astub.c @@ -1568,7 +1568,7 @@ static void ReadHelpFile(const char *name) return; } - helppage=malloc(IHELP_INITPAGES * sizeof(helppage_t *)); + helppage=Bmalloc(IHELP_INITPAGES * sizeof(helppage_t *)); numallocpages=IHELP_INITPAGES; if (!helppage) goto HELPFILE_ERROR; @@ -1599,7 +1599,7 @@ static void ReadHelpFile(const char *name) { if (j >= hp->numlines) { - hp=realloc(hp, sizeof(helppage_t) + 2*hp->numlines*80); + hp=Brealloc(hp, sizeof(helppage_t) + 2*hp->numlines*80); if (!hp) goto HELPFILE_ERROR; hp->numlines *= 2; } @@ -1631,13 +1631,13 @@ static void ReadHelpFile(const char *name) } while (!newpage(tempbuf) && !Bfeof(fp) && charsread>0); - hp=realloc(hp, sizeof(helppage_t) + j*80); + hp=Brealloc(hp, sizeof(helppage_t) + j*80); if (!hp) goto HELPFILE_ERROR; hp->numlines=j; if (i >= numallocpages) { - helppage = realloc(helppage, 2*numallocpages*sizeof(helppage_t *)); + helppage = Brealloc(helppage, 2*numallocpages*sizeof(helppage_t *)); numallocpages *= 2; if (!helppage) goto HELPFILE_ERROR; } @@ -1645,7 +1645,7 @@ static void ReadHelpFile(const char *name) i++; } - helppage = realloc(helppage, i*sizeof(helppage_t *)); + helppage = Brealloc(helppage, i*sizeof(helppage_t *)); if (!helppage) goto HELPFILE_ERROR; numhelppages = i; @@ -8372,7 +8372,7 @@ static void AddGamePath(const char *buffer) { struct strllist *s; s = (struct strllist *)Bcalloc(1,sizeof(struct strllist)); - s->str = strdup(buffer); + s->str = Bstrdup(buffer); if (CommandPaths) { @@ -9855,8 +9855,8 @@ int32_t ExtInit(void) s = CommandPaths->next; addsearchpath(CommandPaths->str); - free(CommandPaths->str); - free(CommandPaths); + Bfree(CommandPaths->str); + Bfree(CommandPaths); CommandPaths = s; } } @@ -9939,8 +9939,8 @@ int32_t ExtInit(void) DoAutoload(CommandGrps->str); } - free(CommandGrps->str); - free(CommandGrps); + Bfree(CommandGrps->str); + Bfree(CommandGrps); CommandGrps = s; } pathsearchmode = 0; @@ -10061,8 +10061,8 @@ void ExtUnInit(void) if (s_TileGroups[i].szText != NULL) Bfree(s_TileGroups[i].szText); } - for (i = numhelppages-1; i >= 0; i--) free(helppage[i]); - if (helppage) free(helppage); + for (i = numhelppages-1; i >= 0; i--) Bfree(helppage[i]); + if (helppage) Bfree(helppage); } void ExtPreCheckKeys(void) // just before drawrooms @@ -10211,7 +10211,7 @@ void ExtPreCheckKeys(void) // just before drawrooms mylight.horiz = SH; mylight.minshade = sprite[i].xoffset; mylight.maxshade = sprite[i].yoffset; - mylight.tilenum = 0; + mylight.tilenum = OW; if (CS & 2) { @@ -10264,6 +10264,7 @@ void ExtPreCheckKeys(void) // just before drawrooms spritelightptr[i]->horiz = SH; spritelightptr[i]->flags.invalidate = 1; } + spritelightptr[i]->tilenum = OW; } } } diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index 3e69b4c00..ec0d80f74 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -4635,9 +4635,13 @@ int32_t A_Spawn(int32_t j, int32_t pn) ActorExtra[i].picnum = PN; + if (PN == SECTOREFFECTOR && SLT == 50) + ActorExtra[i].picnum = OW; + ActorExtra[i].projectile = &SpriteProjectile[i]; OW = ActorExtra[i].owner = i; + ActorExtra[i].floorz = sector[SECT].floorz; ActorExtra[i].ceilingz = sector[SECT].ceilingz; @@ -9927,8 +9931,8 @@ static void G_CompileScripts(void) char *newlabel; intptr_t *newlabelcode; - newlabel = (char *)malloc(g_numLabels<<6); - newlabelcode = (intptr_t *)malloc(g_numLabels*sizeof(intptr_t)); + newlabel = (char *)Bmalloc(g_numLabels<<6); + newlabelcode = (intptr_t *)Bmalloc(g_numLabels*sizeof(intptr_t)); if (!newlabel || !newlabelcode) { @@ -10507,8 +10511,8 @@ void app_main(int32_t argc,const char **argv) s = CommandPaths->next; addsearchpath(CommandPaths->str); - free(CommandPaths->str); - free(CommandPaths); + Bfree(CommandPaths->str); + Bfree(CommandPaths); CommandPaths = s; } } diff --git a/polymer/eduke32/source/global.c b/polymer/eduke32/source/global.c index 9ae351b65..372d25614 100644 --- a/polymer/eduke32/source/global.c +++ b/polymer/eduke32/source/global.c @@ -23,7 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. //------------------------------------------------------------------------- #include "duke3d.h" -const char *s_buildDate = "20090930"; +const char *s_buildDate = "20091006"; char *MusicPtr = NULL; int32_t g_musicSize; diff --git a/polymer/eduke32/source/grpscan.c b/polymer/eduke32/source/grpscan.c index c29b8b873..ea7ca4cdf 100644 --- a/polymer/eduke32/source/grpscan.c +++ b/polymer/eduke32/source/grpscan.c @@ -73,7 +73,7 @@ static void FreeGroupsCache(void) while (grpcache) { fg = grpcache->next; - free(grpcache); + Bfree(grpcache); grpcache = fg; } } @@ -112,14 +112,14 @@ int32_t ScanGroups(void) if (findfrompath(sidx->name, &fn)) continue; // failed to resolve the filename if (Bstat(fn, &st)) { - free(fn); + Bfree(fn); continue; } // failed to stat the file - free(fn); + Bfree(fn); if (fg->size == st.st_size && fg->mtime == st.st_mtime) { grp = (struct grpfile *)Bcalloc(1, sizeof(struct grpfile)); - grp->name = strdup(sidx->name); + grp->name = Bstrdup(sidx->name); grp->crcval = fg->crcval; grp->size = fg->size; grp->next = foundgrps; @@ -157,7 +157,7 @@ int32_t ScanGroups(void) initprintf(" Done\n"); grp = (struct grpfile *)Bcalloc(1, sizeof(struct grpfile)); - grp->name = strdup(sidx->name); + grp->name = Bstrdup(sidx->name); grp->crcval = crcval; grp->size = st.st_size; grp->next = foundgrps; @@ -187,7 +187,7 @@ int32_t ScanGroups(void) { fgg = fg->next; fprintf(fp, "\"%s\" %d %d %d\n", fg->name, fg->size, fg->mtime, fg->crcval); - free(fg); + Bfree(fg); i++; } fclose(fp); @@ -210,8 +210,8 @@ void FreeGroups(void) while (foundgrps) { fg = foundgrps->next; - free((char*)foundgrps->name); - free(foundgrps); + Bfree((char*)foundgrps->name); + Bfree(foundgrps); foundgrps = fg; } } diff --git a/polymer/eduke32/source/jaudiolib/src/linklist.h b/polymer/eduke32/source/jaudiolib/src/linklist.h index 8a7aa5fcc..e4ebd8ad5 100644 --- a/polymer/eduke32/source/jaudiolib/src/linklist.h +++ b/polymer/eduke32/source/jaudiolib/src/linklist.h @@ -24,7 +24,7 @@ extern "C" { #endif -#define NewNode(type) ((type*)SafeMalloc(sizeof(type))) +#define NewNode(type) ((type*)Bmalloc(sizeof(type))) #define LL_CreateNewLinkedList(rootnode,type,next,prev) \ @@ -103,7 +103,7 @@ extern "C" { ((list)->prev == (list)) \ ) -#define LL_Free(list) SafeFree(list) +#define LL_Free(list) Bfree(list) #define LL_Reset(list,next,prev) (list)->next = (list)->prev = (list) #define LL_New LL_CreateNewLinkedList #define LL_Remove LL_RemoveNode diff --git a/polymer/eduke32/source/jaudiolib/src/pitch.c b/polymer/eduke32/source/jaudiolib/src/pitch.c index 3249d5447..786fed04a 100644 --- a/polymer/eduke32/source/jaudiolib/src/pitch.c +++ b/polymer/eduke32/source/jaudiolib/src/pitch.c @@ -32,7 +32,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include "pitch.h" -#define MAXDETUNE 100 +#define MAXDETUNE 50 static uint32_t PitchTable[ 12 ][ MAXDETUNE ]; static int32_t PITCH_Installed = 0; diff --git a/polymer/eduke32/source/jmact/animlib.c b/polymer/eduke32/source/jmact/animlib.c index 261bc764b..6feb0d6fb 100644 --- a/polymer/eduke32/source/jmact/animlib.c +++ b/polymer/eduke32/source/jmact/animlib.c @@ -264,7 +264,7 @@ void ANIM_LoadAnim(char * buffer) if (!Anim_Started) { - anim = SafeMalloc(sizeof(anim_t)); + anim = Bmalloc(sizeof(anim_t)); Anim_Started = TRUE; } @@ -317,7 +317,7 @@ void ANIM_FreeAnim(void) { if (Anim_Started) { - SafeFree(anim); + Bfree(anim); Anim_Started = FALSE; } } diff --git a/polymer/eduke32/source/jmact/file_lib.c b/polymer/eduke32/source/jmact/file_lib.c index f1807eab3..cd5c7884f 100644 --- a/polymer/eduke32/source/jmact/file_lib.c +++ b/polymer/eduke32/source/jmact/file_lib.c @@ -65,8 +65,8 @@ int32_t SafeOpen(const char *filename, int32_t mode, int32_t sharemode) if (h < MaxFiles) { - if (FileNames[h]) SafeFree(FileNames[h]); - FileNames[h] = (char*)SafeMalloc(strlen(filename)+1); + if (FileNames[h]) Bfree(FileNames[h]); + FileNames[h] = (char*)Bmalloc(strlen(filename)+1); if (FileNames[h]) strcpy(FileNames[h], filename); } @@ -100,7 +100,7 @@ void SafeClose(int32_t handle) if (handle < MaxFiles && FileNames[handle]) { - SafeFree(FileNames[handle]); + Bfree(FileNames[handle]); FileNames[handle] = NULL; } } diff --git a/polymer/eduke32/source/jmact/scriplib.c b/polymer/eduke32/source/jmact/scriplib.c index 343b2b135..d0848248c 100644 --- a/polymer/eduke32/source/jmact/scriplib.c +++ b/polymer/eduke32/source/jmact/scriplib.c @@ -57,7 +57,7 @@ int32_t SCRIPT_New(void) { if (!SC(i)) { - SC(i) = (script_t *)SafeMalloc(sizeof(script_t)); + SC(i) = (script_t *)Bmalloc(sizeof(script_t)); if (!SC(i)) return -1; memset(SC(i), 0, sizeof(script_t)); return i; @@ -81,14 +81,14 @@ void SCRIPT_Delete(int32_t scripthandle) { s = SCRIPT(scripthandle,script)->nextsection; SCRIPT_FreeSection(SCRIPT(scripthandle,script)); - SafeFree(SCRIPT(scripthandle,script)); + Bfree(SCRIPT(scripthandle,script)); SCRIPT(scripthandle,script) = s; } - SafeFree(SCRIPT(scripthandle,script)); + Bfree(SCRIPT(scripthandle,script)); } - SafeFree(SC(scripthandle)); + Bfree(SC(scripthandle)); SC(scripthandle) = 0; } @@ -102,17 +102,17 @@ void SCRIPT_FreeSection(ScriptSectionType * section) while (section->entries->nextentry != section->entries) { e = section->entries->nextentry; - SafeFree(section->entries); + Bfree(section->entries); section->entries = e; } - SafeFree(section->entries); - free(section->name); + Bfree(section->entries); + Bfree(section->name); } #define AllocSection(s) \ { \ - (s) = SafeMalloc(sizeof(ScriptSectionType)); \ + (s) = Bmalloc(sizeof(ScriptSectionType)); \ (s)->name = NULL; \ (s)->entries = NULL; \ (s)->lastline = NULL; \ @@ -121,7 +121,7 @@ void SCRIPT_FreeSection(ScriptSectionType * section) } #define AllocEntry(e) \ { \ - (e) = SafeMalloc(sizeof(ScriptEntryType)); \ + (e) = Bmalloc(sizeof(ScriptEntryType)); \ (e)->name = NULL; \ (e)->value = NULL; \ (e)->nextentry = (e); \ @@ -155,7 +155,7 @@ ScriptSectionType * SCRIPT_AddSection(int32_t scripthandle, char * sectionname) if (s) return s; AllocSection(s); - s->name = strdup(sectionname); + s->name = Bstrdup(sectionname); if (!SCRIPT(scripthandle,script)) { SCRIPT(scripthandle,script) = s; @@ -204,7 +204,7 @@ void SCRIPT_AddEntry(int32_t scripthandle, char * sectionname, char * entryname, if (!e) { AllocEntry(e); - e->name = strdup(entryname); + e->name = Bstrdup(entryname); if (!s->entries) { s->entries = e; @@ -218,8 +218,8 @@ void SCRIPT_AddEntry(int32_t scripthandle, char * sectionname, char * entryname, } } - if (e->value) free(e->value); - e->value = strdup(entryvalue); + if (e->value) Bfree(e->value); + e->value = Bstrdup(entryvalue); } @@ -441,7 +441,7 @@ int32_t SCRIPT_Load(char * filename) h = SafeOpenRead(filename, filetype_binary); l = SafeFileLength(h)+1; - b = (char *)SafeMalloc(l); + b = (char *)Bmalloc(l); SafeRead(h,b,l-1); b[l-1] = '\n'; // JBF 20040111: evil nasty hack to trick my evil nasty parser SafeClose(h); @@ -449,13 +449,13 @@ int32_t SCRIPT_Load(char * filename) s = SCRIPT_Init(filename); if (s<0) { - SafeFree(b); + Bfree(b); return -1; } SCRIPT_ParseBuffer(s,b,l); - SafeFree(b); + Bfree(b); return s; } diff --git a/polymer/eduke32/source/jmact/util_lib.c b/polymer/eduke32/source/jmact/util_lib.c index fda26ffd6..e07c85c0d 100644 --- a/polymer/eduke32/source/jmact/util_lib.c +++ b/polymer/eduke32/source/jmact/util_lib.c @@ -79,32 +79,6 @@ char CheckParm(char *check) return 0; } -void *SafeMalloc(int32_t size) -{ - void *p; - - p = malloc(size); - if (!p) Error("SafeMalloc failure for %d bytes",size); - - return p; -} - -void SafeFree(void * ptr) -{ - if (!ptr) Error("Tried to deallocate NULL pointer."); - free(ptr); -} - -void SafeRealloc(void ** ptr, int32_t newsize) -{ - void *p; - - p = realloc(*ptr, newsize); - if (!p) Error("SafeRealloc failure for %d bytes",newsize); - - *ptr = p; -} - int32_t ParseHex(char *hex) { return strtol(hex, NULL, 16); diff --git a/polymer/eduke32/source/jmact/util_lib.h b/polymer/eduke32/source/jmact/util_lib.h index 345db431d..5f18d5de8 100644 --- a/polymer/eduke32/source/jmact/util_lib.h +++ b/polymer/eduke32/source/jmact/util_lib.h @@ -46,10 +46,6 @@ void Error (char *error, ...); char CheckParm (char *check); -void *SafeMalloc (int32_t size); -int32_t SafeMallocSize (void * ptr); -void SafeFree (void * ptr); -void SafeRealloc (void ** ptr, int32_t newsize); int32_t ParseHex (char *hex); int32_t ParseNum (char *str); int16_t MotoShort (int16_t l); diff --git a/polymer/eduke32/source/menus.c b/polymer/eduke32/source/menus.c index fb2c1bb51..60566b4ee 100644 --- a/polymer/eduke32/source/menus.c +++ b/polymer/eduke32/source/menus.c @@ -4415,7 +4415,7 @@ cheat_for_port_credits: "Music", "Music volume", "-", - "Sample rate", + "Playback sampling rate", "Sample size", "Number of voices", "-", @@ -4542,7 +4542,7 @@ cheat_for_port_credits: break; case 4: { - int32_t rates[] = { 11025, 16000, 22050, 32000, 44100, 48000 }; + int32_t rates[] = { 22050, 24000, 32000, 44100, 48000 }; int32_t j = (sizeof(rates)/sizeof(rates[0])); for (i = 0; iname, fileinfo->name, 8); } - free(fileinfoo); + Bfree(fileinfoo); return 0; } @@ -155,7 +155,7 @@ void RTS_Init(const char *filename) // set up caching // length = (numlumps) * sizeof(*lumpcache); - lumpcache = SafeMalloc(length); + lumpcache = Bmalloc(length); memset(lumpcache,0,length); RTS_Started = TRUE; } diff --git a/polymer/eduke32/source/sounds.c b/polymer/eduke32/source/sounds.c index 13498fb34..2db9a40f5 100644 --- a/polymer/eduke32/source/sounds.c +++ b/polymer/eduke32/source/sounds.c @@ -309,7 +309,7 @@ int32_t S_PlayMusic(const char *fn, const int32_t sel) alt = (int32_t)(fn = MapInfo[sel].alt_musicfn); - testfn = (char *) malloc(strlen(fn) + 5); + testfn = (char *) Bmalloc(strlen(fn) + 5); strcpy(testfn, fn); extension = strrchr(testfn, '.'); @@ -324,11 +324,11 @@ int32_t S_PlayMusic(const char *fn, const int32_t sel) fp = kopen4loadfrommod(testfn, 0); if (fp >= 0) { - free(testfn); + Bfree(testfn); break; } } - free(testfn); + Bfree(testfn); // just use what we've been given fp = kopen4loadfrommod((char *)fn, 0); diff --git a/polymer/eduke32/source/startwin.game.c b/polymer/eduke32/source/startwin.game.c index 003169662..577d7210c 100644 --- a/polymer/eduke32/source/startwin.game.c +++ b/polymer/eduke32/source/startwin.game.c @@ -761,14 +761,14 @@ int32_t startwin_run(void) if (wavedevs) { struct audioenumdev *d, *e; - free(wavedevs->drvs); + Bfree(wavedevs->drvs); for (e=wavedevs->devs; e; e=d) { d = e->next; - if (e->devs) free(e->devs); - free(e); + if (e->devs) Bfree(e->devs); + Bfree(e); } - free(wavedevs); + Bfree(wavedevs); } return done;