UI: Fixed pause in background logic when pause in menu is enabled

This commit is contained in:
Sour 2018-08-05 13:22:59 -04:00
parent a3d7538299
commit ebbdf3726f
5 changed files with 23 additions and 9 deletions

View file

@ -22,7 +22,6 @@ enum EmulationFlags : uint64_t
DisableDynamicSampleRate = 0x80, DisableDynamicSampleRate = 0x80,
PauseOnMovieEnd = 0x0100, PauseOnMovieEnd = 0x0100,
PauseWhenInBackground = 0x0200,
AllowBackgroundInput = 0x0400, AllowBackgroundInput = 0x0400,
ReduceSoundInBackground = 0x0800, ReduceSoundInBackground = 0x0800,
MuteSoundInBackground = 0x1000, MuteSoundInBackground = 0x1000,
@ -757,7 +756,7 @@ public:
bool NeedsPause() 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() bool InputEnabled()

View file

@ -187,7 +187,6 @@ namespace Mesen.GUI.Config
InteropEmu.SetFlag(EmulationFlags.FdsAutoInsertDisk, preferenceInfo.FdsAutoInsertDisk); InteropEmu.SetFlag(EmulationFlags.FdsAutoInsertDisk, preferenceInfo.FdsAutoInsertDisk);
InteropEmu.SetFlag(EmulationFlags.PauseOnMovieEnd, preferenceInfo.PauseOnMovieEnd); InteropEmu.SetFlag(EmulationFlags.PauseOnMovieEnd, preferenceInfo.PauseOnMovieEnd);
InteropEmu.SetFlag(EmulationFlags.AllowBackgroundInput, preferenceInfo.AllowBackgroundInput); 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.UseHighResolutionTimer, !preferenceInfo.DisableHighResolutionTimer);
InteropEmu.SetFlag(EmulationFlags.AllowMismatchingSaveStates, preferenceInfo.AllowMismatchingSaveStates); InteropEmu.SetFlag(EmulationFlags.AllowMismatchingSaveStates, preferenceInfo.AllowMismatchingSaveStates);

View file

@ -20,6 +20,7 @@ namespace Mesen.GUI.Forms
private bool _iconSet = false; private bool _iconSet = false;
protected int _inMenu = 0; protected int _inMenu = 0;
private static Timer _tmrUpdateBackground; private static Timer _tmrUpdateBackground;
private static bool _needResume = false;
static BaseForm() static BaseForm()
{ {
@ -38,6 +39,11 @@ namespace Mesen.GUI.Forms
protected virtual bool IsConfigForm { get { return false; } } protected virtual bool IsConfigForm { get { return false; } }
public static void StopBackgroundTimer()
{
_tmrUpdateBackground.Stop();
}
private static void tmrUpdateBackground_Tick(object sender, EventArgs e) private static void tmrUpdateBackground_Tick(object sender, EventArgs e)
{ {
Form focusedForm = null; 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) { if(focusedForm != null) {
inBackground |= ConfigManager.Config.PreferenceInfo.PauseWhenInMenusAndConfig && focusedForm is BaseForm && (((BaseForm)focusedForm)._inMenu > 0 || ((BaseForm)focusedForm).IsConfigForm); needPause |= 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"); needPause |= 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.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) protected override bool ProcessCmdKey(ref Message msg, Keys keyData)

View file

@ -275,6 +275,7 @@ namespace Mesen.GUI.Forms
} }
_shuttingDown = true; _shuttingDown = true;
BaseForm.StopBackgroundTimer();
_logWindow?.Close(); _logWindow?.Close();
_historyViewerWindow?.Close(); _historyViewerWindow?.Close();
_cheatListWindow?.Close(); _cheatListWindow?.Close();

View file

@ -1525,7 +1525,6 @@ namespace Mesen.GUI
DisableDynamicSampleRate = 0x80, DisableDynamicSampleRate = 0x80,
PauseOnMovieEnd = 0x0100, PauseOnMovieEnd = 0x0100,
PauseWhenInBackground = 0x0200,
AllowBackgroundInput = 0x0400, AllowBackgroundInput = 0x0400,
ReduceSoundInBackground = 0x0800, ReduceSoundInBackground = 0x0800,
MuteSoundInBackground = 0x1000, MuteSoundInBackground = 0x1000,