Make mapster32 know r_downsize parameter. For best caching performance, this and glusetexcache should be the same as for the game. Highpalookup script can now generate maps equivalent to the current PHRP tint defs.

git-svn-id: https://svn.eduke32.com/eduke32@1754 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2011-01-09 18:53:06 +00:00
parent 69feee634b
commit e66bec5e31
5 changed files with 175 additions and 88 deletions

View file

@ -172,6 +172,12 @@ int32_t loadsetup(const char *fn)
{
glanisotropy = Batoi(val);
}
if (readconfig(fp, "r_downsize", val, VL) > 0)
{
r_downsize = Batoi(val);
r_downsize = clamp(r_downsize, 0, 5);
r_downsizevar = r_downsize;
}
#endif
if (readconfig(fp, "gameexecutable", val, VL) > 0)
@ -339,9 +345,11 @@ int32_t writesetup(const char *fn)
"; OpenGL mode options\n"
"usemodels = %d\n"
"usehightile = %d\n"
"; glusetexcache: 0:no, 1:yes, 2:compressed\n"
"glusetexcache = %d\n"
"gltexfiltermode = %d\n"
"glanisotropy = %d\n"
"r_downsize = %d\n"
"\n"
#endif
@ -500,7 +508,7 @@ int32_t writesetup(const char *fn)
editorgridextent, min(max(0, default_grid), 9),
#if defined(POLYMOST) && defined(USE_OPENGL)
usemodels, usehightile,
glusetexcache, gltexfiltermode, glanisotropy,
glusetexcache, gltexfiltermode, glanisotropy,r_downsize,
#endif
#ifdef RENDERTYPEWIN
maxrefreshfreq, windowpos, windowx, windowy,

View file

@ -500,13 +500,14 @@ static int32_t daskinloader(int32_t filh, intptr_t *fptr, int32_t *bpl, int32_t
*bpl = xsiz;
*fptr = (intptr_t)pic;
*hasalpha = (al != 255);
return 0;
}
// JONOF'S COMPRESSED TEXTURE CACHE STUFF ---------------------------------------------------
int32_t mdloadskin_trytexcache(char *fn, int32_t len, int32_t pal, char effect, texcacheheader *head)
{
int32_t fp;
int32_t fp, err=0;
char cachefn[BMAX_PATH], *cp;
uint8_t mdsum[16];
@ -576,28 +577,29 @@ int32_t mdloadskin_trytexcache(char *fn, int32_t len, int32_t pal, char effect,
if (Bread(cachefilehandle, head, sizeof(texcacheheader)) < (int32_t)sizeof(texcacheheader))
{
cachepos += sizeof(texcacheheader);
err = 1;
goto failure;
}
cachepos += sizeof(texcacheheader);
}
if (memcmp(head->magic, TEXCACHEMAGIC, 4)) goto failure;
if (memcmp(head->magic, TEXCACHEMAGIC, 4)) { err=2; goto failure; }
head->xdim = B_LITTLE32(head->xdim);
head->ydim = B_LITTLE32(head->ydim);
head->flags = B_LITTLE32(head->flags);
head->quality = B_LITTLE32(head->quality);
if (head->quality != r_downsize) goto failure;
if ((head->flags & 4) && glusetexcache != 2) goto failure;
if (!(head->flags & 4) && glusetexcache == 2) goto failure;
if (gltexmaxsize && (head->xdim > (1<<gltexmaxsize) || head->ydim > (1<<gltexmaxsize))) goto failure;
if (!glinfo.texnpot && (head->flags & 1)) goto failure;
if (head->quality != r_downsize) { err=3; goto failure; }
if ((head->flags & 4) && glusetexcache != 2) { err=4; goto failure; }
if (!(head->flags & 4) && glusetexcache == 2) { err=5; goto failure; }
if (gltexmaxsize && (head->xdim > (1<<gltexmaxsize) || head->ydim > (1<<gltexmaxsize))) { err=6; goto failure; }
if (!glinfo.texnpot && (head->flags & 1)) { err=7; goto failure; }
return cachefilehandle;
failure:
// kclose(fil);
initprintf("cache miss\n");
initprintf("skin cache miss: %d\n", err);
return -1;
}
@ -681,6 +683,8 @@ int32_t mdloadskin(md2model_t *m, int32_t number, int32_t pal, int32_t surf)
int32_t cachefil = -1, picfillen;
texcacheheader cachead;
int32_t startticks, willprint=0;
modelhead=m; // for palmaps
if (m->mdnum == 2) surf = 0;
@ -754,6 +758,8 @@ int32_t mdloadskin(md2model_t *m, int32_t number, int32_t pal, int32_t surf)
picfillen = kfilelength(filh);
kclose(filh); // FIXME: shouldn't have to do this. bug in cache1d.c
startticks = getticks();
cachefil = mdloadskin_trytexcache(fn, picfillen, pal<<8, (globalnoeffect)?0:(hictinting[pal].f&HICEFFECTMASK), &cachead);
if (cachefil >= 0 && !mdloadskin_cached(cachefil, &cachead, &doalloc, texidx, &xsiz, &ysiz, pal))
{
@ -779,6 +785,9 @@ int32_t mdloadskin(md2model_t *m, int32_t number, int32_t pal, int32_t surf)
return(0);
}
else kclose(filh);
willprint = 1;
if (pal < (MAXPALOOKUPS - RESERVEDPALS)) m->usesalpha = hasalpha;
if ((doalloc&3)==1) bglGenTextures(1,(GLuint*)texidx);
bglBindTexture(GL_TEXTURE_2D,*texidx);
@ -849,10 +858,21 @@ int32_t mdloadskin(md2model_t *m, int32_t number, int32_t pal, int32_t surf)
if (ysiz == pow2long[j]) { i |= 2; }
}
cachead.flags = (i!=3) | (hasalpha ? 2 : 0);
OSD_Printf("Caching \"%s\"\n",fn);
/// OSD_Printf("Caching \"%s\"\n",fn);
writexcache(fn, picfillen, pal<<8, (globalnoeffect)?0:(hictinting[pal].f&HICEFFECTMASK), &cachead);
if (willprint)
{
OSD_Printf("Load skin: p%d-e%d \"%s\"... cached... %d ms\n", pal, (globalnoeffect)?0:(hictinting[pal].f&HICEFFECTMASK), fn, getticks()-startticks);
willprint = 0;
}
else
OSD_Printf("Cached skin \"%s\"\n", fn);
}
if (willprint)
OSD_Printf("Load skin: p%d-e%d \"%s\"... %d ms\n", pal, (globalnoeffect)?0:(hictinting[pal].f&HICEFFECTMASK), fn, getticks()-startticks);
return(*texidx);
}

View file

@ -1307,7 +1307,7 @@ void phex(char v, char *s)
int32_t trytexcache(char *fn, int32_t len, int32_t dameth, char effect, texcacheheader *head)
{
int32_t fp;
int32_t fp, err=0;
char cachefn[BMAX_PATH], *cp;
uint8_t mdsum[16];
@ -1366,27 +1366,28 @@ int32_t trytexcache(char *fn, int32_t len, int32_t dameth, char effect, texcache
if (Bread(cachefilehandle, head, sizeof(texcacheheader)) < (int32_t)sizeof(texcacheheader))
{
cachepos += sizeof(texcacheheader);
err = 1;
goto failure;
}
cachepos += sizeof(texcacheheader);
}
if (Bmemcmp(head->magic, TEXCACHEMAGIC, 4)) goto failure;
if (Bmemcmp(head->magic, TEXCACHEMAGIC, 4)) { err=2; goto failure; }
head->xdim = B_LITTLE32(head->xdim);
head->ydim = B_LITTLE32(head->ydim);
head->flags = B_LITTLE32(head->flags);
head->quality = B_LITTLE32(head->quality);
if ((head->flags & 4) && glusetexcache != 2) goto failure;
if (!(head->flags & 4) && glusetexcache == 2) goto failure;
if ((head->flags & 4) && glusetexcache != 2) { err=3; goto failure; }
if (!(head->flags & 4) && glusetexcache == 2) { err=4; goto failure; }
if (!(head->flags & 8) && head->quality != r_downsize) return -1; // handle nocompress
if (gltexmaxsize && (head->xdim > (1<<gltexmaxsize) || head->ydim > (1<<gltexmaxsize))) goto failure;
if (!glinfo.texnpot && (head->flags & 1)) goto failure;
if (gltexmaxsize && (head->xdim > (1<<gltexmaxsize) || head->ydim > (1<<gltexmaxsize))) { err=5; goto failure; }
if (!glinfo.texnpot && (head->flags & 1)) { err=6; goto failure; }
return cachefilehandle;
failure:
initprintf("cache miss\n");
initprintf("cache miss: %d\n", err);
return -1;
}
@ -1636,6 +1637,7 @@ failure:
return -1;
}
// --------------------------------------------------- JONOF'S COMPRESSED TEXTURE CACHE STUFF
//static
int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp *hicr, int32_t dameth, pthtyp *pth, int32_t doalloc, char effect)
{
coltype *pic = NULL, *rpptr;
@ -1652,6 +1654,8 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp
static char *lastfn = NULL;
static int32_t lastsize = 0;
int32_t startticks, didprint=0;
if (!hicr) return -1;
if (facen > 0)
{
@ -1716,15 +1720,19 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp
}
pic = (coltype *)Bcalloc(xsiz,ysiz*sizeof(coltype)); if (!pic) { Bfree(picfil); return 1; }
startticks = getticks();
if (lastpic && lastfn && !Bstrcmp(lastfn,fn))
{
// if (hicprecaching) OSD_Printf("use %4d: p%-3d m%d e%d\n", dapic, dapalnum, dameth, effect);
OSD_Printf("Load tile %4d: p%d-m%d-e%d", dapic, dapalnum, dameth, effect);
didprint=1;
Bmemcpy(pic, lastpic, xsiz*ysiz*sizeof(coltype));
}
else
{
// if (hicprecaching) OSD_Printf("rend %4d: p%-3d m%d e%d: `%s'\n", dapic, dapalnum, dameth, effect, fn);
if (kprender(picfil,picfillen,(intptr_t)pic,xsiz*sizeof(coltype),xsiz,ysiz,0,0)) { Bfree(picfil); Bfree(pic); return -2; }
OSD_Printf("Load tile %4d: p%d-m%d-e%d \"%s\"", dapic, dapalnum, dameth, effect, fn);
didprint=1;
if (hicprecaching)
{
@ -1889,10 +1897,21 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp
if (ysiz == pow2long[j]) { x |= 2; }
}
cachead.flags = (x!=3) | (hasalpha != 255 ? 2 : 0) | (hicr->flags & 16?8:0); // handle nocompress
OSD_Printf("Caching \"%s\"\n", fn);
/// OSD_Printf("Caching \"%s\"\n", fn);
writexcache(fn, picfillen+(dapalnum<<8), dameth, effect, &cachead);
if (didprint)
{
OSD_Printf("... cached... %d ms\n", getticks()-startticks);
didprint = 0;
}
else
OSD_Printf("Cached \"%s\"\n", fn);
}
if (didprint)
OSD_Printf("... %d ms\n", getticks()-startticks);
return 0;
}

View file

@ -2,7 +2,7 @@
import sys;
from numpy import array, zeros, ones, arange
from numpy import array, zeros, ones, arange, uint32
from numpy import vstack, hstack, hsplit, dstack, dsplit
from PIL.Image import frombuffer
@ -66,7 +66,8 @@ def showpalimg(im):
## port of Octave's rbg2hsv
def rgb2hsv(im):
im = imitof(im);
if (im.dtype=='uint8'):
im = imitof(im);
r, g, b = im[..., 0], im[..., 1], im[..., 2];
s, v = im.min(2), im.max(2);
@ -117,11 +118,16 @@ def hsv2rgb(imh):
def imftoi(im):
im = im.copy();
if (im.dtype=='uint8'):
return im
im *= CONVFACT;
im[im>255] = 255;
return im.astype('uint8');
def imitof(im):
if (im.dtype=='float32'):
return im.copy();
return im.astype('float32')/CONVFACT;
@ -144,13 +150,54 @@ BASEPALHSV should the precomputed HSV representation of BASEPAL."
# all true mask will be used unless overridden
mask = ones(h.shape, 'bool');
# plagman:
if (pal==1):
h[:] = 0.66;
elif (pal==6):
h[:] = 0.33;
v = 1.0 - v;
## PHRP r176 defs:
#
# tint { pal 1 red 100 green 120 blue 148 flags 1 }
# tint { pal 2 red 255 green 48 blue 0 flags 0 }
# tint { pal 4 red 0 green 0 blue 0 flags 0 }
# tint { pal 6 red 224 green 255 blue 112 flags 3 }
# tint { pal 7 red 172 green 157 blue 140 flags 0 }
# tint { pal 8 red 199 green 226 blue 113 flags 1 }
#
# bit 1: greyscale (max)
# bit 2: invert (255-x)
# colorization: min(int(C*C')/64, 255)
if (pal in [1,2,4,6,7,8]):
rgbf = { 1: [100, 120, 148, 1],
2: [255, 48, 0, 0],
4: [0, 0, 0, 0],
6: [224, 255, 112, 3],
7: [172, 157, 140, 0],
8: [199, 226, 113, 1]}
newrgb = basepal.astype('uint32');
flags = rgbf[pal][3]
if (flags&1): # greyscale
newrgb = newrgb.max(2);
newrgb = dstack((newrgb, newrgb, newrgb)).copy();
if (flags&2): # invert
newrgb = 255-newrgb;
# colorize
for i in range(3):
newrgb[:,:,i] *= rgbf[pal][i]
newrgb[:,:,i] /= 255
newrgb[newrgb>255] = 255
return newrgb.astype('uint8');
# plagman:
# if (pal==1):
# h[:] = 0.66;
# elif (pal==6):
# h[:] = 0.33;
# v = 1.0 - v;
elif (pal==20):
m1 = ((h>0.6) & (h<0.7));
@ -171,35 +218,39 @@ BASEPALHSV should the precomputed HSV representation of BASEPAL."
# helixhorned:
elif (pal==11):
mask = bluemask;
h[:] = green;
s += 0.1;
h[mask] = green;
s[mask] += 0.1;
elif (pal==12):
mask = bluemask;
h[:] = 0.0;
s[:] = 0.0;
h[mask] = 0.0;
s[mask] = 0.0;
elif (pal==13):
mask = bluemask;
h[:] = 0.0;
s[:] = 0.0;
v *= 0.7;
h[mask] = 0.0;
s[mask] = 0.0;
v[mask] *= 0.7;
elif (pal==16):
mask = bluemask;
s += 0.1;
v -= 0.1;
s[mask] += 0.1;
v[mask] -= 0.1;
elif (pal==21):
mask = bluemask;
h[:] = red;
s += 0.3;
h[mask] = red;
s[mask] += 0.3;
elif (pal==23):
mask = bluemask;
h[:] = yellow;
s += 0.12;
v *= 1.15;
h[mask] = yellow;
s[mask] += 0.12;
v[mask] *= 1.15;
elif (pal==99):
mask = bluemask;
v[mask] = 0;
# user:
# ...
@ -210,9 +261,11 @@ BASEPALHSV should the precomputed HSV representation of BASEPAL."
# ---
newrgb = hsv2rgb(dstack((h, s, v)));
r = mask*newrgb[:,:,0] + (~mask)*basepal[:,:,0];
g = mask*newrgb[:,:,1] + (~mask)*basepal[:,:,1];
b = mask*newrgb[:,:,2] + (~mask)*basepal[:,:,2];
nmask = ~mask;
r = mask*newrgb[:,:,0] + nmask*basepal[:,:,0];
g = mask*newrgb[:,:,1] + nmask*basepal[:,:,1];
b = mask*newrgb[:,:,2] + nmask*basepal[:,:,2];
# PIL doesn't seem to like views/shallow copies
return dstack((r, g, b)).copy();
@ -223,21 +276,18 @@ if (__name__ == "__main__"):
argc = len(sys.argv);
if (argc == 1):
print "Usage: python prhighpal.py <palnum>"
print "Usage: python prhighpal.py (palnums ...)"
sys.exit();
elif (argc > 2):
print "There's a weird bug when passing more than one palnum; \
processing only the first one.\n"
print "Generating base palette..."
bp = genbasepal();
bph = rgb2hsv(bp);
for i in [1]: #xrange(1, argc):
for i in xrange(1, argc):
palnum = int(sys.argv[i]);
filename = "hipal{0}_gen.png".format(palnum);
print "Generating palnum", palnum, "image ...";
palimg = genpal(bp, bph, palnum);
palimg = genpal(bp.copy(), bph.copy(), palnum);
print "Writing", filename, "...";
saveimage(palimg, filename);

View file

@ -268,6 +268,7 @@ static void G_PrecacheSprites(void)
for (i = SCRAP1; i < (SCRAP1+29); i++) tloadtile(i,1);
tloadtile(FIRELASER,1);
for (i=TRANSPORTERSTAR; i<TRANSPORTERSTAR+6; i++) tloadtile(i,1);
for (i=FORCERIPPLE; i<(FORCERIPPLE+9); i++) tloadtile(i,1);
for (i=MENUSCREEN; i<DUKECAR; i++) tloadtile(i,1);
@ -442,7 +443,6 @@ void G_CacheMapData(void)
starttime = getticks();
G_PrecacheSounds();
G_PrecacheSprites();
for (i=0; i<numwalls; i++)
@ -490,6 +490,7 @@ void G_CacheMapData(void)
loadtile((int16_t)i);
#if defined(POLYMOST) && defined(USE_OPENGL)
// PRECACHE
if (ud.config.useprecache)
{
int32_t k,type;
@ -1626,6 +1627,25 @@ void G_FadeLoad(int32_t r, int32_t g, int32_t b, int32_t start, int32_t end, int
}
}
static void G_LoadMapHack(char *outbuf, const char *filename)
{
char *p;
if (filename != NULL)
Bstrcpy(outbuf, filename);
p = Bstrrchr(outbuf,'.');
if (!p) Bstrcat(outbuf,".mhk");
else
{
p[1]='m';
p[2]='h';
p[3]='k';
p[4]=0;
}
if (!loadmaphack(outbuf)) initprintf("Loaded map hack file '%s'\n",outbuf);
}
int32_t G_EnterLevel(int32_t g)
{
int32_t i;
@ -1694,8 +1714,9 @@ int32_t G_EnterLevel(int32_t g)
i = ud.screen_size;
ud.screen_size = 0;
G_DoLoadScreen(NULL, -1);
G_DoLoadScreen("Loading map . . .", -1);
G_UpdateScreenArea();
ud.screen_size = i;
if (boardfilename[0] != 0 && ud.m_level_number == 7 && ud.m_volume_number == 0)
@ -1707,6 +1728,7 @@ int32_t G_EnterLevel(int32_t g)
Bstrcpy(tempbuf,apptitle);
wm_setapptitle(tempbuf);
if (!VOLUMEONE)
{
if (boardfilename[0] != 0 && ud.m_level_number == 7 && ud.m_volume_number == 0)
@ -1722,17 +1744,7 @@ int32_t G_EnterLevel(int32_t g)
{
char *p;
strcpy(levname, boardfilename);
p = Bstrrchr(levname,'.');
if (!p) strcat(levname,".mhk");
else
{
p[1]='m';
p[2]='h';
p[3]='k';
p[4]=0;
}
if (!loadmaphack(levname)) initprintf("Loaded map hack file '%s'\n",levname);
G_LoadMapHack(levname, boardfilename);
// usermap music based on map filename
Bcorrectfilename(levname,0);
@ -1791,20 +1803,8 @@ int32_t G_EnterLevel(int32_t g)
}
else
{
char *p;
strcpy(levname, MapInfo[(ud.volume_number*MAXLEVELS)+ud.level_number].filename);
p = Bstrrchr(levname,'.');
if (!p) strcat(levname,".mhk");
else
{
p[1]='m';
p[2]='h';
p[3]='k';
p[4]=0;
}
if (!loadmaphack(levname)) initprintf("Loaded map hack file '%s'\n",levname);
G_LoadMapHack(levname, MapInfo[(ud.volume_number*MAXLEVELS)+ud.level_number].filename);
}
}
else
{
@ -1823,17 +1823,7 @@ int32_t G_EnterLevel(int32_t g)
}
else
{
char *p;
p = Bstrrchr(levname,'.');
if (!p) strcat(levname,".mhk");
else
{
p[1]='m';
p[2]='h';
p[3]='k';
p[4]=0;
}
if (!loadmaphack(levname)) initprintf("Loaded map hack file '%s'\n",levname);
G_LoadMapHack(levname, NULL);
}
}