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
This commit is contained in:
terminx 2014-09-30 04:17:53 +00:00
parent ff74aa613e
commit cb02cdc571
2 changed files with 30 additions and 18 deletions

View file

@ -39,6 +39,9 @@
#ifdef WITHKPLIB #ifdef WITHKPLIB
#include "kplib.h" #include "kplib.h"
char *kpzbuf = NULL;
int32_t kpzbufsiz = 0;
//Insert '|' in front of filename //Insert '|' in front of filename
//Doing this tells kzopen to load the file only if inside a .ZIP file //Doing this tells kzopen to load the file only if inside a .ZIP file
static intptr_t kzipopen(const char *filnam) static intptr_t kzipopen(const char *filnam)
@ -96,7 +99,7 @@ int32_t cacnum = 0;
cactype cac[MAXCACHEOBJECTS]; cactype cac[MAXCACHEOBJECTS];
#endif #endif
static char toupperlookup[256] = char toupperlookup[256] =
{ {
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f, 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, 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; char *zfn;
#endif #endif
#ifdef _WIN32 // translate all backslashes (0x5c) to forward slashes (0x2f)
// on Windows, translate all backslashes (0x5c) to forward slashes (0x2f)
toupperlookup[0x5c] = 0x2f; toupperlookup[0x5c] = 0x2f;
#endif
#ifdef WITHKPLIB #ifdef WITHKPLIB
if (findfrompath(filename, &zfn) < 0) return -1; if (findfrompath(filename, &zfn) < 0) return -1;

View file

@ -95,6 +95,8 @@ enum scripttoken_t
static int32_t lastmodelid = -1, lastvoxid = -1, modelskin = -1, lastmodelskin = -1, seenframe = 0; static int32_t lastmodelid = -1, lastvoxid = -1, modelskin = -1, lastmodelskin = -1, seenframe = 0;
static int32_t nextvoxid = 0; static int32_t nextvoxid = 0;
static char *faketilebuffer = NULL;
static int32_t faketilebuffersiz = 0;
#ifdef USE_OPENGL #ifdef USE_OPENGL
extern float alphahackarray[MAXTILES]; 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) 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; const vec2_t siz = tilesiz[tile];
int32_t i, j; int32_t i, j, tsiz = siz.x * siz.y;
char *ftd = (char *)Xmalloc(xsiz*ysiz); if (tsiz > faketilebuffersiz)
faketiledata[tile] = (char *)Xmalloc(xsiz*ysiz + 400);
for (i=xsiz-1; i>=0; i--)
{ {
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--)
{ {
const palette_t *col = &picptr[j*xsiz+i]; uint32_t ofs = i * siz.y;
if (col->f < alphacut) { ftd[i*ysiz+j] = 255; continue; }
ftd[i*ysiz+j] = getclosestcol(col->b>>2,col->g>>2,col->r>>2); for (j=siz.y-1; j>=0; j--)
{
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); // initprintf(" %d %d %d %d\n",col->r,col->g,col->b,col->f);
} }
faketilesiz[tile] = LZ4_compress(ftd, faketiledata[tile], xsiz*ysiz); faketilesiz[tile] = LZ4_compress(faketilebuffer, faketiledata[tile], tsiz);
Bfree(ftd);
} }
#undef USE_DEF_PROGRESS #undef USE_DEF_PROGRESS
@ -277,6 +284,7 @@ static int32_t defsparser(scriptfile *script)
iter = 0; iter = 0;
} }
#endif #endif
handleevents();
if (quitevent) return 0; if (quitevent) return 0;
tokn = getatoken(script,basetokens,ARRAY_SIZE(basetokens)); tokn = getatoken(script,basetokens,ARRAY_SIZE(basetokens));
cmdtokptr = script->ltextptr; cmdtokptr = script->ltextptr;
@ -1586,7 +1594,7 @@ static int32_t defsparser(scriptfile *script)
break; 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); Bfree(filebuf);
if (i) if (i)
{ Bfree(highpaldata); initprintf("Error: failed rendering \"%s\".\n", fn); break; } { Bfree(highpaldata); initprintf("Error: failed rendering \"%s\".\n", fn); break; }
@ -2167,6 +2175,9 @@ int32_t loaddefinitionsfile(const char *fn)
scriptfile_clearsymbols(); scriptfile_clearsymbols();
DO_FREE_AND_NULL(faketilebuffer);
faketilebuffersiz = 0;
if (!script) return -1; if (!script) return -1;
initprintf("\n"); initprintf("\n");