From d1266434f1763462c1c2dd49dbde1066abf69abd Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Wed, 4 May 2016 00:25:02 +0000 Subject: [PATCH] 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 --- polymer/eduke32/build/include/texcache.h | 5 +++-- polymer/eduke32/build/src/mdsprite.c | 6 ++++-- polymer/eduke32/build/src/polymost.c | 6 ++++-- polymer/eduke32/build/src/texcache.c | 20 +++++++++----------- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/polymer/eduke32/build/include/texcache.h b/polymer/eduke32/build/include/texcache.h index 1af849bcb..fb2e84853 100644 --- a/polymer/eduke32/build/include/texcache.h +++ b/polymer/eduke32/build/include/texcache.h @@ -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); diff --git a/polymer/eduke32/build/src/mdsprite.c b/polymer/eduke32/build/src/mdsprite.c index ce395da5c..2c1ed3144 100644 --- a/polymer/eduke32/build/src/mdsprite.c +++ b/polymer/eduke32/build/src/mdsprite.c @@ -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) { diff --git a/polymer/eduke32/build/src/polymost.c b/polymer/eduke32/build/src/polymost.c index d9169843a..c575a4a1e 100644 --- a/polymer/eduke32/build/src/polymost.c +++ b/polymer/eduke32/build/src/polymost.c @@ -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) { diff --git a/polymer/eduke32/build/src/texcache.c b/polymer/eduke32/build/src/texcache.c index f76697d76..77d64ce7d 100644 --- a/polymer/eduke32/build/src/texcache.c +++ b/polymer/eduke32/build/src/texcache.c @@ -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