analog controller stuff should work now

This commit is contained in:
goyuken 2013-07-24 02:14:25 +00:00
parent 686960da75
commit 9b423d77e9
6 changed files with 61 additions and 14 deletions

View File

@ -24,8 +24,8 @@ namespace BizHawk.MultiClient
FloatButtons[type.FloatControls[i]] = type.FloatRanges[i].Mid;
FloatRanges[type.FloatControls[i]] = type.FloatRanges[i];
}
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 X", new Config.AnalogBind("P1 X Axis", 1.0f));
//FloatBinds.Add("J5 Y", new Config.AnalogBind("P1 Y Axis", -1.0f));
}
public ControllerDefinition Type { get { return type; } }
@ -89,15 +89,18 @@ namespace BizHawk.MultiClient
}
foreach (var kvp in FloatBinds)
{
float input = controller.GetFloat(kvp.Key);
string outkey = kvp.Value.Value;
float input = controller.GetFloat(kvp.Value.Value);
string outkey = kvp.Key;
float multiplier = kvp.Value.Mult;
ControllerDefinition.FloatRange range;
if (FloatRanges.TryGetValue(outkey, out range))
{
// input range is assumed to be -10000,0,10000
// 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());
}
public void BindFloat(string button, Config.AnalogBind bind)
{
FloatBinds[button] = bind;
}
/// <summary>
/// Returns a list of all keys mapped and the name of the button they are mapped to
/// </summary>

View File

@ -165,6 +165,7 @@ namespace BizHawk.MultiClient
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> FloatDeltas = new WorkingDictionary<string, float>();
private bool trackdeltas = false;
void HandleButton(string button, bool newState)
{
@ -304,7 +305,8 @@ namespace BizHawk.MultiClient
{
string n = xname = sv.Item1;
float f = sv.Item2;
FloatDeltas[n] += Math.Abs(f - FloatValues[n]);
if (trackdeltas)
FloatDeltas[n] += Math.Abs(f - FloatValues[n]);
FloatValues[n] = f;
}
}
@ -323,8 +325,8 @@ namespace BizHawk.MultiClient
float f = sv.Item2;
//if (n == "J5 RotationZ")
// System.Diagnostics.Debugger.Break();
FloatDeltas[n] += Math.Abs(f - FloatValues[n]);
if (trackdeltas)
FloatDeltas[n] += Math.Abs(f - FloatValues[n]);
FloatValues[n] = f;
}
}
@ -350,15 +352,16 @@ namespace BizHawk.MultiClient
public void StartListeningForFloatEvents()
{
lock (this)
lock (FloatValues)
{
FloatDeltas.Clear();
trackdeltas = true;
}
}
public string GetNextFloatEvent()
{
lock (this)
lock (FloatValues)
{
foreach (var kvp in FloatDeltas)
{
@ -370,6 +373,14 @@ namespace BizHawk.MultiClient
return null;
}
public void StopListeningForFloatEvents()
{
lock (FloatValues)
{
trackdeltas = false;
}
}
public void Update()
{
//TODO - for some reason, we may want to control when the next event processing step happens

View File

@ -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);
Dictionary<string, string> binds;
@ -1008,9 +1008,21 @@ namespace BizHawk.MultiClient
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;
}
// could merge these two methods...
static AutofireController BindToDefinitionAF(ControllerDefinition def, Dictionary<string, Dictionary<string, string>> allbinds)
{
var ret = new AutofireController(def);
@ -1032,7 +1044,7 @@ namespace BizHawk.MultiClient
{
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);
// allow propogating controls that are in the current controller definition but not in the prebaked one

View File

@ -16,6 +16,7 @@ namespace BizHawk.MultiClient.config.ControllerConfig
InitializeComponent();
}
public string ButtonName;
public Config.AnalogBind Bind;
bool listening = false;
@ -23,6 +24,7 @@ namespace BizHawk.MultiClient.config.ControllerConfig
: this()
{
this.Bind = Bind;
this.ButtonName = ButtonName;
labelButtonName.Text = ButtonName;
trackBarSensitivity.Value = (int)(Bind.Mult * 1000.0f);
textBox1.Text = Bind.Value;

View File

@ -35,5 +35,14 @@ namespace BizHawk.MultiClient.config.ControllerConfig
}
ResumeLayout();
}
public void Save()
{
foreach (Control c in Controls)
{
var abc = (AnalogBindControl)c;
RealConfigObject[abc.ButtonName] = abc.Bind;
}
}
}
}

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using BizHawk.MultiClient.config.ControllerConfig;
namespace BizHawk.MultiClient.config
{
@ -50,7 +51,7 @@ namespace BizHawk.MultiClient.config
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;
}
@ -153,6 +154,8 @@ namespace BizHawk.MultiClient.config
{
if (c is ControllerConfigPanel)
(c as ControllerConfigPanel).SetAutoTab(value);
else if (c is AnalogBindPanel)
;// TODO
else if (c.HasChildren)
foreach (Control cc in c.Controls)
SetAutoTab(cc, value);
@ -162,6 +165,8 @@ namespace BizHawk.MultiClient.config
{
if (c is ControllerConfigPanel)
(c as ControllerConfigPanel).Save();
else if (c is AnalogBindPanel)
(c as AnalogBindPanel).Save();
else if (c.HasChildren)
foreach (Control cc in c.Controls)
Save(cc);