Make nedmalloc a compile time option and add support for loading an external nedmalloc.dll at run time if it isn't compiled in

git-svn-id: https://svn.eduke32.com/eduke32@1643 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2010-05-18 00:30:30 +00:00
parent 65b29ab092
commit 21192dfb48
18 changed files with 479 additions and 495 deletions

View file

@ -18,6 +18,7 @@ USE_OPENGL = 1
NOASM = 0
LINKED_GTK = 0
BUILD32_ON_64 = 0
NEDMALLOC = 1
# Debugging/Build options
RELEASE?=1

View file

@ -31,11 +31,11 @@ flags_link=/RELEASE /LTCG
DXROOT="C:\Program Files\Microsoft DirectX SDK (February 2010)"
ENGINEOPTS=/DSUPERBUILD /DPOLYMOST /DUSE_OPENGL /DPOLYMER
ENGINEOPTS=/DSUPERBUILD /DPOLYMOST /DUSE_OPENGL /DPOLYMER # /DNEDMALLOC
CC=cl
AS=ml
LINK=link /nologo /opt:ref
LINK=link /nologo /opt:ref
MT=mt
CFLAGS= /MT /J /nologo $(flags_cl) \
/I$(INC) /I$(EINC)\msvc /I$(EINC)\ /I$(SRC)\jmact /I$(JAUDIOLIBDIR)\include /I$(ENETDIR)\include \

View file

@ -26,6 +26,7 @@ USE_OPENGL ?= 1
NOASM ?= 0
LINKED_GTK ?= 0
BUILD32_ON_64 ?= 0
NEDMALLOC ?= 1
ifeq (0,$(USE_OPENGL))
POLYMER = 0
@ -148,8 +149,7 @@ ENGINEOBJS+= \
$(OBJ)/osd.$o \
$(OBJ)/pragmas.$o \
$(OBJ)/scriptfile.$o \
$(OBJ)/nedmalloc.$o \
$(OBJ)/mutex.$o
$(OBJ)/mutex.$o
ifeq (1,$(USE_OPENGL))
ENGINEOBJS+= $(OBJ)/mdsprite.$o
@ -160,6 +160,10 @@ ifeq (1,$(POLYMER))
ENGINEOBJS+= $(OBJ)/polymer.$o
endif
ifeq (1,$(NEDMALLOC))
ENGINEOBJS+= $(OBJ)/nedmalloc.$o
endif
EDITOROBJS=$(OBJ)/build.$o \
$(OBJ)/config.$o

View file

@ -9,7 +9,7 @@ OBJ=obj.msc
!endif
INC=include\ #
!ifndef CFLAGS
CFLAGS=/DSUPERBUILD /DPOLYMOST /DUSE_OPENGL /DKSFORBUILD /DPOLYMER
CFLAGS=/DSUPERBUILD /DPOLYMOST /DUSE_OPENGL /DKSFORBUILD /DPOLYMER # /DNEDMALLOC
!endif
o=obj
@ -76,10 +76,10 @@ ENGINEOBJS= \
$(OBJ)\pragmas.$o \
$(OBJ)\scriptfile.$o \
$(OBJ)\winlayer.$o \
$(OBJ)\polymer.$o \
$(OBJ)\nedmalloc.$o \
$(OBJ)\mutex.$o \
$(OBJ)\rawinput.$o
$(OBJ)\polymer.$o \
$(OBJ)\mutex.$o \
$(OBJ)\rawinput.$o \
# $(OBJ)\nedmalloc.$o
EDITOROBJS=$(OBJ)\build.$o \
$(OBJ)\startwin.editor.$o \

View file

@ -187,6 +187,10 @@ ifneq (0,$(POLYMER))
endif
endif
ifneq (0,$(NEDMALLOC))
BUILDCFLAGS+= -DNEDMALLOC
endif
ifeq ($(PRETTY_OUTPUT),1)
BUILD_STARTED = printf "\033[K\033[1;36mBuild started using \"$(CC) $(OURCFLAGS)\"\033[0m\n"
BUILD_FINISHED = printf "\033[K\033[1;36mBuild successful:\033[0m\n"

View file

@ -12,7 +12,7 @@
extern "C" {
#endif
#define SYSTEM_POOL_SIZE (128 * 1048576)
#define SYSTEM_POOL_SIZE (64 * 1048576)
extern int32_t _buildargc;
extern const char **_buildargv;

View file

@ -35,11 +35,9 @@
#endif
#endif
#define USE_ALLOCATOR 1
#define USE_MAGIC_HEADERS 1
#define ENABLE_FAST_HEAP_DETECTION 1
#ifdef NEDMALLOC
#include "nedmalloc.h"
#endif
#ifndef TRUE
#define TRUE 1
@ -382,10 +380,19 @@ int32_t Bclosedir(BDIR *dir);
#ifdef __compat_h_macrodef__
# define Brand rand
# define Balloca alloca
#ifdef NEDMALLOC
# define Bmalloc nedmalloc
# define Bcalloc nedcalloc
# define Brealloc nedrealloc
# define Bfree nedfree
# define Bstrdup nedstrdup
#else
# define Bmalloc malloc
# define Bcalloc calloc
# define Brealloc realloc
# define Bfree free
# define Bstrdup strdup
#endif
# define Bopen open
# define Bclose close
# define Bwrite write
@ -408,7 +415,6 @@ int32_t Bclosedir(BDIR *dir);
# define Bfread fread
# define Bfwrite fwrite
# define Bfprintf fprintf
# define Bstrdup nedstrdup
# define Bstrcpy strcpy
# define Bstrncpy strncpy
# define Bstrcmp strcmp

View file

@ -81,6 +81,16 @@ fashion which may not hold true across OS upgrades.
#include <stddef.h> /* for size_t */
#define USE_ALLOCATOR 1
#define USE_MAGIC_HEADERS 1
#define MAXTHREADSINPOOL 2
#define FINEGRAINEDBINS 1
#define ENABLE_LARGE_PAGES 1
#define ENABLE_FAST_HEAP_DETECTION 1
#define NDEBUG 1
#define THREADCACHEMAX 4194304
#define THREADCACHEMAXBINS ((22-4)*2)
#ifndef NEDMALLOCEXTSPEC
#ifdef NEDMALLOC_DLL_EXPORTS
#ifdef WIN32

View file

@ -54,12 +54,20 @@ int32_t Brand(void)
void *Bmalloc(bsize_t size)
{
#ifdef NEDMALLOC
return nedmalloc(size);
#else
return malloc(size);
#endif
}
void Bfree(void *ptr)
{
#ifdef NEDMALLOC
nedfree(ptr);
#else
free(ptr);
#endif
}
int32_t Bopen(const char *pathname, int32_t flags, uint32_t mode)
@ -157,7 +165,11 @@ bsize_t Bfwrite(const void *ptr, bsize_t size, bsize_t nmemb, BFILE *stream)
char *Bstrdup(const char *s)
{
#ifdef NEDMALLOC
return nedstrdup(s);
#else
return strdup(s);
#endif
}
char *Bstrcpy(char *dest, const char *src)

View file

@ -247,16 +247,8 @@ int32_t loadsetup(const char *fn)
if (readconfig(fp, "parlock", val, VL) > 0) ParentalLock = Batoi(val);
#ifdef _WIN32
{
extern char map_dik_code(int32_t);
for (i=0; i<256; i++)
remap[i]=map_dik_code(i);
}
#else
for (i=0; i<256; i++)
remap[i]=i;
#endif
remapinit=1;
if (readconfig(fp, "remap", val, VL) > 0)

View file

@ -6672,7 +6672,9 @@ int32_t loadboard(char *filename, char fromwhere, int32_t *daposx, int32_t *dapo
clearbufbyte(&sprite, sizeof(sprite), 0);
*/
#ifdef NEDMALLOC
nedtrimthreadcache(0, 0);
#endif
initspritelists();

View file

@ -81,7 +81,7 @@ void freevbos()
{
// OSD_Printf("freeing model %d vbo\n",i);
bglDeleteBuffersARB(m->head.numsurfs, m->vbos);
nedpfree(model_data_pool, m->vbos);
Bfree(m->vbos);
m->vbos = NULL;
}
}
@ -101,7 +101,7 @@ void freeallmodels()
if (models)
{
for (i=0; i<nextmodelid; i++) mdfree(models[i]);
nedpfree(model_data_pool, models); models = NULL;
Bfree(models); models = NULL;
nummodelsalloced = 0;
nextmodelid = 0;
}
@ -111,7 +111,7 @@ void freeallmodels()
if (vertlist)
{
nedpfree(model_data_pool, vertlist);
Bfree(vertlist);
vertlist = NULL;
allocmodelverts = maxmodelverts = 0;
allocmodeltris = maxmodeltris = 0;
@ -191,7 +191,7 @@ int32_t md_loadmodel(const char *fn)
if (nextmodelid >= nummodelsalloced)
{
ml = (mdmodel_t **)nedprealloc(model_data_pool, models,(nummodelsalloced+MODELALLOCGROUP)*sizeof(void*)); if (!ml) return(-1);
ml = (mdmodel_t **)Brealloc(models,(nummodelsalloced+MODELALLOCGROUP)*sizeof(void*)); if (!ml) return(-1);
models = ml; nummodelsalloced += MODELALLOCGROUP;
}
@ -310,7 +310,7 @@ int32_t md_defineanimation(int32_t modelid, const char *framestart, const char *
ma.fpssc = fpssc;
ma.flags = flags;
map = (mdanim_t*)nedpcalloc(model_data_pool, 1,sizeof(mdanim_t));
map = (mdanim_t*)Bcalloc(1,sizeof(mdanim_t));
if (!map) return(-4);
Bmemcpy(map, &ma, sizeof(ma));
@ -340,13 +340,13 @@ int32_t md_defineskin(int32_t modelid, const char *skinfn, int32_t palnum, int32
if (sk->palette == (uint8_t)palnum && skinnum == sk->skinnum && surfnum == sk->surfnum) break;
if (!sk)
{
sk = (mdskinmap_t *)nedpcalloc(model_data_pool, 1,sizeof(mdskinmap_t));
sk = (mdskinmap_t *)Bcalloc(1,sizeof(mdskinmap_t));
if (!sk) return -4;
if (!skl) m->skinmap = sk;
else skl->next = sk;
}
else if (sk->fn) nedpfree(model_data_pool, sk->fn);
else if (sk->fn) Bfree(sk->fn);
sk->palette = (uint8_t)palnum;
sk->skinnum = skinnum;
@ -354,7 +354,7 @@ int32_t md_defineskin(int32_t modelid, const char *skinfn, int32_t palnum, int32
sk->param = param;
sk->specpower = specpower;
sk->specfactor = specfactor;
sk->fn = (char *)nedpmalloc(model_data_pool, strlen(skinfn)+1);
sk->fn = (char *)malloc(strlen(skinfn)+1);
if (!sk->fn) return(-4);
strcpy(sk->fn, skinfn);
@ -418,14 +418,14 @@ static int32_t daskinloader(int32_t filh, intptr_t *fptr, int32_t *bpl, int32_t
int32_t r, g, b;
picfillen = kfilelength(filh);
picfil = (char *)nedpmalloc(model_data_pool, picfillen+1); if (!picfil) { return -1; }
picfil = (char *)malloc(picfillen+1); if (!picfil) { return -1; }
kread(filh, picfil, picfillen);
// tsizx/y = replacement texture's natural size
// xsiz/y = 2^x size of replacement
kpgetdim(picfil,picfillen,&tsizx,&tsizy);
if (tsizx == 0 || tsizy == 0) { nedpfree(model_data_pool, picfil); return -1; }
if (tsizx == 0 || tsizy == 0) { Bfree(picfil); return -1; }
if (!glinfo.texnpot)
{
@ -438,13 +438,13 @@ static int32_t daskinloader(int32_t filh, intptr_t *fptr, int32_t *bpl, int32_t
ysiz = tsizy;
}
*osizx = tsizx; *osizy = tsizy;
pic = (coltype *)nedpmalloc(model_data_pool, xsiz*ysiz*sizeof(coltype));
if (!pic) { nedpfree(model_data_pool, picfil); return -1; }
pic = (coltype *)malloc(xsiz*ysiz*sizeof(coltype));
if (!pic) { Bfree(picfil); return -1; }
memset(pic,0,xsiz*ysiz*sizeof(coltype));
if (kprender(picfil,picfillen,(intptr_t)pic,xsiz*sizeof(coltype),xsiz,ysiz,0,0))
{ nedpfree(model_data_pool, picfil); nedpfree(model_data_pool, pic); return -1; }
nedpfree(model_data_pool, picfil);
{ Bfree(picfil); Bfree(pic); return -1; }
Bfree(picfil);
cptr = &britable[gammabrightness ? 0 : curbrightness][0];
r=(glinfo.bgra)?hictinting[pal].b:hictinting[pal].r;
@ -621,14 +621,14 @@ static int32_t mdloadskin_cached(int32_t fil, texcacheheader *head, int32_t *doa
if (alloclen < pict.size)
{
void *picc = nedprealloc(model_data_pool, pic, pict.size);
void *picc = Brealloc(pic, pict.size);
if (!picc) goto failure; else pic = picc;
alloclen = pict.size;
picc = nedprealloc(model_data_pool, packbuf, alloclen+16);
picc = Brealloc(packbuf, alloclen+16);
if (!picc) goto failure; else packbuf = picc;
picc = nedprealloc(model_data_pool, midbuf, pict.size);
picc = Brealloc(midbuf, pict.size);
if (!picc) goto failure; else midbuf = picc;
}
@ -639,14 +639,14 @@ static int32_t mdloadskin_cached(int32_t fil, texcacheheader *head, int32_t *doa
if (bglGetError() != GL_NO_ERROR) goto failure;
}
if (midbuf) nedpfree(model_data_pool, midbuf);
if (pic) nedpfree(model_data_pool, pic);
if (packbuf) nedpfree(model_data_pool, packbuf);
if (midbuf) Bfree(midbuf);
if (pic) Bfree(pic);
if (packbuf) Bfree(packbuf);
return 0;
failure:
if (midbuf) nedpfree(model_data_pool, midbuf);
if (pic) nedpfree(model_data_pool, pic);
if (packbuf) nedpfree(model_data_pool, packbuf);
if (midbuf) Bfree(midbuf);
if (pic) Bfree(pic);
if (packbuf) Bfree(packbuf);
return -1;
}
// --------------------------------------------------- JONOF'S COMPRESSED TEXTURE CACHE STUFF
@ -770,7 +770,7 @@ int32_t mdloadskin(md2model_t *m, int32_t number, int32_t pal, int32_t surf)
else if (!hasalpha) intexfmt = GL_RGB;
if (glinfo.bgra) texfmt = GL_BGRA;
uploadtexture((doalloc&1), xsiz, ysiz, intexfmt, texfmt, (coltype*)fptr, xsiz, ysiz, 0|8192);
nedpfree(model_data_pool, (void*)fptr);
Bfree((void*)fptr);
}
if (!m->skinloaded)
@ -965,7 +965,7 @@ static void mdloadvbos(md3model_t *m)
{
int32_t i;
m->vbos = nedpmalloc(model_data_pool, m->head.numsurfs * sizeof(GLuint));
m->vbos = malloc(m->head.numsurfs * sizeof(GLuint));
bglGenBuffersARB(m->head.numsurfs, m->vbos);
i = 0;
@ -989,7 +989,7 @@ static md2model_t *md2load(int32_t fil, const char *filnam)
char st[BMAX_PATH];
int32_t i, j, k;
m = (md2model_t *)nedpcalloc(model_data_pool, 1,sizeof(md2model_t)); if (!m) return(0);
m = (md2model_t *)Bcalloc(1,sizeof(md2model_t)); if (!m) return(0);
m->mdnum = 2; m->scale = .01f;
kread(fil,(char *)&head,sizeof(md2head_t));
@ -1003,7 +1003,7 @@ static md2model_t *md2load(int32_t fil, const char *filnam)
head.ofsframes = B_LITTLE32(head.ofsframes); head.ofsglcmds = B_LITTLE32(head.ofsglcmds);
head.ofseof = B_LITTLE32(head.ofseof);
if ((head.id != 0x32504449) || (head.vers != 8)) { nedpfree(model_data_pool, m); return(0); } //"IDP2"
if ((head.id != 0x32504449) || (head.vers != 8)) { Bfree(m); return(0); } //"IDP2"
m->numskins = head.numskins;
m->numframes = head.numframes;
@ -1011,26 +1011,26 @@ static md2model_t *md2load(int32_t fil, const char *filnam)
m->numglcmds = head.numglcmds;
m->framebytes = head.framebytes;
m->frames = (char *)nedpcalloc(model_data_pool, m->numframes,m->framebytes); if (!m->frames) { nedpfree(model_data_pool, m); return(0); }
m->glcmds = (int32_t *)nedpcalloc(model_data_pool, m->numglcmds,sizeof(int32_t)); if (!m->glcmds) { nedpfree(model_data_pool, m->frames); nedpfree(model_data_pool, m); return(0); }
m->tris = (md2tri_t *)nedpcalloc(model_data_pool, head.numtris, sizeof(md2tri_t)); if (!m->tris) { nedpfree(model_data_pool, m->glcmds); nedpfree(model_data_pool, m->frames); nedpfree(model_data_pool, m); return(0); }
m->uv = (md2uv_t *)nedpcalloc(model_data_pool, head.numuv, sizeof(md2uv_t)); if (!m->uv) { nedpfree(model_data_pool, m->tris); nedpfree(model_data_pool, m->glcmds); nedpfree(model_data_pool, m->frames); nedpfree(model_data_pool, m); return(0); }
m->frames = (char *)Bcalloc(m->numframes,m->framebytes); if (!m->frames) { Bfree(m); return(0); }
m->glcmds = (int32_t *)Bcalloc(m->numglcmds,sizeof(int32_t)); if (!m->glcmds) { Bfree(m->frames); Bfree(m); return(0); }
m->tris = (md2tri_t *)Bcalloc(head.numtris, sizeof(md2tri_t)); if (!m->tris) { Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
m->uv = (md2uv_t *)Bcalloc(head.numuv, sizeof(md2uv_t)); if (!m->uv) { Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
klseek(fil,head.ofsframes,SEEK_SET);
if (kread(fil,(char *)m->frames,m->numframes*m->framebytes) != m->numframes*m->framebytes)
{ nedpfree(model_data_pool, m->uv); nedpfree(model_data_pool, m->tris); nedpfree(model_data_pool, m->glcmds); nedpfree(model_data_pool, m->frames); nedpfree(model_data_pool, m); return(0); }
{ Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
klseek(fil,head.ofsglcmds,SEEK_SET);
if (kread(fil,(char *)m->glcmds,m->numglcmds*sizeof(int32_t)) != (int32_t)(m->numglcmds*sizeof(int32_t)))
{ nedpfree(model_data_pool, m->uv); nedpfree(model_data_pool, m->tris); nedpfree(model_data_pool, m->glcmds); nedpfree(model_data_pool, m->frames); nedpfree(model_data_pool, m); return(0); }
{ Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
klseek(fil,head.ofstris,SEEK_SET);
if (kread(fil,(char *)m->tris,head.numtris*sizeof(md2tri_t)) != (int32_t)(head.numtris*sizeof(md2tri_t)))
{ nedpfree(model_data_pool, m->uv); nedpfree(model_data_pool, m->tris); nedpfree(model_data_pool, m->glcmds); nedpfree(model_data_pool, m->frames); nedpfree(model_data_pool, m); return(0); }
{ Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
klseek(fil,head.ofsuv,SEEK_SET);
if (kread(fil,(char *)m->uv,head.numuv*sizeof(md2uv_t)) != (int32_t)(head.numuv*sizeof(md2uv_t)))
{ nedpfree(model_data_pool, m->uv); nedpfree(model_data_pool, m->tris); nedpfree(model_data_pool, m->glcmds); nedpfree(model_data_pool, m->frames); nedpfree(model_data_pool, m); return(0); }
{ Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
#if B_BIG_ENDIAN != 0
{
@ -1072,16 +1072,16 @@ static md2model_t *md2load(int32_t fil, const char *filnam)
if ((st[i] == '/') || (st[i] == '\\')) { i++; break; }
if (i<0) i=0;
st[i] = 0;
m->basepath = (char *)nedpmalloc(model_data_pool, i+1); if (!m->basepath) { nedpfree(model_data_pool, m->uv); nedpfree(model_data_pool, m->tris); nedpfree(model_data_pool, m->glcmds); nedpfree(model_data_pool, m->frames); nedpfree(model_data_pool, m); return(0); }
m->basepath = (char *)malloc(i+1); if (!m->basepath) { Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
strcpy(m->basepath, st);
m->skinfn = (char *)nedpcalloc(model_data_pool, m->numskins,64); if (!m->skinfn) { nedpfree(model_data_pool, m->basepath); nedpfree(model_data_pool, m->uv); nedpfree(model_data_pool, m->tris); nedpfree(model_data_pool, m->glcmds); nedpfree(model_data_pool, m->frames); nedpfree(model_data_pool, m); return(0); }
m->skinfn = (char *)Bcalloc(m->numskins,64); if (!m->skinfn) { Bfree(m->basepath); Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
klseek(fil,head.ofsskins,SEEK_SET);
if (kread(fil,m->skinfn,64*m->numskins) != 64*m->numskins)
{ nedpfree(model_data_pool, m->glcmds); nedpfree(model_data_pool, m->frames); nedpfree(model_data_pool, m); return(0); }
{ Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
m->texid = (GLuint *)nedpcalloc(model_data_pool, m->numskins, sizeof(GLuint) * (HICEFFECTMASK+1));
if (!m->texid) { nedpfree(model_data_pool, m->skinfn); nedpfree(model_data_pool, m->basepath); nedpfree(model_data_pool, m->uv); nedpfree(model_data_pool, m->tris); nedpfree(model_data_pool, m->glcmds); nedpfree(model_data_pool, m->frames); nedpfree(model_data_pool, m); return(0); }
m->texid = (GLuint *)Bcalloc(m->numskins, sizeof(GLuint) * (HICEFFECTMASK+1));
if (!m->texid) { Bfree(m->skinfn); Bfree(m->basepath); Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
maxmodelverts = max(maxmodelverts, m->numverts);
maxmodeltris = max(maxmodeltris, head.numtris);
@ -1090,7 +1090,7 @@ static md2model_t *md2load(int32_t fil, const char *filnam)
// the MD2 is now loaded internally - let's begin the MD3 conversion process
//OSD_Printf("Beginning md3 conversion.\n");
m3 = (md3model_t *)nedpcalloc(model_data_pool, 1, sizeof(md3model_t)); if (!m3) { nedpfree(model_data_pool, m->skinfn); nedpfree(model_data_pool, m->basepath); nedpfree(model_data_pool, m->uv); nedpfree(model_data_pool, m->tris); nedpfree(model_data_pool, m->glcmds); nedpfree(model_data_pool, m->frames); nedpfree(model_data_pool, m); return(0); }
m3 = (md3model_t *)Bcalloc(1, sizeof(md3model_t)); if (!m3) { Bfree(m->skinfn); Bfree(m->basepath); Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
m3->mdnum = 3; m3->texid = 0; m3->scale = m->scale;
m3->head.id = 0x33504449; m3->head.vers = 15;
// this changes the conversion code to do real MD2->MD3 conversion
@ -1104,8 +1104,8 @@ static md2model_t *md2load(int32_t fil, const char *filnam)
m3->numskins = m3->head.numskins;
m3->numframes = m3->head.numframes;
m3->head.frames = (md3frame_t *)nedpcalloc(model_data_pool, m3->head.numframes, sizeof(md3frame_t)); if (!m3->head.frames) { nedpfree(model_data_pool, m3); nedpfree(model_data_pool, m->skinfn); nedpfree(model_data_pool, m->basepath); nedpfree(model_data_pool, m->uv); nedpfree(model_data_pool, m->tris); nedpfree(model_data_pool, m->glcmds); nedpfree(model_data_pool, m->frames); nedpfree(model_data_pool, m); return(0); }
m3->muladdframes = (point3d *)nedpcalloc(model_data_pool, m->numframes * 2, sizeof(point3d));
m3->head.frames = (md3frame_t *)Bcalloc(m3->head.numframes, sizeof(md3frame_t)); if (!m3->head.frames) { Bfree(m3); Bfree(m->skinfn); Bfree(m->basepath); Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
m3->muladdframes = (point3d *)Bcalloc(m->numframes * 2, sizeof(point3d));
f = (md2frame_t *)(m->frames);
@ -1123,7 +1123,7 @@ static md2model_t *md2load(int32_t fil, const char *filnam)
m3->head.tags = NULL;
m3->head.surfs = (md3surf_t *)nedpcalloc(model_data_pool, 1, sizeof(md3surf_t)); if (!m3->head.surfs) { nedpfree(model_data_pool, m3->head.frames); nedpfree(model_data_pool, m3); nedpfree(model_data_pool, m->skinfn); nedpfree(model_data_pool, m->basepath); nedpfree(model_data_pool, m->uv); nedpfree(model_data_pool, m->tris); nedpfree(model_data_pool, m->glcmds); nedpfree(model_data_pool, m->frames); nedpfree(model_data_pool, m); return(0); }
m3->head.surfs = (md3surf_t *)Bcalloc(1, sizeof(md3surf_t)); if (!m3->head.surfs) { Bfree(m3->head.frames); Bfree(m3); Bfree(m->skinfn); Bfree(m->basepath); Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
s = m3->head.surfs;
// model converting
@ -1140,9 +1140,9 @@ static md2model_t *md2load(int32_t fil, const char *filnam)
s->shaders = NULL;
s->tris = (md3tri_t *)nedpcalloc(model_data_pool, head.numtris, sizeof(md3tri_t)); if (!s->tris) { nedpfree(model_data_pool, s); nedpfree(model_data_pool, m3->head.frames); nedpfree(model_data_pool, m3); nedpfree(model_data_pool, m->skinfn); nedpfree(model_data_pool, m->basepath); nedpfree(model_data_pool, m->uv); nedpfree(model_data_pool, m->tris); nedpfree(model_data_pool, m->glcmds); nedpfree(model_data_pool, m->frames); nedpfree(model_data_pool, m); return(0); }
s->uv = (md3uv_t *)nedpcalloc(model_data_pool, s->numverts, sizeof(md3uv_t)); if (!s->uv) { nedpfree(model_data_pool, s->tris); nedpfree(model_data_pool, s); nedpfree(model_data_pool, m3->head.frames); nedpfree(model_data_pool, m3); nedpfree(model_data_pool, m->skinfn); nedpfree(model_data_pool, m->basepath); nedpfree(model_data_pool, m->uv); nedpfree(model_data_pool, m->tris); nedpfree(model_data_pool, m->glcmds); nedpfree(model_data_pool, m->frames); nedpfree(model_data_pool, m); return(0); }
s->xyzn = (md3xyzn_t *)nedpcalloc(model_data_pool, s->numverts * m->numframes, sizeof(md3xyzn_t)); if (!s->xyzn) { nedpfree(model_data_pool, s->uv); nedpfree(model_data_pool, s->tris); nedpfree(model_data_pool, s); nedpfree(model_data_pool, m3->head.frames); nedpfree(model_data_pool, m3); nedpfree(model_data_pool, m->skinfn); nedpfree(model_data_pool, m->basepath); nedpfree(model_data_pool, m->uv); nedpfree(model_data_pool, m->tris); nedpfree(model_data_pool, m->glcmds); nedpfree(model_data_pool, m->frames); nedpfree(model_data_pool, m); return(0); }
s->tris = (md3tri_t *)Bcalloc(head.numtris, sizeof(md3tri_t)); if (!s->tris) { Bfree(s); Bfree(m3->head.frames); Bfree(m3); Bfree(m->skinfn); Bfree(m->basepath); Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
s->uv = (md3uv_t *)Bcalloc(s->numverts, sizeof(md3uv_t)); if (!s->uv) { Bfree(s->tris); Bfree(s); Bfree(m3->head.frames); Bfree(m3); Bfree(m->skinfn); Bfree(m->basepath); Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
s->xyzn = (md3xyzn_t *)Bcalloc(s->numverts * m->numframes, sizeof(md3xyzn_t)); if (!s->xyzn) { Bfree(s->uv); Bfree(s->tris); Bfree(s); Bfree(m3->head.frames); Bfree(m3); Bfree(m->skinfn); Bfree(m->basepath); Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
//memoryusage += (s->numverts * m->numframes * sizeof(md3xyzn_t));
//OSD_Printf("Current model geometry memory usage : %i.\n", memoryusage);
@ -1196,28 +1196,28 @@ static md2model_t *md2load(int32_t fil, const char *filnam)
{
mdskinmap_t *sk;
sk = (mdskinmap_t *)nedpcalloc(model_data_pool, 1,sizeof(mdskinmap_t));
sk = (mdskinmap_t *)Bcalloc(1,sizeof(mdskinmap_t));
sk->palette = 0;
sk->skinnum = 0;
sk->surfnum = 0;
if (m->numskins > 0)
{
sk->fn = (char *)nedpmalloc(model_data_pool, strlen(m->basepath)+strlen(m->skinfn)+1);
sk->fn = (char *)malloc(strlen(m->basepath)+strlen(m->skinfn)+1);
strcpy(sk->fn, m->basepath);
strcat(sk->fn, m->skinfn);
}
m3->skinmap = sk;
}
m3->indexes = nedpmalloc(model_data_pool, sizeof(uint16_t) * s->numtris);
m3->vindexes = nedpmalloc(model_data_pool, sizeof(uint16_t) * s->numtris * 3);
m3->maxdepths = nedpmalloc(model_data_pool, sizeof(float) * s->numtris);
m3->indexes = malloc(sizeof(uint16_t) * s->numtris);
m3->vindexes = malloc(sizeof(uint16_t) * s->numtris * 3);
m3->maxdepths = malloc(sizeof(float) * s->numtris);
m3->vbos = NULL;
// die MD2 ! DIE !
nedpfree(model_data_pool, m->texid); nedpfree(model_data_pool, m->skinfn); nedpfree(model_data_pool, m->basepath); nedpfree(model_data_pool, m->uv); nedpfree(model_data_pool, m->tris); nedpfree(model_data_pool, m->glcmds); nedpfree(model_data_pool, m->frames); nedpfree(model_data_pool, m);
Bfree(m->texid); Bfree(m->skinfn); Bfree(m->basepath); Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m);
return((md2model_t *)m3);
}
@ -1278,7 +1278,7 @@ static md3model_t *md3load(int32_t fil)
md3model_t *m;
md3surf_t *s;
m = (md3model_t *)nedpcalloc(model_data_pool, 1,sizeof(md3model_t)); if (!m) return(0);
m = (md3model_t *)Bcalloc(1,sizeof(md3model_t)); if (!m) return(0);
m->mdnum = 3; m->texid = 0; m->scale = .01f;
m->muladdframes = NULL;
@ -1291,7 +1291,7 @@ static md3model_t *md3load(int32_t fil)
m->head.ofstags = B_LITTLE32(m->head.ofstags); m->head.ofssurfs = B_LITTLE32(m->head.ofssurfs);
m->head.eof = B_LITTLE32(m->head.eof);
if ((m->head.id != 0x33504449) && (m->head.vers != 15)) { nedpfree(model_data_pool, m); return(0); } //"IDP3"
if ((m->head.id != 0x33504449) && (m->head.vers != 15)) { Bfree(m); return(0); } //"IDP3"
m->numskins = m->head.numskins; //<- dead code?
m->numframes = m->head.numframes;
@ -1299,19 +1299,19 @@ static md3model_t *md3load(int32_t fil)
ofsurf = m->head.ofssurfs;
klseek(fil,m->head.ofsframes,SEEK_SET); i = m->head.numframes*sizeof(md3frame_t);
m->head.frames = (md3frame_t *)nedpmalloc(model_data_pool, i); if (!m->head.frames) { nedpfree(model_data_pool, m); return(0); }
m->head.frames = (md3frame_t *)malloc(i); if (!m->head.frames) { Bfree(m); return(0); }
kread(fil,m->head.frames,i);
if (m->head.numtags == 0) m->head.tags = NULL;
else
{
klseek(fil,m->head.ofstags,SEEK_SET); i = m->head.numtags*sizeof(md3tag_t);
m->head.tags = (md3tag_t *)nedpmalloc(model_data_pool, i); if (!m->head.tags) { nedpfree(model_data_pool, m->head.frames); nedpfree(model_data_pool, m); return(0); }
m->head.tags = (md3tag_t *)malloc(i); if (!m->head.tags) { Bfree(m->head.frames); Bfree(m); return(0); }
kread(fil,m->head.tags,i);
}
klseek(fil,m->head.ofssurfs,SEEK_SET); i = m->head.numsurfs*sizeof(md3surf_t);
m->head.surfs = (md3surf_t *)nedpmalloc(model_data_pool, i); if (!m->head.surfs) { if (m->head.tags) nedpfree(model_data_pool, m->head.tags); nedpfree(model_data_pool, m->head.frames); nedpfree(model_data_pool, m); return(0); }
m->head.surfs = (md3surf_t *)malloc(i); if (!m->head.surfs) { if (m->head.tags) Bfree(m->head.tags); Bfree(m->head.frames); Bfree(m); return(0); }
#if B_BIG_ENDIAN != 0
{
@ -1355,11 +1355,11 @@ static md3model_t *md3load(int32_t fil)
//OSD_Printf("Current model geometry memory usage : %i.\n", memoryusage);
s->tris = (md3tri_t *)nedpmalloc(model_data_pool, leng[0]+leng[1]+leng[2]+leng[3]);
s->tris = (md3tri_t *)malloc(leng[0]+leng[1]+leng[2]+leng[3]);
if (!s->tris)
{
for (surfi--; surfi>=0; surfi--) nedpfree(model_data_pool, m->head.surfs[surfi].tris);
if (m->head.tags) nedpfree(model_data_pool, m->head.tags); nedpfree(model_data_pool, m->head.frames); nedpfree(model_data_pool, m); return(0);
for (surfi--; surfi>=0; surfi--) Bfree(m->head.surfs[surfi].tris);
if (m->head.tags) Bfree(m->head.tags); Bfree(m->head.frames); Bfree(m); return(0);
}
s->shaders = (md3shader_t *)(((intptr_t)s->tris)+leng[0]);
s->uv = (md3uv_t *)(((intptr_t)s->shaders)+leng[1]);
@ -1428,9 +1428,9 @@ static md3model_t *md3load(int32_t fil)
}
#endif
m->indexes = nedpmalloc(model_data_pool, sizeof(uint16_t) * maxtrispersurf);
m->vindexes = nedpmalloc(model_data_pool, sizeof(uint16_t) * maxtrispersurf * 3);
m->maxdepths = nedpmalloc(model_data_pool, sizeof(float) * maxtrispersurf);
m->indexes = malloc(sizeof(uint16_t) * maxtrispersurf);
m->vindexes = malloc(sizeof(uint16_t) * maxtrispersurf * 3);
m->maxdepths = malloc(sizeof(float) * maxtrispersurf);
m->vbos = NULL;
@ -1580,9 +1580,9 @@ static int md3postload(md3model_t* m)
{
s = &m->head.surfs[surfi];
s->geometry = nedpcalloc(model_data_pool, m->head.numframes * s->numverts * sizeof(float), 15);
s->geometry = Bcalloc(m->head.numframes * s->numverts * sizeof(float), 15);
numtris = nedpcalloc(model_data_pool, s->numverts, sizeof(int));
numtris = Bcalloc(s->numverts, sizeof(int));
verti = 0;
while (verti < (m->head.numframes * s->numverts))
@ -1611,7 +1611,7 @@ static int md3postload(md3model_t* m)
s->tris[trii].i[1] >= s->numverts || s->tris[trii].i[1] < 0 ||
s->tris[trii].i[2] >= s->numverts || s->tris[trii].i[2] < 0) {
// corrupt model
nedpfree(model_data_pool, numtris);
Bfree(numtris);
OSD_Printf("Triangle index out of bounds!\n");
return 0;
}
@ -1693,7 +1693,7 @@ static int md3postload(md3model_t* m)
verti++;
}
nedpfree(model_data_pool, numtris);
Bfree(numtris);
surfi++;
}
@ -2232,13 +2232,13 @@ static void md3free(md3model_t *m)
for (anim=m->animations; anim; anim=nanim)
{
nanim = anim->next;
nedpfree(model_data_pool, anim);
Bfree(anim);
}
for (sk=m->skinmap; sk; sk=nsk)
{
nsk = sk->next;
nedpfree(model_data_pool, sk->fn);
nedpfree(model_data_pool, sk);
Bfree(sk->fn);
Bfree(sk);
}
if (m->head.surfs)
@ -2246,35 +2246,35 @@ static void md3free(md3model_t *m)
for (surfi=m->head.numsurfs-1; surfi>=0; surfi--)
{
s = &m->head.surfs[surfi];
if (s->tris) nedpfree(model_data_pool, s->tris);
if (s->tris) Bfree(s->tris);
if (m->head.flags == 1337)
{
if (s->shaders) nedpfree(model_data_pool, s->shaders);
if (s->uv) nedpfree(model_data_pool, s->uv);
if (s->xyzn) nedpfree(model_data_pool, s->xyzn);
if (s->shaders) Bfree(s->shaders);
if (s->uv) Bfree(s->uv);
if (s->xyzn) Bfree(s->xyzn);
}
}
nedpfree(model_data_pool, m->head.surfs);
Bfree(m->head.surfs);
}
if (m->head.tags) nedpfree(model_data_pool, m->head.tags);
if (m->head.frames) nedpfree(model_data_pool, m->head.frames);
if (m->head.tags) Bfree(m->head.tags);
if (m->head.frames) Bfree(m->head.frames);
if (m->texid) nedpfree(model_data_pool, m->texid);
if (m->texid) Bfree(m->texid);
if (m->muladdframes) nedpfree(model_data_pool, m->muladdframes);
if (m->muladdframes) Bfree(m->muladdframes);
if (m->indexes) nedpfree(model_data_pool, m->indexes);
if (m->vindexes) nedpfree(model_data_pool, m->vindexes);
if (m->maxdepths) nedpfree(model_data_pool, m->maxdepths);
if (m->indexes) Bfree(m->indexes);
if (m->vindexes) Bfree(m->vindexes);
if (m->maxdepths) Bfree(m->maxdepths);
if (m->vbos)
{
bglDeleteBuffersARB(m->head.numsurfs, m->vbos);
nedpfree(model_data_pool, m->vbos);
Bfree(m->vbos);
m->vbos = NULL;
}
nedpfree(model_data_pool, m);
Bfree(m);
}
//---------------------------------------- MD3 LIBRARY ENDS ----------------------------------------
@ -2301,7 +2301,7 @@ uint32_t gloadtex(int32_t *picbuf, int32_t xsiz, int32_t ysiz, int32_t is8bit, i
int32_t i;
pic = (coltype *)picbuf; //Correct for GL's RGB order; also apply gamma here..
pic2 = (coltype *)nedpmalloc(model_data_pool, xsiz*ysiz*sizeof(int32_t)); if (!pic2) return((unsigned)-1);
pic2 = (coltype *)malloc(xsiz*ysiz*sizeof(int32_t)); if (!pic2) return((unsigned)-1);
cptr = (char*)&britable[gammabrightness ? 0 : curbrightness][0];
if (!is8bit)
{
@ -2330,7 +2330,7 @@ uint32_t gloadtex(int32_t *picbuf, int32_t xsiz, int32_t ysiz, int32_t is8bit, i
bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
bglTexImage2D(GL_TEXTURE_2D,0,4,xsiz,ysiz,0,GL_RGBA,GL_UNSIGNED_BYTE,(char *)pic2);
nedpfree(model_data_pool, pic2);
Bfree(pic2);
return(rtexid);
}
@ -2344,7 +2344,7 @@ static int32_t getvox(int32_t x, int32_t y, int32_t z)
static void putvox(int32_t x, int32_t y, int32_t z, int32_t col)
{
if (vnum >= vmax) { vmax = max(vmax<<1,4096); vcol = (voxcol_t *)nedprealloc(model_data_pool, vcol,vmax*sizeof(voxcol_t)); }
if (vnum >= vmax) { vmax = max(vmax<<1,4096); vcol = (voxcol_t *)Brealloc(vcol,vmax*sizeof(voxcol_t)); }
z += x*yzsiz + y*zsiz;
vcol[vnum].p = z; z = ((z*214013)&vcolhashsizm1);
@ -2552,7 +2552,7 @@ static voxmodel_t *vox2poly()
int32_t i, j, x, y, z, v, ov, oz = 0, cnt, sc, x0, y0, dx, dy,*bx0, *by0;
void (*daquad)(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t);
gvox = (voxmodel_t *)nedpmalloc(model_data_pool, sizeof(voxmodel_t)); if (!gvox) return(0);
gvox = (voxmodel_t *)malloc(sizeof(voxmodel_t)); if (!gvox) return(0);
memset(gvox,0,sizeof(voxmodel_t));
//x is largest dimension, y is 2nd largest dimension
@ -2560,7 +2560,7 @@ static voxmodel_t *vox2poly()
if ((x < y) && (x < z)) x = z; else if (y < z) y = z;
if (x < y) { z = x; x = y; y = z; }
shcntp = x; i = x*y*sizeof(int32_t);
shcntmal = (int32_t *)nedpmalloc(model_data_pool, i); if (!shcntmal) { nedpfree(model_data_pool, gvox); return(0); }
shcntmal = (int32_t *)malloc(i); if (!shcntmal) { Bfree(gvox); return(0); }
memset(shcntmal,0,i); shcnt = &shcntmal[-shcntp-1];
gmaxx = gmaxy = garea = 0;
@ -2568,7 +2568,7 @@ static voxmodel_t *vox2poly()
for (i=0; i<7; i++) gvox->qfacind[i] = -1;
i = ((max(ysiz,zsiz)+1)<<2);
bx0 = (int32_t *)nedpmalloc(model_data_pool, i<<1); if (!bx0) { nedpfree(model_data_pool, gvox); return(0); }
bx0 = (int32_t *)malloc(i<<1); if (!bx0) { Bfree(gvox); return(0); }
by0 = (int32_t *)(((intptr_t)bx0)+i);
for (cnt=0; cnt<2; cnt++)
@ -2614,8 +2614,8 @@ static voxmodel_t *vox2poly()
if (!cnt)
{
shp = (spoint2d *)nedpmalloc(model_data_pool, gvox->qcnt*sizeof(spoint2d));
if (!shp) { nedpfree(model_data_pool, bx0); nedpfree(model_data_pool, gvox); return(0); }
shp = (spoint2d *)malloc(gvox->qcnt*sizeof(spoint2d));
if (!shp) { Bfree(bx0); Bfree(gvox); return(0); }
sc = 0;
for (y=gmaxy; y; y--)
@ -2636,7 +2636,7 @@ skindidntfit:
mytexo5 = (gvox->mytexx>>5);
i = (((gvox->mytexx*gvox->mytexy+31)>>5)<<2);
zbit = (int32_t *)nedpmalloc(model_data_pool, i); if (!zbit) { nedpfree(model_data_pool, bx0); nedpfree(model_data_pool, gvox); nedpfree(model_data_pool, shp); return(0); }
zbit = (int32_t *)malloc(i); if (!zbit) { Bfree(bx0); Bfree(gvox); Bfree(shp); return(0); }
memset(zbit,0,i);
v = gvox->mytexx*gvox->mytexy;
@ -2655,7 +2655,7 @@ skindidntfit:
i--;
if (i < 0) //Time-out! Very slow if this happens... but at least it still works :P
{
nedpfree(model_data_pool, zbit);
Bfree(zbit);
//Re-generate shp[].x/y (box sizes) from shcnt (now head indices) for next pass :/
j = 0;
@ -2678,14 +2678,14 @@ skindidntfit:
shp[z].x = x0; shp[z].y = y0; //Overwrite size with top-left location
}
gvox->quad = (voxrect_t *)nedpmalloc(model_data_pool, gvox->qcnt*sizeof(voxrect_t));
if (!gvox->quad) { nedpfree(model_data_pool, zbit); nedpfree(model_data_pool, shp); nedpfree(model_data_pool, bx0); nedpfree(model_data_pool, gvox); return(0); }
gvox->quad = (voxrect_t *)malloc(gvox->qcnt*sizeof(voxrect_t));
if (!gvox->quad) { Bfree(zbit); Bfree(shp); Bfree(bx0); Bfree(gvox); return(0); }
gvox->mytex = (int32_t *)nedpmalloc(model_data_pool, gvox->mytexx*gvox->mytexy*sizeof(int32_t));
if (!gvox->mytex) { nedpfree(model_data_pool, gvox->quad); nedpfree(model_data_pool, zbit); nedpfree(model_data_pool, shp); nedpfree(model_data_pool, bx0); nedpfree(model_data_pool, gvox); return(0); }
gvox->mytex = (int32_t *)malloc(gvox->mytexx*gvox->mytexy*sizeof(int32_t));
if (!gvox->mytex) { Bfree(gvox->quad); Bfree(zbit); Bfree(shp); Bfree(bx0); Bfree(gvox); return(0); }
}
}
nedpfree(model_data_pool, shp); nedpfree(model_data_pool, zbit); nedpfree(model_data_pool, bx0);
Bfree(shp); Bfree(zbit); Bfree(bx0);
return(gvox);
}
@ -2708,14 +2708,14 @@ static int32_t loadvox(const char *filnam)
pal[255] = -1;
vcolhashsizm1 = 8192-1;
vcolhashead = (int32_t *)nedpmalloc(model_data_pool, (vcolhashsizm1+1)*sizeof(int32_t)); if (!vcolhashead) { kclose(fil); return(-1); }
vcolhashead = (int32_t *)malloc((vcolhashsizm1+1)*sizeof(int32_t)); if (!vcolhashead) { kclose(fil); return(-1); }
memset(vcolhashead,-1,(vcolhashsizm1+1)*sizeof(int32_t));
yzsiz = ysiz*zsiz; i = ((xsiz*yzsiz+31)>>3);
vbit = (int32_t *)nedpmalloc(model_data_pool, i); if (!vbit) { kclose(fil); return(-1); }
vbit = (int32_t *)malloc(i); if (!vbit) { kclose(fil); return(-1); }
memset(vbit,0,i);
tbuf = (char *)nedpmalloc(model_data_pool, zsiz*sizeof(uint8_t)); if (!tbuf) { kclose(fil); return(-1); }
tbuf = (char *)malloc(zsiz*sizeof(uint8_t)); if (!tbuf) { kclose(fil); return(-1); }
klseek(fil,12,SEEK_SET);
for (x=0; x<xsiz; x++)
@ -2747,7 +2747,7 @@ static int32_t loadvox(const char *filnam)
}
}
nedpfree(model_data_pool, tbuf); kclose(fil); return(0);
Bfree(tbuf); kclose(fil); return(0);
}
static int32_t loadkvx(const char *filnam)
@ -2767,7 +2767,7 @@ static int32_t loadkvx(const char *filnam)
klseek(fil,(xsiz+1)<<2,SEEK_CUR);
ysizp1 = ysiz+1;
i = xsiz*ysizp1*sizeof(int16_t);
xyoffs = (uint16_t *)nedpmalloc(model_data_pool, i); if (!xyoffs) { kclose(fil); return(-1); }
xyoffs = (uint16_t *)malloc(i); if (!xyoffs) { kclose(fil); return(-1); }
kread(fil,xyoffs,i); for (i=i/sizeof(int16_t)-1; i>=0; i--) xyoffs[i] = B_LITTLE16(xyoffs[i]);
klseek(fil,-768,SEEK_END);
@ -2775,17 +2775,17 @@ static int32_t loadkvx(const char *filnam)
{ kread(fil,c,3); pal[i] = B_LITTLE32((((int32_t)c[0])<<18)+(((int32_t)c[1])<<10)+(((int32_t)c[2])<<2)+(i<<24)); }
yzsiz = ysiz*zsiz; i = ((xsiz*yzsiz+31)>>3);
vbit = (int32_t *)nedpmalloc(model_data_pool, i); if (!vbit) { nedpfree(model_data_pool, xyoffs); kclose(fil); return(-1); }
vbit = (int32_t *)malloc(i); if (!vbit) { Bfree(xyoffs); kclose(fil); return(-1); }
memset(vbit,0,i);
for (vcolhashsizm1=4096; vcolhashsizm1<(mip1leng>>1); vcolhashsizm1<<=1); vcolhashsizm1--; //approx to numvoxs!
vcolhashead = (int32_t *)nedpmalloc(model_data_pool, (vcolhashsizm1+1)*sizeof(int32_t)); if (!vcolhashead) { nedpfree(model_data_pool, xyoffs); kclose(fil); return(-1); }
vcolhashead = (int32_t *)malloc((vcolhashsizm1+1)*sizeof(int32_t)); if (!vcolhashead) { Bfree(xyoffs); kclose(fil); return(-1); }
memset(vcolhashead,-1,(vcolhashsizm1+1)*sizeof(int32_t));
klseek(fil,28+((xsiz+1)<<2)+((ysizp1*xsiz)<<1),SEEK_SET);
i = kfilelength(fil)-ktell(fil);
tbuf = (char *)nedpmalloc(model_data_pool, i); if (!tbuf) { nedpfree(model_data_pool, xyoffs); kclose(fil); return(-1); }
tbuf = (char *)malloc(i); if (!tbuf) { Bfree(xyoffs); kclose(fil); return(-1); }
kread(fil,tbuf,i); kclose(fil);
cptr = tbuf;
@ -2804,7 +2804,7 @@ static int32_t loadkvx(const char *filnam)
}
}
nedpfree(model_data_pool, tbuf); nedpfree(model_data_pool, xyoffs); return(0);
Bfree(tbuf); Bfree(xyoffs); return(0);
}
static int32_t loadkv6(const char *filnam)
@ -2823,7 +2823,7 @@ static int32_t loadkv6(const char *filnam)
kread(fil,&i,4); zpiv = (float)(B_LITTLE32(i));
kread(fil,&numvoxs,4); numvoxs = B_LITTLE32(numvoxs);
ylen = (uint16_t *)nedpmalloc(model_data_pool, xsiz*ysiz*sizeof(int16_t));
ylen = (uint16_t *)malloc(xsiz*ysiz*sizeof(int16_t));
if (!ylen) { kclose(fil); return(-1); }
klseek(fil,32+(numvoxs<<3)+(xsiz<<2),SEEK_SET);
@ -2831,11 +2831,11 @@ static int32_t loadkv6(const char *filnam)
klseek(fil,32,SEEK_SET);
yzsiz = ysiz*zsiz; i = ((xsiz*yzsiz+31)>>3);
vbit = (int32_t *)nedpmalloc(model_data_pool, i); if (!vbit) { nedpfree(model_data_pool, ylen); kclose(fil); return(-1); }
vbit = (int32_t *)malloc(i); if (!vbit) { Bfree(ylen); kclose(fil); return(-1); }
memset(vbit,0,i);
for (vcolhashsizm1=4096; vcolhashsizm1<numvoxs; vcolhashsizm1<<=1); vcolhashsizm1--;
vcolhashead = (int32_t *)nedpmalloc(model_data_pool, (vcolhashsizm1+1)*sizeof(int32_t)); if (!vcolhashead) { nedpfree(model_data_pool, ylen); kclose(fil); return(-1); }
vcolhashead = (int32_t *)malloc((vcolhashsizm1+1)*sizeof(int32_t)); if (!vcolhashead) { Bfree(ylen); kclose(fil); return(-1); }
memset(vcolhashead,-1,(vcolhashsizm1+1)*sizeof(int32_t));
for (x=0; x<xsiz; x++)
@ -2852,7 +2852,7 @@ static int32_t loadkv6(const char *filnam)
z1 = z0+1;
}
}
nedpfree(model_data_pool, ylen); kclose(fil); return(0);
Bfree(ylen); kclose(fil); return(0);
}
#if 0
@ -2874,16 +2874,16 @@ static int32_t loadvxl(const char *filnam)
zpiv = ((float)zsiz)*.5;
yzsiz = ysiz*zsiz; i = ((xsiz*yzsiz+31)>>3);
vbit = (int32_t *)nedpmalloc(model_data_pool, i); if (!vbit) { kclose(fil); return(-1); }
vbit = (int32_t *)malloc(i); if (!vbit) { kclose(fil); return(-1); }
memset(vbit,-1,i);
vcolhashsizm1 = 1048576-1;
vcolhashead = (int32_t *)nedpmalloc(model_data_pool, (vcolhashsizm1+1)*sizeof(int32_t)); if (!vcolhashead) { kclose(fil); return(-1); }
vcolhashead = (int32_t *)malloc((vcolhashsizm1+1)*sizeof(int32_t)); if (!vcolhashead) { kclose(fil); return(-1); }
memset(vcolhashead,-1,(vcolhashsizm1+1)*sizeof(int32_t));
//Allocate huge buffer and load rest of file into it...
i = kfilelength(fil)-ktell(fil);
vbuf = (char *)nedpmalloc(model_data_pool, i); if (!vbuf) { kclose(fil); return(-1); }
vbuf = (char *)malloc(i); if (!vbuf) { kclose(fil); return(-1); }
kread(fil,vbuf,i);
kclose(fil);
@ -2901,17 +2901,17 @@ static int32_t loadvxl(const char *filnam)
}
v += ((((int32_t)v[2])-((int32_t)v[1])+2)<<2);
}
nedpfree(model_data_pool, vbuf); return(0);
Bfree(vbuf); return(0);
}
#endif
void voxfree(voxmodel_t *m)
{
if (!m) return;
if (m->mytex) nedpfree(model_data_pool, m->mytex);
if (m->quad) nedpfree(model_data_pool, m->quad);
if (m->texid) nedpfree(model_data_pool, m->texid);
nedpfree(model_data_pool, m);
if (m->mytex) Bfree(m->mytex);
if (m->quad) Bfree(m->quad);
if (m->texid) Bfree(m->texid);
Bfree(m);
}
voxmodel_t *voxload(const char *filnam)
@ -2934,13 +2934,13 @@ voxmodel_t *voxload(const char *filnam)
vm->xpiv = xpiv; vm->ypiv = ypiv; vm->zpiv = zpiv;
vm->is8bit = is8bit;
vm->texid = (uint32_t *)nedpcalloc(model_data_pool, MAXPALOOKUPS,sizeof(uint32_t));
vm->texid = (uint32_t *)Bcalloc(MAXPALOOKUPS,sizeof(uint32_t));
if (!vm->texid) { voxfree(vm); vm = 0; }
}
if (shcntmal) { nedpfree(model_data_pool, shcntmal); shcntmal = 0; }
if (vbit) { nedpfree(model_data_pool, vbit); vbit = 0; }
if (vcol) { nedpfree(model_data_pool, vcol); vcol = 0; vnum = 0; vmax = 0; }
if (vcolhashead) { nedpfree(model_data_pool, vcolhashead); vcolhashead = 0; }
if (shcntmal) { Bfree(shcntmal); shcntmal = 0; }
if (vbit) { Bfree(vbit); vbit = 0; }
if (vcol) { Bfree(vcol); vcol = 0; vnum = 0; vmax = 0; }
if (vcolhashead) { Bfree(vcolhashead); vcolhashead = 0; }
return(vm);
}
@ -3135,8 +3135,8 @@ int32_t mddraw(spritetype *tspr)
if (r_vbos && (r_vbocount > allocvbos))
{
indexvbos = nedprealloc(model_data_pool, indexvbos, sizeof(GLuint) * r_vbocount);
vertvbos = nedprealloc(model_data_pool, vertvbos, sizeof(GLuint) * r_vbocount);
indexvbos = Brealloc(indexvbos, sizeof(GLuint) * r_vbocount);
vertvbos = Brealloc(vertvbos, sizeof(GLuint) * r_vbocount);
bglGenBuffersARB(r_vbocount - allocvbos, &(indexvbos[allocvbos]));
bglGenBuffersARB(r_vbocount - allocvbos, &(vertvbos[allocvbos]));
@ -3159,7 +3159,7 @@ int32_t mddraw(spritetype *tspr)
if (maxmodelverts > allocmodelverts)
{
point3d *vl = (point3d *)nedprealloc(model_data_pool, vertlist,sizeof(point3d)*maxmodelverts);
point3d *vl = (point3d *)Brealloc(vertlist,sizeof(point3d)*maxmodelverts);
if (!vl) { OSD_Printf("ERROR: Not enough memory to allocate %d vertices!\n",maxmodelverts); return 0; }
vertlist = vl;
allocmodelverts = maxmodelverts;

View file

@ -36,15 +36,6 @@ DEALINGS IN THE SOFTWARE.
#pragma warning(disable:4706) /* assignment within conditional expression */
#endif
#define USE_ALLOCATOR 1
#define USE_MAGIC_HEADERS 1
#define MAXTHREADSINPOOL 1
#define FINEGRAINEDBINS 1
#define ENABLE_LARGE_PAGES 1
#define ENABLE_FAST_HEAP_DETECTION 1
#define NDEBUG 1
#define THREADCACHEMAX 32768
#define THREADCACHEMAXBINS ((15-4)*2)
/*#define ENABLE_TOLERANT_NEDMALLOC 1*/
/*#define ENABLE_FAST_HEAP_DETECTION 1*/
/*#define NEDMALLOC_DEBUG 1*/

View file

@ -173,8 +173,10 @@ int32_t main(int32_t argc, char *argv[])
char *argp;
FILE *fp;
#ifdef NEDMALLOC
nedcreatepool(SYSTEM_POOL_SIZE, -1);
// atexit(neddestroysyspool);
// atexit(neddestroysyspool);
#endif
buildkeytranslationtable();

File diff suppressed because it is too large Load diff

Binary file not shown.

View file

@ -9492,7 +9492,7 @@ static void G_ShowParameterHelp(void)
"-connect [host]\tConnect to a multiplayer game\n"
"-c#\t\tUse MP mode #, 1 = Dukematch, 2 = Coop, 3 = Dukematch(no spawn)\n"
"-d[file.dmo]\tPlay a demo\n"
"-g[file.grp]\tUse an extra group file\n"
"-g[file.grp]\tUse additional game data\n"
"-h[file.def]\tUse an alternate def\n"
"-j[dir]\t\tAdds a directory to EDuke32's search list\n"
"-l#\t\tWarp to level #, see -v\n"
@ -9595,7 +9595,7 @@ static void G_DoAutoload(const char *fn)
while (findfiles)
{
Bsprintf(tempbuf,"autoload/%s/%s",fn,findfiles->name);
initprintf("Using group file '%s'.\n",tempbuf);
initprintf("Using file '%s' as game data.\n",tempbuf);
initgroupfile(tempbuf);
findfiles = findfiles->next;
}
@ -9716,10 +9716,10 @@ static int32_t parsedefinitions_game(scriptfile *script, const int32_t preload)
int32_t j = initgroupfile(fn);
if (j == -1)
initprintf("Could not find group file '%s'.\n",fn);
initprintf("Could not find file '%s'.\n",fn);
else
{
initprintf("Using group file '%s'.\n",fn);
initprintf("Using file '%s' as game data.\n",fn);
if (!g_noAutoLoad && !ud.config.NoAutoLoad)
G_DoAutoload(fn);
}
@ -11470,9 +11470,9 @@ CLEAN_DIRECTORY:
i = initgroupfile(g_grpNamePtr);
if (i == -1)
initprintf("Warning: could not find main group file '%s'!\n",g_grpNamePtr);
initprintf("Warning: could not find main data file '%s'!\n",g_grpNamePtr);
else
initprintf("Using '%s' as main group file.\n", g_grpNamePtr);
initprintf("Using '%s' as main game data file.\n", g_grpNamePtr);
if (!g_noAutoLoad && !ud.config.NoAutoLoad)
{
@ -11484,7 +11484,7 @@ CLEAN_DIRECTORY:
while (findfiles)
{
Bsprintf(tempbuf,"autoload/%s",findfiles->name);
initprintf("Using group file '%s'.\n",tempbuf);
initprintf("Using file '%s' as game data.\n",tempbuf);
initgroupfile(tempbuf);
findfiles = findfiles->next;
}
@ -11505,7 +11505,7 @@ CLEAN_DIRECTORY:
while (findfiles)
{
Bsprintf(tempbuf,"%s/%s",g_modDir,findfiles->name);
initprintf("Using group file '%s'.\n",tempbuf);
initprintf("Using file '%s' as game data.\n",tempbuf);
initgroupfile(tempbuf);
findfiles = findfiles->next;
}
@ -11524,11 +11524,11 @@ CLEAN_DIRECTORY:
{
s = CommandGrps->next;
j = initgroupfile(CommandGrps->str);
if (j == -1) initprintf("Could not find group file '%s'.\n",CommandGrps->str);
if (j == -1) initprintf("Could not find file '%s'.\n",CommandGrps->str);
else
{
g_groupFileHandle = j;
initprintf("Using group file '%s'.\n",CommandGrps->str);
initprintf("Using file '%s' as game data.\n",CommandGrps->str);
if (!g_noAutoLoad && !ud.config.NoAutoLoad)
G_DoAutoload(CommandGrps->str);
}

View file

@ -93,7 +93,7 @@ int32_t ScanGroups(void)
return 0;
}
initprintf("Scanning for game data...\n");
initprintf("Searching for game data...\n");
LoadGroupsCache();