mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-21 05:09:46 -06:00
make joystick hotpluggable
This commit is contained in:
@ -401,7 +401,11 @@ int EmuThreadFunc(void* burp)
|
|||||||
if (Joystick)
|
if (Joystick)
|
||||||
{
|
{
|
||||||
njoybuttons = SDL_JoystickNumButtons(Joystick);
|
njoybuttons = SDL_JoystickNumButtons(Joystick);
|
||||||
if (njoybuttons) joybuttons = new Uint8[njoybuttons];
|
if (njoybuttons)
|
||||||
|
{
|
||||||
|
joybuttons = new Uint8[njoybuttons];
|
||||||
|
memset(joybuttons, 0, sizeof(Uint8)*njoybuttons);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 nframes = 0;
|
u32 nframes = 0;
|
||||||
@ -416,15 +420,27 @@ int EmuThreadFunc(void* burp)
|
|||||||
if (EmuRunning == 1)
|
if (EmuRunning == 1)
|
||||||
{
|
{
|
||||||
EmuStatus = 1;
|
EmuStatus = 1;
|
||||||
|
|
||||||
|
SDL_JoystickUpdate();
|
||||||
|
|
||||||
|
if (Joystick)
|
||||||
|
{
|
||||||
|
if (!SDL_JoystickGetAttached(Joystick))
|
||||||
|
{
|
||||||
|
SDL_JoystickClose(Joystick);
|
||||||
|
Joystick = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!Joystick && (SDL_NumJoysticks() > 0))
|
||||||
|
{
|
||||||
|
Joystick = SDL_JoystickOpen(0);
|
||||||
|
}
|
||||||
|
|
||||||
// poll input
|
// poll input
|
||||||
u32 keymask = KeyInputMask;
|
u32 keymask = KeyInputMask;
|
||||||
u32 joymask = 0xFFF;
|
u32 joymask = 0xFFF;
|
||||||
if (Joystick)
|
if (Joystick)
|
||||||
{
|
{
|
||||||
SDL_JoystickUpdate();
|
|
||||||
|
|
||||||
Uint32 hat = SDL_JoystickGetHat(Joystick, 0);
|
Uint32 hat = SDL_JoystickGetHat(Joystick, 0);
|
||||||
Sint16 axisX = SDL_JoystickGetAxis(Joystick, 0);
|
Sint16 axisX = SDL_JoystickGetAxis(Joystick, 0);
|
||||||
Sint16 axisY = SDL_JoystickGetAxis(Joystick, 1);
|
Sint16 axisY = SDL_JoystickGetAxis(Joystick, 1);
|
||||||
|
Reference in New Issue
Block a user