From fcb2618286122e529c79e8677b5159841c018a6d Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Mon, 29 Jul 2013 01:28:52 -0400 Subject: [PATCH] Open all available joysticks --- src/inputmanager.cpp | 21 ++++++++++----------- src/inputmanager.h | 3 ++- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/inputmanager.cpp b/src/inputmanager.cpp index 9698dad..1715af6 100644 --- a/src/inputmanager.cpp +++ b/src/inputmanager.cpp @@ -41,19 +41,18 @@ void InputManager::init(const string &conffile, Menu *menu) { InputManager::InputManager() { #ifndef SDL_JOYSTICK_DISABLED - if (SDL_NumJoysticks() > 0) { - joystick = SDL_JoystickOpen(0); - } else { - joystick = NULL; - } + int i; + for (i = 0; i < SDL_NumJoysticks(); i++) + joysticks.push_back(SDL_JoystickOpen(i)); #endif } -InputManager::~InputManager() { +InputManager::~InputManager() +{ #ifndef SDL_JOYSTICK_DISABLED - if (joystick) { - SDL_JoystickClose(joystick); - } + for (std::vector::iterator it = joysticks.begin(); + it < joysticks.end(); it++) + SDL_JoystickClose(*it); #endif } @@ -139,10 +138,10 @@ bool InputManager::getEvent(ButtonEvent *bevent, bool wait) { int i; #ifndef SDL_JOYSTICK_DISABLED - if (joystick) { + if (joysticks.size() > 0) SDL_JoystickUpdate(); - } #endif + SDL_Event event; if (wait) { SDL_WaitEvent(&event); diff --git a/src/inputmanager.h b/src/inputmanager.h index 72eccdd..2eb001e 100644 --- a/src/inputmanager.h +++ b/src/inputmanager.h @@ -23,6 +23,7 @@ #include #include +#include class Menu; @@ -74,7 +75,7 @@ private: ButtonMapEntry buttonMap[BUTTON_TYPE_SIZE]; #ifndef SDL_JOYSTICK_DISABLED - SDL_Joystick *joystick; + std::vector joysticks; #endif };