Fix SDL2 instance enumeration and mapping

This commit is contained in:
Thomas Altenburger 2016-02-25 20:19:27 +01:00
parent 647ab3026a
commit 6998f94a39
2 changed files with 11 additions and 5 deletions

View file

@ -331,6 +331,10 @@ namespace OpenTK.Platform.SDL2
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_JoystickGetGUID", ExactSpelling = true)]
public static extern JoystickGuid JoystickGetGUID(IntPtr joystick);
[SuppressUnmanagedCodeSecurity]
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_JoystickInstanceID", ExactSpelling = true)]
public static extern int JoystickInstanceID(IntPtr joystick);
[SuppressUnmanagedCodeSecurity]
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_JoystickName", ExactSpelling = true)]
static extern IntPtr JoystickNameInternal(IntPtr joystick);

View file

@ -42,6 +42,7 @@ namespace OpenTK.Platform.SDL2
{
public IntPtr Handle { get; set; }
public Guid Guid { get; set; }
public int InstanceId { get; set; }
public int PacketNumber { get; set; }
public int HatCount { get; set; }
public int BallCount { get; set; }
@ -51,7 +52,6 @@ namespace OpenTK.Platform.SDL2
}
// For IJoystickDriver2 implementation
int last_joystick_instance = 0;
readonly List<JoystickDevice> joysticks = new List<JoystickDevice>(4);
readonly Dictionary<int, int> sdl_instanceid_to_joysticks = new Dictionary<int, int>();
@ -98,6 +98,7 @@ namespace OpenTK.Platform.SDL2
joystick = new JoystickDevice<Sdl2JoystickDetails>(id, num_axes, num_buttons);
joystick.Description = SDL.JoystickName(handle);
joystick.Details.Handle = handle;
joystick.Details.InstanceId = SDL.JoystickInstanceID(handle);
joystick.Details.Guid = SDL.JoystickGetGUID(handle).ToGuid();
joystick.Details.HatCount = num_hats;
joystick.Details.BallCount = num_balls;
@ -315,11 +316,12 @@ namespace OpenTK.Platform.SDL2
{
IntPtr handle = SDL.JoystickOpen(id);
if (handle != IntPtr.Zero)
{
int device_id = id;
int instance_id = last_joystick_instance++;
{
JoystickDevice<Sdl2JoystickDetails> joystick = OpenJoystick(id);
int instance_id = joystick.Details.InstanceId;
int device_id = id;
if (joystick != null)
{
joystick.Details.IsConnected = true;