From 0fd37165ffe1b0f1df35b549ff95a8786399cee9 Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Sat, 23 Nov 2024 17:13:43 +0700 Subject: [PATCH] fix id24 interlevel animation for 1-3 episodes of Doom 1 (#2036) * fix double duration for first frame * refactoring --- src/wi_stuff.c | 127 +++++++++++++++++++++++-------------------------- 1 file changed, 60 insertions(+), 67 deletions(-) diff --git a/src/wi_stuff.c b/src/wi_stuff.c index be31b1c6d..77276e8f0 100644 --- a/src/wi_stuff.c +++ b/src/wi_stuff.c @@ -407,9 +407,6 @@ typedef struct interlevel_t *interlevel_exiting; interlevel_t *interlevel_entering; - wi_animationstate_t *exiting_states; - wi_animationstate_t *entering_states; - wi_animationstate_t *states; char *background_lump; } wi_animation_t; @@ -487,10 +484,15 @@ static boolean CheckConditions(interlevelcond_t *conditions, return conditionsmet; } -static void UpdateAnimationStates(wi_animationstate_t *states) +static boolean UpdateAnimation(void) { + if (!animation || !animation->states) + { + return false; + } + wi_animationstate_t *state; - array_foreach(state, states) + array_foreach(state, animation->states) { interlevelframe_t *frame = &state->frames[state->frame_index]; @@ -501,6 +503,17 @@ static void UpdateAnimationStates(wi_animationstate_t *states) if (state->duration_left == 0) { + if (!state->frame_start) + { + state->frame_index++; + if (state->frame_index == array_size(state->frames)) + { + state->frame_index = 0; + } + + frame = &state->frames[state->frame_index]; + } + int tics = 1; switch (frame->type) { @@ -525,49 +538,11 @@ static void UpdateAnimationStates(wi_animationstate_t *states) } state->duration_left = MAX(tics, 1); - - if (!state->frame_start) - { - state->frame_index++; - if (state->frame_index == array_size(state->frames)) - { - state->frame_index = 0; - } - } } state->duration_left--; state->frame_start = false; } -} - -static boolean UpdateAnimation(boolean enteringcondition) -{ - if (!animation) - { - return false; - } - - animation->states = NULL; - animation->background_lump = NULL; - - if (!enteringcondition) - { - if (animation->interlevel_exiting) - { - animation->states = animation->exiting_states; - animation->background_lump = - animation->interlevel_exiting->background_lump; - } - } - else if (animation->interlevel_entering) - { - animation->states = animation->entering_states; - animation->background_lump = - animation->interlevel_entering->background_lump; - } - - UpdateAnimationStates(animation->states); return true; } @@ -634,31 +609,42 @@ static wi_animationstate_t *SetupAnimationStates(interlevellayer_t *layers, return states; } -static boolean SetupAnimation(void) +static boolean SetupAnimation(boolean enteringcondition) { if (!animation) { return false; } - if (animation->interlevel_exiting) + interlevel_t *interlevel = NULL; + if (!enteringcondition) + { + if (animation->interlevel_exiting) + { + interlevel = animation->interlevel_exiting; + } + } + else if (animation->interlevel_entering) { - animation->exiting_states = - SetupAnimationStates(animation->interlevel_exiting->layers, false); + interlevel = animation->interlevel_entering; } - if (animation->interlevel_entering) + if (interlevel) { - animation->entering_states = - SetupAnimationStates(animation->interlevel_entering->layers, true); + animation->states = + SetupAnimationStates(interlevel->layers, enteringcondition); + animation->background_lump = interlevel->background_lump; + return true; } - return true; + animation->states = NULL; + animation->background_lump = NULL; + return false; } static boolean NextLocAnimation(void) { - if (animation && animation->entering_states + if (animation && animation->interlevel_entering && !(demorecording || demoplayback)) { return true; @@ -667,30 +653,34 @@ static boolean NextLocAnimation(void) return false; } -static boolean UpdateMusic(boolean enteringcondition) +static boolean SetupMusic(boolean enteringcondition) { if (!animation) { return false; } - int musicnum = -1; - if (enteringcondition) + interlevel_t *interlevel = NULL; + if (!enteringcondition) { - if (animation->interlevel_entering) + if (animation->interlevel_exiting) { - musicnum = W_GetNumForName(animation->interlevel_entering->music_lump); + interlevel = animation->interlevel_exiting; } } - else if (animation->interlevel_exiting) + else if (animation->interlevel_entering) { - musicnum = W_GetNumForName(animation->interlevel_exiting->music_lump); + interlevel = animation->interlevel_entering; } - if (musicnum > 0) + if (interlevel) { - S_ChangeMusInfoMusic(musicnum, true); - return true; + int musicnum = W_GetNumForName(interlevel->music_lump); + if (musicnum >= 0) + { + S_ChangeMusInfoMusic(musicnum, true); + return true; + } } return false; @@ -902,7 +892,7 @@ static void WI_initAnimatedBack(boolean firstcall) int i; anim_t* a; - if (SetupAnimation()) + if (SetupAnimation(state != StatCount)) { return; } @@ -953,7 +943,7 @@ static void WI_updateAnimatedBack(void) int i; anim_t* a; - if (UpdateAnimation(state != StatCount)) + if (UpdateAnimation()) { return; } @@ -1314,7 +1304,7 @@ static boolean snl_pointeron = false; // static void WI_initShowNextLoc(void) { - UpdateMusic(true); + SetupMusic(true); if (gamemapinfo) { @@ -1396,7 +1386,9 @@ static void WI_drawShowNextLoc(void) WI_drawEL(); // "Entering..." if not E1 or E2 return; } - + + if (!animation || !animation->states) + { last = (wbs->last == 8) ? wbs->next - 1 : wbs->last; // draw a splat on taken cities. @@ -1410,6 +1402,7 @@ static void WI_drawShowNextLoc(void) // draw flashing ptr if (snl_pointeron) WI_drawOnLnode(wbs->next, yah); + } } // draws which level you are entering.. @@ -2241,7 +2234,7 @@ void WI_Ticker(void) // counter for general background animation bcnt++; - if (bcnt == 1 && !UpdateMusic(false)) + if (bcnt == 1 && !SetupMusic(false)) { // intermission music if ( gamemode == commercial )