Only restart current music if its lump ID changed

This commit is contained in:
Lactozilla 2023-07-28 17:39:04 -03:00
parent 2876a02466
commit c6477ee32f
3 changed files with 25 additions and 4 deletions

View file

@ -1353,6 +1353,7 @@ void S_InitSfxChannels(INT32 sfxVolume)
/// ------------------------ /// ------------------------
static char music_name[7]; // up to 6-character name static char music_name[7]; // up to 6-character name
static lumpnum_t music_lump;
static void *music_data; static void *music_data;
static UINT16 music_flags; static UINT16 music_flags;
static boolean music_looping; static boolean music_looping;
@ -1985,6 +1986,17 @@ static musicstack_t *S_GetMusicStackEntry(UINT16 status, boolean fromfirst, INT1
return NULL; return NULL;
} }
boolean S_CheckDeletedMusic(void)
{
if (music_lump != S_GetMusicLumpNum(music_name))
{
S_StopMusic();
return true;
}
return false;
}
void S_RetainMusic(const char *mname, UINT16 mflags, boolean looping, UINT32 position, UINT16 status) void S_RetainMusic(const char *mname, UINT16 mflags, boolean looping, UINT32 position, UINT16 status)
{ {
musicstack_t *mst; musicstack_t *mst;
@ -2150,12 +2162,12 @@ static boolean S_LoadMusic(const char *mname)
// load & register it // load & register it
mdata = W_CacheLumpNum(mlumpnum, PU_MUSIC); mdata = W_CacheLumpNum(mlumpnum, PU_MUSIC);
if (I_LoadSong(mdata, W_LumpLength(mlumpnum))) if (I_LoadSong(mdata, W_LumpLength(mlumpnum)))
{ {
strncpy(music_name, mname, 7); strncpy(music_name, mname, 7);
music_name[6] = 0; music_name[6] = 0;
music_data = mdata; music_data = mdata;
music_lump = mlumpnum;
return true; return true;
} }
else else
@ -2325,6 +2337,8 @@ void S_StopMusic(void)
I_StopSong(); I_StopSong();
S_UnloadMusic(); // for now, stopping also means you unload the song S_UnloadMusic(); // for now, stopping also means you unload the song
music_lump = LUMPERROR;
if (cv_closedcaptioning.value) if (cv_closedcaptioning.value)
{ {
if (closedcaptions[0].s-S_sfx == sfx_None) if (closedcaptions[0].s-S_sfx == sfx_None)

View file

@ -127,6 +127,8 @@ void S_StopSounds(void);
void S_ClearSfx(void); void S_ClearSfx(void);
void S_PlayMapMusic(boolean reset); void S_PlayMapMusic(boolean reset);
boolean S_CheckDeletedMusic(void);
// //
// Basically a W_GetNumForName that adds "ds" at the beginning of the string. Returns a lumpnum. // Basically a W_GetNumForName that adds "ds" at the beginning of the string. Returns a lumpnum.
// //

View file

@ -1259,6 +1259,9 @@ void W_UnloadWadFile(UINT16 num)
W_ClearCachedData(); W_ClearCachedData();
if (is_important)
S_StopMusic();
W_UnloadFile(wadfiles[num]); W_UnloadFile(wadfiles[num]);
wadfiles[num] = NULL; wadfiles[num] = NULL;
@ -1272,10 +1275,13 @@ void W_UnloadWadFile(UINT16 num)
HU_LoadGraphics(); HU_LoadGraphics();
ST_LoadGraphics(); ST_LoadGraphics();
ST_ReloadSkinFaceGraphics(); ST_ReloadSkinFaceGraphics();
S_PlayMapMusic(true); if (S_CheckDeletedMusic())
S_PlayMapMusic(true);
return; return;
} }
S_CheckDeletedMusic();
D_ReloadFiles(); D_ReloadFiles();
G_LoadGameData(clientGamedata); G_LoadGameData(clientGamedata);
@ -1286,10 +1292,9 @@ void W_UnloadWadFile(UINT16 num)
void W_ClearCachedData(void) void W_ClearCachedData(void)
{ {
// Stop all sounds, stop current music // Stop all sounds
S_StopSounds(); S_StopSounds();
S_ClearSfx(); S_ClearSfx();
S_StopMusic();
// Unload HUD graphics // Unload HUD graphics
ST_UnloadGraphics(); ST_UnloadGraphics();