From 5419e822d812dfc64616bdf87d5bd90ef202690c Mon Sep 17 00:00:00 2001 From: Info Teddy <59748578+InfoTeddy@users.noreply.github.com> Date: Sun, 12 Jan 2020 19:33:58 -0800 Subject: [PATCH] Stop the game from freezing if we play a song during a fadeout (#61) --- desktop_version/src/Music.cpp | 18 +++++++++++++++++- desktop_version/src/Music.h | 3 +++ desktop_version/src/Script.cpp | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/desktop_version/src/Music.cpp b/desktop_version/src/Music.cpp index 12e7dfbe..e6566b79 100644 --- a/desktop_version/src/Music.cpp +++ b/desktop_version/src/Music.cpp @@ -214,6 +214,8 @@ musicclass::musicclass() nicefade = 0; resumesong = 0; volume = 0.0f; + fadeoutqueuesong = -1; + dontquickfade = false; } void musicclass::play(int t) @@ -260,7 +262,16 @@ void musicclass::play(int t) // musicchannel = musicchan[currentsong].play(0); // musicchannel.soundTransform = new SoundTransform(0); // musicchannel.addEventListener(Event.SOUND_COMPLETE, loopmusic); - if(Mix_FadeInMusic(musicTracks[t].m_music, -1, 3000)==-1) + if (Mix_FadingMusic() == MIX_FADING_OUT) { + // We're already fading out + fadeoutqueuesong = t; + currentsong = -1; + if (!dontquickfade) + Mix_FadeOutMusic(500); // fade out quicker + else + dontquickfade = false; + } + else if(Mix_FadeInMusic(musicTracks[t].m_music, -1, 3000)==-1) { printf("Mix_FadeInMusic: %s\n", Mix_GetError()); } @@ -358,6 +369,11 @@ void musicclass::processmusic() //if (musicfade > 0) processmusicfade(); //if (musicfadein > 0) processmusicfadein(); + if (fadeoutqueuesong != -1 && Mix_PlayingMusic() == 0) { + play(fadeoutqueuesong); + fadeoutqueuesong = -1; + } + if (nicefade == 1 && Mix_PlayingMusic() == 0) { play(nicechange); diff --git a/desktop_version/src/Music.h b/desktop_version/src/Music.h index 7e2a67f1..dd081eae 100644 --- a/desktop_version/src/Music.h +++ b/desktop_version/src/Music.h @@ -56,6 +56,9 @@ public: bool custompd; + int fadeoutqueuesong; // -1 if no song queued + bool dontquickfade; + // MMMMMM mod settings bool mmmmmm; bool usingmmmmmm; diff --git a/desktop_version/src/Script.cpp b/desktop_version/src/Script.cpp index 5069f694..7736aa0b 100644 --- a/desktop_version/src/Script.cpp +++ b/desktop_version/src/Script.cpp @@ -248,6 +248,7 @@ void scriptclass::run( KeyPoll& key, Graphics& dwgfx, Game& game, mapclass& map, if (words[0] == "musicfadeout") { music.fadeout(); + music.dontquickfade = true; } if (words[0] == "musicfadein") {