attempt at unmangling lighttables and colormaps

ugh i hope this doesent break
This commit is contained in:
Alug committed 2024-01-22 23:28:34 +01:00
1 parent dde4b4df3b
commit 19702daecd
9 files changed
+368 -217

No files matched your search

+1 -1
View File
@@ -950,7 +950,7 @@ UINT32 HWR_GetLightTableID(extracolormap_t *colormap)
boolean default_colormap = false;
if (!colormap)
{
colormap = &extra_colormaps[num_extra_colormaps]; // a place to store the hw lighttable id
colormap = R_GetDefaultColormap(); // a place to store the hw lighttable id
// alternatively could just store the id in a global variable if there are issues
default_colormap = true;
}
+3 -4
View File
@@ -744,7 +744,6 @@ static void P_LoadRawSectors(UINT8 *data, size_t i)
ss->spawn_flr_xoffs = ss->spawn_ceil_xoffs = ss->spawn_flr_yoffs = ss->spawn_ceil_yoffs = 0;
ss->floorpic_angle = ss->ceilingpic_angle = 0;
ss->spawn_flrpic_angle = ss->spawn_ceilpic_angle = 0;
ss->bottommap = ss->midmap = ss->topmap = -1;
ss->gravity = NULL;
ss->cullheight = NULL;
ss->verticalflip = false;
@@ -1447,7 +1446,7 @@ static void P_LoadRawSideDefs2(void *data)
{
if (msd->toptexture[0] == '#' || msd->bottomtexture[0] == '#')
{
sec->midmap = R_CreateColormap(msd->toptexture, msd->midtexture,
sec->extra_colormap = R_CreateColormap(msd->toptexture, msd->midtexture,
msd->bottomtexture);
sd->toptexture = sd->bottomtexture = 0;
}
@@ -1479,12 +1478,12 @@ static void P_LoadRawSideDefs2(void *data)
RGBA_t color;
size_t j;
sec->midmap = R_CreateColormap(msd->toptexture, msd->midtexture,
sec->extra_colormap = R_CreateColormap(msd->toptexture, msd->midtexture,
msd->bottomtexture);
sd->toptexture = sd->bottomtexture = 0;
#define HEX2INT(x) (x >= '0' && x <= '9' ? x - '0' : x >= 'a' && x <= 'f' ? x - 'a' + 10 : x >= 'A' && x <= 'F' ? x - 'A' + 10 : 0)
#define ALPHA2INT(x) (x >= 'a' && x <= 'z' ? x - 'a' : x >= 'A' && x <= 'Z' ? x - 'A' : x >= '0' && x <= '9' ? 25 : 0)
sec->extra_colormap = &extra_colormaps[sec->midmap];
//sec->extra_colormap = &extra_colormaps[sec->midmap];
if (msd->toptexture[0] == '#' && msd->toptexture[1] && msd->toptexture[2] && msd->toptexture[3] && msd->toptexture[4] && msd->toptexture[5] && msd->toptexture[6])
{
+1 -1
View File
@@ -6701,7 +6701,7 @@ void P_SpawnSpecials(INT32 fromnetsave)
case 606: // HACK! Copy colormaps. Just plain colormaps.
for (s = -1; (s = P_FindSectorFromLineTag(lines + i, s)) >= 0 ;)
sectors[s].midmap = lines[i].frontsector->midmap;
sectors[s].extra_colormap = lines[i].frontsector->extra_colormap;
break;
case 720:
+6 -21
View File
@@ -233,8 +233,6 @@ void R_PortalClearClipSegs(INT32 start, INT32 end)
sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec, INT32 *floorlightlevel,
INT32 *ceilinglightlevel, boolean back)
{
INT32 mapnum = -1;
if (floorlightlevel)
*floorlightlevel = sec->floorlightsec == -1 ?
sec->lightlevel : sectors[sec->floorlightsec].lightlevel;
@@ -244,9 +242,10 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec, INT32 *floorlightlevel,
sec->lightlevel : sectors[sec->ceilinglightsec].lightlevel;
// If the sector has a midmap, it's probably from 280 type
if (sec->midmap != -1)
mapnum = sec->midmap;
else if (sec->heightsec != -1)
//if (sec->midmap != -1)
//mapnum = sec->midmap;
//else if (sec->heightsec != -1)
if (!sec->extra_colormap && sec->heightsec != -1)
{
const sector_t *s = &sectors[sec->heightsec];
mobj_t *viewmobj = viewplayer->mo;
@@ -277,8 +276,6 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec, INT32 *floorlightlevel,
tempsec->floorheight = s->floorheight;
tempsec->ceilingheight = s->ceilingheight;
mapnum = s->midmap;
if ((underwater && (tempsec-> floorheight = sec->floorheight,
tempsec->ceilingheight = s->floorheight - 1, !back)) || viewz <= s->floorheight)
{ // head-below-floor hack
@@ -304,7 +301,6 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec, INT32 *floorlightlevel,
tempsec->ceiling_yoffs = s->ceiling_yoffs;
tempsec->ceilingpic_angle = s->ceilingpic_angle;
}
mapnum = s->bottommap;
}
tempsec->lightlevel = s->lightlevel;
@@ -328,8 +324,6 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec, INT32 *floorlightlevel,
tempsec->floor_yoffs = tempsec->ceiling_yoffs = s->ceiling_yoffs;
tempsec->floorpic_angle = tempsec->ceilingpic_angle = s->ceilingpic_angle;
mapnum = s->topmap;
if (s->floorpic == skyflatnum) // SKYFIX?
{
tempsec->ceilingheight = tempsec->floorheight-1;
@@ -360,11 +354,6 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec, INT32 *floorlightlevel,
sec = tempsec;
}
if (mapnum >= 0 && (size_t)mapnum < num_extra_colormaps)
sec->extra_colormap = &extra_colormaps[mapnum];
else
sec->extra_colormap = NULL;
return sec;
}
@@ -1143,7 +1132,7 @@ void R_Prep3DFloors(sector_t *sector)
ffloor_t *rover;
ffloor_t *best;
fixed_t bestheight, maxheight;
INT32 count, i, mapnum;
INT32 count, i;
sector_t *sec;
pslope_t *bestslope = NULL;
fixed_t heighttest; // I think it's better to check the Z height at the sector's center
@@ -1223,12 +1212,8 @@ void R_Prep3DFloors(sector_t *sector)
sector->lightlist[i].caster = best;
sector->lightlist[i].flags = best->flags;
sector->lightlist[i].slope = bestslope;
sec = &sectors[best->secnum];
mapnum = sec->midmap;
if (mapnum >= 0 && (size_t)mapnum < num_extra_colormaps)
sec->extra_colormap = &extra_colormaps[mapnum];
else
sec->extra_colormap = NULL;
if (best->flags & FF_NOSHADE)
{
+325 -175
View File
@@ -954,6 +954,7 @@ static inline lumpnum_t R_CheckNumForNameList(const char *name, lumplist_t *list
}
*/
#ifdef EXTRACOLORMAPLUMPS
/*static lumplist_t *colormaplumps = NULL; ///\todo free leak
static size_t numcolormaplumps = 0;
@@ -989,6 +990,7 @@ static void R_InitExtraColormaps(void)
}
CONS_Printf(M_GetText("Number of Extra Colormaps: %s\n"), sizeu1(numcolormaplumps));
}*/
#endif
// Search for flat name.
lumpnum_t R_GetFlatNumForName(const char *name)
@@ -1078,7 +1080,9 @@ static void R_InitColormaps(void)
// Init Boom colormaps.
R_ClearColormaps();
#ifdef EXTRACOLORMAPLUMPS
//R_InitExtraColormaps();
#endif
#ifdef HASINVERT
R_MakeInvertmap(); // this isn't the BEST place to do it the first time, but whatever
#endif
@@ -1126,8 +1130,6 @@ void R_ReInitColormaps(UINT16 num, lumpnum_t newencoremap)
R_ClearColormaps();
}
static lumpnum_t foundcolormaps[MAXCOLORMAPS];
//
// R_ClearColormaps
//
@@ -1135,54 +1137,158 @@ static lumpnum_t foundcolormaps[MAXCOLORMAPS];
//
void R_ClearColormaps(void)
{
size_t i;
num_extra_colormaps = 0;
for (i = 0; i < MAXCOLORMAPS; i++)
foundcolormaps[i] = LUMPERROR;
memset(extra_colormaps, 0, sizeof (extra_colormaps));
// Purged by PU_LEVEL, just overwrite the pointer
extra_colormaps = R_CreateDefaultColormap(true);
#ifdef HWRENDER
if (rendermode == render_opengl)
HWR_ClearLightTables();
#endif
}
/*INT32 R_ColormapNumForName(char *name)
//
// R_CreateDefaultColormap()
//
extracolormap_t *R_CreateDefaultColormap(boolean lighttable)
{
lumpnum_t lump, i;
extracolormap_t *exc = Z_Calloc(sizeof (*exc), PU_LEVEL, NULL);
exc->fadestart = 0;
exc->fadeend = 31;
exc->fog = 0;
exc->rgba = 0;
exc->fadergba = 0x19000000;
exc->colormap = lighttable ? R_CreateLightTable(exc) : NULL;
#ifdef EXTRACOLORMAPLUMPS
exc->lump = LUMPERROR;
exc->lumpname[0] = 0;
#endif
exc->next = exc->prev = NULL;
if (num_extra_colormaps == MAXCOLORMAPS)
I_Error("R_ColormapNumForName: Too many colormaps! the limit is %d\n", MAXCOLORMAPS);
return exc;
}
//
// R_GetDefaultColormap()
//
extracolormap_t *R_GetDefaultColormap(void)
{
#ifdef COLORMAPREVERSELIST
extracolormap_t *exc;
#endif
if (!extra_colormaps)
return (extra_colormaps = R_CreateDefaultColormap(true));
#ifdef COLORMAPREVERSELIST
for (exc = extra_colormaps; exc->next; exc = exc->next);
return exc;
#else
return extra_colormaps;
#endif
}
//
// R_CheckDefaultColormap()
//
boolean R_CheckDefaultColormapValues(extracolormap_t *extra_colormap, boolean checkrgba, boolean checkfadergba, boolean checkparams)
{
if (!extra_colormap)
return true;
else
return (
(!checkparams ? true :
(extra_colormap->fadestart == 0
&& extra_colormap->fadeend == 31
&& !extra_colormap->fog)
)
&& (!checkrgba ? true : extra_colormap->rgba == 0)
&& (!checkfadergba ? true : extra_colormap->fadergba == 0x19000000)
#ifdef EXTRACOLORMAPLUMPS
&& extra_colormap->lump == LUMPERROR
&& extra_colormap->lumpname[0] == 0
#endif
);
}
//
// R_AddColormapToList
//
// Sets prev/next chain for extra_colormaps var
// Copypasta from P_AddFFloorToList
//
void R_AddColormapToList(extracolormap_t *extra_colormap)
{
extracolormap_t *exc;
if (!extra_colormaps)
{
extra_colormaps = extra_colormap;
extra_colormap->next = 0;
extra_colormap->prev = 0;
return;
}
#ifdef COLORMAPREVERSELIST
extra_colormaps->prev = extra_colormap;
extra_colormap->next = extra_colormaps;
extra_colormaps = extra_colormap;
extra_colormap->prev = 0;
#else
for (exc = extra_colormaps; exc->next; exc = exc->next);
exc->next = extra_colormap;
extra_colormap->prev = exc;
extra_colormap->next = 0;
#endif
}
#ifdef EXTRACOLORMAPLUMPS
/*extracolormap_t *R_ColormapForName(char *name)
{
lumpnum_t lump;
extracolormap_t *exc;
lump = R_CheckNumForNameList(name, colormaplumps, numcolormaplumps);
if (lump == LUMPERROR)
I_Error("R_ColormapNumForName: Cannot find colormap lump %.8s\n", name);
I_Error("R_ColormapForName: Cannot find colormap lump %.8s\n", name);
for (i = 0; i < num_extra_colormaps; i++)
if (lump == foundcolormaps[i])
return i;
for (exc = extra_colormaps; exc; exc = exc->next)
if (lump == exc->lump)
return exc;
foundcolormaps[num_extra_colormaps] = lump;
exc = Z_Calloc(sizeof (*exc), PU_LEVEL, NULL);
exc->lump = lump;
strncpy(exc->lumpname, name, 9);
exc->lumpname[8] = 0;
// aligned on 8 bit for asm code
extra_colormaps[num_extra_colormaps].colormap = Z_MallocAlign(W_LumpLength(lump), PU_LEVEL, NULL, 16);
W_ReadLump(lump, extra_colormaps[num_extra_colormaps].colormap);
exc->colormap = Z_MallocAlign(W_LumpLength(lump), PU_LEVEL, NULL, 16);
W_ReadLump(lump, exc->colormap);
// We set all params of the colormap to normal because there
// is no real way to tell how GL should handle a colormap lump anyway..
extra_colormaps[num_extra_colormaps].maskcolor = 0xffff;
extra_colormaps[num_extra_colormaps].fadecolor = 0x0;
extra_colormaps[num_extra_colormaps].maskamt = 0x0;
extra_colormaps[num_extra_colormaps].fadestart = 0;
extra_colormaps[num_extra_colormaps].fadeend = 31;
extra_colormaps[num_extra_colormaps].fog = 0;
exc->fadestart = 0;
exc->fadeend = 31;
exc->fog = 0;
exc->rgba = 0;
exc->fadergba = 0x19000000;
num_extra_colormaps++;
return (INT32)num_extra_colormaps - 1;
R_AddColormapToList(exc);
return exc;
}*/
#endif
#ifdef HASINVERT
void R_MakeInvertmap(void)
{
size_t i;
for (i = 0; i < 256; i++)
invertmap[i] = NearestColor(256 - pLocalPalette[i].s.red, 256 - pLocalPalette[i].s.green, 256 - pLocalPalette[i].s.blue);
}
#endif
//
// R_CreateColormap
@@ -1196,144 +1302,66 @@ static double deltas[256][3], map[256][3];
static int RoundUp(double number);
#ifdef HASINVERT
void R_MakeInvertmap(void)
{
size_t i;
for (i = 0; i < 256; i++)
invertmap[i] = NearestColor(256 - pLocalPalette[i].s.red, 256 - pLocalPalette[i].s.green, 256 - pLocalPalette[i].s.blue);
}
#endif
INT32 R_CreateColormap(char *p1, char *p2, char *p3)
lighttable_t *R_CreateLightTable(extracolormap_t *extra_colormap)
{
double cmaskr, cmaskg, cmaskb, cdestr, cdestg, cdestb;
double maskamt = 0, othermask = 0;
int mask, fog = 0;
size_t mapnum = num_extra_colormaps;
UINT8 cr = (extra_colormap->rgba) & 0xFF,
cg = (extra_colormap->rgba >> 8) & 0xFF,
cb = (extra_colormap->rgba >> 16) & 0xFF,
ca = (extra_colormap->rgba >> 24) & 0xFF,
cfr = (extra_colormap->fadergba) & 0xFF,
cfg = (extra_colormap->fadergba >> 8) & 0xFF,
cfb = (extra_colormap->fadergba >> 16) & 0xFF;
// cfa = (extra_colormap->fadergba >> 24) & 0xFF; // unused in software
// "Unpackage" our variables for ease of reading below
UINT8 fadestart = extra_colormap->fadestart,
fadedist = extra_colormap->fadeend - extra_colormap->fadestart;
lighttable_t *lighttable = NULL;
size_t i;
UINT32 cr, cg, cb, maskcolor, fadecolor;
UINT32 fadestart = 0, fadeend = 31, fadedist = 31;
#define HEX2INT(x) (UINT32)(x >= '0' && x <= '9' ? x - '0' : x >= 'a' && x <= 'f' ? x - 'a' + 10 : x >= 'A' && x <= 'F' ? x - 'A' + 10 : 0)
if (p1[0] == '#')
/////////////////////
// Calc the RGBA mask
/////////////////////
cmaskr = cr;
cmaskg = cg;
cmaskb = cb;
maskamt = (double)(ca/24.0l);
othermask = 1 - maskamt;
maskamt /= 0xff;
cmaskr *= maskamt;
cmaskg *= maskamt;
cmaskb *= maskamt;
/////////////////////
// Calc the RGBA fade mask
/////////////////////
cdestr = cfr;
cdestg = cfg;
cdestb = cfb;
// fade alpha unused in software
// maskamt = (double)(cfa/24.0l);
// othermask = 1 - maskamt;
// maskamt /= 0xff;
// cdestr *= maskamt;
// cdestg *= maskamt;
// cdestb *= maskamt;
/////////////////////
// This code creates the colormap array used by software renderer
/////////////////////
{
cr = ((HEX2INT(p1[1]) * 16) + HEX2INT(p1[2]));
cg = ((HEX2INT(p1[3]) * 16) + HEX2INT(p1[4]));
cb = ((HEX2INT(p1[5]) * 16) + HEX2INT(p1[6]));
if (encoremap)
{
i = encoremap[NearestColor((UINT8)cr, (UINT8)cg, (UINT8)cb)];
//CONS_Printf("R_CreateColormap: encoremap[%d] = %d\n", i, encoremap[i]); -- moved encoremap upwards for optimisation
cr = pLocalPalette[i].s.red;
cg = pLocalPalette[i].s.green;
cb = pLocalPalette[i].s.blue;
}
cmaskr = cr;
cmaskg = cg;
cmaskb = cb;
// Create a rough approximation of the color (a 16 bit color)
maskcolor = ((cb) >> 3) + (((cg) >> 2) << 5) + (((cr) >> 3) << 11);
if (p1[7] >= 'a' && p1[7] <= 'z')
mask = (p1[7] - 'a');
else if (p1[7] >= 'A' && p1[7] <= 'Z')
mask = (p1[7] - 'A');
else
mask = 24;
maskamt = (double)(mask/24.0l);
othermask = 1 - maskamt;
maskamt /= 0xff;
cmaskr *= maskamt;
cmaskg *= maskamt;
cmaskb *= maskamt;
}
else
{
cmaskr = cmaskg = cmaskb = 0xff;
maskamt = 0;
maskcolor = ((0xff) >> 3) + (((0xff) >> 2) << 5) + (((0xff) >> 3) << 11);
}
#define NUMFROMCHAR(c) (c >= '0' && c <= '9' ? c - '0' : 0)
if (p2[0] == '#')
{
// Get parameters like fadestart, fadeend, and the fogflag
fadestart = NUMFROMCHAR(p2[3]) + (NUMFROMCHAR(p2[2]) * 10);
fadeend = NUMFROMCHAR(p2[5]) + (NUMFROMCHAR(p2[4]) * 10);
if (fadestart > 30)
fadestart = 0;
if (fadeend > 31 || fadeend < 1)
fadeend = 31;
fadedist = fadeend - fadestart;
fog = NUMFROMCHAR(p2[1]);
}
#undef NUMFROMCHAR
if (p3[0] == '#')
{
cr = ((HEX2INT(p3[1]) * 16) + HEX2INT(p3[2]));
cg = ((HEX2INT(p3[3]) * 16) + HEX2INT(p3[4]));
cb = ((HEX2INT(p3[5]) * 16) + HEX2INT(p3[6]));
if (encoremap)
{
i = encoremap[NearestColor((UINT8)cr, (UINT8)cg, (UINT8)cb)];
cr = pLocalPalette[i].s.red;
cg = pLocalPalette[i].s.green;
cb = pLocalPalette[i].s.blue;
}
cdestr = cr;
cdestg = cg;
cdestb = cb;
fadecolor = (((cb) >> 3) + (((cg) >> 2) << 5) + (((cr) >> 3) << 11));
}
else
cdestr = cdestg = cdestb = fadecolor = 0;
#undef HEX2INT
for (i = 0; i < num_extra_colormaps; i++)
{
if (foundcolormaps[i] != LUMPERROR)
continue;
if (maskcolor == extra_colormaps[i].maskcolor
&& fadecolor == extra_colormaps[i].fadecolor
&& fabs(maskamt - extra_colormaps[i].maskamt) < DBL_EPSILON
&& fadestart == extra_colormaps[i].fadestart
&& fadeend == extra_colormaps[i].fadeend
&& fog == extra_colormaps[i].fog)
{
return (INT32)i;
}
}
if (num_extra_colormaps == MAXCOLORMAPS)
I_Error("R_CreateColormap: Too many colormaps! the limit is %d\n", MAXCOLORMAPS);
num_extra_colormaps++;
foundcolormaps[mapnum] = LUMPERROR;
// aligned on 8 bit for asm code
extra_colormaps[mapnum].colormap = NULL;
extra_colormaps[mapnum].maskcolor = (UINT16)maskcolor;
extra_colormaps[mapnum].fadecolor = (UINT16)fadecolor;
extra_colormaps[mapnum].maskamt = maskamt;
extra_colormaps[mapnum].fadestart = (UINT16)fadestart;
extra_colormaps[mapnum].fadeend = (UINT16)fadeend;
extra_colormaps[mapnum].fog = fog;
if (rendermode != render_none)
{
double r, g, b, cbrightness;
int p;
lighttable_t *colormap_p;
char *colormap_p;
// Initialise the map and delta arrays
// map[i] stores an RGB color (as double) for index i,
// which is then converted to SRB2's palette later
@@ -1363,12 +1391,13 @@ INT32 R_CreateColormap(char *p1, char *p2, char *p3)
}
// Now allocate memory for the actual colormap array itself!
colormap_p = Z_MallocAlign((256 * (encoremap ? 64 : 32)) + 10, PU_LEVEL, NULL, 8);
extra_colormaps[mapnum].colormap = (UINT8 *)colormap_p;
// aligned on 8 bit for asm code
colormap_p = Z_MallocAlign((256 * (encoremap ? 66 : 34)) + 10, PU_LEVEL, NULL, 8);
lighttable = (UINT8 *)colormap_p;
// Calculate the palette index for each palette index, for each light level
// (as well as the two unused colormap lines we inherited from Doom)
for (p = 0; p < 32; p++)
for (p = 0; p < 34; p++)
{
for (i = 0; i < 256; i++)
{
@@ -1397,10 +1426,9 @@ INT32 R_CreateColormap(char *p1, char *p2, char *p3)
#undef ABS2
}
}
if (encoremap)
{
lighttable_t *colormap_p2 = extra_colormaps[mapnum].colormap;
lighttable_t *colormap_p2 = lighttable;
for (p = 0; p < 32; p++)
{
@@ -1413,8 +1441,132 @@ INT32 R_CreateColormap(char *p1, char *p2, char *p3)
}
}
}
return (INT32)mapnum;
return lighttable;
}
extracolormap_t *R_CreateColormap(char *p1, char *p2, char *p3)
{
boolean fog = false;
size_t i;
extracolormap_t *extra_colormap, *exc;
UINT8 cr, cg, cb, ca, cfr, cfg, cfb, cfa;
UINT32 fadestart = 0, fadeend = 31;
INT32 rgba, fadergba;
#define HEX2INT(x) (UINT32)(x >= '0' && x <= '9' ? x - '0' : x >= 'a' && x <= 'f' ? x - 'a' + 10 : x >= 'A' && x <= 'F' ? x - 'A' + 10 : 0)
#define ALPHA2INT(x) (x >= 'a' && x <= 'z' ? x - 'a' : x >= 'A' && x <= 'Z' ? x - 'A' : x >= '0' && x <= '9' ? 25 : 0)
if (p1[0] == '#')
{
cr = ((HEX2INT(p1[1]) * 16) + HEX2INT(p1[2]));
cg = ((HEX2INT(p1[3]) * 16) + HEX2INT(p1[4]));
cb = ((HEX2INT(p1[5]) * 16) + HEX2INT(p1[6]));
if (encoremap)
{
i = encoremap[NearestColor((UINT8)cr, (UINT8)cg, (UINT8)cb)];
//CONS_Printf("R_CreateColormap: encoremap[%d] = %d\n", i, encoremap[i]); -- moved encoremap upwards for optimisation
cr = pLocalPalette[i].s.red;
cg = pLocalPalette[i].s.green;
cb = pLocalPalette[i].s.blue;
}
if (p1[7] >= 'a' && p1[7] <= 'z')
ca = (p1[7] - 'a');
else if (p1[7] >= 'A' && p1[7] <= 'Z')
ca = (p1[7] - 'A');
else
ca = 25;
rgba = cr + (cg << 8) + (cb << 16) + (ca << 24);
}
else
{
cr = cg = cb = ca = 0;
rgba = 0;
}
#define NUMFROMCHAR(c) (c >= '0' && c <= '9' ? c - '0' : 0)
if (p2[0] == '#')
{
// Get parameters like fadestart, fadeend, and the fogflag
fadestart = NUMFROMCHAR(p2[3]) + (NUMFROMCHAR(p2[2]) * 10);
fadeend = NUMFROMCHAR(p2[5]) + (NUMFROMCHAR(p2[4]) * 10);
if (fadestart > 30)
fadestart = 0;
if (fadeend > 31 || fadeend < 1)
fadeend = 31;
fog = (boolean)NUMFROMCHAR(p2[1]);
}
#undef NUMFROMCHAR
if (p3[0] == '#')
{
cfr = ((HEX2INT(p3[1]) * 16) + HEX2INT(p3[2]));
cfg = ((HEX2INT(p3[3]) * 16) + HEX2INT(p3[4]));
cfb = ((HEX2INT(p3[5]) * 16) + HEX2INT(p3[6]));
if (encoremap)
{
i = encoremap[NearestColor((UINT8)cr, (UINT8)cg, (UINT8)cb)];
cr = pLocalPalette[i].s.red;
cg = pLocalPalette[i].s.green;
cb = pLocalPalette[i].s.blue;
}
if (p1[7] >= 'a' && p1[7] <= 'z')
cfa = (p1[7] - 'a');
else if (p1[7] >= 'A' && p1[7] <= 'Z')
cfa = (p1[7] - 'A');
else
cfa = 25;
fadergba = cfr + (cfg << 8) + (cfb << 16) + (cfa << 24);
}
else
{
cfr = cfg = cfb = 0;
cfa = 25;
fadergba = 0x19000000; // default alpha for fade, (25 << 24)
}
#undef ALPHA2INT
#undef HEX2INT
for (exc = extra_colormaps; exc; exc = exc->next)
{
#ifdef EXTRACOLORMAPLUMPS
if (exc->lump != LUMPERROR)
continue;
#endif
if (rgba == exc->rgba
&& fadergba == exc->fadergba
&& fadestart == exc->fadestart
&& fadeend == exc->fadeend
&& fog == exc->fog)
break;
}
extra_colormap = Z_Calloc(sizeof (*extra_colormap), PU_LEVEL, NULL);
extra_colormap->fadestart = (UINT16)fadestart;
extra_colormap->fadeend = (UINT16)fadeend;
extra_colormap->fog = fog;
extra_colormap->rgba = rgba;
extra_colormap->fadergba = fadergba;
#ifdef EXTRACOLORMAPLUMPS
extra_colormap->lump = LUMPERROR;
extra_colormap->lumpname[0] = 0;
#endif
extra_colormap->colormap = R_CreateLightTable(extra_colormap);
R_AddColormapToList(extra_colormap);
return extra_colormap;
}
// Thanks to quake2 source!
@@ -1461,20 +1613,18 @@ static int RoundUp(double number)
return (int)number;
}
const char *R_ColormapNameForNum(INT32 num)
#ifdef EXTRACOLORMAPLUMPS
const char *R_NameForColormap(extracolormap_t *extra_colormap)
{
if (num == -1)
if (!extra_colormap)
return "NONE";
if (num < 0 || num > MAXCOLORMAPS)
I_Error("R_ColormapNameForNum: num %d is invalid!\n", num);
if (foundcolormaps[num] == LUMPERROR)
if (extra_colormap->lump == LUMPERROR)
return "INLEVEL";
return W_CheckNameForNum(foundcolormaps[num]);
return extra_colormap->lumpname;
}
#endif
//
// build a table for quick conversion from 8bpp to 15bpp
+17 -3
View File
@@ -91,14 +91,28 @@ void R_ClearTextureNumCache(boolean btell);
INT32 R_TextureNumForName(const char *name);
INT32 R_CheckTextureNumForName(const char *name);
// Extra Colormap lumps (C_START/C_END) are not used anywhere
// Uncomment to enable
//#define EXTRACOLORMAPLUMPS
// Uncomment to make extra_colormaps order Newest -> Oldest
//#define COLORMAPREVERSELIST
void R_ReInitColormaps(UINT16 num, lumpnum_t newencoremap);
void R_ClearColormaps(void);
INT32 R_ColormapNumForName(char *name);
INT32 R_CreateColormap(char *p1, char *p2, char *p3);
extracolormap_t *R_CreateDefaultColormap(boolean lighttable);
extracolormap_t *R_GetDefaultColormap(void);
boolean R_CheckDefaultColormapValues(extracolormap_t *extra_colormap, boolean checkrgba, boolean checkfadergba, boolean checkparams);
void R_AddColormapToList(extracolormap_t *extra_colormap);
lighttable_t *R_CreateLightTable(extracolormap_t *extra_colormap);
extracolormap_t *R_CreateColormap(char *p1, char *p2, char *p3);
#ifdef HASINVERT
void R_MakeInvertmap(void);
#endif
const char *R_ColormapNameForNum(INT32 num);
#ifdef EXTRACOLORMAPLUMPS
extracolormap_t *R_ColormapForName(char *name);
const char *R_NameForColormap(extracolormap_t *extra_colormap);
#endif
UINT8 NearestPaletteColor(UINT8 r, UINT8 g, UINT8 b, RGBA_t *palette);
#define NearestColor(r, g, b) NearestPaletteColor(r, g, b, NULL)
+13 -8
View File
@@ -51,19 +51,26 @@ typedef struct
typedef UINT8 lighttable_t;
// ExtraColormap type. Use for extra_colormaps from now on.
typedef struct
typedef struct extracolormap_s
{
UINT16 maskcolor, fadecolor;
double maskamt;
UINT16 fadestart, fadeend;
INT32 fog;
UINT8 fadestart, fadeend;
boolean fog;
// rgba is used in hw mode for colored sector lighting
// store rgba values in combined bitwise
// also used in OpenGL instead lighttables
INT32 rgba; // similar to maskcolor in sw mode
INT32 fadergba; // The colour the colourmaps fade to
lighttable_t *colormap;
#ifdef EXTRACOLORMAPLUMPS
lumpnum_t lump; // for colormap lump matching, init to LUMPERROR
char lumpname[9]; // for netsyncing
#endif
struct extracolormap_s *next;
struct extracolormap_s *prev;
#ifdef HWRENDER
// The id of the hardware lighttable. Zero means it does not exist yet.
UINT32 gl_lighttable_id;
@@ -325,8 +332,6 @@ typedef struct sector_s
INT32 floorlightsec, ceilinglightsec;
INT32 crumblestate; // used for crumbling and bobbing
INT32 bottommap, midmap, topmap; // dynamic colormaps
// list of mobjs that are at least partially in the sector
// thinglist is a subset of touching_thinglist
struct msecnode_s *touching_thinglist;
+1 -2
View File
@@ -116,8 +116,7 @@ lighttable_t *scalelightfixed[MAXLIGHTSCALE];
lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ];
// Hack to support extra boom colormaps.
size_t num_extra_colormaps;
extracolormap_t extra_colormaps[MAXCOLORMAPS];
extracolormap_t *extra_colormaps;
// Performance stats
precise_t ps_prevframetime = 0;
+1 -2
View File
@@ -48,8 +48,7 @@ extern UINT8 invertmap[256];
// Had to put a limit on colormaps :(
#define MAXCOLORMAPS 60
extern size_t num_extra_colormaps;
extern extracolormap_t extra_colormaps[MAXCOLORMAPS];
extern extracolormap_t *extra_colormaps;
// for global animation
extern INT32 *texturetranslation;