analog controller stuff should work now
This commit is contained in:
parent
686960da75
commit
9b423d77e9
|
@ -24,8 +24,8 @@ namespace BizHawk.MultiClient
|
||||||
FloatButtons[type.FloatControls[i]] = type.FloatRanges[i].Mid;
|
FloatButtons[type.FloatControls[i]] = type.FloatRanges[i].Mid;
|
||||||
FloatRanges[type.FloatControls[i]] = type.FloatRanges[i];
|
FloatRanges[type.FloatControls[i]] = type.FloatRanges[i];
|
||||||
}
|
}
|
||||||
FloatBinds.Add("J5 X", new Config.AnalogBind("P1 X Axis", 1.0f));
|
//FloatBinds.Add("J5 X", new Config.AnalogBind("P1 X Axis", 1.0f));
|
||||||
FloatBinds.Add("J5 Y", new Config.AnalogBind("P1 Y Axis", -1.0f));
|
//FloatBinds.Add("J5 Y", new Config.AnalogBind("P1 Y Axis", -1.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ControllerDefinition Type { get { return type; } }
|
public ControllerDefinition Type { get { return type; } }
|
||||||
|
@ -89,15 +89,18 @@ namespace BizHawk.MultiClient
|
||||||
}
|
}
|
||||||
foreach (var kvp in FloatBinds)
|
foreach (var kvp in FloatBinds)
|
||||||
{
|
{
|
||||||
float input = controller.GetFloat(kvp.Key);
|
float input = controller.GetFloat(kvp.Value.Value);
|
||||||
string outkey = kvp.Value.Value;
|
string outkey = kvp.Key;
|
||||||
float multiplier = kvp.Value.Mult;
|
float multiplier = kvp.Value.Mult;
|
||||||
ControllerDefinition.FloatRange range;
|
ControllerDefinition.FloatRange range;
|
||||||
if (FloatRanges.TryGetValue(outkey, out range))
|
if (FloatRanges.TryGetValue(outkey, out range))
|
||||||
{
|
{
|
||||||
// input range is assumed to be -10000,0,10000
|
// input range is assumed to be -10000,0,10000
|
||||||
// todo: deadzones and such
|
// todo: deadzones and such
|
||||||
FloatButtons[outkey] = (input * multiplier + 10000.0f) * (range.Max - range.Min) / 20000.0f + range.Min;
|
float output = (input * multiplier + 10000.0f) * (range.Max - range.Min) / 20000.0f + range.Min;
|
||||||
|
if (output < range.Min) output = range.Min;
|
||||||
|
if (output > range.Max) output = range.Max;
|
||||||
|
FloatButtons[outkey] = output;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,6 +137,11 @@ namespace BizHawk.MultiClient
|
||||||
bindings[button].Add(control.Trim());
|
bindings[button].Add(control.Trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void BindFloat(string button, Config.AnalogBind bind)
|
||||||
|
{
|
||||||
|
FloatBinds[button] = bind;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a list of all keys mapped and the name of the button they are mapped to
|
/// Returns a list of all keys mapped and the name of the button they are mapped to
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -165,6 +165,7 @@ namespace BizHawk.MultiClient
|
||||||
private readonly HashSet<string> IgnoreKeys = new HashSet<string>(new[] { "LeftShift", "RightShift", "LeftControl", "RightControl", "LeftAlt", "RightAlt" });
|
private readonly HashSet<string> IgnoreKeys = new HashSet<string>(new[] { "LeftShift", "RightShift", "LeftControl", "RightControl", "LeftAlt", "RightAlt" });
|
||||||
private readonly WorkingDictionary<string, float> FloatValues = new WorkingDictionary<string, float>();
|
private readonly WorkingDictionary<string, float> FloatValues = new WorkingDictionary<string, float>();
|
||||||
private readonly WorkingDictionary<string, float> FloatDeltas = new WorkingDictionary<string, float>();
|
private readonly WorkingDictionary<string, float> FloatDeltas = new WorkingDictionary<string, float>();
|
||||||
|
private bool trackdeltas = false;
|
||||||
|
|
||||||
void HandleButton(string button, bool newState)
|
void HandleButton(string button, bool newState)
|
||||||
{
|
{
|
||||||
|
@ -304,7 +305,8 @@ namespace BizHawk.MultiClient
|
||||||
{
|
{
|
||||||
string n = xname = sv.Item1;
|
string n = xname = sv.Item1;
|
||||||
float f = sv.Item2;
|
float f = sv.Item2;
|
||||||
FloatDeltas[n] += Math.Abs(f - FloatValues[n]);
|
if (trackdeltas)
|
||||||
|
FloatDeltas[n] += Math.Abs(f - FloatValues[n]);
|
||||||
FloatValues[n] = f;
|
FloatValues[n] = f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -323,8 +325,8 @@ namespace BizHawk.MultiClient
|
||||||
float f = sv.Item2;
|
float f = sv.Item2;
|
||||||
//if (n == "J5 RotationZ")
|
//if (n == "J5 RotationZ")
|
||||||
// System.Diagnostics.Debugger.Break();
|
// System.Diagnostics.Debugger.Break();
|
||||||
|
if (trackdeltas)
|
||||||
FloatDeltas[n] += Math.Abs(f - FloatValues[n]);
|
FloatDeltas[n] += Math.Abs(f - FloatValues[n]);
|
||||||
FloatValues[n] = f;
|
FloatValues[n] = f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -350,15 +352,16 @@ namespace BizHawk.MultiClient
|
||||||
|
|
||||||
public void StartListeningForFloatEvents()
|
public void StartListeningForFloatEvents()
|
||||||
{
|
{
|
||||||
lock (this)
|
lock (FloatValues)
|
||||||
{
|
{
|
||||||
FloatDeltas.Clear();
|
FloatDeltas.Clear();
|
||||||
|
trackdeltas = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetNextFloatEvent()
|
public string GetNextFloatEvent()
|
||||||
{
|
{
|
||||||
lock (this)
|
lock (FloatValues)
|
||||||
{
|
{
|
||||||
foreach (var kvp in FloatDeltas)
|
foreach (var kvp in FloatDeltas)
|
||||||
{
|
{
|
||||||
|
@ -370,6 +373,14 @@ namespace BizHawk.MultiClient
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void StopListeningForFloatEvents()
|
||||||
|
{
|
||||||
|
lock (FloatValues)
|
||||||
|
{
|
||||||
|
trackdeltas = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Update()
|
public void Update()
|
||||||
{
|
{
|
||||||
//TODO - for some reason, we may want to control when the next event processing step happens
|
//TODO - for some reason, we may want to control when the next event processing step happens
|
||||||
|
|
|
@ -995,7 +995,7 @@ namespace BizHawk.MultiClient
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Controller BindToDefinition(ControllerDefinition def, Dictionary<string, Dictionary<string, string>> allbinds)
|
static Controller BindToDefinition(ControllerDefinition def, Dictionary<string, Dictionary<string, string>> allbinds, Dictionary<string, Dictionary<string, Config.AnalogBind>> analogbinds)
|
||||||
{
|
{
|
||||||
var ret = new Controller(def);
|
var ret = new Controller(def);
|
||||||
Dictionary<string, string> binds;
|
Dictionary<string, string> binds;
|
||||||
|
@ -1008,9 +1008,21 @@ namespace BizHawk.MultiClient
|
||||||
ret.BindMulti(cbutton, bind);
|
ret.BindMulti(cbutton, bind);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Dictionary<string, Config.AnalogBind> abinds;
|
||||||
|
if (analogbinds.TryGetValue(def.Name, out abinds))
|
||||||
|
{
|
||||||
|
foreach (string cbutton in def.FloatControls)
|
||||||
|
{
|
||||||
|
Config.AnalogBind bind;
|
||||||
|
if (abinds.TryGetValue(cbutton, out bind))
|
||||||
|
{
|
||||||
|
ret.BindFloat(cbutton, bind);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
// could merge these two methods...
|
|
||||||
static AutofireController BindToDefinitionAF(ControllerDefinition def, Dictionary<string, Dictionary<string, string>> allbinds)
|
static AutofireController BindToDefinitionAF(ControllerDefinition def, Dictionary<string, Dictionary<string, string>> allbinds)
|
||||||
{
|
{
|
||||||
var ret = new AutofireController(def);
|
var ret = new AutofireController(def);
|
||||||
|
@ -1032,7 +1044,7 @@ namespace BizHawk.MultiClient
|
||||||
{
|
{
|
||||||
var def = Global.Emulator.ControllerDefinition;
|
var def = Global.Emulator.ControllerDefinition;
|
||||||
|
|
||||||
Global.ActiveController = BindToDefinition(def, Global.Config.AllTrollers);
|
Global.ActiveController = BindToDefinition(def, Global.Config.AllTrollers, Global.Config.AllTrollersAnalog);
|
||||||
Global.AutoFireController = BindToDefinitionAF(def, Global.Config.AllTrollersAutoFire);
|
Global.AutoFireController = BindToDefinitionAF(def, Global.Config.AllTrollersAutoFire);
|
||||||
|
|
||||||
// allow propogating controls that are in the current controller definition but not in the prebaked one
|
// allow propogating controls that are in the current controller definition but not in the prebaked one
|
||||||
|
|
|
@ -16,6 +16,7 @@ namespace BizHawk.MultiClient.config.ControllerConfig
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string ButtonName;
|
||||||
public Config.AnalogBind Bind;
|
public Config.AnalogBind Bind;
|
||||||
bool listening = false;
|
bool listening = false;
|
||||||
|
|
||||||
|
@ -23,6 +24,7 @@ namespace BizHawk.MultiClient.config.ControllerConfig
|
||||||
: this()
|
: this()
|
||||||
{
|
{
|
||||||
this.Bind = Bind;
|
this.Bind = Bind;
|
||||||
|
this.ButtonName = ButtonName;
|
||||||
labelButtonName.Text = ButtonName;
|
labelButtonName.Text = ButtonName;
|
||||||
trackBarSensitivity.Value = (int)(Bind.Mult * 1000.0f);
|
trackBarSensitivity.Value = (int)(Bind.Mult * 1000.0f);
|
||||||
textBox1.Text = Bind.Value;
|
textBox1.Text = Bind.Value;
|
||||||
|
|
|
@ -35,5 +35,14 @@ namespace BizHawk.MultiClient.config.ControllerConfig
|
||||||
}
|
}
|
||||||
ResumeLayout();
|
ResumeLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Save()
|
||||||
|
{
|
||||||
|
foreach (Control c in Controls)
|
||||||
|
{
|
||||||
|
var abc = (AnalogBindControl)c;
|
||||||
|
RealConfigObject[abc.ButtonName] = abc.Bind;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using BizHawk.MultiClient.config.ControllerConfig;
|
||||||
|
|
||||||
namespace BizHawk.MultiClient.config
|
namespace BizHawk.MultiClient.config
|
||||||
{
|
{
|
||||||
|
@ -50,7 +51,7 @@ namespace BizHawk.MultiClient.config
|
||||||
|
|
||||||
Control CreateAnalogPanel(Dictionary<string, Config.AnalogBind> settings, List<string> buttons, Size size)
|
Control CreateAnalogPanel(Dictionary<string, Config.AnalogBind> settings, List<string> buttons, Size size)
|
||||||
{
|
{
|
||||||
var acp = new config.ControllerConfig.AnalogBindPanel(settings, buttons);
|
var acp = new AnalogBindPanel(settings, buttons);
|
||||||
return acp;
|
return acp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,6 +154,8 @@ namespace BizHawk.MultiClient.config
|
||||||
{
|
{
|
||||||
if (c is ControllerConfigPanel)
|
if (c is ControllerConfigPanel)
|
||||||
(c as ControllerConfigPanel).SetAutoTab(value);
|
(c as ControllerConfigPanel).SetAutoTab(value);
|
||||||
|
else if (c is AnalogBindPanel)
|
||||||
|
;// TODO
|
||||||
else if (c.HasChildren)
|
else if (c.HasChildren)
|
||||||
foreach (Control cc in c.Controls)
|
foreach (Control cc in c.Controls)
|
||||||
SetAutoTab(cc, value);
|
SetAutoTab(cc, value);
|
||||||
|
@ -162,6 +165,8 @@ namespace BizHawk.MultiClient.config
|
||||||
{
|
{
|
||||||
if (c is ControllerConfigPanel)
|
if (c is ControllerConfigPanel)
|
||||||
(c as ControllerConfigPanel).Save();
|
(c as ControllerConfigPanel).Save();
|
||||||
|
else if (c is AnalogBindPanel)
|
||||||
|
(c as AnalogBindPanel).Save();
|
||||||
else if (c.HasChildren)
|
else if (c.HasChildren)
|
||||||
foreach (Control cc in c.Controls)
|
foreach (Control cc in c.Controls)
|
||||||
Save(cc);
|
Save(cc);
|
||||||
|
|
Loading…
Reference in New Issue