Misc controller adapter cleanups
This commit is contained in:
parent
e0e5eaea44
commit
82ee945782
|
@ -2,11 +2,6 @@
|
|||
{
|
||||
public class AutoPatternBool
|
||||
{
|
||||
public readonly bool SkipsLag = true;
|
||||
public readonly bool[] Pattern;
|
||||
public readonly int Loop = 0;
|
||||
private int _index = 0;
|
||||
|
||||
public AutoPatternBool()
|
||||
{
|
||||
Pattern = new[] { true };
|
||||
|
@ -36,6 +31,12 @@
|
|||
Loop = loop;
|
||||
}
|
||||
|
||||
private int _index;
|
||||
|
||||
public bool SkipsLag { get; } = true;
|
||||
public bool[] Pattern { get; }
|
||||
public int Loop { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the next value and increments index.
|
||||
/// </summary>
|
||||
|
@ -70,11 +71,6 @@
|
|||
|
||||
public class AutoPatternFloat
|
||||
{
|
||||
public readonly bool SkipsLag = true;
|
||||
public readonly float[] Pattern;
|
||||
public readonly int Loop = 0;
|
||||
private int _index;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AutoPatternFloat"/> class.
|
||||
/// Defaults to 0.
|
||||
|
@ -85,11 +81,12 @@
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AutoPatternFloat"/> class.
|
||||
/// Simple on/off pattern, using the given values as on/off.
|
||||
/// </summary>
|
||||
public AutoPatternFloat(float valueOn, int on, float valueOff, int off, bool skip_lag = true, int offset = 0, int loop = 0)
|
||||
public AutoPatternFloat(float valueOn, int on, float valueOff, int off, bool skipLag = true, int offset = 0, int loop = 0)
|
||||
{
|
||||
SkipsLag = skip_lag;
|
||||
SkipsLag = skipLag;
|
||||
_index = offset;
|
||||
Loop = loop;
|
||||
Pattern = new float[on + off];
|
||||
|
@ -104,14 +101,20 @@
|
|||
}
|
||||
}
|
||||
|
||||
public AutoPatternFloat(float[] pattern, bool skip_lag = true, int offset = 0, int loop = 0)
|
||||
public AutoPatternFloat(float[] pattern, bool skipLag = true, int offset = 0, int loop = 0)
|
||||
{
|
||||
SkipsLag = skip_lag;
|
||||
SkipsLag = skipLag;
|
||||
Pattern = pattern;
|
||||
_index = offset;
|
||||
Loop = loop;
|
||||
}
|
||||
|
||||
private int _index;
|
||||
|
||||
public bool SkipsLag { get; } = true;
|
||||
public float[] Pattern { get; }
|
||||
public int Loop { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the next value and increments index.
|
||||
/// </summary>
|
||||
|
|
|
@ -13,8 +13,8 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
public ControllerDefinition Definition { get; set; }
|
||||
|
||||
protected WorkingDictionary<string, bool> Buttons = new WorkingDictionary<string, bool>();
|
||||
protected WorkingDictionary<string, float> Floats = new WorkingDictionary<string, float>();
|
||||
protected WorkingDictionary<string, bool> Buttons { get; private set; } = new WorkingDictionary<string, bool>();
|
||||
protected WorkingDictionary<string, float> Floats { get; private set; } = new WorkingDictionary<string, float>();
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
|
@ -43,14 +43,6 @@ namespace BizHawk.Client.Common
|
|||
return Buttons;
|
||||
}
|
||||
|
||||
public void LatchFrom(IController source)
|
||||
{
|
||||
foreach (var button in source.Definition.BoolButtons)
|
||||
{
|
||||
Buttons[button] = source.IsPressed(button);
|
||||
}
|
||||
}
|
||||
|
||||
public void AcceptNewFloats(IEnumerable<Tuple<string, float>> newValues)
|
||||
{
|
||||
foreach (var sv in newValues)
|
||||
|
|
|
@ -58,7 +58,7 @@ namespace BizHawk.Client.Common
|
|||
public bool IsPressed(string button)
|
||||
{
|
||||
var source = Source.IsPressed(button);
|
||||
source ^= stickySet.Contains(button);
|
||||
source ^= _stickySet.Contains(button);
|
||||
return source;
|
||||
}
|
||||
|
||||
|
@ -81,15 +81,13 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public IController Source { get; set; }
|
||||
|
||||
public bool Locked { get; set; } // Pretty much a hack,
|
||||
|
||||
private List<string> _justPressed = new List<string>();
|
||||
|
||||
protected readonly HashSet<string> stickySet = new HashSet<string>();
|
||||
private readonly HashSet<string> _stickySet = new HashSet<string>();
|
||||
|
||||
// if SetFloat() is called (typically virtual pads), then that float will entirely override the Source input
|
||||
// otherwise, the source is passed thru.
|
||||
protected readonly WorkingDictionary<string, float?> _floatSet = new WorkingDictionary<string, float?>();
|
||||
private readonly WorkingDictionary<string, float?> _floatSet = new WorkingDictionary<string, float?>();
|
||||
|
||||
public void SetFloat(string name, float? value)
|
||||
{
|
||||
|
@ -112,30 +110,30 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
if (isSticky)
|
||||
{
|
||||
stickySet.Add(button);
|
||||
_stickySet.Add(button);
|
||||
}
|
||||
else
|
||||
{
|
||||
stickySet.Remove(button);
|
||||
_stickySet.Remove(button);
|
||||
}
|
||||
}
|
||||
|
||||
public void Unset(string button)
|
||||
{
|
||||
stickySet.Remove(button);
|
||||
_stickySet.Remove(button);
|
||||
_floatSet.Remove(button);
|
||||
}
|
||||
|
||||
public bool IsSticky(string button)
|
||||
{
|
||||
return stickySet.Contains(button);
|
||||
return _stickySet.Contains(button);
|
||||
}
|
||||
|
||||
public HashSet<string> CurrentStickies => stickySet;
|
||||
public HashSet<string> CurrentStickies => _stickySet;
|
||||
|
||||
public void ClearStickies()
|
||||
{
|
||||
stickySet.Clear();
|
||||
_stickySet.Clear();
|
||||
_floatSet.Clear();
|
||||
}
|
||||
|
||||
|
@ -143,13 +141,13 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
foreach (var button in buttons.Where(button => !_justPressed.Contains(button)))
|
||||
{
|
||||
if (stickySet.Contains(button))
|
||||
if (_stickySet.Contains(button))
|
||||
{
|
||||
stickySet.Remove(button);
|
||||
_stickySet.Remove(button);
|
||||
}
|
||||
else
|
||||
{
|
||||
stickySet.Add(button);
|
||||
_stickySet.Add(button);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -207,13 +205,13 @@ namespace BizHawk.Client.Common
|
|||
|
||||
// TODO: Change the AutoHold adapter to be one of these, with an 'Off' value of 0?
|
||||
// Probably would have slightly lower performance, but it seems weird to have such a similar class that is only used once.
|
||||
private int On;
|
||||
private int Off;
|
||||
private int _on;
|
||||
private int _off;
|
||||
|
||||
public void SetOnOffPatternFromConfig()
|
||||
{
|
||||
On = Global.Config.AutofireOn < 1 ? 0 : Global.Config.AutofireOn;
|
||||
Off = Global.Config.AutofireOff < 1 ? 0 : Global.Config.AutofireOff;
|
||||
_on = Global.Config.AutofireOn < 1 ? 0 : Global.Config.AutofireOn;
|
||||
_off = Global.Config.AutofireOff < 1 ? 0 : Global.Config.AutofireOff;
|
||||
}
|
||||
|
||||
private readonly WorkingDictionary<string, AutoPatternBool> _boolPatterns = new WorkingDictionary<string, AutoPatternBool>();
|
||||
|
@ -221,21 +219,19 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public AutoFireStickyXorAdapter()
|
||||
{
|
||||
On = 1;
|
||||
Off = 1;
|
||||
_on = 1;
|
||||
_off = 1;
|
||||
}
|
||||
|
||||
public IController Source { get; set; }
|
||||
|
||||
public bool Locked { get; set; } // Pretty much a hack,
|
||||
|
||||
public void SetFloat(string name, float? value, AutoPatternFloat pattern = null)
|
||||
{
|
||||
if (value.HasValue)
|
||||
{
|
||||
if (pattern == null)
|
||||
{
|
||||
pattern = new AutoPatternFloat(value.Value, On, 0, Off);
|
||||
pattern = new AutoPatternFloat(value.Value, _on, 0, _off);
|
||||
}
|
||||
|
||||
_floatPatterns[name] = pattern;
|
||||
|
@ -246,18 +242,13 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
}
|
||||
|
||||
public void ClearStickyFloats()
|
||||
{
|
||||
_floatPatterns.Clear();
|
||||
}
|
||||
|
||||
public void SetSticky(string button, bool isSticky, AutoPatternBool pattern = null)
|
||||
{
|
||||
if (isSticky)
|
||||
{
|
||||
if (pattern == null)
|
||||
{
|
||||
pattern = new AutoPatternBool(On, Off);
|
||||
pattern = new AutoPatternBool(_on, _off);
|
||||
}
|
||||
|
||||
_boolPatterns[button] = pattern;
|
||||
|
@ -268,12 +259,6 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
}
|
||||
|
||||
public void Unset(string button)
|
||||
{
|
||||
_boolPatterns.Remove(button);
|
||||
_floatPatterns.Remove(button);
|
||||
}
|
||||
|
||||
public bool IsSticky(string button)
|
||||
{
|
||||
return _boolPatterns.ContainsKey(button) || _floatPatterns.ContainsKey(button);
|
||||
|
|
|
@ -28,14 +28,14 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
if (!Source.IsPressed(button))
|
||||
{
|
||||
Unpresses.Remove(button);
|
||||
_unpresses.Remove(button);
|
||||
}
|
||||
|
||||
prefix = button.GetPrecedingString("Down");
|
||||
string other = prefix + "Up";
|
||||
if (Source.IsPressed(other))
|
||||
{
|
||||
if (Unpresses.Contains(button))
|
||||
if (_unpresses.Contains(button))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -45,11 +45,11 @@ namespace BizHawk.Client.Common
|
|||
return false;
|
||||
}
|
||||
|
||||
Unpresses.Add(other);
|
||||
_unpresses.Add(other);
|
||||
}
|
||||
else
|
||||
{
|
||||
Unpresses.Remove(button);
|
||||
_unpresses.Remove(button);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,14 +57,14 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
if (!Source.IsPressed(button))
|
||||
{
|
||||
Unpresses.Remove(button);
|
||||
_unpresses.Remove(button);
|
||||
}
|
||||
|
||||
prefix = button.GetPrecedingString("Up");
|
||||
string other = prefix + "Down";
|
||||
if (Source.IsPressed(other))
|
||||
{
|
||||
if (Unpresses.Contains(button))
|
||||
if (_unpresses.Contains(button))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -74,11 +74,11 @@ namespace BizHawk.Client.Common
|
|||
return false;
|
||||
}
|
||||
|
||||
Unpresses.Add(other);
|
||||
_unpresses.Add(other);
|
||||
}
|
||||
else
|
||||
{
|
||||
Unpresses.Remove(button);
|
||||
_unpresses.Remove(button);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,14 +86,14 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
if (!Source.IsPressed(button))
|
||||
{
|
||||
Unpresses.Remove(button);
|
||||
_unpresses.Remove(button);
|
||||
}
|
||||
|
||||
prefix = button.GetPrecedingString("Right");
|
||||
string other = prefix + "Left";
|
||||
if (Source.IsPressed(other))
|
||||
{
|
||||
if (Unpresses.Contains(button))
|
||||
if (_unpresses.Contains(button))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -103,11 +103,11 @@ namespace BizHawk.Client.Common
|
|||
return false;
|
||||
}
|
||||
|
||||
Unpresses.Add(other);
|
||||
_unpresses.Add(other);
|
||||
}
|
||||
else
|
||||
{
|
||||
Unpresses.Remove(button);
|
||||
_unpresses.Remove(button);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -115,14 +115,14 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
if (!Source.IsPressed(button))
|
||||
{
|
||||
Unpresses.Remove(button);
|
||||
_unpresses.Remove(button);
|
||||
}
|
||||
|
||||
prefix = button.GetPrecedingString("Left");
|
||||
string other = prefix + "Right";
|
||||
if (Source.IsPressed(other))
|
||||
{
|
||||
if (Unpresses.Contains(button))
|
||||
if (_unpresses.Contains(button))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -132,11 +132,11 @@ namespace BizHawk.Client.Common
|
|||
return false;
|
||||
}
|
||||
|
||||
Unpresses.Add(other);
|
||||
_unpresses.Add(other);
|
||||
}
|
||||
else
|
||||
{
|
||||
Unpresses.Remove(button);
|
||||
_unpresses.Remove(button);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -149,7 +149,7 @@ namespace BizHawk.Client.Common
|
|||
return Source.GetFloat(name);
|
||||
}
|
||||
|
||||
private readonly HashSet<string> Unpresses = new HashSet<string>();
|
||||
private readonly HashSet<string> _unpresses = new HashSet<string>();
|
||||
|
||||
public IController Source { get; set; }
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue