mirror of
https://git.naxdy.org/Mirror/Ryujinx.git
synced 2025-01-02 22:13:04 +00:00
Basic XInput support.
This commit is contained in:
parent
7b7dbdcc6a
commit
a5e90ec2d1
2 changed files with 68 additions and 0 deletions
|
@ -7,6 +7,7 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="OpenTK.NETCore" Version="1.1.2749.6433" />
|
<PackageReference Include="OpenTK.NETCore" Version="1.1.2749.6433" />
|
||||||
|
<PackageReference Include="SharpDX.XInput" Version="4.1.0" />
|
||||||
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.4.0" />
|
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.4.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
using OpenTK.Input;
|
using OpenTK.Input;
|
||||||
|
using SharpDX.XInput;
|
||||||
using Ryujinx.Core;
|
using Ryujinx.Core;
|
||||||
using Ryujinx.Core.Input;
|
using Ryujinx.Core.Input;
|
||||||
using Ryujinx.Graphics.Gal;
|
using Ryujinx.Graphics.Gal;
|
||||||
|
@ -20,6 +21,19 @@ namespace Ryujinx
|
||||||
|
|
||||||
private IGalRenderer Renderer;
|
private IGalRenderer Renderer;
|
||||||
|
|
||||||
|
// Initialize XInput
|
||||||
|
private Controller[] InputControllers = new[]
|
||||||
|
{
|
||||||
|
new Controller(UserIndex.One),
|
||||||
|
new Controller(UserIndex.Two),
|
||||||
|
new Controller(UserIndex.Three),
|
||||||
|
new Controller(UserIndex.Four)
|
||||||
|
};
|
||||||
|
|
||||||
|
private Controller InputController = null;
|
||||||
|
|
||||||
|
private bool XInputEnabled = false;
|
||||||
|
|
||||||
public GLScreen(Switch Ns, IGalRenderer Renderer)
|
public GLScreen(Switch Ns, IGalRenderer Renderer)
|
||||||
: base(1280, 720,
|
: base(1280, 720,
|
||||||
new GraphicsMode(), "Ryujinx", 0,
|
new GraphicsMode(), "Ryujinx", 0,
|
||||||
|
@ -29,6 +43,26 @@ namespace Ryujinx
|
||||||
this.Ns = Ns;
|
this.Ns = Ns;
|
||||||
this.Renderer = Renderer;
|
this.Renderer = Renderer;
|
||||||
|
|
||||||
|
// Get 1st controller detected/available
|
||||||
|
foreach (Controller SelectController in InputControllers)
|
||||||
|
{
|
||||||
|
if (SelectController.IsConnected)
|
||||||
|
{
|
||||||
|
InputController = SelectController;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (InputController != null)
|
||||||
|
{
|
||||||
|
XInputEnabled = true;
|
||||||
|
Console.WriteLine("XInput controller detected!");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("XInput controller not detected!");
|
||||||
|
}
|
||||||
|
|
||||||
Location = new Point(
|
Location = new Point(
|
||||||
(DisplayDevice.Default.Width / 2) - (Width / 2),
|
(DisplayDevice.Default.Width / 2) - (Width / 2),
|
||||||
(DisplayDevice.Default.Height / 2) - (Height / 2));
|
(DisplayDevice.Default.Height / 2) - (Height / 2));
|
||||||
|
@ -54,6 +88,39 @@ namespace Ryujinx
|
||||||
int RightJoystickDX = 0;
|
int RightJoystickDX = 0;
|
||||||
int RightJoystickDY = 0;
|
int RightJoystickDY = 0;
|
||||||
|
|
||||||
|
//XInput
|
||||||
|
if (XInputEnabled)
|
||||||
|
{
|
||||||
|
State CurrentState = InputController.GetState();
|
||||||
|
switch (CurrentState.Gamepad.Buttons)
|
||||||
|
{
|
||||||
|
case GamepadButtonFlags.A:
|
||||||
|
CurrentButton |= HidControllerButtons.KEY_A;
|
||||||
|
break;
|
||||||
|
case GamepadButtonFlags.B:
|
||||||
|
CurrentButton |= HidControllerButtons.KEY_B;
|
||||||
|
break;
|
||||||
|
case GamepadButtonFlags.X:
|
||||||
|
CurrentButton |= HidControllerButtons.KEY_X;
|
||||||
|
break;
|
||||||
|
case GamepadButtonFlags.Y:
|
||||||
|
CurrentButton |= HidControllerButtons.KEY_Y;
|
||||||
|
break;
|
||||||
|
case GamepadButtonFlags.DPadUp:
|
||||||
|
CurrentButton |= HidControllerButtons.KEY_DUP;
|
||||||
|
break;
|
||||||
|
case GamepadButtonFlags.DPadDown:
|
||||||
|
CurrentButton |= HidControllerButtons.KEY_DDOWN;
|
||||||
|
break;
|
||||||
|
case GamepadButtonFlags.DPadLeft:
|
||||||
|
CurrentButton |= HidControllerButtons.KEY_DLEFT;
|
||||||
|
break;
|
||||||
|
case GamepadButtonFlags.DPadRight:
|
||||||
|
CurrentButton |= HidControllerButtons.KEY_DRIGHT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//RightJoystick
|
//RightJoystick
|
||||||
if (Keyboard[(Key)Config.FakeJoyCon.Left.StickUp]) LeftJoystickDY = short.MaxValue;
|
if (Keyboard[(Key)Config.FakeJoyCon.Left.StickUp]) LeftJoystickDY = short.MaxValue;
|
||||||
if (Keyboard[(Key)Config.FakeJoyCon.Left.StickDown]) LeftJoystickDY = -short.MaxValue;
|
if (Keyboard[(Key)Config.FakeJoyCon.Left.StickDown]) LeftJoystickDY = -short.MaxValue;
|
||||||
|
|
Loading…
Reference in a new issue