BasicServiceProvider - catch any IEmulatorServices that the core implements that aren't defined in the Emulation.Common assembly, and make IGBAGPUViewable an emulator service

This commit is contained in:
adelikat 2014-12-13 23:45:51 +00:00
parent 7f0229d9e6
commit d1cc13a9c0
2 changed files with 33 additions and 33 deletions

View File

@ -10,9 +10,10 @@ using System.Collections.Generic;
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
{ {
[RequiredServices(typeof(IGBAGPUViewable))]
public partial class GBAGPUView : Form, IToolForm public partial class GBAGPUView : Form, IToolForm
{ {
IGBAGPUViewable gba; IGBAGPUViewable gba { get { return (IGBAGPUViewable)EmulatorServices[typeof(IGBAGPUViewable)]; } }
public IDictionary<Type, object> EmulatorServices { private get; set; } public IDictionary<Type, object> EmulatorServices { private get; set; }
@ -682,9 +683,6 @@ namespace BizHawk.Client.EmuHawk
public void Restart() public void Restart()
{
gba = Global.Emulator as IGBAGPUViewable;
if (gba != null)
{ {
var mem = gba.GetMemoryAreas(); var mem = gba.GetMemoryAreas();
vram = mem.vram; vram = mem.vram;
@ -695,20 +693,13 @@ namespace BizHawk.Client.EmuHawk
_cbscanlineEmu = 500; // force an update _cbscanlineEmu = 500; // force an update
UpdateValues(); UpdateValues();
} }
else
{
if (Visible)
Close();
}
}
/// <summary>belongs in ToolsBefore</summary> /// <summary>belongs in ToolsBefore</summary>
public void UpdateValues() public void UpdateValues()
{ {
if (!IsHandleCreated || IsDisposed) if (!IsHandleCreated || IsDisposed)
return; return;
if (gba != null)
{
if (_cbscanlineEmu != _cbscanline) if (_cbscanlineEmu != _cbscanline)
{ {
_cbscanlineEmu = _cbscanline; _cbscanlineEmu = _cbscanline;
@ -722,7 +713,6 @@ namespace BizHawk.Client.EmuHawk
} }
} }
} }
}
public void FastUpdate() public void FastUpdate()
{ {
@ -805,12 +795,8 @@ namespace BizHawk.Client.EmuHawk
#endregion #endregion
private void GBAGPUView_FormClosed(object sender, FormClosedEventArgs e) private void GBAGPUView_FormClosed(object sender, FormClosedEventArgs e)
{
if (gba != null)
{ {
gba.SetScanlineCallback(null, 0); gba.SetScanlineCallback(null, 0);
gba = null;
}
} }
#region copy to clipboard #region copy to clipboard

View File

@ -33,6 +33,20 @@ namespace BizHawk.Emulation.Common
// Add the core itself since we know a core implements IEmulatorService // Add the core itself since we know a core implements IEmulatorService
Services.Add(core.GetType(), core); Services.Add(core.GetType(), core);
// Any IEmulatorServices the core might have that are core specific (and therefore not in Emulation.Common)
var coreSpecificServices = core
.GetType()
.GetInterfaces()
.Where(i => !services.Contains(i))
.Where(t => typeof(IEmulatorService).IsAssignableFrom(t))
.Where(t => !t.FullName.Contains("ISettable")) // adelikat: TODO: Hack! but I need a way around this, every core implements their own specific ISettable
.ToList();
foreach (var service in coreSpecificServices)
{
Services.Add(service, core);
}
foreach (var service in core.GetType().GetNestedTypes(BindingFlags.Public) foreach (var service in core.GetType().GetNestedTypes(BindingFlags.Public)
.Where(t => typeof(IEmulatorService).IsAssignableFrom(t)) .Where(t => typeof(IEmulatorService).IsAssignableFrom(t))
.Where(t => t.IsClass)) .Where(t => t.IsClass))