From aeb435acf0e7c74ff293f4958cf969ff82eac89d Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Sun, 28 Jan 2018 20:57:10 +0100 Subject: [PATCH] fixed bug with fading menu music on 'start game' if game music is the same --- src/game.c | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/game.c b/src/game.c index d615d633..ee6de4e8 100644 --- a/src/game.c +++ b/src/game.c @@ -1052,6 +1052,7 @@ static void PlayLevelSoundElementActionIfLoop(int, int, int, int); static void PlayLevelSoundActionIfLoop(int, int, int); static void StopLevelSoundActionIfLoop(int, int, int); static void PlayLevelMusic(); +static void FadeLevelSoundsAndMusic(); static void HandleGameButtons(struct GadgetInfo *); @@ -3118,7 +3119,7 @@ void InitGame() if (CheckIfGlobalBorderHasChanged()) fade_mask = REDRAW_ALL; - FadeSoundsAndMusic(); + FadeLevelSoundsAndMusic(); ExpireSoundLoops(TRUE); @@ -14232,12 +14233,43 @@ static void StopLevelSoundActionIfLoop(int x, int y, int action) StopSound(sound_effect); } -static void PlayLevelMusic() +static int getLevelMusicNr() { if (levelset.music[level_nr] != MUS_UNDEFINED) - PlayMusic(levelset.music[level_nr]); /* from config file */ + return levelset.music[level_nr]; /* from config file */ else - PlayMusic(MAP_NOCONF_MUSIC(level_nr)); /* from music dir */ + return MAP_NOCONF_MUSIC(level_nr); /* from music dir */ +} + +static void FadeLevelSounds() +{ + FadeSounds(); +} + +static void FadeLevelMusic() +{ + int music_nr = getLevelMusicNr(); + char *curr_music = getCurrentlyPlayingMusicFilename(); + char *next_music = getMusicListEntry(music_nr)->filename; + + if (!strEqual(curr_music, next_music)) + FadeMusic(); +} + +void FadeLevelSoundsAndMusic() +{ + FadeLevelSounds(); + FadeLevelMusic(); +} + +static void PlayLevelMusic() +{ + int music_nr = getLevelMusicNr(); + char *curr_music = getCurrentlyPlayingMusicFilename(); + char *next_music = getMusicListEntry(music_nr)->filename; + + if (!strEqual(curr_music, next_music)) + PlayMusic(music_nr); } void PlayLevelSound_EM(int xx, int yy, int element_em, int sample) -- 2.34.1