[918] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
[1413] | 3 | * > www.orxonox.net < |
---|
[918] | 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Reto Grieder |
---|
| 24 | * Co-authors: |
---|
[934] | 25 | * ... |
---|
[918] | 26 | * |
---|
| 27 | */ |
---|
[973] | 28 | |
---|
[918] | 29 | /** |
---|
[1219] | 30 | @file |
---|
| 31 | @brief Implementation of the InputManager that captures all the input from OIS |
---|
[1293] | 32 | and redirects it to handlers. |
---|
[918] | 33 | */ |
---|
| 34 | |
---|
[1062] | 35 | #include "InputManager.h" |
---|
| 36 | #include "CoreIncludes.h" |
---|
| 37 | #include "Debug.h" |
---|
[1219] | 38 | #include "InputBuffer.h" |
---|
[1413] | 39 | #include "KeyBinder.h" |
---|
[918] | 40 | |
---|
| 41 | namespace orxonox |
---|
| 42 | { |
---|
[1219] | 43 | // ############################### |
---|
| 44 | // ### Internal Methods ### |
---|
| 45 | // ############################### |
---|
| 46 | // ############################### |
---|
[1084] | 47 | |
---|
[919] | 48 | /** |
---|
[1219] | 49 | @brief Constructor only sets member fields to initial zero values |
---|
| 50 | and registers the class in the class hierarchy. |
---|
[919] | 51 | */ |
---|
[973] | 52 | InputManager::InputManager() : |
---|
[1034] | 53 | inputSystem_(0), keyboard_(0), mouse_(0), |
---|
[1413] | 54 | keyBinder_(0), buffer_(0), |
---|
[1293] | 55 | joySticksSize_(0), |
---|
| 56 | state_(IS_UNINIT), stateRequest_(IS_UNINIT), |
---|
| 57 | keyboardModifiers_(0) |
---|
[918] | 58 | { |
---|
[1089] | 59 | RegisterObject(InputManager); |
---|
[929] | 60 | } |
---|
| 61 | |
---|
| 62 | /** |
---|
[973] | 63 | @brief The one instance of the InputManager is stored in this function. |
---|
[1035] | 64 | @return A reference to the only instance of the InputManager |
---|
[919] | 65 | */ |
---|
[1219] | 66 | InputManager& InputManager::_getSingleton() |
---|
[919] | 67 | { |
---|
[1035] | 68 | static InputManager theOnlyInstance; |
---|
| 69 | return theOnlyInstance; |
---|
[919] | 70 | } |
---|
| 71 | |
---|
| 72 | /** |
---|
[1219] | 73 | @brief Destructor only called at the end of the program, after main. |
---|
| 74 | */ |
---|
| 75 | InputManager::~InputManager() |
---|
| 76 | { |
---|
| 77 | _destroy(); |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | /** |
---|
| 81 | @brief Creates the OIS::InputMananger, the keyboard, the mouse and |
---|
| 82 | the joysticks and assigns the key bindings. |
---|
[919] | 83 | @param windowHnd The window handle of the render window |
---|
| 84 | @param windowWidth The width of the render window |
---|
| 85 | @param windowHeight The height of the render window |
---|
| 86 | */ |
---|
[1293] | 87 | bool InputManager::_initialise(const size_t windowHnd, int windowWidth, int windowHeight, |
---|
| 88 | bool createKeyboard, bool createMouse, bool createJoySticks) |
---|
[919] | 89 | { |
---|
[1219] | 90 | if (state_ == IS_UNINIT) |
---|
[918] | 91 | { |
---|
[1293] | 92 | CCOUT(3) << "Initialising Input System..." << std::endl; |
---|
[1219] | 93 | CCOUT(ORX_DEBUG) << "Initialising OIS components..." << std::endl; |
---|
| 94 | |
---|
[918] | 95 | OIS::ParamList paramList; |
---|
| 96 | std::ostringstream windowHndStr; |
---|
| 97 | |
---|
| 98 | // Fill parameter list |
---|
| 99 | windowHndStr << (unsigned int)windowHnd; |
---|
| 100 | paramList.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); |
---|
[1413] | 101 | //paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_NONEXCLUSIVE"))); |
---|
[1349] | 102 | //paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_FOREGROUND"))); |
---|
[1219] | 103 | //#if defined OIS_LINUX_PLATFORM |
---|
| 104 | // paramList.insert(std::make_pair(std::string("XAutoRepeatOn"), std::string("true"))); |
---|
| 105 | //#endif |
---|
[928] | 106 | |
---|
[934] | 107 | try |
---|
[918] | 108 | { |
---|
[934] | 109 | inputSystem_ = OIS::InputManager::createInputSystem(paramList); |
---|
[1219] | 110 | CCOUT(ORX_DEBUG) << "Created OIS input system" << std::endl; |
---|
[918] | 111 | } |
---|
[934] | 112 | catch (OIS::Exception ex) |
---|
| 113 | { |
---|
[1219] | 114 | CCOUT(ORX_ERROR) << "Error: Failed creating an OIS input system." |
---|
| 115 | << "OIS message: \"" << ex.eText << "\"" << std::endl; |
---|
| 116 | inputSystem_ = 0; |
---|
[934] | 117 | return false; |
---|
| 118 | } |
---|
[1219] | 119 | |
---|
| 120 | if (createKeyboard) |
---|
| 121 | _initialiseKeyboard(); |
---|
| 122 | |
---|
| 123 | if (createMouse) |
---|
| 124 | _initialiseMouse(); |
---|
| 125 | |
---|
| 126 | if (createJoySticks) |
---|
| 127 | _initialiseJoySticks(); |
---|
| 128 | |
---|
| 129 | // Set mouse/joystick region |
---|
[1349] | 130 | if (mouse_) |
---|
| 131 | { |
---|
| 132 | //// hack the mouse position |
---|
| 133 | //((OIS::MouseState&)mouse_->getMouseState()).X.abs = windowWidth/2; |
---|
| 134 | //((OIS::MouseState&)mouse_->getMouseState()).Y.abs = windowHeight/2; |
---|
| 135 | setWindowExtents(windowWidth, windowHeight); |
---|
| 136 | } |
---|
[1219] | 137 | |
---|
| 138 | state_ = IS_NONE; |
---|
| 139 | CCOUT(ORX_DEBUG) << "Initialising OIS components done." << std::endl; |
---|
[918] | 140 | } |
---|
[1219] | 141 | else |
---|
| 142 | { |
---|
| 143 | CCOUT(ORX_WARNING) << "Warning: OIS compoments already initialised, skipping" << std::endl; |
---|
| 144 | } |
---|
[922] | 145 | |
---|
[1219] | 146 | // InputManager holds the input buffer --> create one and add it. |
---|
[1413] | 147 | buffer_ = new InputBuffer(); |
---|
| 148 | addKeyHandler(buffer_, "buffer"); |
---|
[1022] | 149 | |
---|
[1413] | 150 | keyBinder_ = new KeyBinder(); |
---|
| 151 | keyBinder_->loadBindings(); |
---|
| 152 | addKeyHandler(keyBinder_, "keybinder"); |
---|
| 153 | addMouseHandler(keyBinder_, "keybinder"); |
---|
| 154 | addJoyStickHandler(keyBinder_, "keybinder"); |
---|
[922] | 155 | |
---|
[1413] | 156 | keyDetector_ = new KeyDetector(); |
---|
| 157 | keyDetector_->loadBindings(); |
---|
| 158 | addKeyHandler(keyDetector_, "keydetector"); |
---|
| 159 | addMouseHandler(keyDetector_, "keydetector"); |
---|
| 160 | addJoyStickHandler(keyDetector_, "keydetector"); |
---|
[934] | 161 | |
---|
[1219] | 162 | CCOUT(ORX_DEBUG) << "Initialising complete." << std::endl; |
---|
[934] | 163 | return true; |
---|
[918] | 164 | } |
---|
| 165 | |
---|
[919] | 166 | /** |
---|
[1219] | 167 | @brief Creates a keyboard and sets the event handler. |
---|
| 168 | @return False if keyboard stays uninitialised, true otherwise. |
---|
[928] | 169 | */ |
---|
[1219] | 170 | bool InputManager::_initialiseKeyboard() |
---|
[928] | 171 | { |
---|
[1219] | 172 | if (keyboard_ != 0) |
---|
| 173 | { |
---|
| 174 | CCOUT(2) << "Warning: Keyboard already initialised, skipping." << std::endl; |
---|
| 175 | return true; |
---|
| 176 | } |
---|
| 177 | try |
---|
| 178 | { |
---|
| 179 | if (inputSystem_->getNumberOfDevices(OIS::OISKeyboard) > 0) |
---|
| 180 | { |
---|
| 181 | keyboard_ = (OIS::Keyboard*)inputSystem_->createInputObject(OIS::OISKeyboard, true); |
---|
| 182 | // register our listener in OIS. |
---|
| 183 | keyboard_->setEventCallback(this); |
---|
| 184 | // note: OIS will not detect keys that have already been down when the keyboard was created. |
---|
| 185 | CCOUT(ORX_DEBUG) << "Created OIS keyboard" << std::endl; |
---|
| 186 | return true; |
---|
| 187 | } |
---|
| 188 | else |
---|
| 189 | { |
---|
| 190 | CCOUT(ORX_WARNING) << "Warning: No keyboard found!" << std::endl; |
---|
| 191 | return false; |
---|
| 192 | } |
---|
| 193 | } |
---|
| 194 | catch (OIS::Exception ex) |
---|
| 195 | { |
---|
| 196 | // TODO: Test this output regarding formatting |
---|
| 197 | CCOUT(ORX_WARNING) << "Warning: Failed to create an OIS keyboard\n" |
---|
| 198 | << "OIS error message: \"" << ex.eText << "\"" << std::endl; |
---|
| 199 | keyboard_ = 0; |
---|
| 200 | return false; |
---|
| 201 | } |
---|
| 202 | } |
---|
[928] | 203 | |
---|
[1219] | 204 | /** |
---|
| 205 | @brief Creates a mouse and sets the event handler. |
---|
| 206 | @return False if mouse stays uninitialised, true otherwise. |
---|
| 207 | */ |
---|
| 208 | bool InputManager::_initialiseMouse() |
---|
| 209 | { |
---|
| 210 | if (mouse_ != 0) |
---|
| 211 | { |
---|
| 212 | CCOUT(2) << "Warning: Mouse already initialised, skipping." << std::endl; |
---|
| 213 | return true; |
---|
| 214 | } |
---|
| 215 | try |
---|
| 216 | { |
---|
| 217 | if (inputSystem_->getNumberOfDevices(OIS::OISMouse) > 0) |
---|
| 218 | { |
---|
| 219 | mouse_ = static_cast<OIS::Mouse*>(inputSystem_->createInputObject(OIS::OISMouse, true)); |
---|
| 220 | // register our listener in OIS. |
---|
| 221 | mouse_->setEventCallback(this); |
---|
| 222 | CCOUT(ORX_DEBUG) << "Created OIS keyboard" << std::endl; |
---|
| 223 | return true; |
---|
| 224 | } |
---|
| 225 | else |
---|
| 226 | { |
---|
| 227 | CCOUT(ORX_WARNING) << "Warning: No mouse found!" << std::endl; |
---|
| 228 | return false; |
---|
| 229 | } |
---|
| 230 | } |
---|
| 231 | catch (OIS::Exception ex) |
---|
| 232 | { |
---|
| 233 | CCOUT(ORX_WARNING) << "Warning: Failed to create an OIS mouse\n" |
---|
| 234 | << "OIS error message: \"" << ex.eText << "\"" << std::endl; |
---|
| 235 | mouse_ = 0; |
---|
| 236 | return false; |
---|
| 237 | } |
---|
| 238 | } |
---|
[1035] | 239 | |
---|
[1219] | 240 | /** |
---|
| 241 | @brief Creates all joy sticks and sets the event handler. |
---|
| 242 | @return False joy stick stay uninitialised, true otherwise. |
---|
| 243 | */ |
---|
| 244 | bool InputManager::_initialiseJoySticks() |
---|
| 245 | { |
---|
[1293] | 246 | if (joySticksSize_ > 0) |
---|
[1219] | 247 | { |
---|
| 248 | CCOUT(2) << "Warning: Joy sticks already initialised, skipping." << std::endl; |
---|
| 249 | return true; |
---|
| 250 | } |
---|
| 251 | bool success = false; |
---|
| 252 | if (inputSystem_->getNumberOfDevices(OIS::OISJoyStick) > 0) |
---|
| 253 | { |
---|
| 254 | for (int i = 0; i < inputSystem_->getNumberOfDevices(OIS::OISJoyStick); i++) |
---|
| 255 | { |
---|
| 256 | try |
---|
| 257 | { |
---|
| 258 | OIS::JoyStick* stig = static_cast<OIS::JoyStick*>(inputSystem_->createInputObject(OIS::OISJoyStick, true)); |
---|
| 259 | joySticks_.push_back(stig); |
---|
| 260 | // register our listener in OIS. |
---|
| 261 | stig->setEventCallback(this); |
---|
| 262 | CCOUT(ORX_DEBUG) << "Created OIS joy stick with ID " << stig->getID() << std::endl; |
---|
| 263 | success = true; |
---|
| 264 | } |
---|
| 265 | catch (OIS::Exception ex) |
---|
| 266 | { |
---|
| 267 | CCOUT(ORX_WARNING) << "Warning: Failed to create OIS joy number" << i << "\n" |
---|
| 268 | << "OIS error message: \"" << ex.eText << "\"" << std::endl; |
---|
| 269 | } |
---|
| 270 | } |
---|
| 271 | } |
---|
| 272 | else |
---|
| 273 | { |
---|
| 274 | CCOUT(ORX_WARNING) << "Warning: Joy stick support requested, but no joy stick was found" << std::endl; |
---|
| 275 | return false; |
---|
| 276 | } |
---|
[1293] | 277 | joySticksSize_ = joySticks_.size(); |
---|
| 278 | activeJoyStickHandlers_.resize(joySticksSize_); |
---|
| 279 | joyStickButtonsDown_.resize(joySticksSize_); |
---|
[1349] | 280 | povStates_.resize(joySticksSize_); |
---|
| 281 | sliderStates_.resize(joySticksSize_); |
---|
[1219] | 282 | return success; |
---|
| 283 | } |
---|
[1035] | 284 | |
---|
[1219] | 285 | /** |
---|
| 286 | @brief Destroys all the created input devices and sets the InputManager to construction state. |
---|
| 287 | */ |
---|
| 288 | void InputManager::_destroy() |
---|
| 289 | { |
---|
| 290 | if (state_ != IS_UNINIT) |
---|
| 291 | { |
---|
[1293] | 292 | CCOUT(ORX_DEBUG) << "Destroying ..." << std::endl; |
---|
| 293 | |
---|
[1413] | 294 | if (buffer_) |
---|
| 295 | delete buffer_; |
---|
[1219] | 296 | |
---|
[1413] | 297 | if (keyBinder_) |
---|
| 298 | delete keyBinder_; |
---|
[1219] | 299 | |
---|
[1413] | 300 | if (keyDetector_) |
---|
| 301 | delete keyDetector_; |
---|
| 302 | |
---|
[1219] | 303 | keyHandlers_.clear(); |
---|
| 304 | mouseHandlers_.clear(); |
---|
| 305 | joyStickHandlers_.clear(); |
---|
| 306 | |
---|
| 307 | _destroyKeyboard(); |
---|
| 308 | _destroyMouse(); |
---|
| 309 | _destroyJoySticks(); |
---|
| 310 | |
---|
| 311 | // inputSystem_ can never be 0, or else the code is mistaken |
---|
| 312 | OIS::InputManager::destroyInputSystem(inputSystem_); |
---|
| 313 | inputSystem_ = 0; |
---|
| 314 | |
---|
| 315 | state_ = IS_UNINIT; |
---|
[1293] | 316 | CCOUT(ORX_DEBUG) << "Destroying done." << std::endl; |
---|
[1219] | 317 | } |
---|
[928] | 318 | } |
---|
| 319 | |
---|
| 320 | /** |
---|
[1219] | 321 | @brief Destroys the keyboard and sets it to 0. |
---|
| 322 | */ |
---|
| 323 | void InputManager::_destroyKeyboard() |
---|
| 324 | { |
---|
| 325 | if (keyboard_) |
---|
| 326 | // inputSystem_ can never be 0, or else the code is mistaken |
---|
| 327 | inputSystem_->destroyInputObject(keyboard_); |
---|
| 328 | keyboard_ = 0; |
---|
| 329 | activeKeyHandlers_.clear(); |
---|
| 330 | keysDown_.clear(); |
---|
| 331 | CCOUT(ORX_DEBUG) << "Keyboard destroyed." << std::endl; |
---|
| 332 | } |
---|
| 333 | |
---|
| 334 | /** |
---|
| 335 | @brief Destroys the mouse and sets it to 0. |
---|
| 336 | */ |
---|
| 337 | void InputManager::_destroyMouse() |
---|
| 338 | { |
---|
| 339 | if (mouse_) |
---|
| 340 | // inputSystem_ can never be 0, or else the code is mistaken |
---|
| 341 | inputSystem_->destroyInputObject(mouse_); |
---|
| 342 | mouse_ = 0; |
---|
| 343 | activeMouseHandlers_.clear(); |
---|
| 344 | mouseButtonsDown_.clear(); |
---|
| 345 | CCOUT(ORX_DEBUG) << "Mouse destroyed." << std::endl; |
---|
| 346 | } |
---|
| 347 | |
---|
| 348 | /** |
---|
| 349 | @brief Destroys all the joy sticks and resizes the lists to 0. |
---|
| 350 | */ |
---|
| 351 | void InputManager::_destroyJoySticks() |
---|
| 352 | { |
---|
[1293] | 353 | if (joySticksSize_ > 0) |
---|
[1219] | 354 | { |
---|
| 355 | // note: inputSystem_ can never be 0, or else the code is mistaken |
---|
[1293] | 356 | for (unsigned int i = 0; i < joySticksSize_; i++) |
---|
[1219] | 357 | if (joySticks_[i] != 0) |
---|
| 358 | inputSystem_->destroyInputObject(joySticks_[i]); |
---|
| 359 | |
---|
| 360 | joySticks_.clear(); |
---|
[1293] | 361 | joySticksSize_ = 0; |
---|
[1219] | 362 | activeJoyStickHandlers_.clear(); |
---|
| 363 | joyStickButtonsDown_.clear(); |
---|
| 364 | } |
---|
| 365 | CCOUT(ORX_DEBUG) << "Joy sticks destroyed." << std::endl; |
---|
| 366 | } |
---|
| 367 | |
---|
[1349] | 368 | void InputManager::_updateTickables() |
---|
| 369 | { |
---|
[1413] | 370 | // we can use a map to have a list of unique pointers (an object can implement all 3 handlers) |
---|
| 371 | std::map<InputTickable*, HandlerState> tempSet; |
---|
[1349] | 372 | for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++) |
---|
[1413] | 373 | tempSet[activeKeyHandlers_[iHandler]].joyStick = true; |
---|
[1349] | 374 | for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++) |
---|
[1413] | 375 | tempSet[activeMouseHandlers_[iHandler]].mouse = true; |
---|
[1349] | 376 | for (unsigned int iJoyStick = 0; iJoyStick < joySticksSize_; iJoyStick++) |
---|
| 377 | for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) |
---|
[1413] | 378 | tempSet[activeJoyStickHandlers_[iJoyStick][iHandler]].joyStick = true; |
---|
[1219] | 379 | |
---|
[1413] | 380 | // copy the content of the map back to the actual vector |
---|
[1349] | 381 | activeHandlers_.clear(); |
---|
[1413] | 382 | for (std::map<InputTickable*, HandlerState>::const_iterator itHandler = tempSet.begin(); |
---|
| 383 | itHandler != tempSet.end(); itHandler++) |
---|
| 384 | activeHandlers_.push_back(std::pair<InputTickable*, HandlerState>((*itHandler).first, (*itHandler).second)); |
---|
[1349] | 385 | } |
---|
| 386 | |
---|
| 387 | |
---|
[1219] | 388 | // ################################# |
---|
| 389 | // ### Private Interface Methods ### |
---|
| 390 | // ################################# |
---|
| 391 | // ################################# |
---|
| 392 | |
---|
| 393 | /** |
---|
| 394 | @brief Updates the InputManager. Tick is called by Orxonox. |
---|
[919] | 395 | @param dt Delta time |
---|
| 396 | */ |
---|
[973] | 397 | void InputManager::tick(float dt) |
---|
[918] | 398 | { |
---|
[1219] | 399 | if (state_ == IS_UNINIT) |
---|
| 400 | return; |
---|
| 401 | |
---|
[1022] | 402 | // reset the game if it has changed |
---|
[1219] | 403 | if (state_ != stateRequest_) |
---|
[1022] | 404 | { |
---|
[1219] | 405 | if (stateRequest_ != IS_CUSTOM) |
---|
[1022] | 406 | { |
---|
[1219] | 407 | activeKeyHandlers_.clear(); |
---|
| 408 | activeMouseHandlers_.clear(); |
---|
[1293] | 409 | for (unsigned int i = 0; i < joySticksSize_; i++) |
---|
| 410 | activeJoyStickHandlers_[i].clear(); |
---|
[1219] | 411 | |
---|
| 412 | switch (stateRequest_) |
---|
| 413 | { |
---|
| 414 | case IS_NORMAL: |
---|
| 415 | // normal play mode |
---|
| 416 | // note: we assume that the handlers exist since otherwise, something's wrong anyway. |
---|
[1349] | 417 | enableKeyHandler("keybinder"); |
---|
| 418 | enableMouseHandler("keybinder"); |
---|
| 419 | enableJoyStickHandler("keybinder", 0); |
---|
[1219] | 420 | break; |
---|
| 421 | |
---|
| 422 | case IS_GUI: |
---|
[1349] | 423 | // TODO: do stuff |
---|
[1219] | 424 | break; |
---|
| 425 | |
---|
| 426 | case IS_CONSOLE: |
---|
[1349] | 427 | enableMouseHandler("keybinder"); |
---|
| 428 | enableJoyStickHandler("keybinder", 0); |
---|
| 429 | enableKeyHandler("buffer"); |
---|
[1219] | 430 | break; |
---|
| 431 | |
---|
[1413] | 432 | case IS_DETECTION: |
---|
| 433 | if (mouse_) |
---|
| 434 | mouse_->capture(); |
---|
| 435 | if (keyboard_) |
---|
| 436 | keyboard_->capture(); |
---|
| 437 | for (unsigned int i = 0; i < joySticksSize_; i++) |
---|
| 438 | joySticks_[i]->capture(); |
---|
| 439 | |
---|
| 440 | lastStroke_ = ""; |
---|
| 441 | enableKeyHandler("keydetector"); |
---|
| 442 | enableMouseHandler("keydetector"); |
---|
| 443 | enableJoyStickHandler("keydetector", 0); |
---|
| 444 | break; |
---|
| 445 | |
---|
[1219] | 446 | default: |
---|
| 447 | break; |
---|
| 448 | } |
---|
| 449 | state_ = stateRequest_; |
---|
| 450 | } |
---|
| 451 | } |
---|
| 452 | |
---|
| 453 | // Capture all the input. This calls the event handlers in InputManager. |
---|
| 454 | if (mouse_) |
---|
| 455 | mouse_->capture(); |
---|
| 456 | if (keyboard_) |
---|
| 457 | keyboard_->capture(); |
---|
[1293] | 458 | for (unsigned int i = 0; i < joySticksSize_; i++) |
---|
| 459 | joySticks_[i]->capture(); |
---|
[1219] | 460 | |
---|
| 461 | |
---|
| 462 | // call all the handlers for the held key events |
---|
[1293] | 463 | for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++) |
---|
| 464 | for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++) |
---|
| 465 | activeKeyHandlers_[iHandler]->keyHeld(KeyEvent(keysDown_[iKey], keyboardModifiers_)); |
---|
[1219] | 466 | |
---|
| 467 | // call all the handlers for the held mouse button events |
---|
[1293] | 468 | for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++) |
---|
| 469 | for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++) |
---|
[1349] | 470 | activeMouseHandlers_[iHandler]->mouseButtonHeld(mouseButtonsDown_[iButton]); |
---|
[1219] | 471 | |
---|
| 472 | // call all the handlers for the held joy stick button events |
---|
[1293] | 473 | for (unsigned int iJoyStick = 0; iJoyStick < joySticksSize_; iJoyStick++) |
---|
| 474 | for (unsigned int iButton = 0; iButton < joyStickButtonsDown_[iJoyStick].size(); iButton++) |
---|
| 475 | for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) |
---|
[1349] | 476 | activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonHeld(iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]); |
---|
| 477 | |
---|
| 478 | |
---|
[1413] | 479 | // call the ticks for the handlers (need to be treated specially) |
---|
[1349] | 480 | for (unsigned int iHandler = 0; iHandler < activeHandlers_.size(); iHandler++) |
---|
[1413] | 481 | activeHandlers_[iHandler].first->tickInput(dt, activeHandlers_[iHandler].second); |
---|
| 482 | |
---|
| 483 | /*for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++) |
---|
| 484 | activeKeyHandlers_[iHandler]->tickKey(dt); |
---|
| 485 | for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++) |
---|
| 486 | activeMouseHandlers_[iHandler]->tickMouse(dt); |
---|
| 487 | for (unsigned int iJoyStick = 0; iJoyStick < joySticksSize_; iJoyStick++) |
---|
| 488 | for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) |
---|
| 489 | activeJoyStickHandlers_[iJoyStick][iHandler]->tickJoyStick(dt);*/ |
---|
[1219] | 490 | } |
---|
| 491 | |
---|
| 492 | // ###### Key Events ###### |
---|
| 493 | |
---|
| 494 | /** |
---|
| 495 | @brief Event handler for the keyPressed Event. |
---|
| 496 | @param e Event information |
---|
| 497 | */ |
---|
| 498 | bool InputManager::keyPressed(const OIS::KeyEvent &e) |
---|
| 499 | { |
---|
| 500 | // check whether the key already is in the list (can happen when focus was lost) |
---|
[1293] | 501 | unsigned int iKey = 0; |
---|
| 502 | while (iKey < keysDown_.size() && keysDown_[iKey].key != (KeyCode::Enum)e.key) |
---|
| 503 | iKey++; |
---|
| 504 | if (iKey == keysDown_.size()) |
---|
| 505 | keysDown_.push_back(Key(e)); |
---|
[1219] | 506 | |
---|
[1293] | 507 | // update modifiers |
---|
| 508 | if(e.key == OIS::KC_RMENU || e.key == OIS::KC_LMENU) |
---|
| 509 | keyboardModifiers_ |= KeyboardModifier::Alt; // alt key |
---|
| 510 | if(e.key == OIS::KC_RCONTROL || e.key == OIS::KC_LCONTROL) |
---|
| 511 | keyboardModifiers_ |= KeyboardModifier::Ctrl; // ctrl key |
---|
| 512 | if(e.key == OIS::KC_RSHIFT || e.key == OIS::KC_LSHIFT) |
---|
| 513 | keyboardModifiers_ |= KeyboardModifier::Shift; // shift key |
---|
| 514 | |
---|
[1219] | 515 | for (unsigned int i = 0; i < activeKeyHandlers_.size(); i++) |
---|
[1293] | 516 | activeKeyHandlers_[i]->keyPressed(KeyEvent(e, keyboardModifiers_)); |
---|
[1219] | 517 | |
---|
| 518 | return true; |
---|
| 519 | } |
---|
| 520 | |
---|
| 521 | /** |
---|
| 522 | @brief Event handler for the keyReleased Event. |
---|
| 523 | @param e Event information |
---|
| 524 | */ |
---|
| 525 | bool InputManager::keyReleased(const OIS::KeyEvent &e) |
---|
| 526 | { |
---|
| 527 | // remove the key from the keysDown_ list |
---|
[1293] | 528 | for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++) |
---|
[1219] | 529 | { |
---|
[1293] | 530 | if (keysDown_[iKey].key == (KeyCode::Enum)e.key) |
---|
[1219] | 531 | { |
---|
[1293] | 532 | keysDown_.erase(keysDown_.begin() + iKey); |
---|
[1022] | 533 | break; |
---|
[1219] | 534 | } |
---|
| 535 | } |
---|
| 536 | |
---|
[1293] | 537 | // update modifiers |
---|
| 538 | if(e.key == OIS::KC_RMENU || e.key == OIS::KC_LMENU) |
---|
| 539 | keyboardModifiers_ &= ~KeyboardModifier::Alt; // alt key |
---|
| 540 | if(e.key == OIS::KC_RCONTROL || e.key == OIS::KC_LCONTROL) |
---|
| 541 | keyboardModifiers_ &= ~KeyboardModifier::Ctrl; // ctrl key |
---|
| 542 | if(e.key == OIS::KC_RSHIFT || e.key == OIS::KC_LSHIFT) |
---|
| 543 | keyboardModifiers_ &= ~KeyboardModifier::Shift; // shift key |
---|
| 544 | |
---|
[1219] | 545 | for (unsigned int i = 0; i < activeKeyHandlers_.size(); i++) |
---|
[1293] | 546 | activeKeyHandlers_[i]->keyReleased(KeyEvent(e, keyboardModifiers_)); |
---|
[1219] | 547 | |
---|
| 548 | return true; |
---|
| 549 | } |
---|
| 550 | |
---|
| 551 | |
---|
| 552 | // ###### Mouse Events ###### |
---|
| 553 | |
---|
| 554 | /** |
---|
| 555 | @brief Event handler for the mouseMoved Event. |
---|
| 556 | @param e Event information |
---|
| 557 | */ |
---|
| 558 | bool InputManager::mouseMoved(const OIS::MouseEvent &e) |
---|
| 559 | { |
---|
[1293] | 560 | // check for actual moved event |
---|
| 561 | if (e.state.X.rel != 0 || e.state.Y.rel != 0) |
---|
| 562 | { |
---|
| 563 | for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) |
---|
[1349] | 564 | activeMouseHandlers_[i]->mouseMoved(IntVector2(e.state.X.abs, e.state.Y.abs), |
---|
| 565 | IntVector2(e.state.X.rel, e.state.Y.rel), IntVector2(e.state.width, e.state.height)); |
---|
[1293] | 566 | } |
---|
[1219] | 567 | |
---|
[1293] | 568 | // check for mouse scrolled event |
---|
| 569 | if (e.state.Z.rel != 0) |
---|
| 570 | { |
---|
| 571 | for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) |
---|
[1349] | 572 | activeMouseHandlers_[i]->mouseScrolled(e.state.Z.abs, e.state.Z.rel); |
---|
[1293] | 573 | } |
---|
| 574 | |
---|
[1219] | 575 | return true; |
---|
| 576 | } |
---|
| 577 | |
---|
| 578 | /** |
---|
| 579 | @brief Event handler for the mousePressed Event. |
---|
| 580 | @param e Event information |
---|
| 581 | @param id The ID of the mouse button |
---|
| 582 | */ |
---|
| 583 | bool InputManager::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id) |
---|
| 584 | { |
---|
| 585 | // check whether the button already is in the list (can happen when focus was lost) |
---|
[1293] | 586 | unsigned int iButton = 0; |
---|
| 587 | while (iButton < mouseButtonsDown_.size() && mouseButtonsDown_[iButton] != (MouseButton::Enum)id) |
---|
| 588 | iButton++; |
---|
| 589 | if (iButton == mouseButtonsDown_.size()) |
---|
| 590 | mouseButtonsDown_.push_back((MouseButton::Enum)id); |
---|
[1219] | 591 | |
---|
| 592 | for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) |
---|
[1349] | 593 | activeMouseHandlers_[i]->mouseButtonPressed((MouseButton::Enum)id); |
---|
[1219] | 594 | |
---|
| 595 | return true; |
---|
| 596 | } |
---|
| 597 | |
---|
| 598 | /** |
---|
| 599 | @brief Event handler for the mouseReleased Event. |
---|
| 600 | @param e Event information |
---|
| 601 | @param id The ID of the mouse button |
---|
| 602 | */ |
---|
| 603 | bool InputManager::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id) |
---|
| 604 | { |
---|
| 605 | // remove the button from the keysDown_ list |
---|
[1293] | 606 | for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++) |
---|
[1219] | 607 | { |
---|
[1293] | 608 | if (mouseButtonsDown_[iButton] == (MouseButton::Enum)id) |
---|
[1219] | 609 | { |
---|
[1293] | 610 | mouseButtonsDown_.erase(mouseButtonsDown_.begin() + iButton); |
---|
[1022] | 611 | break; |
---|
| 612 | } |
---|
| 613 | } |
---|
| 614 | |
---|
[1219] | 615 | for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) |
---|
[1349] | 616 | activeMouseHandlers_[i]->mouseButtonReleased((MouseButton::Enum)id); |
---|
[918] | 617 | |
---|
[1219] | 618 | return true; |
---|
[918] | 619 | } |
---|
| 620 | |
---|
[1219] | 621 | |
---|
| 622 | // ###### Joy Stick Events ###### |
---|
| 623 | |
---|
[1413] | 624 | bool InputManager::buttonPressed(const OIS::JoyStickEvent &arg, int button) |
---|
| 625 | { |
---|
| 626 | // use the device to identify which one called the method |
---|
| 627 | OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; |
---|
[1293] | 628 | unsigned int iJoyStick = 0; |
---|
| 629 | while (joySticks_[iJoyStick] != joyStick) |
---|
| 630 | iJoyStick++; |
---|
[1413] | 631 | |
---|
[1219] | 632 | // check whether the button already is in the list (can happen when focus was lost) |
---|
[1391] | 633 | std::vector<int>& buttonsDown = joyStickButtonsDown_[iJoyStick]; |
---|
[1293] | 634 | unsigned int iButton = 0; |
---|
| 635 | while (iButton < buttonsDown.size() && buttonsDown[iButton] != button) |
---|
| 636 | iButton++; |
---|
| 637 | if (iButton == buttonsDown.size()) |
---|
| 638 | buttonsDown.push_back(button); |
---|
[1219] | 639 | |
---|
[1293] | 640 | for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) |
---|
[1349] | 641 | activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonPressed(iJoyStick, button); |
---|
[1219] | 642 | |
---|
| 643 | return true; |
---|
[1413] | 644 | } |
---|
| 645 | |
---|
| 646 | bool InputManager::buttonReleased(const OIS::JoyStickEvent &arg, int button) |
---|
| 647 | { |
---|
| 648 | // use the device to identify which one called the method |
---|
| 649 | OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; |
---|
[1293] | 650 | unsigned int iJoyStick = 0; |
---|
| 651 | while (joySticks_[iJoyStick] != joyStick) |
---|
| 652 | iJoyStick++; |
---|
[1413] | 653 | |
---|
[1219] | 654 | // remove the button from the joyStickButtonsDown_ list |
---|
[1391] | 655 | std::vector<int>& buttonsDown = joyStickButtonsDown_[iJoyStick]; |
---|
[1293] | 656 | for (unsigned int iButton = 0; iButton < buttonsDown.size(); iButton++) |
---|
[1219] | 657 | { |
---|
[1293] | 658 | if (buttonsDown[iButton] == button) |
---|
[1219] | 659 | { |
---|
[1293] | 660 | buttonsDown.erase(buttonsDown.begin() + iButton); |
---|
[1219] | 661 | break; |
---|
| 662 | } |
---|
| 663 | } |
---|
| 664 | |
---|
[1293] | 665 | for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) |
---|
[1349] | 666 | activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonReleased(iJoyStick, button); |
---|
[1219] | 667 | |
---|
| 668 | return true; |
---|
[1413] | 669 | } |
---|
| 670 | |
---|
| 671 | bool InputManager::axisMoved(const OIS::JoyStickEvent &arg, int axis) |
---|
| 672 | { |
---|
| 673 | //if (arg.state.mAxes[axis].abs > 10000 || arg.state.mAxes[axis].abs < -10000) |
---|
| 674 | //{ CCOUT(3) << "axis " << axis << " moved" << arg.state.mAxes[axis].abs << std::endl;} |
---|
| 675 | // use the device to identify which one called the method |
---|
| 676 | OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; |
---|
[1293] | 677 | unsigned int iJoyStick = 0; |
---|
| 678 | while (joySticks_[iJoyStick] != joyStick) |
---|
| 679 | iJoyStick++; |
---|
[1219] | 680 | |
---|
[1349] | 681 | // keep in mind that the first 8 axes are reserved for the sliders |
---|
[1293] | 682 | for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) |
---|
[1349] | 683 | activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, axis + 8, arg.state.mAxes[axis].abs); |
---|
[1293] | 684 | |
---|
[1413] | 685 | return true; |
---|
| 686 | } |
---|
| 687 | |
---|
| 688 | bool InputManager::sliderMoved(const OIS::JoyStickEvent &arg, int id) |
---|
| 689 | { |
---|
| 690 | //if (arg.state.mSliders[id].abX > 10000 || arg.state.mSliders[id].abX < -10000) |
---|
| 691 | //{CCOUT(3) << "slider " << id << " moved" << arg.state.mSliders[id].abX << std::endl;} |
---|
| 692 | //CCOUT(3) << arg.state.mSliders[id].abX << "\t |" << arg.state.mSliders[id].abY << std::endl; |
---|
| 693 | // use the device to identify which one called the method |
---|
| 694 | OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; |
---|
[1293] | 695 | unsigned int iJoyStick = 0; |
---|
| 696 | while (joySticks_[iJoyStick] != joyStick) |
---|
| 697 | iJoyStick++; |
---|
| 698 | |
---|
[1349] | 699 | if (sliderStates_[iJoyStick].sliderStates[id].x != arg.state.mSliders[id].abX) |
---|
| 700 | { |
---|
| 701 | // slider X axis changed |
---|
| 702 | sliderStates_[iJoyStick].sliderStates[id].x = arg.state.mSliders[id].abX; |
---|
| 703 | for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) |
---|
| 704 | activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, id * 2, arg.state.mSliders[id].abX); |
---|
| 705 | } |
---|
| 706 | else if (sliderStates_[iJoyStick].sliderStates[id].y != arg.state.mSliders[id].abY) |
---|
| 707 | { |
---|
| 708 | // slider Y axis changed |
---|
| 709 | sliderStates_[iJoyStick].sliderStates[id].y = arg.state.mSliders[id].abY; |
---|
| 710 | for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) |
---|
| 711 | activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, id * 2 + 1, arg.state.mSliders[id].abY); |
---|
| 712 | } |
---|
[1413] | 713 | |
---|
| 714 | return true; |
---|
| 715 | } |
---|
| 716 | |
---|
| 717 | bool InputManager::povMoved(const OIS::JoyStickEvent &arg, int id) |
---|
| 718 | { |
---|
| 719 | // use the device to identify which one called the method |
---|
| 720 | OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; |
---|
[1293] | 721 | unsigned int iJoyStick = 0; |
---|
| 722 | while (joySticks_[iJoyStick] != joyStick) |
---|
| 723 | iJoyStick++; |
---|
| 724 | |
---|
[1349] | 725 | // translate the POV into 8 simple buttons |
---|
| 726 | int lastState = povStates_[iJoyStick][id]; |
---|
| 727 | if (lastState & OIS::Pov::North) |
---|
| 728 | buttonReleased(arg, 32 + id * 4 + 0); |
---|
| 729 | if (lastState & OIS::Pov::South) |
---|
| 730 | buttonReleased(arg, 32 + id * 4 + 1); |
---|
| 731 | if (lastState & OIS::Pov::East) |
---|
| 732 | buttonReleased(arg, 32 + id * 4 + 2); |
---|
| 733 | if (lastState & OIS::Pov::West) |
---|
| 734 | buttonReleased(arg, 32 + id * 4 + 3); |
---|
| 735 | |
---|
| 736 | povStates_[iJoyStick].povStates[id] = arg.state.mPOV[id].direction; |
---|
| 737 | int currentState = povStates_[iJoyStick][id]; |
---|
| 738 | if (currentState & OIS::Pov::North) |
---|
| 739 | buttonPressed(arg, 32 + id * 4 + 0); |
---|
| 740 | if (currentState & OIS::Pov::South) |
---|
| 741 | buttonPressed(arg, 32 + id * 4 + 1); |
---|
| 742 | if (currentState & OIS::Pov::East) |
---|
| 743 | buttonPressed(arg, 32 + id * 4 + 2); |
---|
| 744 | if (currentState & OIS::Pov::West) |
---|
| 745 | buttonPressed(arg, 32 + id * 4 + 3); |
---|
[1219] | 746 | |
---|
[1413] | 747 | return true; |
---|
| 748 | } |
---|
| 749 | |
---|
| 750 | /*bool InputManager::vector3Moved(const OIS::JoyStickEvent &arg, int id) |
---|
| 751 | { |
---|
| 752 | // use the device to identify which one called the method |
---|
| 753 | OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; |
---|
[1293] | 754 | unsigned int iJoyStick = 0; |
---|
| 755 | while (joySticks_[iJoyStick] != joyStick) |
---|
| 756 | iJoyStick++; |
---|
| 757 | |
---|
| 758 | for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) |
---|
| 759 | activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickVector3Moved(JoyStickState(arg.state, iJoyStick), id); |
---|
[1219] | 760 | |
---|
[1413] | 761 | return true; |
---|
| 762 | }*/ |
---|
[1219] | 763 | |
---|
[1413] | 764 | |
---|
[1219] | 765 | // ################################ |
---|
| 766 | // ### Static Interface Methods ### |
---|
| 767 | // ################################ |
---|
| 768 | // ################################ |
---|
| 769 | |
---|
[1293] | 770 | bool InputManager::initialise(const size_t windowHnd, int windowWidth, int windowHeight, |
---|
| 771 | bool createKeyboard, bool createMouse, bool createJoySticks) |
---|
[1219] | 772 | { |
---|
| 773 | return _getSingleton()._initialise(windowHnd, windowWidth, windowHeight, |
---|
| 774 | createKeyboard, createMouse, createJoySticks); |
---|
| 775 | } |
---|
| 776 | |
---|
| 777 | bool InputManager::initialiseKeyboard() |
---|
| 778 | { |
---|
| 779 | return _getSingleton()._initialiseKeyboard(); |
---|
| 780 | } |
---|
| 781 | |
---|
| 782 | bool InputManager::initialiseMouse() |
---|
| 783 | { |
---|
| 784 | return _getSingleton()._initialiseMouse(); |
---|
| 785 | } |
---|
| 786 | |
---|
| 787 | bool InputManager::initialiseJoySticks() |
---|
| 788 | { |
---|
| 789 | return _getSingleton()._initialiseJoySticks(); |
---|
| 790 | } |
---|
| 791 | |
---|
| 792 | int InputManager::numberOfKeyboards() |
---|
| 793 | { |
---|
| 794 | if (_getSingleton().keyboard_ != 0) |
---|
| 795 | return 1; |
---|
| 796 | else |
---|
| 797 | return 0; |
---|
| 798 | } |
---|
| 799 | |
---|
| 800 | int InputManager::numberOfMice() |
---|
| 801 | { |
---|
| 802 | if (_getSingleton().mouse_ != 0) |
---|
| 803 | return 1; |
---|
| 804 | else |
---|
| 805 | return 0; |
---|
| 806 | } |
---|
| 807 | |
---|
| 808 | int InputManager::numberOfJoySticks() |
---|
| 809 | { |
---|
[1293] | 810 | return _getSingleton().joySticksSize_; |
---|
[1219] | 811 | } |
---|
| 812 | |
---|
[1413] | 813 | /*bool InputManager::isKeyDown(KeyCode::Enum key) |
---|
[1293] | 814 | { |
---|
| 815 | if (_getSingleton().keyboard_) |
---|
| 816 | return _getSingleton().keyboard_->isKeyDown((OIS::KeyCode)key); |
---|
| 817 | else |
---|
| 818 | return false; |
---|
[1413] | 819 | }*/ |
---|
[1219] | 820 | |
---|
[1413] | 821 | /*bool InputManager::isModifierDown(KeyboardModifier::Enum modifier) |
---|
[1293] | 822 | { |
---|
| 823 | if (_getSingleton().keyboard_) |
---|
| 824 | return isModifierDown(modifier); |
---|
| 825 | else |
---|
| 826 | return false; |
---|
[1413] | 827 | }*/ |
---|
[1293] | 828 | |
---|
[1349] | 829 | /*const MouseState InputManager::getMouseState() |
---|
[1293] | 830 | { |
---|
| 831 | if (_getSingleton().mouse_) |
---|
| 832 | return _getSingleton().mouse_->getMouseState(); |
---|
| 833 | else |
---|
| 834 | return MouseState(); |
---|
[1349] | 835 | }*/ |
---|
[1293] | 836 | |
---|
[1349] | 837 | /*const JoyStickState InputManager::getJoyStickState(unsigned int ID) |
---|
[1293] | 838 | { |
---|
| 839 | if (ID < _getSingleton().joySticksSize_) |
---|
| 840 | return JoyStickState(_getSingleton().joySticks_[ID]->getJoyStickState(), ID); |
---|
| 841 | else |
---|
| 842 | return JoyStickState(); |
---|
[1349] | 843 | }*/ |
---|
[1293] | 844 | |
---|
[1219] | 845 | void InputManager::destroy() |
---|
| 846 | { |
---|
| 847 | _getSingleton()._destroy(); |
---|
| 848 | } |
---|
| 849 | |
---|
| 850 | void InputManager::destroyKeyboard() |
---|
| 851 | { |
---|
| 852 | return _getSingleton()._destroyKeyboard(); |
---|
| 853 | } |
---|
| 854 | |
---|
| 855 | void InputManager::destroyMouse() |
---|
| 856 | { |
---|
| 857 | return _getSingleton()._destroyMouse(); |
---|
| 858 | } |
---|
| 859 | |
---|
| 860 | void InputManager::destroyJoySticks() |
---|
| 861 | { |
---|
| 862 | return _getSingleton()._destroyJoySticks(); |
---|
| 863 | } |
---|
| 864 | |
---|
| 865 | |
---|
[919] | 866 | /** |
---|
| 867 | @brief Adjusts the mouse window metrics. |
---|
| 868 | This method has to be called every time the size of the window changes. |
---|
| 869 | @param width The new width of the render window |
---|
| 870 | @param height the new height of the render window |
---|
| 871 | */ |
---|
[1219] | 872 | void InputManager::setWindowExtents(const int width, const int height) |
---|
[918] | 873 | { |
---|
[1219] | 874 | if (_getSingleton().mouse_) |
---|
| 875 | { |
---|
| 876 | // Set mouse region (if window resizes, we should alter this to reflect as well) |
---|
| 877 | const OIS::MouseState &mouseState = _getSingleton().mouse_->getMouseState(); |
---|
| 878 | mouseState.width = width; |
---|
| 879 | mouseState.height = height; |
---|
| 880 | } |
---|
[918] | 881 | } |
---|
| 882 | |
---|
[919] | 883 | /** |
---|
[1022] | 884 | @brief Sets the input mode to either GUI, inGame or Buffer |
---|
| 885 | @param mode The new input mode |
---|
| 886 | @remark Only has an affect if the mode actually changes |
---|
[922] | 887 | */ |
---|
[1219] | 888 | void InputManager::setInputState(const InputState state) |
---|
[922] | 889 | { |
---|
[1219] | 890 | _getSingleton().stateRequest_ = state; |
---|
[922] | 891 | } |
---|
| 892 | |
---|
| 893 | /** |
---|
[1022] | 894 | @brief Returns the current input handling method |
---|
| 895 | @return The current input mode. |
---|
[919] | 896 | */ |
---|
[1219] | 897 | InputManager::InputState InputManager::getInputState() |
---|
[918] | 898 | { |
---|
[1219] | 899 | return _getSingleton().state_; |
---|
[918] | 900 | } |
---|
| 901 | |
---|
[1413] | 902 | void InputManager::storeKeyStroke(const std::string& name) |
---|
| 903 | { |
---|
| 904 | if (_getSingleton().lastStroke_ == "") |
---|
| 905 | _getSingleton().lastStroke_ = name; |
---|
| 906 | } |
---|
[1219] | 907 | |
---|
[1413] | 908 | const std::string& InputManager::getLastKeyStroke() |
---|
| 909 | { |
---|
| 910 | return _getSingleton().lastStroke_; |
---|
| 911 | } |
---|
| 912 | |
---|
| 913 | |
---|
[1219] | 914 | // ###### KeyHandler ###### |
---|
| 915 | |
---|
| 916 | /** |
---|
| 917 | @brief Adds a new key handler. |
---|
| 918 | @param handler Pointer to the handler object. |
---|
| 919 | @param name Unique name of the handler. |
---|
| 920 | @return True if added, false if name already existed. |
---|
| 921 | */ |
---|
| 922 | bool InputManager::addKeyHandler(KeyHandler* handler, const std::string& name) |
---|
[1066] | 923 | { |
---|
[1293] | 924 | if (!handler) |
---|
| 925 | return false; |
---|
[1219] | 926 | if (_getSingleton().keyHandlers_.find(name) == _getSingleton().keyHandlers_.end()) |
---|
| 927 | { |
---|
| 928 | _getSingleton().keyHandlers_[name] = handler; |
---|
| 929 | return true; |
---|
| 930 | } |
---|
| 931 | else |
---|
| 932 | return false; |
---|
[1066] | 933 | } |
---|
| 934 | |
---|
[1219] | 935 | /** |
---|
| 936 | @brief Removes a Key handler from the list. |
---|
| 937 | @param name Unique name of the handler. |
---|
| 938 | @return True if removal was successful, false if name was not found. |
---|
| 939 | */ |
---|
| 940 | bool InputManager::removeKeyHandler(const std::string &name) |
---|
| 941 | { |
---|
| 942 | disableKeyHandler(name); |
---|
| 943 | std::map<std::string, KeyHandler*>::iterator it = _getSingleton().keyHandlers_.find(name); |
---|
| 944 | if (it != _getSingleton().keyHandlers_.end()) |
---|
| 945 | { |
---|
| 946 | _getSingleton().keyHandlers_.erase(it); |
---|
| 947 | return true; |
---|
| 948 | } |
---|
| 949 | else |
---|
| 950 | return false; |
---|
| 951 | } |
---|
[1066] | 952 | |
---|
[1219] | 953 | /** |
---|
| 954 | @brief Returns the pointer to a handler. |
---|
| 955 | @param name Unique name of the handler. |
---|
| 956 | @return Pointer to the instance, 0 if name was not found. |
---|
| 957 | */ |
---|
| 958 | KeyHandler* InputManager::getKeyHandler(const std::string& name) |
---|
| 959 | { |
---|
| 960 | std::map<std::string, KeyHandler*>::iterator it = _getSingleton().keyHandlers_.find(name); |
---|
| 961 | if (it != _getSingleton().keyHandlers_.end()) |
---|
| 962 | { |
---|
| 963 | return (*it).second; |
---|
| 964 | } |
---|
| 965 | else |
---|
| 966 | return 0; |
---|
| 967 | } |
---|
| 968 | |
---|
| 969 | /** |
---|
| 970 | @brief Enables a specific key handler that has already been added. |
---|
| 971 | @param name Unique name of the handler. |
---|
| 972 | @return False if name was not found, true otherwise. |
---|
| 973 | */ |
---|
| 974 | bool InputManager::enableKeyHandler(const std::string& name) |
---|
| 975 | { |
---|
| 976 | // get pointer from the map with all stored handlers |
---|
| 977 | std::map<std::string, KeyHandler*>::const_iterator mapIt = _getSingleton().keyHandlers_.find(name); |
---|
| 978 | if (mapIt == _getSingleton().keyHandlers_.end()) |
---|
| 979 | return false; |
---|
| 980 | // see whether the handler already is in the list |
---|
| 981 | for (std::vector<KeyHandler*>::iterator it = _getSingleton().activeKeyHandlers_.begin(); |
---|
| 982 | it != _getSingleton().activeKeyHandlers_.end(); it++) |
---|
| 983 | { |
---|
| 984 | if ((*it) == (*mapIt).second) |
---|
| 985 | { |
---|
| 986 | return true; |
---|
| 987 | } |
---|
| 988 | } |
---|
| 989 | _getSingleton().activeKeyHandlers_.push_back((*mapIt).second); |
---|
| 990 | _getSingleton().stateRequest_ = IS_CUSTOM; |
---|
[1349] | 991 | _getSingleton()._updateTickables(); |
---|
[1219] | 992 | return true; |
---|
| 993 | } |
---|
| 994 | |
---|
| 995 | /** |
---|
| 996 | @brief Disables a specific key handler. |
---|
| 997 | @param name Unique name of the handler. |
---|
| 998 | @return False if name was not found, true otherwise. |
---|
| 999 | */ |
---|
| 1000 | bool InputManager::disableKeyHandler(const std::string &name) |
---|
| 1001 | { |
---|
| 1002 | // get pointer from the map with all stored handlers |
---|
| 1003 | std::map<std::string, KeyHandler*>::const_iterator mapIt = _getSingleton().keyHandlers_.find(name); |
---|
| 1004 | if (mapIt == _getSingleton().keyHandlers_.end()) |
---|
| 1005 | return false; |
---|
| 1006 | // look for the handler in the list |
---|
| 1007 | for (std::vector<KeyHandler*>::iterator it = _getSingleton().activeKeyHandlers_.begin(); |
---|
| 1008 | it != _getSingleton().activeKeyHandlers_.end(); it++) |
---|
| 1009 | { |
---|
| 1010 | if ((*it) == (*mapIt).second) |
---|
| 1011 | { |
---|
| 1012 | _getSingleton().activeKeyHandlers_.erase(it); |
---|
| 1013 | _getSingleton().stateRequest_ = IS_CUSTOM; |
---|
[1349] | 1014 | _getSingleton()._updateTickables(); |
---|
[1219] | 1015 | return true; |
---|
| 1016 | } |
---|
| 1017 | } |
---|
| 1018 | return true; |
---|
| 1019 | } |
---|
| 1020 | |
---|
| 1021 | /** |
---|
| 1022 | @brief Checks whether a key handler is active |
---|
| 1023 | @param name Unique name of the handler. |
---|
| 1024 | @return False if key handler is not active or doesn't exist, true otherwise. |
---|
| 1025 | */ |
---|
| 1026 | bool InputManager::isKeyHandlerActive(const std::string& name) |
---|
| 1027 | { |
---|
| 1028 | // get pointer from the map with all stored handlers |
---|
| 1029 | std::map<std::string, KeyHandler*>::const_iterator mapIt = _getSingleton().keyHandlers_.find(name); |
---|
| 1030 | if (mapIt == _getSingleton().keyHandlers_.end()) |
---|
| 1031 | return false; |
---|
| 1032 | // see whether the handler already is in the list |
---|
| 1033 | for (std::vector<KeyHandler*>::iterator it = _getSingleton().activeKeyHandlers_.begin(); |
---|
| 1034 | it != _getSingleton().activeKeyHandlers_.end(); it++) |
---|
| 1035 | { |
---|
| 1036 | if ((*it) == (*mapIt).second) |
---|
| 1037 | return true; |
---|
| 1038 | } |
---|
| 1039 | return false; |
---|
| 1040 | } |
---|
| 1041 | |
---|
| 1042 | |
---|
| 1043 | // ###### MouseHandler ###### |
---|
| 1044 | /** |
---|
| 1045 | @brief Adds a new mouse handler. |
---|
| 1046 | @param handler Pointer to the handler object. |
---|
| 1047 | @param name Unique name of the handler. |
---|
| 1048 | @return True if added, false if name already existed. |
---|
| 1049 | */ |
---|
| 1050 | bool InputManager::addMouseHandler(MouseHandler* handler, const std::string& name) |
---|
| 1051 | { |
---|
[1293] | 1052 | if (!handler) |
---|
| 1053 | return false; |
---|
[1219] | 1054 | if (_getSingleton().mouseHandlers_.find(name) == _getSingleton().mouseHandlers_.end()) |
---|
| 1055 | { |
---|
| 1056 | _getSingleton().mouseHandlers_[name] = handler; |
---|
| 1057 | return true; |
---|
| 1058 | } |
---|
| 1059 | else |
---|
| 1060 | return false; |
---|
| 1061 | } |
---|
| 1062 | |
---|
| 1063 | /** |
---|
| 1064 | @brief Removes a Mouse handler from the list. |
---|
| 1065 | @param name Unique name of the handler. |
---|
| 1066 | @return True if removal was successful, false if name was not found. |
---|
| 1067 | */ |
---|
| 1068 | bool InputManager::removeMouseHandler(const std::string &name) |
---|
| 1069 | { |
---|
| 1070 | disableMouseHandler(name); |
---|
| 1071 | std::map<std::string, MouseHandler*>::iterator it = _getSingleton().mouseHandlers_.find(name); |
---|
| 1072 | if (it != _getSingleton().mouseHandlers_.end()) |
---|
| 1073 | { |
---|
| 1074 | _getSingleton().mouseHandlers_.erase(it); |
---|
| 1075 | return true; |
---|
| 1076 | } |
---|
| 1077 | else |
---|
| 1078 | return false; |
---|
| 1079 | } |
---|
| 1080 | |
---|
| 1081 | /** |
---|
| 1082 | @brief Returns the pointer to a handler. |
---|
| 1083 | @param name Unique name of the handler. |
---|
| 1084 | @return Pointer to the instance, 0 if name was not found. |
---|
| 1085 | */ |
---|
| 1086 | MouseHandler* InputManager::getMouseHandler(const std::string& name) |
---|
| 1087 | { |
---|
| 1088 | std::map<std::string, MouseHandler*>::iterator it = _getSingleton().mouseHandlers_.find(name); |
---|
| 1089 | if (it != _getSingleton().mouseHandlers_.end()) |
---|
| 1090 | { |
---|
| 1091 | return (*it).second; |
---|
| 1092 | } |
---|
| 1093 | else |
---|
| 1094 | return 0; |
---|
| 1095 | } |
---|
| 1096 | |
---|
| 1097 | /** |
---|
| 1098 | @brief Enables a specific mouse handler that has already been added. |
---|
| 1099 | @param name Unique name of the handler. |
---|
| 1100 | @return False if name was not found, true otherwise. |
---|
| 1101 | */ |
---|
| 1102 | bool InputManager::enableMouseHandler(const std::string& name) |
---|
| 1103 | { |
---|
| 1104 | // get pointer from the map with all stored handlers |
---|
| 1105 | std::map<std::string, MouseHandler*>::const_iterator mapIt = _getSingleton().mouseHandlers_.find(name); |
---|
| 1106 | if (mapIt == _getSingleton().mouseHandlers_.end()) |
---|
| 1107 | return false; |
---|
| 1108 | // see whether the handler already is in the list |
---|
| 1109 | for (std::vector<MouseHandler*>::iterator it = _getSingleton().activeMouseHandlers_.begin(); |
---|
| 1110 | it != _getSingleton().activeMouseHandlers_.end(); it++) |
---|
| 1111 | { |
---|
| 1112 | if ((*it) == (*mapIt).second) |
---|
| 1113 | { |
---|
| 1114 | return true; |
---|
| 1115 | } |
---|
| 1116 | } |
---|
| 1117 | _getSingleton().activeMouseHandlers_.push_back((*mapIt).second); |
---|
| 1118 | _getSingleton().stateRequest_ = IS_CUSTOM; |
---|
[1349] | 1119 | _getSingleton()._updateTickables(); |
---|
[1219] | 1120 | return true; |
---|
| 1121 | } |
---|
| 1122 | |
---|
| 1123 | /** |
---|
| 1124 | @brief Disables a specific mouse handler. |
---|
| 1125 | @param name Unique name of the handler. |
---|
| 1126 | @return False if name was not found, true otherwise. |
---|
| 1127 | */ |
---|
| 1128 | bool InputManager::disableMouseHandler(const std::string &name) |
---|
| 1129 | { |
---|
| 1130 | // get pointer from the map with all stored handlers |
---|
| 1131 | std::map<std::string, MouseHandler*>::const_iterator mapIt = _getSingleton().mouseHandlers_.find(name); |
---|
| 1132 | if (mapIt == _getSingleton().mouseHandlers_.end()) |
---|
| 1133 | return false; |
---|
| 1134 | // look for the handler in the list |
---|
| 1135 | for (std::vector<MouseHandler*>::iterator it = _getSingleton().activeMouseHandlers_.begin(); |
---|
| 1136 | it != _getSingleton().activeMouseHandlers_.end(); it++) |
---|
| 1137 | { |
---|
| 1138 | if ((*it) == (*mapIt).second) |
---|
| 1139 | { |
---|
| 1140 | _getSingleton().activeMouseHandlers_.erase(it); |
---|
| 1141 | _getSingleton().stateRequest_ = IS_CUSTOM; |
---|
[1349] | 1142 | _getSingleton()._updateTickables(); |
---|
[1219] | 1143 | return true; |
---|
| 1144 | } |
---|
| 1145 | } |
---|
| 1146 | return true; |
---|
| 1147 | } |
---|
| 1148 | |
---|
| 1149 | /** |
---|
| 1150 | @brief Checks whether a mouse handler is active |
---|
| 1151 | @param name Unique name of the handler. |
---|
| 1152 | @return False if key handler is not active or doesn't exist, true otherwise. |
---|
| 1153 | */ |
---|
| 1154 | bool InputManager::isMouseHandlerActive(const std::string& name) |
---|
| 1155 | { |
---|
| 1156 | // get pointer from the map with all stored handlers |
---|
| 1157 | std::map<std::string, MouseHandler*>::const_iterator mapIt = _getSingleton().mouseHandlers_.find(name); |
---|
| 1158 | if (mapIt == _getSingleton().mouseHandlers_.end()) |
---|
| 1159 | return false; |
---|
| 1160 | // see whether the handler already is in the list |
---|
| 1161 | for (std::vector<MouseHandler*>::iterator it = _getSingleton().activeMouseHandlers_.begin(); |
---|
| 1162 | it != _getSingleton().activeMouseHandlers_.end(); it++) |
---|
| 1163 | { |
---|
| 1164 | if ((*it) == (*mapIt).second) |
---|
| 1165 | return true; |
---|
| 1166 | } |
---|
| 1167 | return false; |
---|
| 1168 | } |
---|
| 1169 | |
---|
| 1170 | |
---|
| 1171 | // ###### JoyStickHandler ###### |
---|
| 1172 | |
---|
| 1173 | /** |
---|
| 1174 | @brief Adds a new joy stick handler. |
---|
| 1175 | @param handler Pointer to the handler object. |
---|
| 1176 | @param name Unique name of the handler. |
---|
| 1177 | @return True if added, false if name already existed. |
---|
| 1178 | */ |
---|
| 1179 | bool InputManager::addJoyStickHandler(JoyStickHandler* handler, const std::string& name) |
---|
| 1180 | { |
---|
[1293] | 1181 | if (!handler) |
---|
| 1182 | return false; |
---|
[1219] | 1183 | if (_getSingleton().joyStickHandlers_.find(name) == _getSingleton().joyStickHandlers_.end()) |
---|
| 1184 | { |
---|
| 1185 | _getSingleton().joyStickHandlers_[name] = handler; |
---|
| 1186 | return true; |
---|
| 1187 | } |
---|
| 1188 | else |
---|
| 1189 | return false; |
---|
| 1190 | } |
---|
| 1191 | |
---|
| 1192 | /** |
---|
| 1193 | @brief Removes a JoyStick handler from the list. |
---|
| 1194 | @param name Unique name of the handler. |
---|
| 1195 | @return True if removal was successful, false if name was not found. |
---|
| 1196 | */ |
---|
| 1197 | bool InputManager::removeJoyStickHandler(const std::string &name) |
---|
| 1198 | { |
---|
| 1199 | for (std::vector<OIS::JoyStick*>::iterator itstick = _getSingleton().joySticks_.begin(); |
---|
| 1200 | itstick != _getSingleton().joySticks_.end(); itstick++) |
---|
| 1201 | disableJoyStickHandler(name, itstick - _getSingleton().joySticks_.begin()); |
---|
| 1202 | |
---|
| 1203 | std::map<std::string, JoyStickHandler*>::iterator it = _getSingleton().joyStickHandlers_.find(name); |
---|
| 1204 | if (it != _getSingleton().joyStickHandlers_.end()) |
---|
| 1205 | { |
---|
| 1206 | _getSingleton().joyStickHandlers_.erase(it); |
---|
| 1207 | return true; |
---|
| 1208 | } |
---|
| 1209 | else |
---|
| 1210 | return false; |
---|
| 1211 | } |
---|
| 1212 | |
---|
| 1213 | /** |
---|
| 1214 | @brief Returns the pointer to a handler. |
---|
| 1215 | @param name Unique name of the handler. |
---|
| 1216 | @return Pointer to the instance, 0 if name was not found. |
---|
| 1217 | */ |
---|
| 1218 | JoyStickHandler* InputManager::getJoyStickHandler(const std::string& name) |
---|
| 1219 | { |
---|
| 1220 | std::map<std::string, JoyStickHandler*>::iterator it = _getSingleton().joyStickHandlers_.find(name); |
---|
| 1221 | if (it != _getSingleton().joyStickHandlers_.end()) |
---|
| 1222 | { |
---|
| 1223 | return (*it).second; |
---|
| 1224 | } |
---|
| 1225 | else |
---|
| 1226 | return 0; |
---|
| 1227 | } |
---|
| 1228 | |
---|
| 1229 | /** |
---|
| 1230 | @brief Enables a specific joy stick handler that has already been added. |
---|
| 1231 | @param name Unique name of the handler. |
---|
| 1232 | @return False if name or id was not found, true otherwise. |
---|
| 1233 | */ |
---|
[1293] | 1234 | bool InputManager::enableJoyStickHandler(const std::string& name, unsigned int ID) |
---|
[1219] | 1235 | { |
---|
| 1236 | // get handler pointer from the map with all stored handlers |
---|
| 1237 | std::map<std::string, JoyStickHandler*>::const_iterator handlerIt = _getSingleton().joyStickHandlers_.find(name); |
---|
| 1238 | if (handlerIt == _getSingleton().joyStickHandlers_.end()) |
---|
| 1239 | return false; |
---|
| 1240 | |
---|
| 1241 | // check for existence of the ID |
---|
[1293] | 1242 | if (ID >= _getSingleton().joySticksSize_) |
---|
[1219] | 1243 | return false; |
---|
| 1244 | |
---|
| 1245 | // see whether the handler already is in the list |
---|
[1293] | 1246 | for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ID].begin(); |
---|
| 1247 | it != _getSingleton().activeJoyStickHandlers_[ID].end(); it++) |
---|
[1219] | 1248 | { |
---|
| 1249 | if ((*it) == (*handlerIt).second) |
---|
| 1250 | { |
---|
| 1251 | return true; |
---|
| 1252 | } |
---|
| 1253 | } |
---|
[1293] | 1254 | _getSingleton().activeJoyStickHandlers_[ID].push_back((*handlerIt).second); |
---|
[1219] | 1255 | _getSingleton().stateRequest_ = IS_CUSTOM; |
---|
[1349] | 1256 | _getSingleton()._updateTickables(); |
---|
[1219] | 1257 | return true; |
---|
| 1258 | } |
---|
| 1259 | |
---|
| 1260 | /** |
---|
| 1261 | @brief Disables a specific joy stick handler. |
---|
| 1262 | @param name Unique name of the handler. |
---|
| 1263 | @return False if name or id was not found, true otherwise. |
---|
| 1264 | */ |
---|
[1293] | 1265 | bool InputManager::disableJoyStickHandler(const std::string &name, unsigned int ID) |
---|
[1219] | 1266 | { |
---|
| 1267 | // get handler pointer from the map with all stored handlers |
---|
| 1268 | std::map<std::string, JoyStickHandler*>::const_iterator handlerIt = _getSingleton().joyStickHandlers_.find(name); |
---|
| 1269 | if (handlerIt == _getSingleton().joyStickHandlers_.end()) |
---|
| 1270 | return false; |
---|
| 1271 | |
---|
| 1272 | // check for existence of the ID |
---|
[1293] | 1273 | if (ID >= _getSingleton().joySticksSize_) |
---|
[1219] | 1274 | return false; |
---|
| 1275 | |
---|
| 1276 | // look for the handler in the list |
---|
[1293] | 1277 | for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ID].begin(); |
---|
| 1278 | it != _getSingleton().activeJoyStickHandlers_[ID].end(); it++) |
---|
[1219] | 1279 | { |
---|
| 1280 | if ((*it) == (*handlerIt).second) |
---|
| 1281 | { |
---|
[1293] | 1282 | _getSingleton().activeJoyStickHandlers_[ID].erase(it); |
---|
[1219] | 1283 | _getSingleton().stateRequest_ = IS_CUSTOM; |
---|
[1349] | 1284 | _getSingleton()._updateTickables(); |
---|
[1219] | 1285 | return true; |
---|
| 1286 | } |
---|
| 1287 | } |
---|
| 1288 | return true; |
---|
| 1289 | } |
---|
| 1290 | |
---|
| 1291 | /** |
---|
| 1292 | @brief Checks whether a joy stick handler is active |
---|
| 1293 | @param name Unique name of the handler. |
---|
| 1294 | @return False if key handler is not active or doesn't exist, true otherwise. |
---|
| 1295 | */ |
---|
[1293] | 1296 | bool InputManager::isJoyStickHandlerActive(const std::string& name, unsigned int ID) |
---|
[1219] | 1297 | { |
---|
| 1298 | // get handler pointer from the map with all stored handlers |
---|
| 1299 | std::map<std::string, JoyStickHandler*>::const_iterator handlerIt = _getSingleton().joyStickHandlers_.find(name); |
---|
| 1300 | if (handlerIt == _getSingleton().joyStickHandlers_.end()) |
---|
| 1301 | return false; |
---|
| 1302 | |
---|
| 1303 | // check for existence of the ID |
---|
[1293] | 1304 | if (ID >= _getSingleton().joySticksSize_) |
---|
[1219] | 1305 | return false; |
---|
| 1306 | |
---|
| 1307 | // see whether the handler already is in the list |
---|
[1293] | 1308 | for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ID].begin(); |
---|
| 1309 | it != _getSingleton().activeJoyStickHandlers_[ID].end(); it++) |
---|
[1219] | 1310 | { |
---|
| 1311 | if ((*it) == (*handlerIt).second) |
---|
| 1312 | return true; |
---|
| 1313 | } |
---|
| 1314 | return false; |
---|
| 1315 | } |
---|
| 1316 | |
---|
[918] | 1317 | } |
---|