From fc3df5bfe4e5c2ea851b0fe1ab136d85a2f9e2fe Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 23 Jan 2024 06:41:25 +0100 Subject: [PATCH] Revert "attempt at unmangling lighttables and colormaps" This reverts commit 19702daecdc2cb0e313efeeaf32ab6c80880da30. --- src/hardware/hw_cache.c | 2 +- src/p_setup.c | 7 +- src/p_spec.c | 2 +- src/r_bsp.c | 27 ++- src/r_data.c | 499 ++++++++++++++-------------------------- src/r_data.h | 20 +- src/r_defs.h | 21 +- src/r_main.c | 3 +- src/r_state.h | 3 +- 9 files changed, 217 insertions(+), 367 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index b264abd54..0fadfed4b 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -948,7 +948,7 @@ UINT32 HWR_GetLightTableID(extracolormap_t *colormap) boolean default_colormap = false; if (!colormap) { - colormap = R_GetDefaultColormap(); // a place to store the hw lighttable id + colormap = &extra_colormaps[num_extra_colormaps]; // 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; } diff --git a/src/p_setup.c b/src/p_setup.c index b6098d8ee..807b9e55e 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -744,6 +744,7 @@ 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; @@ -1446,7 +1447,7 @@ static void P_LoadRawSideDefs2(void *data) { if (msd->toptexture[0] == '#' || msd->bottomtexture[0] == '#') { - sec->extra_colormap = R_CreateColormap(msd->toptexture, msd->midtexture, + sec->midmap = R_CreateColormap(msd->toptexture, msd->midtexture, msd->bottomtexture); sd->toptexture = sd->bottomtexture = 0; } @@ -1478,12 +1479,12 @@ static void P_LoadRawSideDefs2(void *data) RGBA_t color; size_t j; - sec->extra_colormap = R_CreateColormap(msd->toptexture, msd->midtexture, + sec->midmap = 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]) { diff --git a/src/p_spec.c b/src/p_spec.c index 45f1cfa81..1d1cad62f 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -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].extra_colormap = lines[i].frontsector->extra_colormap; + sectors[s].midmap = lines[i].frontsector->midmap; break; case 720: diff --git a/src/r_bsp.c b/src/r_bsp.c index cdc6cc3e8..2de30d2ab 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -233,6 +233,8 @@ 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; @@ -242,10 +244,9 @@ 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->extra_colormap && sec->heightsec != -1) + if (sec->midmap != -1) + mapnum = sec->midmap; + else if (sec->heightsec != -1) { const sector_t *s = §ors[sec->heightsec]; mobj_t *viewmobj = viewplayer->mo; @@ -276,6 +277,8 @@ 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 @@ -301,6 +304,7 @@ 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; @@ -324,6 +328,8 @@ 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; @@ -354,6 +360,11 @@ 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; } @@ -1132,7 +1143,7 @@ void R_Prep3DFloors(sector_t *sector) ffloor_t *rover; ffloor_t *best; fixed_t bestheight, maxheight; - INT32 count, i; + INT32 count, i, mapnum; 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 @@ -1212,8 +1223,12 @@ void R_Prep3DFloors(sector_t *sector) sector->lightlist[i].caster = best; sector->lightlist[i].flags = best->flags; sector->lightlist[i].slope = bestslope; - sec = §ors[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) { diff --git a/src/r_data.c b/src/r_data.c index 0af66efd6..8e3be5111 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -954,7 +954,6 @@ 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; @@ -990,7 +989,6 @@ 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) @@ -1080,9 +1078,7 @@ 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 @@ -1130,6 +1126,8 @@ void R_ReInitColormaps(UINT16 num, lumpnum_t newencoremap) R_ClearColormaps(); } +static lumpnum_t foundcolormaps[MAXCOLORMAPS]; + // // R_ClearColormaps // @@ -1137,157 +1135,54 @@ void R_ReInitColormaps(UINT16 num, lumpnum_t newencoremap) // void R_ClearColormaps(void) { - // Purged by PU_LEVEL, just overwrite the pointer - extra_colormaps = R_CreateDefaultColormap(true); + size_t i; + + num_extra_colormaps = 0; + + for (i = 0; i < MAXCOLORMAPS; i++) + foundcolormaps[i] = LUMPERROR; + + memset(extra_colormaps, 0, sizeof (extra_colormaps)); + #ifdef HWRENDER if (rendermode == render_opengl) HWR_ClearLightTables(); #endif } -// -// R_CreateDefaultColormap() -// -extracolormap_t *R_CreateDefaultColormap(boolean lighttable) +/*INT32 R_ColormapNumForName(char *name) { - 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; - return exc; -} + lumpnum_t lump, i; -// -// 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; + if (num_extra_colormaps == MAXCOLORMAPS) + I_Error("R_ColormapNumForName: Too many colormaps! the limit is %d\n", MAXCOLORMAPS); lump = R_CheckNumForNameList(name, colormaplumps, numcolormaplumps); if (lump == LUMPERROR) - I_Error("R_ColormapForName: Cannot find colormap lump %.8s\n", name); + I_Error("R_ColormapNumForName: Cannot find colormap lump %.8s\n", name); - for (exc = extra_colormaps; exc; exc = exc->next) - if (lump == exc->lump) - return exc; + for (i = 0; i < num_extra_colormaps; i++) + if (lump == foundcolormaps[i]) + return i; - exc = Z_Calloc(sizeof (*exc), PU_LEVEL, NULL); - - exc->lump = lump; - strncpy(exc->lumpname, name, 9); - exc->lumpname[8] = 0; + foundcolormaps[num_extra_colormaps] = lump; // aligned on 8 bit for asm code - exc->colormap = Z_MallocAlign(W_LumpLength(lump), PU_LEVEL, NULL, 16); - W_ReadLump(lump, exc->colormap); + extra_colormaps[num_extra_colormaps].colormap = Z_MallocAlign(W_LumpLength(lump), PU_LEVEL, NULL, 16); + W_ReadLump(lump, extra_colormaps[num_extra_colormaps].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.. - exc->fadestart = 0; - exc->fadeend = 31; - exc->fog = 0; - exc->rgba = 0; - exc->fadergba = 0x19000000; + 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; - R_AddColormapToList(exc); - - return exc; + num_extra_colormaps++; + return (INT32)num_extra_colormaps - 1; }*/ -#endif - -#ifdef HASINVERT -void R_MakeInvertmap(void) -{ - size_t i; - - for (i = 0; i < 256; i++) - invertmap[i] = NearestColor(256 - pMasterPalette[i].s.red, 256 - pMasterPalette[i].s.green, 256 - pMasterPalette[i].s.blue); -} -#endif // // R_CreateColormap @@ -1301,66 +1196,144 @@ static double deltas[256][3], map[256][3]; static int RoundUp(double number); -lighttable_t *R_CreateLightTable(extracolormap_t *extra_colormap) +#ifdef HASINVERT +void R_MakeInvertmap(void) +{ + size_t i; + + for (i = 0; i < 256; i++) + invertmap[i] = NearestColor(256 - pMasterPalette[i].s.red, 256 - pMasterPalette[i].s.green, 256 - pMasterPalette[i].s.blue); +} +#endif + +INT32 R_CreateColormap(char *p1, char *p2, char *p3) { double cmaskr, cmaskg, cmaskb, cdestr, cdestg, cdestb; double maskamt = 0, othermask = 0; - - 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; + int mask, fog = 0; + size_t mapnum = num_extra_colormaps; size_t i; + UINT32 cr, cg, cb, maskcolor, fadecolor; + UINT32 fadestart = 0, fadeend = 31, fadedist = 31; - ///////////////////// - // 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 - ///////////////////// +#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] == '#') { + 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 = pMasterPalette[i].s.red; + cg = pMasterPalette[i].s.green; + cb = pMasterPalette[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 = pMasterPalette[i].s.red; + cg = pMasterPalette[i].s.green; + cb = pMasterPalette[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; - char *colormap_p; - + lighttable_t *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 @@ -1390,13 +1363,12 @@ lighttable_t *R_CreateLightTable(extracolormap_t *extra_colormap) } // Now allocate memory for the actual colormap array itself! - // aligned on 8 bit for asm code - colormap_p = Z_MallocAlign((256 * (encoremap ? 66 : 34)) + 10, PU_LEVEL, NULL, 8); - lighttable = (UINT8 *)colormap_p; + colormap_p = Z_MallocAlign((256 * (encoremap ? 64 : 32)) + 10, PU_LEVEL, NULL, 8); + extra_colormaps[mapnum].colormap = (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 < 34; p++) + for (p = 0; p < 32; p++) { for (i = 0; i < 256; i++) { @@ -1425,9 +1397,10 @@ lighttable_t *R_CreateLightTable(extracolormap_t *extra_colormap) #undef ABS2 } } + if (encoremap) { - lighttable_t *colormap_p2 = lighttable; + lighttable_t *colormap_p2 = extra_colormaps[mapnum].colormap; for (p = 0; p < 32; p++) { @@ -1440,132 +1413,8 @@ lighttable_t *R_CreateLightTable(extracolormap_t *extra_colormap) } } } - - 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 = pMasterPalette[i].s.red; - cg = pMasterPalette[i].s.green; - cb = pMasterPalette[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 = pMasterPalette[i].s.red; - cg = pMasterPalette[i].s.green; - cb = pMasterPalette[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; + + return (INT32)mapnum; } // Thanks to quake2 source! @@ -1612,18 +1461,20 @@ static int RoundUp(double number) return (int)number; } -#ifdef EXTRACOLORMAPLUMPS -const char *R_NameForColormap(extracolormap_t *extra_colormap) +const char *R_ColormapNameForNum(INT32 num) { - if (!extra_colormap) + if (num == -1) return "NONE"; - if (extra_colormap->lump == LUMPERROR) + if (num < 0 || num > MAXCOLORMAPS) + I_Error("R_ColormapNameForNum: num %d is invalid!\n", num); + + if (foundcolormaps[num] == LUMPERROR) return "INLEVEL"; - return extra_colormap->lumpname; + return W_CheckNameForNum(foundcolormaps[num]); } -#endif + // // build a table for quick conversion from 8bpp to 15bpp diff --git a/src/r_data.h b/src/r_data.h index a9a0b09ac..ec1146322 100644 --- a/src/r_data.h +++ b/src/r_data.h @@ -91,28 +91,14 @@ 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); -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); +INT32 R_ColormapNumForName(char *name); +INT32 R_CreateColormap(char *p1, char *p2, char *p3); #ifdef HASINVERT void R_MakeInvertmap(void); #endif -#ifdef EXTRACOLORMAPLUMPS -extracolormap_t *R_ColormapForName(char *name); -const char *R_NameForColormap(extracolormap_t *extra_colormap); -#endif +const char *R_ColormapNameForNum(INT32 num); UINT8 NearestPaletteColor(UINT8 r, UINT8 g, UINT8 b, RGBA_t *palette); #define NearestColor(r, g, b) NearestPaletteColor(r, g, b, NULL) diff --git a/src/r_defs.h b/src/r_defs.h index 63add4487..b14b3364f 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -51,26 +51,19 @@ typedef struct typedef UINT8 lighttable_t; // ExtraColormap type. Use for extra_colormaps from now on. -typedef struct extracolormap_s +typedef struct { - UINT8 fadestart, fadeend; - boolean fog; + UINT16 maskcolor, fadecolor; + double maskamt; + UINT16 fadestart, fadeend; + INT32 fog; - // store rgba values in combined bitwise - // also used in OpenGL instead lighttables + // rgba is used in hw mode for colored sector lighting 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; @@ -332,6 +325,8 @@ 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; diff --git a/src/r_main.c b/src/r_main.c index a2c1063de..9ca72dd15 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -116,7 +116,8 @@ lighttable_t *scalelightfixed[MAXLIGHTSCALE]; lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ]; // Hack to support extra boom colormaps. -extracolormap_t *extra_colormaps; +size_t num_extra_colormaps; +extracolormap_t extra_colormaps[MAXCOLORMAPS]; // Performance stats precise_t ps_prevframetime = 0; diff --git a/src/r_state.h b/src/r_state.h index c7b21e6b8..e37bdf52e 100644 --- a/src/r_state.h +++ b/src/r_state.h @@ -48,7 +48,8 @@ extern UINT8 invertmap[256]; // Had to put a limit on colormaps :( #define MAXCOLORMAPS 60 -extern extracolormap_t *extra_colormaps; +extern size_t num_extra_colormaps; +extern extracolormap_t extra_colormaps[MAXCOLORMAPS]; // for global animation extern INT32 *texturetranslation;