Commit 446d19c4de2dff6fd941239a41c360c25a6ae1bf

Ryan C. Gordon 2014-06-14T23:31:23

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c
index 28be2ed..7cb4f0c 100644
--- a/src/events/SDL_events.c
+++ b/src/events/SDL_events.c
@@ -83,19 +83,6 @@ static struct
 } 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 @@ SDL_PumpEvents(void)
     }
 #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
diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c
index 062ece3..b9924f3 100644
--- a/src/joystick/SDL_joystick.c
+++ b/src/joystick/SDL_joystick.c
@@ -736,18 +736,6 @@ SDL_JoystickEventState(int state)
 #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)
 {
diff --git a/src/joystick/SDL_joystick_c.h b/src/joystick/SDL_joystick_c.h
index bb0c020..064fb8a 100644
--- a/src/joystick/SDL_joystick_c.h
+++ b/src/joystick/SDL_joystick_c.h
@@ -42,9 +42,6 @@ extern int SDL_PrivateJoystickHat(SDL_Joystick * joystick,
 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);
 
diff --git a/src/joystick/SDL_sysjoystick.h b/src/joystick/SDL_sysjoystick.h
index 818509d..a5218d5 100644
--- a/src/joystick/SDL_sysjoystick.h
+++ b/src/joystick/SDL_sysjoystick.h
@@ -68,9 +68,6 @@ extern int SDL_SYS_NumJoysticks();
 /* 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);
 
diff --git a/src/joystick/android/SDL_sysjoystick.c b/src/joystick/android/SDL_sysjoystick.c
index 422c5f5..cce94b8 100644
--- a/src/joystick/android/SDL_sysjoystick.c
+++ b/src/joystick/android/SDL_sysjoystick.c
@@ -410,11 +410,6 @@ void SDL_SYS_JoystickDetect()
     }
 }
 
-SDL_bool SDL_SYS_JoystickNeedsPolling()
-{
-    return SDL_TRUE;
-}
-
 static SDL_joylist_item *
 JoystickByDevIndex(int device_index)
 {
diff --git a/src/joystick/bsd/SDL_sysjoystick.c b/src/joystick/bsd/SDL_sysjoystick.c
index 2a09f92..65a32ed 100644
--- a/src/joystick/bsd/SDL_sysjoystick.c
+++ b/src/joystick/bsd/SDL_sysjoystick.c
@@ -213,11 +213,6 @@ void SDL_SYS_JoystickDetect()
 {
 }
 
-SDL_bool SDL_SYS_JoystickNeedsPolling()
-{
-    return SDL_FALSE;
-}
-
 const char *
 SDL_SYS_JoystickNameForDeviceIndex(int device_index)
 {
diff --git a/src/joystick/darwin/SDL_sysjoystick.c b/src/joystick/darwin/SDL_sysjoystick.c
index bdb6d29..12c1048 100644
--- a/src/joystick/darwin/SDL_sysjoystick.c
+++ b/src/joystick/darwin/SDL_sysjoystick.c
@@ -601,15 +601,6 @@ SDL_SYS_JoystickDetect()
     }
 }
 
-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)
diff --git a/src/joystick/dummy/SDL_sysjoystick.c b/src/joystick/dummy/SDL_sysjoystick.c
index 0d45b6c..9baa795 100644
--- a/src/joystick/dummy/SDL_sysjoystick.c
+++ b/src/joystick/dummy/SDL_sysjoystick.c
@@ -46,11 +46,6 @@ void SDL_SYS_JoystickDetect()
 {
 }
 
-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)
diff --git a/src/joystick/haiku/SDL_haikujoystick.cc b/src/joystick/haiku/SDL_haikujoystick.cc
index 95757bc..0caea17 100644
--- a/src/joystick/haiku/SDL_haikujoystick.cc
+++ b/src/joystick/haiku/SDL_haikujoystick.cc
@@ -94,11 +94,6 @@ extern "C"
     {
     }
 
-    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)
     {
diff --git a/src/joystick/iphoneos/SDL_sysjoystick.m b/src/joystick/iphoneos/SDL_sysjoystick.m
index b89bd78..a895130 100644
--- a/src/joystick/iphoneos/SDL_sysjoystick.m
+++ b/src/joystick/iphoneos/SDL_sysjoystick.m
@@ -49,11 +49,6 @@ void SDL_SYS_JoystickDetect()
 {
 }
 
-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)
diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c
index c37a22d..05bf086 100644
--- a/src/joystick/linux/SDL_sysjoystick.c
+++ b/src/joystick/linux/SDL_sysjoystick.c
@@ -392,15 +392,6 @@ void SDL_SYS_JoystickDetect()
     
 }
 
-SDL_bool SDL_SYS_JoystickNeedsPolling()
-{
-#if SDL_USE_LIBUDEV
-    return SDL_TRUE;
-#endif
-    
-    return SDL_FALSE;
-}
-
 static SDL_joylist_item *
 JoystickByDevIndex(int device_index)
 {
diff --git a/src/joystick/psp/SDL_sysjoystick.c b/src/joystick/psp/SDL_sysjoystick.c
index d01489b..9a2362e 100644
--- a/src/joystick/psp/SDL_sysjoystick.c
+++ b/src/joystick/psp/SDL_sysjoystick.c
@@ -141,11 +141,6 @@ void SDL_SYS_JoystickDetect()
 {
 }
 
-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)
 {
diff --git a/src/joystick/windows/SDL_dxjoystick.c b/src/joystick/windows/SDL_dxjoystick.c
index 66c2e0f..ff8a215 100644
--- a/src/joystick/windows/SDL_dxjoystick.c
+++ b/src/joystick/windows/SDL_dxjoystick.c
@@ -797,80 +797,71 @@ EnumXInputDevices(JoyStick_DeviceData **pContext)
 void SDL_SYS_JoystickDetect()
 {
     JoyStick_DeviceData *pCurList = NULL;
+#if !SDL_EVENTS_DISABLED
+    SDL_Event event;
+#endif
+
     /* only enum the devices if the joystick thread told us something changed */
-    if ( s_bDeviceAdded || s_bDeviceRemoved )
-    {
-        SDL_LockMutex( s_mutexJoyStickEnum );
+    if (!s_bDeviceAdded && !s_bDeviceRemoved) {
+        return;  /* thread hasn't signaled, nothing to do right now. */
+    }
 
-        s_bDeviceAdded = SDL_FALSE;
-        s_bDeviceRemoved = SDL_FALSE;
+    SDL_LockMutex(s_mutexJoyStickEnum);
 
-        pCurList = SYS_Joystick;
-        SYS_Joystick = NULL;
+    s_bDeviceAdded = SDL_FALSE;
+    s_bDeviceRemoved = SDL_FALSE;
 
-        /* Look for DirectInput joysticks, wheels, head trackers, gamepads, etc.. */
-        IDirectInput8_EnumDevices(dinput,
-            DI8DEVCLASS_GAMECTRL,
-            EnumJoysticksCallback,
-            &pCurList, DIEDFL_ATTACHEDONLY);
+    pCurList = SYS_Joystick;
+    SYS_Joystick = NULL;
 
-        SDL_free(SDL_RawDevList);  /* in case we used this in DirectInput enumerator. */
-        SDL_RawDevList = NULL;
-        SDL_RawDevListCount = 0;
+    /* Look for DirectInput joysticks, wheels, head trackers, gamepads, etc.. */
+    IDirectInput8_EnumDevices(dinput, DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback, &pCurList, DIEDFL_ATTACHEDONLY);
 
-        /* Look for XInput devices. Do this last, so they're first in the final list. */
-        EnumXInputDevices(&pCurList);
+    SDL_free(SDL_RawDevList);  /* in case we used this in DirectInput enumerator. */
+    SDL_RawDevList = NULL;
+    SDL_RawDevListCount = 0;
 
-        SDL_UnlockMutex( s_mutexJoyStickEnum );
-    }
+    /* Look for XInput devices. Do this last, so they're first in the final list. */
+    EnumXInputDevices(&pCurList);
 
-    if ( pCurList )
-    {
-        while ( pCurList )
-        {
-            JoyStick_DeviceData *pListNext = NULL;
+    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;
         }
+#endif /* !SDL_EVENTS_DISABLED */
 
+        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 @@ void SDL_SYS_JoystickDetect()
 #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 @@ void SDL_SYS_JoystickDetect()
     }
 }
 
-/* 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)
diff --git a/src/joystick/windows/SDL_mmjoystick.c b/src/joystick/windows/SDL_mmjoystick.c
index c28ed91..0f3b6de 100644
--- a/src/joystick/windows/SDL_mmjoystick.c
+++ b/src/joystick/windows/SDL_mmjoystick.c
@@ -193,11 +193,6 @@ void SDL_SYS_JoystickDetect()
 {
 }
 
-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)
diff --git a/src/joystick/winrt/SDL_xinputjoystick.c b/src/joystick/winrt/SDL_xinputjoystick.c
index 0000508..63e694c 100644
--- a/src/joystick/winrt/SDL_xinputjoystick.c
+++ b/src/joystick/winrt/SDL_xinputjoystick.c
@@ -230,14 +230,6 @@ void SDL_SYS_JoystickDetect()
     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