Replace Tuple with ValueTuple in input system
This commit is contained in:
parent
d0cc17c208
commit
573aa13c64
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using BizHawk.Common;
|
||||
using BizHawk.Emulation.Common;
|
||||
|
@ -43,16 +42,16 @@ namespace BizHawk.Client.Common
|
|||
return Buttons;
|
||||
}
|
||||
|
||||
public void AcceptNewAxes(Tuple<string, float> newValue)
|
||||
public void AcceptNewAxes((string AxisID, float Value) newValue)
|
||||
{
|
||||
Axes[newValue.Item1] = newValue.Item2;
|
||||
Axes[newValue.AxisID] = newValue.Value;
|
||||
}
|
||||
|
||||
public void AcceptNewAxes(IEnumerable<Tuple<string, float>> newValues)
|
||||
public void AcceptNewAxes(IEnumerable<(string AxisID, float Value)> newValues)
|
||||
{
|
||||
foreach (var sv in newValues)
|
||||
foreach (var (axisID, value) in newValues)
|
||||
{
|
||||
Axes[sv.Item1] = sv.Item2;
|
||||
Axes[axisID] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -122,8 +122,8 @@ namespace BizHawk.Client.Common
|
|||
|
||||
controller.AcceptNewAxes(new[]
|
||||
{
|
||||
new Tuple<string, float>("TouchX", touchX),
|
||||
new Tuple<string, float>("TouchY", touchY)
|
||||
("TouchX", (float) touchX),
|
||||
("TouchY", (float) touchY)
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.IO;
|
||||
using BizHawk.Emulation.Cores.Sony.PSX;
|
||||
|
||||
namespace BizHawk.Client.Common
|
||||
|
@ -213,10 +212,10 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
controllers["P1 L3"] = (controllerState & 0x2) != 0;
|
||||
controllers["P1 R3"] = (controllerState & 0x4) != 0;
|
||||
var leftX = new Tuple<string, float>("P1 LStick X", br.ReadByte());
|
||||
var leftY = new Tuple<string, float>("P1 LStick Y", br.ReadByte());
|
||||
var rightX = new Tuple<string, float>("P1 RStick X", br.ReadByte());
|
||||
var rightY = new Tuple<string, float>("P1 RStick Y", br.ReadByte());
|
||||
var leftX = ("P1 LStick X", (float) br.ReadByte());
|
||||
var leftY = ("P1 LStick Y", (float) br.ReadByte());
|
||||
var rightX = ("P1 RStick X", (float) br.ReadByte());
|
||||
var rightY = ("P1 RStick Y", (float) br.ReadByte());
|
||||
|
||||
controllers.AcceptNewAxes(new[] { leftX, leftY, rightX, rightY });
|
||||
}
|
||||
|
@ -236,10 +235,10 @@ namespace BizHawk.Client.Common
|
|||
|
||||
if (info.Player2Type == OctoshockDll.ePeripheralType.DualShock)
|
||||
{
|
||||
var leftX = new Tuple<string, float>("P2 LStick X", br.ReadByte());
|
||||
var leftY = new Tuple<string, float>("P2 LStick Y", br.ReadByte());
|
||||
var rightX = new Tuple<string, float>("P2 RStick X", br.ReadByte());
|
||||
var rightY = new Tuple<string, float>("P2 RStick Y", br.ReadByte());
|
||||
var leftX = ("P2 LStick X", (float) br.ReadByte());
|
||||
var leftY = ("P2 LStick Y", (float) br.ReadByte());
|
||||
var rightX = ("P2 RStick X", (float) br.ReadByte());
|
||||
var rightY = ("P2 RStick Y", (float) br.ReadByte());
|
||||
|
||||
controllers.AcceptNewAxes(new[] { leftX, leftY, rightX, rightY });
|
||||
}
|
||||
|
@ -267,7 +266,7 @@ namespace BizHawk.Client.Common
|
|||
controllers["Open"] = false;
|
||||
}
|
||||
|
||||
Tuple<string, float> discSelect = new Tuple<string, float>("Disc Select", cdNumber);
|
||||
var discSelect = ("Disc Select", (float) cdNumber);
|
||||
controllers.AcceptNewAxes(new[] { discSelect });
|
||||
|
||||
if ((controlState & 0xFC) != 0)
|
||||
|
@ -351,10 +350,10 @@ namespace BizHawk.Client.Common
|
|||
string rightXRaw = player1Str.Substring(24, 4);
|
||||
string rightYRaw = player1Str.Substring(28, 4);
|
||||
|
||||
Tuple<string, float> leftX = new Tuple<string, float>("P1 LStick X", float.Parse(leftXRaw));
|
||||
Tuple<string, float> leftY = new Tuple<string, float>("P1 LStick Y", float.Parse(leftYRaw));
|
||||
Tuple<string, float> rightX = new Tuple<string, float>("P1 RStick X", float.Parse(rightXRaw));
|
||||
Tuple<string, float> rightY = new Tuple<string, float>("P1 RStick Y", float.Parse(rightYRaw));
|
||||
var leftX = ("P1 LStick X", float.Parse(leftXRaw));
|
||||
var leftY = ("P1 LStick Y", float.Parse(leftYRaw));
|
||||
var rightX = ("P1 RStick X", float.Parse(rightXRaw));
|
||||
var rightY = ("P1 RStick Y", float.Parse(rightYRaw));
|
||||
|
||||
controllers.AcceptNewAxes(new[] { leftX, leftY, rightX, rightY });
|
||||
}
|
||||
|
@ -386,10 +385,10 @@ namespace BizHawk.Client.Common
|
|||
string rightXRaw = player2Str.Substring(24, 4);
|
||||
string rightYRaw = player2Str.Substring(28, 4);
|
||||
|
||||
Tuple<string, float> leftX = new Tuple<string, float>("P2 LStick X", float.Parse(leftXRaw));
|
||||
Tuple<string, float> leftY = new Tuple<string, float>("P2 LStick Y", float.Parse(leftYRaw));
|
||||
Tuple<string, float> rightX = new Tuple<string, float>("P2 RStick X", float.Parse(rightXRaw));
|
||||
Tuple<string, float> rightY = new Tuple<string, float>("P2 RStick Y", float.Parse(rightYRaw));
|
||||
var leftX = ("P2 LStick X", float.Parse(leftXRaw));
|
||||
var leftY = ("P2 LStick Y", float.Parse(leftYRaw));
|
||||
var rightX = ("P2 RStick X", float.Parse(rightXRaw));
|
||||
var rightY = ("P2 RStick Y", float.Parse(rightYRaw));
|
||||
|
||||
controllers.AcceptNewAxes(new[] { leftX, leftY, rightX, rightY });
|
||||
}
|
||||
|
@ -417,7 +416,7 @@ namespace BizHawk.Client.Common
|
|||
controllers["Open"] = false;
|
||||
}
|
||||
|
||||
Tuple<string, float> discSelect = new Tuple<string, float>("Disc Select", cdNumber);
|
||||
var discSelect = ("Disc Select", (float) cdNumber);
|
||||
controllers.AcceptNewAxes(new[] { discSelect });
|
||||
|
||||
if ((controlState & 0xFC) != 0)
|
||||
|
|
|
@ -125,12 +125,12 @@ namespace BizHawk.Client.EmuHawk
|
|||
return;
|
||||
}
|
||||
|
||||
public IEnumerable<Tuple<string, float>> GetFloats()
|
||||
public IEnumerable<(string AxisID, float Value)> GetFloats()
|
||||
{
|
||||
var pis = typeof(JoystickState).GetProperties();
|
||||
foreach (var pi in pis)
|
||||
{
|
||||
yield return new Tuple<string, float>(pi.Name, 10.0f * (float)(int)pi.GetValue(_state, null));
|
||||
yield return (pi.Name, 10.0f * (float)(int)pi.GetValue(_state, null));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -154,7 +154,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Tuple<string, float>> GetFloats()
|
||||
public IEnumerable<(string AxisID, float Value)> GetFloats()
|
||||
{
|
||||
var g = _state.Gamepad;
|
||||
|
||||
|
@ -167,12 +167,12 @@ namespace BizHawk.Client.EmuHawk
|
|||
lTrig *= 10000;
|
||||
rTrig *= 10000;
|
||||
|
||||
yield return new Tuple<string, float>("LeftThumbX", g.sThumbLX / f);
|
||||
yield return new Tuple<string, float>("LeftThumbY", g.sThumbLY / f);
|
||||
yield return new Tuple<string, float>("RightThumbX", g.sThumbRX / f);
|
||||
yield return new Tuple<string, float>("RightThumbY", g.sThumbRY / f);
|
||||
yield return new Tuple<string, float>("LeftTrigger", lTrig);
|
||||
yield return new Tuple<string, float>("RightTrigger", rTrig);
|
||||
yield return ("LeftThumbX", g.sThumbLX / f);
|
||||
yield return ("LeftThumbY", g.sThumbLY / f);
|
||||
yield return ("RightThumbX", g.sThumbRX / f);
|
||||
yield return ("RightThumbY", g.sThumbRY / f);
|
||||
yield return ("LeftTrigger", lTrig);
|
||||
yield return ("RightTrigger", rTrig);
|
||||
}
|
||||
|
||||
public int NumButtons { get; private set; }
|
||||
|
|
|
@ -338,14 +338,14 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
public List<Tuple<string, float>> GetAxisValues()
|
||||
public List<(string AxisID, float Value)> GetAxisValues()
|
||||
{
|
||||
var axisValuesCopy = new List<Tuple<string,float>>();
|
||||
var axisValuesCopy = new List<(string, float)>();
|
||||
lock (_axisValues)
|
||||
{
|
||||
foreach (var kvp in _axisValues)
|
||||
{
|
||||
axisValuesCopy.Add(new Tuple<string, float>(kvp.Key, kvp.Value));
|
||||
axisValuesCopy.Add((kvp.Key, kvp.Value));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -394,10 +394,9 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
HandleButton(pad.InputNamePrefix + but.ButtonName, but.ButtonAction(), InputFocus.Pad);
|
||||
}
|
||||
foreach (var sv in pad.GetAxes())
|
||||
foreach (var (axisID, f) in pad.GetAxes())
|
||||
{
|
||||
var n = $"{pad.InputNamePrefix}{sv.Item1} Axis";
|
||||
var f = sv.Item2;
|
||||
var n = $"{pad.InputNamePrefix}{axisID} Axis";
|
||||
if (_trackDeltas) _axisDeltas[n] += Math.Abs(f - _axisValues[n]);
|
||||
_axisValues[n] = f;
|
||||
}
|
||||
|
|
|
@ -168,36 +168,36 @@ namespace BizHawk.Client.EmuHawk
|
|||
if (!tmpJstate.Equals(jState)) Debug.WriteLine($"Joystick State:\t{tmpJstate}");
|
||||
}
|
||||
|
||||
public IEnumerable<Tuple<string, float>> GetAxes()
|
||||
public IEnumerable<(string AxisID, float Value)> GetAxes()
|
||||
{
|
||||
if (MappedGamePad)
|
||||
{
|
||||
// automapping identified - use OpenTKGamePad
|
||||
yield return new Tuple<string, float>("LeftThumbX", ConstrainFloatInput(state.ThumbSticks.Left.X));
|
||||
yield return new Tuple<string, float>("LeftThumbY", ConstrainFloatInput(state.ThumbSticks.Left.Y));
|
||||
yield return new Tuple<string, float>("RightThumbX", ConstrainFloatInput(state.ThumbSticks.Right.X));
|
||||
yield return new Tuple<string, float>("RightThumbY", ConstrainFloatInput(state.ThumbSticks.Right.Y));
|
||||
yield return new Tuple<string, float>("LeftTrigger", ConstrainFloatInput(state.Triggers.Left));
|
||||
yield return new Tuple<string, float>("RightTrigger", ConstrainFloatInput(state.Triggers.Right));
|
||||
yield return ("LeftThumbX", ConstrainFloatInput(state.ThumbSticks.Left.X));
|
||||
yield return ("LeftThumbY", ConstrainFloatInput(state.ThumbSticks.Left.Y));
|
||||
yield return ("RightThumbX", ConstrainFloatInput(state.ThumbSticks.Right.X));
|
||||
yield return ("RightThumbY", ConstrainFloatInput(state.ThumbSticks.Right.Y));
|
||||
yield return ("LeftTrigger", ConstrainFloatInput(state.Triggers.Left));
|
||||
yield return ("RightTrigger", ConstrainFloatInput(state.Triggers.Right));
|
||||
yield break;
|
||||
}
|
||||
else
|
||||
{
|
||||
// use Joystick
|
||||
yield return new Tuple<string, float>("X", ConstrainFloatInput(jState.GetAxis(0)));
|
||||
yield return new Tuple<string, float>("Y", ConstrainFloatInput(jState.GetAxis(1)));
|
||||
yield return new Tuple<string, float>("Z", ConstrainFloatInput(jState.GetAxis(2)));
|
||||
yield return new Tuple<string, float>("W", ConstrainFloatInput(jState.GetAxis(3)));
|
||||
yield return new Tuple<string, float>("V", ConstrainFloatInput(jState.GetAxis(4)));
|
||||
yield return new Tuple<string, float>("S", ConstrainFloatInput(jState.GetAxis(5)));
|
||||
yield return new Tuple<string, float>("Q", ConstrainFloatInput(jState.GetAxis(6)));
|
||||
yield return new Tuple<string, float>("P", ConstrainFloatInput(jState.GetAxis(7)));
|
||||
yield return new Tuple<string, float>("N", ConstrainFloatInput(jState.GetAxis(8)));
|
||||
yield return ("X", ConstrainFloatInput(jState.GetAxis(0)));
|
||||
yield return ("Y", ConstrainFloatInput(jState.GetAxis(1)));
|
||||
yield return ("Z", ConstrainFloatInput(jState.GetAxis(2)));
|
||||
yield return ("W", ConstrainFloatInput(jState.GetAxis(3)));
|
||||
yield return ("V", ConstrainFloatInput(jState.GetAxis(4)));
|
||||
yield return ("S", ConstrainFloatInput(jState.GetAxis(5)));
|
||||
yield return ("Q", ConstrainFloatInput(jState.GetAxis(6)));
|
||||
yield return ("P", ConstrainFloatInput(jState.GetAxis(7)));
|
||||
yield return ("N", ConstrainFloatInput(jState.GetAxis(8)));
|
||||
|
||||
for (var i = 9; i < 64; i++)
|
||||
{
|
||||
var j = i;
|
||||
yield return new Tuple<string, float>($"Axis{j.ToString()}", ConstrainFloatInput(jState.GetAxis(j)));
|
||||
yield return ($"Axis{j.ToString()}", ConstrainFloatInput(jState.GetAxis(j)));
|
||||
}
|
||||
|
||||
yield break;
|
||||
|
|
|
@ -970,7 +970,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
//also handle floats
|
||||
//we'll need to isolate the mouse coordinates so we can translate them
|
||||
Tuple<string, float> mouseX = null, mouseY = null;
|
||||
(string AxisID, float Value)? mouseX = null, mouseY = null;
|
||||
var floats = Input.Instance.GetAxisValues();
|
||||
foreach (var f in Input.Instance.GetAxisValues())
|
||||
{
|
||||
|
@ -985,11 +985,11 @@ namespace BizHawk.Client.EmuHawk
|
|||
//NOTE: these must go together, because in the case of screen rotation, X and Y are transformed together
|
||||
if(mouseX != null && mouseY != null)
|
||||
{
|
||||
var p = DisplayManager.UntransformPoint(new Point((int)mouseX.Item2, (int)mouseY.Item2));
|
||||
var p = DisplayManager.UntransformPoint(new Point((int) mouseX.Value.Value, (int) mouseY.Value.Value));
|
||||
float x = p.X / (float)_currentVideoProvider.BufferWidth;
|
||||
float y = p.Y / (float)_currentVideoProvider.BufferHeight;
|
||||
conInput.AcceptNewAxes(new Tuple<string, float>("WMouse X", (x * 20000) - 10000));
|
||||
conInput.AcceptNewAxes(new Tuple<string, float>("WMouse Y", (y * 20000) - 10000));
|
||||
conInput.AcceptNewAxes(("WMouse X", (x * 20000) - 10000));
|
||||
conInput.AcceptNewAxes(("WMouse Y", (y * 20000) - 10000));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue