Separate StopMusic and UnloadMusic

This commit is contained in:
mazmazz 2018-09-14 12:47:33 -04:00
parent 8e05de17f0
commit e72610a3dc
2 changed files with 25 additions and 37 deletions

View file

@ -1344,11 +1344,13 @@ static boolean S_LoadMusic(const char *mname)
static void S_UnloadMusic(void) static void S_UnloadMusic(void)
{ {
I_UnloadSong(); I_UnloadSong();
music_name[0] = 0;
#ifndef HAVE_SDL //SDL uses RWOPS #ifndef HAVE_SDL //SDL uses RWOPS
Z_ChangeTag(music_data, PU_CACHE); Z_ChangeTag(music_data, PU_CACHE);
#endif #endif
music_data = NULL; music_data = NULL;
music_name[0] = 0;
music_flags = 0; music_flags = 0;
music_looping = false; music_looping = false;
} }
@ -1413,13 +1415,7 @@ void S_StopMusic(void)
S_SpeedMusic(1.0f); S_SpeedMusic(1.0f);
I_StopSong(); I_StopSong();
I_UnloadSong(); S_UnloadMusic(); // for now, stopping also means you unload the song
#ifndef HAVE_SDL //SDL uses RWOPS
Z_ChangeTag(music_data, PU_CACHE);
#endif
music_name[0] = 0;
} }
// //

View file

@ -484,19 +484,7 @@ FUNCMATH void I_InitMusic(void)
void I_ShutdownMusic(void) void I_ShutdownMusic(void)
{ {
#ifdef HAVE_LIBGME I_UnloadSong();
if (gme)
{
Mix_HookMusic(NULL, NULL);
gme_delete(gme);
gme = NULL;
}
#endif
if (!music)
return;
Mix_HookMusicFinished(NULL);
Mix_FreeMusic(music);
music = NULL;
} }
/// ------------------------ /// ------------------------
@ -565,10 +553,8 @@ boolean I_SetSongSpeed(float speed)
boolean I_LoadSong(char *data, size_t len) boolean I_LoadSong(char *data, size_t len)
{ {
I_Assert(!music); if (music || gme)
#ifdef HAVE_LIBGME I_UnloadSong();
I_Assert(!gme);
#endif
#ifdef HAVE_LIBGME #ifdef HAVE_LIBGME
if ((UINT8)data[0] == 0x1F if ((UINT8)data[0] == 0x1F
@ -710,11 +696,20 @@ boolean I_LoadSong(char *data, size_t len)
void I_UnloadSong(void) void I_UnloadSong(void)
{ {
// \todo unhook looper
//var_cleanup();
//Mix_FreeMusic(music);
//music = NULL;
I_StopSong(); I_StopSong();
#ifdef HAVE_LIBGME
if (gme)
{
gme_delete(gme);
gme = NULL;
}
#endif
if (music)
{
Mix_FreeMusic(music);
music = NULL;
}
} }
boolean I_PlaySong(boolean looping) boolean I_PlaySong(boolean looping)
@ -750,17 +745,14 @@ void I_StopSong(void)
if (gme) if (gme)
{ {
Mix_HookMusic(NULL, NULL); Mix_HookMusic(NULL, NULL);
gme_delete(gme);
gme = NULL;
current_track = -1; current_track = -1;
return;
} }
#endif #endif
if (!music) if (music)
return; {
Mix_HookMusicFinished(NULL); Mix_HookMusicFinished(NULL);
Mix_FreeMusic(music); Mix_HaltMusic();
music = NULL; }
} }
void I_PauseSong(void) void I_PauseSong(void)