forked from MoonsideGames/MoonWorks
fix controller hot swapping
parent
3584e670ee
commit
e3c2f0e119
|
@ -195,6 +195,20 @@ namespace MoonWorks.Input
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Register(IntPtr handle)
|
||||||
|
{
|
||||||
|
Handle = handle;
|
||||||
|
|
||||||
|
IntPtr joystickHandle = SDL.SDL_GameControllerGetJoystick(Handle);
|
||||||
|
JoystickInstanceID = SDL.SDL_JoystickInstanceID(joystickHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Unregister()
|
||||||
|
{
|
||||||
|
Handle = IntPtr.Zero;
|
||||||
|
JoystickInstanceID = -1;
|
||||||
|
}
|
||||||
|
|
||||||
internal void Update()
|
internal void Update()
|
||||||
{
|
{
|
||||||
AnyPressed = false;
|
AnyPressed = false;
|
||||||
|
|
|
@ -95,7 +95,7 @@ namespace MoonWorks.Input
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gamepads[slot].Handle = openResult;
|
gamepads[slot].Register(openResult);
|
||||||
System.Console.WriteLine($"Gamepad added to slot {slot}!");
|
System.Console.WriteLine($"Gamepad added to slot {slot}!");
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -112,7 +112,7 @@ namespace MoonWorks.Input
|
||||||
if (joystickInstanceID == gamepads[slot].JoystickInstanceID)
|
if (joystickInstanceID == gamepads[slot].JoystickInstanceID)
|
||||||
{
|
{
|
||||||
SDL.SDL_GameControllerClose(gamepads[slot].Handle);
|
SDL.SDL_GameControllerClose(gamepads[slot].Handle);
|
||||||
gamepads[slot].Handle = IntPtr.Zero;
|
gamepads[slot].Unregister();
|
||||||
System.Console.WriteLine($"Removing gamepad from slot {slot}!");
|
System.Console.WriteLine($"Removing gamepad from slot {slot}!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue