LibsnesCore - Move ScanlineHookManager class to its own file
This commit is contained in:
parent
e3ae4b1410
commit
58189f0113
|
@ -914,7 +914,7 @@
|
||||||
<DependentUpon>LibsnesCore.cs</DependentUpon>
|
<DependentUpon>LibsnesCore.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Consoles\Nintendo\SNES\LibsnesCore.IMemoryDomains.cs">
|
<Compile Include="Consoles\Nintendo\SNES\LibsnesCore.IMemoryDomains.cs">
|
||||||
<DependentUpon>LibsnesCore.cs</DependentUpon>
|
<DependentUpon>LibsnesCore.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Consoles\Nintendo\SNES\LibsnesCore.IRegionable.cs">
|
<Compile Include="Consoles\Nintendo\SNES\LibsnesCore.IRegionable.cs">
|
||||||
<DependentUpon>LibsnesCore.cs</DependentUpon>
|
<DependentUpon>LibsnesCore.cs</DependentUpon>
|
||||||
|
@ -938,6 +938,7 @@
|
||||||
<Compile Include="Consoles\Nintendo\SNES\LibsnesCore.IVideoProvider.cs">
|
<Compile Include="Consoles\Nintendo\SNES\LibsnesCore.IVideoProvider.cs">
|
||||||
<DependentUpon>LibsnesCore.cs</DependentUpon>
|
<DependentUpon>LibsnesCore.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Consoles\Nintendo\SNES\ScanlineHookManager.cs" />
|
||||||
<Compile Include="Consoles\Nintendo\SNES\SnesColors.cs" />
|
<Compile Include="Consoles\Nintendo\SNES\SnesColors.cs" />
|
||||||
<Compile Include="Consoles\Nintendo\SNES\SNESGraphicsDecoder.cs" />
|
<Compile Include="Consoles\Nintendo\SNES\SNESGraphicsDecoder.cs" />
|
||||||
<Compile Include="Consoles\PC Engine\ADPCM.cs" />
|
<Compile Include="Consoles\PC Engine\ADPCM.cs" />
|
||||||
|
|
|
@ -233,7 +233,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
|
||||||
_core = core;
|
_core = core;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnHooksChanged()
|
protected override void OnHooksChanged()
|
||||||
{
|
{
|
||||||
_core.OnScanlineHooksChanged();
|
_core.OnScanlineHooksChanged();
|
||||||
}
|
}
|
||||||
|
@ -670,48 +670,4 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ScanlineHookManager
|
|
||||||
{
|
|
||||||
public void Register(object tag, Action<int> callback)
|
|
||||||
{
|
|
||||||
var rr = new RegistrationRecord
|
|
||||||
{
|
|
||||||
tag = tag,
|
|
||||||
callback = callback
|
|
||||||
};
|
|
||||||
|
|
||||||
Unregister(tag);
|
|
||||||
records.Add(rr);
|
|
||||||
OnHooksChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int HookCount => records.Count;
|
|
||||||
|
|
||||||
public virtual void OnHooksChanged()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Unregister(object tag)
|
|
||||||
{
|
|
||||||
records.RemoveAll(r => r.tag == tag);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void HandleScanline(int scanline)
|
|
||||||
{
|
|
||||||
foreach (var rr in records)
|
|
||||||
{
|
|
||||||
rr.callback(scanline);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly List<RegistrationRecord> records = new List<RegistrationRecord>();
|
|
||||||
|
|
||||||
private class RegistrationRecord
|
|
||||||
{
|
|
||||||
public object tag;
|
|
||||||
public int scanline = 0;
|
|
||||||
public Action<int> callback;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace BizHawk.Emulation.Cores.Nintendo.SNES
|
||||||
|
{
|
||||||
|
// TODO: This class is specifically for the SNES Graphics Debugger, but written generally, perhaps it could be moved to a more generic place
|
||||||
|
public class ScanlineHookManager
|
||||||
|
{
|
||||||
|
private readonly List<RegistrationRecord> _records = new List<RegistrationRecord>();
|
||||||
|
|
||||||
|
public void Register(object tag, Action<int> callback)
|
||||||
|
{
|
||||||
|
Unregister(tag);
|
||||||
|
|
||||||
|
_records.Add(new RegistrationRecord
|
||||||
|
{
|
||||||
|
Tag = tag,
|
||||||
|
Callback = callback
|
||||||
|
});
|
||||||
|
|
||||||
|
OnHooksChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int HookCount => _records.Count;
|
||||||
|
|
||||||
|
protected virtual void OnHooksChanged()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Unregister(object tag)
|
||||||
|
{
|
||||||
|
_records.RemoveAll(r => r.Tag == tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void HandleScanline(int scanline)
|
||||||
|
{
|
||||||
|
foreach (var rr in _records)
|
||||||
|
{
|
||||||
|
rr.Callback(scanline);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class RegistrationRecord
|
||||||
|
{
|
||||||
|
public object Tag { get; set; }
|
||||||
|
|
||||||
|
public int Scanline { get; set; } = 0;
|
||||||
|
|
||||||
|
public Action<int> Callback { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue