HID SharedMem Rework (#1003)

* Delete old HLE.Input

* Add new HLE Input.

git shows Hid.cs as modified because of the same name. It is new.

* Change HID Service

* Change Ryujinx UI to reflect new Input

* Add basic ControllerApplet

* Add DebugPad

Should fix Kirby Star Allies

* Address Ac_K's comments

* Moved all of HLE.Input to Services.Hid
* Separated all structs and enums each to a file
* Removed vars
* Made some naming changes to align with switchbrew
* Added official joycon colors

As an aside, fixed a mistake in touchscreen headers and added checks to
important SharedMem structs at init time.

* Further address Ac_K's comments

* Addressed gdkchan's and some more Ac_K's comments

* Address AcK's review comments

* Address AcK's second review comments

* Replace missed Marshal.SizeOf and address gdkchan's comments
This commit is contained in:
mageven 2020-04-03 05:40:02 +05:30 committed by GitHub
parent 5b5239ab5b
commit 2365ddfc36
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
105 changed files with 1500 additions and 1044 deletions

View file

@ -7,7 +7,7 @@ using OpenTK.Platform;
using Ryujinx.Configuration;
using Ryujinx.Graphics.OpenGL;
using Ryujinx.HLE;
using Ryujinx.HLE.Input;
using Ryujinx.HLE.HOS.Services.Hid;
using Ryujinx.Ui;
using System;
using System.Collections.Generic;
@ -382,10 +382,10 @@ namespace Ryujinx.Ui
}
HotkeyButtons currentHotkeyButtons = 0;
ControllerButtons currentButton = 0;
ControllerKeys currentButton = 0;
JoystickPosition leftJoystick;
JoystickPosition rightJoystick;
HLE.Input.Keyboard? hidKeyboard = null;
KeyboardInput? hidKeyboard = null;
int leftJoystickDx = 0;
int leftJoystickDy = 0;
@ -417,7 +417,7 @@ namespace Ryujinx.Ui
if (!hidKeyboard.HasValue)
{
hidKeyboard = new HLE.Input.Keyboard
hidKeyboard = new KeyboardInput
{
Modifier = 0,
Keys = new int[0x8]
@ -489,8 +489,8 @@ namespace Ryujinx.Ui
TouchPoint currentPoint = new TouchPoint
{
X = mX,
Y = mY,
X = (uint)mX,
Y = (uint)mY,
// Placeholder values till more data is acquired
DiameterX = 10,
@ -500,23 +500,29 @@ namespace Ryujinx.Ui
hasTouch = true;
_device.Hid.SetTouchPoints(currentPoint);
_device.Hid.Touchscreen.Update(currentPoint);
}
}
if (!hasTouch)
{
_device.Hid.SetTouchPoints();
_device.Hid.Touchscreen.Update();
}
if (ConfigurationState.Instance.Hid.EnableKeyboard && hidKeyboard.HasValue)
{
_device.Hid.WriteKeyboard(hidKeyboard.Value);
_device.Hid.Keyboard.Update(hidKeyboard.Value);
}
BaseController controller = _device.Hid.PrimaryController;
_device.Hid.DebugPad.Update();
controller.SendInput(currentButton, leftJoystick, rightJoystick);
_device.Hid.Npads.SetGamepadsInput(new GamepadInput
{
PlayerId = PlayerIndex.Auto,
Buttons = currentButton,
LStick = leftJoystick,
RStick = rightJoystick
});
// Toggle vsync
if (currentHotkeyButtons.HasFlag(HotkeyButtons.ToggleVSync) &&

View file

@ -1,32 +1,39 @@
using OpenTK.Input;
using Ryujinx.HLE.Input;
using System;
using OpenTK.Input;
using Ryujinx.HLE.HOS.Services.Hid;
using Ryujinx.UI.Input;
namespace Ryujinx.Ui
{
[Flags]
public enum HotkeyButtons
{
ToggleVSync = 1 << 0,
}
public static class KeyboardControls
{
public static ControllerButtons GetButtons(NpadKeyboard npad, KeyboardState keyboard)
public static ControllerKeys GetButtons(NpadKeyboard npad, KeyboardState keyboard)
{
ControllerButtons buttons = 0;
ControllerKeys buttons = 0;
if (keyboard[(Key)npad.LeftJoycon.StickButton]) buttons |= ControllerButtons.StickLeft;
if (keyboard[(Key)npad.LeftJoycon.DPadUp]) buttons |= ControllerButtons.DpadUp;
if (keyboard[(Key)npad.LeftJoycon.DPadDown]) buttons |= ControllerButtons.DpadDown;
if (keyboard[(Key)npad.LeftJoycon.DPadLeft]) buttons |= ControllerButtons.DpadLeft;
if (keyboard[(Key)npad.LeftJoycon.DPadRight]) buttons |= ControllerButtons.DPadRight;
if (keyboard[(Key)npad.LeftJoycon.ButtonMinus]) buttons |= ControllerButtons.Minus;
if (keyboard[(Key)npad.LeftJoycon.ButtonL]) buttons |= ControllerButtons.L;
if (keyboard[(Key)npad.LeftJoycon.ButtonZl]) buttons |= ControllerButtons.Zl;
if (keyboard[(Key)npad.LeftJoycon.StickButton]) buttons |= ControllerKeys.LStick;
if (keyboard[(Key)npad.LeftJoycon.DPadUp]) buttons |= ControllerKeys.DpadUp;
if (keyboard[(Key)npad.LeftJoycon.DPadDown]) buttons |= ControllerKeys.DpadDown;
if (keyboard[(Key)npad.LeftJoycon.DPadLeft]) buttons |= ControllerKeys.DpadLeft;
if (keyboard[(Key)npad.LeftJoycon.DPadRight]) buttons |= ControllerKeys.DpadRight;
if (keyboard[(Key)npad.LeftJoycon.ButtonMinus]) buttons |= ControllerKeys.Minus;
if (keyboard[(Key)npad.LeftJoycon.ButtonL]) buttons |= ControllerKeys.L | ControllerKeys.Sl;
if (keyboard[(Key)npad.LeftJoycon.ButtonZl]) buttons |= ControllerKeys.Zl;
if (keyboard[(Key)npad.RightJoycon.StickButton]) buttons |= ControllerButtons.StickRight;
if (keyboard[(Key)npad.RightJoycon.ButtonA]) buttons |= ControllerButtons.A;
if (keyboard[(Key)npad.RightJoycon.ButtonB]) buttons |= ControllerButtons.B;
if (keyboard[(Key)npad.RightJoycon.ButtonX]) buttons |= ControllerButtons.X;
if (keyboard[(Key)npad.RightJoycon.ButtonY]) buttons |= ControllerButtons.Y;
if (keyboard[(Key)npad.RightJoycon.ButtonPlus]) buttons |= ControllerButtons.Plus;
if (keyboard[(Key)npad.RightJoycon.ButtonR]) buttons |= ControllerButtons.R;
if (keyboard[(Key)npad.RightJoycon.ButtonZr]) buttons |= ControllerButtons.Zr;
if (keyboard[(Key)npad.RightJoycon.StickButton]) buttons |= ControllerKeys.RStick;
if (keyboard[(Key)npad.RightJoycon.ButtonA]) buttons |= ControllerKeys.A;
if (keyboard[(Key)npad.RightJoycon.ButtonB]) buttons |= ControllerKeys.B;
if (keyboard[(Key)npad.RightJoycon.ButtonX]) buttons |= ControllerKeys.X;
if (keyboard[(Key)npad.RightJoycon.ButtonY]) buttons |= ControllerKeys.Y;
if (keyboard[(Key)npad.RightJoycon.ButtonPlus]) buttons |= ControllerKeys.Plus;
if (keyboard[(Key)npad.RightJoycon.ButtonR]) buttons |= ControllerKeys.R | ControllerKeys.Sr;
if (keyboard[(Key)npad.RightJoycon.ButtonZr]) buttons |= ControllerKeys.Zr;
return buttons;
}
@ -216,9 +223,9 @@ namespace Ryujinx.Ui
new KeyMappingEntry { TargetKey = Key.NumLock, Target = 10 },
};
public static HLE.Input.Keyboard GetKeysDown(NpadKeyboard npad, KeyboardState keyboard)
public static KeyboardInput GetKeysDown(NpadKeyboard npad, KeyboardState keyboard)
{
HLE.Input.Keyboard hidKeyboard = new HLE.Input.Keyboard
KeyboardInput hidKeyboard = new KeyboardInput
{
Modifier = 0,
Keys = new int[0x8]

View file

@ -10,6 +10,7 @@ using Ryujinx.Graphics.GAL;
using Ryujinx.Graphics.OpenGL;
using Ryujinx.HLE.FileSystem;
using Ryujinx.HLE.FileSystem.Content;
using Ryujinx.HLE.HOS.Services.Hid;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@ -446,7 +447,19 @@ namespace Ryujinx.Ui
private void CreateGameWindow(HLE.Switch device)
{
device.Hid.InitializePrimaryController(ConfigurationState.Instance.Hid.ControllerType);
ControllerType type = (Ryujinx.Configuration.Hid.ControllerType)ConfigurationState.Instance.Hid.ControllerType switch {
Ryujinx.Configuration.Hid.ControllerType.ProController => ControllerType.ProController,
Ryujinx.Configuration.Hid.ControllerType.Handheld => ControllerType.Handheld,
Ryujinx.Configuration.Hid.ControllerType.NpadPair => ControllerType.JoyconPair,
Ryujinx.Configuration.Hid.ControllerType.NpadLeft => ControllerType.JoyconLeft,
Ryujinx.Configuration.Hid.ControllerType.NpadRight => ControllerType.JoyconRight,
_ => ControllerType.Handheld
};
device.Hid.Npads.AddControllers(new ControllerConfig {
Player = PlayerIndex.Player1,
Type = type
});
_gLWidget = new GLRenderer(_emulationContext);

View file

@ -1,7 +1,7 @@
using OpenTK;
using OpenTK.Input;
using Ryujinx.Common.Configuration.Hid;
using Ryujinx.HLE.Input;
using Ryujinx.HLE.HOS.Services.Hid;
using System;
using InnerNpadController = Ryujinx.Common.Configuration.Hid.NpadController;
@ -24,7 +24,7 @@ namespace Ryujinx.Ui.Input
return _inner.Enabled && Joystick.GetState(_inner.Index).IsConnected;
}
public ControllerButtons GetButtons()
public ControllerKeys GetButtons()
{
if (!IsEnabled())
{
@ -33,30 +33,30 @@ namespace Ryujinx.Ui.Input
JoystickState joystickState = Joystick.GetState(_inner.Index);
ControllerButtons buttons = 0;
ControllerKeys buttons = 0;
if (IsActivated(joystickState, _inner.LeftJoycon.DPadUp)) buttons |= ControllerButtons.DpadUp;
if (IsActivated(joystickState, _inner.LeftJoycon.DPadDown)) buttons |= ControllerButtons.DpadDown;
if (IsActivated(joystickState, _inner.LeftJoycon.DPadLeft)) buttons |= ControllerButtons.DpadLeft;
if (IsActivated(joystickState, _inner.LeftJoycon.DPadRight)) buttons |= ControllerButtons.DPadRight;
if (IsActivated(joystickState, _inner.LeftJoycon.StickButton)) buttons |= ControllerButtons.StickLeft;
if (IsActivated(joystickState, _inner.LeftJoycon.ButtonMinus)) buttons |= ControllerButtons.Minus;
if (IsActivated(joystickState, _inner.LeftJoycon.ButtonL)) buttons |= ControllerButtons.L;
if (IsActivated(joystickState, _inner.LeftJoycon.ButtonZl)) buttons |= ControllerButtons.Zl;
if (IsActivated(joystickState, _inner.LeftJoycon.DPadUp)) buttons |= ControllerKeys.DpadUp;
if (IsActivated(joystickState, _inner.LeftJoycon.DPadDown)) buttons |= ControllerKeys.DpadDown;
if (IsActivated(joystickState, _inner.LeftJoycon.DPadLeft)) buttons |= ControllerKeys.DpadLeft;
if (IsActivated(joystickState, _inner.LeftJoycon.DPadRight)) buttons |= ControllerKeys.DpadRight;
if (IsActivated(joystickState, _inner.LeftJoycon.StickButton)) buttons |= ControllerKeys.LStick;
if (IsActivated(joystickState, _inner.LeftJoycon.ButtonMinus)) buttons |= ControllerKeys.Minus;
if (IsActivated(joystickState, _inner.LeftJoycon.ButtonL)) buttons |= ControllerKeys.L | ControllerKeys.Sl;
if (IsActivated(joystickState, _inner.LeftJoycon.ButtonZl)) buttons |= ControllerKeys.Zl;
if (IsActivated(joystickState, _inner.RightJoycon.ButtonA)) buttons |= ControllerButtons.A;
if (IsActivated(joystickState, _inner.RightJoycon.ButtonB)) buttons |= ControllerButtons.B;
if (IsActivated(joystickState, _inner.RightJoycon.ButtonX)) buttons |= ControllerButtons.X;
if (IsActivated(joystickState, _inner.RightJoycon.ButtonY)) buttons |= ControllerButtons.Y;
if (IsActivated(joystickState, _inner.RightJoycon.StickButton)) buttons |= ControllerButtons.StickRight;
if (IsActivated(joystickState, _inner.RightJoycon.ButtonPlus)) buttons |= ControllerButtons.Plus;
if (IsActivated(joystickState, _inner.RightJoycon.ButtonR)) buttons |= ControllerButtons.R;
if (IsActivated(joystickState, _inner.RightJoycon.ButtonZr)) buttons |= ControllerButtons.Zr;
if (IsActivated(joystickState, _inner.RightJoycon.ButtonA)) buttons |= ControllerKeys.A;
if (IsActivated(joystickState, _inner.RightJoycon.ButtonB)) buttons |= ControllerKeys.B;
if (IsActivated(joystickState, _inner.RightJoycon.ButtonX)) buttons |= ControllerKeys.X;
if (IsActivated(joystickState, _inner.RightJoycon.ButtonY)) buttons |= ControllerKeys.Y;
if (IsActivated(joystickState, _inner.RightJoycon.StickButton)) buttons |= ControllerKeys.RStick;
if (IsActivated(joystickState, _inner.RightJoycon.ButtonPlus)) buttons |= ControllerKeys.Plus;
if (IsActivated(joystickState, _inner.RightJoycon.ButtonR)) buttons |= ControllerKeys.R | ControllerKeys.Sr;
if (IsActivated(joystickState, _inner.RightJoycon.ButtonZr)) buttons |= ControllerKeys.Zr;
return buttons;
}
private bool IsActivated(JoystickState joystickState,ControllerInputId controllerInputId)
private bool IsActivated(JoystickState joystickState, ControllerInputId controllerInputId)
{
if (controllerInputId <= ControllerInputId.Button20)
{