Skip to content

Commit

Permalink
A11Y - implement grayscale invulnerability effect
Browse files Browse the repository at this point in the history
Co-Authored-By: pvictress <[email protected]>
  • Loading branch information
JNechaevsky and pvictress committed Nov 23, 2024
1 parent 951b6fb commit 6134038
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 50 deletions.
43 changes: 30 additions & 13 deletions src/doom/m_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ static void M_DrawGameplayFooter (char *pagenum);

static void M_Choose_ID_Misc (int choice);
static void M_Draw_ID_Misc (void);
static void M_ID_Misc_A11yInvul (int choice);
static void M_ID_Misc_AutoloadWAD (int choice);
static void M_ID_Misc_AutoloadDEH (int choice);
static void M_ID_Misc_Hightlight (int choice);
Expand Down Expand Up @@ -3849,6 +3850,8 @@ static void M_DrawGameplayFooter (char *pagenum)

static menuitem_t ID_Menu_Misc[]=
{
{ M_LFRT, "INVULNERABILITY EFFECT", M_ID_Misc_A11yInvul, 'i' },
{ M_SKIP, "", 0, '\0' },
{ M_LFRT, "AUTOLOAD WAD FILES", M_ID_Misc_AutoloadWAD, 'a' },
{ M_LFRT, "AUTOLOAD DEH FILES", M_ID_Misc_AutoloadDEH, 'a' },
{ M_SKIP, "", 0, '\0' },
Expand All @@ -3858,7 +3861,7 @@ static menuitem_t ID_Menu_Misc[]=

static menu_t ID_Def_Misc =
{
5,
7,
&ID_Def_Main,
ID_Menu_Misc,
M_Draw_ID_Misc,
Expand All @@ -3876,42 +3879,49 @@ static void M_Draw_ID_Misc (void)
{
char str[32];

M_WriteTextCentered(9, "AUTOLOAD", cr[CR_YELLOW]);
M_WriteTextCentered(9, "ACCESSIBILITY", cr[CR_YELLOW]);

// Invulnerability effect
sprintf(str, a11y_invul ? "GRAYSCALE" : "DEFAULT");
M_WriteText (M_ItemRightAlign(str), 18, str,
M_Item_Glow(1, a11y_invul ? GLOW_GREEN : GLOW_DARKRED));

M_WriteTextCentered(27, "AUTOLOAD", cr[CR_YELLOW]);

// Autoload WAD files
sprintf(str, autoload_wad == 1 ? "IWAD ONLY" :
autoload_wad == 2 ? "IWAD AND PWAD" : "OFF");
M_WriteText (M_ItemRightAlign(str), 18, str,
M_Item_Glow(0, autoload_wad == 1 ? GLOW_YELLOW :
M_WriteText (M_ItemRightAlign(str), 36, str,
M_Item_Glow(3, autoload_wad == 1 ? GLOW_YELLOW :
autoload_wad == 2 ? GLOW_GREEN : GLOW_DARKRED));

// Autoload DEH patches
sprintf(str, autoload_deh == 1 ? "IWAD ONLY" :
autoload_deh == 2 ? "IWAD AND PWAD" : "OFF");
M_WriteText (M_ItemRightAlign(str), 27, str,
M_Item_Glow(1, autoload_deh == 1 ? GLOW_YELLOW :
M_WriteText (M_ItemRightAlign(str), 45, str,
M_Item_Glow(4, autoload_deh == 1 ? GLOW_YELLOW :
autoload_deh == 2 ? GLOW_GREEN : GLOW_DARKRED));

M_WriteTextCentered(36, "MENU SETTINGS", cr[CR_YELLOW]);
M_WriteTextCentered(54, "MENU SETTINGS", cr[CR_YELLOW]);

// Animation and highlighting
sprintf(str, menu_highlight ? "ON" : "OFF");
M_WriteText (M_ItemRightAlign(str), 45, str,
M_Item_Glow(3, menu_highlight ? GLOW_GREEN : GLOW_DARKRED));
M_WriteText (M_ItemRightAlign(str), 63, str,
M_Item_Glow(6, menu_highlight ? GLOW_GREEN : GLOW_DARKRED));

// ESC key behaviour
sprintf(str, menu_esc_key ? "GO BACK" : "CLOSE MENU" );
M_WriteText (M_ItemRightAlign(str), 54, str,
M_Item_Glow(4, menu_esc_key ? GLOW_GREEN : GLOW_DARKRED));
M_WriteText (M_ItemRightAlign(str), 72, str,
M_Item_Glow(7, menu_esc_key ? GLOW_GREEN : GLOW_DARKRED));

// [PN] Added explanations for autoload variables
if (itemOn == 0 || itemOn == 1)
if (itemOn == 2 || itemOn == 3)
{
const char *off = "AUTOLOAD IS DISABLED";
const char *first_line = "AUTOLOAD AND FOLDER CREATION";
const char *second_line1 = "ONLY ALLOWED FOR IWAD FILES";
const char *second_line2 = "ALLOWED FOR BOTH IWAD AND PWAD FILES";
const int autoload_option = (itemOn == 0) ? autoload_wad : autoload_deh;
const int autoload_option = (itemOn == 2) ? autoload_wad : autoload_deh;

switch (autoload_option)
{
Expand All @@ -3932,6 +3942,13 @@ static void M_Draw_ID_Misc (void)
}
}

static void M_ID_Misc_A11yInvul (int choice)
{
a11y_invul ^= 1;
// [JN] Recalculate colormaps to apply the appropriate invulnerability effect.
R_InitColormaps();
}

static void M_ID_Misc_AutoloadWAD (int choice)
{
autoload_wad = M_INT_Slider(autoload_wad, 0, 2, choice, false);
Expand Down
63 changes: 39 additions & 24 deletions src/doom/r_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -1187,9 +1187,45 @@ void R_InitColormaps (void)
colormaps[j++] = 0xff000000 | (r << 16) | (g << 8) | b;
}
}
}
else
{
for (c = 0; c < NUMCOLORMAPS; c++)
{
for (i = 0; i < 256; i++)
{
// [PN] Apply intensity and saturation corrections
static byte pal[3];
static byte channels[3];

// [crispy] Invulnerability (c == COLORMAPS)
for (i = 0; i < 256; i++)
CALC_INTENSITY(pal, playpal, colormap[c * 256 + i]);
CALC_SATURATION(channels, pal, a_hi, a_lo);

r = gammatable[vid_gamma][channels[0]] & ~3;
g = gammatable[vid_gamma][channels[1]] & ~3;
b = gammatable[vid_gamma][channels[2]] & ~3;

colormaps[j++] = 0xff000000 | (r << 16) | (g << 8) | b;
}
}
}

// [crispy] Invulnerability (c == COLORMAPS)
for (i = 0; i < 256; i++)
{
if (a11y_invul)
{
// [JN] A11Y - grayscale invulnerability effect,
// independendt from COLORMAP lump.
// [PN] Do not use Rec. 601 formula here; weights are
// equalized to balance all color contributions equally.
const byte gray =
(byte)((playpal[3 * i + 0] +
playpal[3 * i + 1] +
playpal[3 * i + 2]) / 3);
r = g = b = gammatable[vid_gamma][gray];
}
else
{
// [JN] Check if we have a modified COLORMAP lump to decide
// how invulnerability effect will be drawn.
Expand Down Expand Up @@ -1220,30 +1256,9 @@ void R_InitColormaps (void)
g = gammatable[vid_gamma][channels[1]] & ~3;
b = gammatable[vid_gamma][channels[2]] & ~3;
}

colormaps[j++] = 0xff000000 | (r << 16) | (g << 8) | b;
}
}
else
{
for (c = 0; c <= NUMCOLORMAPS; c++)
{
for (i = 0; i < 256; i++)
{
// [PN] Apply intensity and saturation corrections
static byte pal[3];
static byte channels[3];

CALC_INTENSITY(pal, playpal, colormap[c * 256 + i]);
CALC_SATURATION(channels, pal, a_hi, a_lo);

r = gammatable[vid_gamma][channels[0]] & ~3;
g = gammatable[vid_gamma][channels[1]] & ~3;
b = gammatable[vid_gamma][channels[2]] & ~3;

colormaps[j++] = 0xff000000 | (r << 16) | (g << 8) | b;
}
}
colormaps[j++] = 0xff000000 | (r << 16) | (g << 8) | b;
}

W_ReleaseLumpName("COLORMAP");
Expand Down
43 changes: 30 additions & 13 deletions src/heretic/mn_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ static void M_ScrollGameplay (int choice);
static void M_DrawGameplayFooter (char *pagenum);

static void M_Draw_ID_Misc (void);
static void M_ID_Misc_A11yInvul (int choice);
static void M_ID_Misc_AutoloadWAD (int choice);
static void M_ID_Misc_AutoloadHHE (int choice);
static void M_ID_Misc_Hightlight (int choice);
Expand Down Expand Up @@ -3611,6 +3612,8 @@ static void M_DrawGameplayFooter (char *pagenum)
// -----------------------------------------------------------------------------

static MenuItem_t ID_Menu_Misc[] = {
{ ITT_LRFUNC, "INVULNERABILITY EFFECT", M_ID_Misc_A11yInvul, 0, MENU_NONE },
{ ITT_EMPTY, NULL, NULL, 0, MENU_NONE },
{ ITT_LRFUNC, "AUTOLOAD WAD FILES", M_ID_Misc_AutoloadWAD, 0, MENU_NONE },
{ ITT_LRFUNC, "AUTOLOAD HHE FILES", M_ID_Misc_AutoloadHHE, 0, MENU_NONE },
{ ITT_EMPTY, NULL, NULL, 0, MENU_NONE },
Expand All @@ -3621,7 +3624,7 @@ static MenuItem_t ID_Menu_Misc[] = {
static Menu_t ID_Def_Misc = {
ID_MENU_CTRLSOFFSET, ID_MENU_TOPOFFSET,
M_Draw_ID_Misc,
5, ID_Menu_Misc,
7, ID_Menu_Misc,
0,
SmallFont, false, true,
MENU_ID_MAIN
Expand All @@ -3631,42 +3634,49 @@ static void M_Draw_ID_Misc (void)
{
char str[32];

MN_DrTextACentered("AUTOLOAD", 10, cr[CR_YELLOW]);
MN_DrTextACentered("ACCESSIBILITY", 10, cr[CR_YELLOW]);

// Invulnerability effect
sprintf(str, a11y_invul ? "GRAYSCALE" : "DEFAULT");
MN_DrTextA(str, M_ItemRightAlign(str), 20,
M_Item_Glow(0, a11y_invul ? GLOW_GREEN : GLOW_DARKRED));

MN_DrTextACentered("AUTOLOAD", 30, cr[CR_YELLOW]);

// Autoload WAD files
sprintf(str, autoload_wad == 1 ? "IWAD ONLY" :
autoload_wad == 2 ? "IWAD AND PWAD" : "OFF");
MN_DrTextA(str, M_ItemRightAlign(str), 20,
M_Item_Glow(0, autoload_wad == 1 ? GLOW_YELLOW :
MN_DrTextA(str, M_ItemRightAlign(str), 40,
M_Item_Glow(2, autoload_wad == 1 ? GLOW_YELLOW :
autoload_wad == 2 ? GLOW_GREEN : GLOW_DARKRED));

// Autoload DEH patches
sprintf(str, autoload_hhe == 1 ? "IWAD ONLY" :
autoload_hhe == 2 ? "IWAD AND PWAD" : "OFF");
MN_DrTextA(str, M_ItemRightAlign(str), 30,
M_Item_Glow(1, autoload_hhe == 1 ? GLOW_YELLOW :
MN_DrTextA(str, M_ItemRightAlign(str), 50,
M_Item_Glow(3, autoload_hhe == 1 ? GLOW_YELLOW :
autoload_hhe == 2 ? GLOW_GREEN : GLOW_DARKRED));

MN_DrTextACentered("MENU SETTINGS", 40, cr[CR_YELLOW]);
MN_DrTextACentered("MENU SETTINGS", 60, cr[CR_YELLOW]);

// Animation and highlighting
sprintf(str, menu_highlight ? "ON" : "OFF");
MN_DrTextA(str, M_ItemRightAlign(str), 50,
M_Item_Glow(3, menu_highlight ? GLOW_GREEN : GLOW_DARKRED));
MN_DrTextA(str, M_ItemRightAlign(str), 70,
M_Item_Glow(5, menu_highlight ? GLOW_GREEN : GLOW_DARKRED));

// ESC key behaviour
sprintf(str, menu_esc_key ? "GO BACK" : "CLOSE MENU");
MN_DrTextA(str, M_ItemRightAlign(str), 60,
M_Item_Glow(4, menu_esc_key ? GLOW_GREEN : GLOW_DARKRED));
MN_DrTextA(str, M_ItemRightAlign(str), 80,
M_Item_Glow(6, menu_esc_key ? GLOW_GREEN : GLOW_DARKRED));

// [PN] Added explanations for autoload variables
if (CurrentItPos == 0 || CurrentItPos == 1)
if (CurrentItPos == 2 || CurrentItPos == 3)
{
const char *off = "AUTOLOAD IS DISABLED";
const char *first_line = "AUTOLOAD AND FOLDER CREATION";
const char *second_line1 = "ONLY ALLOWED FOR IWAD FILES";
const char *second_line2 = "ALLOWED FOR BOTH IWAD AND PWAD FILES";
const int autoload_option = (CurrentItPos == 0) ? autoload_wad : autoload_hhe;
const int autoload_option = (CurrentItPos == 2) ? autoload_wad : autoload_hhe;

switch (autoload_option)
{
Expand All @@ -3687,6 +3697,13 @@ static void M_Draw_ID_Misc (void)
}
}

static void M_ID_Misc_A11yInvul (int choice)
{
a11y_invul ^= 1;
// [JN] Recalculate colormaps to apply the appropriate invulnerability effect.
R_InitColormaps();
}

static void M_ID_Misc_AutoloadWAD (int choice)
{
autoload_wad = M_INT_Slider(autoload_wad, 0, 2, choice, false);
Expand Down
15 changes: 15 additions & 0 deletions src/heretic/r_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,20 @@ void R_InitColormaps(void)
// [crispy] Invulnerability (c == COLORMAPS), generated from COLORMAP lump
for (i = 0; i < 256; i++)
{
if (a11y_invul)
{
// [JN] A11Y - grayscale invulnerability effect,
// independendt from COLORMAP lump.
// [PN] Do not use Rec. 601 formula here; weights are
// equalized to balance all color contributions equally.
const byte gray =
(byte)((playpal[3 * i + 0] +
playpal[3 * i + 1] +
playpal[3 * i + 2]) / 3);
r = g = b = gammatable[vid_gamma][gray];
}
else
{
// [PN] Apply intensity and saturation corrections
static byte pal[3];
static byte channels[3];
Expand All @@ -875,6 +889,7 @@ void R_InitColormaps(void)
r = gammatable[vid_gamma][channels[0]] & ~3;
g = gammatable[vid_gamma][channels[1]] & ~3;
b = gammatable[vid_gamma][channels[2]] & ~3;
}

colormaps[j++] = 0xff000000 | (r << 16) | (g << 8) | b;
}
Expand Down
5 changes: 5 additions & 0 deletions src/id_vars.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ int compat_vertical_aiming = 0;
// Miscellaneous
//

int a11y_invul = 0;
int autoload_wad = 1;
int autoload_deh = 1;
int autoload_hhe = 1;
Expand Down Expand Up @@ -415,6 +416,10 @@ void ID_BindVariables (GameMission_t mission)
{
M_BindIntVariable("autoload_seh", &autoload_seh);
}
if (mission == doom || mission == heretic)
{
M_BindIntVariable("a11y_invul", &a11y_invul);
}
M_BindIntVariable("menu_highlight", &menu_highlight);
M_BindIntVariable("menu_esc_key", &menu_esc_key);
}
1 change: 1 addition & 0 deletions src/id_vars.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ extern int compat_blockmap_fix;
extern int compat_vertical_aiming;

// Miscellaneous
extern int a11y_invul;
extern int autoload_wad;
extern int autoload_deh;
extern int autoload_hhe;
Expand Down
1 change: 1 addition & 0 deletions src/m_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ static default_t doom_defaults_list[] =
CONFIG_VARIABLE_INT(compat_blockmap_fix),
CONFIG_VARIABLE_INT(compat_vertical_aiming),

CONFIG_VARIABLE_INT(a11y_invul),
CONFIG_VARIABLE_INT(menu_highlight),
CONFIG_VARIABLE_INT(menu_esc_key),
};
Expand Down

0 comments on commit 6134038

Please sign in to comment.