diff --git a/BizHawk.Client.Common/BizHawk.Client.Common.csproj b/BizHawk.Client.Common/BizHawk.Client.Common.csproj index 3d8a3c6ad4..d59a5d43ea 100644 --- a/BizHawk.Client.Common/BizHawk.Client.Common.csproj +++ b/BizHawk.Client.Common/BizHawk.Client.Common.csproj @@ -105,6 +105,7 @@ + diff --git a/BizHawk.Client.Common/InputManager.cs b/BizHawk.Client.Common/InputManager.cs new file mode 100644 index 0000000000..2a3ab5e436 --- /dev/null +++ b/BizHawk.Client.Common/InputManager.cs @@ -0,0 +1,107 @@ +using System.Collections.Generic; + +using BizHawk.Emulation.Common; + +namespace BizHawk.Client.Common +{ + public static class InputManager + { + public static void RewireInputChain() + { + Global.ControllerInputCoalescer.Clear(); + Global.ControllerInputCoalescer.Type = Global.ActiveController.Type; + + Global.OrControllerAdapter.Source = Global.ActiveController; + Global.OrControllerAdapter.SourceOr = Global.AutoFireController; + Global.UD_LR_ControllerAdapter.Source = Global.OrControllerAdapter; + + Global.StickyXORAdapter.Source = Global.UD_LR_ControllerAdapter; + Global.AutofireStickyXORAdapter.Source = Global.StickyXORAdapter; + + Global.MultitrackRewiringControllerAdapter.Source = Global.AutofireStickyXORAdapter; + Global.ForceOffAdaptor.Source = Global.MultitrackRewiringControllerAdapter; + + Global.MovieInputSourceAdapter.Source = Global.ForceOffAdaptor; + Global.ControllerOutput.Source = Global.MovieOutputHardpoint; + + Global.Emulator.Controller = Global.ControllerOutput; + Global.MovieSession.MovieControllerAdapter.Type = Global.MovieInputSourceAdapter.Type; + + // connect the movie session before MovieOutputHardpoint if it is doing anything + // otherwise connect the MovieInputSourceAdapter to it, effectively bypassing the movie session + if (Global.MovieSession.Movie != null) + { + Global.MovieOutputHardpoint.Source = Global.MovieSession.MovieControllerAdapter; + } + else + { + Global.MovieOutputHardpoint.Source = Global.MovieInputSourceAdapter; + } + } + + public static void SyncControls() // Move to client.comon + { + var def = Global.Emulator.ControllerDefinition; + + Global.ActiveController = BindToDefinition(def, Global.Config.AllTrollers, Global.Config.AllTrollersAnalog); + Global.AutoFireController = BindToDefinitionAF(def, Global.Config.AllTrollersAutoFire); + + // allow propogating controls that are in the current controller definition but not in the prebaked one + // these two lines shouldn't be required anymore under the new system? + Global.ActiveController.ForceType(new ControllerDefinition(Global.Emulator.ControllerDefinition)); + Global.ClickyVirtualPadController.Type = new ControllerDefinition(Global.Emulator.ControllerDefinition); + RewireInputChain(); + } + + private static Controller BindToDefinition(ControllerDefinition def, IDictionary> allbinds, IDictionary> analogbinds) + { + var ret = new Controller(def); + Dictionary binds; + if (allbinds.TryGetValue(def.Name, out binds)) + { + foreach (var cbutton in def.BoolButtons) + { + string bind; + if (binds.TryGetValue(cbutton, out bind)) + { + ret.BindMulti(cbutton, bind); + } + } + } + + Dictionary abinds; + if (analogbinds.TryGetValue(def.Name, out abinds)) + { + foreach (var cbutton in def.FloatControls) + { + Config.AnalogBind bind; + if (abinds.TryGetValue(cbutton, out bind)) + { + ret.BindFloat(cbutton, bind); + } + } + } + + return ret; + } + + private static AutofireController BindToDefinitionAF(ControllerDefinition def, IDictionary> allbinds) + { + var ret = new AutofireController(def); + Dictionary binds; + if (allbinds.TryGetValue(def.Name, out binds)) + { + foreach (var cbutton in def.BoolButtons) + { + string bind; + if (binds.TryGetValue(cbutton, out bind)) + { + ret.BindMulti(cbutton, bind); + } + } + } + + return ret; + } + } +} \ No newline at end of file diff --git a/BizHawk.Client.EmuHawk/MainForm.Events.cs b/BizHawk.Client.EmuHawk/MainForm.Events.cs index 8f32505de9..8f34a0df82 100644 --- a/BizHawk.Client.EmuHawk/MainForm.Events.cs +++ b/BizHawk.Client.EmuHawk/MainForm.Events.cs @@ -804,7 +804,7 @@ namespace BizHawk.Client.EmuHawk if (controller.ShowDialog() == DialogResult.OK) { InitControls(); - SyncControls(); + InputManager.SyncControls(); } } @@ -814,7 +814,7 @@ namespace BizHawk.Client.EmuHawk if (hotkeys.ShowDialog() == DialogResult.OK) { InitControls(); - SyncControls(); + InputManager.SyncControls(); } } diff --git a/BizHawk.Client.EmuHawk/MainForm.Movie.cs b/BizHawk.Client.EmuHawk/MainForm.Movie.cs index ef9e123aed..5d7a57334c 100644 --- a/BizHawk.Client.EmuHawk/MainForm.Movie.cs +++ b/BizHawk.Client.EmuHawk/MainForm.Movie.cs @@ -27,7 +27,7 @@ namespace BizHawk.Client.EmuHawk AskYesNoCallback = StateErrorAskUser }; - RewireInputChain(); + InputManager.RewireInputChain(); if (!record) { diff --git a/BizHawk.Client.EmuHawk/MainForm.cs b/BizHawk.Client.EmuHawk/MainForm.cs index 2818f45025..3724aa9849 100644 --- a/BizHawk.Client.EmuHawk/MainForm.cs +++ b/BizHawk.Client.EmuHawk/MainForm.cs @@ -160,7 +160,7 @@ namespace BizHawk.Client.EmuHawk Global.Sound = new Sound(); #endif GlobalWin.Sound.StartSound(); - RewireInputChain(); + InputManager.RewireInputChain(); GlobalWin.Tools = new ToolManager(); RewireSound(); @@ -1385,57 +1385,6 @@ namespace BizHawk.Client.EmuHawk } } - private static Controller BindToDefinition(ControllerDefinition def, IDictionary> allbinds, IDictionary> analogbinds) - { - var ret = new Controller(def); - Dictionary binds; - if (allbinds.TryGetValue(def.Name, out binds)) - { - foreach (var cbutton in def.BoolButtons) - { - string bind; - if (binds.TryGetValue(cbutton, out bind)) - { - ret.BindMulti(cbutton, bind); - } - } - } - - Dictionary abinds; - if (analogbinds.TryGetValue(def.Name, out abinds)) - { - foreach (var cbutton in def.FloatControls) - { - Config.AnalogBind bind; - if (abinds.TryGetValue(cbutton, out bind)) - { - ret.BindFloat(cbutton, bind); - } - } - } - - return ret; - } - - private static AutofireController BindToDefinitionAF(ControllerDefinition def, IDictionary> allbinds) - { - var ret = new AutofireController(def); - Dictionary binds; - if (allbinds.TryGetValue(def.Name, out binds)) - { - foreach (var cbutton in def.BoolButtons) - { - string bind; - if (binds.TryGetValue(cbutton, out bind)) - { - ret.BindMulti(cbutton, bind); - } - } - } - - return ret; - } - private void SaturnSetPrefs(Yabause e = null) { if (e == null) @@ -3018,53 +2967,6 @@ namespace BizHawk.Client.EmuHawk MessageBox.Show(this, message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } - private static void RewireInputChain() // Move to Client.Common - { - Global.ControllerInputCoalescer.Clear(); - Global.ControllerInputCoalescer.Type = Global.ActiveController.Type; - - Global.OrControllerAdapter.Source = Global.ActiveController; - Global.OrControllerAdapter.SourceOr = Global.AutoFireController; - Global.UD_LR_ControllerAdapter.Source = Global.OrControllerAdapter; - - Global.StickyXORAdapter.Source = Global.UD_LR_ControllerAdapter; - Global.AutofireStickyXORAdapter.Source = Global.StickyXORAdapter; - - Global.MultitrackRewiringControllerAdapter.Source = Global.AutofireStickyXORAdapter; - Global.ForceOffAdaptor.Source = Global.MultitrackRewiringControllerAdapter; - - Global.MovieInputSourceAdapter.Source = Global.ForceOffAdaptor; - Global.ControllerOutput.Source = Global.MovieOutputHardpoint; - - Global.Emulator.Controller = Global.ControllerOutput; - Global.MovieSession.MovieControllerAdapter.Type = Global.MovieInputSourceAdapter.Type; - - // connect the movie session before MovieOutputHardpoint if it is doing anything - // otherwise connect the MovieInputSourceAdapter to it, effectively bypassing the movie session - if (Global.MovieSession.Movie != null) - { - Global.MovieOutputHardpoint.Source = Global.MovieSession.MovieControllerAdapter; - } - else - { - Global.MovieOutputHardpoint.Source = Global.MovieInputSourceAdapter; - } - } - - private static void SyncControls() // Move to client.comon - { - var def = Global.Emulator.ControllerDefinition; - - Global.ActiveController = BindToDefinition(def, Global.Config.AllTrollers, Global.Config.AllTrollersAnalog); - Global.AutoFireController = BindToDefinitionAF(def, Global.Config.AllTrollersAutoFire); - - // allow propogating controls that are in the current controller definition but not in the prebaked one - // these two lines shouldn't be required anymore under the new system? - Global.ActiveController.ForceType(new ControllerDefinition(Global.Emulator.ControllerDefinition)); - Global.ClickyVirtualPadController.Type = new ControllerDefinition(Global.Emulator.ControllerDefinition); - RewireInputChain(); - } - public bool LoadRom(string path, bool deterministicemulation = false, bool hasmovie = false) // Move to client.common { if (path == null) @@ -3423,7 +3325,7 @@ namespace BizHawk.Client.EmuHawk Global.CoreComm = nextComm; Global.Game = game; CoreFileProvider.SyncCoreCommInputSignals(); - SyncControls(); + InputManager.SyncControls(); if (nextEmulator is LibsnesCore) {