Skip to content

Commit

Permalink
Strife: crossfade code improvements (#1204)
Browse files Browse the repository at this point in the history
* Better comments and fail-safe counter handling.
* Fixed memory leak.
  • Loading branch information
JNechaevsky authored Jun 19, 2024
1 parent 79949ce commit 5ad5f9d
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/strife/f_wipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ static pixel_t* wipe_scr_end;
static pixel_t* wipe_scr;

// [crispy] Additional fail-safe counter for performing crossfade effect.
// Vanilla Strife goes into an infinite loop when using an imprecise XLATAB
// during a crossfade, so we stop it when the counter reaches zero. It also
// acts as an opacity multiplier in TrueColor mode.
static int fade_counter;

void
Expand Down Expand Up @@ -75,9 +78,9 @@ wipe_initColorXForm
int ticks )
{
memcpy(wipe_scr, wipe_scr_start, width*height*sizeof(*wipe_scr));
// [crispy] arm fail-safe crossfade counter with
// 13 screen transitions, "zero" count won't be used.
fade_counter = 14;
// [crispy] arm fail-safe crossfade counter with 13 screen transitions
// to make crossfading duration identical to Vanilla Strife
fade_counter = 13;
return 0;
}

Expand All @@ -101,24 +104,25 @@ wipe_doColorXForm
boolean changed = false;

// [crispy] reduce fail-safe crossfade counter tics
fade_counter--;

if (fade_counter--)
{
for(i = pix; i > 0; i--)
{
if(*cur_screen != *end_screen && fade_counter)
if(*cur_screen != *end_screen)
{
changed = true;
#ifndef CRISPY_TRUECOLOR
*cur_screen = xlatab[(*cur_screen << 8) + *end_screen];
#else
// [crispy] perform crossfading effect with 13 given opacity steps, multipled by 19:
// 247, 228, 209, 190, 171, 152, 133, 114, 95, 76, 57, 38, 19
*cur_screen = I_BlendOver(*end_screen, *cur_screen, fade_counter * 19);
// [crispy] perform TrueColour blending with the following 13 opacity levels:
// 250, 230, 210, 190, 170, 150, 130, 110, 90, 70, 50, 30, 10
*cur_screen = I_BlendOver(*end_screen, *cur_screen, (fade_counter * 20) + 10);
#endif
}
++cur_screen;
++end_screen;
}
}

return !changed;
}
Expand All @@ -130,6 +134,11 @@ wipe_exitColorXForm
int height,
int ticks )
{
// [crispy] fix memory leak - crossfade calls wipe_exitColorXForm instead of
// wipe_exitMelt, so we need to do a memory cleanup in this function
Z_Free(wipe_scr_start);
Z_Free(wipe_scr_end);
Z_Free(wipe_scr);
return 0;
}

Expand Down

0 comments on commit 5ad5f9d

Please sign in to comment.