diff --git a/include/mapper.h b/include/mapper.h index 674a9363..975d865d 100644 --- a/include/mapper.h +++ b/include/mapper.h @@ -36,7 +36,8 @@ void MAPPER_BindKeys(); void MAPPER_StartUp(Section * sec); void MAPPER_Run(bool pressed); void MAPPER_DisplayUI(); -void MAPPER_LosingFocus(void); +void MAPPER_LosingFocus(); +bool MAPPER_IsUsingJoysticks(); std::vector MAPPER_GetEventNames(const std::string &prefix); void MAPPER_AutoType(std::vector &sequence, const uint32_t wait_ms, diff --git a/src/gui/sdl_mapper.cpp b/src/gui/sdl_mapper.cpp index 0d549c8d..e884de5a 100644 --- a/src/gui/sdl_mapper.cpp +++ b/src/gui/sdl_mapper.cpp @@ -2500,9 +2500,10 @@ void BIND_MappingEvents() { /** * Queries SDL's joysticks and sets joytype accordingly. * If no joysticks are valid then joytype is left at JOY_NONE. - * Also resets mapper.sticks.num_groups to 0 and - * mapper.sticks.num to the number of found SDL joysticks. - */ + * Also resets mapper.sticks.num_groups to 0, mapper.sticks.num + * to the number of found SDL joysticks, and enables the boolean + * joysticks_active if joystick support is enabled and are present. + */ static void QueryJoysticks() { // Initialize SDL's Joystick and Event subsystems, if needed if (SDL_WasInit(SDL_INIT_JOYSTICK) != SDL_INIT_JOYSTICK) @@ -2597,6 +2598,10 @@ static void CreateBindGroups() { } } +bool MAPPER_IsUsingJoysticks() { + return (mapper.sticks.num > 0); +} + #if defined (REDUCE_JOYSTICK_POLLING) void MAPPER_UpdateJoysticks() { for (Bitu i=0; i 20) { - poll_delay = time; - if (sdl.num_joysticks > 0) SDL_JoystickUpdate(); - MAPPER_UpdateJoysticks(); + if (MAPPER_IsUsingJoysticks()) { + static int poll_delay = 0; + int time = GetTicks(); + if (time - poll_delay > 20) { + poll_delay = time; + SDL_JoystickUpdate(); + MAPPER_UpdateJoysticks(); + } } #endif while (SDL_PollEvent(&event)) { @@ -3151,18 +3152,9 @@ int main(int argc, char* argv[]) { // Once initialized, ensure we clean up SDL for all exit conditions atexit(SDL_Quit); -#ifndef DISABLE_JOYSTICK - //Initialise Joystick separately. This way we can warn when it fails instead - //of exiting the application - if( SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0 ) - LOG_MSG("Failed to init joystick support"); -#endif - sdl.laltstate = SDL_KEYUP; sdl.raltstate = SDL_KEYUP; - sdl.num_joysticks=SDL_NumJoysticks(); - CROSS_DetermineConfigPaths(); /* Parse configuration files */