From 4bea40fc223dea70bb4b719d909c03bf31857824 Mon Sep 17 00:00:00 2001 From: Misa Date: Sun, 19 Apr 2020 13:21:36 -0700 Subject: [PATCH] Pause all audio output when the game is unfocused Some custom levels have their own custom music and sync that music to scripted cutscenes, which is actually pretty impressive. However, they've always run into a small thorn, which is that you can easily desync the music by unfocusing the game, because the audio will keep playing when the game is unfocused. This should remove that thorn by pausing the audio on unfocus, and resuming when focused, so that the music can no longer desync, but you can still pause the game by unfocusing it. This is yet another feature in VCE that hasn't been upstreamed until now. --- desktop_version/src/main.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/desktop_version/src/main.cpp b/desktop_version/src/main.cpp index 73589672..16aa50e6 100644 --- a/desktop_version/src/main.cpp +++ b/desktop_version/src/main.cpp @@ -379,6 +379,9 @@ int main(int argc, char *argv[]) game.infocus = key.isActive; if(!game.infocus) { + Mix_Pause(-1); + Mix_PauseMusic(); + FillRect(graphics.backBuffer, 0x00000000); graphics.bprint(5, 110, "Game paused", 196 - help.glow, 255 - help.glow, 196 - help.glow, true); graphics.bprint(5, 120, "[click to resume]", 196 - help.glow, 255 - help.glow, 196 - help.glow, true); @@ -390,6 +393,9 @@ int main(int argc, char *argv[]) } else { + Mix_Resume(-1); + Mix_ResumeMusic(); + switch(game.gamestate) { case PRELOADER: