From 7349f8ef0fdc384973d1ed9ec256d36a0be9e1ec Mon Sep 17 00:00:00 2001 From: JadingTsunami Date: Wed, 21 Apr 2021 00:12:57 -0700 Subject: [PATCH] Fix for UMAPINFO music restarting issue. (#281) * Fix for UMAPINFO music restarting issue. * Fix bugs with MUSINFO and UMAPINFO present simultaneously. Fixes #279, fixes #102. --- prboom2/src/s_advsound.c | 20 ++++++++++++++++---- prboom2/src/s_advsound.h | 2 ++ prboom2/src/s_sound.c | 4 +++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/prboom2/src/s_advsound.c b/prboom2/src/s_advsound.c index 1490006cf..415c4d509 100644 --- a/prboom2/src/s_advsound.c +++ b/prboom2/src/s_advsound.c @@ -59,15 +59,27 @@ musinfo_t musinfo; // void S_ParseMusInfo(const char *mapid) { - memset(&musinfo, 0, sizeof(musinfo)); - musinfo.current_item = -1; - - S_music[NUMMUSIC].lumpnum = -1; if (W_CheckNumForName("MUSINFO") != -1) { int num, lumpnum; int inMap = false; + int load_muslump = -1; + /* musinfo item zero is initialized + * before we reach the parser and it must be + * saved and restored */ + int itemzero = musinfo.items[0]; + + /* don't restart music that is already playing */ + if (mus_playing && + mus_playing->lumpnum == S_music[NUMMUSIC].lumpnum) { + load_muslump = S_music[NUMMUSIC].lumpnum; + } + + memset(&musinfo, 0, sizeof(musinfo)); + musinfo.items[0] = itemzero; + musinfo.current_item = load_muslump; + S_music[NUMMUSIC].lumpnum = load_muslump; SC_OpenLump("MUSINFO"); diff --git a/prboom2/src/s_advsound.h b/prboom2/src/s_advsound.h index 1bdeb8894..0db760eea 100644 --- a/prboom2/src/s_advsound.h +++ b/prboom2/src/s_advsound.h @@ -35,6 +35,7 @@ #define __S_ADVSOUND__ #include "p_mobj.h" +#include "sounds.h" #ifdef __GNUG__ #pragma interface @@ -55,6 +56,7 @@ typedef struct musinfo_s int items[MAX_MUS_ENTRIES]; } musinfo_t; +extern musicinfo_t *mus_playing; extern musinfo_t musinfo; void S_ParseMusInfo(const char *mapid); diff --git a/prboom2/src/s_sound.c b/prboom2/src/s_sound.c index 63d5cc2b8..5e19a20d1 100644 --- a/prboom2/src/s_sound.c +++ b/prboom2/src/s_sound.c @@ -95,7 +95,7 @@ int snd_MusicVolume = 15; static dboolean mus_paused; // music currently being played -static musicinfo_t *mus_playing; +musicinfo_t *mus_playing; // music currently should play static int musicnum_current; @@ -207,6 +207,7 @@ void S_Start(void) int muslump = W_CheckNumForName(gamemapinfo->music); if (muslump >= 0) { + musinfo.items[0] = muslump; S_ChangeMusInfoMusic(muslump, true); return; } @@ -533,6 +534,7 @@ void S_ChangeMusic(int musicnum, int looping) // current music which should play musicnum_current = musicnum; musinfo.current_item = -1; + S_music[NUMMUSIC].lumpnum = -1; //jff 1/22/98 return if music is not enabled if (!mus_card || nomusicparm)