| 134 | } |
| 135 | |
| 136 | void InputManager::init() |
| 137 | { |
| 138 | if(mJoysticks != NULL) |
| 139 | deinit(); |
| 140 | |
| 141 | //get current input devices from system |
| 142 | inputDevices = getInputDevices(); |
| 143 | |
| 144 | SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_TIMER); |
| 145 | |
| 146 | mNumJoysticks = SDL_NumJoysticks(); |
| 147 | mJoysticks = new SDL_Joystick*[mNumJoysticks]; |
| 148 | mInputConfigs = new InputConfig*[mNumJoysticks]; |
| 149 | mPrevAxisValues = new std::map<int, int>[mNumJoysticks]; |
| 150 | |
| 151 | for(int i = 0; i < mNumJoysticks; i++) |
| 152 | { |
| 153 | mJoysticks[i] = SDL_JoystickOpen(i); |
| 154 | mInputConfigs[i] = new InputConfig(i); |
| 155 | |
| 156 | for(int k = 0; k < SDL_JoystickNumAxes(mJoysticks[i]); k++) |
| 157 | { |
| 158 | mPrevAxisValues[i][k] = 0; |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | mKeyboardInputConfig = new InputConfig(DEVICE_KEYBOARD); |
| 163 | |
| 164 | SDL_JoystickEventState(SDL_ENABLE); |
| 165 | |
| 166 | //start timer for input device polling |
| 167 | startPolling(); |
| 168 | |
| 169 | loadConfig(); |
| 170 | } |
| 171 | |
| 172 | void InputManager::startPolling() |
| 173 | { |