cross-fading screen wipe implementation (#1557)

* cross-fading screen wipe implementation

* add config and afjust menu entry

* do not trash the CPU

* fix memory leak
This commit is contained in:
Fabian Greffrath 2024-03-05 15:23:04 +01:00 committed by GitHub
parent 1448fd85b0
commit 27bfa9302d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 60 additions and 28 deletions

View File

@ -448,12 +448,14 @@ void D_Display (void)
int nowtime, tics; int nowtime, tics;
do do
{ {
I_Sleep(1);
nowtime = I_GetTime(); nowtime = I_GetTime();
tics = nowtime - wipestart; tics = nowtime - wipestart;
} }
while (!tics); while (!tics);
wipestart = nowtime; wipestart = nowtime;
done = wipe_ScreenWipe(wipe_Melt, 0, 0, video.unscaledw, SCREENHEIGHT, tics); done = wipe_ScreenWipe(strictmode ? wipe_Melt : screen_melt,
0, 0, video.unscaledw, SCREENHEIGHT, tics);
M_Drawer(); // menu is drawn even on top of wipes M_Drawer(); // menu is drawn even on top of wipes
I_FinishUpdate(); // page flip or blit buffer I_FinishUpdate(); // page flip or blit buffer
} }

View File

@ -23,6 +23,7 @@
#include "f_wipe.h" #include "f_wipe.h"
#include "i_video.h" #include "i_video.h"
#include "m_random.h" #include "m_random.h"
#include "v_flextran.h"
#include "v_video.h" #include "v_video.h"
#include "z_zone.h" #include "z_zone.h"
@ -57,33 +58,47 @@ static void wipe_shittyColMajorXform(byte *array, int width, int height)
Z_Free(dest); Z_Free(dest);
} }
// [FG] cross-fading screen wipe implementation
static int fade_tick;
static int wipe_initColorXForm(int width, int height, int ticks) static int wipe_initColorXForm(int width, int height, int ticks)
{ {
V_PutBlock(0, 0, width, height, wipe_scr_start); V_PutBlock(0, 0, width, height, wipe_scr_start);
fade_tick = 0;
return 0; return 0;
} }
// killough 3/5/98: reformatted and cleaned up
static int wipe_doColorXForm(int width, int height, int ticks) static int wipe_doColorXForm(int width, int height, int ticks)
{ {
boolean unchanged = true; for (int y = 0; y < height; y++)
byte *w = wipe_scr; {
byte *e = wipe_scr_end; byte *sta = wipe_scr_start + y * width;
byte *end = wipe_scr+width*height; byte *end = wipe_scr_end + y * width;
for (;w != end; w++, e++) byte *dst = wipe_scr + y * video.pitch;
if (*w != *e)
{ for (int x = 0; x < width; x++)
int newval; {
unchanged = false; unsigned int *fg2rgb = Col2RGB8[fade_tick];
*w = *w > *e ? unsigned int *bg2rgb = Col2RGB8[64 - fade_tick];
(newval = *w - ticks) < *e ? *e : newval : unsigned int fg, bg;
(newval = *w + ticks) > *e ? *e : newval ;
} fg = fg2rgb[end[x]];
return unchanged; bg = bg2rgb[sta[x]];
fg = (fg + bg) | 0x1f07c1f;
dst[x] = RGB32k[0][0][fg & (fg >> 15)];
}
}
fade_tick += 2 * ticks;
return (fade_tick > 64);
} }
static int wipe_exitColorXForm(int width, int height, int ticks) static int wipe_exit(int width, int height, int ticks)
{ {
Z_Free(wipe_scr_start);
Z_Free(wipe_scr_end);
return 0; return 0;
} }
@ -173,8 +188,7 @@ static int wipe_doMelt(int width, int height, int ticks)
static int wipe_exitMelt(int width, int height, int ticks) static int wipe_exitMelt(int width, int height, int ticks)
{ {
Z_Free(col_y); Z_Free(col_y);
Z_Free(wipe_scr_start); wipe_exit(width, height, ticks);
Z_Free(wipe_scr_end);
return 0; return 0;
} }
@ -195,13 +209,21 @@ int wipe_EndScreen(int x, int y, int width, int height)
return 0; return 0;
} }
static int wipe_NOP(int x, int y, int t)
{
return 0;
}
static int (*const wipes[])(int, int, int) = { static int (*const wipes[])(int, int, int) = {
wipe_initColorXForm, wipe_NOP,
wipe_doColorXForm, wipe_NOP,
wipe_exitColorXForm, wipe_exit,
wipe_initMelt, wipe_initMelt,
wipe_doMelt, wipe_doMelt,
wipe_exitMelt wipe_exitMelt,
wipe_initColorXForm,
wipe_doColorXForm,
wipe_exit,
}; };
// killough 3/5/98: reformatted and cleaned up // killough 3/5/98: reformatted and cleaned up

View File

@ -25,9 +25,9 @@
// //
enum { enum {
// simple gradual pixel change for 8-bit only wipe_None,
wipe_ColorXForm,
wipe_Melt, // weird screen melt wipe_Melt, // weird screen melt
wipe_ColorXForm,
wipe_NUMWIPES wipe_NUMWIPES
}; };

View File

@ -2022,6 +2022,7 @@ enum
str_menu_backdrop, str_menu_backdrop,
str_widescreen, str_widescreen,
str_bobbing_pct, str_bobbing_pct,
str_screen_melt,
str_invul_mode, str_invul_mode,
}; };
@ -4122,6 +4123,10 @@ static const char *menu_backdrop_strings[] = {
"Off", "Dark", "Texture" "Off", "Dark", "Texture"
}; };
static const char *screen_melt_strings[] = {
"Off", "Melt", "Crossfade"
};
static const char *invul_mode_strings[] = { static const char *invul_mode_strings[] = {
"Vanilla", "MBF", "Gray" "Vanilla", "MBF", "Gray"
}; };
@ -4247,7 +4252,8 @@ setup_menu_t gen_settings6[] = {
{"Quality of life", S_SKIP|S_TITLE, m_null, M_X, M_Y}, {"Quality of life", S_SKIP|S_TITLE, m_null, M_X, M_Y},
{"Screen melt", S_ONOFF|S_STRICT, m_null, M_X, M_SPC, {"screen_melt"}}, {"Screen wipe effect", S_CHOICE|S_STRICT, m_null, M_X, M_SPC,
{"screen_melt"}, 0, NULL, str_screen_melt},
{"On death action", S_CHOICE, m_null, M_X, M_SPC, {"On death action", S_CHOICE, m_null, M_X, M_SPC,
{"death_use_action"}, 0, NULL, str_death_use_action}, {"death_use_action"}, 0, NULL, str_death_use_action},
@ -6919,6 +6925,7 @@ static const char **selectstrings[] = {
menu_backdrop_strings, menu_backdrop_strings,
widescreen_strings, widescreen_strings,
bobbing_pct_strings, bobbing_pct_strings,
screen_melt_strings,
invul_mode_strings, invul_mode_strings,
}; };

View File

@ -33,6 +33,7 @@
#include "doomkeys.h" #include "doomkeys.h"
#include "doomstat.h" #include "doomstat.h"
#include "dstrings.h" #include "dstrings.h"
#include "f_wipe.h"
#include "g_game.h" #include "g_game.h"
#include "hu_lib.h" // HU_MAXMESSAGES #include "hu_lib.h" // HU_MAXMESSAGES
#include "hu_obituary.h" #include "hu_obituary.h"
@ -606,8 +607,8 @@ default_t defaults[] = {
{ {
"screen_melt", "screen_melt",
(config_t *) &screen_melt, NULL, (config_t *) &screen_melt, NULL,
{1}, {0,1}, number, ss_gen, wad_no, {wipe_Melt}, {wipe_None, wipe_ColorXForm}, number, ss_gen, wad_no,
"0 to disable screen melt" "screen wipe effect (0 = none, 1 = melt, 2 = crossfade)"
}, },
{ {