From 8185991062366449ad0950fe6071c43cb9928b00 Mon Sep 17 00:00:00 2001 From: Kp Date: Sun, 13 Sep 2015 21:02:19 +0000 Subject: [PATCH] Ignore excess joysticks --- common/arch/sdl/joy.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/common/arch/sdl/joy.cpp b/common/arch/sdl/joy.cpp index a3f7a7c78..3fc676513 100644 --- a/common/arch/sdl/joy.cpp +++ b/common/arch/sdl/joy.cpp @@ -141,15 +141,16 @@ template static T check_warn_joy_support_limit(const T n, const char *const desc) { if (n <= MAX) + { + con_printf(CON_NORMAL, "sdl-joystick: %d %ss", n, desc); return n; + } Warning("sdl-joystick: found %d %ss, only %d supported.\n", n, desc, MAX); return MAX; } void joy_init() { - int n; - if (SDL_Init(SDL_INIT_JOYSTICK) < 0) { con_printf(CON_NORMAL, "sdl-joystick: initialisation failed: %s.",SDL_GetError()); return; @@ -159,9 +160,7 @@ void joy_init() joyaxis_text.clear(); joybutton_text.clear(); - n = SDL_NumJoysticks(); - - con_printf(CON_NORMAL, "sdl-joystick: found %d joysticks", n); + const auto n = check_warn_joy_support_limit(SDL_NumJoysticks(), "joystick"); for (int i = 0; i < n; i++) { auto &joystick = SDL_Joysticks[num_joysticks]; const auto handle = joystick.handle = SDL_JoystickOpen(i); @@ -175,9 +174,6 @@ void joy_init() const auto n_axes = joystick.n_axes = check_warn_joy_support_limit(SDL_JoystickNumAxes(handle), "axe"); const auto n_buttons = joystick.n_buttons = check_warn_joy_support_limit(SDL_JoystickNumButtons(handle), "button"); const auto n_hats = joystick.n_hats = check_warn_joy_support_limit(SDL_JoystickNumHats(handle), "hat"); - con_printf(CON_NORMAL, "sdl-joystick: %d axes", n_axes); - con_printf(CON_NORMAL, "sdl-joystick: %d buttons", n_buttons); - con_printf(CON_NORMAL, "sdl-joystick: %d hats", n_hats); joyaxis_text.resize(joyaxis_text.size() + n_axes); for (int j=0; j < n_axes; j++)