Merge branch 'grayscale-command' into 'master'

Add grayscale palette toggle command

See merge request KartKrew/Kart!753
This commit is contained in:
Oni 2022-11-07 01:06:43 +00:00
commit 578908065b
7 changed files with 58 additions and 18 deletions

View file

@ -1080,9 +1080,10 @@ static void COM_Toggle_f(void)
for (i = 2; i < COM_Argc() - 1; ++i) for (i = 2; i < COM_Argc() - 1; ++i)
{ {
const char *str = COM_Argv(i); const char *str = COM_Argv(i);
INT32 val; INT32 val = 0;
if (CV_CompleteValue(cvar, &str, &val)) if (!cvar->PossibleValue ||
CV_CompleteValue(cvar, &str, &val))
{ {
if (str ? !stricmp(cvar->string, str) if (str ? !stricmp(cvar->string, str)
: cvar->value == val) : cvar->value == val)

View file

@ -986,6 +986,9 @@ void D_RegisterClientCommands(void)
CV_RegisterVar(&cv_bsaturation); CV_RegisterVar(&cv_bsaturation);
CV_RegisterVar(&cv_msaturation); CV_RegisterVar(&cv_msaturation);
CV_RegisterVar(&cv_palette);
CV_RegisterVar(&cv_palettenum);
// k_menu.c // k_menu.c
//CV_RegisterVar(&cv_compactscoreboard); //CV_RegisterVar(&cv_compactscoreboard);
CV_RegisterVar(&cv_chatheight); CV_RegisterVar(&cv_chatheight);
@ -1089,6 +1092,7 @@ void D_RegisterClientCommands(void)
COM_AddCommand("rteleport", Command_RTeleport_f); COM_AddCommand("rteleport", Command_RTeleport_f);
COM_AddCommand("skynum", Command_Skynum_f); COM_AddCommand("skynum", Command_Skynum_f);
COM_AddCommand("weather", Command_Weather_f); COM_AddCommand("weather", Command_Weather_f);
COM_AddCommand("grayscale", Command_Grayscale_f);
#ifdef _DEBUG #ifdef _DEBUG
COM_AddCommand("causecfail", Command_CauseCfail_f); COM_AddCommand("causecfail", Command_CauseCfail_f);
#endif #endif

View file

@ -762,6 +762,13 @@ void Command_Setlives_f(void)
D_Cheat(consoleplayer, CHEAT_LIVES, atoi(COM_Argv(1))); D_Cheat(consoleplayer, CHEAT_LIVES, atoi(COM_Argv(1)));
} }
void Command_Grayscale_f(void)
{
REQUIRE_CHEATS;
COM_ImmedExecute("toggle palette \"\" GRAYPAL");
}
// //
// OBJECTPLACE (and related variables) // OBJECTPLACE (and related variables)
// //

View file

@ -75,6 +75,7 @@ void Command_Teleport_f(void);
void Command_RTeleport_f(void); void Command_RTeleport_f(void);
void Command_Skynum_f(void); void Command_Skynum_f(void);
void Command_Weather_f(void); void Command_Weather_f(void);
void Command_Grayscale_f(void);
#ifdef _DEBUG #ifdef _DEBUG
void Command_CauseCfail_f(void); void Command_CauseCfail_f(void);
#endif #endif

View file

@ -7350,7 +7350,7 @@ boolean P_LoadLevel(boolean fromnetsave, boolean reloadinggamestate)
// Reset the palette now all fades have been done // Reset the palette now all fades have been done
if (rendermode != render_none) if (rendermode != render_none)
V_SetPaletteLump(GetPalette()); // Set the level palette V_ReloadPalette(); // Set the level palette
if (!(reloadinggamestate || titlemapinaction)) if (!(reloadinggamestate || titlemapinaction))
{ {

View file

@ -86,11 +86,16 @@ static CV_PossibleValue_t constextsize_cons_t[] = {
static void CV_constextsize_OnChange(void); static void CV_constextsize_OnChange(void);
consvar_t cv_constextsize = CVAR_INIT ("con_textsize", "Medium", CV_SAVE|CV_CALL, constextsize_cons_t, CV_constextsize_OnChange); consvar_t cv_constextsize = CVAR_INIT ("con_textsize", "Medium", CV_SAVE|CV_CALL, constextsize_cons_t, CV_constextsize_OnChange);
consvar_t cv_palette = CVAR_INIT ("palette", "", CV_CHEAT|CV_CALL|CV_NOINIT, NULL, CV_palette_OnChange);
consvar_t cv_palettenum = CVAR_INIT ("palettenum", "0", CV_CHEAT|CV_CALL|CV_NOINIT, CV_Unsigned, CV_palette_OnChange);
// local copy of the palette for V_GetColor() // local copy of the palette for V_GetColor()
RGBA_t *pLocalPalette = NULL; RGBA_t *pLocalPalette = NULL;
RGBA_t *pMasterPalette = NULL; RGBA_t *pMasterPalette = NULL;
RGBA_t *pGammaCorrectedPalette = NULL; RGBA_t *pGammaCorrectedPalette = NULL;
static size_t currentPaletteSize;
/* /*
The following was an extremely helpful resource when developing my Colour Cube LUT. The following was an extremely helpful resource when developing my Colour Cube LUT.
http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter24.html http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter24.html
@ -311,9 +316,12 @@ UINT32 V_GammaCorrect(UINT32 input, double power)
static void LoadPalette(const char *lumpname) static void LoadPalette(const char *lumpname)
{ {
lumpnum_t lumpnum = W_GetNumForName(lumpname); lumpnum_t lumpnum = W_GetNumForName(lumpname);
size_t i, palsize = W_LumpLength(lumpnum)/3; size_t i, palsize;
UINT8 *pal; UINT8 *pal;
currentPaletteSize = W_LumpLength(lumpnum);
palsize = currentPaletteSize / 3;
Cubeapply = InitCube(); Cubeapply = InitCube();
if (pLocalPalette != pMasterPalette) if (pLocalPalette != pMasterPalette)
@ -400,8 +408,24 @@ const char *R_GetPalname(UINT16 num)
const char *GetPalette(void) const char *GetPalette(void)
{ {
const char *user = cv_palette.string;
if (user && user[0])
{
if (W_CheckNumForName(user) == LUMPERROR)
{
CONS_Alert(CONS_WARNING,
"cv_palette %s lump does not exist\n", user);
}
else
{
return cv_palette.string;
}
}
if (gamestate == GS_LEVEL) if (gamestate == GS_LEVEL)
return R_GetPalname((encoremode ? mapheaderinfo[gamemap-1]->encorepal : mapheaderinfo[gamemap-1]->palette)); return R_GetPalname((encoremode ? mapheaderinfo[gamemap-1]->encorepal : mapheaderinfo[gamemap-1]->palette));
return "PLAYPAL"; return "PLAYPAL";
} }
@ -419,6 +443,19 @@ void V_SetPalette(INT32 palettenum)
if (!pLocalPalette) if (!pLocalPalette)
V_ReloadPalette(); V_ReloadPalette();
if (palettenum == 0)
{
palettenum = cv_palettenum.value;
if (palettenum * 256U > currentPaletteSize - 256)
{
CONS_Alert(CONS_WARNING,
"cv_palettenum %d out of range\n",
palettenum);
palettenum = 0;
}
}
#ifdef HWRENDER #ifdef HWRENDER
if (rendermode == render_opengl) if (rendermode == render_opengl)
HWR_SetPalette(&pLocalPalette[palettenum*256]); HWR_SetPalette(&pLocalPalette[palettenum*256]);
@ -433,23 +470,12 @@ void V_SetPalette(INT32 palettenum)
void V_SetPaletteLump(const char *pal) void V_SetPaletteLump(const char *pal)
{ {
LoadPalette(pal); LoadPalette(pal);
#ifdef HWRENDER V_SetPalette(0);
if (rendermode == render_opengl)
HWR_SetPalette(pLocalPalette);
#if (defined (__unix__) && !defined (MSDOS)) || defined (UNIXCOMMON) || defined (HAVE_SDL)
else
#endif
#endif
if (rendermode != render_none)
I_SetPalette(pLocalPalette);
#ifdef HASINVERT
R_MakeInvertmap();
#endif
} }
static void CV_palette_OnChange(void) static void CV_palette_OnChange(void)
{ {
// reload palette // recalculate Color Cube
V_ReloadPalette(); V_ReloadPalette();
V_SetPalette(0); V_SetPalette(0);
} }

View file

@ -34,7 +34,8 @@ extern consvar_t cv_ticrate, cv_constextsize,
cv_globalgamma, cv_globalsaturation, cv_globalgamma, cv_globalsaturation,
cv_rhue, cv_yhue, cv_ghue, cv_chue, cv_bhue, cv_mhue, cv_rhue, cv_yhue, cv_ghue, cv_chue, cv_bhue, cv_mhue,
cv_rgamma, cv_ygamma, cv_ggamma, cv_cgamma, cv_bgamma, cv_mgamma, cv_rgamma, cv_ygamma, cv_ggamma, cv_cgamma, cv_bgamma, cv_mgamma,
cv_rsaturation, cv_ysaturation, cv_gsaturation, cv_csaturation, cv_bsaturation, cv_msaturation; cv_rsaturation, cv_ysaturation, cv_gsaturation, cv_csaturation, cv_bsaturation, cv_msaturation,
cv_palette, cv_palettenum;
// Allocates buffer screens, call before R_Init. // Allocates buffer screens, call before R_Init.
void V_Init(void); void V_Init(void);