mirror of
https://github.com/DrBeef/Raze.git
synced 2025-01-31 05:00:41 +00:00
Minor texcache cleanup. Nukes the hilarious MAXTILES<<1 sized array of pointers in the global texcache struct.
git-svn-id: https://svn.eduke32.com/eduke32@4666 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
0cf527914f
commit
5897c844d2
2 changed files with 31 additions and 21 deletions
|
@ -29,14 +29,14 @@ struct texcacheitem_t
|
||||||
typedef struct texcacheitem_t texcacheindex;
|
typedef struct texcacheitem_t texcacheindex;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t filehandle, filepos, numentries;
|
int32_t filehandle, filepos, numentries, iptrcnt;
|
||||||
FILE *index;
|
FILE *index;
|
||||||
pthtyp *list[GLTEXCACHEADSIZ];
|
pthtyp *list[GLTEXCACHEADSIZ];
|
||||||
texcacheindex *firstindex, *currentindex, *ptrs[MAXTILES<<1];
|
texcacheindex *firstindex, *currentindex, **iptrs;
|
||||||
hashtable_t hashes;
|
hashtable_t hashes;
|
||||||
struct {
|
struct {
|
||||||
uint8_t *ptr;
|
uint8_t *ptr;
|
||||||
size_t size;
|
int32_t size;
|
||||||
// Set to 1 when we failed (re)allocating space for the memcache or failing to
|
// Set to 1 when we failed (re)allocating space for the memcache or failing to
|
||||||
// read into it (which would presumably generate followup errors spamming the
|
// read into it (which would presumably generate followup errors spamming the
|
||||||
// log otherwise):
|
// log otherwise):
|
||||||
|
@ -51,7 +51,6 @@ extern char TEXCACHEFILE[BMAX_PATH];
|
||||||
extern void texcache_freeptrs(void);
|
extern void texcache_freeptrs(void);
|
||||||
extern void texcache_syncmemcache(void);
|
extern void texcache_syncmemcache(void);
|
||||||
extern void texcache_init(void);
|
extern void texcache_init(void);
|
||||||
extern void texcache_clearmemcache(void);
|
|
||||||
extern int32_t texcache_loadoffsets(void);
|
extern int32_t texcache_loadoffsets(void);
|
||||||
extern int32_t texcache_readdata(void *dest, int32_t len);
|
extern int32_t texcache_readdata(void *dest, int32_t len);
|
||||||
extern pthtyp *texcache_fetch(int32_t dapicnum, int32_t dapalnum, int32_t dashade, int32_t dameth);
|
extern pthtyp *texcache_fetch(int32_t dapicnum, int32_t dapalnum, int32_t dashade, int32_t dameth);
|
||||||
|
|
|
@ -185,20 +185,24 @@ void texcache_freeptrs(void)
|
||||||
{
|
{
|
||||||
int32_t i;
|
int32_t i;
|
||||||
|
|
||||||
|
if (texcache.iptrs)
|
||||||
for (i = 0; i < texcache.numentries; i++)
|
for (i = 0; i < texcache.numentries; i++)
|
||||||
if (texcache.ptrs[i])
|
if (texcache.iptrs[i])
|
||||||
{
|
{
|
||||||
int32_t ii;
|
int32_t ii;
|
||||||
for (ii = texcache.numentries-1; ii >= 0; ii--)
|
for (ii = texcache.numentries-1; ii >= 0; ii--)
|
||||||
if (i != ii && texcache.ptrs[ii] == texcache.ptrs[i])
|
if (i != ii && texcache.iptrs[ii] == texcache.iptrs[i])
|
||||||
{
|
{
|
||||||
/*OSD_Printf("removing duplicate cacheptr %d\n",ii);*/
|
/*OSD_Printf("removing duplicate cacheptr %d\n",ii);*/
|
||||||
texcache.ptrs[ii] = NULL;
|
texcache.iptrs[ii] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bfree(texcache.ptrs[i]);
|
Bfree(texcache.iptrs[i]);
|
||||||
texcache.ptrs[i] = NULL;
|
texcache.iptrs[i] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
texcache.iptrcnt = 0;
|
||||||
|
DO_FREE_AND_NULL(texcache.iptrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void texcache_clearmemcache(void)
|
static inline void texcache_clearmemcache(void)
|
||||||
|
@ -209,14 +213,11 @@ static inline void texcache_clearmemcache(void)
|
||||||
|
|
||||||
void texcache_syncmemcache(void)
|
void texcache_syncmemcache(void)
|
||||||
{
|
{
|
||||||
size_t len;
|
size_t len = Bfilelength(texcache.filehandle);
|
||||||
|
|
||||||
if (!texcache.memcache.ptr || texcache.filehandle == -1 ||
|
if (!texcache.memcache.ptr || texcache.filehandle == -1 || len <= (int32_t)texcache.memcache.size)
|
||||||
(bsize_t)Bfilelength(texcache.filehandle) <= texcache.memcache.size)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
len = Bfilelength(texcache.filehandle);
|
|
||||||
|
|
||||||
texcache.memcache.ptr = (uint8_t *)Brealloc(texcache.memcache.ptr, len);
|
texcache.memcache.ptr = (uint8_t *)Brealloc(texcache.memcache.ptr, len);
|
||||||
|
|
||||||
if (!texcache.memcache.ptr)
|
if (!texcache.memcache.ptr)
|
||||||
|
@ -374,7 +375,7 @@ int32_t texcache_loadoffsets(void)
|
||||||
if (i > -1)
|
if (i > -1)
|
||||||
{
|
{
|
||||||
// update an existing entry
|
// update an existing entry
|
||||||
texcacheindex *t = texcache.ptrs[i];
|
texcacheindex *t = texcache.iptrs[i];
|
||||||
t->offset = foffset;
|
t->offset = foffset;
|
||||||
t->len = fsize;
|
t->len = fsize;
|
||||||
/*initprintf("%s %d got a match for %s offset %d\n",__FILE__, __LINE__, fname,foffset);*/
|
/*initprintf("%s %d got a match for %s offset %d\n",__FILE__, __LINE__, fname,foffset);*/
|
||||||
|
@ -386,7 +387,12 @@ int32_t texcache_loadoffsets(void)
|
||||||
texcache.currentindex->len = fsize;
|
texcache.currentindex->len = fsize;
|
||||||
texcache.currentindex->next = (texcacheindex *)Xcalloc(1, sizeof(texcacheindex));
|
texcache.currentindex->next = (texcacheindex *)Xcalloc(1, sizeof(texcacheindex));
|
||||||
hash_add(&texcache.hashes, fname, texcache.numentries, 1);
|
hash_add(&texcache.hashes, fname, texcache.numentries, 1);
|
||||||
texcache.ptrs[texcache.numentries++] = texcache.currentindex;
|
if (++texcache.numentries > texcache.iptrcnt)
|
||||||
|
{
|
||||||
|
texcache.iptrcnt += 512;
|
||||||
|
texcache.iptrs = (texcacheindex **) Xrealloc(texcache.iptrs, sizeof(intptr_t) * texcache.iptrcnt);
|
||||||
|
}
|
||||||
|
texcache.iptrs[texcache.numentries-1] = texcache.currentindex;
|
||||||
texcache.currentindex = texcache.currentindex->next;
|
texcache.currentindex = texcache.currentindex->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -456,10 +462,10 @@ int32_t texcache_readtexheader(const char *fn, int32_t len, int32_t dameth, char
|
||||||
|
|
||||||
i = hash_find(&texcache.hashes, texcache_calcid(cachefn, fn, len, dameth, effect));
|
i = hash_find(&texcache.hashes, texcache_calcid(cachefn, fn, len, dameth, effect));
|
||||||
|
|
||||||
if (i < 0 || !texcache.ptrs[i])
|
if (i < 0 || !texcache.iptrs[i])
|
||||||
return 0; // didn't find it
|
return 0; // didn't find it
|
||||||
|
|
||||||
texcache.filepos = texcache.ptrs[i]->offset;
|
texcache.filepos = texcache.iptrs[i]->offset;
|
||||||
// initprintf("%s %d got a match for %s offset %d\n",__FILE__, __LINE__, cachefn,offset);
|
// initprintf("%s %d got a match for %s offset %d\n",__FILE__, __LINE__, cachefn,offset);
|
||||||
|
|
||||||
if (texcache_readdata(head, sizeof(texcacheheader)))
|
if (texcache_readdata(head, sizeof(texcacheheader)))
|
||||||
|
@ -587,7 +593,7 @@ void texcache_writetex(const char *fn, int32_t len, int32_t dameth, char effect,
|
||||||
{
|
{
|
||||||
pic = (char *)Xrealloc(pic, miplen);
|
pic = (char *)Xrealloc(pic, miplen);
|
||||||
alloclen = miplen;
|
alloclen = miplen;
|
||||||
packbuf = (char *)Xrealloc(packbuf, alloclen+400);
|
packbuf = (char *)Xrealloc(packbuf, alloclen);
|
||||||
midbuf = (void *)Xrealloc(midbuf, miplen);
|
midbuf = (void *)Xrealloc(midbuf, miplen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -603,7 +609,7 @@ void texcache_writetex(const char *fn, int32_t len, int32_t dameth, char effect,
|
||||||
if (i > -1)
|
if (i > -1)
|
||||||
{
|
{
|
||||||
// update an existing entry
|
// update an existing entry
|
||||||
t = texcache.ptrs[i];
|
t = texcache.iptrs[i];
|
||||||
t->offset = offset;
|
t->offset = offset;
|
||||||
t->len = Blseek(texcache.filehandle, 0, BSEEK_CUR) - t->offset;
|
t->len = Blseek(texcache.filehandle, 0, BSEEK_CUR) - t->offset;
|
||||||
/*initprintf("%s %d got a match for %s offset %d\n",__FILE__, __LINE__, cachefn,offset);*/
|
/*initprintf("%s %d got a match for %s offset %d\n",__FILE__, __LINE__, cachefn,offset);*/
|
||||||
|
@ -617,7 +623,12 @@ void texcache_writetex(const char *fn, int32_t len, int32_t dameth, char effect,
|
||||||
t->next = (texcacheindex *)Xcalloc(1, sizeof(texcacheindex));
|
t->next = (texcacheindex *)Xcalloc(1, sizeof(texcacheindex));
|
||||||
|
|
||||||
hash_add(&texcache.hashes, cachefn, texcache.numentries, 0);
|
hash_add(&texcache.hashes, cachefn, texcache.numentries, 0);
|
||||||
texcache.ptrs[texcache.numentries++] = t;
|
if (++texcache.numentries > texcache.iptrcnt)
|
||||||
|
{
|
||||||
|
texcache.iptrcnt += 512;
|
||||||
|
texcache.iptrs = (texcacheindex **) Xrealloc(texcache.iptrs, sizeof(intptr_t) * texcache.iptrcnt);
|
||||||
|
}
|
||||||
|
texcache.iptrs[texcache.numentries-1] = t;
|
||||||
texcache.currentindex = t->next;
|
texcache.currentindex = t->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue