Check in patch from zeromus that provides back end support for custom Axis constraints for analog input
This commit is contained in:
parent
0f9488f405
commit
0588c3d7ea
|
@ -132,6 +132,11 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
}
|
||||
|
||||
public void ApplyAxisConstraints(string constraintClass)
|
||||
{
|
||||
_type.ApplyAxisConstraints(constraintClass,_floatButtons);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// merges pressed logical buttons from the supplied controller, effectively ORing it with the current state
|
||||
/// </summary>
|
||||
|
|
|
@ -427,8 +427,12 @@ 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(Global.ControllerInputCoalescer);
|
||||
|
||||
//TODO - use preferences to apply this
|
||||
Global.ActiveController.ApplyAxisConstraints("Natural Circle");
|
||||
|
||||
Global.ActiveController.OR_FromLogical(Global.ClickyVirtualPadController);
|
||||
Global.ActiveController.Overrides(Global.LuaAndAdaptor);
|
||||
Global.AutoFireController.LatchFromPhysical(Global.ControllerInputCoalescer);
|
||||
|
|
|
@ -17,6 +17,38 @@ namespace BizHawk.Emulation.Common
|
|||
|
||||
public class ControllerDefinition
|
||||
{
|
||||
public void ApplyAxisConstraints(string constraintClass, IDictionary<string, float> floatButtons)
|
||||
{
|
||||
if (AxisConstraints == null) return;
|
||||
|
||||
foreach (var constraint in AxisConstraints)
|
||||
{
|
||||
if (constraint.Class != constraintClass)
|
||||
continue;
|
||||
switch (constraint.Type)
|
||||
{
|
||||
case AxisConstraintType.Circular:
|
||||
{
|
||||
string xaxis = constraint.Params[0] as string;
|
||||
string yaxis = constraint.Params[1] as string;
|
||||
float range = (float)constraint.Params[2];
|
||||
double xval = floatButtons[xaxis];
|
||||
double yval = floatButtons[yaxis];
|
||||
double length = Math.Sqrt(xval * xval + yval * yval);
|
||||
if (length > range)
|
||||
{
|
||||
double ratio = range / length;
|
||||
xval *= ratio;
|
||||
yval *= ratio;
|
||||
}
|
||||
floatButtons[xaxis] = (float)xval;
|
||||
floatButtons[yaxis] = (float)yval;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public struct FloatRange
|
||||
{
|
||||
public readonly float Min;
|
||||
|
@ -46,11 +78,24 @@ namespace BizHawk.Emulation.Common
|
|||
}
|
||||
}
|
||||
|
||||
public enum AxisConstraintType
|
||||
{
|
||||
Circular
|
||||
}
|
||||
|
||||
public struct AxisConstraint
|
||||
{
|
||||
public string Class;
|
||||
public AxisConstraintType Type;
|
||||
public object[] Params;
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public List<string> BoolButtons { get; set; }
|
||||
public List<string> FloatControls { get; private set; }
|
||||
public List<FloatRange> FloatRanges { get; private set; }
|
||||
public List<AxisConstraint> AxisConstraints { get; private set; }
|
||||
|
||||
public ControllerDefinition(ControllerDefinition source)
|
||||
: this()
|
||||
|
@ -59,6 +104,7 @@ namespace BizHawk.Emulation.Common
|
|||
BoolButtons.AddRange(source.BoolButtons);
|
||||
FloatControls.AddRange(source.FloatControls);
|
||||
FloatRanges.AddRange(source.FloatRanges);
|
||||
AxisConstraints.AddRange(source.AxisConstraints);
|
||||
}
|
||||
|
||||
public ControllerDefinition()
|
||||
|
@ -66,6 +112,7 @@ namespace BizHawk.Emulation.Common
|
|||
BoolButtons = new List<string>();
|
||||
FloatControls = new List<string>();
|
||||
FloatRanges = new List<FloatRange>();
|
||||
AxisConstraints = new List<AxisConstraint>();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64
|
|||
new[] {127.0f, 0.0f, -128.0f},
|
||||
new[] {-128.0f, 0.0f, 127.0f},
|
||||
new[] {127.0f, 0.0f, -128.0f}
|
||||
},
|
||||
AxisConstraints =
|
||||
{
|
||||
new ControllerDefinition.AxisConstraint { Class = "Natural Circle", Type = ControllerDefinition.AxisConstraintType.Circular, Params = new object[] {"P1 X Axis", "P1 Y Axis", 127.0f} }
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue