Improvements to input and input configuration in the GUI. (#849)

* Improvements to input and input configuration in the GUI

* Requested changes

* nits

* more nits
This commit is contained in:
Xpl0itR 2020-05-03 03:00:53 +01:00 committed by GitHub
parent 5f3558fd51
commit 538fba826b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
50 changed files with 5883 additions and 2511 deletions

View file

@ -7,16 +7,16 @@ namespace Ryujinx.HLE.HOS.Services.Hid
public class Hid
{
private readonly Switch _device;
private long _hidMemoryAddress;
private readonly long _hidMemoryAddress;
internal ref HidSharedMemory SharedMemory => ref _device.Memory.GetStructRef<HidSharedMemory>(_hidMemoryAddress);
internal const int SharedMemEntryCount = 17;
public DebugPadDevice DebugPad;
public TouchDevice Touchscreen;
public MouseDevice Mouse;
public TouchDevice Touchscreen;
public MouseDevice Mouse;
public KeyboardDevice Keyboard;
public NpadDevices Npads;
public NpadDevices Npads;
static Hid()
{
@ -48,7 +48,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid
public Hid(in Switch device, long sharedHidMemoryAddress)
{
_device = device;
_device = device;
_hidMemoryAddress = sharedHidMemoryAddress;
device.Memory.FillWithZeros(sharedHidMemoryAddress, Horizon.HidSize);
@ -56,26 +56,26 @@ namespace Ryujinx.HLE.HOS.Services.Hid
public void InitDevices()
{
DebugPad = new DebugPadDevice(_device, true);
DebugPad = new DebugPadDevice(_device, true);
Touchscreen = new TouchDevice(_device, true);
Mouse = new MouseDevice(_device, false);
Keyboard = new KeyboardDevice(_device, false);
Npads = new NpadDevices(_device, true);
Mouse = new MouseDevice(_device, false);
Keyboard = new KeyboardDevice(_device, false);
Npads = new NpadDevices(_device, true);
}
public ControllerKeys UpdateStickButtons(JoystickPosition leftStick, JoystickPosition rightStick)
{
ControllerKeys result = 0;
result |= (leftStick.Dx < 0) ? ControllerKeys.LStickLeft : result;
result |= (leftStick.Dx < 0) ? ControllerKeys.LStickLeft : result;
result |= (leftStick.Dx > 0) ? ControllerKeys.LStickRight : result;
result |= (leftStick.Dy < 0) ? ControllerKeys.LStickDown : result;
result |= (leftStick.Dy > 0) ? ControllerKeys.LStickUp : result;
result |= (leftStick.Dy < 0) ? ControllerKeys.LStickDown : result;
result |= (leftStick.Dy > 0) ? ControllerKeys.LStickUp : result;
result |= (rightStick.Dx < 0) ? ControllerKeys.RStickLeft : result;
result |= (rightStick.Dx < 0) ? ControllerKeys.RStickLeft : result;
result |= (rightStick.Dx > 0) ? ControllerKeys.RStickRight : result;
result |= (rightStick.Dy < 0) ? ControllerKeys.RStickDown : result;
result |= (rightStick.Dy > 0) ? ControllerKeys.RStickUp : result;
result |= (rightStick.Dy < 0) ? ControllerKeys.RStickDown : result;
result |= (rightStick.Dy > 0) ? ControllerKeys.RStickUp : result;
return result;
}

View file

@ -1,6 +1,6 @@
using System;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.Common.Logging;
using Ryujinx.HLE.HOS.Kernel.Threading;
namespace Ryujinx.HLE.HOS.Services.Hid
{
@ -9,14 +9,14 @@ namespace Ryujinx.HLE.HOS.Services.Hid
internal NpadJoyHoldType JoyHold = NpadJoyHoldType.Vertical;
internal bool SixAxisActive = false; // TODO: link to hidserver when implemented
enum FilterState
private enum FilterState
{
Unconfigured = 0,
Configured = 1,
Accepted = 2
Configured = 1,
Accepted = 2
}
struct NpadConfig
private struct NpadConfig
{
public ControllerType ConfiguredType;
public FilterState State;
@ -33,7 +33,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid
public ControllerType SupportedStyleSets
{
get { return _supportedStyleSets; }
get => _supportedStyleSets;
set
{
if (_supportedStyleSets != value) // Deal with spamming
@ -46,9 +46,9 @@ namespace Ryujinx.HLE.HOS.Services.Hid
public PlayerIndex PrimaryController { get; set; } = PlayerIndex.Unknown;
KEvent[] _styleSetUpdateEvents;
private KEvent[] _styleSetUpdateEvents;
static readonly Array3<BatteryCharge> _fullBattery;
private static readonly Array3<BatteryCharge> _fullBattery;
public NpadDevices(Switch device, bool active = true) : base(device, active)
{
@ -68,7 +68,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid
{
for (int i = 0; i < configs.Length; ++i)
{
PlayerIndex player = configs[i].Player;
PlayerIndex player = configs[i].Player;
ControllerType controllerType = configs[i].Type;
if (player > PlayerIndex.Handheld)
@ -87,7 +87,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid
MatchControllers();
}
void MatchControllers()
private void MatchControllers()
{
PrimaryController = PlayerIndex.Unknown;
@ -141,7 +141,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid
return ref _styleSetUpdateEvents[(int)player];
}
void InitController(PlayerIndex player, ControllerType type)
private void InitController(PlayerIndex player, ControllerType type)
{
if (type == ControllerType.Handheld)
{
@ -155,13 +155,13 @@ namespace Ryujinx.HLE.HOS.Services.Hid
// TODO: Allow customizing colors at config
NpadStateHeader defaultHeader = new NpadStateHeader
{
IsHalf = false,
SingleColorBody = NpadColor.BodyGray,
IsHalf = false,
SingleColorBody = NpadColor.BodyGray,
SingleColorButtons = NpadColor.ButtonGray,
LeftColorBody = NpadColor.BodyNeonBlue,
LeftColorButtons = NpadColor.ButtonGray,
RightColorBody = NpadColor.BodyNeonRed,
RightColorButtons = NpadColor.ButtonGray
LeftColorBody = NpadColor.BodyNeonBlue,
LeftColorButtons = NpadColor.ButtonGray,
RightColorBody = NpadColor.BodyNeonRed,
RightColorButtons = NpadColor.ButtonGray
};
controller.SystemProperties = NpadSystemProperties.PowerInfo0Connected |
@ -173,44 +173,44 @@ namespace Ryujinx.HLE.HOS.Services.Hid
switch (type)
{
case ControllerType.ProController:
defaultHeader.Type = ControllerType.ProController;
controller.DeviceType = DeviceType.FullKey;
defaultHeader.Type = ControllerType.ProController;
controller.DeviceType = DeviceType.FullKey;
controller.SystemProperties |= NpadSystemProperties.AbxyButtonOriented |
NpadSystemProperties.PlusButtonCapability |
NpadSystemProperties.MinusButtonCapability;
break;
case ControllerType.Handheld:
defaultHeader.Type = ControllerType.Handheld;
controller.DeviceType = DeviceType.HandheldLeft |
defaultHeader.Type = ControllerType.Handheld;
controller.DeviceType = DeviceType.HandheldLeft |
DeviceType.HandheldRight;
controller.SystemProperties |= NpadSystemProperties.AbxyButtonOriented |
NpadSystemProperties.PlusButtonCapability |
NpadSystemProperties.MinusButtonCapability;
break;
case ControllerType.JoyconPair:
defaultHeader.Type = ControllerType.JoyconPair;
controller.DeviceType = DeviceType.JoyLeft |
defaultHeader.Type = ControllerType.JoyconPair;
controller.DeviceType = DeviceType.JoyLeft |
DeviceType.JoyRight;
controller.SystemProperties |= NpadSystemProperties.AbxyButtonOriented |
NpadSystemProperties.PlusButtonCapability |
NpadSystemProperties.MinusButtonCapability;
break;
case ControllerType.JoyconLeft:
defaultHeader.Type = ControllerType.JoyconLeft;
defaultHeader.IsHalf = true;
controller.DeviceType = DeviceType.JoyLeft;
defaultHeader.Type = ControllerType.JoyconLeft;
defaultHeader.IsHalf = true;
controller.DeviceType = DeviceType.JoyLeft;
controller.SystemProperties |= NpadSystemProperties.SlSrButtonOriented |
NpadSystemProperties.MinusButtonCapability;
break;
case ControllerType.JoyconRight:
defaultHeader.Type = ControllerType.JoyconRight;
defaultHeader.IsHalf = true;
controller.DeviceType = DeviceType.JoyRight;
defaultHeader.Type = ControllerType.JoyconRight;
defaultHeader.IsHalf = true;
controller.DeviceType = DeviceType.JoyRight;
controller.SystemProperties |= NpadSystemProperties.SlSrButtonOriented |
NpadSystemProperties.PlusButtonCapability;
break;
case ControllerType.Pokeball:
defaultHeader.Type = ControllerType.Pokeball;
defaultHeader.Type = ControllerType.Pokeball;
controller.DeviceType = DeviceType.Palma;
break;
}
@ -229,16 +229,16 @@ namespace Ryujinx.HLE.HOS.Services.Hid
Logger.PrintInfo(LogClass.Hid, $"Connected ControllerType {type} to PlayerIndex {player}");
}
static NpadLayoutsIndex ControllerTypeToLayout(ControllerType controllerType)
private static NpadLayoutsIndex ControllerTypeToLayout(ControllerType controllerType)
=> controllerType switch
{
ControllerType.ProController => NpadLayoutsIndex.ProController,
ControllerType.Handheld => NpadLayoutsIndex.Handheld,
ControllerType.JoyconPair => NpadLayoutsIndex.JoyDual,
ControllerType.JoyconLeft => NpadLayoutsIndex.JoyLeft,
ControllerType.JoyconRight => NpadLayoutsIndex.JoyRight,
ControllerType.Pokeball => NpadLayoutsIndex.Pokeball,
_ => NpadLayoutsIndex.SystemExternal
ControllerType.Handheld => NpadLayoutsIndex.Handheld,
ControllerType.JoyconPair => NpadLayoutsIndex.JoyDual,
ControllerType.JoyconLeft => NpadLayoutsIndex.JoyLeft,
ControllerType.JoyconRight => NpadLayoutsIndex.JoyRight,
ControllerType.Pokeball => NpadLayoutsIndex.Pokeball,
_ => NpadLayoutsIndex.SystemExternal
};
public void SetGamepadsInput(params GamepadInput[] states)
@ -251,8 +251,8 @@ namespace Ryujinx.HLE.HOS.Services.Hid
}
}
void SetGamepadState(PlayerIndex player, ControllerKeys buttons,
JoystickPosition leftJoystick, JoystickPosition rightJoystick)
private void SetGamepadState(PlayerIndex player, ControllerKeys buttons,
JoystickPosition leftJoystick, JoystickPosition rightJoystick)
{
if (player == PlayerIndex.Auto)
{
@ -269,9 +269,9 @@ namespace Ryujinx.HLE.HOS.Services.Hid
return;
}
ref ShMemNpad currentNpad = ref _device.Hid.SharedMemory.Npads[(int)player];
ref ShMemNpad currentNpad = ref _device.Hid.SharedMemory.Npads[(int)player];
ref NpadLayout currentLayout = ref currentNpad.Layouts[(int)ControllerTypeToLayout(currentNpad.Header.Type)];
ref NpadState currentEntry = ref currentLayout.Entries[(int)currentLayout.Header.LatestEntry];
ref NpadState currentEntry = ref currentLayout.Entries[(int)currentLayout.Header.LatestEntry];
currentEntry.Buttons = buttons;
currentEntry.LStickX = leftJoystick.Dx;
@ -284,7 +284,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid
mainLayout.Entries[(int)mainLayout.Header.LatestEntry] = currentEntry;
}
void UpdateAllEntries()
private void UpdateAllEntries()
{
ref Array10<ShMemNpad> controllers = ref _device.Hid.SharedMemory.Npads;
for (int i = 0; i < controllers.Length; ++i)
@ -296,9 +296,9 @@ namespace Ryujinx.HLE.HOS.Services.Hid
int currentIndex = UpdateEntriesHeader(ref currentLayout.Header, out int previousIndex);
ref NpadState currentEntry = ref currentLayout.Entries[currentIndex];
NpadState previousEntry = currentLayout.Entries[previousIndex];
NpadState previousEntry = currentLayout.Entries[previousIndex];
currentEntry.SampleTimestamp = previousEntry.SampleTimestamp + 1;
currentEntry.SampleTimestamp = previousEntry.SampleTimestamp + 1;
currentEntry.SampleTimestamp2 = previousEntry.SampleTimestamp2 + 1;
if (controllers[i].Header.Type == ControllerType.None)

View file

@ -2,7 +2,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid
{
public struct ControllerConfig
{
public PlayerIndex Player;
public PlayerIndex Player;
public ControllerType Type;
}
}

View file

@ -2,8 +2,8 @@ namespace Ryujinx.HLE.HOS.Services.Hid
{
public struct GamepadInput
{
public PlayerIndex PlayerId;
public ControllerKeys Buttons;
public PlayerIndex PlayerId;
public ControllerKeys Buttons;
public JoystickPosition LStick;
public JoystickPosition RStick;
}

View file

@ -5,41 +5,41 @@ namespace Ryujinx.HLE.HOS.Services.Hid
[Flags]
public enum ControllerKeys : long
{
A = 1 << 0,
B = 1 << 1,
X = 1 << 2,
Y = 1 << 3,
LStick = 1 << 4,
RStick = 1 << 5,
L = 1 << 6,
R = 1 << 7,
Zl = 1 << 8,
Zr = 1 << 9,
Plus = 1 << 10,
Minus = 1 << 11,
DpadLeft = 1 << 12,
DpadUp = 1 << 13,
DpadRight = 1 << 14,
DpadDown = 1 << 15,
LStickLeft = 1 << 16,
LStickUp = 1 << 17,
A = 1 << 0,
B = 1 << 1,
X = 1 << 2,
Y = 1 << 3,
LStick = 1 << 4,
RStick = 1 << 5,
L = 1 << 6,
R = 1 << 7,
Zl = 1 << 8,
Zr = 1 << 9,
Plus = 1 << 10,
Minus = 1 << 11,
DpadLeft = 1 << 12,
DpadUp = 1 << 13,
DpadRight = 1 << 14,
DpadDown = 1 << 15,
LStickLeft = 1 << 16,
LStickUp = 1 << 17,
LStickRight = 1 << 18,
LStickDown = 1 << 19,
RStickLeft = 1 << 20,
RStickUp = 1 << 21,
LStickDown = 1 << 19,
RStickLeft = 1 << 20,
RStickUp = 1 << 21,
RStickRight = 1 << 22,
RStickDown = 1 << 23,
SlLeft = 1 << 24,
SrLeft = 1 << 25,
SlRight = 1 << 26,
SrRight = 1 << 27,
RStickDown = 1 << 23,
SlLeft = 1 << 24,
SrLeft = 1 << 25,
SlRight = 1 << 26,
SrRight = 1 << 27,
// Generic Catch-all
Up = DpadUp | LStickUp | RStickUp,
Down = DpadDown | LStickDown | RStickDown,
Left = DpadLeft | LStickLeft | RStickLeft,
Up = DpadUp | LStickUp | RStickUp,
Down = DpadDown | LStickDown | RStickDown,
Left = DpadLeft | LStickLeft | RStickLeft,
Right = DpadRight | LStickRight | RStickRight,
Sl = SlLeft | SlRight,
Sr = SrLeft | SrRight
Sl = SlLeft | SlRight,
Sr = SrLeft | SrRight
}
}

View file

@ -6,14 +6,14 @@ namespace Ryujinx.HLE.HOS.Services.Hid
public enum ControllerType : int
{
None,
ProController = 1 << 0,
Handheld = 1 << 1,
JoyconPair = 1 << 2,
JoyconLeft = 1 << 3,
JoyconRight = 1 << 4,
Invalid = 1 << 5,
Pokeball = 1 << 6,
ProController = 1 << 0,
Handheld = 1 << 1,
JoyconPair = 1 << 2,
JoyconLeft = 1 << 3,
JoyconRight = 1 << 4,
Invalid = 1 << 5,
Pokeball = 1 << 6,
SystemExternal = 1 << 29,
System = 1 << 30
System = 1 << 30
}
}

View file

@ -2,12 +2,12 @@ namespace Ryujinx.HLE.HOS.Services.Hid
{
enum NpadLayoutsIndex : int
{
ProController = 0,
Handheld = 1,
JoyDual = 2,
JoyLeft = 3,
JoyRight = 4,
Pokeball = 5,
ProController = 0,
Handheld = 1,
JoyDual = 2,
JoyLeft = 3,
JoyRight = 4,
Pokeball = 5,
SystemExternal = 6
}
}

View file

@ -14,6 +14,6 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.UserManager
public DeviceState State = DeviceState.Unavailable;
public PlayerIndex Handle;
public NpadIdType NpadIdType;
public NpadIdType NpadIdType;
}
}