From 6dfb0a8af8e564af324055124a853fa64ca5737e Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Thu, 26 Nov 2020 21:36:23 +1000 Subject: [PATCH] Move GlobalWin.DisableSecondaryThrottling to MainForm --- .../DisplayManager/DisplayManager.cs | 7 +++++-- src/BizHawk.Client.EmuHawk/GlobalWin.cs | 5 ----- src/BizHawk.Client.EmuHawk/MainForm.cs | 11 ++++++++--- src/BizHawk.Client.EmuHawk/Sound/Sound.cs | 6 +++--- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs b/src/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs index 7aa6731f5f..5c8484367f 100644 --- a/src/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs +++ b/src/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs @@ -47,14 +47,17 @@ namespace BizHawk.Client.EmuHawk } } + private readonly Func _getIsSecondaryThrottlingDisabled; + private readonly OSDManager _osdManager; private Config GlobalConfig => GlobalWin.Config; private IEmulator GlobalEmulator => GlobalWin.Emulator; - public DisplayManager(OSDManager osdManager, IGL gl, PresentationPanel presentationPanel) + public DisplayManager(OSDManager osdManager, IGL gl, PresentationPanel presentationPanel, Func getIsSecondaryThrottlingDisabled) { + _getIsSecondaryThrottlingDisabled = getIsSecondaryThrottlingDisabled; _osdManager = osdManager; GL = gl; @@ -934,7 +937,7 @@ namespace BizHawk.Client.EmuHawk //this makes sense... but we don't have the infrastructure to support it now (we'd have to enable triple buffering or something like that) //so what we're gonna do is disable vsync no matter what if throttling is off, and maybe nobody will notice. //update 26-mar-2016: this upsets me. When fast-forwarding and skipping frames, vsync should still work. But I'm not changing it yet - if (GlobalWin.DisableSecondaryThrottling) + if (_getIsSecondaryThrottlingDisabled()) vsync = false; //for now, it's assumed that the presentation panel is the main window, but that may not always be true diff --git a/src/BizHawk.Client.EmuHawk/GlobalWin.cs b/src/BizHawk.Client.EmuHawk/GlobalWin.cs index f889a426d8..9bc6d409dc 100644 --- a/src/BizHawk.Client.EmuHawk/GlobalWin.cs +++ b/src/BizHawk.Client.EmuHawk/GlobalWin.cs @@ -28,11 +28,6 @@ namespace BizHawk.Client.EmuHawk public static int ExitCode; - /// - /// Used to disable secondary throttling (e.g. vsync, audio) for unthrottled modes or when the primary (clock) throttle is taking over (e.g. during fast forward/rewind). - /// - public static bool DisableSecondaryThrottling { get; set; } - public static Dictionary UserBag { get; set; } = new Dictionary(); public static Config Config { get; set; } diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index 93185e953e..03f1939596 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -340,7 +340,7 @@ namespace BizHawk.Client.EmuHawk { GraphicsControl = { MainWindow = true } }; - GlobalWin.DisplayManager = new DisplayManager(OSD, GlobalWin.GL, PresentationPanel); + GlobalWin.DisplayManager = new DisplayManager(OSD, GlobalWin.GL, PresentationPanel, () => DisableSecondaryThrottling); Controls.Add(PresentationPanel); Controls.SetChildIndex(PresentationPanel, 0); @@ -793,6 +793,11 @@ namespace BizHawk.Client.EmuHawk private bool IsTurboSeeking => PauseOnFrame.HasValue && Config.TurboSeek; public bool IsTurboing => InputManager.ClientControls["Turbo"] || IsTurboSeeking; + /// + /// Used to disable secondary throttling (e.g. vsync, audio) for unthrottled modes or when the primary (clock) throttle is taking over (e.g. during fast forward/rewind). + /// + public static bool DisableSecondaryThrottling { get; set; } + public void AddOnScreenMessage(string message) => OSD.AddMessage(message); public void ClearHolds() @@ -2063,7 +2068,7 @@ namespace BizHawk.Client.EmuHawk speedPercent = Math.Max(speedPercent / Rewinder.RewindFrequency, 5); } - GlobalWin.DisableSecondaryThrottling = _unthrottled || turbo || fastForward || rewind; + DisableSecondaryThrottling = _unthrottled || turbo || fastForward || rewind; // realtime throttle is never going to be so exact that using a double here is wrong _throttle.SetCoreFps(Emulator.VsyncRate()); @@ -3019,7 +3024,7 @@ namespace BizHawk.Client.EmuHawk UpdateToolsAfter(); } - Sound.UpdateSound(atten); + Sound.UpdateSound(atten, DisableSecondaryThrottling); } private void UpdateFpsDisplay(long currentTimestamp, bool isRewinding, bool isFastForwarding) diff --git a/src/BizHawk.Client.EmuHawk/Sound/Sound.cs b/src/BizHawk.Client.EmuHawk/Sound/Sound.cs index bfa9f1e127..abe36cb7c3 100644 --- a/src/BizHawk.Client.EmuHawk/Sound/Sound.cs +++ b/src/BizHawk.Client.EmuHawk/Sound/Sound.cs @@ -143,7 +143,7 @@ namespace BizHawk.Client.EmuHawk } } - public void UpdateSound(float atten) + public void UpdateSound(float atten, bool isSecondaryThrottlingDisabled) { if (!GlobalWin.Config.SoundEnabled || !IsStarted || _bufferedProvider == null || _disposed) { @@ -175,7 +175,7 @@ namespace BizHawk.Client.EmuHawk _outputProvider.BaseSoundProvider.GetSamplesSync(out samples, out sampleCount); sampleOffset = 0; - if (GlobalWin.DisableSecondaryThrottling && sampleCount > samplesNeeded) + if (isSecondaryThrottlingDisabled && sampleCount > samplesNeeded) { return; } @@ -203,7 +203,7 @@ namespace BizHawk.Client.EmuHawk } else { - if (GlobalWin.DisableSecondaryThrottling) // This indicates rewind or fast-forward + if (isSecondaryThrottlingDisabled) // This indicates rewind or fast-forward { _outputProvider.OnVolatility(); }