Make some GlobalWin props read from MainForm instead of the reverse

these props' setters were only called from MainForm
This commit is contained in:
YoshiRulz 2020-11-28 23:28:32 +10:00
parent 0899369d1a
commit 3be90efd57
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
2 changed files with 23 additions and 19 deletions

View File

@ -7,7 +7,9 @@ namespace BizHawk.Client.EmuHawk
{ {
public static class GlobalWin public static class GlobalWin
{ {
public static IEmulator Emulator { get; set; } public static MainForm _mainForm { get; set; }
public static IEmulator Emulator => _mainForm.Emulator;
/// <summary> /// <summary>
/// the IGL to be used for rendering /// the IGL to be used for rendering
@ -22,8 +24,11 @@ namespace BizHawk.Client.EmuHawk
public static Sound Sound; public static Sound Sound;
public static Config Config { get; set; } 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(); public static InputManager InputManager { get; } = new InputManager();
} }
} }

View File

@ -279,6 +279,8 @@ namespace BizHawk.Client.EmuHawk
Database.InitializeDatabase(Path.Combine(PathUtils.ExeDirectoryPath, "gamedb", "gamedb.txt")); Database.InitializeDatabase(Path.Combine(PathUtils.ExeDirectoryPath, "gamedb", "gamedb.txt"));
BootGodDb.Initialize(Path.Combine(PathUtils.ExeDirectoryPath, "gamedb")); BootGodDb.Initialize(Path.Combine(PathUtils.ExeDirectoryPath, "gamedb"));
GlobalWin._mainForm = this;
_config = config; // skips assignment to GlobalWin.Config as Program already did that _config = config; // skips assignment to GlobalWin.Config as Program already did that
InputManager.ControllerInputCoalescer = new ControllerInputCoalescer(); InputManager.ControllerInputCoalescer = new ControllerInputCoalescer();
@ -308,7 +310,7 @@ namespace BizHawk.Client.EmuHawk
Icon = Properties.Resources.Logo; Icon = Properties.Resources.Logo;
SetImages(); SetImages();
GlobalWin.Game = GameInfo.NullInstance; Game = GameInfo.NullInstance;
_throttle = new Throttle(); _throttle = new Throttle();
Emulator = new NullEmulator(); Emulator = new NullEmulator();
@ -827,18 +829,19 @@ namespace BizHawk.Client.EmuHawk
AddOnScreenMessage("Core reboot needed for this setting"); AddOnScreenMessage("Core reboot needed for this setting");
} }
// TODO: make these actual properties /// <remarks>don't use this, use <see cref="Emulator"/></remarks>
// This is a quick hack to reduce the dependency on Globals private IEmulator _emulator;
public IEmulator Emulator public IEmulator Emulator
{ {
get => GlobalWin.Emulator; get => _emulator;
private set 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 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(); _currentVideoProvider = value.AsVideoProviderOrDefault();
_currentSoundProvider = GlobalWin.Emulator.AsSoundProviderOrDefault(); _currentSoundProvider = value.AsSoundProviderOrDefault();
} }
} }
@ -865,13 +868,9 @@ namespace BizHawk.Client.EmuHawk
private OSDManager OSD => DisplayManager.OSD; private OSDManager OSD => DisplayManager.OSD;
public IMovieSession MovieSession public IMovieSession MovieSession { get; }
{
get => GlobalWin.MovieSession;
private set => GlobalWin.MovieSession = value;
}
private GameInfo Game => GlobalWin.Game; public GameInfo Game { get; private set; }
private Sound Sound private Sound Sound
{ {
@ -3624,10 +3623,10 @@ namespace BizHawk.Client.EmuHawk
//path = ioa_openrom.Path; //path = ioa_openrom.Path;
} }
var oldGame = GlobalWin.Game; var oldGame = Game;
var result = loader.LoadRom(path, nextComm, ioaRetro?.CorePath); 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. // 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) // It can't be done until loader.LoadRom happens (for CanonicalFullPath)
@ -3908,7 +3907,7 @@ namespace BizHawk.Client.EmuHawk
{ {
CloseGame(clearSram); CloseGame(clearSram);
Emulator = new NullEmulator(); Emulator = new NullEmulator();
EmuClient.Game = GlobalWin.Game = GameInfo.NullInstance; EmuClient.Game = Game = GameInfo.NullInstance;
CreateRewinder(); CreateRewinder();
Tools.Restart(Config, Emulator, Game); Tools.Restart(Config, Emulator, Game);
RewireSound(); RewireSound();