diff --git a/src/BizHawk.Client.Common/Api/Interfaces/IEmuClientApi.cs b/src/BizHawk.Client.Common/Api/Interfaces/IEmuClientApi.cs
index 9530c6d05d..cb9bbdbcf2 100644
--- a/src/BizHawk.Client.Common/Api/Interfaces/IEmuClientApi.cs
+++ b/src/BizHawk.Client.Common/Api/Interfaces/IEmuClientApi.cs
@@ -1,8 +1,6 @@
using System;
using System.Drawing;
-using BizHawk.Emulation.Common;
-
namespace BizHawk.Client.Common
{
public interface IEmuClientApi : IExternalApi
@@ -116,7 +114,7 @@ namespace BizHawk.Client.Common
///
/// Raise when a rom is successfully Loaded
///
- void OnRomLoaded(IEmulator emu);
+ void OnRomLoaded();
///
/// Raise when a state is loaded
@@ -207,8 +205,6 @@ namespace BizHawk.Client.Common
void UnpauseAv();
- void UpdateEmulatorAndVP(IEmulator emu = null);
-
int Xpos();
int Ypos();
diff --git a/src/BizHawk.Client.EmuHawk/Api/ClientApi.cs b/src/BizHawk.Client.EmuHawk/Api/ClientApi.cs
index c7de1d55db..1363d4eec3 100644
--- a/src/BizHawk.Client.EmuHawk/Api/ClientApi.cs
+++ b/src/BizHawk.Client.EmuHawk/Api/ClientApi.cs
@@ -117,8 +117,7 @@ namespace BizHawk.Client.EmuHawk
///
public static void OnBeforeQuickSave(object sender, string quickSaveSlotName, out bool eventHandled) => EmuClient.OnBeforeQuickSave(sender, quickSaveSlotName, out eventHandled);
- ///
- public static void OnRomLoaded(IEmulator emu) => EmuClient.OnRomLoaded(emu);
+ public static void OnRomLoaded(IEmulator emu) {}
///
public static void OnStateLoaded(object sender, string stateName) => EmuClient.OnStateLoaded(sender, stateName);
@@ -198,8 +197,7 @@ namespace BizHawk.Client.EmuHawk
///
public static void UnpauseEmulation() => Unpause();
- ///
- public static void UpdateEmulatorAndVP(IEmulator emu = null) => EmuClient.UpdateEmulatorAndVP(emu);
+ public static void UpdateEmulatorAndVP(IEmulator emu = null) {}
///
public static int Xpos() => EmuClient.Xpos();
diff --git a/src/BizHawk.Client.EmuHawk/Api/Libraries/EmuClientApi.cs b/src/BizHawk.Client.EmuHawk/Api/Libraries/EmuClientApi.cs
index 11706b58f3..2fa649066c 100644
--- a/src/BizHawk.Client.EmuHawk/Api/Libraries/EmuClientApi.cs
+++ b/src/BizHawk.Client.EmuHawk/Api/Libraries/EmuClientApi.cs
@@ -17,7 +17,7 @@ namespace BizHawk.Client.EmuHawk
{
public sealed class EmuClientApi : IEmuClientApi
{
- private List _allJoyPads;
+ private readonly List _allJoyPads;
private readonly Config _config;
@@ -29,11 +29,9 @@ namespace BizHawk.Client.EmuHawk
private readonly Action _logCallback;
- private IEmulator _maybeEmulator;
+ private readonly IEmulator Emulator;
- public IEmulator Emulator;
-
- public IGameInfo Game;
+ private readonly IGameInfo Game;
private readonly IReadOnlyCollection JoypadButtonsArray = Enum.GetValues(typeof(JoypadButton)).Cast().ToList(); //TODO can the return of GetValues be cast to JoypadButton[]? --yoshi
@@ -74,7 +72,7 @@ namespace BizHawk.Client.EmuHawk
internal static readonly BizHawkSystemIdToEnumConverter SystemIdConverter = new BizHawkSystemIdToEnumConverter();
- private IVideoProvider VideoProvider { get; set; }
+ private readonly IVideoProvider VideoProvider;
public event BeforeQuickLoadEventHandler BeforeQuickLoad;
@@ -95,6 +93,19 @@ namespace BizHawk.Client.EmuHawk
_inputManager = inputManager;
_logCallback = logCallback;
_mainForm = mainForm;
+
+ try
+ {
+ _allJoyPads = new List(RunningSystem.MaxControllers);
+ for (var i = 1; i <= RunningSystem.MaxControllers; i++)
+ _allJoyPads.Add(new Joypad(RunningSystem, i));
+ }
+ catch (Exception e)
+ {
+ Console.Error.WriteLine("Apihawk is garbage and may not work this session.");
+ Console.Error.WriteLine(e);
+ }
+ VideoProvider = Emulator.AsVideoProviderOrDefault();
}
public int BorderHeight() => _displayManager.TransformPoint(new Point(0, 0)).Y;
@@ -176,7 +187,7 @@ namespace BizHawk.Client.EmuHawk
public int GetTargetScanlineIntensity() => _config.TargetScanlineFilterIntensity;
- public int GetWindowSize() => _config.TargetZoomFactors[_maybeEmulator.SystemId];
+ public int GetWindowSize() => _config.TargetZoomFactors[Emulator.SystemId];
public void InvisibleEmulation(bool invisible) => _mainForm.InvisibleEmulation = invisible;
@@ -212,23 +223,9 @@ namespace BizHawk.Client.EmuHawk
eventHandled = e.Handled;
}
- public void OnRomLoaded(IEmulator emu)
+ public void OnRomLoaded()
{
- _maybeEmulator = emu;
- VideoProvider = emu.AsVideoProviderOrDefault();
RomLoaded?.Invoke(null, EventArgs.Empty);
-
- try
- {
- _allJoyPads = new List(RunningSystem.MaxControllers);
- for (var i = 1; i <= RunningSystem.MaxControllers; i++)
- _allJoyPads.Add(new Joypad(RunningSystem, i));
- }
- catch (Exception e)
- {
- Console.Error.WriteLine("Apihawk is garbage and may not work this session.");
- Console.Error.WriteLine(e);
- }
}
public void OnStateLoaded(object sender, string stateName) => StateLoaded?.Invoke(sender, new StateLoadedEventArgs(stateName));
@@ -262,7 +259,7 @@ namespace BizHawk.Client.EmuHawk
public void SeekFrame(int frame)
{
var wasPaused = _mainForm.EmulatorPaused;
- while (_maybeEmulator.Frame != frame) _mainForm.SeekFrameAdvance();
+ while (Emulator.Frame != frame) _mainForm.SeekFrameAdvance();
if (!wasPaused) _mainForm.UnpauseEmulator();
}
@@ -324,7 +321,7 @@ namespace BizHawk.Client.EmuHawk
{
if (size == 1 || size == 2 || size == 3 || size == 4 || size == 5 || size == 10)
{
- _config.TargetZoomFactors[_maybeEmulator.SystemId] = size;
+ _config.TargetZoomFactors[Emulator.SystemId] = size;
_mainForm.FrameBufferResized();
_mainForm.AddOnScreenMessage($"Window size set to {size}x");
}
@@ -348,12 +345,6 @@ namespace BizHawk.Client.EmuHawk
public void UnpauseAv() => _mainForm.PauseAvi = false;
- public void UpdateEmulatorAndVP(IEmulator emu)
- {
- _maybeEmulator = emu;
- VideoProvider = emu.AsVideoProviderOrDefault();
- }
-
public int Xpos() => _mainForm.DesktopLocation.X;
public int Ypos() => _mainForm.DesktopLocation.Y;
diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs
index 167d2ee882..74065c83f2 100644
--- a/src/BizHawk.Client.EmuHawk/MainForm.cs
+++ b/src/BizHawk.Client.EmuHawk/MainForm.cs
@@ -842,7 +842,6 @@ namespace BizHawk.Client.EmuHawk
private set
{
_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 = value.AsVideoProviderOrDefault();
_currentSoundProvider = value.AsSoundProviderOrDefault();
}
@@ -3637,7 +3636,7 @@ namespace BizHawk.Client.EmuHawk
var oldGame = Game;
var result = loader.LoadRom(path, nextComm, ioaRetro?.CorePath);
- EmuClient.Game = Game = result ? loader.Game : oldGame;
+ 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)
@@ -3800,20 +3799,19 @@ namespace BizHawk.Client.EmuHawk
ExtToolManager.BuildToolStrip();
- EmuClient.OnRomLoaded(Emulator);
+ EmuClient.OnRomLoaded();
return true;
}
else if (Emulator.IsNull())
{
// This shows up if there's a problem
- EmuClient.UpdateEmulatorAndVP(Emulator);
OnRomChanged();
return false;
}
else
{
// The ROM has been loaded by a recursive invocation of the LoadROM method.
- EmuClient.OnRomLoaded(Emulator);
+ EmuClient.OnRomLoaded();
return true;
}
}
@@ -3901,7 +3899,6 @@ namespace BizHawk.Client.EmuHawk
CheatList.SaveOnClose();
Emulator.Dispose();
Emulator = new NullEmulator();
- EmuClient.UpdateEmulatorAndVP(Emulator);
InputManager.ActiveController = new Controller(NullController.Instance.Definition);
InputManager.AutoFireController = _autofireNullControls;
RewireSound();
@@ -3919,7 +3916,7 @@ namespace BizHawk.Client.EmuHawk
{
CloseGame(clearSram);
Emulator = new NullEmulator();
- EmuClient.Game = Game = GameInfo.NullInstance;
+ Game = GameInfo.NullInstance;
CreateRewinder();
Tools.Restart(Config, Emulator, Game);
RewireSound();