From 36e4f25cc9d32125f2113609f9489f2080195e49 Mon Sep 17 00:00:00 2001 From: TehRealSalt Date: Wed, 7 Aug 2019 02:21:04 -0400 Subject: [PATCH] Uses pre-defined colormap lumps now Works much faster now. I'd like to clean up this code some though --- src/d_main.c | 4 +- src/f_finale.c | 8 +-- src/f_finale.h | 2 +- src/f_wipe.c | 141 +++++++++++++++++++------------------------------ src/p_setup.c | 6 +-- 5 files changed, 65 insertions(+), 96 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 1404a5e61..a6bd48e0e 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -325,7 +325,7 @@ static void D_Display(void) F_WipeStartScreen(); V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 31); F_WipeEndScreen(); - F_RunWipe(wipedefs[wipedefindex], gamestate != GS_TIMEATTACK); + F_RunWipe(wipedefs[wipedefindex], gamestate != GS_TIMEATTACK, "FADEMAP0", false); } if (gamestate != GS_LEVEL && rendermode != render_none) @@ -556,7 +556,7 @@ static void D_Display(void) if (rendermode != render_none) { F_WipeEndScreen(); - F_RunWipe(wipedefs[wipedefindex], gamestate != GS_TIMEATTACK); + F_RunWipe(wipedefs[wipedefindex], gamestate != GS_TIMEATTACK, "FADEMAP0", true); } } diff --git a/src/f_finale.c b/src/f_finale.c index 9a4be070c..d45a9cfa9 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -220,7 +220,7 @@ void F_StartIntro(void) F_WipeStartScreen(); V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 31); F_WipeEndScreen(); - F_RunWipe(wipedefs[wipe_level_final], false); + F_RunWipe(wipedefs[wipe_level_final], false, "FADEMAP0", false); } if (introtoplay) @@ -306,7 +306,7 @@ void F_IntroDrawer(void) F_WipeStartScreen(); V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 31); F_WipeEndScreen(); - F_RunWipe(99,true); + F_RunWipe(99, true, "FADEMAP0", false); } // Stay on black for a bit. =) @@ -1420,7 +1420,7 @@ void F_CutsceneDrawer(void) V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, cutscenes[cutnum]->scene[scenenum].fadecolor); F_WipeEndScreen(); - F_RunWipe(cutscenes[cutnum]->scene[scenenum].fadeinid, true); + F_RunWipe(cutscenes[cutnum]->scene[scenenum].fadeinid, true, NULL, false); F_WipeStartScreen(); } @@ -1440,7 +1440,7 @@ void F_CutsceneDrawer(void) if (dofadenow && rendermode != render_none) { F_WipeEndScreen(); - F_RunWipe(cutscenes[cutnum]->scene[scenenum].fadeoutid, true); + F_RunWipe(cutscenes[cutnum]->scene[scenenum].fadeoutid, true, NULL, false); } V_DrawString(textxpos, textypos, 0, cutscene_disptext); diff --git a/src/f_finale.h b/src/f_finale.h index 45166e03d..a6fccf888 100644 --- a/src/f_finale.h +++ b/src/f_finale.h @@ -74,7 +74,7 @@ extern INT32 lastwipetic; void F_WipeStartScreen(void); void F_WipeEndScreen(void); -void F_RunWipe(UINT8 wipetype, boolean drawMenu); +void F_RunWipe(UINT8 wipetype, boolean drawMenu, const char *colormap, boolean reverse); enum { diff --git a/src/f_wipe.c b/src/f_wipe.c index 842161a62..0abef4ca7 100644 --- a/src/f_wipe.c +++ b/src/f_wipe.c @@ -18,12 +18,9 @@ #include "i_video.h" #include "v_video.h" -#ifdef GENESIS_WIPE #include "r_data.h" // NearestColor -#else #include "r_draw.h" // transtable #include "p_pspr.h" // tr_transxxx -#endif #include "w_wad.h" #include "z_zone.h" @@ -93,6 +90,9 @@ boolean WipeInAction = false; INT32 lastwipetic = 0; #ifndef NOWIPE + +#define GENLEN 31 + static UINT8 *wipe_scr_start; //screen 3 static UINT8 *wipe_scr_end; //screen 4 static UINT8 *wipe_scr; //screen 0 (main drawing) @@ -189,7 +189,7 @@ static fademask_t *F_GetFadeMask(UINT8 masknum, UINT8 scrnnum) { * * \param fademask pixels to change */ -static void F_DoWipe(fademask_t *fademask) +static void F_DoWipe(fademask_t *fademask, lighttable_t *fadecolormap, boolean reverse) { // Software mask wipe -- optimized; though it might not look like it! // Okay, to save you wondering *how* this is more optimized than the simpler @@ -207,6 +207,10 @@ static void F_DoWipe(fademask_t *fademask) // look a little messy; sorry!) but it simultaneously runs at twice the speed. // In addition, we precalculate all the X and Y positions that we need to draw // from and to, so it uses a little extra memory, but again, helps it run faster. + // --- + // Sal: I kinda destroyed some of this code by introducing Genesis-style fades. + // A colormap can be provided in F_RunWipe, which the white/black values will be + // remapped to the appropriate entry in the fade colormap. { // wipe screen, start, end UINT8 *w = wipe_scr; @@ -219,12 +223,7 @@ static void F_DoWipe(fademask_t *fademask) const UINT8 *e_base = e; // mask data, end -#ifdef GENESIS_WIPE - UINT8 i; - RGBA_t wcolor, *ecolor; -#else - UINT8 *transtbl; -#endif + UINT8 *transtbl; const UINT8 *mask = fademask->mask; const UINT8 *maskend = mask + fademask->size; @@ -255,6 +254,8 @@ static void F_DoWipe(fademask_t *fademask) maskx = masky = 0; do { + UINT8 m = *mask; + draw_rowstart = scrxpos[maskx]; draw_rowend = scrxpos[maskx + 1]; draw_linestart = scrypos[masky]; @@ -263,27 +264,32 @@ static void F_DoWipe(fademask_t *fademask) relativepos = (draw_linestart * vid.width) + draw_rowstart; draw_linestogo = draw_lineend - draw_linestart; - if (*mask == 0) + if (reverse) + m = ((pallen-1) - m); + + if (m == 0) { // shortcut - memcpy source to work while (draw_linestogo--) { - M_Memcpy(w_base+relativepos, s_base+relativepos, draw_rowend-draw_rowstart); + M_Memcpy(w_base+relativepos, (reverse ? e_base : s_base)+relativepos, draw_rowend-draw_rowstart); relativepos += vid.width; } } - else if (*mask == pallen) + else if (m >= (pallen-1)) { // shortcut - memcpy target to work while (draw_linestogo--) { - M_Memcpy(w_base+relativepos, e_base+relativepos, draw_rowend-draw_rowstart); + M_Memcpy(w_base+relativepos, (reverse ? s_base : e_base)+relativepos, draw_rowend-draw_rowstart); relativepos += vid.width; } } else { -#ifdef GENESIS_WIPE + // pointer to transtable that this mask would use + transtbl = transtables + ((9 - m)<s.red) > 34) - { - if (wcolor.s.red < ecolor->s.red) - wcolor.s.red += 34; - else - wcolor.s.red -= 34; - } + if (reverse) + *w++ = fadecolormap[ ( m << 8 ) + *e++ ]; else - { - wcolor.s.red = ecolor->s.red; - - if (abs(wcolor.s.green - ecolor->s.green) > 34) - { - if (wcolor.s.green < ecolor->s.green) - wcolor.s.green += 34; - else - wcolor.s.green -= 34; - } - else - { - wcolor.s.green = ecolor->s.green; - - if (abs(wcolor.s.blue - ecolor->s.blue) > 34) - { - if (wcolor.s.blue < ecolor->s.blue) - wcolor.s.blue += 34; - else - wcolor.s.blue -= 34; - - } - else - wcolor.s.blue = ecolor->s.blue; - } - } + *w++ = fadecolormap[ ( m << 8 ) + *s++ ]; } - - *w++ = NearestColor(wcolor.s.red, wcolor.s.green, wcolor.s.blue); + else + *w++ = transtbl[ ( *e++ << 8 ) + *s++ ]; } relativepos += vid.width; } // END DRAWING LOOP -#else - // pointer to transtable that this mask would use - transtbl = transtables + ((9 - *mask)<= fademask->width) @@ -415,23 +364,36 @@ void F_WipeEndScreen(void) /** After setting up the screens you want to wipe, * calling this will do a 'typical' wipe. */ -void F_RunWipe(UINT8 wipetype, boolean drawMenu) +void F_RunWipe(UINT8 wipetype, boolean drawMenu, const char *colormap, boolean reverse) { #ifdef NOWIPE (void)wipetype; (void)drawMenu; + (void)colormap; + (void)reverse; #else tic_t nowtime; UINT8 wipeframe = 0; fademask_t *fmask; -#ifndef GENESIS_WIPE - pallen = 21; // 21 steps -#else - pallen = 10; // 10 steps -#endif + lumpnum_t clump; + lighttable_t *fcolor = NULL; - paldiv = FixedDiv(257<