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,7 +31,7 @@ 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

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,7 +149,6 @@ ENGINEOBJS+= \
$(OBJ)/osd.$o \
$(OBJ)/pragmas.$o \
$(OBJ)/scriptfile.$o \
$(OBJ)/nedmalloc.$o \
$(OBJ)/mutex.$o
ifeq (1,$(USE_OPENGL))
@ -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
@ -77,9 +77,9 @@ ENGINEOBJS= \
$(OBJ)\scriptfile.$o \
$(OBJ)\winlayer.$o \
$(OBJ)\polymer.$o \
$(OBJ)\nedmalloc.$o \
$(OBJ)\mutex.$o \
$(OBJ)\rawinput.$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);
#endif
buildkeytranslationtable();

View file

@ -39,6 +39,7 @@
#include "a.h"
#include "osd.h"
#include "rawinput.h"
#include "nedmalloc.h"
// undefine to restrict windowed resolutions to conventional sizes
#define ANY_WINDOWED_SIZE
@ -85,7 +86,7 @@ static void ReleaseDirectDrawSurfaces(void);
static BOOL InitDirectInput(void);
static void UninitDirectInput(void);
static void GetKeyNames(void);
static void AcquireInputDevices(char acquire, int8_t device);
static void AcquireInputDevices(char acquire);
static inline void DI_PollJoysticks(void);
static int32_t SetupDirectDraw(int32_t width, int32_t height);
static void UninitDIB(void);
@ -132,7 +133,11 @@ int32_t remapinit=0;
static char key_names[256][24];
static OSVERSIONINFOEX osv;
#ifdef NEDMALLOC
extern int32_t largepagesavailable;
#else
static HMODULE nedhandle = NULL;
#endif
void (*keypresscallback)(int32_t,int32_t) = 0;
void (*mousepresscallback)(int32_t,int32_t) = 0;
@ -286,6 +291,7 @@ int32_t WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, in
return -1;
}
#ifdef NEDMALLOC
/* Attempt to enable SeLockMemoryPrivilege, 2003/Vista/7 only */
if (Bgetenv("BUILD_NOLARGEPAGES") == NULL &&
(osv.dwMajorVersion >= 6 || (osv.dwMajorVersion == 5 && osv.dwMinorVersion == 2)))
@ -310,8 +316,16 @@ int32_t WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, in
}
nedcreatepool(SYSTEM_POOL_SIZE, -1);
// atexit(neddestroysyspool);
#else
if ((nedhandle = LoadLibrary("nedmalloc.dll")))
{
nedpool *(WINAPI *nedcreatepool)(size_t, int);
if ((nedcreatepool = (void *)GetProcAddress(nedhandle, "nedcreatepool")))
nedcreatepool(SYSTEM_POOL_SIZE, -1);
}
#endif
hdc = GetDC(NULL);
r = GetDeviceCaps(hdc, BITSPIXEL);
@ -528,12 +542,19 @@ static void printsysversion(void)
break;
}
initprintf("Running under Windows %s (build %lu.%lu.%lu) %s\n", ver, osv.dwMajorVersion, osv.dwMinorVersion,
initprintf("Running under Windows %s (build %lu.%lu.%lu) %s", ver, osv.dwMajorVersion, osv.dwMinorVersion,
osv.dwPlatformId == VER_PLATFORM_WIN32_NT ? osv.dwBuildNumber : osv.dwBuildNumber&0xffff,
osv.szCSDVersion);
#ifdef NEDMALLOC
initprintf("\n");
if (largepagesavailable)
initprintf("Large page support available\n");
#else
if (nedhandle) initprintf("with nedmalloc\n");
#endif
}
@ -596,6 +617,10 @@ void uninitsystem(void)
#if defined(USE_OPENGL) && defined(POLYMOST)
unloadgldriver();
#endif
#ifndef NEDMALLOC
if (nedhandle) FreeLibrary(nedhandle), nedhandle = NULL;
#endif
}
@ -671,18 +696,20 @@ int32_t handleevents(void)
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
quitevent = 1;
if (startwin_idle((void*)&msg) > 0) continue;
if (msg.message == WM_INPUT)
switch (msg.message)
{
RI_PollDevices(FALSE);
case WM_QUIT:
quitevent = 1;
continue;
case WM_INPUT:
// this call to RI_PollDevices() probably isn't necessary
// RI_PollDevices(FALSE);
RI_ProcessMessage(&msg);
continue;
}
if (startwin_idle((void*)&msg) > 0) continue;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
@ -699,31 +726,25 @@ int32_t handleevents(void)
//=================================================================================================
#define JOYSTICK 0
#define NUM_INPUTS 1
static HMODULE hDInputDLL = NULL;
static LPDIRECTINPUT7A lpDI = NULL;
static LPDIRECTINPUTDEVICE7A lpDID[NUM_INPUTS] = { NULL };
static LPDIRECTINPUTDEVICE7A lpDID = NULL;
#define INPUT_BUFFER_SIZE 32
static GUID guidDevs[NUM_INPUTS];
static GUID guidDevs;
static char devacquired[NUM_INPUTS];
static HANDLE inputevt[NUM_INPUTS];
static char di_devacquired;
static HANDLE di_inputevt;
static int32_t joyblast=0;
volatile uint8_t moustat = 0, mousegrab = 0;
static uint32_t idevnums[NUM_INPUTS], numdevs = 0;
static HANDLE waithnds[NUM_INPUTS];
static struct
{
char *name;
LPDIRECTINPUTDEVICE7A *did;
const DIDATAFORMAT *df;
} devicedef[NUM_INPUTS] =
{
{ "joystick", &lpDID[JOYSTICK], &c_dfDIJoystick }
};
} devicedef = { "joystick", &lpDID, &c_dfDIJoystick };
static struct _joydef
{
const char *name;
@ -744,34 +765,30 @@ inline void SetKey(int32_t key, int32_t state)
}
}
char map_dik_code(int32_t scanCode)
{
// ugly table for remapping out of range DIK_ entries will go here
// if I can't figure out the layout problem
return scanCode;
}
//
// initinput() -- init input system
//
int32_t initinput(void)
{
int32_t i;
char layoutname[KL_NAMELENGTH];
moustat=0;
memset(keystatus, 0, sizeof(keystatus));
if (!remapinit)
for (i=0; i<256; i++)
remap[i]=map_dik_code(i);
remap[i]=i;
remapinit=1;
keyfifoplc = keyfifoend = 0;
keyasciififoplc = keyasciififoend = 0;
inputdevices = 1|2;
joyisgamepad=0, joynumaxes=0, joynumbuttons=0, joynumhats=0;
joyisgamepad = joynumaxes = joynumbuttons = joynumhats=0;
// 00000409 is "American English"
{
char layoutname[KL_NAMELENGTH];
GetKeyboardLayoutName(layoutname);
if (Bstrcmp(layoutname, "00000409"))
{
@ -780,7 +797,6 @@ int32_t initinput(void)
GetKeyboardLayoutName(layoutname);
initprintf("to %s\n",layoutname);
}
}
GetKeyNames();
InitDirectInput();
@ -858,7 +874,7 @@ void setjoydeadzone(int32_t axis, uint16_t dead, uint16_t satur)
DIPROPDWORD dipdw;
HRESULT result;
if (!lpDID[JOYSTICK]) return;
if (!lpDID) return;
if (dead > 10000) dead = 10000;
if (satur > 10000) satur = 10000;
@ -880,8 +896,8 @@ void setjoydeadzone(int32_t axis, uint16_t dead, uint16_t satur)
}
dipdw.dwData = dead;
result = IDirectInputDevice7_SetProperty(lpDID[JOYSTICK], DIPROP_DEADZONE, &dipdw.diph);
if FAILED(result)
result = IDirectInputDevice7_SetProperty(lpDID, DIPROP_DEADZONE, &dipdw.diph);
if (FAILED(result))
{
//ShowDInputErrorBox("Failed setting joystick dead zone", result);
initprintf("Failed setting joystick dead zone: %s\n", GetDInputError(result));
@ -890,8 +906,8 @@ void setjoydeadzone(int32_t axis, uint16_t dead, uint16_t satur)
dipdw.dwData = satur;
result = IDirectInputDevice7_SetProperty(lpDID[JOYSTICK], DIPROP_SATURATION, &dipdw.diph);
if FAILED(result)
result = IDirectInputDevice7_SetProperty(lpDID, DIPROP_SATURATION, &dipdw.diph);
if (FAILED(result))
{
//ShowDInputErrorBox("Failed setting joystick saturation point", result);
initprintf("Failed setting joystick saturation point: %s\n", GetDInputError(result));
@ -909,7 +925,7 @@ void getjoydeadzone(int32_t axis, uint16_t *dead, uint16_t *satur)
HRESULT result;
if (!dead || !satur) return;
if (!lpDID[JOYSTICK]) { *dead = *satur = 0; return; }
if (!lpDID) { *dead = *satur = 0; return; }
if (axis >= joynumaxes) { *dead = *satur = 0; return; }
memset(&dipdw, 0, sizeof(dipdw));
@ -926,8 +942,8 @@ void getjoydeadzone(int32_t axis, uint16_t *dead, uint16_t *satur)
dipdw.diph.dwHow = DIPH_BYOFFSET;
}
result = IDirectInputDevice7_GetProperty(lpDID[JOYSTICK], DIPROP_DEADZONE, &dipdw.diph);
if FAILED(result)
result = IDirectInputDevice7_GetProperty(lpDID, DIPROP_DEADZONE, &dipdw.diph);
if (FAILED(result))
{
//ShowDInputErrorBox("Failed getting joystick dead zone", result);
initprintf("Failed getting joystick dead zone: %s\n", GetDInputError(result));
@ -936,8 +952,8 @@ void getjoydeadzone(int32_t axis, uint16_t *dead, uint16_t *satur)
*dead = dipdw.dwData;
result = IDirectInputDevice7_GetProperty(lpDID[JOYSTICK], DIPROP_SATURATION, &dipdw.diph);
if FAILED(result)
result = IDirectInputDevice7_GetProperty(lpDID, DIPROP_SATURATION, &dipdw.diph);
if (FAILED(result))
{
//ShowDInputErrorBox("Failed getting joystick saturation point", result);
initprintf("Failed getting joystick saturation point: %s\n", GetDInputError(result));
@ -994,21 +1010,13 @@ static BOOL CALLBACK InitDirectInput_enum(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRe
UNREFERENCED_PARAMETER(pvRef);
#define COPYGUID(d,s) Bmemcpy(&d,&s,sizeof(GUID))
if ((lpddi->dwDevType&0xff) != DIDEVTYPE_JOYSTICK)
return DIENUM_CONTINUE;
switch (lpddi->dwDevType&0xff)
{
case DIDEVTYPE_JOYSTICK:
{
inputdevices |= (1<<(JOYSTICK+2));
inputdevices |= 4;
joyisgamepad = ((lpddi->dwDevType & (DIDEVTYPEJOYSTICK_GAMEPAD<<8)) != 0);
d = joyisgamepad ? "GAMEPAD" : "JOYSTICK";
COPYGUID(guidDevs[JOYSTICK],lpddi->guidInstance);
}
break;
default:
return DIENUM_CONTINUE;
}
Bmemcpy(&guidDevs, &lpddi->guidInstance, sizeof(GUID));
initprintf(" * %s: %s\n", d, lpddi->tszProductName);
@ -1064,13 +1072,10 @@ static BOOL InitDirectInput(void)
LPDIRECTINPUTDEVICE7A dev2;
DIDEVCAPS didc;
int32_t devn;
if (bDInputInited) return FALSE;
initprintf("Initializing DirectInput...\n");
// load up the DirectInput DLL
if (!hDInputDLL)
{
// initprintf(" - Loading DINPUT.DLL\n");
@ -1082,21 +1087,17 @@ static BOOL InitDirectInput(void)
}
}
// get the pointer to DirectInputCreate
aDirectInputCreateA = (void *)GetProcAddress(hDInputDLL, "DirectInputCreateA");
if (!aDirectInputCreateA) ShowErrorBox("Error fetching DirectInputCreateA()");
// create a new DirectInput object
// initprintf(" - Creating DirectInput object\n");
result = aDirectInputCreateA(hInstance, DIRECTINPUT_VERSION, &lpDI, NULL);
if FAILED(result) { HorribleDInputDeath("DirectInputCreateA() failed", result); }
if (FAILED(result)) { HorribleDInputDeath("DirectInputCreateA() failed", result); }
else if (result != DI_OK) initprintf(" Created DirectInput object with warning: %s\n",GetDInputError(result));
// enumerate devices to make us look fancy
initprintf(" - Enumerating attached game controllers\n");
inputdevices = 1|2;
result = IDirectInput7_EnumDevices(lpDI, 0, InitDirectInput_enum, NULL, DIEDFL_ATTACHEDONLY);
if FAILED(result) { HorribleDInputDeath("Failed enumerating attached game controllers", result); }
if (FAILED(result)) { HorribleDInputDeath("Failed enumerating attached game controllers", result); }
else if (result != DI_OK) initprintf(" Enumerated game controllers with warning: %s\n",GetDInputError(result));
if (inputdevices == (1|2))
@ -1107,30 +1108,24 @@ static BOOL InitDirectInput(void)
return TRUE;
}
// ***
// create the devices
// ***
for (devn = 0; devn < NUM_INPUTS; devn++)
{
if ((inputdevices & (1<<(devn+2))) == 0) continue;
*devicedef[devn].did = NULL;
*devicedef.did = NULL;
// initprintf(" - Creating %s device\n", devicedef[devn].name);
result = IDirectInput7_CreateDeviceEx(lpDI, &guidDevs[devn], &IID_IDirectInputDevice7, (void *)&dev, NULL);
if FAILED(result) { HorribleDInputDeath("Failed creating device", result); }
// initprintf(" - Creating %s device\n", devicedef.name);
result = IDirectInput7_CreateDeviceEx(lpDI, &guidDevs, &IID_IDirectInputDevice7, (void *)&dev, NULL);
if (FAILED(result)) { HorribleDInputDeath("Failed creating device", result); }
else if (result != DI_OK) initprintf(" Created device with warning: %s\n",GetDInputError(result));
result = IDirectInputDevice7_QueryInterface(dev, &IID_IDirectInputDevice7, (LPVOID *)&dev2);
IDirectInputDevice7_Release(dev);
if FAILED(result) { HorribleDInputDeath("Failed querying DirectInput7 interface for device", result); }
if (FAILED(result)) { HorribleDInputDeath("Failed querying DirectInput7 interface for device", result); }
else if (result != DI_OK) initprintf(" Queried IDirectInputDevice7 interface with warning: %s\n",GetDInputError(result));
result = IDirectInputDevice7_SetDataFormat(dev2, devicedef[devn].df);
if FAILED(result) { IDirectInputDevice7_Release(dev2); HorribleDInputDeath("Failed setting data format", result); }
result = IDirectInputDevice7_SetDataFormat(dev2, devicedef.df);
if (FAILED(result)) { IDirectInputDevice7_Release(dev2); HorribleDInputDeath("Failed setting data format", result); }
else if (result != DI_OK) initprintf(" Set data format with warning: %s\n",GetDInputError(result));
inputevt[devn] = CreateEvent(NULL, FALSE, FALSE, NULL);
if (inputevt[devn] == NULL)
di_inputevt = CreateEvent(NULL, FALSE, FALSE, NULL);
if (di_inputevt == NULL)
{
IDirectInputDevice7_Release(dev2);
ShowErrorBox("Couldn't create event object");
@ -1138,8 +1133,8 @@ static BOOL InitDirectInput(void)
return TRUE;
}
result = IDirectInputDevice7_SetEventNotification(dev2, inputevt[devn]);
if FAILED(result) { IDirectInputDevice7_Release(dev2); HorribleDInputDeath("Failed setting event object", result); }
result = IDirectInputDevice7_SetEventNotification(dev2, di_inputevt);
if (FAILED(result)) { IDirectInputDevice7_Release(dev2); HorribleDInputDeath("Failed setting event object", result); }
else if (result != DI_OK) initprintf(" Set event object with warning: %s\n",GetDInputError(result));
IDirectInputDevice7_Unacquire(dev2);
@ -1152,18 +1147,17 @@ static BOOL InitDirectInput(void)
dipdw.dwData = INPUT_BUFFER_SIZE;
result = IDirectInputDevice7_SetProperty(dev2, DIPROP_BUFFERSIZE, &dipdw.diph);
if FAILED(result) { IDirectInputDevice7_Release(dev2); HorribleDInputDeath("Failed setting buffering", result); }
if (FAILED(result)) { IDirectInputDevice7_Release(dev2); HorribleDInputDeath("Failed setting buffering", result); }
else if (result != DI_OK) initprintf(" Set buffering with warning: %s\n",GetDInputError(result));
// set up device
if (devn == JOYSTICK)
{
int32_t typecounts[3] = {0,0,0};
memset(&didc, 0, sizeof(didc));
didc.dwSize = sizeof(didc);
result = IDirectInputDevice7_GetCapabilities(dev2, &didc);
if FAILED(result) { IDirectInputDevice7_Release(dev2); HorribleDInputDeath("Failed getting controller capabilities", result); }
if (FAILED(result)) { IDirectInputDevice7_Release(dev2); HorribleDInputDeath("Failed getting controller capabilities", result); }
else if (result != DI_OK) initprintf(" Fetched controller capabilities with warning: %s\n",GetDInputError(result));
joynumaxes = (uint8_t)didc.dwAxes;
@ -1179,14 +1173,13 @@ static BOOL InitDirectInput(void)
joyhat = (int32_t *)Bcalloc(didc.dwPOVs, sizeof(int32_t));
result = IDirectInputDevice7_EnumObjects(dev2, InitDirectInput_enumobjects, (LPVOID)typecounts, DIDFT_ALL);
if FAILED(result) { IDirectInputDevice7_Release(dev2); HorribleDInputDeath("Failed getting controller features", result); }
if (FAILED(result)) { IDirectInputDevice7_Release(dev2); HorribleDInputDeath("Failed getting controller features", result); }
else if (result != DI_OK) initprintf(" Fetched controller features with warning: %s\n",GetDInputError(result));
}
*devicedef[devn].did = dev2;
}
*devicedef.did = dev2;
memset(devacquired, 0, sizeof(devacquired));
di_devacquired = 0;
bDInputInited = TRUE;
return FALSE;
@ -1198,12 +1191,11 @@ static BOOL InitDirectInput(void)
//
static void UninitDirectInput(void)
{
int32_t devn;
int32_t i;
if (bDInputInited) initprintf("Uninitializing DirectInput...\n");
AcquireInputDevices(0,-1);
AcquireInputDevices(0);
if (axisdefs)
{
@ -1221,20 +1213,15 @@ static void UninitDirectInput(void)
Bfree(hatdefs); hatdefs = NULL;
}
for (devn = 0; devn < NUM_INPUTS; devn++)
if (*devicedef.did)
{
if (*devicedef[devn].did)
{
if (devn != JOYSTICK) IDirectInputDevice7_SetEventNotification(*devicedef[devn].did, NULL);
IDirectInputDevice7_Release(*devicedef[devn].did);
*devicedef[devn].did = NULL;
IDirectInputDevice7_Release(*devicedef.did);
*devicedef.did = NULL;
}
if (inputevt[devn])
if (di_inputevt)
{
CloseHandle(inputevt[devn]);
inputevt[devn] = NULL;
}
CloseHandle(di_inputevt);
di_inputevt = NULL;
}
if (lpDI)
@ -1294,11 +1281,10 @@ const char *getjoyname(int32_t what, int32_t num)
//
// AcquireInputDevices() -- (un)acquires the input devices
//
static void AcquireInputDevices(char acquire, int8_t device)
static void AcquireInputDevices(char acquire)
{
DWORD flags;
HRESULT result;
int32_t i;
if (!bDInputInited) return;
if (!hWindow) return;
@ -1306,45 +1292,38 @@ static void AcquireInputDevices(char acquire, int8_t device)
if (acquire)
{
// if (!appactive) return; // why acquire when inactive?
for (i=0; i<NUM_INPUTS; i++)
{
if (! *devicedef[i].did) continue;
if (device != -1 && i != device) continue; // don't touch other devices if only the mouse is wanted
IDirectInputDevice7_Unacquire(*devicedef[i].did);
if (! *devicedef.did) return;
IDirectInputDevice7_Unacquire(*devicedef.did);
flags = DISCL_FOREGROUND|DISCL_NONEXCLUSIVE;
result = IDirectInputDevice7_SetCooperativeLevel(*devicedef[i].did, hWindow, flags);
result = IDirectInputDevice7_SetCooperativeLevel(*devicedef.did, hWindow, flags);
if (FAILED(result))
initprintf("IDirectInputDevice7_SetCooperativeLevel(%s): %s\n",
devicedef[i].name, GetDInputError(result));
devicedef.name, GetDInputError(result));
if (SUCCEEDED(IDirectInputDevice7_Acquire(*devicedef[i].did)))
devacquired[i] = 1;
if (SUCCEEDED(IDirectInputDevice7_Acquire(*devicedef.did)))
di_devacquired = 1;
else
devacquired[i] = 0;
di_devacquired = 0;
return;
}
}
else
{
di_devacquired = 0;
releaseallbuttons();
for (i=0; i<NUM_INPUTS; i++)
{
if (! *devicedef[i].did) continue;
if (device != -1 && i != device) continue; // don't touch other devices if only the mouse is wanted
if (! *devicedef.did) return;
IDirectInputDevice7_Unacquire(*devicedef[i].did);
IDirectInputDevice7_Unacquire(*devicedef.did);
result = IDirectInputDevice7_SetCooperativeLevel(*devicedef[i].did, hWindow, DISCL_FOREGROUND|DISCL_NONEXCLUSIVE);
result = IDirectInputDevice7_SetCooperativeLevel(*devicedef.did, hWindow, DISCL_FOREGROUND|DISCL_NONEXCLUSIVE);
if (FAILED(result))
initprintf("IDirectInputDevice7_SetCooperativeLevel(%s): %s\n",
devicedef[i].name, GetDInputError(result));
devacquired[i] = 0;
}
}
devicedef.name, GetDInputError(result));
}
//
@ -1355,54 +1334,35 @@ static inline void DI_PollJoysticks(void)
DWORD dwElements = INPUT_BUFFER_SIZE;
HRESULT result;
DIDEVICEOBJECTDATA didod[INPUT_BUFFER_SIZE];
uint32_t t;
int32_t i, ev;
numdevs = 0;
for (t = 0; t < NUM_INPUTS; t++)
if (*devicedef.did)
{
if (*devicedef[t].did)
{
result = IDirectInputDevice7_Poll(*devicedef[t].did);
result = IDirectInputDevice7_Poll(*devicedef.did);
if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED)
{
if (SUCCEEDED(IDirectInputDevice7_Acquire(*devicedef[t].did)))
if (SUCCEEDED(IDirectInputDevice7_Acquire(*devicedef.did)))
{
devacquired[t] = 1;
IDirectInputDevice7_Poll(*devicedef[t].did);
di_devacquired = 1;
IDirectInputDevice7_Poll(*devicedef.did);
}
else devacquired[t] = 0;
else di_devacquired = 0;
}
if (devacquired[t])
if (di_devacquired)
{
waithnds[numdevs] = inputevt[t];
idevnums[numdevs] = t;
numdevs++;
}
}
}
if (numdevs == 0) return; // nothing to do
// use event objects so that we can quickly get indication of when data is ready
// to be read and input events processed
ev = MsgWaitForMultipleObjects(numdevs, waithnds, FALSE, 0, 0);
ev = WaitForSingleObject(di_inputevt, 0);
if (ev < WAIT_OBJECT_0 || ev > (int32_t)(WAIT_OBJECT_0+numdevs))
if (ev != WAIT_OBJECT_0 || !lpDID)
return;
switch (idevnums[ev - WAIT_OBJECT_0])
{
case JOYSTICK:
if (!lpDID[JOYSTICK]) break;
result = IDirectInputDevice7_GetDeviceData(lpDID[JOYSTICK], sizeof(DIDEVICEOBJECTDATA),
result = IDirectInputDevice7_GetDeviceData(lpDID, sizeof(DIDEVICEOBJECTDATA),
(LPDIDEVICEOBJECTDATA)&didod, &dwElements, 0);
if (result != DI_OK || !dwElements) break;
if (result != DI_OK || !dwElements) return;
for (i=dwElements-1; i>=0; i--)
{
@ -1437,7 +1397,7 @@ static inline void DI_PollJoysticks(void)
break;
}
}
break;
}
}
}
@ -1767,7 +1727,7 @@ static HWND hGLWindow = NULL;
int32_t setvideomode(int32_t x, int32_t y, int32_t c, int32_t fs)
{
char i,inp[NUM_INPUTS];
char inp;
int32_t modenum;
if ((fs == fullscreen) && (x == xres) && (y == yres) && (c == bpp) && !videomodereset)
@ -1786,8 +1746,8 @@ int32_t setvideomode(int32_t x, int32_t y, int32_t c, int32_t fs)
customfs = fs;
}
for (i=0; i<NUM_INPUTS; i++) inp[i] = devacquired[i];
AcquireInputDevices(0,-1);
inp = di_devacquired;
AcquireInputDevices(0);
if (hWindow && gammabrightness)
{
@ -1813,7 +1773,7 @@ int32_t setvideomode(int32_t x, int32_t y, int32_t c, int32_t fs)
#if defined(USE_OPENGL) && defined(POLYMOST)
if (hGLWindow && glinfo.vsync) bwglSwapIntervalEXT(vsync);
#endif
for (i=0; i<NUM_INPUTS; i++) if (inp[i]) AcquireInputDevices(1,i);
if (inp) AcquireInputDevices(1);
modechange=1;
videomodereset = 0;
OSD_ResizeDisplay(xres,yres);
@ -3700,7 +3660,7 @@ static LRESULT CALLBACK WndProcCallback(HWND hWnd, UINT uMsg, WPARAM wParam, LPA
}
Bmemset(keystatus, 0, sizeof(keystatus));
AcquireInputDevices(appactive,-1);
AcquireInputDevices(appactive);
break;
}
@ -3712,13 +3672,13 @@ static LRESULT CALLBACK WndProcCallback(HWND hWnd, UINT uMsg, WPARAM wParam, LPA
}
Bmemset(keystatus, 0, sizeof(keystatus));
AcquireInputDevices(appactive,-1);
AcquireInputDevices(appactive);
break;
case WM_SIZE:
if (wParam == SIZE_MAXHIDE || wParam == SIZE_MINIMIZED) appactive = 0;
else appactive = 1;
AcquireInputDevices(appactive,-1);
AcquireInputDevices(appactive);
break;
case WM_PALETTECHANGED:
@ -3776,11 +3736,11 @@ static LRESULT CALLBACK WndProcCallback(HWND hWnd, UINT uMsg, WPARAM wParam, LPA
case WM_ENTERMENULOOP:
case WM_ENTERSIZEMOVE:
AcquireInputDevices(0,-1);
AcquireInputDevices(0);
return 0;
case WM_EXITMENULOOP:
case WM_EXITSIZEMOVE:
AcquireInputDevices(1,-1);
AcquireInputDevices(1);
return 0;
case WM_DESTROY:

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();