From 3be90efd57d819d25f35f321704a9a83a471fbc1 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Sat, 28 Nov 2020 23:28:32 +1000 Subject: [PATCH] Make some GlobalWin props read from MainForm instead of the reverse these props' setters were only called from MainForm --- src/BizHawk.Client.EmuHawk/GlobalWin.cs | 11 ++++++--- src/BizHawk.Client.EmuHawk/MainForm.cs | 31 ++++++++++++------------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/GlobalWin.cs b/src/BizHawk.Client.EmuHawk/GlobalWin.cs index a74358f940..c7d4ef8d8b 100644 --- a/src/BizHawk.Client.EmuHawk/GlobalWin.cs +++ b/src/BizHawk.Client.EmuHawk/GlobalWin.cs @@ -7,7 +7,9 @@ namespace BizHawk.Client.EmuHawk { public static class GlobalWin { - public static IEmulator Emulator { get; set; } + public static MainForm _mainForm { get; set; } + + public static IEmulator Emulator => _mainForm.Emulator; /// /// the IGL to be used for rendering @@ -22,8 +24,11 @@ namespace BizHawk.Client.EmuHawk public static Sound Sound; public static Config Config { get; set; } - public static GameInfo Game { get; set; } - public static IMovieSession MovieSession { get; set; } + + public static GameInfo Game => _mainForm.Game; + + public static IMovieSession MovieSession => _mainForm.MovieSession; + public static InputManager InputManager { get; } = new InputManager(); } } diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index 47d977a3bf..dbf7fb3981 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -279,6 +279,8 @@ 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 InputManager.ControllerInputCoalescer = new ControllerInputCoalescer(); @@ -308,7 +310,7 @@ namespace BizHawk.Client.EmuHawk Icon = Properties.Resources.Logo; SetImages(); - GlobalWin.Game = GameInfo.NullInstance; + Game = GameInfo.NullInstance; _throttle = new Throttle(); Emulator = new NullEmulator(); @@ -827,18 +829,19 @@ namespace BizHawk.Client.EmuHawk AddOnScreenMessage("Core reboot needed for this setting"); } - // TODO: make these actual properties - // This is a quick hack to reduce the dependency on Globals + /// don't use this, use + private IEmulator _emulator; + public IEmulator Emulator { - get => GlobalWin.Emulator; + get => _emulator; private set { - GlobalWin.Emulator = value; + _emulator = value; if (EmuClient != null) EmuClient.Emulator = value; // first call to this setter is in the ctor, before the APIs have been registered by the ToolManager ctor - _currentVideoProvider = GlobalWin.Emulator.AsVideoProviderOrDefault(); - _currentSoundProvider = GlobalWin.Emulator.AsSoundProviderOrDefault(); + _currentVideoProvider = value.AsVideoProviderOrDefault(); + _currentSoundProvider = value.AsSoundProviderOrDefault(); } } @@ -865,13 +868,9 @@ namespace BizHawk.Client.EmuHawk private OSDManager OSD => DisplayManager.OSD; - public IMovieSession MovieSession - { - get => GlobalWin.MovieSession; - private set => GlobalWin.MovieSession = value; - } + public IMovieSession MovieSession { get; } - private GameInfo Game => GlobalWin.Game; + public GameInfo Game { get; private set; } private Sound Sound { @@ -3624,10 +3623,10 @@ namespace BizHawk.Client.EmuHawk //path = ioa_openrom.Path; } - var oldGame = GlobalWin.Game; + var oldGame = Game; var result = loader.LoadRom(path, nextComm, ioaRetro?.CorePath); - EmuClient.Game = GlobalWin.Game = result ? loader.Game : oldGame; + EmuClient.Game = Game = result ? loader.Game : oldGame; // we need to replace the path in the OpenAdvanced with the canonical one the user chose. // It can't be done until loader.LoadRom happens (for CanonicalFullPath) @@ -3908,7 +3907,7 @@ namespace BizHawk.Client.EmuHawk { CloseGame(clearSram); Emulator = new NullEmulator(); - EmuClient.Game = GlobalWin.Game = GameInfo.NullInstance; + EmuClient.Game = Game = GameInfo.NullInstance; CreateRewinder(); Tools.Restart(Config, Emulator, Game); RewireSound();