mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-03 16:20:06 +00:00
Do not block everything when fading music in and out.
Fixes #4460. Also fixes the seconds-long UI block at the start of a scenario and when beginning story view at the start of a campaign. And thus, also fixes the new visual fade-in effect which was completely broken by music fade-in blocking everything. Note that this fix does cause fades to happen in a non-blocking manner. Old music will fade out in the background, then the new music will fade in once the old music has finished fading out.
This commit is contained in:
parent
96ebc1b531
commit
d95a154a59
@ -672,6 +672,14 @@ static void play_new_music()
|
||||
fading_time = 0;
|
||||
}
|
||||
|
||||
// Halt any existing music.
|
||||
// If we don't do this SDL_Mixer blocks everything until fade out is complete.
|
||||
// Do not remove this without ensuring that it does not block.
|
||||
// If you don't want it to halt the music, ensure that fades are completed
|
||||
// before attempting to play new music.
|
||||
Mix_HaltMusic();
|
||||
|
||||
// Fade in the new music
|
||||
const int res = Mix_FadeInMusic(itor->second.get(), 1, fading_time);
|
||||
if(res < 0) {
|
||||
ERR_AUDIO << "Could not play music: " << Mix_GetError() << " " << filename << " " << std::endl;
|
||||
@ -767,6 +775,11 @@ void play_music_config(const config& music_node, bool allow_interrupt_current_tr
|
||||
|
||||
void music_thinker::process(events::pump_info& info)
|
||||
{
|
||||
if(Mix_FadingMusic() != MIX_NO_FADING) {
|
||||
// Do not block everything while fading.
|
||||
return;
|
||||
}
|
||||
|
||||
if(preferences::music_on()) {
|
||||
if(!music_start_time && !current_track_list.empty() && !Mix_PlayingMusic()) {
|
||||
// Pick next track, add ending time to its start time.
|
||||
@ -784,6 +797,7 @@ void music_thinker::process(events::pump_info& info)
|
||||
if(want_new_music) {
|
||||
if(Mix_PlayingMusic()) {
|
||||
Mix_FadeOutMusic(fadingout_time);
|
||||
return;
|
||||
}
|
||||
|
||||
unload_music = false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user