using Ryujinx.Common.Configuration.Hid;
using Ryujinx.Common.Memory;
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
namespace Ryujinx.Input
{
///
/// Represent an emulated gamepad.
///
public interface IGamepad : IDisposable
{
///
/// Features supported by the gamepad.
///
GamepadFeaturesFlag Features { get; }
///
/// Unique Id of the gamepad.
///
string Id { get; }
///
/// The name of the gamepad.
///
string Name { get; }
///
/// True if the gamepad is connected.
///
bool IsConnected { get; }
///
/// Check if a given input button is pressed on the gamepad.
///
/// The button id
/// True if the given button is pressed on the gamepad
bool IsPressed(GamepadButtonInputId inputId);
///
/// Get the values of a given input joystick on the gamepad.
///
/// The stick id
/// The values of the given input joystick on the gamepad
(float, float) GetStick(StickInputId inputId);
///
/// Get the values of a given motion sensors on the gamepad.
///
/// The motion id
/// The values of the given motion sensors on the gamepad.
Vector3 GetMotionData(MotionInputId inputId);
///
/// Configure the threshold of the triggers on the gamepad.
///
/// The threshold value for the triggers on the gamepad
void SetTriggerThreshold(float triggerThreshold);
///
/// Set the configuration of the gamepad.
///
/// This expect config to be in the format expected by the driver
/// The configuration of the gamepad
void SetConfiguration(InputConfig configuration);
///
/// Starts a rumble effect on the gamepad.
///
/// The intensity of the low frequency from 0.0f to 1.0f
/// The intensity of the high frequency from 0.0f to 1.0f
/// The duration of the rumble effect in milliseconds.
void Rumble(float lowFrequency, float highFrequency, uint durationMs);
///
/// Get a snaphost of the state of the gamepad that is remapped with the informations from the set via .
///
/// A remapped snaphost of the state of the gamepad.
GamepadStateSnapshot GetMappedStateSnapshot();
///
/// Get a snaphost of the state of the gamepad.
///
/// A snaphost of the state of the gamepad.
GamepadStateSnapshot GetStateSnapshot();
///
/// Get a snaphost of the state of a gamepad.
///
/// The gamepad to do a snapshot of
/// A snaphost of the state of the gamepad.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static GamepadStateSnapshot GetStateSnapshot(IGamepad gamepad)
{
// NOTE: Update Array size if JoystickInputId is changed.
Array3> joysticksState = default;
for (StickInputId inputId = StickInputId.Left; inputId < StickInputId.Count; inputId++)
{
(float state0, float state1) = gamepad.GetStick(inputId);
Array2 state = default;
state[0] = state0;
state[1] = state1;
joysticksState[(int)inputId] = state;
}
// NOTE: Update Array size if GamepadInputId is changed.
Array28 buttonsState = default;
for (GamepadButtonInputId inputId = GamepadButtonInputId.A; inputId < GamepadButtonInputId.Count; inputId++)
{
buttonsState[(int)inputId] = gamepad.IsPressed(inputId);
}
return new GamepadStateSnapshot(joysticksState, buttonsState);
}
}
}