git-svn-id: https://svn.eduke32.com/eduke32@1166 1a8010ca-5511-0410-912e-c29ae57300e0

This commit is contained in:
terminx 2008-11-26 22:51:56 +00:00
parent 2ac3fe6312
commit 0cf8a909d4
7 changed files with 87 additions and 112 deletions

View file

@ -1399,7 +1399,7 @@ static int defsparser(scriptfile *script)
double scale=1.0; double scale=1.0;
scriptfile_getdouble(script,&scale); scriptfile_getdouble(script,&scale);
#ifdef SUPERBUILD #ifdef SUPERBUILD
voxscale[lastvoxid] = 65536*scale; voxscale[lastvoxid] = (int)(65536*scale);
#endif #endif
break; break;
} }

View file

@ -5783,8 +5783,6 @@ void uninitengine(void)
//OSD_Printf("cacheresets = %d, cacheinvalidates = %d\n", cacheresets, cacheinvalidates); //OSD_Printf("cacheresets = %d, cacheinvalidates = %d\n", cacheresets, cacheinvalidates);
#if defined(POLYMOST) && defined(USE_OPENGL) #if defined(POLYMOST) && defined(USE_OPENGL)
texcacheindex *index;
polymost_glreset(); polymost_glreset();
hicinit(); hicinit();
freeallmodels(); freeallmodels();
@ -5792,15 +5790,6 @@ void uninitengine(void)
Bclose(cachefilehandle); Bclose(cachefilehandle);
if (cacheindexptr != NULL) if (cacheindexptr != NULL)
Bfclose(cacheindexptr); */ Bfclose(cacheindexptr); */
datextures = &firstcacheindex;
while (datextures->next)
{
index = datextures;
datextures = datextures->next;
if (index != &firstcacheindex)
Bfree(index);
}
#endif #endif
uninitsystem(); uninitsystem();
@ -12229,7 +12218,8 @@ void HASH_init(struct HASH_table *t)
{ {
HASH_free(t); HASH_free(t);
t->items=Bcalloc(1, t->size * sizeof(struct HASH_item)); t->items=Bcalloc(1, t->size * sizeof(struct HASH_item));
Bmemset(t->items,0,t->size * sizeof(struct HASH_item)); // memset commented because it's redundant with calloc
// Bmemset(t->items,0,t->size * sizeof(struct HASH_item));
} }
void HASH_free(struct HASH_table *t) void HASH_free(struct HASH_table *t)
@ -12238,7 +12228,8 @@ void HASH_free(struct HASH_table *t)
int i; int i;
int num; int num;
if (t->items==NULL)return; if (t->items == NULL)
return;
// initprintf("*free, num:%d\n",t->size); // initprintf("*free, num:%d\n",t->size);
i= t->size-1; i= t->size-1;
do do
@ -12255,7 +12246,7 @@ void HASH_free(struct HASH_table *t)
} }
// initprintf("#%4d: %3d\t",i,num); // initprintf("#%4d: %3d\t",i,num);
} }
while (--i>=0); while (--i > -1);
Bfree(t->items); Bfree(t->items);
t->items = 0; t->items = 0;
} }
@ -12277,8 +12268,13 @@ void HASH_add(struct HASH_table *t, const char *s, int key)
struct HASH_item *cur, *prev=NULL; struct HASH_item *cur, *prev=NULL;
int code; int code;
if (!s)return; if (!s)
if (t->items==NULL) {initprintf("HASH_add: not initalized\n");return;} return;
if (t->items == NULL)
{
initprintf("HASH_add: not initalized\n");
return;
}
code = HASH_getcode(s)%t->size; code = HASH_getcode(s)%t->size;
cur = t->items[code]; cur = t->items[code];
@ -12294,7 +12290,8 @@ void HASH_add(struct HASH_table *t, const char *s, int key)
do do
{ {
if (Bstrcmp(s,cur->string)==0)return; if (Bstrcmp(s,cur->string)==0)
return;
prev=cur; prev=cur;
cur=cur->next; cur=cur->next;
} }

View file

@ -574,7 +574,7 @@ int mdloadskin_trytexcache(char *fn, int len, int pal, char effect, texcachehead
} }
md4once((unsigned char *)fn, strlen(fn), mdsum); md4once((unsigned char *)fn, strlen(fn), mdsum);
// for (cp = cachefn, fp = 0; (*cp = TEXCACHEDIR[fp]); cp++,fp++); // for (cp = cachefn, fp = 0; (*cp = TEXCACHEFILE[fp]); cp++,fp++);
// *(cp++) = '/'; // *(cp++) = '/';
cp = cachefn; cp = cachefn;
for (fp = 0; fp < 16; phex(mdsum[fp++], cp), cp+=2); for (fp = 0; fp < 16; phex(mdsum[fp++], cp), cp+=2);
@ -1049,7 +1049,7 @@ static md2model *md2load(int fil, const char *filnam)
int i, j, k; int i, j, k;
m = (md2model *)calloc(1,sizeof(md2model)); if (!m) return(0); m = (md2model *)calloc(1,sizeof(md2model)); if (!m) return(0);
m->mdnum = 2; m->scale = .01; m->mdnum = 2; m->scale = .01f;
kread(fil,(char *)&head,sizeof(md2head_t)); kread(fil,(char *)&head,sizeof(md2head_t));
head.id = B_LITTLE32(head.id); head.vers = B_LITTLE32(head.vers); head.id = B_LITTLE32(head.id); head.vers = B_LITTLE32(head.vers);

View file

@ -330,7 +330,7 @@ FILE *cacheindexptr = NULL;
static struct HASH_table cacheH = { MAXTILES<<2, NULL }; static struct HASH_table cacheH = { MAXTILES<<2, NULL };
char TEXCACHEDIR[BMAX_PATH] = "textures"; char TEXCACHEFILE[BMAX_PATH] = "textures";
typedef struct typedef struct
{ {
@ -727,44 +727,18 @@ void polymost_glreset()
Bfclose(cacheindexptr); Bfclose(cacheindexptr);
cacheindexptr = NULL; cacheindexptr = NULL;
} }
datextures = &firstcacheindex;
numcacheentries = 0;
Bmemset(&cacheptrs[0],0,sizeof(cacheptrs));
HASH_init(&cacheH);
LoadCacheOffsets();
Bstrcpy(tempbuf,TEXCACHEDIR);
Bstrcat(tempbuf,".cache");
cacheindexptr = Bfopen(tempbuf, "at");
if (!cacheindexptr)
{ {
glusetexcache = 0; texcacheindex *index;
initprintf("Unable to open cache index!\n");
return;
}
cachefilehandle = Bopen(TEXCACHEDIR,BO_BINARY|BO_CREAT|BO_APPEND|BO_RDWR,BS_IREAD|BS_IWRITE); datextures = firstcacheindex.next;
while (datextures)
if (cachefilehandle < 0)
{ {
glusetexcache = 0; index = datextures;
initprintf("Unable to open cache file! %s\n",strerror(errno));
}
#if 0
i = 0;
datextures = &firstcacheindex;
while (datextures->next)
{
i += datextures->len;
datextures = datextures->next; datextures = datextures->next;
Bfree(index);
}
firstcacheindex.next = NULL;
} }
datextures = &firstcacheindex;
initprintf("Cache contains %d bytes of garbage data\n",Blseek(cachefilehandle, 0, BSEEK_END)-i);
Blseek(cachefilehandle, 0, BSEEK_SET);
#endif
} }
// one-time initialization of OpenGL for polymost // one-time initialization of OpenGL for polymost
@ -941,17 +915,18 @@ void polymost_glinit()
datextures = &firstcacheindex; datextures = &firstcacheindex;
numcacheentries = 0; numcacheentries = 0;
Bmemset(&firstcacheindex, 0, sizeof(texcacheindex));
Bmemset(&cacheptrs[0], 0, sizeof(cacheptrs)); Bmemset(&cacheptrs[0], 0, sizeof(cacheptrs));
HASH_init(&cacheH); HASH_init(&cacheH);
LoadCacheOffsets(); LoadCacheOffsets();
Bstrcpy(tempbuf,TEXCACHEDIR); Bstrcpy(tempbuf,TEXCACHEFILE);
Bstrcat(tempbuf,".cache"); Bstrcat(tempbuf,".cache");
cacheindexptr = Bfopen(tempbuf, "at"); cacheindexptr = Bfopen(tempbuf, "at");
if (!cacheindexptr) if (!cacheindexptr)
{ {
glusetexcache = 0; glusetexcache = 0;
initprintf("Unable to open cache index!\n"); initprintf("Unable to open cache index: %s\n",strerror(errno));
return; return;
} }
@ -959,15 +934,15 @@ void polymost_glinit()
if (!ftell(cacheindexptr)) if (!ftell(cacheindexptr))
{ {
rewind(cacheindexptr); rewind(cacheindexptr);
fprintf(cacheindexptr,"// this file automatically generated by EDuke32\n// DO NOT MODIFY\n"); fprintf(cacheindexptr,"// automatically generated by EDuke32, DO NOT MODIFY!\n");
} }
else rewind(cacheindexptr); else rewind(cacheindexptr);
cachefilehandle = Bopen(TEXCACHEDIR,BO_BINARY|BO_CREAT|BO_APPEND|BO_RDWR,BS_IREAD|BS_IWRITE); cachefilehandle = Bopen(TEXCACHEFILE,BO_BINARY|BO_CREAT|BO_APPEND|BO_RDWR,BS_IREAD|BS_IWRITE);
if (cachefilehandle < 0) if (cachefilehandle < 0)
{ {
initprintf("Unable to open cache file! %s\n",strerror(errno)); initprintf("Unable to open cache file: %s\n",strerror(errno));
glusetexcache = 0; glusetexcache = 0;
return; return;
} }
@ -988,7 +963,7 @@ void polymost_glinit()
void invalidatecache(void) void invalidatecache(void)
{ {
if (cachefilehandle > -1) if (cachefilehandle != -1)
{ {
Bclose(cachefilehandle); Bclose(cachefilehandle);
cachefilehandle = -1; cachefilehandle = -1;
@ -999,37 +974,45 @@ void invalidatecache(void)
Bfclose(cacheindexptr); Bfclose(cacheindexptr);
cacheindexptr = NULL; cacheindexptr = NULL;
} }
{
texcacheindex *index;
datextures = firstcacheindex.next;
while (datextures)
{
index = datextures;
datextures = datextures->next;
Bfree(index);
}
}
datextures = &firstcacheindex; datextures = &firstcacheindex;
numcacheentries = 0; numcacheentries = 0;
Bmemset(&firstcacheindex, 0, sizeof(texcacheindex));
Bmemset(&cacheptrs[0], 0, sizeof(cacheptrs)); Bmemset(&cacheptrs[0], 0, sizeof(cacheptrs));
HASH_init(&cacheH);
// LoadCacheOffsets();
Bstrcpy(tempbuf,TEXCACHEDIR); Bstrcpy(tempbuf,TEXCACHEFILE);
Bstrcat(tempbuf,".cache"); Bstrcat(tempbuf,".cache");
cacheindexptr = Bfopen(tempbuf, "wt"); cacheindexptr = Bfopen(tempbuf, "wt");
if (!cacheindexptr) if (!cacheindexptr)
{ {
glusetexcache = 0; glusetexcache = 0;
initprintf("Unable to open cache index!\n"); initprintf("Unable to open cache index: %s\n",strerror(errno));
return; return;
} }
fseek(cacheindexptr, 0, BSEEK_END); fprintf(cacheindexptr,"// automatically generated by EDuke32, DO NOT MODIFY!\n");
if (!ftell(cacheindexptr))
{
rewind(cacheindexptr);
fprintf(cacheindexptr,"// this file automatically generated by EDuke32\n// DO NOT MODIFY\n");
}
else rewind(cacheindexptr);
cachefilehandle = Bopen(TEXCACHEDIR,BO_BINARY|BO_CREAT|BO_TRUNC|BO_RDWR,BS_IREAD|BS_IWRITE); cachefilehandle = Bopen(TEXCACHEFILE,BO_BINARY|BO_TRUNC|BO_APPEND|BO_RDWR,BS_IREAD|BS_IWRITE);
if (cachefilehandle < 0) if (cachefilehandle < 0)
{ {
initprintf("Unable to open cache file: %s\n",strerror(errno));
glusetexcache = 0; glusetexcache = 0;
initprintf("Unable to open cache file! %s\n",strerror(errno)); return;
} }
HASH_init(&cacheH);
} }
void resizeglcheck() void resizeglcheck()
@ -1403,7 +1386,7 @@ static int LoadCacheOffsets(void)
scriptfile *script; scriptfile *script;
Bstrcpy(tempbuf,TEXCACHEDIR); Bstrcpy(tempbuf,TEXCACHEFILE);
Bstrcat(tempbuf,".cache"); Bstrcat(tempbuf,".cache");
script = scriptfile_fromfile(tempbuf); script = scriptfile_fromfile(tempbuf);
@ -1465,7 +1448,7 @@ int trytexcache(char *fn, int len, int dameth, char effect, texcacheheader *head
} }
md4once((unsigned char *)fn, strlen(fn), mdsum); md4once((unsigned char *)fn, strlen(fn), mdsum);
// for (cp = cachefn, fp = 0; (*cp = TEXCACHEDIR[fp]); cp++,fp++); // for (cp = cachefn, fp = 0; (*cp = TEXCACHEFILE[fp]); cp++,fp++);
// *(cp++) = '/'; // *(cp++) = '/';
cp = cachefn; cp = cachefn;
for (fp = 0; fp < 16; phex(mdsum[fp++], cp), cp+=2); for (fp = 0; fp < 16; phex(mdsum[fp++], cp), cp+=2);
@ -1479,21 +1462,6 @@ int trytexcache(char *fn, int len, int dameth, char effect, texcacheheader *head
int len = 0; int len = 0;
int i; int i;
// texcacheindex *cacheindexptr = &firstcacheindex;
/* do
{
// initprintf("checking %s against %s\n",cachefn,cacheindexptr->name);
if (!Bstrcmp(cachefn,cacheindexptr->name))
{
offset = cacheindexptr->offset;
len = cacheindexptr->len;
// initprintf("got a match for %s offset %d\n",cachefn,offset);
// break;
}
cacheindexptr = cacheindexptr->next;
}
while (cacheindexptr->next); */
i = HASH_find(&cacheH,cachefn); i = HASH_find(&cacheH,cachefn);
if (i != -1) if (i != -1)
{ {
@ -1504,7 +1472,11 @@ int trytexcache(char *fn, int len, int dameth, char effect, texcacheheader *head
} }
if (len == 0) return -1; // didn't find it if (len == 0) return -1; // didn't find it
Blseek(cachefilehandle, offset, BSEEK_SET); if (Blseek(cachefilehandle, offset, BSEEK_SET) == -1)
{
OSD_Printf("Cache seek error: %s\n",strerror(errno));
return -1;
}
} }
// initprintf("Loading cached tex: %s\n", cachefn); // initprintf("Loading cached tex: %s\n", cachefn);
@ -1555,18 +1527,18 @@ void writexcache(char *fn, int len, int dameth, char effect, texcacheheader *hea
/* /*
{ {
struct stat st; struct stat st;
if (stat(TEXCACHEDIR, &st) < 0) if (stat(TEXCACHEFILE, &st) < 0)
{ {
if (errno == ENOENT) // path doesn't exist if (errno == ENOENT) // path doesn't exist
{ {
// try to create the cache directory // try to create the cache directory
if (Bmkdir(TEXCACHEDIR, S_IRWXU) < 0) if (Bmkdir(TEXCACHEFILE, S_IRWXU) < 0)
{ {
OSD_Printf("Failed to create texture cache directory %s\n", TEXCACHEDIR); OSD_Printf("Failed to create texture cache directory %s\n", TEXCACHEFILE);
glusetexcache = 0; glusetexcache = 0;
return; return;
} }
else OSD_Printf("Created texture cache directory %s\n", TEXCACHEDIR); else OSD_Printf("Created texture cache directory %s\n", TEXCACHEFILE);
} }
else else
{ {
@ -1588,7 +1560,7 @@ void writexcache(char *fn, int len, int dameth, char effect, texcacheheader *hea
if (gi != GL_TRUE) return; if (gi != GL_TRUE) return;
md4once((unsigned char *)fn, strlen(fn), mdsum); md4once((unsigned char *)fn, strlen(fn), mdsum);
// for (cp = cachefn, fp = 0; (*cp = TEXCACHEDIR[fp]); cp++,fp++); // for (cp = cachefn, fp = 0; (*cp = TEXCACHEFILE[fp]); cp++,fp++);
// *(cp++) = '/'; // *(cp++) = '/';
cp = cachefn; cp = cachefn;
for (fp = 0; fp < 16; phex(mdsum[fp++], cp), cp+=2); for (fp = 0; fp < 16; phex(mdsum[fp++], cp), cp+=2);

View file

@ -7419,7 +7419,13 @@ static void G_CheckCommandLine(int argc, const char **argv)
{ {
if (argc > i+1) if (argc > i+1)
{ {
#if defined(POLYMOST) && defined(USE_OPENGL)
extern char TEXCACHEFILE[BMAX_PATH];
Bsprintf(tempbuf,"%s/%s",argv[i+1],TEXCACHEFILE);
Bstrcpy(TEXCACHEFILE,tempbuf);
#endif
AddGamePath(argv[i+1]); AddGamePath(argv[i+1]);
COPYARG(i); COPYARG(i);
COPYARG(i+1); COPYARG(i+1);
i++; i++;

View file

@ -117,7 +117,7 @@ static char *confilename = defaultconfilename;
char *duke3ddef = "duke3d.def"; char *duke3ddef = "duke3d.def";
char mod_dir[BMAX_PATH] = "/"; char mod_dir[BMAX_PATH] = "/";
#if defined(POLYMOST) #if defined(POLYMOST)
extern char TEXCACHEDIR[BMAX_PATH]; extern char TEXCACHEFILE[BMAX_PATH];
#endif #endif
extern int lastvisinc; extern int lastvisinc;
@ -11067,8 +11067,8 @@ void app_main(int argc,const char **argv)
addsearchpath(root); addsearchpath(root);
// addsearchpath(mod_dir); // addsearchpath(mod_dir);
#if defined(POLYMOST) && defined(USE_OPENGL) #if defined(POLYMOST) && defined(USE_OPENGL)
Bsprintf(tempbuf,"%s/%s",mod_dir,TEXCACHEDIR); Bsprintf(tempbuf,"%s/%s",mod_dir,TEXCACHEFILE);
Bstrcpy(TEXCACHEDIR,tempbuf); Bstrcpy(TEXCACHEFILE,tempbuf);
#endif #endif
} }

View file

@ -74,7 +74,7 @@ static int getfilenames(char *path)
#define POPULATE_GAMEDIRS 8 #define POPULATE_GAMEDIRS 8
#if defined(POLYMOST) #if defined(POLYMOST)
extern char TEXCACHEDIR[]; extern char TEXCACHEFILE[];
#endif #endif
extern int g_noSetup; extern int g_noSetup;
@ -193,7 +193,7 @@ static void PopulateForm(int pgs)
for (dirs=finddirs,i=1; dirs != NULL; dirs=dirs->next,i++) for (dirs=finddirs,i=1; dirs != NULL; dirs=dirs->next,i++)
{ {
#if defined(POLYMOST) && defined(USE_OPENGL) #if defined(POLYMOST) && defined(USE_OPENGL)
if (Bstrcasecmp(TEXCACHEDIR,dirs->name) == 0) continue; if (Bstrcasecmp(TEXCACHEFILE,dirs->name) == 0) continue;
#endif #endif
j = ComboBox_AddString(hwnd, dirs->name); j = ComboBox_AddString(hwnd, dirs->name);
(void)ComboBox_SetItemData(hwnd, j, i); (void)ComboBox_SetItemData(hwnd, j, i);