aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStapleButter <thetotalworm@gmail.com>2018-12-30 00:27:12 +0100
committerStapleButter <thetotalworm@gmail.com>2018-12-30 00:27:12 +0100
commit1cf49e0dbe74007a077f3c032b28e335fccb6d75 (patch)
treeed39102b40ee0a8d2b107805bb7507ac7f8eba55 /src
parent65c27c5c288818193d7957ae3549d687ccafaec5 (diff)
make joystick hotpluggable
Diffstat (limited to 'src')
-rw-r--r--src/libui_sdl/main.cpp24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp
index cd350f7..9f8f678 100644
--- a/src/libui_sdl/main.cpp
+++ b/src/libui_sdl/main.cpp
@@ -401,7 +401,11 @@ int EmuThreadFunc(void* burp)
if (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;
@@ -416,15 +420,27 @@ int EmuThreadFunc(void* burp)
if (EmuRunning == 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
u32 keymask = KeyInputMask;
u32 joymask = 0xFFF;
if (Joystick)
{
- SDL_JoystickUpdate();
-
Uint32 hat = SDL_JoystickGetHat(Joystick, 0);
Sint16 axisX = SDL_JoystickGetAxis(Joystick, 0);
Sint16 axisY = SDL_JoystickGetAxis(Joystick, 1);