Removed SDL_SYS_JoystickNeedsPolling().
authorRyan C. Gordon <icculus@icculus.org>
Sat, 14 Jun 2014 23:31:23 -0400
changeset 8860 c4133d635375
parent 8859 8396cc409327
child 8861 dfc5e5220e54
Removed SDL_SYS_JoystickNeedsPolling(). It was simpler to just have the polling (actually: hotplug detection) functions return immediately if it's not an appropriate time to poll. Note that previously, if any joystick/controller was opened, we would poll every time anyhow, skipping this function.
src/events/SDL_events.c
src/joystick/SDL_joystick.c
src/joystick/SDL_joystick_c.h
src/joystick/SDL_sysjoystick.h
src/joystick/android/SDL_sysjoystick.c
src/joystick/bsd/SDL_sysjoystick.c
src/joystick/darwin/SDL_sysjoystick.c
src/joystick/dummy/SDL_sysjoystick.c
src/joystick/haiku/SDL_haikujoystick.cc
src/joystick/iphoneos/SDL_sysjoystick.m
src/joystick/linux/SDL_sysjoystick.c
src/joystick/psp/SDL_sysjoystick.c
src/joystick/windows/SDL_dxjoystick.c
src/joystick/windows/SDL_mmjoystick.c
src/joystick/winrt/SDL_xinputjoystick.c
--- a/src/events/SDL_events.c	Fri Jun 13 14:52:26 2014 -0400
+++ b/src/events/SDL_events.c	Sat Jun 14 23:31:23 2014 -0400
@@ -83,19 +83,6 @@
 } SDL_EventQ = { NULL, SDL_TRUE };
 
 
-static SDL_INLINE SDL_bool
-SDL_ShouldPollJoystick()
-{
-#if !SDL_JOYSTICK_DISABLED
-    if ((!SDL_disabled_events[SDL_JOYAXISMOTION >> 8] ||
-         SDL_JoystickEventState(SDL_QUERY)) &&
-        SDL_PrivateJoystickNeedsPolling()) {
-        return SDL_TRUE;
-    }
-#endif
-    return SDL_FALSE;
-}
-
 /* Public functions */
 
 void
@@ -403,7 +390,7 @@
     }
 #if !SDL_JOYSTICK_DISABLED
     /* Check for joystick state change */
-    if (SDL_ShouldPollJoystick()) {
+    if ((!SDL_disabled_events[SDL_JOYAXISMOTION >> 8] || SDL_JoystickEventState(SDL_QUERY))) {
         SDL_JoystickUpdate();
     }
 #endif
--- a/src/joystick/SDL_joystick.c	Fri Jun 13 14:52:26 2014 -0400
+++ b/src/joystick/SDL_joystick.c	Sat Jun 14 23:31:23 2014 -0400
@@ -736,18 +736,6 @@
 #endif /* SDL_EVENTS_DISABLED */
 }
 
-/* return 1 if you want to run the joystick update loop this frame, used by hotplug support */
-SDL_bool
-SDL_PrivateJoystickNeedsPolling()
-{
-    if (SDL_joysticks != NULL) {
-        return SDL_TRUE;
-    } else {
-        return SDL_SYS_JoystickNeedsPolling();
-    }
-}
-
-
 /* return the guid for this index */
 SDL_JoystickGUID SDL_JoystickGetDeviceGUID(int device_index)
 {
--- a/src/joystick/SDL_joystick_c.h	Fri Jun 13 14:52:26 2014 -0400
+++ b/src/joystick/SDL_joystick_c.h	Sat Jun 14 23:31:23 2014 -0400
@@ -42,9 +42,6 @@
 extern int SDL_PrivateJoystickButton(SDL_Joystick * joystick,
                                      Uint8 button, Uint8 state);
 
-/* Helper function to let lower sys layer tell the event system if the joystick code needs to think */
-extern SDL_bool SDL_PrivateJoystickNeedsPolling();
-
 /* Internal sanity checking functions */
 extern int SDL_PrivateJoystickValid(SDL_Joystick * joystick);
 
--- a/src/joystick/SDL_sysjoystick.h	Fri Jun 13 14:52:26 2014 -0400
+++ b/src/joystick/SDL_sysjoystick.h	Sat Jun 14 23:31:23 2014 -0400
@@ -68,9 +68,6 @@
 /* Function to cause any queued joystick insertions to be processed */
 extern void SDL_SYS_JoystickDetect();
 
-/* Function to determine if the joystick loop needs to run right now */
-extern SDL_bool SDL_SYS_JoystickNeedsPolling();
-
 /* Function to get the device-dependent name of a joystick */
 extern const char *SDL_SYS_JoystickNameForDeviceIndex(int device_index);
 
--- a/src/joystick/android/SDL_sysjoystick.c	Fri Jun 13 14:52:26 2014 -0400
+++ b/src/joystick/android/SDL_sysjoystick.c	Sat Jun 14 23:31:23 2014 -0400
@@ -410,11 +410,6 @@
     }
 }
 
-SDL_bool SDL_SYS_JoystickNeedsPolling()
-{
-    return SDL_TRUE;
-}
-
 static SDL_joylist_item *
 JoystickByDevIndex(int device_index)
 {
--- a/src/joystick/bsd/SDL_sysjoystick.c	Fri Jun 13 14:52:26 2014 -0400
+++ b/src/joystick/bsd/SDL_sysjoystick.c	Sat Jun 14 23:31:23 2014 -0400
@@ -213,11 +213,6 @@
 {
 }
 
-SDL_bool SDL_SYS_JoystickNeedsPolling()
-{
-    return SDL_FALSE;
-}
-
 const char *
 SDL_SYS_JoystickNameForDeviceIndex(int device_index)
 {
--- a/src/joystick/darwin/SDL_sysjoystick.c	Fri Jun 13 14:52:26 2014 -0400
+++ b/src/joystick/darwin/SDL_sysjoystick.c	Sat Jun 14 23:31:23 2014 -0400
@@ -601,15 +601,6 @@
     }
 }
 
-SDL_bool
-SDL_SYS_JoystickNeedsPolling()
-{
-    while (CFRunLoopRunInMode(SDL_JOYSTICK_RUNLOOP_MODE,0,TRUE) == kCFRunLoopRunHandledSource) {
-        /* no-op. Pending callbacks will fire in CFRunLoopRunInMode(). */
-    }
-    return s_bDeviceAdded || s_bDeviceRemoved;
-}
-
 /* Function to get the device-dependent name of a joystick */
 const char *
 SDL_SYS_JoystickNameForDeviceIndex(int device_index)
--- a/src/joystick/dummy/SDL_sysjoystick.c	Fri Jun 13 14:52:26 2014 -0400
+++ b/src/joystick/dummy/SDL_sysjoystick.c	Sat Jun 14 23:31:23 2014 -0400
@@ -46,11 +46,6 @@
 {
 }
 
-SDL_bool SDL_SYS_JoystickNeedsPolling()
-{
-    return SDL_FALSE;
-}
-
 /* Function to get the device-dependent name of a joystick */
 const char *
 SDL_SYS_JoystickNameForDeviceIndex(int device_index)
--- a/src/joystick/haiku/SDL_haikujoystick.cc	Fri Jun 13 14:52:26 2014 -0400
+++ b/src/joystick/haiku/SDL_haikujoystick.cc	Sat Jun 14 23:31:23 2014 -0400
@@ -94,11 +94,6 @@
     {
     }
 
-    SDL_bool SDL_SYS_JoystickNeedsPolling()
-    {
-        return SDL_FALSE;
-    }
-
 /* Function to get the device-dependent name of a joystick */
     const char *SDL_SYS_JoystickNameForDeviceIndex(int device_index)
     {
--- a/src/joystick/iphoneos/SDL_sysjoystick.m	Fri Jun 13 14:52:26 2014 -0400
+++ b/src/joystick/iphoneos/SDL_sysjoystick.m	Sat Jun 14 23:31:23 2014 -0400
@@ -49,11 +49,6 @@
 {
 }
 
-SDL_bool SDL_SYS_JoystickNeedsPolling()
-{
-    return SDL_FALSE;
-}
-
 /* Function to get the device-dependent name of a joystick */
 const char *
 SDL_SYS_JoystickNameForDeviceIndex(int device_index)
--- a/src/joystick/linux/SDL_sysjoystick.c	Fri Jun 13 14:52:26 2014 -0400
+++ b/src/joystick/linux/SDL_sysjoystick.c	Sat Jun 14 23:31:23 2014 -0400
@@ -392,15 +392,6 @@
     
 }
 
-SDL_bool SDL_SYS_JoystickNeedsPolling()
-{
-#if SDL_USE_LIBUDEV
-    return SDL_TRUE;
-#endif
-    
-    return SDL_FALSE;
-}
-
 static SDL_joylist_item *
 JoystickByDevIndex(int device_index)
 {
--- a/src/joystick/psp/SDL_sysjoystick.c	Fri Jun 13 14:52:26 2014 -0400
+++ b/src/joystick/psp/SDL_sysjoystick.c	Sat Jun 14 23:31:23 2014 -0400
@@ -141,11 +141,6 @@
 {
 }
 
-SDL_bool SDL_SYS_JoystickNeedsPolling()
-{
-    return SDL_FALSE;
-}
-
 /* Function to get the device-dependent name of a joystick */
 const char * SDL_SYS_JoystickNameForDeviceIndex(int device_index)
 {
--- a/src/joystick/windows/SDL_dxjoystick.c	Fri Jun 13 14:52:26 2014 -0400
+++ b/src/joystick/windows/SDL_dxjoystick.c	Sat Jun 14 23:31:23 2014 -0400
@@ -797,80 +797,71 @@
 void SDL_SYS_JoystickDetect()
 {
     JoyStick_DeviceData *pCurList = NULL;
-    /* only enum the devices if the joystick thread told us something changed */
-    if ( s_bDeviceAdded || s_bDeviceRemoved )
-    {
-        SDL_LockMutex( s_mutexJoyStickEnum );
-
-        s_bDeviceAdded = SDL_FALSE;
-        s_bDeviceRemoved = SDL_FALSE;
-
-        pCurList = SYS_Joystick;
-        SYS_Joystick = NULL;
+#if !SDL_EVENTS_DISABLED
+    SDL_Event event;
+#endif
 
-        /* Look for DirectInput joysticks, wheels, head trackers, gamepads, etc.. */
-        IDirectInput8_EnumDevices(dinput,
-            DI8DEVCLASS_GAMECTRL,
-            EnumJoysticksCallback,
-            &pCurList, DIEDFL_ATTACHEDONLY);
-
-        SDL_free(SDL_RawDevList);  /* in case we used this in DirectInput enumerator. */
-        SDL_RawDevList = NULL;
-        SDL_RawDevListCount = 0;
-
-        /* Look for XInput devices. Do this last, so they're first in the final list. */
-        EnumXInputDevices(&pCurList);
-
-        SDL_UnlockMutex( s_mutexJoyStickEnum );
+    /* only enum the devices if the joystick thread told us something changed */
+    if (!s_bDeviceAdded && !s_bDeviceRemoved) {
+        return;  /* thread hasn't signaled, nothing to do right now. */
     }
 
-    if ( pCurList )
-    {
-        while ( pCurList )
-        {
-            JoyStick_DeviceData *pListNext = NULL;
+    SDL_LockMutex(s_mutexJoyStickEnum);
+
+    s_bDeviceAdded = SDL_FALSE;
+    s_bDeviceRemoved = SDL_FALSE;
+
+    pCurList = SYS_Joystick;
+    SYS_Joystick = NULL;
+
+    /* Look for DirectInput joysticks, wheels, head trackers, gamepads, etc.. */
+    IDirectInput8_EnumDevices(dinput, DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback, &pCurList, DIEDFL_ATTACHEDONLY);
+
+    SDL_free(SDL_RawDevList);  /* in case we used this in DirectInput enumerator. */
+    SDL_RawDevList = NULL;
+    SDL_RawDevListCount = 0;
+
+    /* Look for XInput devices. Do this last, so they're first in the final list. */
+    EnumXInputDevices(&pCurList);
+
+    SDL_UnlockMutex(s_mutexJoyStickEnum);
+
+    while (pCurList) {
+        JoyStick_DeviceData *pListNext = NULL;
 
 #if SDL_HAPTIC_DINPUT
-            if (pCurList->bXInputDevice) {
-                XInputHaptic_MaybeRemoveDevice(pCurList->XInputUserId);
-            } else {
-                DirectInputHaptic_MaybeRemoveDevice(&pCurList->dxdevice);
-            }
+        if (pCurList->bXInputDevice) {
+            XInputHaptic_MaybeRemoveDevice(pCurList->XInputUserId);
+        } else {
+            DirectInputHaptic_MaybeRemoveDevice(&pCurList->dxdevice);
+        }
 #endif
 
 #if !SDL_EVENTS_DISABLED
-            {
-            SDL_Event event;
-            event.type = SDL_JOYDEVICEREMOVED;
+        SDL_zero(event);
+        event.type = SDL_JOYDEVICEREMOVED;
 
-            if (SDL_GetEventState(event.type) == SDL_ENABLE) {
-                event.jdevice.which = pCurList->nInstanceID;
-                if ((SDL_EventOK == NULL)
-                    || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
-                        SDL_PushEvent(&event);
-                }
+        if (SDL_GetEventState(event.type) == SDL_ENABLE) {
+            event.jdevice.which = pCurList->nInstanceID;
+            if ((!SDL_EventOK) || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
+                SDL_PushEvent(&event);
             }
-            }
+        }
 #endif /* !SDL_EVENTS_DISABLED */
 
-            pListNext = pCurList->pNext;
-            SDL_free(pCurList->joystickname);
-            SDL_free(pCurList);
-            pCurList = pListNext;
-        }
-
+        pListNext = pCurList->pNext;
+        SDL_free(pCurList->joystickname);
+        SDL_free(pCurList);
+        pCurList = pListNext;
     }
 
-    if ( s_bDeviceAdded )
-    {
+    if (s_bDeviceAdded) {
         JoyStick_DeviceData *pNewJoystick;
         int device_index = 0;
         s_bDeviceAdded = SDL_FALSE;
         pNewJoystick = SYS_Joystick;
-        while ( pNewJoystick )
-        {
-            if ( pNewJoystick->send_add_event )
-            {
+        while (pNewJoystick) {
+            if (pNewJoystick->send_add_event) {
 #if SDL_HAPTIC_DINPUT
                 if (pNewJoystick->bXInputDevice) {
                     XInputHaptic_MaybeAddDevice(pNewJoystick->XInputUserId);
@@ -880,18 +871,15 @@
 #endif
 
 #if !SDL_EVENTS_DISABLED
-                {
-                SDL_Event event;
+                SDL_zero(event);
                 event.type = SDL_JOYDEVICEADDED;
 
                 if (SDL_GetEventState(event.type) == SDL_ENABLE) {
                     event.jdevice.which = device_index;
-                    if ((SDL_EventOK == NULL)
-                        || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
-                            SDL_PushEvent(&event);
+                    if ((!SDL_EventOK) || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
+                        SDL_PushEvent(&event);
                     }
                 }
-                }
 #endif /* !SDL_EVENTS_DISABLED */
                 pNewJoystick->send_add_event = 0;
             }
@@ -901,16 +889,6 @@
     }
 }
 
-/* we need to poll if we have pending hotplug device changes or connected devices */
-SDL_bool SDL_SYS_JoystickNeedsPolling()
-{
-    /* we have a new device or one was pulled, we need to think this frame please */
-    if ( s_bDeviceAdded || s_bDeviceRemoved )
-        return SDL_TRUE;
-
-    return SDL_FALSE;
-}
-
 /* Function to get the device-dependent name of a joystick */
 const char *
 SDL_SYS_JoystickNameForDeviceIndex(int device_index)
--- a/src/joystick/windows/SDL_mmjoystick.c	Fri Jun 13 14:52:26 2014 -0400
+++ b/src/joystick/windows/SDL_mmjoystick.c	Sat Jun 14 23:31:23 2014 -0400
@@ -193,11 +193,6 @@
 {
 }
 
-SDL_bool SDL_SYS_JoystickNeedsPolling()
-{
-    return SDL_FALSE;
-}
-
 /* Function to get the device-dependent name of a joystick */
 const char *
 SDL_SYS_JoystickNameForDeviceIndex(int device_index)
--- a/src/joystick/winrt/SDL_xinputjoystick.c	Fri Jun 13 14:52:26 2014 -0400
+++ b/src/joystick/winrt/SDL_xinputjoystick.c	Sat Jun 14 23:31:23 2014 -0400
@@ -230,14 +230,6 @@
     SDL_UnlockMutex(g_DeviceInfoLock);
 }
 
-SDL_bool SDL_SYS_JoystickNeedsPolling()
-{
-    /* Since XInput, or WinRT, provides any events to indicate when a game
-       controller gets connected, and instead indicates device availability
-       solely through polling, we'll poll (for new devices).
-     */
-    return SDL_TRUE;
-}
 
 /* Internal function to retreive device capabilities.
    This function will return an SDL-standard value of 0 on success