move some stuff from EmuHawk to Client.Common

This commit is contained in:
adelikat 2013-12-24 21:59:41 +00:00
parent 302e71edc3
commit dd63395f67
5 changed files with 113 additions and 103 deletions

View File

@ -105,6 +105,7 @@
<Compile Include="FirmwareManager.cs" />
<Compile Include="Global.cs" />
<Compile Include="helpers\InputValidate.cs" />
<Compile Include="InputManager.cs" />
<Compile Include="IPS.cs" />
<Compile Include="KeyTurbo.cs" />
<Compile Include="lua\EmuLuaLibrary.Bit.cs" />

View File

@ -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<string, Dictionary<string, string>> allbinds, IDictionary<string, Dictionary<string, Config.AnalogBind>> analogbinds)
{
var ret = new Controller(def);
Dictionary<string, string> 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<string, Config.AnalogBind> 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<string, Dictionary<string, string>> allbinds)
{
var ret = new AutofireController(def);
Dictionary<string, string> 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;
}
}
}

View File

@ -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();
}
}

View File

@ -27,7 +27,7 @@ namespace BizHawk.Client.EmuHawk
AskYesNoCallback = StateErrorAskUser
};
RewireInputChain();
InputManager.RewireInputChain();
if (!record)
{

View File

@ -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<string, Dictionary<string, string>> allbinds, IDictionary<string, Dictionary<string, Config.AnalogBind>> analogbinds)
{
var ret = new Controller(def);
Dictionary<string, string> 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<string, Config.AnalogBind> 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<string, Dictionary<string, string>> allbinds)
{
var ret = new AutofireController(def);
Dictionary<string, string> 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)
{