Fade out music on scenario start and on disabling it

This commit is contained in:
Jyrki Vesterinen 2016-07-31 21:00:06 +03:00
parent 40bc508f7f
commit d4e6d0bf2b
4 changed files with 25 additions and 11 deletions

View File

@ -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.

View File

@ -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

View File

@ -5,6 +5,7 @@ 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.

View File

@ -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<std::string,Mix_Music*>::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() :