@@ -28,27 +28,27 @@ struct InputJoypadSDL {
2828 }
2929
3030 auto poll (vector<shared_pointer<HID::Device>>& devices) -> void {
31- SDL_JoystickUpdate ();
31+ SDL_UpdateJoysticks ();
3232 SDL_Event event;
3333 while (SDL_PollEvent (&event)) {
34- if (event.type == SDL_JOYDEVICEADDED || event.type == SDL_JOYDEVICEREMOVED ) {
34+ if (event.type == SDL_EVENT_JOYSTICK_ADDED || event.type == SDL_EVENT_JOYSTICK_REMOVED ) {
3535 enumerate();
3636 }
3737 }
3838
3939 for (auto & jp : joypads) {
4040 for (u32 n : range (jp.hid ->axes ().size ())) {
41- assign (jp, HID::Joypad::GroupID::Axis, n, (s16)SDL_JoystickGetAxis (jp.handle , n));
41+ assign (jp, HID::Joypad::GroupID::Axis, n, (s16)SDL_GetJoystickAxis (jp.handle , n));
4242 }
4343
4444 for (s32 n = 0 ; n < (s32)jp.hid ->hats ().size () - 1 ; n += 2 ) {
45- u8 state = SDL_JoystickGetHat (jp.handle , n >> 1 );
45+ u8 state = SDL_GetJoystickHat (jp.handle , n >> 1 );
4646 assign (jp, HID::Joypad::GroupID::Hat, n + 0 , state & SDL_HAT_LEFT ? -32767 : state & SDL_HAT_RIGHT ? +32767 : 0 );
4747 assign (jp, HID::Joypad::GroupID::Hat, n + 1 , state & SDL_HAT_UP ? -32767 : state & SDL_HAT_DOWN ? +32767 : 0 );
4848 }
4949
5050 for (u32 n : range (jp.hid ->buttons ().size ())) {
51- assign (jp, HID::Joypad::GroupID::Button, n, (bool )SDL_JoystickGetButton (jp.handle , n));
51+ assign (jp, HID::Joypad::GroupID::Button, n, (bool )SDL_GetJoystickButton (jp.handle , n));
5252 }
5353
5454 devices.append (jp.hid );
@@ -59,7 +59,7 @@ struct InputJoypadSDL {
5959 for (auto & jp : joypads) {
6060 if (jp.hid ->id () != id) continue ;
6161
62- SDL_JoystickRumble (jp.handle , strong, weak, 0 );
62+ SDL_RumbleJoystick (jp.handle , strong, weak, 0 );
6363 return true ;
6464 }
6565
@@ -70,14 +70,14 @@ struct InputJoypadSDL {
7070 terminate ();
7171 SDL_Init (SDL_INIT_EVENTS);
7272 SDL_InitSubSystem (SDL_INIT_JOYSTICK);
73- SDL_JoystickEventState (SDL_ENABLE );
73+ // SDL_JoystickEventState(1 );
7474 enumerate();
7575 return true ;
7676 }
7777
7878 auto terminate () -> void {
7979 for (auto & jp : joypads) {
80- SDL_JoystickClose (jp.handle );
80+ SDL_CloseJoystick (jp.handle );
8181 }
8282 joypads.reset ();
8383 SDL_QuitSubSystem (SDL_INIT_JOYSTICK);
@@ -86,31 +86,33 @@ struct InputJoypadSDL {
8686private:
8787 auto enumerate() -> void {
8888 for (auto & joypad : joypads) {
89- SDL_JoystickClose (joypad.handle );
89+ SDL_CloseJoystick (joypad.handle );
9090 }
9191 joypads.reset ();
92-
93- for (u32 id : range (SDL_NumJoysticks ())) {
92+ int num_joysticks;
93+ SDL_JoystickID *joysticks = SDL_GetJoysticks (&num_joysticks);
94+ for (int i = 0 ; i < num_joysticks; i++) {
95+ SDL_JoystickID id = joysticks[i];
9496 Joypad jp;
9597 jp.id = id;
96- jp.handle = SDL_JoystickOpen (jp.id );
98+ jp.handle = SDL_OpenJoystick (jp.id );
9799 if (!jp.handle ) {
98100 const char *err = SDL_GetError ();
99101 print (" Error opening SDL joystick id " , id, " : " , err);
100102 continue ;
101103 }
102104
103- s32 axes = SDL_JoystickNumAxes (jp.handle );
104- s32 hats = SDL_JoystickNumHats (jp.handle ) * 2 ;
105- s32 buttons = SDL_JoystickNumButtons (jp.handle );
105+ s32 axes = SDL_GetNumJoystickAxes (jp.handle );
106+ s32 hats = SDL_GetNumJoystickHats (jp.handle ) * 2 ;
107+ s32 buttons = SDL_GetNumJoystickButtons (jp.handle );
106108 if (axes < 0 || hats < 0 || buttons < 0 ) {
107109 const char *err = SDL_GetError ();
108110 print (" Error retrieving SDL joystick information for device " , jp.handle , " at index " , id, " : " , err);
109111 continue ;
110112 }
111113
112- u16 vid = SDL_JoystickGetVendor (jp.handle );
113- u16 pid = SDL_JoystickGetProduct (jp.handle );
114+ u16 vid = SDL_GetJoystickVendor (jp.handle );
115+ u16 pid = SDL_GetJoystickProduct (jp.handle );
114116 if (vid == 0 ) vid = HID::Joypad::GenericVendorID;
115117 if (pid == 0 ) pid = HID::Joypad::GenericProductID;
116118
@@ -124,7 +126,7 @@ struct InputJoypadSDL {
124126
125127 joypads.append (jp);
126128 }
127-
128- SDL_JoystickUpdate ();
129+ SDL_free (joysticks);
130+ SDL_UpdateJoysticks ();
129131 }
130132};
0 commit comments