From 6adb957f0f836349ee684d366d679505c9cfc0ec Mon Sep 17 00:00:00 2001 From: Jaime Passos Date: Wed, 4 Dec 2019 19:25:39 -0300 Subject: [PATCH 1/5] Slap colormap fades everywhere --- src/d_main.c | 16 ++++++++-- src/f_finale.c | 12 ++++---- src/f_finale.h | 7 ++++- src/f_wipe.c | 80 ++++++++++++++++++++++++++++++++++++++++---------- src/g_game.c | 9 +++--- src/g_game.h | 2 +- src/p_setup.c | 2 +- src/st_stuff.c | 5 ++-- src/st_stuff.h | 2 +- 9 files changed, 100 insertions(+), 35 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 5853fccf0..c26fbad0d 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -274,7 +274,10 @@ static void D_Display(void) && wipetypepre != UINT8_MAX) { F_WipeStartScreen(); - F_WipeColorFill(31); + // Check for Mega Genesis fade + wipestyleflags = WSF_FADEOUT; + if (F_TryColormapFade(31)) + wipetypepost = -1; // Don't run the fade below this one F_WipeEndScreen(); F_RunWipe(wipetypepre, gamestate != GS_TIMEATTACK && gamestate != GS_TITLESCREEN); } @@ -488,15 +491,24 @@ static void D_Display(void) if (rendermode != render_none) { F_WipeEndScreen(); + // Funny. if (WipeStageTitle && st_overlay) { lt_ticker--; lt_lasttic = lt_ticker; - ST_preLevelTitleCardDrawer(0, false); + ST_preLevelTitleCardDrawer(false); V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, levelfadecol); F_WipeStartScreen(); } + + // Check for Mega Genesis fade + if (F_ShouldColormapFade()) + { + wipestyleflags |= WSF_FADEIN; + wipestyleflags &= ~WSF_FADEOUT; + } + F_RunWipe(wipetypepost, gamestate != GS_TIMEATTACK && gamestate != GS_TITLESCREEN); } diff --git a/src/f_finale.c b/src/f_finale.c index 306dad4e9..c33cbc16b 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -910,8 +910,9 @@ void F_IntroDrawer(void) { if (rendermode != render_none) { + wipestyleflags = WSF_FADEOUT; F_WipeStartScreen(); - F_WipeColorFill(31); + F_TryColormapFade(31); F_WipeEndScreen(); F_RunWipe(99,true); } @@ -920,12 +921,11 @@ void F_IntroDrawer(void) } else if (intro_scenenum == 10) { - // The only fade to white in the entire damn game. - // (not true) if (rendermode != render_none) { + wipestyleflags = (WSF_FADEOUT|WSF_TOWHITE); F_WipeStartScreen(); - F_WipeColorFill(0); + F_TryColormapFade(0); F_WipeEndScreen(); F_RunWipe(99,true); } @@ -934,8 +934,9 @@ void F_IntroDrawer(void) { if (rendermode != render_none) { + wipestyleflags = WSF_FADEOUT; F_WipeStartScreen(); - F_WipeColorFill(31); + F_TryColormapFade(31); F_WipeEndScreen(); F_RunWipe(99,true); } @@ -970,6 +971,7 @@ void F_IntroDrawer(void) F_WipeStartScreen(); wipegamestate = -1; + wipestyleflags = WSF_CROSSFADE; animtimer = stoptimer = 0; } diff --git a/src/f_finale.h b/src/f_finale.h index 0002cb3cf..5c03518a1 100644 --- a/src/f_finale.h +++ b/src/f_finale.h @@ -146,7 +146,7 @@ extern boolean WipeStageTitle; typedef enum { WIPESTYLE_NORMAL, - WIPESTYLE_LEVEL + WIPESTYLE_COLORMAP } wipestyle_t; extern wipestyle_t wipestyle; @@ -159,6 +159,11 @@ typedef enum } wipestyleflags_t; extern wipestyleflags_t wipestyleflags; +// Even my function names are borderline +boolean F_ShouldColormapFade(void); +boolean F_TryColormapFade(UINT8 wipecolor); +void F_DecideWipeStyle(void); + #define FADECOLORMAPDIV 8 #define FADECOLORMAPROWS (256/FADECOLORMAPDIV) diff --git a/src/f_wipe.c b/src/f_wipe.c index b88b39ef0..ea52042a5 100644 --- a/src/f_wipe.c +++ b/src/f_wipe.c @@ -161,7 +161,7 @@ static fademask_t *F_GetFadeMask(UINT8 masknum, UINT8 scrnnum) { { // Determine pixel to use from fademask pcolor = &pMasterPalette[*lump++]; - if (wipestyle == WIPESTYLE_LEVEL) + if (wipestyle == WIPESTYLE_COLORMAP) *mask++ = pcolor->s.red / FADECOLORMAPDIV; else *mask++ = FixedDiv((pcolor->s.red+1)<>FRACBITS; @@ -191,7 +191,7 @@ void F_WipeStageTitle(void) { // draw level title if ((WipeStageTitle && st_overlay) - && (wipestyle == WIPESTYLE_LEVEL) + && (wipestyle == WIPESTYLE_COLORMAP) && !(mapheaderinfo[gamemap-1]->levelflags & LF_NOTITLECARD) && *mapheaderinfo[gamemap-1]->lvlttl != '\0') { @@ -282,7 +282,7 @@ static void F_DoWipe(fademask_t *fademask) relativepos += vid.width; } } - else if (*mask >= ((wipestyle == WIPESTYLE_LEVEL) ? FADECOLORMAPROWS : 10)) + else if (*mask >= ((wipestyle == WIPESTYLE_COLORMAP) ? FADECOLORMAPROWS : 10)) { // shortcut - memcpy target to work while (draw_linestogo--) @@ -293,7 +293,7 @@ static void F_DoWipe(fademask_t *fademask) } else { - if (wipestyle == WIPESTYLE_LEVEL) + if (wipestyle == WIPESTYLE_COLORMAP) { int nmask; UINT8 *fade = fadecolormap; @@ -321,7 +321,7 @@ static void F_DoWipe(fademask_t *fademask) e = e_base + relativepos; draw_rowstogo = draw_rowend - draw_rowstart; - if (wipestyle == WIPESTYLE_LEVEL) + if (wipestyle == WIPESTYLE_COLORMAP) { while (draw_rowstogo--) *w++ = transtbl[*e++]; @@ -382,6 +382,62 @@ void F_WipeEndScreen(void) #endif } +/** Verifies every condition for a colormapped fade. + */ +boolean F_ShouldColormapFade(void) +{ + if ((wipestyleflags & (WSF_FADEIN|WSF_FADEOUT)) // only if one of those wipestyleflags are actually set + && !(wipestyleflags & WSF_CROSSFADE)) // and if not crossfading + { + // World + return (gamestate == GS_LEVEL + || gamestate == GS_TITLESCREEN + // Finales + || gamestate == GS_CONTINUING + || gamestate == GS_CREDITS + || gamestate == GS_EVALUATION + || gamestate == GS_INTRO + || gamestate == GS_ENDING + // Menus + || gamestate == GS_TIMEATTACK); + } + return false; +} + +/** Decides what wipe style to use. + */ +void F_DecideWipeStyle(void) +{ + // Set default wipe style + wipestyle = WIPESTYLE_NORMAL; + + // Check for colormap wipe style + if (F_ShouldColormapFade()) + wipestyle = WIPESTYLE_COLORMAP; +} + +/** Attempt to run a colormap fade, + provided all the conditionals were properly met. + Returns true if so. + I demand you call F_RunWipe after this function. + */ +boolean F_TryColormapFade(UINT8 wipecolor) +{ + if (F_ShouldColormapFade()) + { +#ifdef HWRENDER + if (rendermode == render_opengl) + F_WipeColorFill(wipecolor); +#endif + return true; + } + else + { + F_WipeColorFill(wipecolor); + return false; + } +} + /** After setting up the screens you want to wipe, * calling this will do a 'typical' wipe. */ @@ -399,18 +455,10 @@ void F_RunWipe(UINT8 wipetype, boolean drawMenu) paldiv = FixedDiv(257<levelflags & LF_NOTITLECARD) @@ -1828,7 +1825,7 @@ void G_StartTitleCard(void) // // Run the title card before fading in to the level. // -void G_PreLevelTitleCard(tic_t ticker, boolean update) +void G_PreLevelTitleCard(void) { tic_t starttime = I_GetTime(); tic_t endtime = starttime + (PRELEVELTIME*NEWTICRATERATIO); @@ -1842,13 +1839,15 @@ void G_PreLevelTitleCard(tic_t ticker, boolean update) lasttime = nowtime; ST_runTitleCard(); - ST_preLevelTitleCardDrawer(ticker, update); + ST_preLevelTitleCardDrawer(true); if (moviemode) M_SaveFrame(); if (takescreenshot) // Only take screenshots after drawing. M_DoScreenShot(); } + if (!st_overlay) + wipestyleflags = WSF_CROSSFADE; } INT32 pausedelay = 0; diff --git a/src/g_game.h b/src/g_game.h index 0a575c099..b4898a68f 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -141,7 +141,7 @@ void G_DeferedInitNew(boolean pultmode, const char *mapname, INT32 pickedchar, boolean SSSG, boolean FLS); void G_DoLoadLevel(boolean resetplayer); void G_StartTitleCard(void); -void G_PreLevelTitleCard(tic_t ticker, boolean update); +void G_PreLevelTitleCard(void); void G_DeferedPlayDemo(const char *demo); // Can be called by the startup code or M_Responder, calls P_SetupLevel. diff --git a/src/p_setup.c b/src/p_setup.c index 9054b582c..520f3136d 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3265,7 +3265,7 @@ boolean P_SetupLevel(boolean skipprecip) // If so... if ((!(mapheaderinfo[gamemap-1]->levelflags & LF_NOTITLECARD)) && (*mapheaderinfo[gamemap-1]->lvlttl != '\0')) - G_PreLevelTitleCard(lt_ticker, true); + G_PreLevelTitleCard(); return true; } diff --git a/src/st_stuff.c b/src/st_stuff.c index 3a8a4d2f1..8e255a46e 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -1348,11 +1348,10 @@ luahook: // // Drawer for G_PreLevelTitleCard. // -void ST_preLevelTitleCardDrawer(tic_t ticker, boolean update) +void ST_preLevelTitleCardDrawer(boolean update) { V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, levelfadecol); - if (ticker < PRELEVELTIME-1) - ST_drawWipeTitleCard(); + ST_drawWipeTitleCard(); I_OsPolling(); I_UpdateNoBlit(); diff --git a/src/st_stuff.h b/src/st_stuff.h index 33ffa957a..325114af5 100644 --- a/src/st_stuff.h +++ b/src/st_stuff.h @@ -52,7 +52,7 @@ void ST_startTitleCard(void); void ST_runTitleCard(void); void ST_drawTitleCard(void); void ST_preDrawTitleCard(void); -void ST_preLevelTitleCardDrawer(tic_t ticker, boolean update); +void ST_preLevelTitleCardDrawer(boolean update); void ST_drawWipeTitleCard(void); extern tic_t lt_ticker, lt_lasttic; From 7384522aef5dcd85ac5ef3171571c120e1887143 Mon Sep 17 00:00:00 2001 From: Jaime Passos Date: Thu, 5 Dec 2019 01:47:51 -0300 Subject: [PATCH 2/5] Fix Continue game state wipes --- src/f_finale.c | 2 ++ src/f_wipe.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/f_finale.c b/src/f_finale.c index c33cbc16b..73a82523f 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -3569,6 +3569,8 @@ void F_StartContinue(void) return; } + wipestyleflags = WSF_FADEOUT; + F_TryColormapFade(31); G_SetGamestate(GS_CONTINUING); gameaction = ga_nothing; diff --git a/src/f_wipe.c b/src/f_wipe.c index ea52042a5..f9d03a149 100644 --- a/src/f_wipe.c +++ b/src/f_wipe.c @@ -56,7 +56,7 @@ UINT8 wipedefs[NUMWIPEDEFS] = { 0, // wipe_level_toblack UINT8_MAX, // wipe_intermission_toblack - UINT8_MAX, // wipe_continuing_toblack + 0, // wipe_continuing_toblack 0, // wipe_titlescreen_toblack 0, // wipe_timeattack_toblack 99, // wipe_credits_toblack From ed34cb8d793692694a0a2694af00ec68793a5f5c Mon Sep 17 00:00:00 2001 From: Jaime Passos Date: Thu, 5 Dec 2019 16:25:19 -0300 Subject: [PATCH 3/5] Change st_overlay to cv_showhud.value --- src/g_game.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/g_game.c b/src/g_game.c index 6b987646a..4df8071ad 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -1847,7 +1847,7 @@ void G_PreLevelTitleCard(void) if (takescreenshot) // Only take screenshots after drawing. M_DoScreenShot(); } - if (!st_overlay) + if (!cv_showhud.value) wipestyleflags = WSF_CROSSFADE; } From 9340557d2de00ecdd8d3c4604ff92206c852a986 Mon Sep 17 00:00:00 2001 From: Jaime Passos Date: Wed, 11 Dec 2019 13:09:27 -0300 Subject: [PATCH 4/5] Update f_wipe.c --- src/f_wipe.c | 152 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 121 insertions(+), 31 deletions(-) diff --git a/src/f_wipe.c b/src/f_wipe.c index 829bceae0..fc6fc6b6d 100644 --- a/src/f_wipe.c +++ b/src/f_wipe.c @@ -282,7 +282,7 @@ static void F_DoWipe(fademask_t *fademask) relativepos += vid.width; } } - else if (*mask >= ((wipestyle == WIPESTYLE_COLORMAP) ? FADECOLORMAPROWS : 10)) + else if (*mask >= 10) { // shortcut - memcpy target to work while (draw_linestogo--) @@ -293,25 +293,8 @@ static void F_DoWipe(fademask_t *fademask) } else { - if (wipestyle == WIPESTYLE_COLORMAP) - { - int nmask; - UINT8 *fade = fadecolormap; - - if (wipestyleflags & WSF_TOWHITE) - fade = fadecolormap + (FADECOLORMAPROWS * 256); - - nmask = *mask; - if (wipestyleflags & WSF_FADEIN) - nmask = (FADECOLORMAPROWS-1) - nmask; - - transtbl = fade + (nmask * 256); - } - else - { - // pointer to transtable that this mask would use - transtbl = transtables + ((9 - *mask)<= fademask->width) + ++masky, maskx = 0; + } while (++mask < maskend); + + free(scrxpos); + free(scrypos); + } +} + +static void F_DoColormapWipe(fademask_t *fademask, UINT8 *colormap) +{ + // Lactozilla: F_DoWipe for WIPESTYLE_COLORMAP + { + // wipe screen, start, end + UINT8 *w = wipe_scr; + const UINT8 *s = wipe_scr_start; + const UINT8 *e = wipe_scr_end; + + // first pixel for each screen + UINT8 *w_base = w; + const UINT8 *s_base = s; + const UINT8 *e_base = e; + + // mask data, end + UINT8 *transtbl; + const UINT8 *mask = fademask->mask; + const UINT8 *maskend = mask + fademask->size; + + // rectangle draw hints + UINT32 draw_linestart, draw_rowstart; + UINT32 draw_lineend, draw_rowend; + UINT32 draw_linestogo, draw_rowstogo; + + // rectangle coordinates, etc. + UINT16* scrxpos = (UINT16*)malloc((fademask->width + 1) * sizeof(UINT16)); + UINT16* scrypos = (UINT16*)malloc((fademask->height + 1) * sizeof(UINT16)); + UINT16 maskx, masky; + UINT32 relativepos; + + // --- + // Screw it, we do the fixed point math ourselves up front. + scrxpos[0] = 0; + for (relativepos = 0, maskx = 1; maskx < fademask->width; ++maskx) + scrxpos[maskx] = (relativepos += fademask->xscale)>>FRACBITS; + scrxpos[fademask->width] = vid.width; + + scrypos[0] = 0; + for (relativepos = 0, masky = 1; masky < fademask->height; ++masky) + scrypos[masky] = (relativepos += fademask->yscale)>>FRACBITS; + scrypos[fademask->height] = vid.height; + // --- + + maskx = masky = 0; + do + { + draw_rowstart = scrxpos[maskx]; + draw_rowend = scrxpos[maskx + 1]; + draw_linestart = scrypos[masky]; + draw_lineend = scrypos[masky + 1]; + + relativepos = (draw_linestart * vid.width) + draw_rowstart; + draw_linestogo = draw_lineend - draw_linestart; + + if (*mask == 0) + { + // shortcut - memcpy source to work + while (draw_linestogo--) + { + M_Memcpy(w_base+relativepos, s_base+relativepos, draw_rowend-draw_rowstart); + relativepos += vid.width; + } + } + else if (*mask >= FADECOLORMAPROWS) + { + // shortcut - memcpy target to work + while (draw_linestogo--) + { + M_Memcpy(w_base+relativepos, e_base+relativepos, draw_rowend-draw_rowstart); + relativepos += vid.width; + } + } + else + { + int nmask = *mask; + if (wipestyleflags & WSF_FADEIN) + nmask = (FADECOLORMAPROWS-1) - nmask; + + transtbl = colormap + (nmask * 256); + + // DRAWING LOOP + while (draw_linestogo--) + { + w = w_base + relativepos; + s = s_base + relativepos; + e = e_base + relativepos; + draw_rowstogo = draw_rowend - draw_rowstart; + + while (draw_rowstogo--) + *w++ = transtbl[*e++]; relativepos += vid.width; } @@ -484,7 +564,17 @@ void F_RunWipe(UINT8 wipetype, boolean drawMenu) } else #endif - F_DoWipe(fmask); + { + if (wipestyle == WIPESTYLE_COLORMAP) + { + UINT8 *colormap = fadecolormap; + if (wipestyleflags & WSF_TOWHITE) + colormap += (FADECOLORMAPROWS * 256); + F_DoColormapWipe(fmask, colormap); + } + else + F_DoWipe(fmask); + } if (wipestyle == WIPESTYLE_COLORMAP) F_WipeStageTitle(); From 37679bb44e94779d8ae9c4804030cc77ccfd3ccc Mon Sep 17 00:00:00 2001 From: Jaime Passos Date: Wed, 11 Dec 2019 13:26:28 -0300 Subject: [PATCH 5/5] Organise --- src/f_wipe.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/f_wipe.c b/src/f_wipe.c index fc6fc6b6d..a83d104f2 100644 --- a/src/f_wipe.c +++ b/src/f_wipe.c @@ -553,32 +553,40 @@ void F_RunWipe(UINT8 wipetype, boolean drawMenu) I_Sleep(); lastwipetic = nowtime; + // Wipe styles + if (wipestyle == WIPESTYLE_COLORMAP) + { #ifdef HWRENDER - if (rendermode == render_opengl) - { - // send in the wipe type and wipe frame because we need to cache the graphic - if (wipestyle == WIPESTYLE_COLORMAP) + if (rendermode == render_opengl) + { + // send in the wipe type and wipe frame because we need to cache the graphic HWR_DoTintedWipe(wipetype, wipeframe-1); + } else - HWR_DoWipe(wipetype, wipeframe-1); - } - else #endif - { - if (wipestyle == WIPESTYLE_COLORMAP) { UINT8 *colormap = fadecolormap; if (wipestyleflags & WSF_TOWHITE) colormap += (FADECOLORMAPROWS * 256); F_DoColormapWipe(fmask, colormap); } + + // Draw the title card above the wipe + F_WipeStageTitle(); + } + else + { +#ifdef HWRENDER + if (rendermode == render_opengl) + { + // send in the wipe type and wipe frame because we need to cache the graphic + HWR_DoWipe(wipetype, wipeframe-1); + } else +#endif F_DoWipe(fmask); } - if (wipestyle == WIPESTYLE_COLORMAP) - F_WipeStageTitle(); - I_OsPolling(); I_UpdateNoBlit();