From 453ea2b1bbff862fc39c78eca6cd742d994c00cd Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Mon, 30 Nov 2020 19:09:24 +1000 Subject: [PATCH] Pass globals to DisplayManager as with OSDManager * moved initialisation of global `OSDManager` to `DisplayManager` ctor again * `DisplayManager.UpdateGlobals` calls `DisplayManager.OSD.UpdateGlobals` * goodbye `GlobalWin.Emulator` and `GlobalWin._mainForm` :) --- .../DisplayManager/DisplayManager.cs | 17 +++++++++++++---- src/BizHawk.Client.EmuHawk/GlobalWin.cs | 5 ----- src/BizHawk.Client.EmuHawk/MainForm.cs | 10 ++++------ 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs b/src/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs index a05a68e1ad..40c89bf8af 100644 --- a/src/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs +++ b/src/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs @@ -51,13 +51,15 @@ namespace BizHawk.Client.EmuHawk public readonly OSDManager OSD; - private Config GlobalConfig => GlobalWin.Config; + private Config GlobalConfig; - private IEmulator GlobalEmulator => GlobalWin.Emulator; + private IEmulator GlobalEmulator; - public DisplayManager(OSDManager osd, IGL gl, PresentationPanel presentationPanel, Func getIsSecondaryThrottlingDisabled) + public DisplayManager(Config config, IEmulator emulator, InputManager inputManager, IMovieSession movieSession, IGL gl, PresentationPanel presentationPanel, Func getIsSecondaryThrottlingDisabled) { - OSD = osd; + GlobalConfig = config; + GlobalEmulator = emulator; + OSD = new OSDManager(config, emulator, inputManager, movieSession); _getIsSecondaryThrottlingDisabled = getIsSecondaryThrottlingDisabled; _gl = gl; @@ -136,6 +138,13 @@ namespace BizHawk.Client.EmuHawk RefreshUserShader(); } + public void UpdateGlobals(Config config, IEmulator emulator) + { + GlobalConfig = config; + GlobalEmulator = emulator; + OSD.UpdateGlobals(config, emulator); + } + public bool Disposed { get; private set; } public void Dispose() diff --git a/src/BizHawk.Client.EmuHawk/GlobalWin.cs b/src/BizHawk.Client.EmuHawk/GlobalWin.cs index 5ebc8d4e25..2fb96c8fe3 100644 --- a/src/BizHawk.Client.EmuHawk/GlobalWin.cs +++ b/src/BizHawk.Client.EmuHawk/GlobalWin.cs @@ -1,15 +1,10 @@ using BizHawk.Client.Common; -using BizHawk.Emulation.Common; // ReSharper disable StyleCop.SA1401 namespace BizHawk.Client.EmuHawk { public static class GlobalWin { - public static MainForm _mainForm { get; set; } - - public static IEmulator Emulator => _mainForm.Emulator; - public static Sound Sound; public static Config Config { get; set; } diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index 375303c978..8a2c83b1bf 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -279,8 +279,6 @@ namespace BizHawk.Client.EmuHawk Database.InitializeDatabase(Path.Combine(PathUtils.ExeDirectoryPath, "gamedb", "gamedb.txt")); BootGodDb.Initialize(Path.Combine(PathUtils.ExeDirectoryPath, "gamedb")); - GlobalWin._mainForm = this; - _config = config; // skips assignment to GlobalWin.Config as Program already did that GL = gl; @@ -339,7 +337,7 @@ namespace BizHawk.Client.EmuHawk { GraphicsControl = { MainWindow = true } }; - DisplayManager = new DisplayManager(new OSDManager(Config, Emulator, InputManager, MovieSession), GL, _presentationPanel, () => DisableSecondaryThrottling); + DisplayManager = new DisplayManager(Config, Emulator, InputManager, MovieSession, GL, _presentationPanel, () => DisableSecondaryThrottling); Controls.Add(_presentationPanel); Controls.SetChildIndex(_presentationPanel, 0); @@ -2796,7 +2794,7 @@ namespace BizHawk.Client.EmuHawk InputManager.SyncControls(Emulator, MovieSession, Config); Tools.Restart(Config, Emulator, Game); ExtToolManager.Restart(Config.PathEntries); - OSD.UpdateGlobals(Config, Emulator); + DisplayManager.UpdateGlobals(Config, Emulator); AddOnScreenMessage($"Config file loaded: {iniPath}"); } @@ -3773,7 +3771,7 @@ namespace BizHawk.Client.EmuHawk CurrentlyOpenRom = oaOpenrom?.Path ?? openAdvancedArgs; CurrentlyOpenRomArgs = args; OnRomChanged(); - OSD.UpdateGlobals(Config, Emulator); + DisplayManager.UpdateGlobals(Config, Emulator); DisplayManager.Blank(); CreateRewinder(); @@ -3923,7 +3921,7 @@ namespace BizHawk.Client.EmuHawk Tools.Restart(Config, Emulator, Game); RewireSound(); ClearHolds(); - OSD.UpdateGlobals(Config, Emulator); + DisplayManager.UpdateGlobals(Config, Emulator); InputManager.SyncControls(Emulator, MovieSession, Config); Tools.UpdateCheatRelatedTools(null, null); PauseOnFrame = null;