From 1bdbfdf22b648853168a6775b7b528b526fd67f6 Mon Sep 17 00:00:00 2001 From: toaster Date: Mon, 3 Apr 2023 19:59:46 +0100 Subject: [PATCH] S_TickSoundTest: Clean up significantly. - Introduce comments to make flow understandable. - Abstract the number of seconds in the fade out (previously handled across multiple places) into SOUNDTEST_FADEOUTSECONDS. - Make all next/conclude song cases for autosequence and non-looping track handled in one place. - Fixes the case where a non-looping track could stop the Sound Test even in autosequence mode. --- src/k_menudraw.c | 2 +- src/s_sound.c | 81 +++++++++++++++++++++++++++--------------------- src/s_sound.h | 2 ++ 3 files changed, 48 insertions(+), 37 deletions(-) diff --git a/src/k_menudraw.c b/src/k_menudraw.c index 012613e51..3b63a5b97 100644 --- a/src/k_menudraw.c +++ b/src/k_menudraw.c @@ -6046,7 +6046,7 @@ void M_DrawSoundTest(void) UINT32 exittime = soundtest.sequencemaxtime; if (soundtest.dosequencefadeout == true) { - exittime += 3*TICRATE; + exittime += SOUNDTEST_FADEOUTSECONDS*TICRATE; } V_DrawRightAlignedString(x + 272-1, 18+32+10, 0, diff --git a/src/s_sound.c b/src/s_sound.c index d45a3da26..e3a828bf5 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1694,66 +1694,75 @@ void S_TickSoundTest(void) { static UINT32 storetime = 0; UINT32 lasttime = storetime; - boolean donext = false; storetime = I_GetTime(); if (soundtest.playing == false || soundtest.current == NULL) { + // Nothing worth discussing. return; } if (I_SongPlaying() == false) { - S_SoundTestStop(); - return; + // We stopped for some reason. Accomodate this. + goto handlenextsong; } if (I_SongPaused() == false) { + // Increment the funny little timer. soundtest.currenttime += (storetime - lasttime); } - if (soundtest.sequencefadeout > 0) + if (soundtest.sequencefadeout != 0) { - if (soundtest.currenttime >= soundtest.sequencefadeout) + // Are we done fading out? + if (soundtest.currenttime > soundtest.sequencefadeout) { - donext = true; + goto handlenextsong; } - } - else if (soundtest.currenttime >= soundtest.sequencemaxtime) - { - if (soundtest.autosequence == false) - { - if (soundtest.current->basenoloop[soundtest.currenttrack] == true) - { - S_SoundTestStop(); - } - return; - } - else if (soundtest.dosequencefadeout == false) - { - donext = true; - } - else - { - if (soundtest.sequencemaxtime > 0) - { - soundtest.privilegedrequest = true; - S_FadeMusic(0, 3000); - soundtest.privilegedrequest = false; - } - - soundtest.sequencefadeout = soundtest.currenttime + 3*TICRATE; - } - } - - if (donext == false) - { return; } + if (soundtest.autosequence == false) + { + // There's nothing else for us here. + return; + } + + if (soundtest.currenttime >= soundtest.sequencemaxtime) + { + if (soundtest.dosequencefadeout == false) + { + // Handle the immediate progression. + goto handlenextsong; + } + + if (soundtest.sequencemaxtime > 0) + { + // Handle the fade. + soundtest.privilegedrequest = true; + S_FadeMusic(0, SOUNDTEST_FADEOUTSECONDS*1000); + soundtest.privilegedrequest = false; + } + + // Set the conclusion. + soundtest.sequencefadeout = soundtest.currenttime + SOUNDTEST_FADEOUTSECONDS*TICRATE; + } + + return; + +handlenextsong: + // If the song's stopped while not in autosequence, stop visibly playing. + if (soundtest.autosequence == false) + { + S_SoundTestStop(); + return; + } + + // Okay, this is autosequence in action. S_UpdateSoundTestDef(false, true, true); } diff --git a/src/s_sound.h b/src/s_sound.h index da0ca75fc..1e24118e2 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -210,6 +210,8 @@ extern struct cursongcredit fixed_t old_x; } cursongcredit; +#define SOUNDTEST_FADEOUTSECONDS 3 + extern struct soundtest { boolean playing; // Music is playing?