From ebbdf3726f6768d42aa8210e0d4042f73d182378 Mon Sep 17 00:00:00 2001 From: Sour Date: Sun, 5 Aug 2018 13:22:59 -0400 Subject: [PATCH] UI: Fixed pause in background logic when pause in menu is enabled --- Core/EmulationSettings.h | 3 +-- GUI.NET/Config/PreferenceInfo.cs | 1 - GUI.NET/Forms/BaseForm.cs | 26 +++++++++++++++++++++----- GUI.NET/Forms/frmMain.cs | 1 + GUI.NET/InteropEmu.cs | 1 - 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Core/EmulationSettings.h b/Core/EmulationSettings.h index 5981b466..7fde6ad5 100644 --- a/Core/EmulationSettings.h +++ b/Core/EmulationSettings.h @@ -22,7 +22,6 @@ enum EmulationFlags : uint64_t DisableDynamicSampleRate = 0x80, PauseOnMovieEnd = 0x0100, - PauseWhenInBackground = 0x0200, AllowBackgroundInput = 0x0400, ReduceSoundInBackground = 0x0800, MuteSoundInBackground = 0x1000, @@ -757,7 +756,7 @@ public: bool NeedsPause() { - return (CheckFlag(EmulationFlags::Paused) || (CheckFlag(EmulationFlags::InBackground) && CheckFlag(EmulationFlags::PauseWhenInBackground) && !GameClient::Connected())) && !CheckFlag(EmulationFlags::DebuggerWindowEnabled); + return CheckFlag(EmulationFlags::Paused) && !CheckFlag(EmulationFlags::DebuggerWindowEnabled); } bool InputEnabled() diff --git a/GUI.NET/Config/PreferenceInfo.cs b/GUI.NET/Config/PreferenceInfo.cs index a8406789..1892a334 100644 --- a/GUI.NET/Config/PreferenceInfo.cs +++ b/GUI.NET/Config/PreferenceInfo.cs @@ -187,7 +187,6 @@ namespace Mesen.GUI.Config InteropEmu.SetFlag(EmulationFlags.FdsAutoInsertDisk, preferenceInfo.FdsAutoInsertDisk); InteropEmu.SetFlag(EmulationFlags.PauseOnMovieEnd, preferenceInfo.PauseOnMovieEnd); InteropEmu.SetFlag(EmulationFlags.AllowBackgroundInput, preferenceInfo.AllowBackgroundInput); - InteropEmu.SetFlag(EmulationFlags.PauseWhenInBackground, preferenceInfo.PauseWhenInBackground || preferenceInfo.PauseWhenInMenusAndConfig || preferenceInfo.PauseWhenInDebuggingTools); InteropEmu.SetFlag(EmulationFlags.UseHighResolutionTimer, !preferenceInfo.DisableHighResolutionTimer); InteropEmu.SetFlag(EmulationFlags.AllowMismatchingSaveStates, preferenceInfo.AllowMismatchingSaveStates); diff --git a/GUI.NET/Forms/BaseForm.cs b/GUI.NET/Forms/BaseForm.cs index ac41abea..d49eca28 100644 --- a/GUI.NET/Forms/BaseForm.cs +++ b/GUI.NET/Forms/BaseForm.cs @@ -20,6 +20,7 @@ namespace Mesen.GUI.Forms private bool _iconSet = false; protected int _inMenu = 0; private static Timer _tmrUpdateBackground; + private static bool _needResume = false; static BaseForm() { @@ -38,6 +39,11 @@ namespace Mesen.GUI.Forms protected virtual bool IsConfigForm { get { return false; } } + public static void StopBackgroundTimer() + { + _tmrUpdateBackground.Stop(); + } + private static void tmrUpdateBackground_Tick(object sender, EventArgs e) { Form focusedForm = null; @@ -48,14 +54,24 @@ namespace Mesen.GUI.Forms } } - bool inBackground = focusedForm == null; + bool needPause = focusedForm == null && ConfigManager.Config.PreferenceInfo.PauseWhenInBackground; if(focusedForm != null) { - inBackground |= ConfigManager.Config.PreferenceInfo.PauseWhenInMenusAndConfig && focusedForm is BaseForm && (((BaseForm)focusedForm)._inMenu > 0 || ((BaseForm)focusedForm).IsConfigForm); - inBackground |= ConfigManager.Config.PreferenceInfo.PauseWhenInMenusAndConfig && !(focusedForm is BaseInputForm) && !focusedForm.GetType().FullName.Contains("Debugger"); - inBackground |= ConfigManager.Config.PreferenceInfo.PauseWhenInDebuggingTools && focusedForm.GetType().FullName.Contains("Debugger"); + needPause |= ConfigManager.Config.PreferenceInfo.PauseWhenInMenusAndConfig && focusedForm is BaseForm && (((BaseForm)focusedForm)._inMenu > 0 || ((BaseForm)focusedForm).IsConfigForm); + needPause |= ConfigManager.Config.PreferenceInfo.PauseWhenInMenusAndConfig && !(focusedForm is BaseInputForm) && !focusedForm.GetType().FullName.Contains("Debugger"); + needPause |= ConfigManager.Config.PreferenceInfo.PauseWhenInDebuggingTools && focusedForm.GetType().FullName.Contains("Debugger"); } - InteropEmu.SetFlag(EmulationFlags.InBackground, inBackground); + if(needPause) { + if(!InteropEmu.IsPaused(InteropEmu.ConsoleId.Master)) { + _needResume = true; + InteropEmu.Pause(InteropEmu.ConsoleId.Master); + } + } else if(_needResume) { + InteropEmu.Resume(InteropEmu.ConsoleId.Master); + _needResume = false; + } + + InteropEmu.SetFlag(EmulationFlags.InBackground, focusedForm == null); } protected override bool ProcessCmdKey(ref Message msg, Keys keyData) diff --git a/GUI.NET/Forms/frmMain.cs b/GUI.NET/Forms/frmMain.cs index 8309761b..3a4e1347 100644 --- a/GUI.NET/Forms/frmMain.cs +++ b/GUI.NET/Forms/frmMain.cs @@ -275,6 +275,7 @@ namespace Mesen.GUI.Forms } _shuttingDown = true; + BaseForm.StopBackgroundTimer(); _logWindow?.Close(); _historyViewerWindow?.Close(); _cheatListWindow?.Close(); diff --git a/GUI.NET/InteropEmu.cs b/GUI.NET/InteropEmu.cs index 7803fb52..4b20613a 100644 --- a/GUI.NET/InteropEmu.cs +++ b/GUI.NET/InteropEmu.cs @@ -1525,7 +1525,6 @@ namespace Mesen.GUI DisableDynamicSampleRate = 0x80, PauseOnMovieEnd = 0x0100, - PauseWhenInBackground = 0x0200, AllowBackgroundInput = 0x0400, ReduceSoundInBackground = 0x0800, MuteSoundInBackground = 0x1000,