1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-29 17:17:31 +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;
static SDL_Joystick *joystick;
void InputManager::init(const string &conffile) {
if (!readConfFile(conffile)) {
ERROR("InputManager initialization from config file failed.\n");
}
}
InputManager::InputManager() {
initJoystick();
}
InputManager::~InputManager() {
InputManager::InputManager()
: joystick(NULL)
{
if (SDL_NumJoysticks() > 0) {
SDL_JoystickClose(joystick);
joystick = SDL_JoystickOpen(0);
}
}
void InputManager::initJoystick() {
if (SDL_NumJoysticks() > 0) {
joystick = SDL_JoystickOpen(0);
InputManager::~InputManager() {
if (joystick) {
SDL_JoystickClose(joystick);
}
}
@ -134,7 +130,9 @@ bool InputManager::getEvent(ButtonEvent *bevent, bool wait) {
//TODO: when an event is processed, program a new event
//in some time, and when it occurs, do a key repeat
SDL_JoystickUpdate();
if (joystick) {
SDL_JoystickUpdate();
}
SDL_Event event;
if (wait) {
SDL_WaitEvent(&event);

View File

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