1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-26 08:26:15 +02:00

InputManager: have "joystick" as a member instead of a global.

This commit is contained in:
Maarten ter Huurne 2011-10-23 09:59:22 +02:00
parent 641c989934
commit 433be5daf7
2 changed files with 15 additions and 15 deletions

View File

@ -30,27 +30,23 @@
using namespace std; using namespace std;
static SDL_Joystick *joystick;
void InputManager::init(const string &conffile) { void InputManager::init(const string &conffile) {
if (!readConfFile(conffile)) { if (!readConfFile(conffile)) {
ERROR("InputManager initialization from config file failed.\n"); ERROR("InputManager initialization from config file failed.\n");
} }
} }
InputManager::InputManager() { InputManager::InputManager()
initJoystick(); : joystick(NULL)
} {
InputManager::~InputManager() {
if (SDL_NumJoysticks() > 0) { if (SDL_NumJoysticks() > 0) {
SDL_JoystickClose(joystick); joystick = SDL_JoystickOpen(0);
} }
} }
void InputManager::initJoystick() { InputManager::~InputManager() {
if (SDL_NumJoysticks() > 0) { if (joystick) {
joystick = SDL_JoystickOpen(0); SDL_JoystickClose(joystick);
} }
} }
@ -134,7 +130,9 @@ bool InputManager::getEvent(ButtonEvent *bevent, bool wait) {
//TODO: when an event is processed, program a new event //TODO: when an event is processed, program a new event
//in some time, and when it occurs, do a key repeat //in some time, and when it occurs, do a key repeat
if (joystick) {
SDL_JoystickUpdate(); SDL_JoystickUpdate();
}
SDL_Event event; SDL_Event event;
if (wait) { if (wait) {
SDL_WaitEvent(&event); SDL_WaitEvent(&event);

View File

@ -23,6 +23,8 @@
#include <string> #include <string>
typedef struct _SDL_Joystick SDL_Joystick;
class InputManager { class InputManager {
public: public:
enum Button { enum Button {
@ -58,12 +60,12 @@ private:
unsigned int code; unsigned int code;
}; };
ButtonMapEntry buttonMap[BUTTON_TYPE_SIZE];
bool readConfFile(const std::string &conffile); bool readConfFile(const std::string &conffile);
void initJoystick();
bool getEvent(ButtonEvent *bevent, bool wait); bool getEvent(ButtonEvent *bevent, bool wait);
Button waitForButton(ButtonState state); Button waitForButton(ButtonState state);
ButtonMapEntry buttonMap[BUTTON_TYPE_SIZE];
SDL_Joystick *joystick;
}; };
#endif #endif