diff --git a/changelog b/changelog index 82b5e94e77f..498afaca897 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,7 @@ Version 1.13.5+dev: * Music and sound effects: * Added a preference to pause the music when the game loses focus. + * Now the storyscreen music fades out at the start of each scenario. * Units: * Changed the sound for the melee attack of the Loyalist Bowman, Orcish Crossbowman and Orcish Slurbow. diff --git a/data/core/macros/sound-utils.cfg b/data/core/macros/sound-utils.cfg index 4670c8dd9fb..774aae01146 100644 --- a/data/core/macros/sound-utils.cfg +++ b/data/core/macros/sound-utils.cfg @@ -628,6 +628,7 @@ [music] name={MUSIC} immediate=yes + ms_after=2000 [/music] [/event] #enddef @@ -661,6 +662,7 @@ name={SCENARIO_MUSIC} immediate=yes append=no + ms_after=2000 [/music] [/event] #enddef diff --git a/players_changelog b/players_changelog index 4cc7ba0711c..2f5b0c236c4 100644 --- a/players_changelog +++ b/players_changelog @@ -5,15 +5,16 @@ changelog: https://github.com/wesnoth/wesnoth/blob/master/changelog Version 1.13.5+dev: * Music and sound effects: * Added a preference to pause the music when the game loses focus. + * Now the storyscreen music fades out at the start of each scenario. * Units: * Changed the sound for the melee attack of the Loyalist Bowman, Orcish Crossbowman and Orcish Slurbow. * Performance: - * When a heuristic determines that it's probably faster, the game predicts battle - outcome by simulating a few thousand fights instead of calculating exact - probabilities. This method is inexact, but in very complex battles (extremely - high HP, drain, slow, berserk, etc.) it's significantly faster than the default - damage calculation method. + * When a heuristic determines that it's probably faster, the game predicts battle + outcome by simulating a few thousand fights instead of calculating exact + probabilities. This method is inexact, but in very complex battles (extremely + high HP, drain, slow, berserk, etc.) it's significantly faster than the default + damage calculation method. Version 1.13.5: * Campaigns: diff --git a/src/sound.cpp b/src/sound.cpp index a48ba07331d..e2cc8b39e19 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -61,6 +61,7 @@ unsigned music_refresh_rate = 20; bool want_new_music = false; int fadingout_time=5000; bool no_fading = false; +bool unload_music = false; // number of allocated channels, const size_t n_of_channels = 32; @@ -410,12 +411,8 @@ void reset_sound() { void stop_music() { if(mix_ok) { - Mix_HaltMusic(); - - std::map::iterator i; - for(i = music_cache.begin(); i != music_cache.end(); ++i) - Mix_FreeMusic(i->second); - music_cache.clear(); + Mix_FadeOutMusic(500); + Mix_HookMusicFinished([](){ unload_music = true; }); } } @@ -613,9 +610,22 @@ void music_thinker::process(events::pump_info &info) { if(Mix_PlayingMusic()) { Mix_FadeOutMusic(fadingout_time); } + + unload_music = false; play_new_music(); } } + + if (unload_music) { + for (auto track : music_cache) { + Mix_FreeMusic(track.second); + } + music_cache.clear(); + + Mix_HookMusicFinished(nullptr); + + unload_music = false; + } } music_muter::music_muter() :