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;
do
{
I_Sleep(1);
nowtime = I_GetTime();
tics = nowtime - wipestart;
}
while (!tics);
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
I_FinishUpdate(); // page flip or blit buffer
}

View File

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

View File

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

View File

@ -2022,6 +2022,7 @@ enum
str_menu_backdrop,
str_widescreen,
str_bobbing_pct,
str_screen_melt,
str_invul_mode,
};
@ -4122,6 +4123,10 @@ static const char *menu_backdrop_strings[] = {
"Off", "Dark", "Texture"
};
static const char *screen_melt_strings[] = {
"Off", "Melt", "Crossfade"
};
static const char *invul_mode_strings[] = {
"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},
{"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,
{"death_use_action"}, 0, NULL, str_death_use_action},
@ -6919,6 +6925,7 @@ static const char **selectstrings[] = {
menu_backdrop_strings,
widescreen_strings,
bobbing_pct_strings,
screen_melt_strings,
invul_mode_strings,
};

View File

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