fixed bug with restarting same menu music on different screens
authorHolger Schemel <info@artsoft.org>
Tue, 20 Dec 2016 19:46:46 +0000 (20:46 +0100)
committerHolger Schemel <info@artsoft.org>
Tue, 20 Dec 2016 19:46:46 +0000 (20:46 +0100)
src/libgame/sound.c
src/libgame/sound.h
src/tools.c

index e860ba5ad443acd63e2669618d3f7c5e04c0872d..cb788e7e573769a7efeec3e8ff1fbeaec7692fc3 100644 (file)
@@ -116,6 +116,8 @@ static MusicInfo **Music_NoConf = NULL;
 static int num_music_noconf = 0;
 static int stereo_volume[SOUND_MAX_LEFT2RIGHT + 1];
 
+static char *currently_playing_music_filename = NULL;
+
 
 /* ========================================================================= */
 /* THE STUFF BELOW IS ONLY USED BY THE SOUND SERVER CHILD PROCESS            */
@@ -242,6 +244,8 @@ static void Mixer_StopMusicChannel()
   Mixer_StopChannel(audio.music_channel);
 
   Mix_HaltMusic();
+
+  setString(&currently_playing_music_filename, NULL);
 }
 
 static void Mixer_FadeChannel(int channel)
@@ -259,6 +263,8 @@ static void Mixer_FadeMusicChannel()
   Mixer_FadeChannel(audio.music_channel);
 
   Mix_FadeOutMusic(SOUND_FADING_INTERVAL);
+
+  setString(&currently_playing_music_filename, NULL);
 }
 
 static void Mixer_UnFadeChannel(int channel)
@@ -322,6 +328,9 @@ static void Mixer_InsertSound(SoundControl snd_ctrl)
     mixer[audio.music_channel] = snd_ctrl;
     Mixer_PlayMusicChannel();
 
+    setString(&currently_playing_music_filename,
+             getBaseNamePtr(snd_info->source_filename));
+
     return;
   }
 
@@ -696,6 +705,11 @@ static MusicInfo *getMusicInfoEntryFromMusicID(int pos)
   return mus_info[list_pos];
 }
 
+char *getCurrentlyPlayingMusicFilename()
+{
+  return currently_playing_music_filename;
+}
+
 int getSoundListPropertyMappingSize()
 {
   return sound_info->num_property_mapping_entries;
index 26e882b3e177c5345b97c8a3670046463dd83c9e..8eb344ef2e921dfae3d8ef554d86d77784740b04 100644 (file)
@@ -121,6 +121,7 @@ int getSoundListSize();
 int getMusicListSize();
 struct FileInfo *getSoundListEntry(int);
 struct FileInfo *getMusicListEntry(int);
+char *getCurrentlyPlayingMusicFilename();
 int getSoundListPropertyMappingSize();
 int getMusicListPropertyMappingSize();
 struct PropertyMapping *getSoundListPropertyMapping();
index 9b573f66c2c2bbebb0880b9d882808ce1135d4e0..b07e19d37ee75fd9b92f6835d43513a67fa55f74 100644 (file)
@@ -8398,7 +8398,11 @@ void PlayMenuMusicExt(int music)
 
 void PlayMenuMusic()
 {
-  PlayMenuMusicExt(menu.music[game_status]);
+  char *curr_music = getCurrentlyPlayingMusicFilename();
+  char *next_music = getMusicListEntry(menu.music[game_status])->filename;
+
+  if (!strEqual(curr_music, next_music))
+    PlayMenuMusicExt(menu.music[game_status]);
 }
 
 void PlayMenuSoundsAndMusic()
@@ -8407,9 +8411,24 @@ void PlayMenuSoundsAndMusic()
   PlayMenuMusic();
 }
 
+static void FadeMenuSounds()
+{
+  FadeSounds();
+}
+
+static void FadeMenuMusic()
+{
+  char *curr_music = getCurrentlyPlayingMusicFilename();
+  char *next_music = getMusicListEntry(menu.music[game_status])->filename;
+
+  if (!strEqual(curr_music, next_music))
+    FadeMusic();
+}
+
 void FadeMenuSoundsAndMusic()
 {
-  FadeSoundsAndMusic();
+  FadeMenuSounds();
+  FadeMenuMusic();
 }
 
 void PlaySoundActivating()