event: Check subsystem initialization before events or devices

SDL_WasInit() is cheaper SDL_NumJoysticks()/SDL_NumSensors().
This commit is contained in:
Cameron Gutman 2021-10-26 20:02:38 -05:00
parent 1bc6dc3ea0
commit ac54d57aa5
1 changed files with 7 additions and 6 deletions

View File

@ -881,19 +881,20 @@ SDL_WaitEventTimeout_Device(_THIS, SDL_Window *wakeup_window, SDL_Event * event,
return 0; return 0;
} }
static int static SDL_bool
SDL_events_need_polling() { SDL_events_need_polling() {
SDL_bool need_polling = SDL_FALSE; SDL_bool need_polling = SDL_FALSE;
#if !SDL_JOYSTICK_DISABLED #if !SDL_JOYSTICK_DISABLED
need_polling = \ need_polling =
(!SDL_disabled_events[SDL_JOYAXISMOTION >> 8] || SDL_JoystickEventState(SDL_QUERY)) \ SDL_WasInit(SDL_INIT_JOYSTICK) &&
&& (SDL_NumJoysticks() > 0); (!SDL_disabled_events[SDL_JOYAXISMOTION >> 8] || SDL_JoystickEventState(SDL_QUERY)) &&
(SDL_NumJoysticks() > 0);
#endif #endif
#if !SDL_SENSOR_DISABLED #if !SDL_SENSOR_DISABLED
need_polling = need_polling || (!SDL_disabled_events[SDL_SENSORUPDATE >> 8] && \ need_polling = need_polling ||
(SDL_NumSensors() > 0)); (SDL_WasInit(SDL_INIT_SENSOR) && !SDL_disabled_events[SDL_SENSORUPDATE >> 8] && (SDL_NumSensors() > 0));
#endif #endif
return need_polling; return need_polling;