Improve behavior of SDL_events_need_periodic_poll() and SDL_events_need_polling()

SDL_events_need_periodic_poll() and SDL_events_need_polling() are intended to allow the event loop to update joysticks and/or sensors if needed, however those systems only update when the SDL_update_joysticks and/or SDL_update_sensors variables are true. This change brings the behavior of these functions in line with if work will actually need to be performed.

This change allows the hints for AUTO_UPDATE to influence the polling behavior of the event loop such that an app can choose to update joysticks/sensors itself and avoid the expense of constantly sleeping and waking the event loop. Additionally in makes these functions marginally faster in some situations by not searching the active events.
main
diddily 2022-07-25 10:12:53 -04:00 committed by Sam Lantinga
parent d9bda89fce
commit 1e492b2f6d
1 changed files with 4 additions and 5 deletions

View File

@ -903,13 +903,12 @@ SDL_events_need_periodic_poll() {
#if !SDL_JOYSTICK_DISABLED
need_periodic_poll =
SDL_WasInit(SDL_INIT_JOYSTICK) &&
(!SDL_disabled_events[SDL_JOYAXISMOTION >> 8] || SDL_JoystickEventState(SDL_QUERY));
SDL_WasInit(SDL_INIT_JOYSTICK) && SDL_update_joysticks;
#endif
#if !SDL_SENSOR_DISABLED
need_periodic_poll = need_periodic_poll ||
(SDL_WasInit(SDL_INIT_SENSOR) && !SDL_disabled_events[SDL_SENSORUPDATE >> 8]);
(SDL_WasInit(SDL_INIT_SENSOR) && SDL_update_sensors);
#endif
return need_periodic_poll;
@ -994,13 +993,13 @@ SDL_events_need_polling() {
#if !SDL_JOYSTICK_DISABLED
need_polling =
SDL_WasInit(SDL_INIT_JOYSTICK) &&
(!SDL_disabled_events[SDL_JOYAXISMOTION >> 8] || SDL_JoystickEventState(SDL_QUERY)) &&
SDL_update_joysticks &&
(SDL_NumJoysticks() > 0);
#endif
#if !SDL_SENSOR_DISABLED
need_polling = need_polling ||
(SDL_WasInit(SDL_INIT_SENSOR) && !SDL_disabled_events[SDL_SENSORUPDATE >> 8] && (SDL_NumSensors() > 0));
(SDL_WasInit(SDL_INIT_SENSOR) && SDL_update_sensors && (SDL_NumSensors() > 0));
#endif
return need_polling;