blob: 3853f281967c4b846c01c5c0ab618583b11199cc (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
using Ryujinx.Common.Configuration.Hid;
using Ryujinx.Common.Memory;
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
namespace Ryujinx.Input
{
/// <summary>
/// Represent an emulated gamepad.
/// </summary>
public interface IGamepad : IDisposable
{
/// <summary>
/// Features supported by the gamepad.
/// </summary>
GamepadFeaturesFlag Features { get; }
/// <summary>
/// Unique Id of the gamepad.
/// </summary>
string Id { get; }
/// <summary>
/// The name of the gamepad.
/// </summary>
string Name { get; }
/// <summary>
/// True if the gamepad is connected.
/// </summary>
bool IsConnected { get; }
/// <summary>
/// Check if a given input button is pressed on the gamepad.
/// </summary>
/// <param name="inputId">The button id</param>
/// <returns>True if the given button is pressed on the gamepad</returns>
bool IsPressed(GamepadButtonInputId inputId);
/// <summary>
/// Get the values of a given input joystick on the gamepad.
/// </summary>
/// <param name="inputId">The stick id</param>
/// <returns>The values of the given input joystick on the gamepad</returns>
(float, float) GetStick(StickInputId inputId);
/// <summary>
/// Get the values of a given motion sensors on the gamepad.
/// </summary>
/// <param name="inputId">The motion id</param>
/// <returns> The values of the given motion sensors on the gamepad.</returns>
Vector3 GetMotionData(MotionInputId inputId);
/// <summary>
/// Configure the threshold of the triggers on the gamepad.
/// </summary>
/// <param name="triggerThreshold">The threshold value for the triggers on the gamepad</param>
void SetTriggerThreshold(float triggerThreshold);
/// <summary>
/// Set the configuration of the gamepad.
/// </summary>
/// <remarks>This expect config to be in the format expected by the driver</remarks>
/// <param name="configuration">The configuration of the gamepad</param>
void SetConfiguration(InputConfig configuration);
/// <summary>
/// Starts a rumble effect on the gamepad.
/// </summary>
/// <param name="lowFrequency">The intensity of the low frequency from 0.0f to 1.0f</param>
/// <param name="highFrequency">The intensity of the high frequency from 0.0f to 1.0f</param>
/// <param name="durationMs">The duration of the rumble effect in milliseconds.</param>
void Rumble(float lowFrequency, float highFrequency, uint durationMs);
/// <summary>
/// Get a snaphost of the state of the gamepad that is remapped with the informations from the <see cref="InputConfig"/> set via <see cref="SetConfiguration(InputConfig)"/>.
/// </summary>
/// <returns>A remapped snaphost of the state of the gamepad.</returns>
GamepadStateSnapshot GetMappedStateSnapshot();
/// <summary>
/// Get a snaphost of the state of the gamepad.
/// </summary>
/// <returns>A snaphost of the state of the gamepad.</returns>
GamepadStateSnapshot GetStateSnapshot();
/// <summary>
/// Get a snaphost of the state of a gamepad.
/// </summary>
/// <param name="gamepad">The gamepad to do a snapshot of</param>
/// <returns>A snaphost of the state of the gamepad.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static GamepadStateSnapshot GetStateSnapshot(IGamepad gamepad)
{
// NOTE: Update Array size if JoystickInputId is changed.
Array3<Array2<float>> joysticksState = default;
for (StickInputId inputId = StickInputId.Left; inputId < StickInputId.Count; inputId++)
{
(float state0, float state1) = gamepad.GetStick(inputId);
Array2<float> state = default;
state[0] = state0;
state[1] = state1;
joysticksState[(int)inputId] = state;
}
// NOTE: Update Array size if GamepadInputId is changed.
Array28<bool> buttonsState = default;
for (GamepadButtonInputId inputId = GamepadButtonInputId.A; inputId < GamepadButtonInputId.Count; inputId++)
{
buttonsState[(int)inputId] = gamepad.IsPressed(inputId);
}
return new GamepadStateSnapshot(joysticksState, buttonsState);
}
}
}
|