Move axis types to own files

This commit is contained in:
YoshiRulz 2020-06-26 09:00:33 +10:00
parent a0c8f722d2
commit 3d8ed7483f
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
37 changed files with 164 additions and 202 deletions

View File

@ -28,7 +28,7 @@ namespace BizHawk.Client.Common
private readonly WorkingDictionary<string, List<string>> _bindings = new WorkingDictionary<string, List<string>>();
private readonly WorkingDictionary<string, bool> _buttons = new WorkingDictionary<string, bool>();
private readonly WorkingDictionary<string, int> _axes = new WorkingDictionary<string, int>();
private readonly Dictionary<string, ControllerDefinition.AxisSpec> _axisRanges = new WorkingDictionary<string, ControllerDefinition.AxisSpec>();
private readonly Dictionary<string, AxisSpec> _axisRanges = new WorkingDictionary<string, AxisSpec>();
private readonly Dictionary<string, AnalogBind> _axisBindings = new Dictionary<string, AnalogBind>();
/// <summary>don't do this</summary>

View File

@ -90,7 +90,7 @@ namespace BizHawk.Client.Common
"Right", "Left", "Down", "Up", "Start", "Select",
"B", "A", "X", "Y", "L", "R", "LidOpen", "LidClose", "Touch"
}
}.AddXYPair("Touch{0}", ControllerDefinition.AxisPairOrientation.RightAndUp, 0.RangeTo(255), 128, 0.RangeTo(191), 96) //TODO verify direction against hardware
}.AddXYPair("Touch{0}", AxisPairOrientation.RightAndUp, 0.RangeTo(255), 128, 0.RangeTo(191), 96) //TODO verify direction against hardware
};
controller["LidOpen"] = false;

View File

@ -7,8 +7,6 @@ using BizHawk.Emulation.Common;
using BizHawk.Client.Common;
using BizHawk.Common;
using static BizHawk.Emulation.Common.ControllerDefinition;
namespace BizHawk.Client.EmuHawk
{
public partial class VirtualPadAnalogStick : UserControl, IVirtualPadControl

View File

@ -6,8 +6,6 @@ using BizHawk.Common;
using BizHawk.Common.NumberExtensions;
using BizHawk.Emulation.Common;
using static BizHawk.Emulation.Common.ControllerDefinition;
namespace BizHawk.Client.EmuHawk
{
public sealed class AnalogStickPanel : Panel

View File

@ -5,8 +5,6 @@ using BizHawk.Common;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Nintendo.N64;
using static BizHawk.Emulation.Common.ControllerDefinition;
namespace BizHawk.Client.EmuHawk
{
[Schema("N64")]

View File

@ -5,8 +5,6 @@ using BizHawk.Common;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Sony.PSX;
using static BizHawk.Emulation.Common.ControllerDefinition;
namespace BizHawk.Client.EmuHawk
{
[Schema("PSX")]

View File

@ -7,8 +7,6 @@ using System.Windows.Forms;
using BizHawk.Client.EmuHawk.Properties;
using BizHawk.Emulation.Common;
using static BizHawk.Emulation.Common.ControllerDefinition;
namespace BizHawk.Client.EmuHawk
{
public abstract class PadSchemaControl

View File

@ -8,8 +8,6 @@ using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.PCEngine;
using BizHawk.Emulation.Cores.Waterbox;
using static BizHawk.Emulation.Common.ControllerDefinition;
namespace BizHawk.Client.EmuHawk
{
[Schema("PCECD")]

View File

@ -7,8 +7,6 @@ using BizHawk.Common;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Waterbox;
using static BizHawk.Emulation.Common.ControllerDefinition;
namespace BizHawk.Client.EmuHawk
{
[Schema("PCFX")]

View File

@ -6,8 +6,6 @@ using System.Windows.Forms;
using BizHawk.Common;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Waterbox;
using static BizHawk.Emulation.Common.ControllerDefinition;
namespace BizHawk.Client.EmuHawk
{
[Schema("SAT")]

View File

@ -0,0 +1,9 @@
namespace BizHawk.Emulation.Common
{
public interface AxisConstraint
{
public string Class { get; }
public string PairedAxis { get; }
}
}

View File

@ -0,0 +1,56 @@
using System.Collections;
using System.Collections.Generic;
namespace BizHawk.Emulation.Common
{
public sealed class AxisDict : IReadOnlyDictionary<string, AxisSpec>
{
private readonly IList<string> _keys = new List<string>();
private readonly IDictionary<string, AxisSpec> _specs = new Dictionary<string, AxisSpec>();
public int Count => _keys.Count;
public bool HasContraints { get; private set; }
public IEnumerable<string> Keys => _keys;
public IEnumerable<AxisSpec> Values => _specs.Values;
public string this[int index] => _keys[index];
public AxisSpec this[string index]
{
get => _specs[index];
set => _specs[index] = value;
}
public void Add(string key, AxisSpec value)
{
_keys.Add(key);
_specs.Add(key, value);
if (value.Constraint != null) HasContraints = true;
}
public void Add(KeyValuePair<string, AxisSpec> item) => Add(item.Key, item.Value);
public void Clear()
{
_keys.Clear();
_specs.Clear();
HasContraints = false;
}
public bool ContainsKey(string key) => _keys.Contains(key);
public IEnumerator<KeyValuePair<string, AxisSpec>> GetEnumerator() => _specs.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
public int IndexOf(string key) => _keys.IndexOf(key);
public AxisSpec SpecAtIndex(int index) => this[_keys[index]];
public bool TryGetValue(string key, out AxisSpec value) => _specs.TryGetValue(key, out value);
}
}

View File

@ -0,0 +1,12 @@
namespace BizHawk.Emulation.Common
{
/// <summary>represents the direction of <c>(+, +)</c></summary>
/// <remarks>docs of individual controllers are being collected in comments of https://github.com/TASVideos/BizHawk/issues/1200</remarks>
public enum AxisPairOrientation : byte
{
RightAndUp = 0,
RightAndDown = 1,
LeftAndUp = 2,
LeftAndDown = 3
}
}

View File

@ -0,0 +1,42 @@
using System;
using BizHawk.Common;
namespace BizHawk.Emulation.Common
{
public readonly struct AxisSpec
{
/// <summary>
/// Gets the axis constraints that apply artificial constraints to float values
/// For instance, a N64 controller's analog range is actually larger than the amount allowed by the plastic that artificially constrains it to lower values
/// Axis constraints provide a way to technically allow the full range but have a user option to constrain down to typical values that a real control would have
/// </summary>
public readonly AxisConstraint Constraint;
public Range<float> FloatRange => ((float) Min).RangeTo(Max);
public readonly bool IsReversed;
public int Max => Range.EndInclusive;
/// <value>maximum decimal digits analog input can occupy with no-args ToString</value>
/// <remarks>does not include the extra char needed for a minus sign</remarks>
public int MaxDigits => Math.Max(Math.Abs(Min).ToString().Length, Math.Abs(Max).ToString().Length);
public readonly int Mid;
public int Min => Range.Start;
public string PairedAxis => Constraint?.PairedAxis;
public readonly Range<int> Range;
public AxisSpec(Range<int> range, int mid, bool isReversed = false, AxisConstraint constraint = null)
{
Constraint = constraint;
IsReversed = isReversed;
Mid = mid;
Range = range;
}
}
}

View File

@ -0,0 +1,31 @@
using System;
namespace BizHawk.Emulation.Common
{
public sealed class CircularAxisConstraint : AxisConstraint
{
public string Class { get; }
private readonly float Magnitude;
public string PairedAxis { get; }
public CircularAxisConstraint(string @class, string pairedAxis, float magnitude)
{
Class = @class;
Magnitude = magnitude;
PairedAxis = pairedAxis;
}
public (int X, int Y) ApplyTo(int rawX, int rawY)
{
var xVal = (double) rawX;
var yVal = (double) rawY;
var length = Math.Sqrt(xVal * xVal + yVal * yVal);
var ratio = Magnitude / length;
return ratio < 1.0
? ((int) (xVal * ratio), (int) (yVal * ratio))
: ((int) xVal, (int) yVal);
}
}
}

View File

@ -0,0 +1,11 @@
namespace BizHawk.Emulation.Common
{
public sealed class NoOpAxisConstraint : AxisConstraint
{
public string Class { get; } = null;
public string PairedAxis { get; }
public NoOpAxisConstraint(string pairedAxis) => PairedAxis = pairedAxis;
}
}

View File

@ -1,11 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using BizHawk.Common;
namespace BizHawk.Emulation.Common
{
/// <summary>
@ -37,95 +33,8 @@ namespace BizHawk.Emulation.Common
/// </summary>
public List<string> BoolButtons { get; set; } = new List<string>();
public sealed class AxisDict : IReadOnlyDictionary<string, AxisSpec>
{
private readonly IList<string> _keys = new List<string>();
private readonly IDictionary<string, AxisSpec> _specs = new Dictionary<string, AxisSpec>();
public int Count => _keys.Count;
public bool HasContraints { get; private set; }
public IEnumerable<string> Keys => _keys;
public IEnumerable<AxisSpec> Values => _specs.Values;
public string this[int index] => _keys[index];
public AxisSpec this[string index]
{
get => _specs[index];
set => _specs[index] = value;
}
public void Add(string key, AxisSpec value)
{
_keys.Add(key);
_specs.Add(key, value);
if (value.Constraint != null) HasContraints = true;
}
public void Add(KeyValuePair<string, AxisSpec> item) => Add(item.Key, item.Value);
public void Clear()
{
_keys.Clear();
_specs.Clear();
HasContraints = false;
}
public bool ContainsKey(string key) => _keys.Contains(key);
public IEnumerator<KeyValuePair<string, AxisSpec>> GetEnumerator() => _specs.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
public int IndexOf(string key) => _keys.IndexOf(key);
public AxisSpec SpecAtIndex(int index) => this[_keys[index]];
public bool TryGetValue(string key, out AxisSpec value) => _specs.TryGetValue(key, out value);
}
public readonly AxisDict Axes = new AxisDict();
public readonly struct AxisSpec
{
/// <summary>
/// Gets the axis constraints that apply artificial constraints to float values
/// For instance, a N64 controller's analog range is actually larger than the amount allowed by the plastic that artificially constrains it to lower values
/// Axis constraints provide a way to technically allow the full range but have a user option to constrain down to typical values that a real control would have
/// </summary>
public readonly AxisConstraint Constraint;
public Range<float> FloatRange => ((float) Min).RangeTo(Max);
public readonly bool IsReversed;
public int Max => Range.EndInclusive;
/// <value>maximum decimal digits analog input can occupy with no-args ToString</value>
/// <remarks>does not include the extra char needed for a minus sign</remarks>
public int MaxDigits => Math.Max(Math.Abs(Min).ToString().Length, Math.Abs(Max).ToString().Length);
public readonly int Mid;
public int Min => Range.Start;
public string PairedAxis => Constraint?.PairedAxis;
public readonly Range<int> Range;
public AxisSpec(Range<int> range, int mid, bool isReversed = false, AxisConstraint constraint = null)
{
Constraint = constraint;
IsReversed = isReversed;
Mid = mid;
Range = range;
}
}
/// <summary>
/// Gets the category labels. These labels provide a means of categorizing controls in various controller display and config screens
/// </summary>
@ -149,59 +58,6 @@ namespace BizHawk.Emulation.Common
}
}
/// <summary>represents the direction of <c>(+, +)</c></summary>
/// <remarks>docs of individual controllers are being collected in comments of https://github.com/TASVideos/BizHawk/issues/1200</remarks>
public enum AxisPairOrientation : byte
{
RightAndUp = 0,
RightAndDown = 1,
LeftAndUp = 2,
LeftAndDown = 3
}
public interface AxisConstraint
{
public string Class { get; }
public string PairedAxis { get; }
}
public sealed class NoOpAxisConstraint : AxisConstraint
{
public string Class { get; } = null;
public string PairedAxis { get; }
public NoOpAxisConstraint(string pairedAxis) => PairedAxis = pairedAxis;
}
public sealed class CircularAxisConstraint : AxisConstraint
{
public string Class { get; }
private readonly float Magnitude;
public string PairedAxis { get; }
public CircularAxisConstraint(string @class, string pairedAxis, float magnitude)
{
Class = @class;
Magnitude = magnitude;
PairedAxis = pairedAxis;
}
public (int X, int Y) ApplyTo(int rawX, int rawY)
{
var xVal = (double) rawX;
var yVal = (double) rawY;
var length = Math.Sqrt(xVal * xVal + yVal * yVal);
var ratio = Magnitude / length;
return ratio < 1.0
? ((int) (xVal * ratio), (int) (yVal * ratio))
: ((int) xVal, (int) yVal);
}
}
/// <summary>
/// Gets a list of controls put in a logical order such as by controller number,
/// This is a default implementation that should work most of the time

View File

@ -9,8 +9,6 @@ using BizHawk.Common;
using BizHawk.Common.PathExtensions;
using BizHawk.Common.StringExtensions;
using static BizHawk.Emulation.Common.ControllerDefinition;
namespace BizHawk.Emulation.Common
{
public static class EmulatorExtensions

View File

@ -4,8 +4,6 @@ using System.Linq;
using BizHawk.Common;
using BizHawk.Emulation.Common;
using static BizHawk.Emulation.Common.ControllerDefinition;
namespace BizHawk.Emulation.Cores.Atari.A7800Hawk
{
/// <summary>

View File

@ -4,8 +4,6 @@ using System;
using BizHawk.Common;
using static BizHawk.Emulation.Common.ControllerDefinition;
namespace BizHawk.Emulation.Cores.Consoles.Belogic
{
[Core("uzem", "David Etherton", true, true, "", "", false)]

View File

@ -6,8 +6,6 @@ using System.Linq;
using BizHawk.Common;
using BizHawk.Emulation.Common;
using static BizHawk.Emulation.Common.ControllerDefinition;
namespace BizHawk.Emulation.Cores.ColecoVision
{
/// <summary>

View File

@ -4,8 +4,6 @@ using System.Linq;
using BizHawk.Common;
using BizHawk.Emulation.Common;
using static BizHawk.Emulation.Common.ControllerDefinition;
namespace BizHawk.Emulation.Cores.Consoles.Vectrex
{
/// <summary>

View File

@ -6,8 +6,6 @@ using System.Linq;
using BizHawk.Common;
using BizHawk.Emulation.Common;
using static BizHawk.Emulation.Common.ControllerDefinition;
namespace BizHawk.Emulation.Cores.Intellivision
{
/// <summary>

View File

@ -5,8 +5,6 @@ using System.Linq;
using BizHawk.Common;
using BizHawk.Emulation.Common;
using static BizHawk.Emulation.Common.ControllerDefinition;
namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
{
/// <summary>

View File

@ -1,8 +1,6 @@
using BizHawk.Common;
using BizHawk.Emulation.Common;
using static BizHawk.Emulation.Common.ControllerDefinition;
namespace BizHawk.Emulation.Cores.Nintendo.N64
{
public partial class N64 : ISettable<N64Settings, N64SyncSettings>

View File

@ -5,8 +5,6 @@ using System.IO;
using BizHawk.Common;
using BizHawk.Emulation.Common;
using static BizHawk.Emulation.Common.ControllerDefinition;
namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS
{
[Core("MelonDS", "Arisotura", false, false, null, null, true)]

View File

@ -5,8 +5,6 @@ using BizHawk.Emulation.Common;
using BizHawk.Common;
using Newtonsoft.Json;
using static BizHawk.Emulation.Common.ControllerDefinition;
namespace BizHawk.Emulation.Cores.Nintendo.NES
{
/*

View File

@ -6,8 +6,6 @@ using BizHawk.Common;
using BizHawk.Emulation.Common;
using BizHawk.Common.NumberExtensions;
using static BizHawk.Emulation.Common.ControllerDefinition;
namespace BizHawk.Emulation.Cores.Nintendo.SNES
{
public class LibsnesControllerDeck

View File

@ -9,8 +9,6 @@ using System.Linq;
using BizHawk.Emulation.Cores.Nintendo.SNES;
using static BizHawk.Emulation.Common.ControllerDefinition;
namespace BizHawk.Emulation.Cores.Nintendo.SNES9X
{
[Core(CoreNames.Snes9X, "", true, true,

View File

@ -1,8 +1,6 @@
using BizHawk.Common;
using BizHawk.Emulation.Common;
using static BizHawk.Emulation.Common.ControllerDefinition;
namespace BizHawk.Emulation.Cores.Sega.MasterSystem
{
public partial class SMS : IEmulator

View File

@ -4,8 +4,6 @@ using System.Linq;
using BizHawk.Common;
using BizHawk.Emulation.Common;
using static BizHawk.Emulation.Common.ControllerDefinition;
namespace BizHawk.Emulation.Cores.Sega.MasterSystem
{
public partial class SMS

View File

@ -4,8 +4,6 @@ using System.Collections.Generic;
using BizHawk.Common;
using BizHawk.Emulation.Common;
using static BizHawk.Emulation.Common.ControllerDefinition;
namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
{
public class GPGXControlConverter

View File

@ -24,8 +24,6 @@ using BizHawk.Emulation.Common;
using BizHawk.Common;
using BizHawk.Emulation.DiscSystem;
using static BizHawk.Emulation.Common.ControllerDefinition;
#pragma warning disable 649 //adelikat: Disable dumb warnings until this file is complete
namespace BizHawk.Emulation.Cores.Sony.PSX

View File

@ -11,8 +11,6 @@ using System.Runtime.InteropServices;
using BizHawk.Common;
using BizHawk.Emulation.Common;
using static BizHawk.Emulation.Common.ControllerDefinition;
namespace BizHawk.Emulation.Cores.Libretro
{
[Core("Libretro", "zeromus", isPorted: false, isReleased: false)]

View File

@ -7,7 +7,6 @@ using BizHawk.Common;
using BizHawk.Emulation.Common;
using NymaTypes;
using static BizHawk.Emulation.Common.ControllerDefinition;
using static BizHawk.Emulation.Cores.Waterbox.LibNymaCore;
namespace BizHawk.Emulation.Cores.Waterbox

View File

@ -4,8 +4,6 @@ using BizHawk.Client.Common;
using BizHawk.Common;
using BizHawk.Emulation.Common;
using static BizHawk.Emulation.Common.ControllerDefinition;
namespace BizHawk.Tests.Client.Common.Display
{
[TestClass]

View File

@ -3,8 +3,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
using BizHawk.Client.Common;
using BizHawk.Emulation.Common;
using static BizHawk.Emulation.Common.ControllerDefinition;
namespace BizHawk.Common.Tests.Client.Common.Movie
{
[TestClass]