Skip to content

Commit

Permalink
add console commands for controlling light-amp goggle effect
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesDunne committed May 4, 2024
1 parent 98ea337 commit 0246efd
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 57 deletions.
55 changes: 45 additions & 10 deletions prboom2/src/dsda/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "p_spec.h"
#include "p_tick.h"
#include "p_user.h"
#include "r_main.h"
#include "s_sound.h"
#include "smooth.h"
#include "v_video.h"
Expand Down Expand Up @@ -1047,6 +1048,32 @@ static dboolean console_Exit(const char* command, const char* args) {
return true;
}

static dboolean getOrSet(const char *name, double *var, const char *newValue) {
dboolean assigned = false;
if (strlen(newValue) > 0) {
*var = strtod(newValue, NULL);
assigned = true;
}
lprintf(LO_INFO, "%s = %lf\n", name, *var);
return assigned;
}

static dboolean console_GogglesSet(const char* command, const char* args) {
dboolean assigned = false;
if (stricmp(command, "goggles.cL.mul") == 0) { assigned = getOrSet("cL_mul", &goggles_cL_mul, args); }
else if (stricmp(command, "goggles.cL.add") == 0) { assigned = getOrSet("cL_add", &goggles_cL_add, args); }
else if (stricmp(command, "goggles.ca.mul") == 0) { assigned = getOrSet("ca_mul", &goggles_ca_mul, args); }
else if (stricmp(command, "goggles.ca.add") == 0) { assigned = getOrSet("ca_add", &goggles_ca_add, args); }
else if (stricmp(command, "goggles.cb.mul") == 0) { assigned = getOrSet("cb_mul", &goggles_cb_mul, args); }
else if (stricmp(command, "goggles.cb.add") == 0) { assigned = getOrSet("cb_add", &goggles_cb_add, args); }
else return false;

if (assigned) {
R_InitGoggleMaps();
}
return true;
}

static dboolean console_BasicCheat(const char* command, const char* args) {
return M_CheatEntered(command, args);
}
Expand Down Expand Up @@ -2480,18 +2507,26 @@ static console_command_entry_t console_commands[] = {
{ "nra", console_BasicCheat, CF_DEMO },
{ "indiana", console_BasicCheat, CF_DEMO },
{ "locksmith", console_BasicCheat, CF_DEMO },
{ "sherlock", console_BasicCheat, CF_DEMO },
{ "casper", console_BasicCheat, CF_DEMO },
{ "init", console_BasicCheat, CF_DEMO },
{ "mapsco", console_IDDT, CF_DEMO },
{ "deliverance", console_BasicCheat, CF_DEMO },
{ "shadowcaster", console_BasicCheat, CF_DEMO },
{ "visit", console_BasicCheat, CF_DEMO },
{ "puke", console_BasicCheat, CF_DEMO },
{ "sherlock", console_BasicCheat, CF_DEMO },
{ "casper", console_BasicCheat, CF_DEMO },
{ "init", console_BasicCheat, CF_DEMO },
{ "mapsco", console_IDDT, CF_DEMO },
{ "deliverance", console_BasicCheat, CF_DEMO },
{ "shadowcaster", console_BasicCheat, CF_DEMO },
{ "visit", console_BasicCheat, CF_DEMO },
{ "puke", console_BasicCheat, CF_DEMO },

// jsd: light-amp goggle parameters:
{ "goggles.cL.mul", console_GogglesSet, CF_ALWAYS },
{ "goggles.cL.add", console_GogglesSet, CF_ALWAYS },
{ "goggles.ca.mul", console_GogglesSet, CF_ALWAYS },
{ "goggles.ca.add", console_GogglesSet, CF_ALWAYS },
{ "goggles.cb.mul", console_GogglesSet, CF_ALWAYS },
{ "goggles.cb.add", console_GogglesSet, CF_ALWAYS },

// exit
{ "exit", console_Exit, CF_ALWAYS },
{ "quit", console_Exit, CF_ALWAYS },
{ "exit", console_Exit, CF_ALWAYS },
{ "quit", console_Exit, CF_ALWAYS },
{ NULL }
};

Expand Down
89 changes: 44 additions & 45 deletions prboom2/src/r_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,42 @@ static void R_InitSpriteLumps(void)
numspritelumps = lastspritelump - firstspritelump + 1;
}

void R_InitGoggleMaps(void) {
int i, j, m;

// jsd: allocate gogglemaps here but fill them in R_InitPatches after PLAYPAL palette loaded:
gogglemaps = Z_Malloc(sizeof(*gogglemaps) * numcolormaps);

// jsd: build light-amp goggle colormaps:
const unsigned char *playpal = V_GetPlaypal();

for (i = 0; i < numcolormaps; i++) {
lighttable_t *gmap = (lighttable_t *) Z_Malloc((NUMCOLORMAPS + 1) * 256 * sizeof(lighttable_t));
for (m = 0; m < NUMCOLORMAPS + 1; m++) {
for (j = 0; j < 256; j++) {
double cL, ca, cb;
double x, y, z;
lighttable_t c;

// look up color in colormap:
c = colormaps[i][m * 256 + j];
// convert the RGB to Lab colorspace:
dsda_PaletteGetColorLab(playpal, c, &cL, &ca, &cb);

// lighten the color and apply gamma ramp:
cL = (log(1.0+cL)*goggles_cL_mul) + goggles_cL_add;
// green tint:
ca = (ca * goggles_ca_mul) + goggles_ca_add;
cb = (cb * goggles_cb_mul) + goggles_cb_add;
// find the nearest color in playpal:
dsda_ColorLabToXYZ(cL, ca, cb, &x, &y, &z);
gmap[m * 256 + j] = dsda_PaletteFindNearestXYZColor(playpal, x, y, z);
}
}
gogglemaps[i] = (const lighttable_t *) gmap;
}
}

//
// R_InitColormaps
//
Expand All @@ -379,62 +415,25 @@ static void R_InitSpriteLumps(void)
// killough 4/4/98: Add support for C_START/C_END markers
//

static void R_InitColormaps(void)
{
static void R_InitColormaps(void) {
int i;
// MAP_FORMAT_TODO: not sure about this
if (hexen)
{
if (hexen) {
firstcolormaplump = -1;
lastcolormaplump = -1;
numcolormaps = 1;
}
else
{
} else {
firstcolormaplump = W_GetNumForName("C_START");
lastcolormaplump = W_GetNumForName("C_END");
lastcolormaplump = W_GetNumForName("C_END");
numcolormaps = lastcolormaplump - firstcolormaplump;
}
colormaps = Z_Malloc(sizeof(*colormaps) * numcolormaps);
colormaps[0] = (const lighttable_t *)W_LumpByName("COLORMAP");
for (i=1; i<numcolormaps; i++)
colormaps[i] = (const lighttable_t *)W_LumpByNum(i+firstcolormaplump);
colormaps[0] = (const lighttable_t *) W_LumpByName("COLORMAP");
for (i = 1; i < numcolormaps; i++)
colormaps[i] = (const lighttable_t *) W_LumpByNum(i + firstcolormaplump);
// cph - always lock

// jsd: allocate gogglemaps here but fill them in R_InitPatches after PLAYPAL palette loaded:
gogglemaps = Z_Malloc(sizeof(*gogglemaps) * numcolormaps);

// jsd: build light-amp goggle colormaps:
{
int i, j, m;

const unsigned char *playpal = V_GetPlaypal();

for (i = 0; i < numcolormaps; i++) {
lighttable_t *gmap = (lighttable_t *) Z_Malloc((NUMCOLORMAPS+1) * 256 * sizeof(lighttable_t));
for (m = 0; m < NUMCOLORMAPS+1; m++) {
for (j = 0; j < 256; j++) {
double cL, ca, cb;
double x, y, z;
lighttable_t c;

// look up color in colormap:
c = colormaps[i][(m * 5 / 6 + 1) * 256 + j];
// convert the RGB to Lab colorspace:
dsda_PaletteGetColorLab(playpal, c, &cL, &ca, &cb);
// lighten the color and apply gamma ramp:
cL = pow((cL + 25.0), 2.65) / 373.0;
// green tint:
ca = -200.0;
cb = 56.0;
dsda_ColorLabToXYZ(cL, ca, cb, &x, &y, &z);
// find the nearest color in playpal:
gmap[m*256+j] = dsda_PaletteFindNearestXYZColor(playpal, x, y, z);
}
}
gogglemaps[i] = (const lighttable_t *) gmap;
}
}
R_InitGoggleMaps();
}

// killough 4/4/98: get colormap number from name
Expand Down
1 change: 1 addition & 0 deletions prboom2/src/r_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const byte *R_GetTextureColumn(const rpatch_t *texpatch, int col);
void R_InitData (void);
void R_PrecacheLevel (void);

void R_InitGoggleMaps (void);

// Retrieval.
// Floor/ceiling opaque texture tiles,
Expand Down
6 changes: 5 additions & 1 deletion prboom2/src/r_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,13 @@ const lighttable_t *(*scalelight)[MAXLIGHTSCALE];
const lighttable_t *(*zlight)[MAXLIGHTZ];
const lighttable_t *fullcolormap;
const lighttable_t **colormaps;
// killough 3/20/98, 4/4/98: end dynamic colormaps

const lighttable_t **gogglemaps;
double goggles_cL_mul = 30.0, goggles_cL_add = 2.0;
double goggles_ca_mul = 0.2, goggles_ca_add = -160.0;
double goggles_cb_mul = 0.2, goggles_cb_add = 56.0;

// killough 3/20/98, 4/4/98: end dynamic colormaps

//e6y: for Boom colormaps in OpenGL mode
dboolean use_boom_cm;
Expand Down
6 changes: 5 additions & 1 deletion prboom2/src/r_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,13 @@ extern const lighttable_t *(*zlight)[MAXLIGHTZ];
extern const lighttable_t *fullcolormap;
extern int numcolormaps; // killough 4/4/98: dynamic number of maps
extern const lighttable_t **colormaps;
extern const lighttable_t **gogglemaps;
// killough 3/20/98, 4/4/98: end dynamic colormaps

extern const lighttable_t **gogglemaps;
extern double goggles_cL_mul, goggles_cL_add;
extern double goggles_ca_mul, goggles_ca_add;
extern double goggles_cb_mul, goggles_cb_add;

//e6y: for Boom colormaps in OpenGL mode
extern dboolean use_boom_cm;
extern int boom_cm; // current colormap
Expand Down

0 comments on commit 0246efd

Please sign in to comment.