diff --git a/src/doom/m_crispy.c b/src/doom/m_crispy.c index c9e67036c..53666e963 100644 --- a/src/doom/m_crispy.c +++ b/src/doom/m_crispy.c @@ -25,6 +25,7 @@ #include "s_sound.h" #include "r_defs.h" // [crispy] laserpatch #include "r_sky.h" // [crispy] R_InitSkyMap() +#include "z_zone.h" // [crispy] Z_Free() #include "m_crispy.h" @@ -516,6 +517,17 @@ static void M_CrispyToggleSmoothLightingHook (void) { crispy->smoothlight = !crispy->smoothlight; +#ifdef CRISPY_TRUECOLOR + // [crispy] zero out colormaps[] array so it can be + // reallocated and recalculated in R_InitColormaps() + if (colormaps != NULL) + { + Z_Free(colormaps); + colormaps = NULL; + } + // [crispy] re-calculate light tables and amount of colormaps + R_InitColormaps(); +#endif // [crispy] re-calculate the zlight[][] array R_InitLightTables(); // [crispy] re-calculate the scalelight[][] array diff --git a/src/doom/m_menu.c b/src/doom/m_menu.c index aa048a6c6..8af456c72 100644 --- a/src/doom/m_menu.c +++ b/src/doom/m_menu.c @@ -2789,7 +2789,6 @@ boolean M_Responder (event_t* ev) I_SetPalette (W_CacheLumpName (DEH_String("PLAYPAL"),PU_CACHE)); #else { - extern void R_InitColormaps (void); I_SetPalette (0); R_InitColormaps(); inhelpscreens = true; diff --git a/src/doom/p_user.c b/src/doom/p_user.c index 21bc0efeb..f55447cab 100644 --- a/src/doom/p_user.c +++ b/src/doom/p_user.c @@ -34,7 +34,12 @@ // Index of the special effects (INVUL inverse) map. +#ifndef CRISPY_TRUECOLOR #define INVERSECOLORMAP 32 +#else +// [crispy] parameterized for smooth diminishing lighting +int INVERSECOLORMAP; +#endif // diff --git a/src/doom/r_data.c b/src/doom/r_data.c index aebbd3354..f21ac7138 100644 --- a/src/doom/r_data.c +++ b/src/doom/r_data.c @@ -1196,6 +1196,21 @@ void R_InitColormaps (void) byte *const playpal = W_CacheLumpName("PLAYPAL", PU_STATIC); byte *const colormap = W_CacheLumpName("COLORMAP", PU_STATIC); + // [crispy] Smoother diminished lighting. + // Compiled in but not enabled TrueColor mode + // can't use more than original 32 colormaps. + if (crispy->truecolor && crispy->smoothlight) + { + NUMCOLORMAPS = 256; + } + else + { + NUMCOLORMAPS = 32; + } + // [crispy] Regardless of the number of color maps, + // invulnerability is always the last one. + INVERSECOLORMAP = NUMCOLORMAPS; + if (!colormaps) { colormaps = (lighttable_t*) Z_Malloc((NUMCOLORMAPS + 1) * 256 * sizeof(lighttable_t), PU_STATIC, 0); diff --git a/src/doom/r_main.c b/src/doom/r_main.c index 71d68dd81..19cc26eb7 100644 --- a/src/doom/r_main.c +++ b/src/doom/r_main.c @@ -111,6 +111,9 @@ lighttable_t*** zlight = NULL; int extralight; // [crispy] parameterized for smooth diminishing lighting +#ifdef CRISPY_TRUECOLOR +int NUMCOLORMAPS; +#endif int LIGHTLEVELS; int LIGHTSEGSHIFT; int LIGHTBRIGHT; @@ -699,13 +702,38 @@ void R_InitLightTables (void) // [crispy] smooth diminishing lighting if (crispy->smoothlight) { - LIGHTLEVELS = 32; - LIGHTSEGSHIFT = 3; - LIGHTBRIGHT = 2; - MAXLIGHTSCALE = 48; - LIGHTSCALESHIFT = 12; - MAXLIGHTZ = 1024; - LIGHTZSHIFT = 17; +#ifndef CRISPY_TRUECOLOR + LIGHTLEVELS = 32; + LIGHTSEGSHIFT = 3; + LIGHTBRIGHT = 2; + MAXLIGHTSCALE = 48; + LIGHTSCALESHIFT = 12; + MAXLIGHTZ = 1024; + LIGHTZSHIFT = 17; +#else + if (crispy->truecolor) + { + // [crispy] if in TrueColor mode, use smoothest diminished lighting + LIGHTLEVELS = 256; + LIGHTSEGSHIFT = 0; + LIGHTBRIGHT = 15; + MAXLIGHTSCALE = 376; + LIGHTSCALESHIFT = 9; + MAXLIGHTZ = 1024; + LIGHTZSHIFT = 17; + } + else + { + // [crispy] else, use paletted paletted approach + LIGHTLEVELS = 32; + LIGHTSEGSHIFT = 3; + LIGHTBRIGHT = 2; + MAXLIGHTSCALE = 48; + LIGHTSCALESHIFT = 12; + MAXLIGHTZ = 1024; + LIGHTZSHIFT = 17; + } +#endif } else { diff --git a/src/doom/r_main.h b/src/doom/r_main.h index e3fc7961b..0bcd2d311 100644 --- a/src/doom/r_main.h +++ b/src/doom/r_main.h @@ -80,7 +80,13 @@ extern lighttable_t* fixedcolormap; // Number of diminishing brightness levels. // There a 0-31, i.e. 32 LUT in the COLORMAP lump. +#ifndef CRISPY_TRUECOLOR #define NUMCOLORMAPS 32 +#else +// [crispy] parameterized for smooth diminishing lighting +extern int NUMCOLORMAPS; +extern int INVERSECOLORMAP; +#endif // Blocky/low detail mode. //B remove this? @@ -200,6 +206,7 @@ void R_Init (void); // Called by M_Responder. void R_SetViewSize (int blocks, int detail); +void R_InitColormaps(void); void R_ExecuteSetViewSize(void);