diff --git a/BizHawk.Client.Common/Global.cs b/BizHawk.Client.Common/Global.cs index e36e660e3b..0dda8686fd 100644 --- a/BizHawk.Client.Common/Global.cs +++ b/BizHawk.Client.Common/Global.cs @@ -84,5 +84,9 @@ namespace BizHawk.Client.Common public static SimpleController MovieOutputController = new SimpleController(); public static Controller ClientControls; + + // Input state which has been estine for game controller inputs are coalesce here + // This relies on a client specific implementation! + public static SimpleController ControllerInputCoalescer; } } diff --git a/BizHawk.Client.Common/movie/InputAdapters.cs b/BizHawk.Client.Common/movie/InputAdapters.cs index e32b196f30..1259f9a315 100644 --- a/BizHawk.Client.Common/movie/InputAdapters.cs +++ b/BizHawk.Client.Common/movie/InputAdapters.cs @@ -129,7 +129,13 @@ namespace BizHawk.Client.Common protected WorkingDictionary Buttons = new WorkingDictionary(); protected WorkingDictionary Floats = new WorkingDictionary(); - + + public virtual void Clear() + { + Buttons = new WorkingDictionary(); + Floats = new WorkingDictionary(); + } + public virtual bool this[string button] { get { return Buttons[button]; } set { Buttons[button] = value; } diff --git a/BizHawk.Client.EmuHawk/GlobalWin.cs b/BizHawk.Client.EmuHawk/GlobalWin.cs index 32307e78e8..cfed14692e 100644 --- a/BizHawk.Client.EmuHawk/GlobalWin.cs +++ b/BizHawk.Client.EmuHawk/GlobalWin.cs @@ -19,7 +19,7 @@ namespace BizHawk.Client.EmuHawk public static DisplayManager DisplayManager = new DisplayManager(); //input state which has been destined for game controller inputs are coalesced here - public static ControllerInputCoalescer ControllerInputCoalescer = new ControllerInputCoalescer(); + //public static ControllerInputCoalescer ControllerInputCoalescer = new ControllerInputCoalescer(); //input state which has been destined for client hotkey consumption are colesced here public static InputCoalescer HotkeyCoalescer = new InputCoalescer(); } diff --git a/BizHawk.Client.EmuHawk/MainForm.cs b/BizHawk.Client.EmuHawk/MainForm.cs index e2b97d37f1..2818f45025 100644 --- a/BizHawk.Client.EmuHawk/MainForm.cs +++ b/BizHawk.Client.EmuHawk/MainForm.cs @@ -59,6 +59,7 @@ namespace BizHawk.Client.EmuHawk public MainForm(string[] args) { GlobalWin.MainForm = this; + Global.ControllerInputCoalescer = new ControllerInputCoalescer(); Global.FirmwareManager = new FirmwareManager(); Global.MovieSession = new MovieSession { @@ -397,10 +398,10 @@ namespace BizHawk.Client.EmuHawk // handle events and dispatch as a hotkey action, or a hotkey button, or an input button ProcessInput(); Global.ClientControls.LatchFromPhysical(GlobalWin.HotkeyCoalescer); - Global.ActiveController.LatchFromPhysical(GlobalWin.ControllerInputCoalescer); + Global.ActiveController.LatchFromPhysical(Global.ControllerInputCoalescer); Global.ActiveController.OR_FromLogical(Global.ClickyVirtualPadController); - Global.AutoFireController.LatchFromPhysical(GlobalWin.ControllerInputCoalescer); + Global.AutoFireController.LatchFromPhysical(Global.ControllerInputCoalescer); if (Global.ClientControls["Autohold"]) { @@ -517,8 +518,11 @@ namespace BizHawk.Client.EmuHawk public void ProcessInput() { + ControllerInputCoalescer conInput = Global.ControllerInputCoalescer as ControllerInputCoalescer; + for (; ; ) { + // loop through all available events var ie = Input.Instance.DequeueEvent(); if (ie == null) { break; } @@ -561,7 +565,7 @@ namespace BizHawk.Client.EmuHawk { default: case 0: // Both allowed - GlobalWin.ControllerInputCoalescer.Receive(ie); + conInput.Receive(ie); handled = false; if (ie.EventType == Input.InputEventType.Press) @@ -577,7 +581,7 @@ namespace BizHawk.Client.EmuHawk break; case 1: // Input overrides Hokeys - GlobalWin.ControllerInputCoalescer.Receive(ie); + conInput.Receive(ie); if (!Global.ActiveController.HasBinding(ie.LogicalButton.ToString())) { handled = false; @@ -604,7 +608,7 @@ namespace BizHawk.Client.EmuHawk if (!handled) { GlobalWin.HotkeyCoalescer.Receive(ie); - GlobalWin.ControllerInputCoalescer.Receive(ie); + conInput.Receive(ie); } break; @@ -613,7 +617,7 @@ namespace BizHawk.Client.EmuHawk } // foreach event // also handle floats - GlobalWin.ControllerInputCoalescer.AcceptNewFloats(Input.Instance.GetFloats()); + conInput.AcceptNewFloats(Input.Instance.GetFloats()); } public void RebootCore() @@ -3016,7 +3020,8 @@ namespace BizHawk.Client.EmuHawk private static void RewireInputChain() // Move to Client.Common { - GlobalWin.ControllerInputCoalescer = new ControllerInputCoalescer { Type = Global.ActiveController.Type }; + Global.ControllerInputCoalescer.Clear(); + Global.ControllerInputCoalescer.Type = Global.ActiveController.Type; Global.OrControllerAdapter.Source = Global.ActiveController; Global.OrControllerAdapter.SourceOr = Global.AutoFireController; diff --git a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Input.cs b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Input.cs index 450ba13021..1aca85bfe4 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Input.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Input.cs @@ -31,7 +31,7 @@ namespace BizHawk.Client.EmuHawk public LuaTable input_get() { var buttons = _lua.NewTable(); - foreach (var kvp in GlobalWin.ControllerInputCoalescer.BoolButtons().Where(kvp => kvp.Value)) + foreach (var kvp in Global.ControllerInputCoalescer.BoolButtons().Where(kvp => kvp.Value)) { buttons[kvp.Key] = true; }