remove ApiProvider from GlobalWin, and have ToolManager own it instead, keep a copy of IEmulator in ToolManager and reference that instead of Global.Emulator
This commit is contained in:
parent
84a9dec7a8
commit
e0cd66613f
|
@ -15,7 +15,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
public static class ApiManager
|
public static class ApiManager
|
||||||
{
|
{
|
||||||
private static ApiContainer container;
|
private static ApiContainer container;
|
||||||
private static void Register(IEmulatorServiceProvider serviceProvider)
|
private static IExternalApiProvider Register(IEmulatorServiceProvider serviceProvider)
|
||||||
{
|
{
|
||||||
foreach (var api in Assembly.Load("BizHawk.Client.Common").GetTypes()
|
foreach (var api in Assembly.Load("BizHawk.Client.Common").GetTypes()
|
||||||
.Concat(Assembly.Load("BizHawk.Client.ApiHawk").GetTypes())
|
.Concat(Assembly.Load("BizHawk.Client.ApiHawk").GetTypes())
|
||||||
|
@ -27,13 +27,14 @@ namespace BizHawk.Client.EmuHawk
|
||||||
Libraries.Add(api, instance);
|
Libraries.Add(api, instance);
|
||||||
}
|
}
|
||||||
container = new ApiContainer(Libraries);
|
container = new ApiContainer(Libraries);
|
||||||
GlobalWin.ApiProvider = new BasicApiProvider(container);
|
return new BasicApiProvider(container);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static readonly Dictionary<Type, IExternalApi> Libraries = new Dictionary<Type, IExternalApi>();
|
private static readonly Dictionary<Type, IExternalApi> Libraries = new Dictionary<Type, IExternalApi>();
|
||||||
public static void Restart(IEmulatorServiceProvider newServiceProvider)
|
public static IExternalApiProvider Restart(IEmulatorServiceProvider newServiceProvider)
|
||||||
{
|
{
|
||||||
Libraries.Clear();
|
Libraries.Clear();
|
||||||
Register(newServiceProvider);
|
return Register(newServiceProvider);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using BizHawk.Bizware.BizwareGL;
|
using BizHawk.Bizware.BizwareGL;
|
||||||
using BizHawk.Client.ApiHawk;
|
|
||||||
|
|
||||||
// ReSharper disable StyleCop.SA1401
|
// ReSharper disable StyleCop.SA1401
|
||||||
namespace BizHawk.Client.EmuHawk
|
namespace BizHawk.Client.EmuHawk
|
||||||
|
@ -8,7 +7,6 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
public static MainForm MainForm;
|
public static MainForm MainForm;
|
||||||
public static ToolManager Tools;
|
public static ToolManager Tools;
|
||||||
public static BasicApiProvider ApiProvider;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// the IGL to be used for rendering
|
/// the IGL to be used for rendering
|
||||||
|
|
|
@ -356,7 +356,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
Sound.StartSound();
|
Sound.StartSound();
|
||||||
InputManager.RewireInputChain();
|
InputManager.RewireInputChain();
|
||||||
GlobalWin.Tools = new ToolManager(this);
|
GlobalWin.Tools = new ToolManager(this, Emulator);
|
||||||
RewireSound();
|
RewireSound();
|
||||||
|
|
||||||
// Workaround for windows, location is -32000 when minimized, if they close it during this time, that's what gets saved
|
// Workaround for windows, location is -32000 when minimized, if they close it during this time, that's what gets saved
|
||||||
|
@ -3831,8 +3831,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ApiManager.Restart(Emulator.ServiceProvider);
|
Tools.Restart(Emulator);
|
||||||
Tools.Restart();
|
|
||||||
|
|
||||||
if (Config.LoadCheatFileByGame)
|
if (Config.LoadCheatFileByGame)
|
||||||
{
|
{
|
||||||
|
@ -4001,8 +4000,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
Emulator = new NullEmulator(coreComm);
|
Emulator = new NullEmulator(coreComm);
|
||||||
Global.Game = GameInfo.NullInstance;
|
Global.Game = GameInfo.NullInstance;
|
||||||
|
|
||||||
Tools.Restart();
|
Tools.Restart(Emulator);
|
||||||
ApiManager.Restart(Emulator.ServiceProvider);
|
|
||||||
RewireSound();
|
RewireSound();
|
||||||
ClearHolds();
|
ClearHolds();
|
||||||
ToolFormBase.UpdateCheatRelatedTools(null, null);
|
ToolFormBase.UpdateCheatRelatedTools(null, null);
|
||||||
|
|
|
@ -19,6 +19,8 @@ namespace BizHawk.Client.EmuHawk
|
||||||
public class ToolManager
|
public class ToolManager
|
||||||
{
|
{
|
||||||
private readonly Form _owner;
|
private readonly Form _owner;
|
||||||
|
private IExternalApiProvider _apiProvider;
|
||||||
|
private IEmulator _emulator;
|
||||||
|
|
||||||
// TODO: merge ToolHelper code where logical
|
// TODO: merge ToolHelper code where logical
|
||||||
// For instance, add an IToolForm property called UsesCheats, so that a UpdateCheatRelatedTools() method can update all tools of this type
|
// For instance, add an IToolForm property called UsesCheats, so that a UpdateCheatRelatedTools() method can update all tools of this type
|
||||||
|
@ -28,10 +30,11 @@ namespace BizHawk.Client.EmuHawk
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="ToolManager"/> class.
|
/// Initializes a new instance of the <see cref="ToolManager"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="owner">Form that handle the ToolManager</param>
|
public ToolManager(Form owner, IEmulator emulator)
|
||||||
public ToolManager(Form owner)
|
|
||||||
{
|
{
|
||||||
_owner = owner;
|
_owner = owner;
|
||||||
|
_emulator = emulator;
|
||||||
|
_apiProvider = ApiManager.Restart(_emulator.ServiceProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -125,10 +128,10 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
if (isExternal)
|
if (isExternal)
|
||||||
{
|
{
|
||||||
ApiInjector.UpdateApis(GlobalWin.ApiProvider, newTool);
|
ApiInjector.UpdateApis(_apiProvider, newTool);
|
||||||
}
|
}
|
||||||
|
|
||||||
ServiceInjector.UpdateServices(Global.Emulator.ServiceProvider, newTool);
|
ServiceInjector.UpdateServices(_emulator.ServiceProvider, newTool);
|
||||||
string toolType = typeof(T).ToString();
|
string toolType = typeof(T).ToString();
|
||||||
|
|
||||||
// auto settings
|
// auto settings
|
||||||
|
@ -482,8 +485,10 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Restart()
|
public void Restart(IEmulator emulator)
|
||||||
{
|
{
|
||||||
|
_emulator = emulator;
|
||||||
|
_apiProvider = ApiManager.Restart(_emulator.ServiceProvider);
|
||||||
// If Cheat tool is loaded, restarting will restart the list too anyway
|
// If Cheat tool is loaded, restarting will restart the list too anyway
|
||||||
if (!Has<Cheats>())
|
if (!Has<Cheats>())
|
||||||
{
|
{
|
||||||
|
@ -494,14 +499,14 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
foreach (var tool in _tools)
|
foreach (var tool in _tools)
|
||||||
{
|
{
|
||||||
if (ServiceInjector.IsAvailable(Global.Emulator.ServiceProvider, tool.GetType()))
|
if (ServiceInjector.IsAvailable(_emulator.ServiceProvider, tool.GetType()))
|
||||||
{
|
{
|
||||||
ServiceInjector.UpdateServices(Global.Emulator.ServiceProvider, tool);
|
ServiceInjector.UpdateServices(_emulator.ServiceProvider, tool);
|
||||||
|
|
||||||
if ((tool.IsHandleCreated && !tool.IsDisposed) || tool is RamWatch) // Hack for RAM Watch - in display watches mode it wants to keep running even closed, it will handle disposed logic
|
if ((tool.IsHandleCreated && !tool.IsDisposed) || tool is RamWatch) // Hack for RAM Watch - in display watches mode it wants to keep running even closed, it will handle disposed logic
|
||||||
{
|
{
|
||||||
if (tool is IExternalToolForm)
|
if (tool is IExternalToolForm)
|
||||||
ApiInjector.UpdateApis(GlobalWin.ApiProvider, tool);
|
ApiInjector.UpdateApis(_apiProvider, tool);
|
||||||
tool.Restart();
|
tool.Restart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -732,7 +737,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
public bool IsAvailable(Type tool)
|
public bool IsAvailable(Type tool)
|
||||||
{
|
{
|
||||||
if (!ServiceInjector.IsAvailable(Global.Emulator.ServiceProvider, tool)
|
if (!ServiceInjector.IsAvailable(_emulator.ServiceProvider, tool)
|
||||||
|| !LazyAsmTypes.Value.Contains(tool.AssemblyQualifiedName)) // not a tool
|
|| !LazyAsmTypes.Value.Contains(tool.AssemblyQualifiedName)) // not a tool
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -744,8 +749,8 @@ namespace BizHawk.Client.EmuHawk
|
||||||
return true; // no ToolAttribute on given type -> assumed all supported
|
return true; // no ToolAttribute on given type -> assumed all supported
|
||||||
}
|
}
|
||||||
|
|
||||||
var displayName = Global.Emulator.DisplayName();
|
var displayName = _emulator.DisplayName();
|
||||||
var systemId = Global.Emulator.SystemId;
|
var systemId = _emulator.SystemId;
|
||||||
return !attr.UnsupportedCores.Contains(displayName) // not unsupported
|
return !attr.UnsupportedCores.Contains(displayName) // not unsupported
|
||||||
&& (!attr.SupportedSystems.Any() || attr.SupportedSystems.Contains(systemId)); // supported (no supported list -> assumed all supported)
|
&& (!attr.SupportedSystems.Any() || attr.SupportedSystems.Contains(systemId)); // supported (no supported list -> assumed all supported)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue