Removed SDL_SYS_JoystickNeedsPolling().
authorRyan C. Gordon <icculus@icculus.org>
Sat, 14 Jun 2014 23:31:23 -0400
changeset 8860c4133d635375
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
     1.1 --- a/src/events/SDL_events.c	Fri Jun 13 14:52:26 2014 -0400
     1.2 +++ b/src/events/SDL_events.c	Sat Jun 14 23:31:23 2014 -0400
     1.3 @@ -83,19 +83,6 @@
     1.4  } SDL_EventQ = { NULL, SDL_TRUE };
     1.5  
     1.6  
     1.7 -static SDL_INLINE SDL_bool
     1.8 -SDL_ShouldPollJoystick()
     1.9 -{
    1.10 -#if !SDL_JOYSTICK_DISABLED
    1.11 -    if ((!SDL_disabled_events[SDL_JOYAXISMOTION >> 8] ||
    1.12 -         SDL_JoystickEventState(SDL_QUERY)) &&
    1.13 -        SDL_PrivateJoystickNeedsPolling()) {
    1.14 -        return SDL_TRUE;
    1.15 -    }
    1.16 -#endif
    1.17 -    return SDL_FALSE;
    1.18 -}
    1.19 -
    1.20  /* Public functions */
    1.21  
    1.22  void
    1.23 @@ -403,7 +390,7 @@
    1.24      }
    1.25  #if !SDL_JOYSTICK_DISABLED
    1.26      /* Check for joystick state change */
    1.27 -    if (SDL_ShouldPollJoystick()) {
    1.28 +    if ((!SDL_disabled_events[SDL_JOYAXISMOTION >> 8] || SDL_JoystickEventState(SDL_QUERY))) {
    1.29          SDL_JoystickUpdate();
    1.30      }
    1.31  #endif
     2.1 --- a/src/joystick/SDL_joystick.c	Fri Jun 13 14:52:26 2014 -0400
     2.2 +++ b/src/joystick/SDL_joystick.c	Sat Jun 14 23:31:23 2014 -0400
     2.3 @@ -736,18 +736,6 @@
     2.4  #endif /* SDL_EVENTS_DISABLED */
     2.5  }
     2.6  
     2.7 -/* return 1 if you want to run the joystick update loop this frame, used by hotplug support */
     2.8 -SDL_bool
     2.9 -SDL_PrivateJoystickNeedsPolling()
    2.10 -{
    2.11 -    if (SDL_joysticks != NULL) {
    2.12 -        return SDL_TRUE;
    2.13 -    } else {
    2.14 -        return SDL_SYS_JoystickNeedsPolling();
    2.15 -    }
    2.16 -}
    2.17 -
    2.18 -
    2.19  /* return the guid for this index */
    2.20  SDL_JoystickGUID SDL_JoystickGetDeviceGUID(int device_index)
    2.21  {
     3.1 --- a/src/joystick/SDL_joystick_c.h	Fri Jun 13 14:52:26 2014 -0400
     3.2 +++ b/src/joystick/SDL_joystick_c.h	Sat Jun 14 23:31:23 2014 -0400
     3.3 @@ -42,9 +42,6 @@
     3.4  extern int SDL_PrivateJoystickButton(SDL_Joystick * joystick,
     3.5                                       Uint8 button, Uint8 state);
     3.6  
     3.7 -/* Helper function to let lower sys layer tell the event system if the joystick code needs to think */
     3.8 -extern SDL_bool SDL_PrivateJoystickNeedsPolling();
     3.9 -
    3.10  /* Internal sanity checking functions */
    3.11  extern int SDL_PrivateJoystickValid(SDL_Joystick * joystick);
    3.12  
     4.1 --- a/src/joystick/SDL_sysjoystick.h	Fri Jun 13 14:52:26 2014 -0400
     4.2 +++ b/src/joystick/SDL_sysjoystick.h	Sat Jun 14 23:31:23 2014 -0400
     4.3 @@ -68,9 +68,6 @@
     4.4  /* Function to cause any queued joystick insertions to be processed */
     4.5  extern void SDL_SYS_JoystickDetect();
     4.6  
     4.7 -/* Function to determine if the joystick loop needs to run right now */
     4.8 -extern SDL_bool SDL_SYS_JoystickNeedsPolling();
     4.9 -
    4.10  /* Function to get the device-dependent name of a joystick */
    4.11  extern const char *SDL_SYS_JoystickNameForDeviceIndex(int device_index);
    4.12  
     5.1 --- a/src/joystick/android/SDL_sysjoystick.c	Fri Jun 13 14:52:26 2014 -0400
     5.2 +++ b/src/joystick/android/SDL_sysjoystick.c	Sat Jun 14 23:31:23 2014 -0400
     5.3 @@ -410,11 +410,6 @@
     5.4      }
     5.5  }
     5.6  
     5.7 -SDL_bool SDL_SYS_JoystickNeedsPolling()
     5.8 -{
     5.9 -    return SDL_TRUE;
    5.10 -}
    5.11 -
    5.12  static SDL_joylist_item *
    5.13  JoystickByDevIndex(int device_index)
    5.14  {
     6.1 --- a/src/joystick/bsd/SDL_sysjoystick.c	Fri Jun 13 14:52:26 2014 -0400
     6.2 +++ b/src/joystick/bsd/SDL_sysjoystick.c	Sat Jun 14 23:31:23 2014 -0400
     6.3 @@ -213,11 +213,6 @@
     6.4  {
     6.5  }
     6.6  
     6.7 -SDL_bool SDL_SYS_JoystickNeedsPolling()
     6.8 -{
     6.9 -    return SDL_FALSE;
    6.10 -}
    6.11 -
    6.12  const char *
    6.13  SDL_SYS_JoystickNameForDeviceIndex(int device_index)
    6.14  {
     7.1 --- a/src/joystick/darwin/SDL_sysjoystick.c	Fri Jun 13 14:52:26 2014 -0400
     7.2 +++ b/src/joystick/darwin/SDL_sysjoystick.c	Sat Jun 14 23:31:23 2014 -0400
     7.3 @@ -601,15 +601,6 @@
     7.4      }
     7.5  }
     7.6  
     7.7 -SDL_bool
     7.8 -SDL_SYS_JoystickNeedsPolling()
     7.9 -{
    7.10 -    while (CFRunLoopRunInMode(SDL_JOYSTICK_RUNLOOP_MODE,0,TRUE) == kCFRunLoopRunHandledSource) {
    7.11 -        /* no-op. Pending callbacks will fire in CFRunLoopRunInMode(). */
    7.12 -    }
    7.13 -    return s_bDeviceAdded || s_bDeviceRemoved;
    7.14 -}
    7.15 -
    7.16  /* Function to get the device-dependent name of a joystick */
    7.17  const char *
    7.18  SDL_SYS_JoystickNameForDeviceIndex(int device_index)
     8.1 --- a/src/joystick/dummy/SDL_sysjoystick.c	Fri Jun 13 14:52:26 2014 -0400
     8.2 +++ b/src/joystick/dummy/SDL_sysjoystick.c	Sat Jun 14 23:31:23 2014 -0400
     8.3 @@ -46,11 +46,6 @@
     8.4  {
     8.5  }
     8.6  
     8.7 -SDL_bool SDL_SYS_JoystickNeedsPolling()
     8.8 -{
     8.9 -    return SDL_FALSE;
    8.10 -}
    8.11 -
    8.12  /* Function to get the device-dependent name of a joystick */
    8.13  const char *
    8.14  SDL_SYS_JoystickNameForDeviceIndex(int device_index)
     9.1 --- a/src/joystick/haiku/SDL_haikujoystick.cc	Fri Jun 13 14:52:26 2014 -0400
     9.2 +++ b/src/joystick/haiku/SDL_haikujoystick.cc	Sat Jun 14 23:31:23 2014 -0400
     9.3 @@ -94,11 +94,6 @@
     9.4      {
     9.5      }
     9.6  
     9.7 -    SDL_bool SDL_SYS_JoystickNeedsPolling()
     9.8 -    {
     9.9 -        return SDL_FALSE;
    9.10 -    }
    9.11 -
    9.12  /* Function to get the device-dependent name of a joystick */
    9.13      const char *SDL_SYS_JoystickNameForDeviceIndex(int device_index)
    9.14      {
    10.1 --- a/src/joystick/iphoneos/SDL_sysjoystick.m	Fri Jun 13 14:52:26 2014 -0400
    10.2 +++ b/src/joystick/iphoneos/SDL_sysjoystick.m	Sat Jun 14 23:31:23 2014 -0400
    10.3 @@ -49,11 +49,6 @@
    10.4  {
    10.5  }
    10.6  
    10.7 -SDL_bool SDL_SYS_JoystickNeedsPolling()
    10.8 -{
    10.9 -    return SDL_FALSE;
   10.10 -}
   10.11 -
   10.12  /* Function to get the device-dependent name of a joystick */
   10.13  const char *
   10.14  SDL_SYS_JoystickNameForDeviceIndex(int device_index)
    11.1 --- a/src/joystick/linux/SDL_sysjoystick.c	Fri Jun 13 14:52:26 2014 -0400
    11.2 +++ b/src/joystick/linux/SDL_sysjoystick.c	Sat Jun 14 23:31:23 2014 -0400
    11.3 @@ -392,15 +392,6 @@
    11.4      
    11.5  }
    11.6  
    11.7 -SDL_bool SDL_SYS_JoystickNeedsPolling()
    11.8 -{
    11.9 -#if SDL_USE_LIBUDEV
   11.10 -    return SDL_TRUE;
   11.11 -#endif
   11.12 -    
   11.13 -    return SDL_FALSE;
   11.14 -}
   11.15 -
   11.16  static SDL_joylist_item *
   11.17  JoystickByDevIndex(int device_index)
   11.18  {
    12.1 --- a/src/joystick/psp/SDL_sysjoystick.c	Fri Jun 13 14:52:26 2014 -0400
    12.2 +++ b/src/joystick/psp/SDL_sysjoystick.c	Sat Jun 14 23:31:23 2014 -0400
    12.3 @@ -141,11 +141,6 @@
    12.4  {
    12.5  }
    12.6  
    12.7 -SDL_bool SDL_SYS_JoystickNeedsPolling()
    12.8 -{
    12.9 -    return SDL_FALSE;
   12.10 -}
   12.11 -
   12.12  /* Function to get the device-dependent name of a joystick */
   12.13  const char * SDL_SYS_JoystickNameForDeviceIndex(int device_index)
   12.14  {
    13.1 --- a/src/joystick/windows/SDL_dxjoystick.c	Fri Jun 13 14:52:26 2014 -0400
    13.2 +++ b/src/joystick/windows/SDL_dxjoystick.c	Sat Jun 14 23:31:23 2014 -0400
    13.3 @@ -797,80 +797,71 @@
    13.4  void SDL_SYS_JoystickDetect()
    13.5  {
    13.6      JoyStick_DeviceData *pCurList = NULL;
    13.7 +#if !SDL_EVENTS_DISABLED
    13.8 +    SDL_Event event;
    13.9 +#endif
   13.10 +
   13.11      /* only enum the devices if the joystick thread told us something changed */
   13.12 -    if ( s_bDeviceAdded || s_bDeviceRemoved )
   13.13 -    {
   13.14 -        SDL_LockMutex( s_mutexJoyStickEnum );
   13.15 -
   13.16 -        s_bDeviceAdded = SDL_FALSE;
   13.17 -        s_bDeviceRemoved = SDL_FALSE;
   13.18 -
   13.19 -        pCurList = SYS_Joystick;
   13.20 -        SYS_Joystick = NULL;
   13.21 -
   13.22 -        /* Look for DirectInput joysticks, wheels, head trackers, gamepads, etc.. */
   13.23 -        IDirectInput8_EnumDevices(dinput,
   13.24 -            DI8DEVCLASS_GAMECTRL,
   13.25 -            EnumJoysticksCallback,
   13.26 -            &pCurList, DIEDFL_ATTACHEDONLY);
   13.27 -
   13.28 -        SDL_free(SDL_RawDevList);  /* in case we used this in DirectInput enumerator. */
   13.29 -        SDL_RawDevList = NULL;
   13.30 -        SDL_RawDevListCount = 0;
   13.31 -
   13.32 -        /* Look for XInput devices. Do this last, so they're first in the final list. */
   13.33 -        EnumXInputDevices(&pCurList);
   13.34 -
   13.35 -        SDL_UnlockMutex( s_mutexJoyStickEnum );
   13.36 +    if (!s_bDeviceAdded && !s_bDeviceRemoved) {
   13.37 +        return;  /* thread hasn't signaled, nothing to do right now. */
   13.38      }
   13.39  
   13.40 -    if ( pCurList )
   13.41 -    {
   13.42 -        while ( pCurList )
   13.43 -        {
   13.44 -            JoyStick_DeviceData *pListNext = NULL;
   13.45 +    SDL_LockMutex(s_mutexJoyStickEnum);
   13.46 +
   13.47 +    s_bDeviceAdded = SDL_FALSE;
   13.48 +    s_bDeviceRemoved = SDL_FALSE;
   13.49 +
   13.50 +    pCurList = SYS_Joystick;
   13.51 +    SYS_Joystick = NULL;
   13.52 +
   13.53 +    /* Look for DirectInput joysticks, wheels, head trackers, gamepads, etc.. */
   13.54 +    IDirectInput8_EnumDevices(dinput, DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback, &pCurList, DIEDFL_ATTACHEDONLY);
   13.55 +
   13.56 +    SDL_free(SDL_RawDevList);  /* in case we used this in DirectInput enumerator. */
   13.57 +    SDL_RawDevList = NULL;
   13.58 +    SDL_RawDevListCount = 0;
   13.59 +
   13.60 +    /* Look for XInput devices. Do this last, so they're first in the final list. */
   13.61 +    EnumXInputDevices(&pCurList);
   13.62 +
   13.63 +    SDL_UnlockMutex(s_mutexJoyStickEnum);
   13.64 +
   13.65 +    while (pCurList) {
   13.66 +        JoyStick_DeviceData *pListNext = NULL;
   13.67  
   13.68  #if SDL_HAPTIC_DINPUT
   13.69 -            if (pCurList->bXInputDevice) {
   13.70 -                XInputHaptic_MaybeRemoveDevice(pCurList->XInputUserId);
   13.71 -            } else {
   13.72 -                DirectInputHaptic_MaybeRemoveDevice(&pCurList->dxdevice);
   13.73 -            }
   13.74 +        if (pCurList->bXInputDevice) {
   13.75 +            XInputHaptic_MaybeRemoveDevice(pCurList->XInputUserId);
   13.76 +        } else {
   13.77 +            DirectInputHaptic_MaybeRemoveDevice(&pCurList->dxdevice);
   13.78 +        }
   13.79  #endif
   13.80  
   13.81  #if !SDL_EVENTS_DISABLED
   13.82 -            {
   13.83 -            SDL_Event event;
   13.84 -            event.type = SDL_JOYDEVICEREMOVED;
   13.85 +        SDL_zero(event);
   13.86 +        event.type = SDL_JOYDEVICEREMOVED;
   13.87  
   13.88 -            if (SDL_GetEventState(event.type) == SDL_ENABLE) {
   13.89 -                event.jdevice.which = pCurList->nInstanceID;
   13.90 -                if ((SDL_EventOK == NULL)
   13.91 -                    || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
   13.92 -                        SDL_PushEvent(&event);
   13.93 -                }
   13.94 +        if (SDL_GetEventState(event.type) == SDL_ENABLE) {
   13.95 +            event.jdevice.which = pCurList->nInstanceID;
   13.96 +            if ((!SDL_EventOK) || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
   13.97 +                SDL_PushEvent(&event);
   13.98              }
   13.99 -            }
  13.100 +        }
  13.101  #endif /* !SDL_EVENTS_DISABLED */
  13.102  
  13.103 -            pListNext = pCurList->pNext;
  13.104 -            SDL_free(pCurList->joystickname);
  13.105 -            SDL_free(pCurList);
  13.106 -            pCurList = pListNext;
  13.107 -        }
  13.108 -
  13.109 +        pListNext = pCurList->pNext;
  13.110 +        SDL_free(pCurList->joystickname);
  13.111 +        SDL_free(pCurList);
  13.112 +        pCurList = pListNext;
  13.113      }
  13.114  
  13.115 -    if ( s_bDeviceAdded )
  13.116 -    {
  13.117 +    if (s_bDeviceAdded) {
  13.118          JoyStick_DeviceData *pNewJoystick;
  13.119          int device_index = 0;
  13.120          s_bDeviceAdded = SDL_FALSE;
  13.121          pNewJoystick = SYS_Joystick;
  13.122 -        while ( pNewJoystick )
  13.123 -        {
  13.124 -            if ( pNewJoystick->send_add_event )
  13.125 -            {
  13.126 +        while (pNewJoystick) {
  13.127 +            if (pNewJoystick->send_add_event) {
  13.128  #if SDL_HAPTIC_DINPUT
  13.129                  if (pNewJoystick->bXInputDevice) {
  13.130                      XInputHaptic_MaybeAddDevice(pNewJoystick->XInputUserId);
  13.131 @@ -880,18 +871,15 @@
  13.132  #endif
  13.133  
  13.134  #if !SDL_EVENTS_DISABLED
  13.135 -                {
  13.136 -                SDL_Event event;
  13.137 +                SDL_zero(event);
  13.138                  event.type = SDL_JOYDEVICEADDED;
  13.139  
  13.140                  if (SDL_GetEventState(event.type) == SDL_ENABLE) {
  13.141                      event.jdevice.which = device_index;
  13.142 -                    if ((SDL_EventOK == NULL)
  13.143 -                        || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
  13.144 -                            SDL_PushEvent(&event);
  13.145 +                    if ((!SDL_EventOK) || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
  13.146 +                        SDL_PushEvent(&event);
  13.147                      }
  13.148                  }
  13.149 -                }
  13.150  #endif /* !SDL_EVENTS_DISABLED */
  13.151                  pNewJoystick->send_add_event = 0;
  13.152              }
  13.153 @@ -901,16 +889,6 @@
  13.154      }
  13.155  }
  13.156  
  13.157 -/* we need to poll if we have pending hotplug device changes or connected devices */
  13.158 -SDL_bool SDL_SYS_JoystickNeedsPolling()
  13.159 -{
  13.160 -    /* we have a new device or one was pulled, we need to think this frame please */
  13.161 -    if ( s_bDeviceAdded || s_bDeviceRemoved )
  13.162 -        return SDL_TRUE;
  13.163 -
  13.164 -    return SDL_FALSE;
  13.165 -}
  13.166 -
  13.167  /* Function to get the device-dependent name of a joystick */
  13.168  const char *
  13.169  SDL_SYS_JoystickNameForDeviceIndex(int device_index)
    14.1 --- a/src/joystick/windows/SDL_mmjoystick.c	Fri Jun 13 14:52:26 2014 -0400
    14.2 +++ b/src/joystick/windows/SDL_mmjoystick.c	Sat Jun 14 23:31:23 2014 -0400
    14.3 @@ -193,11 +193,6 @@
    14.4  {
    14.5  }
    14.6  
    14.7 -SDL_bool SDL_SYS_JoystickNeedsPolling()
    14.8 -{
    14.9 -    return SDL_FALSE;
   14.10 -}
   14.11 -
   14.12  /* Function to get the device-dependent name of a joystick */
   14.13  const char *
   14.14  SDL_SYS_JoystickNameForDeviceIndex(int device_index)
    15.1 --- a/src/joystick/winrt/SDL_xinputjoystick.c	Fri Jun 13 14:52:26 2014 -0400
    15.2 +++ b/src/joystick/winrt/SDL_xinputjoystick.c	Sat Jun 14 23:31:23 2014 -0400
    15.3 @@ -230,14 +230,6 @@
    15.4      SDL_UnlockMutex(g_DeviceInfoLock);
    15.5  }
    15.6  
    15.7 -SDL_bool SDL_SYS_JoystickNeedsPolling()
    15.8 -{
    15.9 -    /* Since XInput, or WinRT, provides any events to indicate when a game
   15.10 -       controller gets connected, and instead indicates device availability
   15.11 -       solely through polling, we'll poll (for new devices).
   15.12 -     */
   15.13 -    return SDL_TRUE;
   15.14 -}
   15.15  
   15.16  /* Internal function to retreive device capabilities.
   15.17     This function will return an SDL-standard value of 0 on success