Changeset 1293 for code/trunk/src/core/InputManager.cc
- Timestamp:
- May 15, 2008, 5:44:55 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/core/InputManager.cc
r1219 r1293 30 30 @file 31 31 @brief Implementation of the InputManager that captures all the input from OIS 32 and redirects it to handlers if necessary.32 and redirects it to handlers. 33 33 */ 34 34 … … 52 52 InputManager::InputManager() : 53 53 inputSystem_(0), keyboard_(0), mouse_(0), 54 state_(IS_UNINIT), stateRequest_(IS_UNINIT) 54 joySticksSize_(0), 55 state_(IS_UNINIT), stateRequest_(IS_UNINIT), 56 keyboardModifiers_(0) 55 57 { 56 58 RegisterObject(InputManager); 57 58 this->joySticks_.reserve(5);59 //this->activeJoyStickHandlers_.reserve(10);60 this->activeKeyHandlers_.reserve(10);61 this->activeMouseHandlers_.reserve(10);62 59 } 63 60 … … 87 84 @param windowHeight The height of the render window 88 85 */ 89 bool InputManager::_initialise(const size_t windowHnd, const int windowWidth, constint windowHeight,90 const bool createKeyboard, const bool createMouse, constbool createJoySticks)86 bool InputManager::_initialise(const size_t windowHnd, int windowWidth, int windowHeight, 87 bool createKeyboard, bool createMouse, bool createJoySticks) 91 88 { 92 89 if (state_ == IS_UNINIT) 93 90 { 91 CCOUT(3) << "Initialising Input System..." << std::endl; 94 92 CCOUT(ORX_DEBUG) << "Initialising OIS components..." << std::endl; 95 93 … … 145 143 addKeyHandler(binder, "keybinder"); 146 144 addMouseHandler(binder, "keybinder"); 145 addJoyStickHandler(binder, "keybinder"); 147 146 148 147 // Read all the key bindings and assign them … … 234 233 bool InputManager::_initialiseJoySticks() 235 234 { 236 if (joySticks _.size()> 0)235 if (joySticksSize_ > 0) 237 236 { 238 237 CCOUT(2) << "Warning: Joy sticks already initialised, skipping." << std::endl; … … 265 264 return false; 266 265 } 266 joySticksSize_ = joySticks_.size(); 267 activeJoyStickHandlers_.resize(joySticksSize_); 268 joyStickButtonsDown_.resize(joySticksSize_); 267 269 return success; 268 270 } … … 273 275 void InputManager::_destroy() 274 276 { 275 CCOUT(ORX_DEBUG) << "Destroying ..." << std::endl;276 277 277 if (state_ != IS_UNINIT) 278 278 { 279 CCOUT(ORX_DEBUG) << "Destroying ..." << std::endl; 280 279 281 if (keyHandlers_.find("buffer") != keyHandlers_.end()) 280 282 delete keyHandlers_["buffer"]; … … 296 298 297 299 state_ = IS_UNINIT; 298 } 299 else 300 CCOUT(ORX_WARNING) << "Warning: Cannot be destroyed, since not initialised." << std::endl; 301 302 CCOUT(ORX_DEBUG) << "Destroying done." << std::endl; 300 CCOUT(ORX_DEBUG) << "Destroying done." << std::endl; 301 } 303 302 } 304 303 … … 336 335 void InputManager::_destroyJoySticks() 337 336 { 338 if (joySticks _.size()> 0)337 if (joySticksSize_ > 0) 339 338 { 340 339 // note: inputSystem_ can never be 0, or else the code is mistaken 341 for (unsigned int i = 0; i < joySticks _.size(); i++)340 for (unsigned int i = 0; i < joySticksSize_; i++) 342 341 if (joySticks_[i] != 0) 343 342 inputSystem_->destroyInputObject(joySticks_[i]); 344 343 345 344 joySticks_.clear(); 345 joySticksSize_ = 0; 346 346 activeJoyStickHandlers_.clear(); 347 347 joyStickButtonsDown_.clear(); … … 372 372 activeKeyHandlers_.clear(); 373 373 activeMouseHandlers_.clear(); 374 activeJoyStickHandlers_.clear(); 374 for (unsigned int i = 0; i < joySticksSize_; i++) 375 activeJoyStickHandlers_[i].clear(); 375 376 376 377 switch (stateRequest_) … … 381 382 activeKeyHandlers_.push_back(keyHandlers_["keybinder"]); 382 383 activeMouseHandlers_.push_back(mouseHandlers_["keybinder"]); 383 activeMouseHandlers_.push_back(mouseHandlers_["SpaceShip"]);384 for (std::vector<OIS::JoyStick*>::const_iterator it = joySticks_.begin();385 it != joySticks_.end(); it++)386 activeJoyStickHandlers_[ *it].push_back(joyStickHandlers_["keybinder"]);384 if (getMouseHandler("SpaceShip")) 385 activeMouseHandlers_.push_back(mouseHandlers_["SpaceShip"]); 386 for (unsigned int i = 0; i < joySticksSize_; i++) 387 activeJoyStickHandlers_[i].push_back(joyStickHandlers_["keybinder"]); 387 388 break; 388 389 … … 393 394 case IS_CONSOLE: 394 395 activeMouseHandlers_.push_back(mouseHandlers_["keybinder"]); 395 for (std::vector<OIS::JoyStick*>::const_iterator it = joySticks_.begin(); 396 it != joySticks_.end(); it++) 397 activeJoyStickHandlers_[*it].push_back(joyStickHandlers_["keybinder"]); 396 if (getMouseHandler("SpaceShip")) 397 activeMouseHandlers_.push_back(mouseHandlers_["SpaceShip"]); 398 for (unsigned int i = 0; i < joySticksSize_; i++) 399 activeJoyStickHandlers_[i].push_back(joyStickHandlers_["keybinder"]); 398 400 399 401 activeKeyHandlers_.push_back(keyHandlers_["buffer"]); … … 412 414 if (keyboard_) 413 415 keyboard_->capture(); 416 for (unsigned int i = 0; i < joySticksSize_; i++) 417 joySticks_[i]->capture(); 414 418 415 419 416 420 // call all the handlers for the held key events 417 for (std::list<OIS::KeyCode>::const_iterator itKey = keysDown_.begin(); 418 itKey != keysDown_.end(); itKey++) 419 { 420 OIS::KeyEvent keyArg(keyboard_, *itKey, 0); 421 for (unsigned int i = 0; i < activeKeyHandlers_.size(); i++) 422 activeKeyHandlers_[i]->keyHeld(keyArg); 423 } 421 for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++) 422 for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++) 423 activeKeyHandlers_[iHandler]->keyHeld(KeyEvent(keysDown_[iKey], keyboardModifiers_)); 424 424 425 425 // call all the handlers for the held mouse button events 426 for (std::list<OIS::MouseButtonID>::const_iterator itMouseButton = mouseButtonsDown_.begin(); 427 itMouseButton != mouseButtonsDown_.end(); itMouseButton++) 428 { 429 OIS::MouseEvent mouseButtonArg(mouse_, mouse_->getMouseState()); 430 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 431 activeMouseHandlers_[i]->mouseHeld(mouseButtonArg, *itMouseButton); 432 } 426 for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++) 427 for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++) 428 activeMouseHandlers_[iHandler]->mouseButtonHeld(mouse_->getMouseState(), mouseButtonsDown_[iButton]); 433 429 434 430 // call all the handlers for the held joy stick button events 435 for (std::map< OIS::JoyStick*, std::list <int> >::const_iterator itJoyStick = joyStickButtonsDown_.begin(); 436 itJoyStick != joyStickButtonsDown_.end(); itJoyStick++) 437 { 438 OIS::JoyStick* joyStick = (*itJoyStick).first; 439 for (std::list<int>::const_iterator itJoyStickButton = (*itJoyStick).second.begin(); 440 itJoyStickButton != (*itJoyStick).second.end(); itJoyStickButton++) 441 { 442 OIS::JoyStickEvent joyStickButtonArg(joyStick, joyStick->getJoyStickState()); 443 for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++) 444 activeJoyStickHandlers_[joyStick][i]->buttonHeld(i, joyStickButtonArg, *itJoyStickButton); 445 } 446 } 447 } 448 431 for (unsigned int iJoyStick = 0; iJoyStick < joySticksSize_; iJoyStick++) 432 for (unsigned int iButton = 0; iButton < joyStickButtonsDown_[iJoyStick].size(); iButton++) 433 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 434 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonHeld( 435 JoyStickState(joySticks_[iJoyStick]->getJoyStickState(), iJoyStick), joyStickButtonsDown_[iJoyStick][iButton]); 436 } 449 437 450 438 // ###### Key Events ###### … … 457 445 { 458 446 // check whether the key already is in the list (can happen when focus was lost) 459 for (std::list<OIS::KeyCode>::iterator it = keysDown_.begin(); it != keysDown_.end(); it++) 460 { 461 if (*it == e.key) 462 { 463 keysDown_.erase(it); 464 break; 465 } 466 } 467 keysDown_.push_back(e.key); 447 unsigned int iKey = 0; 448 while (iKey < keysDown_.size() && keysDown_[iKey].key != (KeyCode::Enum)e.key) 449 iKey++; 450 if (iKey == keysDown_.size()) 451 keysDown_.push_back(Key(e)); 452 453 // update modifiers 454 if(e.key == OIS::KC_RMENU || e.key == OIS::KC_LMENU) 455 keyboardModifiers_ |= KeyboardModifier::Alt; // alt key 456 if(e.key == OIS::KC_RCONTROL || e.key == OIS::KC_LCONTROL) 457 keyboardModifiers_ |= KeyboardModifier::Ctrl; // ctrl key 458 if(e.key == OIS::KC_RSHIFT || e.key == OIS::KC_LSHIFT) 459 keyboardModifiers_ |= KeyboardModifier::Shift; // shift key 468 460 469 461 for (unsigned int i = 0; i < activeKeyHandlers_.size(); i++) 470 activeKeyHandlers_[i]->keyPressed( e);462 activeKeyHandlers_[i]->keyPressed(KeyEvent(e, keyboardModifiers_)); 471 463 472 464 return true; … … 480 472 { 481 473 // remove the key from the keysDown_ list 482 for ( std::list<OIS::KeyCode>::iterator it = keysDown_.begin(); it != keysDown_.end(); it++)483 { 484 if ( *it ==e.key)485 { 486 keysDown_.erase( it);474 for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++) 475 { 476 if (keysDown_[iKey].key == (KeyCode::Enum)e.key) 477 { 478 keysDown_.erase(keysDown_.begin() + iKey); 487 479 break; 488 480 } 489 481 } 490 482 483 // update modifiers 484 if(e.key == OIS::KC_RMENU || e.key == OIS::KC_LMENU) 485 keyboardModifiers_ &= ~KeyboardModifier::Alt; // alt key 486 if(e.key == OIS::KC_RCONTROL || e.key == OIS::KC_LCONTROL) 487 keyboardModifiers_ &= ~KeyboardModifier::Ctrl; // ctrl key 488 if(e.key == OIS::KC_RSHIFT || e.key == OIS::KC_LSHIFT) 489 keyboardModifiers_ &= ~KeyboardModifier::Shift; // shift key 490 491 491 for (unsigned int i = 0; i < activeKeyHandlers_.size(); i++) 492 activeKeyHandlers_[i]->keyReleased( e);492 activeKeyHandlers_[i]->keyReleased(KeyEvent(e, keyboardModifiers_)); 493 493 494 494 return true; … … 504 504 bool InputManager::mouseMoved(const OIS::MouseEvent &e) 505 505 { 506 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 507 activeMouseHandlers_[i]->mouseMoved(e); 506 // check for actual moved event 507 if (e.state.X.rel != 0 || e.state.Y.rel != 0) 508 { 509 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 510 activeMouseHandlers_[i]->mouseMoved(e.state); 511 } 512 513 // check for mouse scrolled event 514 if (e.state.Z.rel != 0) 515 { 516 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 517 activeMouseHandlers_[i]->mouseScrolled(e.state); 518 } 508 519 509 520 return true; … … 518 529 { 519 530 // check whether the button already is in the list (can happen when focus was lost) 520 for (std::list<OIS::MouseButtonID>::iterator it = mouseButtonsDown_.begin(); it != mouseButtonsDown_.end(); it++) 521 { 522 if (*it == id) 523 { 524 mouseButtonsDown_.erase(it); 525 break; 526 } 527 } 528 mouseButtonsDown_.push_back(id); 531 unsigned int iButton = 0; 532 while (iButton < mouseButtonsDown_.size() && mouseButtonsDown_[iButton] != (MouseButton::Enum)id) 533 iButton++; 534 if (iButton == mouseButtonsDown_.size()) 535 mouseButtonsDown_.push_back((MouseButton::Enum)id); 529 536 530 537 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 531 activeMouseHandlers_[i]->mouse Pressed(e,id);538 activeMouseHandlers_[i]->mouseButtonPressed(e.state, (MouseButton::Enum)id); 532 539 533 540 return true; … … 542 549 { 543 550 // remove the button from the keysDown_ list 544 for ( std::list<OIS::MouseButtonID>::iterator it = mouseButtonsDown_.begin(); it != mouseButtonsDown_.end(); it++)545 { 546 if ( *it ==id)547 { 548 mouseButtonsDown_.erase( it);551 for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++) 552 { 553 if (mouseButtonsDown_[iButton] == (MouseButton::Enum)id) 554 { 555 mouseButtonsDown_.erase(mouseButtonsDown_.begin() + iButton); 549 556 break; 550 557 } … … 552 559 553 560 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 554 activeMouseHandlers_[i]->mouse Released(e,id);561 activeMouseHandlers_[i]->mouseButtonReleased(e.state, (MouseButton::Enum)id); 555 562 556 563 return true; … … 562 569 bool InputManager::buttonPressed(const OIS::JoyStickEvent &arg, int button) 563 570 { 571 // use the device to identify which one called the method 564 572 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 573 unsigned int iJoyStick = 0; 574 while (joySticks_[iJoyStick] != joyStick) 575 iJoyStick++; 565 576 566 577 // check whether the button already is in the list (can happen when focus was lost) 567 std::list<int>& buttonsDownList = joyStickButtonsDown_[joyStick]; 568 for (std::list<int>::iterator it = buttonsDownList.begin(); it != buttonsDownList.end(); it++) 569 { 570 if (*it == button) 571 { 572 buttonsDownList.erase(it); 578 std::vector<int> buttonsDown = joyStickButtonsDown_[iJoyStick]; 579 unsigned int iButton = 0; 580 while (iButton < buttonsDown.size() && buttonsDown[iButton] != button) 581 iButton++; 582 if (iButton == buttonsDown.size()) 583 buttonsDown.push_back(button); 584 585 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 586 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonPressed(JoyStickState(arg.state, iJoyStick), button); 587 588 return true; 589 } 590 591 bool InputManager::buttonReleased(const OIS::JoyStickEvent &arg, int button) 592 { 593 // use the device to identify which one called the method 594 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 595 unsigned int iJoyStick = 0; 596 while (joySticks_[iJoyStick] != joyStick) 597 iJoyStick++; 598 599 // remove the button from the joyStickButtonsDown_ list 600 std::vector<int> buttonsDown = joyStickButtonsDown_[iJoyStick]; 601 for (unsigned int iButton = 0; iButton < buttonsDown.size(); iButton++) 602 { 603 if (buttonsDown[iButton] == button) 604 { 605 buttonsDown.erase(buttonsDown.begin() + iButton); 573 606 break; 574 607 } 575 608 } 576 joyStickButtonsDown_[joyStick].push_back(button); 577 578 for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++)579 activeJoyStickHandlers_[joyStick][i]->buttonPressed(i, arg, button); 580 581 return true;582 } 583 584 bool InputManager::buttonReleased(const OIS::JoyStickEvent &arg, int button)585 {609 610 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 611 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonReleased(JoyStickState(arg.state, iJoyStick), button); 612 613 return true; 614 } 615 616 bool InputManager::axisMoved(const OIS::JoyStickEvent &arg, int axis) 617 { 618 // use the device to identify which one called the method 586 619 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 587 588 // remove the button from the joyStickButtonsDown_ list 589 std::list<int>& buttonsDownList = joyStickButtonsDown_[joyStick]; 590 for (std::list<int>::iterator it = buttonsDownList.begin(); it != buttonsDownList.end(); it++) 591 { 592 if (*it == button) 593 { 594 buttonsDownList.erase(it); 595 break; 596 } 597 } 598 599 for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++) 600 activeJoyStickHandlers_[joyStick][i]->buttonReleased(i, arg, button); 601 602 return true; 603 } 604 605 bool InputManager::axisMoved(const OIS::JoyStickEvent &arg, int axis) 606 { 620 unsigned int iJoyStick = 0; 621 while (joySticks_[iJoyStick] != joyStick) 622 iJoyStick++; 623 624 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 625 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(JoyStickState(arg.state, iJoyStick), axis); 626 627 return true; 628 } 629 630 bool InputManager::sliderMoved(const OIS::JoyStickEvent &arg, int id) 631 { 632 // use the device to identify which one called the method 607 633 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 608 for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++) 609 activeJoyStickHandlers_[joyStick][i]->axisMoved(i, arg, axis); 610 611 return true; 612 } 613 614 bool InputManager::sliderMoved(const OIS::JoyStickEvent &arg, int id) 615 { 634 unsigned int iJoyStick = 0; 635 while (joySticks_[iJoyStick] != joyStick) 636 iJoyStick++; 637 638 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 639 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickSliderMoved(JoyStickState(arg.state, iJoyStick), id); 640 641 return true; 642 } 643 644 bool InputManager::povMoved(const OIS::JoyStickEvent &arg, int id) 645 { 646 // use the device to identify which one called the method 616 647 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 617 for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++) 618 activeJoyStickHandlers_[joyStick][i]->sliderMoved(i, arg, id); 619 620 return true; 621 } 622 623 bool InputManager::povMoved(const OIS::JoyStickEvent &arg, int id) 624 { 648 unsigned int iJoyStick = 0; 649 while (joySticks_[iJoyStick] != joyStick) 650 iJoyStick++; 651 652 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 653 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickPovMoved(JoyStickState(arg.state, iJoyStick), id); 654 655 return true; 656 } 657 658 bool InputManager::vector3Moved(const OIS::JoyStickEvent &arg, int id) 659 { 660 // use the device to identify which one called the method 625 661 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 626 for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++) 627 activeJoyStickHandlers_[joyStick][i]->povMoved(i, arg, id); 628 629 return true; 630 } 631 632 bool InputManager::vector3Moved(const OIS::JoyStickEvent &arg, int id) 633 { 634 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 635 for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++) 636 activeJoyStickHandlers_[joyStick][i]->vector3Moved(i, arg, id); 662 unsigned int iJoyStick = 0; 663 while (joySticks_[iJoyStick] != joyStick) 664 iJoyStick++; 665 666 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 667 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickVector3Moved(JoyStickState(arg.state, iJoyStick), id); 637 668 638 669 return true; … … 645 676 // ################################ 646 677 647 bool InputManager::initialise(const size_t windowHnd, const int windowWidth, constint windowHeight,648 const bool createKeyboard, const bool createMouse, constbool createJoySticks)678 bool InputManager::initialise(const size_t windowHnd, int windowWidth, int windowHeight, 679 bool createKeyboard, bool createMouse, bool createJoySticks) 649 680 { 650 681 return _getSingleton()._initialise(windowHnd, windowWidth, windowHeight, … … 685 716 int InputManager::numberOfJoySticks() 686 717 { 687 return _getSingleton().joySticks_.size(); 718 return _getSingleton().joySticksSize_; 719 } 720 721 bool InputManager::isKeyDown(KeyCode::Enum key) 722 { 723 if (_getSingleton().keyboard_) 724 return _getSingleton().keyboard_->isKeyDown((OIS::KeyCode)key); 725 else 726 return false; 727 } 728 729 bool InputManager::isModifierDown(KeyboardModifier::Enum modifier) 730 { 731 if (_getSingleton().keyboard_) 732 return isModifierDown(modifier); 733 else 734 return false; 735 } 736 737 const MouseState InputManager::getMouseState() 738 { 739 if (_getSingleton().mouse_) 740 return _getSingleton().mouse_->getMouseState(); 741 else 742 return MouseState(); 743 } 744 745 const JoyStickState InputManager::getJoyStickState(unsigned int ID) 746 { 747 if (ID < _getSingleton().joySticksSize_) 748 return JoyStickState(_getSingleton().joySticks_[ID]->getJoyStickState(), ID); 749 else 750 return JoyStickState(); 688 751 } 689 752 … … 757 820 bool InputManager::addKeyHandler(KeyHandler* handler, const std::string& name) 758 821 { 822 if (!handler) 823 return false; 759 824 if (_getSingleton().keyHandlers_.find(name) == _getSingleton().keyHandlers_.end()) 760 825 { … … 883 948 bool InputManager::addMouseHandler(MouseHandler* handler, const std::string& name) 884 949 { 950 if (!handler) 951 return false; 885 952 if (_getSingleton().mouseHandlers_.find(name) == _getSingleton().mouseHandlers_.end()) 886 953 { … … 1010 1077 bool InputManager::addJoyStickHandler(JoyStickHandler* handler, const std::string& name) 1011 1078 { 1079 if (!handler) 1080 return false; 1012 1081 if (_getSingleton().joyStickHandlers_.find(name) == _getSingleton().joyStickHandlers_.end()) 1013 1082 { … … 1061 1130 @return False if name or id was not found, true otherwise. 1062 1131 */ 1063 bool InputManager::enableJoyStickHandler(const std::string& name, constint ID)1132 bool InputManager::enableJoyStickHandler(const std::string& name, unsigned int ID) 1064 1133 { 1065 1134 // get handler pointer from the map with all stored handlers … … 1069 1138 1070 1139 // check for existence of the ID 1071 if ((unsigned int)ID >= _getSingleton().joySticks_.size()) 1072 return false; 1073 OIS::JoyStick* joyStick = _getSingleton().joySticks_[ID]; 1140 if (ID >= _getSingleton().joySticksSize_) 1141 return false; 1074 1142 1075 1143 // see whether the handler already is in the list 1076 for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ joyStick].begin();1077 it != _getSingleton().activeJoyStickHandlers_[ joyStick].end(); it++)1144 for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ID].begin(); 1145 it != _getSingleton().activeJoyStickHandlers_[ID].end(); it++) 1078 1146 { 1079 1147 if ((*it) == (*handlerIt).second) … … 1083 1151 } 1084 1152 } 1085 _getSingleton().activeJoyStickHandlers_[ joyStick].push_back((*handlerIt).second);1153 _getSingleton().activeJoyStickHandlers_[ID].push_back((*handlerIt).second); 1086 1154 _getSingleton().stateRequest_ = IS_CUSTOM; 1087 1155 return true; … … 1093 1161 @return False if name or id was not found, true otherwise. 1094 1162 */ 1095 bool InputManager::disableJoyStickHandler(const std::string &name, int ID)1163 bool InputManager::disableJoyStickHandler(const std::string &name, unsigned int ID) 1096 1164 { 1097 1165 // get handler pointer from the map with all stored handlers … … 1101 1169 1102 1170 // check for existence of the ID 1103 if ((unsigned int)ID >= _getSingleton().joySticks_.size()) 1104 return false; 1105 OIS::JoyStick* joyStick = _getSingleton().joySticks_[ID]; 1171 if (ID >= _getSingleton().joySticksSize_) 1172 return false; 1106 1173 1107 1174 // look for the handler in the list 1108 for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ joyStick].begin();1109 it != _getSingleton().activeJoyStickHandlers_[ joyStick].end(); it++)1175 for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ID].begin(); 1176 it != _getSingleton().activeJoyStickHandlers_[ID].end(); it++) 1110 1177 { 1111 1178 if ((*it) == (*handlerIt).second) 1112 1179 { 1113 _getSingleton().activeJoyStickHandlers_[ joyStick].erase(it);1180 _getSingleton().activeJoyStickHandlers_[ID].erase(it); 1114 1181 _getSingleton().stateRequest_ = IS_CUSTOM; 1115 1182 return true; … … 1124 1191 @return False if key handler is not active or doesn't exist, true otherwise. 1125 1192 */ 1126 bool InputManager::isJoyStickHandlerActive(const std::string& name, constint ID)1193 bool InputManager::isJoyStickHandlerActive(const std::string& name, unsigned int ID) 1127 1194 { 1128 1195 // get handler pointer from the map with all stored handlers … … 1132 1199 1133 1200 // check for existence of the ID 1134 if ((unsigned int)ID >= _getSingleton().joySticks_.size()) 1135 return false; 1136 OIS::JoyStick* joyStick = _getSingleton().joySticks_[ID]; 1201 if (ID >= _getSingleton().joySticksSize_) 1202 return false; 1137 1203 1138 1204 // see whether the handler already is in the list 1139 for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ joyStick].begin();1140 it != _getSingleton().activeJoyStickHandlers_[ joyStick].end(); it++)1205 for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ID].begin(); 1206 it != _getSingleton().activeJoyStickHandlers_[ID].end(); it++) 1141 1207 { 1142 1208 if ((*it) == (*handlerIt).second)
Note: See TracChangeset
for help on using the changeset viewer.