From cb02cdc571106181efe04d7761cb6f4e9bb9cdb8 Mon Sep 17 00:00:00 2001 From: terminx Date: Tue, 30 Sep 2014 04:17:53 +0000 Subject: [PATCH] Re-use temporary buffer for tilefromtexture true color -> paletted conversion and free when finished with the .def instead of freeing and re-allocating for every tile git-svn-id: https://svn.eduke32.com/eduke32@4637 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/src/cache1d.c | 9 ++++--- polymer/eduke32/build/src/defs.c | 39 ++++++++++++++++++----------- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/polymer/eduke32/build/src/cache1d.c b/polymer/eduke32/build/src/cache1d.c index e8b59d743..0b2b1d36f 100644 --- a/polymer/eduke32/build/src/cache1d.c +++ b/polymer/eduke32/build/src/cache1d.c @@ -39,6 +39,9 @@ #ifdef WITHKPLIB #include "kplib.h" +char *kpzbuf = NULL; +int32_t kpzbufsiz = 0; + //Insert '|' in front of filename //Doing this tells kzopen to load the file only if inside a .ZIP file static intptr_t kzipopen(const char *filnam) @@ -96,7 +99,7 @@ int32_t cacnum = 0; cactype cac[MAXCACHEOBJECTS]; #endif -static char toupperlookup[256] = +char toupperlookup[256] = { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f, 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f, @@ -647,10 +650,8 @@ int32_t initgroupfile(const char *filename) char *zfn; #endif -#ifdef _WIN32 - // on Windows, translate all backslashes (0x5c) to forward slashes (0x2f) + // translate all backslashes (0x5c) to forward slashes (0x2f) toupperlookup[0x5c] = 0x2f; -#endif #ifdef WITHKPLIB if (findfrompath(filename, &zfn) < 0) return -1; diff --git a/polymer/eduke32/build/src/defs.c b/polymer/eduke32/build/src/defs.c index cbf8cb4f4..2be14bb68 100644 --- a/polymer/eduke32/build/src/defs.c +++ b/polymer/eduke32/build/src/defs.c @@ -95,6 +95,8 @@ enum scripttoken_t static int32_t lastmodelid = -1, lastvoxid = -1, modelskin = -1, lastmodelskin = -1, seenframe = 0; static int32_t nextvoxid = 0; +static char *faketilebuffer = NULL; +static int32_t faketilebuffersiz = 0; #ifdef USE_OPENGL extern float alphahackarray[MAXTILES]; @@ -171,26 +173,31 @@ static int32_t check_tile(const char *defcmd, int32_t tile, const scriptfile *sc static void tile_from_truecolpic(int32_t tile, const palette_t *picptr, int32_t alphacut) { - const int32_t xsiz = tilesiz[tile].x, ysiz = tilesiz[tile].y; - int32_t i, j; + const vec2_t siz = tilesiz[tile]; + int32_t i, j, tsiz = siz.x * siz.y; - char *ftd = (char *)Xmalloc(xsiz*ysiz); - - faketiledata[tile] = (char *)Xmalloc(xsiz*ysiz + 400); - - for (i=xsiz-1; i>=0; i--) + if (tsiz > faketilebuffersiz) { - for (j=ysiz-1; j>=0; j--) + faketilebuffer = (char *) Xrealloc(faketilebuffer, tsiz); + faketilebuffersiz = tsiz; + } + + faketiledata[tile] = (char *)Xmalloc(tsiz + 32); + + for (i=siz.x-1; i>=0; i--) + { + uint32_t ofs = i * siz.y; + + for (j=siz.y-1; j>=0; j--) { - const palette_t *col = &picptr[j*xsiz+i]; - if (col->f < alphacut) { ftd[i*ysiz+j] = 255; continue; } - ftd[i*ysiz+j] = getclosestcol(col->b>>2,col->g>>2,col->r>>2); + const palette_t *col = &picptr[j*siz.x+i]; + if (col->f < alphacut) { faketilebuffer[ofs+j] = 255; continue; } + faketilebuffer[ofs+j] = getclosestcol(col->b>>2, col->g>>2, col->r>>2); } // initprintf(" %d %d %d %d\n",col->r,col->g,col->b,col->f); } - faketilesiz[tile] = LZ4_compress(ftd, faketiledata[tile], xsiz*ysiz); - Bfree(ftd); + faketilesiz[tile] = LZ4_compress(faketilebuffer, faketiledata[tile], tsiz); } #undef USE_DEF_PROGRESS @@ -277,6 +284,7 @@ static int32_t defsparser(scriptfile *script) iter = 0; } #endif + handleevents(); if (quitevent) return 0; tokn = getatoken(script,basetokens,ARRAY_SIZE(basetokens)); cmdtokptr = script->ltextptr; @@ -1586,7 +1594,7 @@ static int32_t defsparser(scriptfile *script) break; } - i = kprender(filebuf, filesize, (intptr_t)highpaldata, xsiz*sizeof(coltype), xsiz, ysiz, 0, 0); + i = kprender(filebuf, filesize, (intptr_t)highpaldata, xsiz*sizeof(coltype), xsiz, ysiz); Bfree(filebuf); if (i) { Bfree(highpaldata); initprintf("Error: failed rendering \"%s\".\n", fn); break; } @@ -2167,6 +2175,9 @@ int32_t loaddefinitionsfile(const char *fn) scriptfile_clearsymbols(); + DO_FREE_AND_NULL(faketilebuffer); + faketilebuffersiz = 0; + if (!script) return -1; initprintf("\n");