Skip to content

Commit

Permalink
Initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
JNechaevsky committed Sep 3, 2024
1 parent edc1e6e commit 872d4de
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 8 deletions.
12 changes: 12 additions & 0 deletions src/doom/m_crispy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/doom/m_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/doom/p_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -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


//
Expand Down
15 changes: 15 additions & 0 deletions src/doom/r_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
42 changes: 35 additions & 7 deletions src/doom/r_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
{
Expand Down
7 changes: 7 additions & 0 deletions src/doom/r_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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);


Expand Down

0 comments on commit 872d4de

Please sign in to comment.