From c55fb60cc85268a1e18fb0aa5e99aafe8bc5febe Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 10 Feb 2025 16:51:17 +0100 Subject: [PATCH] add some comments + smol cleanup again for keepmusic --- src/s_sound.c | 55 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/src/s_sound.c b/src/s_sound.c index 6c3e95ddd..7461150b6 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -119,7 +119,7 @@ consvar_t cv_ignoremusicchanges = {"ignoremusicchanges", "No", CV_SAVE, CV_YesNo boolean keepmapmusic = false; // keep the current music on map restart boolean skipintromus = false; // skip the intro fanfare -static boolean keepmusicresume = false; +static boolean resumekeepmusic = false; static music_t keepmusic; static void S_SetKeepMusResume(void); static void S_SetKeepMusicStuff(void); @@ -1946,6 +1946,7 @@ static boolean S_CheckMusicException(void) if (stricmp(music.name, mapmusic.name)) return true; + // in case somehow the mapmusic was replaced with smth we dont want to keep for (size_t i = 0; i < sizeof(musicexception_list)/sizeof(musicexception_list[0]); i++) { if (!stricmp(music.name, musicexception_list[i]) || !stricmp(checkmusic, musicexception_list[i])) @@ -1962,6 +1963,8 @@ void S_ResetKeepAndSpecialMus(void) keepmapmusic = skipintromus = false; } +// saves the current song position everytime a song stops +// so we can resume it in some cases static void S_SetKeepMusResume(void) { keepmusic.resume = 0; @@ -1972,7 +1975,7 @@ static void S_SetKeepMusResume(void) } } -// save some values +// copy over all the mapmusic stuff into temporary vars static void S_SetKeepMusicStuff(void) { if (!cv_keepmusic.value) @@ -1992,6 +1995,7 @@ static void S_SetKeepMusicStuff(void) keepmusic.position = mapmusic.position; } +// replace mapmusic with our saved keepmusic stuff static void S_CopyKeepMusicStuff(void) { if (!cv_keepmusic.value) @@ -2007,12 +2011,13 @@ static void S_CopyKeepMusicStuff(void) } // determine if we should keep the music on a map restart +// this gets called BEFORE the level gets loaded in G_DoLoadLevel void S_KeepMusic(void) { static INT16 oldmap = -1; static boolean oldencore = false; - keepmapmusic = keepmusicresume = false; + keepmapmusic = resumekeepmusic = false; if (!cv_keepmusic.value) { @@ -2025,14 +2030,16 @@ void S_KeepMusic(void) { const boolean musicchanged = S_CheckMusicException(); - keepmusicresume = (musicchanged && keepmusic.resume); - keepmapmusic = (!musicchanged || keepmusicresume); + resumekeepmusic = (musicchanged && keepmusic.resume); + keepmapmusic = (!musicchanged || resumekeepmusic); } oldencore = encoremode; oldmap = gamemap; } +// Sets up the map music in case it should be reloaded +// Special case for keep music void S_HandleReloadResetMusic(void) { if (!(mapmusic.flags & MUSIC_RELOADRESET)) @@ -2040,7 +2047,7 @@ void S_HandleReloadResetMusic(void) if (keepmapmusic) { - // this is horrible, this copies over everything about the mapmusic into temporary variables to reuse + // this is horrible, but oh well S_CopyKeepMusicStuff(); } else @@ -2054,6 +2061,24 @@ void S_HandleReloadResetMusic(void) mapmusic.resume = 0; } +static boolean S_SkipIntroMusic(void) +{ + boolean skip = cv_skipintromusic.value; + + if (!skip) + return false; + + char *maptitle = G_BuildMapTitle(gamemap); // Zzz... + + // check if menu music is playing, otherwise it may continue playing + if (!stricmp(music.name, "titles") || (maptitle && (!stricmp(maptitle, "Wandering Falls")))) // wandering balls changes its song when the race starts Zzz... + skip = false; + + Z_Free(maptitle); + + return skip; +} + // // Per level startup code. // Kills playing sounds at start of level, @@ -2066,7 +2091,7 @@ void S_InitMapMusic(void) if (keepmapmusic) { // this is kinda silly, but we can use it to fade back into the map song at the saved point, should the current music be different from the map music - if (keepmusicresume) + if (resumekeepmusic) S_ChangeMusicEx(mapmusic.name, mapmusic.flags, true, keepmusic.resume, 0, 500); return; } @@ -2075,24 +2100,13 @@ void S_InitMapMusic(void) // lug: but not when we keep the map music lol S_StopMusic(); - if (cv_skipintromusic.value) - { - char *maptitle = G_BuildMapTitle(gamemap); - // for some reason, occasionally the title screen music doesent seem to be reset in time, so skipping the intro may make it just continue playing it instead, weird.. - skipintromus = true; - if (!stricmp(music.name, "titles") || (maptitle && (!stricmp(maptitle, "Wandering Falls")))) // thanks diggle! - skipintromus = false; - - if (maptitle) - Z_Free(maptitle); - } + skipintromus = S_SkipIntroMusic(); if (skipintromus) return; if (leveltime < MUSICSTARTTIME) // SRB2Kart S_ChangeMusicInternal((encoremode ? "estart" : "kstart"), false); //S_StopMusic(); - //S_ChangeMusicEx((encoremode ? "estart" : "kstart"), 0, false, mapmusic.position, 0, 0); } void S_StartMapMusic(void) @@ -2108,8 +2122,9 @@ void S_StartMapMusic(void) { if (leveltime < starttime) S_ChangeMusicEx(mapmusic.name, mapmusic.flags, true, mapmusic.position, 0, 0); - if (leveltime == MUSICSTARTTIME) + else if (leveltime == MUSICSTARTTIME) S_ShowMusicCredit(); + return; }