Polymost: Call texcache_calcid once per texture instead of twice. Clean it up a little while we're at it.

git-svn-id: https://svn.eduke32.com/eduke32@5709 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2016-05-04 00:25:02 +00:00
parent 9db5f7e44f
commit d1266434f1
4 changed files with 20 additions and 17 deletions

View file

@ -60,8 +60,9 @@ 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 int32_t texcache_loadskin(const texcacheheader *head, int32_t *doalloc, GLuint *glpic, vec2_t *siz);
extern int32_t texcache_loadtile(const texcacheheader *head, int32_t *doalloc, pthtyp *pth);
extern void texcache_writetex(const char *fn, int32_t len, int32_t dameth, char effect, texcacheheader *head);
extern int32_t texcache_readtexheader(const char *fn, int32_t len, int32_t dameth, char effect, texcacheheader *head, int32_t modelp);
extern char const * texcache_calcid(char *cachefn, const char *fn, const int32_t len, const int32_t dameth, const char effect);
extern void texcache_writetex(char const * cachefn, texcacheheader *head);
extern int32_t texcache_readtexheader(char const * cachefn, texcacheheader *head, int32_t modelp);
extern void texcache_openfiles(void);
extern void texcache_setupmemcache(void);
extern void texcache_checkgarbage(void);

View file

@ -701,7 +701,9 @@ int32_t mdloadskin(md2model_t *m, int32_t number, int32_t pal, int32_t surf)
char hasalpha;
texcacheheader cachead;
int32_t gotcache = texcache_readtexheader(fn, picfillen, pal<<8, hicfxmask(pal), &cachead, 1);
char texcacheid[BMAX_PATH];
texcache_calcid(texcacheid, fn, picfillen, pal<<8, hicfxmask(pal));
int32_t gotcache = texcache_readtexheader(texcacheid, &cachead, 1);
vec2_t siz = { 0, 0 }, tsiz = { 0, 0 };
if (gotcache && !texcache_loadskin(&cachead, &doalloc, texidx, &siz))
@ -975,7 +977,7 @@ int32_t mdloadskin(md2model_t *m, int32_t number, int32_t pal, int32_t surf)
(sk->flags & (HICR_NODOWNSIZE|HICR_ARTIMMUNITY) ? CACHEAD_NODOWNSIZE : 0);
/// OSD_Printf("Caching \"%s\"\n",fn);
texcache_writetex(fn, picfillen, pal<<8, hicfxmask(pal), &cachead);
texcache_writetex(texcacheid, &cachead);
if (willprint)
{

View file

@ -1268,7 +1268,9 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp
char hasalpha;
texcacheheader cachead;
int32_t gotcache = texcache_readtexheader(fn, picfillen+(dapalnum<<8), dameth, effect, &cachead, 0);
char texcacheid[BMAX_PATH];
texcache_calcid(texcacheid, fn, picfillen+(dapalnum<<8), DAMETH_NARROW_MASKPROPS(dameth), effect);
int32_t gotcache = texcache_readtexheader(texcacheid, &cachead, 0);
vec2_t siz = { 0, 0 }, tsiz = { 0, 0 };
if (gotcache && !texcache_loadtile(&cachead, &doalloc, pth))
@ -1531,7 +1533,7 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp
(hicr->flags & (HICR_NODOWNSIZE|HICR_ARTIMMUNITY) ? CACHEAD_NODOWNSIZE : 0);
/// OSD_Printf("Caching \"%s\"\n", fn);
texcache_writetex(fn, picfillen + (dapalnum << 8), dameth, effect, &cachead);
texcache_writetex(texcacheid, &cachead);
if (willprint)
{

View file

@ -433,7 +433,7 @@ int32_t texcache_readdata(void *dest, int32_t len)
return 0;
}
static const char * texcache_calcid(char *cachefn, const char *fn, const int32_t len, const int32_t dameth, const char effect)
char const * texcache_calcid(char *cachefn, const char *fn, const int32_t len, const int32_t dameth, const char effect)
{
// Assert that BMAX_PATH is a multiple of 4 so that struct texcacheid_t
// gets no padding inserted by the compiler.
@ -442,15 +442,16 @@ static const char * texcache_calcid(char *cachefn, const char *fn, const int32_t
struct texcacheid_t {
int32_t len, method;
char effect, name[BMAX_PATH+3]; // +3: pad to a multiple of 4
} id = { len, DAMETH_NARROW_MASKPROPS(dameth), effect, "" };
} id = { len, dameth, effect, "" };
Bstrcpy(id.name, fn);
while (Bstrlen(id.name) < BMAX_PATH - Bstrlen(fn))
size_t const fnlen = Bstrlen(fn);
while (Bstrlen(id.name) < BMAX_PATH - fnlen)
Bstrcat(id.name, fn);
Bsprintf(cachefn, "%08x%08x%08x",
XXH32((uint8_t const *)fn, Bstrlen(fn), TEXCACHEMAGIC[3]),
XXH32((uint8_t *)id.name, fnlen, TEXCACHEMAGIC[3]),
XXH32((uint8_t *)id.name, Bstrlen(id.name), TEXCACHEMAGIC[3]),
XXH32((uint8_t *)&id, sizeof(struct texcacheid_t), TEXCACHEMAGIC[3]));
@ -460,16 +461,14 @@ static const char * texcache_calcid(char *cachefn, const char *fn, const int32_t
#define READTEXHEADER_FAILURE(x) { err = x; goto failure; }
// returns 1 on success
int32_t texcache_readtexheader(const char *fn, int32_t len, int32_t dameth, char effect,
texcacheheader *head, int32_t modelp)
int32_t texcache_readtexheader(char const * const cachefn, texcacheheader *head, int32_t modelp)
{
int32_t i, err = 0;
char cachefn[BMAX_PATH];
if (!texcache_enabled())
return 0;
i = hash_find(&texcache.hashes, texcache_calcid(cachefn, fn, len, dameth, effect));
i = hash_find(&texcache.hashes, cachefn);
if (i < 0 || !texcache.iptrs[i])
return 0; // didn't find it
@ -528,9 +527,8 @@ failure:
#undef READTEXHEADER_FAILURE
#define WRITEX_FAIL_ON_ERROR() if (bglGetError() != GL_NO_ERROR) goto failure
void texcache_writetex(const char *fn, int32_t len, int32_t dameth, char effect, texcacheheader *head)
void texcache_writetex(char const * const cachefn, texcacheheader *head)
{
char cachefn[BMAX_PATH];
char *pic = NULL, *packbuf = NULL;
void *midbuf = NULL;
uint32_t alloclen=0;
@ -631,7 +629,7 @@ void texcache_writetex(const char *fn, int32_t len, int32_t dameth, char effect,
{
texcacheindex *t;
int32_t i = hash_find(&texcache.hashes, texcache_calcid(cachefn, fn, len, dameth, effect));
int32_t i = hash_find(&texcache.hashes, cachefn);
if (i > -1)
{
// update an existing entry