Lua - event.OnInputPoll() - allow multiple functions to be registered

This commit is contained in:
adelikat 2013-11-10 18:15:32 +00:00
parent 28a73c8174
commit ea24f236fb
12 changed files with 45 additions and 25 deletions

View File

@ -149,7 +149,7 @@ namespace BizHawk.Client.Common
{
if (luaf != null)
{
Global.Emulator.CoreComm.InputCallback = delegate
Global.Emulator.CoreComm.InputCallback.Add(delegate
{
try
{
@ -162,7 +162,7 @@ namespace BizHawk.Client.Common
"\nError message: "
+ e.Message);
}
};
});
}
else
{

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace BizHawk.Emulation.Common
@ -38,7 +39,7 @@ namespace BizHawk.Emulation.Common
/// <summary>
/// for emu.on_snoop()
/// </summary>
public Action InputCallback;
public InputCallbackSystem InputCallback = new InputCallbackSystem();
public MemoryCallbackSystem MemoryCallbackSystem = new MemoryCallbackSystem();
@ -118,6 +119,34 @@ namespace BizHawk.Emulation.Common
private bool logging;
}
public class InputCallbackSystem
{
private List<Action> _list = new List<Action>();
public void Add(Action action)
{
_list.Add(action);
}
public void Call()
{
foreach (var action in _list)
{
action();
}
}
public void Remove(Action action)
{
throw new NotImplementedException();
}
public void Clear()
{
_list.Clear();
}
}
public class MemoryCallbackSystem
{
public int? ReadAddr = null;

View File

@ -237,7 +237,7 @@ namespace BizHawk
public byte ReadControls1(bool peek)
{
if (CoreComm.InputCallback != null) CoreComm.InputCallback();
CoreComm.InputCallback.Call();
byte value = 0xFF;
if (Controller["P1 Up"]) value &= 0xEF;
@ -251,7 +251,7 @@ namespace BizHawk
public byte ReadControls2(bool peek)
{
if (CoreComm.InputCallback != null) CoreComm.InputCallback();
CoreComm.InputCallback.Call();
byte value = 0xFF;
if (Controller["P2 Up"]) value &= 0xEF;

View File

@ -155,7 +155,7 @@ namespace BizHawk.Emulation.Consoles.Calculator
byte ReadKeyboard()
{
if (CoreComm.InputCallback != null) CoreComm.InputCallback();
CoreComm.InputCallback.Call();
//ref TI-9X
int ret = 0xFF;

View File

@ -119,7 +119,7 @@ namespace BizHawk.Emulation.Consoles.GB
LibGambatte.Buttons ControllerCallback()
{
if (CoreComm.InputCallback != null) CoreComm.InputCallback();
CoreComm.InputCallback.Call();
IsLagFrame = false;
return CurrentButtons;
}

View File

@ -54,8 +54,8 @@ namespace BizHawk.Emulation.Consoles.GB
SetMemoryDomains();
L.CoreComm.InputCallback = CallbackLinker;
R.CoreComm.InputCallback = CallbackLinker;
L.CoreComm.InputCallback = CoreComm.InputCallback;
R.CoreComm.InputCallback = CoreComm.InputCallback;
}
public IVideoProvider VideoProvider { get { return this; } }
@ -77,15 +77,6 @@ namespace BizHawk.Emulation.Consoles.GB
public ControllerDefinition ControllerDefinition { get { return DualGbController; } }
public IController Controller { get; set; }
/// <summary>
/// each sub-core calls this
/// </summary>
void CallbackLinker()
{
if (CoreComm.InputCallback != null)
CoreComm.InputCallback();
}
public void FrameAdvance(bool render, bool rendersound = true)
{
LCont.Clear();

View File

@ -96,7 +96,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo.N64
public void setControllers()
{
if (CoreComm.InputCallback != null) CoreComm.InputCallback();
CoreComm.InputCallback.Call();
IsLagFrame = false;
// Analog stick right = +X

View File

@ -392,7 +392,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
byte read_joyport(int addr)
{
if (CoreComm.InputCallback != null) CoreComm.InputCallback();
CoreComm.InputCallback.Call();
return handle_read_joyport(addr, false);
}

View File

@ -290,7 +290,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo.SNES
{
// as this is implemented right now, only P1 and P2 normal controllers work
if (!nocallbacks && CoreComm.InputCallback != null) CoreComm.InputCallback();
CoreComm.InputCallback.Call();
//Console.WriteLine("{0} {1} {2} {3}", port, device, index, id);
string key = "P" + (1 + port) + " ";

View File

@ -41,7 +41,7 @@ namespace BizHawk.Emulation.Consoles.TurboGrafx
byte ReadInput()
{
if (CoreComm.InputCallback != null) CoreComm.InputCallback();
CoreComm.InputCallback.Call();
byte value = 0x3F;
int player = SelectedController + 1;

View File

@ -108,7 +108,7 @@ namespace BizHawk.Emulation.Consoles.Sega
void ReadController(ref byte data)
{
if (CoreComm.InputCallback != null) CoreComm.InputCallback();
CoreComm.InputCallback.Call();
data &= 0xC0;
if ((data & 0x40) != 0) // TH high
{

View File

@ -20,7 +20,7 @@ namespace BizHawk.Emulation.Consoles.Sega
byte ReadControls1()
{
if (CoreComm.InputCallback != null) CoreComm.InputCallback();
CoreComm.InputCallback.Call();
lagged = false;
byte value = 0xFF;
@ -39,7 +39,7 @@ namespace BizHawk.Emulation.Consoles.Sega
byte ReadControls2()
{
if (CoreComm.InputCallback != null) CoreComm.InputCallback();
CoreComm.InputCallback.Call();
lagged = false;
byte value = 0xFF;