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
|
||||
{
|
||||
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()
|
||||
.Concat(Assembly.Load("BizHawk.Client.ApiHawk").GetTypes())
|
||||
|
@ -27,13 +27,14 @@ namespace BizHawk.Client.EmuHawk
|
|||
Libraries.Add(api, instance);
|
||||
}
|
||||
container = new ApiContainer(Libraries);
|
||||
GlobalWin.ApiProvider = new BasicApiProvider(container);
|
||||
return new BasicApiProvider(container);
|
||||
}
|
||||
|
||||
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();
|
||||
Register(newServiceProvider);
|
||||
return Register(newServiceProvider);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using BizHawk.Bizware.BizwareGL;
|
||||
using BizHawk.Client.ApiHawk;
|
||||
|
||||
// ReSharper disable StyleCop.SA1401
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
|
@ -8,7 +7,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
public static MainForm MainForm;
|
||||
public static ToolManager Tools;
|
||||
public static BasicApiProvider ApiProvider;
|
||||
|
||||
/// <summary>
|
||||
/// the IGL to be used for rendering
|
||||
|
|
|
@ -356,7 +356,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
Sound.StartSound();
|
||||
InputManager.RewireInputChain();
|
||||
GlobalWin.Tools = new ToolManager(this);
|
||||
GlobalWin.Tools = new ToolManager(this, Emulator);
|
||||
RewireSound();
|
||||
|
||||
// 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();
|
||||
Tools.Restart(Emulator);
|
||||
|
||||
if (Config.LoadCheatFileByGame)
|
||||
{
|
||||
|
@ -4001,8 +4000,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
Emulator = new NullEmulator(coreComm);
|
||||
Global.Game = GameInfo.NullInstance;
|
||||
|
||||
Tools.Restart();
|
||||
ApiManager.Restart(Emulator.ServiceProvider);
|
||||
Tools.Restart(Emulator);
|
||||
RewireSound();
|
||||
ClearHolds();
|
||||
ToolFormBase.UpdateCheatRelatedTools(null, null);
|
||||
|
|
|
@ -19,6 +19,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
public class ToolManager
|
||||
{
|
||||
private readonly Form _owner;
|
||||
private IExternalApiProvider _apiProvider;
|
||||
private IEmulator _emulator;
|
||||
|
||||
// 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
|
||||
|
@ -28,10 +30,11 @@ namespace BizHawk.Client.EmuHawk
|
|||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ToolManager"/> class.
|
||||
/// </summary>
|
||||
/// <param name="owner">Form that handle the ToolManager</param>
|
||||
public ToolManager(Form owner)
|
||||
public ToolManager(Form owner, IEmulator emulator)
|
||||
{
|
||||
_owner = owner;
|
||||
_emulator = emulator;
|
||||
_apiProvider = ApiManager.Restart(_emulator.ServiceProvider);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -125,10 +128,10 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
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();
|
||||
|
||||
// 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 (!Has<Cheats>())
|
||||
{
|
||||
|
@ -494,14 +499,14 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
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 is IExternalToolForm)
|
||||
ApiInjector.UpdateApis(GlobalWin.ApiProvider, tool);
|
||||
ApiInjector.UpdateApis(_apiProvider, tool);
|
||||
tool.Restart();
|
||||
}
|
||||
}
|
||||
|
@ -732,7 +737,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
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
|
||||
{
|
||||
return false;
|
||||
|
@ -744,8 +749,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
return true; // no ToolAttribute on given type -> assumed all supported
|
||||
}
|
||||
|
||||
var displayName = Global.Emulator.DisplayName();
|
||||
var systemId = Global.Emulator.SystemId;
|
||||
var displayName = _emulator.DisplayName();
|
||||
var systemId = _emulator.SystemId;
|
||||
return !attr.UnsupportedCores.Contains(displayName) // not unsupported
|
||||
&& (!attr.SupportedSystems.Any() || attr.SupportedSystems.Contains(systemId)); // supported (no supported list -> assumed all supported)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue