delete unused KeyTurbo.cs and misc small cleanups to InputAdapters

This commit is contained in:
adelikat 2020-02-22 12:44:03 -06:00
parent f9c6234262
commit c3811721c2
7 changed files with 129 additions and 166 deletions

View File

@ -177,7 +177,7 @@ namespace BizHawk.Client.Common
} }
} }
public void Overrides(OverrideAdaptor controller) public void Overrides(OverrideAdapter controller)
{ {
foreach (var button in controller.Overrides) foreach (var button in controller.Overrides)
{ {

View File

@ -43,7 +43,7 @@ namespace BizHawk.Client.Common
// the "output" port for the controller chain. // the "output" port for the controller chain.
public static readonly CopyControllerAdapter ControllerOutput = new CopyControllerAdapter(); public static readonly CopyControllerAdapter ControllerOutput = new CopyControllerAdapter();
public static readonly UD_LR_ControllerAdapter UD_LR_ControllerAdapter = new UD_LR_ControllerAdapter(); public static readonly UdlrControllerAdapter UD_LR_ControllerAdapter = new UdlrControllerAdapter();
public static readonly AutoFireStickyXorAdapter AutofireStickyXORAdapter = new AutoFireStickyXorAdapter(); public static readonly AutoFireStickyXorAdapter AutofireStickyXORAdapter = new AutoFireStickyXorAdapter();
@ -55,7 +55,7 @@ namespace BizHawk.Client.Common
/// <summary> /// <summary>
/// Used to AND to another controller, used for <see cref="JoypadApi.Set(System.Collections.Generic.Dictionary{string,bool},System.Nullable{int})">JoypadApi.Set</see> /// Used to AND to another controller, used for <see cref="JoypadApi.Set(System.Collections.Generic.Dictionary{string,bool},System.Nullable{int})">JoypadApi.Set</see>
/// </summary> /// </summary>
public static readonly OverrideAdaptor ButtonOverrideAdaptor = new OverrideAdaptor(); public static readonly OverrideAdapter ButtonOverrideAdaptor = new OverrideAdapter();
/// <summary> /// <summary>
/// fire off one-frame logical button clicks here. useful for things like ti-83 virtual pad and reset buttons /// fire off one-frame logical button clicks here. useful for things like ti-83 virtual pad and reset buttons

View File

@ -1,40 +0,0 @@
namespace BizHawk.Client.Common
{
public class TurboKey
{
private int _upTime, _downTime, _timer;
public bool Value { get; set; }
public void Reset(int downTime, int upTime)
{
Value = false;
_timer = 0;
_upTime = upTime;
_downTime = downTime;
}
public void Tick(bool down)
{
if (!down)
{
Reset(_downTime, _upTime);
return;
}
_timer++;
Value = true;
if (_timer > _downTime)
{
Value = false;
}
if (_timer > _upTime + _downTime)
{
_timer = 0;
Value = true;
}
}
}
}

View File

@ -4,7 +4,6 @@
{ {
public AutoPatternBool() public AutoPatternBool()
{ {
Pattern = new[] { true };
} }
/// <summary> /// <summary>
@ -34,7 +33,7 @@
private int _index; private int _index;
public bool SkipsLag { get; } = true; public bool SkipsLag { get; } = true;
public bool[] Pattern { get; } public bool[] Pattern { get; } = { true };
public int Loop { get; } public int Loop { get; }
/// <summary> /// <summary>
@ -77,7 +76,6 @@
/// </summary> /// </summary>
public AutoPatternFloat() public AutoPatternFloat()
{ {
Pattern = new[] { 0f };
} }
/// <summary> /// <summary>
@ -112,7 +110,7 @@
private int _index; private int _index;
public bool SkipsLag { get; } = true; public bool SkipsLag { get; } = true;
public float[] Pattern { get; } public float[] Pattern { get; } = { 0f };
public int Loop { get; } public int Loop { get; }
/// <summary> /// <summary>

View File

@ -1,118 +1,118 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common namespace BizHawk.Client.Common
{ {
/// <summary> /// <summary>
/// Used to pass into an Override method to manage the logic overriding input /// Used to pass into an Override method to manage the logic overriding input
/// This only works with bool buttons! /// This only works with bool buttons!
/// </summary> /// </summary>
public class OverrideAdaptor : IController public class OverrideAdapter : IController
{ {
public ControllerDefinition Definition { get; private set; } public ControllerDefinition Definition { get; private set; }
private readonly Dictionary<string, bool> _overrides = new Dictionary<string, bool>(); private readonly Dictionary<string, bool> _overrides = new Dictionary<string, bool>();
private readonly Dictionary<string, float> _floatOverrides = new Dictionary<string, float>(); private readonly Dictionary<string, float> _floatOverrides = new Dictionary<string, float>();
private readonly List<string> _inverses = new List<string>(); private readonly List<string> _inverses = new List<string>();
/// <exception cref="InvalidOperationException"><paramref name="button"/> not overridden</exception> /// <exception cref="InvalidOperationException"><paramref name="button"/> not overridden</exception>
public bool IsPressed(string button) public bool IsPressed(string button)
{ {
if (_overrides.ContainsKey(button)) if (_overrides.ContainsKey(button))
{ {
return _overrides[button]; return _overrides[button];
} }
throw new InvalidOperationException(); throw new InvalidOperationException();
} }
public float GetFloat(string name) public float GetFloat(string name)
{ {
if (_floatOverrides.ContainsKey(name)) if (_floatOverrides.ContainsKey(name))
{ {
return _floatOverrides[name]; return _floatOverrides[name];
} }
return 0.0F; return 0.0F;
} }
public IEnumerable<string> Overrides public IEnumerable<string> Overrides
{ {
get get
{ {
foreach (var kvp in _overrides) foreach (var kvp in _overrides)
{ {
yield return kvp.Key; yield return kvp.Key;
} }
} }
} }
public IEnumerable<string> FloatOverrides public IEnumerable<string> FloatOverrides
{ {
get get
{ {
foreach (var kvp in _floatOverrides) foreach (var kvp in _floatOverrides)
{ {
yield return kvp.Key; yield return kvp.Key;
} }
} }
} }
public IEnumerable<string> InversedButtons public IEnumerable<string> InversedButtons
{ {
get get
{ {
foreach (var name in _inverses) foreach (var name in _inverses)
{ {
yield return name; yield return name;
} }
} }
} }
public void SetFloat(string name, float value) public void SetFloat(string name, float value)
{ {
if (_floatOverrides.ContainsKey(name)) if (_floatOverrides.ContainsKey(name))
{ {
_floatOverrides[name] = value; _floatOverrides[name] = value;
} }
else else
{ {
_floatOverrides.Add(name, value); _floatOverrides.Add(name, value);
} }
} }
public void SetButton(string button, bool value) public void SetButton(string button, bool value)
{ {
if (_overrides.ContainsKey(button)) if (_overrides.ContainsKey(button))
{ {
_overrides[button] = value; _overrides[button] = value;
} }
else else
{ {
_overrides.Add(button, value); _overrides.Add(button, value);
} }
_inverses.Remove(button); _inverses.Remove(button);
} }
public void UnSet(string button) public void UnSet(string button)
{ {
_overrides.Remove(button); _overrides.Remove(button);
_inverses.Remove(button); _inverses.Remove(button);
} }
public void SetInverse(string button) public void SetInverse(string button)
{ {
_inverses.Add(button); _inverses.Add(button);
} }
public void FrameTick() public void FrameTick()
{ {
_overrides.Clear(); _overrides.Clear();
_floatOverrides.Clear(); _floatOverrides.Clear();
_inverses.Clear(); _inverses.Clear();
} }
} }
} }

View File

@ -9,7 +9,7 @@ namespace BizHawk.Client.Common
/// Filters input for things called Up and Down while considering the client's AllowUD_LR option. /// Filters input for things called Up and Down while considering the client's AllowUD_LR option.
/// This is a bit gross but it is unclear how to do it more nicely /// This is a bit gross but it is unclear how to do it more nicely
/// </summary> /// </summary>
public class UD_LR_ControllerAdapter : IController public class UdlrControllerAdapter : IController
{ {
public ControllerDefinition Definition => Source.Definition; public ControllerDefinition Definition => Source.Definition;

View File

@ -338,6 +338,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Multitap/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Multitap/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Multitrack/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Multitrack/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Mupen/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Mupen/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=mutexing/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=muxed/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=muxed/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Nametable/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Nametable/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Nametables/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Nametables/@EntryIndexedValue">True</s:Boolean>
@ -356,6 +357,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Overscan/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Overscan/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=palettized/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=palettized/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Palletize/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Palletize/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=passthru/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=PCFX/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=PCFX/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=PCSX/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=PCSX/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=performant/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=performant/@EntryIndexedValue">True</s:Boolean>
@ -428,6 +430,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Turboing/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Turboing/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=tvalue/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=tvalue/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=UDLR/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=UDLR/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unclick/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=underrun/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=underrun/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Underruns/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Underruns/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=undriven/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=undriven/@EntryIndexedValue">True</s:Boolean>
@ -439,6 +442,8 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=unpaused/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=unpaused/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unpausing/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Unpausing/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=unpress/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=unpress/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=unpresses/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=unpressing/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unregister/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Unregister/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=unseekable/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=unseekable/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unthrottle/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Unthrottle/@EntryIndexedValue">True</s:Boolean>