Remove weird double-updating of EmuClientApi
changes signatures in IEmuClientApi but they were never meant to be called outside MainForm anyway
This commit is contained in:
parent
a1ccac4d67
commit
a393c7d368
|
@ -1,8 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
|
||||||
using BizHawk.Emulation.Common;
|
|
||||||
|
|
||||||
namespace BizHawk.Client.Common
|
namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
public interface IEmuClientApi : IExternalApi
|
public interface IEmuClientApi : IExternalApi
|
||||||
|
@ -116,7 +114,7 @@ namespace BizHawk.Client.Common
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Raise when a rom is successfully Loaded
|
/// Raise when a rom is successfully Loaded
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void OnRomLoaded(IEmulator emu);
|
void OnRomLoaded();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Raise when a state is loaded
|
/// Raise when a state is loaded
|
||||||
|
@ -207,8 +205,6 @@ namespace BizHawk.Client.Common
|
||||||
|
|
||||||
void UnpauseAv();
|
void UnpauseAv();
|
||||||
|
|
||||||
void UpdateEmulatorAndVP(IEmulator emu = null);
|
|
||||||
|
|
||||||
int Xpos();
|
int Xpos();
|
||||||
|
|
||||||
int Ypos();
|
int Ypos();
|
||||||
|
|
|
@ -117,8 +117,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
/// <inheritdoc cref="IEmuClientApi.OnBeforeQuickSave"/>
|
/// <inheritdoc cref="IEmuClientApi.OnBeforeQuickSave"/>
|
||||||
public static void OnBeforeQuickSave(object sender, string quickSaveSlotName, out bool eventHandled) => EmuClient.OnBeforeQuickSave(sender, quickSaveSlotName, out eventHandled);
|
public static void OnBeforeQuickSave(object sender, string quickSaveSlotName, out bool eventHandled) => EmuClient.OnBeforeQuickSave(sender, quickSaveSlotName, out eventHandled);
|
||||||
|
|
||||||
/// <inheritdoc cref="IEmuClientApi.OnRomLoaded"/>
|
public static void OnRomLoaded(IEmulator emu) {}
|
||||||
public static void OnRomLoaded(IEmulator emu) => EmuClient.OnRomLoaded(emu);
|
|
||||||
|
|
||||||
/// <inheritdoc cref="IEmuClientApi.OnStateLoaded"/>
|
/// <inheritdoc cref="IEmuClientApi.OnStateLoaded"/>
|
||||||
public static void OnStateLoaded(object sender, string stateName) => EmuClient.OnStateLoaded(sender, stateName);
|
public static void OnStateLoaded(object sender, string stateName) => EmuClient.OnStateLoaded(sender, stateName);
|
||||||
|
@ -198,8 +197,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
/// <inheritdoc cref="Unpause"/>
|
/// <inheritdoc cref="Unpause"/>
|
||||||
public static void UnpauseEmulation() => Unpause();
|
public static void UnpauseEmulation() => Unpause();
|
||||||
|
|
||||||
/// <inheritdoc cref="IEmuClientApi.UpdateEmulatorAndVP"/>
|
public static void UpdateEmulatorAndVP(IEmulator emu = null) {}
|
||||||
public static void UpdateEmulatorAndVP(IEmulator emu = null) => EmuClient.UpdateEmulatorAndVP(emu);
|
|
||||||
|
|
||||||
/// <inheritdoc cref="IEmuClientApi.Xpos"/>
|
/// <inheritdoc cref="IEmuClientApi.Xpos"/>
|
||||||
public static int Xpos() => EmuClient.Xpos();
|
public static int Xpos() => EmuClient.Xpos();
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
public sealed class EmuClientApi : IEmuClientApi
|
public sealed class EmuClientApi : IEmuClientApi
|
||||||
{
|
{
|
||||||
private List<Joypad> _allJoyPads;
|
private readonly List<Joypad> _allJoyPads;
|
||||||
|
|
||||||
private readonly Config _config;
|
private readonly Config _config;
|
||||||
|
|
||||||
|
@ -29,11 +29,9 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
private readonly Action<string> _logCallback;
|
private readonly Action<string> _logCallback;
|
||||||
|
|
||||||
private IEmulator _maybeEmulator;
|
private readonly IEmulator Emulator;
|
||||||
|
|
||||||
public IEmulator Emulator;
|
private readonly IGameInfo Game;
|
||||||
|
|
||||||
public IGameInfo Game;
|
|
||||||
|
|
||||||
private readonly IReadOnlyCollection<JoypadButton> JoypadButtonsArray = Enum.GetValues(typeof(JoypadButton)).Cast<JoypadButton>().ToList(); //TODO can the return of GetValues be cast to JoypadButton[]? --yoshi
|
private readonly IReadOnlyCollection<JoypadButton> JoypadButtonsArray = Enum.GetValues(typeof(JoypadButton)).Cast<JoypadButton>().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();
|
internal static readonly BizHawkSystemIdToEnumConverter SystemIdConverter = new BizHawkSystemIdToEnumConverter();
|
||||||
|
|
||||||
private IVideoProvider VideoProvider { get; set; }
|
private readonly IVideoProvider VideoProvider;
|
||||||
|
|
||||||
public event BeforeQuickLoadEventHandler BeforeQuickLoad;
|
public event BeforeQuickLoadEventHandler BeforeQuickLoad;
|
||||||
|
|
||||||
|
@ -95,6 +93,19 @@ namespace BizHawk.Client.EmuHawk
|
||||||
_inputManager = inputManager;
|
_inputManager = inputManager;
|
||||||
_logCallback = logCallback;
|
_logCallback = logCallback;
|
||||||
_mainForm = mainForm;
|
_mainForm = mainForm;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_allJoyPads = new List<Joypad>(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;
|
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 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;
|
public void InvisibleEmulation(bool invisible) => _mainForm.InvisibleEmulation = invisible;
|
||||||
|
|
||||||
|
@ -212,23 +223,9 @@ namespace BizHawk.Client.EmuHawk
|
||||||
eventHandled = e.Handled;
|
eventHandled = e.Handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnRomLoaded(IEmulator emu)
|
public void OnRomLoaded()
|
||||||
{
|
{
|
||||||
_maybeEmulator = emu;
|
|
||||||
VideoProvider = emu.AsVideoProviderOrDefault();
|
|
||||||
RomLoaded?.Invoke(null, EventArgs.Empty);
|
RomLoaded?.Invoke(null, EventArgs.Empty);
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_allJoyPads = new List<Joypad>(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));
|
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)
|
public void SeekFrame(int frame)
|
||||||
{
|
{
|
||||||
var wasPaused = _mainForm.EmulatorPaused;
|
var wasPaused = _mainForm.EmulatorPaused;
|
||||||
while (_maybeEmulator.Frame != frame) _mainForm.SeekFrameAdvance();
|
while (Emulator.Frame != frame) _mainForm.SeekFrameAdvance();
|
||||||
if (!wasPaused) _mainForm.UnpauseEmulator();
|
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)
|
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.FrameBufferResized();
|
||||||
_mainForm.AddOnScreenMessage($"Window size set to {size}x");
|
_mainForm.AddOnScreenMessage($"Window size set to {size}x");
|
||||||
}
|
}
|
||||||
|
@ -348,12 +345,6 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
public void UnpauseAv() => _mainForm.PauseAvi = false;
|
public void UnpauseAv() => _mainForm.PauseAvi = false;
|
||||||
|
|
||||||
public void UpdateEmulatorAndVP(IEmulator emu)
|
|
||||||
{
|
|
||||||
_maybeEmulator = emu;
|
|
||||||
VideoProvider = emu.AsVideoProviderOrDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int Xpos() => _mainForm.DesktopLocation.X;
|
public int Xpos() => _mainForm.DesktopLocation.X;
|
||||||
|
|
||||||
public int Ypos() => _mainForm.DesktopLocation.Y;
|
public int Ypos() => _mainForm.DesktopLocation.Y;
|
||||||
|
|
|
@ -842,7 +842,6 @@ namespace BizHawk.Client.EmuHawk
|
||||||
private set
|
private set
|
||||||
{
|
{
|
||||||
_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 = value.AsVideoProviderOrDefault();
|
_currentVideoProvider = value.AsVideoProviderOrDefault();
|
||||||
_currentSoundProvider = value.AsSoundProviderOrDefault();
|
_currentSoundProvider = value.AsSoundProviderOrDefault();
|
||||||
}
|
}
|
||||||
|
@ -3637,7 +3636,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
var oldGame = Game;
|
var oldGame = Game;
|
||||||
var result = loader.LoadRom(path, nextComm, ioaRetro?.CorePath);
|
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.
|
// 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)
|
||||||
|
@ -3800,20 +3799,19 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
ExtToolManager.BuildToolStrip();
|
ExtToolManager.BuildToolStrip();
|
||||||
|
|
||||||
EmuClient.OnRomLoaded(Emulator);
|
EmuClient.OnRomLoaded();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (Emulator.IsNull())
|
else if (Emulator.IsNull())
|
||||||
{
|
{
|
||||||
// This shows up if there's a problem
|
// This shows up if there's a problem
|
||||||
EmuClient.UpdateEmulatorAndVP(Emulator);
|
|
||||||
OnRomChanged();
|
OnRomChanged();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// The ROM has been loaded by a recursive invocation of the LoadROM method.
|
// The ROM has been loaded by a recursive invocation of the LoadROM method.
|
||||||
EmuClient.OnRomLoaded(Emulator);
|
EmuClient.OnRomLoaded();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3901,7 +3899,6 @@ namespace BizHawk.Client.EmuHawk
|
||||||
CheatList.SaveOnClose();
|
CheatList.SaveOnClose();
|
||||||
Emulator.Dispose();
|
Emulator.Dispose();
|
||||||
Emulator = new NullEmulator();
|
Emulator = new NullEmulator();
|
||||||
EmuClient.UpdateEmulatorAndVP(Emulator);
|
|
||||||
InputManager.ActiveController = new Controller(NullController.Instance.Definition);
|
InputManager.ActiveController = new Controller(NullController.Instance.Definition);
|
||||||
InputManager.AutoFireController = _autofireNullControls;
|
InputManager.AutoFireController = _autofireNullControls;
|
||||||
RewireSound();
|
RewireSound();
|
||||||
|
@ -3919,7 +3916,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
CloseGame(clearSram);
|
CloseGame(clearSram);
|
||||||
Emulator = new NullEmulator();
|
Emulator = new NullEmulator();
|
||||||
EmuClient.Game = Game = GameInfo.NullInstance;
|
Game = GameInfo.NullInstance;
|
||||||
CreateRewinder();
|
CreateRewinder();
|
||||||
Tools.Restart(Config, Emulator, Game);
|
Tools.Restart(Config, Emulator, Game);
|
||||||
RewireSound();
|
RewireSound();
|
||||||
|
|
Loading…
Reference in New Issue