Date:2011-10-23 09:59:22 (12 years 5 months ago)
Author:Maarten ter Huurne
Commit:433be5daf73485ba1be24e2db8a860d2e7884697
Message:InputManager: have "joystick" as a member instead of a global.

Files: src/inputmanager.cpp (2 diffs)
src/inputmanager.h (2 diffs)

Change Details

src/inputmanager.cpp
3030
3131using namespace std;
3232
33static SDL_Joystick *joystick;
34
3533void InputManager::init(const string &conffile) {
3634    if (!readConfFile(conffile)) {
3735        ERROR("InputManager initialization from config file failed.\n");
3836    }
3937}
4038
41InputManager::InputManager() {
42    initJoystick();
43}
44
45InputManager::~InputManager() {
39InputManager::InputManager()
40    : joystick(NULL)
41{
4642    if (SDL_NumJoysticks() > 0) {
47        SDL_JoystickClose(joystick);
43        joystick = SDL_JoystickOpen(0);
4844    }
4945}
5046
51void InputManager::initJoystick() {
52    if (SDL_NumJoysticks() > 0) {
53        joystick = SDL_JoystickOpen(0);
47InputManager::~InputManager() {
48    if (joystick) {
49        SDL_JoystickClose(joystick);
5450    }
5551}
5652
...... 
134130    //TODO: when an event is processed, program a new event
135131    //in some time, and when it occurs, do a key repeat
136132
137    SDL_JoystickUpdate();
133    if (joystick) {
134        SDL_JoystickUpdate();
135    }
138136    SDL_Event event;
139137    if (wait) {
140138        SDL_WaitEvent(&event);
src/inputmanager.h
2323
2424#include <string>
2525
26typedef struct _SDL_Joystick SDL_Joystick;
27
2628class InputManager {
2729public:
2830    enum Button {
...... 
5860        unsigned int code;
5961    };
6062
61    ButtonMapEntry buttonMap[BUTTON_TYPE_SIZE];
62
6363    bool readConfFile(const std::string &conffile);
64    void initJoystick();
6564    bool getEvent(ButtonEvent *bevent, bool wait);
6665    Button waitForButton(ButtonState state);
66
67    ButtonMapEntry buttonMap[BUTTON_TYPE_SIZE];
68    SDL_Joystick *joystick;
6769};
6870
6971#endif

Archive Download the corresponding diff file



interactive