From aab87012dff516089b587d44bcc7293a7c3342dd Mon Sep 17 00:00:00 2001 From: Latapostrophe Date: Tue, 12 Nov 2019 00:40:25 +0100 Subject: [PATCH] dontencoreremap flag + colormaps --- src/hardware/hw_main.c | 4 +-- src/p_setup.c | 61 +++++++++++++++++++++++++++++++++++------- src/r_data.c | 4 +-- 3 files changed, 56 insertions(+), 13 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index fd112c29..23a2120f 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5762,7 +5762,7 @@ static void HWR_ProjectSprite(mobj_t *thing) { vis->colormap = colormaps; #ifdef GLENCORE - if (encoremap && (thing->flags & (MF_SCENERY|MF_NOTHINK))) + if (encoremap && (thing->flags & (MF_SCENERY|MF_NOTHINK)) && !(thing->flags & MF_DONTENCOREMAP)) vis->colormap += (256*32); #endif } @@ -5880,7 +5880,7 @@ static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) vis->colormap = colormaps; #ifdef GLENCORE - if (encoremap) + if (encoremap && !(thing->flags & MF_DONTENCOREMAP)) vis->colormap += (256*32); #endif diff --git a/src/p_setup.c b/src/p_setup.c index bf13971b..59c4429b 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1407,11 +1407,12 @@ static inline void P_LoadSideDefs(lumpnum_t lumpnum) P_LoadRawSideDefs(W_LumpLength(lumpnum)); } - static void P_LoadRawSideDefs2(void *data) { UINT16 i; INT32 num; + size_t j; + UINT32 cr, cg, cb; for (i = 0; i < numsides; i++) { @@ -1490,16 +1491,43 @@ static void P_LoadRawSideDefs2(void *data) { col = msd->toptexture; - sec->extra_colormap->rgba = - (HEX2INT(col[1]) << 4) + (HEX2INT(col[2]) << 0) + - (HEX2INT(col[3]) << 12) + (HEX2INT(col[4]) << 8) + - (HEX2INT(col[5]) << 20) + (HEX2INT(col[6]) << 16); + // encore mode colormaps! + // do it like software by aproximating a color to a palette index, and then convert it to its encore variant and then back to a color code. + // do this for both the start and fade colormaps. + + cr = (HEX2INT(col[1]) << 4) + (HEX2INT(col[2]) << 0); + cg = (HEX2INT(col[3]) << 12) + (HEX2INT(col[4]) << 8); + cb = (HEX2INT(col[5]) << 20) + (HEX2INT(col[6]) << 16); + +#ifdef GLENCORE + if (encoremap) + { + j = encoremap[NearestColor((UINT8)cr, (UINT8)cg, (UINT8)cb)]; + //CONS_Printf("R_CreateColormap: encoremap[%d] = %d\n", j, encoremap[j]); -- moved encoremap upwards for optimisation + cr = pLocalPalette[j].s.red; + cg = pLocalPalette[j].s.green; + cb = pLocalPalette[j].s.blue; + } +#endif + + sec->extra_colormap->rgba = cr + cg + cb; // alpha if (msd->toptexture[7]) sec->extra_colormap->rgba += (ALPHA2INT(col[7]) << 24); else sec->extra_colormap->rgba += (25 << 24); + + /*nearest = NearestColor( + (HEX2INT(col[1]) << 4) + (HEX2INT(col[2]) << 0), + (HEX2INT(col[3]) << 4) + (HEX2INT(col[4]) << 0), + (HEX2INT(col[5]) << 4) + (HEX2INT(col[6]) << 0) + ); + + sec->extra_colormap->rgba = + pLocalPalette[nearest].s.red + + (pLocalPalette[nearest].s.green << 8) + + (pLocalPalette[nearest].s.blue << 16);*/ } else sec->extra_colormap->rgba = 0; @@ -1508,10 +1536,24 @@ static void P_LoadRawSideDefs2(void *data) { col = msd->bottomtexture; - sec->extra_colormap->fadergba = - (HEX2INT(col[1]) << 4) + (HEX2INT(col[2]) << 0) + - (HEX2INT(col[3]) << 12) + (HEX2INT(col[4]) << 8) + - (HEX2INT(col[5]) << 20) + (HEX2INT(col[6]) << 16); + // do the exact same thing as above here. + + cr = (HEX2INT(col[1]) << 4) + (HEX2INT(col[2]) << 0); + cg = (HEX2INT(col[3]) << 12) + (HEX2INT(col[4]) << 8); + cb = (HEX2INT(col[5]) << 20) + (HEX2INT(col[6]) << 16); + +#ifdef GLENCORE + if (encoremap) + { + j = encoremap[NearestColor((UINT8)cr, (UINT8)cg, (UINT8)cb)]; + //CONS_Printf("R_CreateColormap: encoremap[%d] = %d\n", j, encoremap[j]); -- moved encoremap upwards for optimisation + cr = pLocalPalette[j].s.red; + cg = pLocalPalette[j].s.green; + cb = pLocalPalette[j].s.blue; + } +#endif + + sec->extra_colormap->fadergba = cr + cg + cb; // alpha if (msd->bottomtexture[7]) @@ -1658,6 +1700,7 @@ static void P_LoadRawSideDefs2(void *data) R_ClearTextureNumCache(true); } + // Delay loading texture names until after loaded linedefs. static void P_LoadSideDefs2(lumpnum_t lumpnum) { diff --git a/src/r_data.c b/src/r_data.c index 7fb11855..d5e384bb 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -1177,7 +1177,7 @@ void R_ClearColormaps(void) // static double deltas[256][3], map[256][3]; -static UINT8 NearestColor(UINT8 r, UINT8 g, UINT8 b); +UINT8 NearestColor(UINT8 r, UINT8 g, UINT8 b); static int RoundUp(double number); #ifdef HASINVERT @@ -1403,7 +1403,7 @@ INT32 R_CreateColormap(char *p1, char *p2, char *p3) // Thanks to quake2 source! // utils3/qdata/images.c -static UINT8 NearestColor(UINT8 r, UINT8 g, UINT8 b) +UINT8 NearestColor(UINT8 r, UINT8 g, UINT8 b) { int dr, dg, db; int distortion, bestdistortion = 256 * 256 * 4, bestcolor = 0, i;