Changeset 1637 for code/branches/input/src/core/input/InputManager.cc
- Timestamp:
- Jul 20, 2008, 6:49:24 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/input/src/core/input/InputManager.cc
r1630 r1637 38 38 #include <limits.h> 39 39 40 #include "ois/OISException.h" 41 #include "ois/OISInputManager.h" 42 40 43 #include "core/CoreIncludes.h" 41 44 #include "core/ConfigValueIncludes.h" … … 43 46 #include "core/CommandExecutor.h" 44 47 #include "core/ConsoleCommand.h" 45 #include "core/Shell.h" // hack!46 48 47 49 #include "InputBuffer.h" … … 49 51 #include "KeyDetector.h" 50 52 #include "CalibratorCallback.h" 51 52 #include " src/ois/OISException.h"53 #include " src/ois/OISInputManager.h"53 #include "InputState.h" 54 #include "SimpleInputState.h" 55 #include "ExtendedInputState.h" 54 56 55 57 namespace orxonox … … 59 61 SetConsoleCommandShortcut(InputManager, calibrate); 60 62 63 using namespace InputDevice; 64 61 65 // ############################### 62 66 // ### Internal Methods ### … … 74 78 , mouse_(0) 75 79 , joySticksSize_(0) 76 , keyBinder_(0) 77 , keyDetector_(0) 78 , buffer_(0) 79 , calibratorCallback_(0) 80 , state_(IS_UNINIT) 81 , stateRequest_(IS_UNINIT) 82 , savedState_(IS_UNINIT) 80 , devicesNum_(0) 81 , stateDetector_(0) 82 , stateCalibrator_(0) 83 , stateEmpty_(0) 83 84 , keyboardModifiers_(0) 85 , bCalibrating_(false) 84 86 { 85 87 RegisterRootObject(InputManager); … … 92 94 A reference to the only instance of the InputManager 93 95 */ 94 InputManager& InputManager::_get Singleton()96 InputManager& InputManager::_getInstance() 95 97 { 96 98 static InputManager theOnlyInstance; … … 106 108 _destroy(); 107 109 } 110 111 112 // ############################################################ 113 // ##### Initialisation ##### 114 // ########## ########## 115 // ############################################################ 108 116 109 117 /** … … 121 129 bool createKeyboard, bool createMouse, bool createJoySticks) 122 130 { 123 if ( state_ == IS_UNINIT)131 if (inputSystem_ == 0) 124 132 { 125 133 CCOUT(3) << "Initialising Input System..." << std::endl; … … 160 168 _initialiseJoySticks(); 161 169 170 // set all the std::vector list sizes now that the devices have been created 171 _redimensionLists(); 172 162 173 // Set mouse/joystick region 163 174 if (mouse_) … … 166 177 } 167 178 168 state_ = IS_NONE;169 179 CCOUT(ORX_DEBUG) << "Initialising OIS components done." << std::endl; 170 180 171 181 // InputManager holds the input buffer --> create one and add it. 172 buffer_ = new InputBuffer(); 173 addKeyHandler(buffer_, "buffer"); 174 Shell::getInstance().setInputBuffer(buffer_); 175 176 keyBinder_ = new KeyBinder(); 177 keyBinder_->loadBindings(); 178 addKeyHandler(keyBinder_, "keybinder"); 179 addMouseHandler(keyBinder_, "keybinder"); 180 addJoyStickHandler(keyBinder_, "keybinder"); 181 182 keyDetector_ = new KeyDetector(); 183 keyDetector_->loadBindings(); 184 addKeyHandler(keyDetector_, "keydetector"); 185 addMouseHandler(keyDetector_, "keydetector"); 186 addJoyStickHandler(keyDetector_, "keydetector"); 187 188 calibratorCallback_ = new CalibratorCallback(); 189 addKeyHandler(calibratorCallback_, "calibratorcallback"); 182 //buffer_ = new InputBuffer(); 183 //addKeyHandler(buffer_, "buffer"); 184 //Shell::getInstance().setInputBuffer(buffer_); 190 185 191 186 setConfigValues(); 187 188 stateEmpty_ = createSimpleInputState("empty", -1); 189 stateEmpty_->setHandler(new EmptyHandler()); 190 activeStates_[stateEmpty_->getPriority()] = stateEmpty_; 191 192 stateDetector_ = createSimpleInputState("detector", 101); 193 KeyDetector* temp = new KeyDetector(); 194 temp->loadBindings("storeKeyStroke"); 195 stateDetector_->setHandler(temp); 196 197 stateCalibrator_ = createSimpleInputState("calibrator", 100); 198 stateCalibrator_->setHandler(new EmptyHandler()); 199 InputBuffer* buffer = new InputBuffer(); 200 buffer->registerListener(this, &InputManager::_completeCalibration, '\r', true); 201 stateCalibrator_->setKeyHandler(buffer); 202 203 _updateActiveStates(); 192 204 193 205 CCOUT(ORX_DEBUG) << "Initialising complete." << std::endl; … … 232 244 catch (OIS::Exception ex) 233 245 { 234 // TODO: Test this output regarding formatting235 246 CCOUT(ORX_WARNING) << "Warning: Failed to create an OIS keyboard\n" 236 247 << "OIS error message: \"" << ex.eText << "\"" << std::endl; … … 300 311 OIS::JoyStick* stig = static_cast<OIS::JoyStick*> 301 312 (inputSystem_->createInputObject(OIS::OISJoyStick, true)); 313 CCOUT(ORX_DEBUG) << "Created OIS joy stick with ID " << stig->getID() << std::endl; 302 314 joySticks_.push_back(stig); 303 315 // register our listener in OIS. 304 316 stig->setEventCallback(this); 305 CCOUT(ORX_DEBUG) << "Created OIS joy stick with ID " << stig->getID() << std::endl;306 317 success = true; 307 318 } … … 318 329 return false; 319 330 } 331 return success; 332 } 333 334 void InputManager::_redimensionLists() 335 { 320 336 joySticksSize_ = joySticks_.size(); 321 activeJoyStickHandlers_.resize(joySticksSize_);322 joyStickButtonsDown_ .resize(joySticksSize_);323 povStates_ .resize(joySticksSize_);324 sliderStates_ .resize(joySticksSize_);337 devicesNum_ = 2 + joySticksSize_; 338 joyStickButtonsDown_ .resize(joySticksSize_); 339 povStates_ .resize(joySticksSize_); 340 sliderStates_ .resize(joySticksSize_); 325 341 joySticksCalibration_.resize(joySticksSize_); 342 326 343 for (unsigned int iJoyStick = 0; iJoyStick < joySticksSize_; iJoyStick++) 327 344 { … … 334 351 } 335 352 } 336 return success; 353 354 // state management 355 activeStatesTop_.resize(devicesNum_); 356 357 // inform all registered states 358 for (std::map<int, InputState*>::const_iterator it = inputStatesByPriority_.begin(); 359 it != inputStatesByPriority_.end(); ++it) 360 (*it).second->setNumOfJoySticks(joySticksSize_); 337 361 } 338 362 … … 392 416 } 393 417 418 419 // ############################################################ 420 // ##### Destruction ##### 421 // ########## ########## 422 // ############################################################ 423 394 424 /** 395 425 @brief … … 398 428 void InputManager::_destroy() 399 429 { 400 if ( state_ != IS_UNINIT)430 if (inputSystem_) 401 431 { 402 432 CCOUT(ORX_DEBUG) << "Destroying ..." << std::endl; 403 433 404 if (buffer_) 405 delete buffer_; 406 407 if (keyBinder_) 408 delete keyBinder_; 409 410 if (keyDetector_) 411 delete keyDetector_; 412 413 if (calibratorCallback_) 414 delete calibratorCallback_; 415 416 keyHandlers_.clear(); 417 mouseHandlers_.clear(); 418 joyStickHandlers_.clear(); 419 434 // kick all active states 'nicely' 435 for (std::map<int, InputState*>::reverse_iterator rit = activeStates_.rbegin(); 436 rit != activeStates_.rend(); ++rit) 437 (*rit).second->onLeave(); 438 activeStates_.clear(); 439 440 // destroy our own states 441 stateEmpty_->removeAndDestroyAllHandlers(); 442 stateCalibrator_->removeAndDestroyAllHandlers(); 443 stateDetector_->removeAndDestroyAllHandlers(); 444 _destroyState(stateEmpty_); 445 _destroyState(stateCalibrator_); 446 _destroyState(stateDetector_); 447 stateEmpty_ = 0; 448 stateCalibrator_ = 0; 449 stateDetector_ = 0; 450 451 // we don't remove the other states yet because the singleton might still exist. 452 // So people can still removeAndDestroy their states 453 //inputStatesByName_.clear(); 454 //inputStatesByPriority_.clear(); 455 456 // destroy the devices 420 457 _destroyKeyboard(); 421 458 _destroyMouse(); 422 459 _destroyJoySticks(); 423 460 424 activeHandlers_.clear(); 425 426 // inputSystem_ can never be 0, or else the code is mistaken 461 _redimensionLists(); 462 427 463 OIS::InputManager::destroyInputSystem(inputSystem_); 428 464 inputSystem_ = 0; 429 465 430 state_ = IS_UNINIT;431 466 CCOUT(ORX_DEBUG) << "Destroying done." << std::endl; 432 467 } … … 442 477 inputSystem_->destroyInputObject(keyboard_); 443 478 keyboard_ = 0; 444 activeKeyHandlers_.clear();445 479 keysDown_.clear(); 446 480 CCOUT(ORX_DEBUG) << "Keyboard destroyed." << std::endl; … … 456 490 inputSystem_->destroyInputObject(mouse_); 457 491 mouse_ = 0; 458 activeMouseHandlers_.clear();459 492 mouseButtonsDown_.clear(); 460 493 CCOUT(ORX_DEBUG) << "Mouse destroyed." << std::endl; … … 475 508 476 509 joySticks_.clear(); 477 joySticksSize_ = 0;478 activeJoyStickHandlers_.clear();479 joyStickButtonsDown_.clear();480 povStates_.clear();481 sliderStates_.clear();482 joySticksCalibration_.clear();483 510 } 484 511 CCOUT(ORX_DEBUG) << "Joy sticks destroyed." << std::endl; 485 512 } 486 513 487 void InputManager::_saveState() 488 { 489 savedHandlers_.activeHandlers_ = activeHandlers_; 490 savedHandlers_.activeJoyStickHandlers_ = activeJoyStickHandlers_; 491 savedHandlers_.activeKeyHandlers_ = activeKeyHandlers_; 492 savedHandlers_.activeMouseHandlers_ = activeMouseHandlers_; 493 } 494 495 void InputManager::_restoreState() 496 { 497 activeHandlers_ = savedHandlers_.activeHandlers_; 498 activeJoyStickHandlers_ = savedHandlers_.activeJoyStickHandlers_; 499 activeKeyHandlers_ = savedHandlers_.activeKeyHandlers_; 500 activeMouseHandlers_ = savedHandlers_.activeMouseHandlers_; 501 } 502 503 void InputManager::_updateTickables() 504 { 505 // we can use a map to have a list of unique pointers (an object can implement all 3 handlers) 506 std::map<InputTickable*, HandlerState> tempSet; 507 for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++) 508 tempSet[activeKeyHandlers_[iHandler]].joyStick = true; 509 for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++) 510 tempSet[activeMouseHandlers_[iHandler]].mouse = true; 511 for (unsigned int iJoyStick = 0; iJoyStick < joySticksSize_; iJoyStick++) 512 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 513 tempSet[activeJoyStickHandlers_[iJoyStick][iHandler]].joyStick = true; 514 515 // copy the content of the map back to the actual vector 516 activeHandlers_.clear(); 517 for (std::map<InputTickable*, HandlerState>::const_iterator itHandler = tempSet.begin(); 518 itHandler != tempSet.end(); itHandler++) 519 activeHandlers_.push_back(std::pair<InputTickable*, HandlerState>((*itHandler).first, (*itHandler).second)); 520 } 521 522 523 // ################################# 524 // ### Private Interface Methods ### 525 // ################################# 526 // ################################# 527 528 /** 529 @brief 530 Updates the InputManager. Tick is called by Orxonox. 514 void InputManager::_destroyState(InputState* state) 515 { 516 assert(state); 517 inputStatesByPriority_.erase(state->getPriority()); 518 inputStatesByName_.erase(state->getName()); 519 delete state; 520 } 521 522 523 // ############################################################ 524 // ##### Runtime Methods ##### 525 // ########## ########## 526 // ############################################################ 527 528 /** 529 @brief 530 Updates the InputManager. Tick is called by the Core class. 531 531 @param dt 532 532 Delta time … … 534 534 void InputManager::_tick(float dt) 535 535 { 536 if ( state_ == IS_UNINIT)536 if (inputSystem_ == 0) 537 537 return; 538 538 539 if (state_ != stateRequest_) 540 { 541 InputState sr = stateRequest_; 542 switch (sr) 543 { 544 case IS_NORMAL: 545 activeKeyHandlers_.clear(); 546 activeMouseHandlers_.clear(); 547 for (unsigned int i = 0; i < joySticksSize_; i++) 548 activeJoyStickHandlers_[i].clear(); 549 550 // normal play mode 551 // note: we assume that the handlers exist since otherwise, something's wrong anyway. 552 enableKeyHandler("keybinder"); 553 enableMouseHandler("keybinder"); 554 enableJoyStickHandler("keybinder", 0); 555 stateRequest_ = IS_NORMAL; 556 state_ = IS_NORMAL; 557 break; 558 559 case IS_GUI: 560 state_ = IS_GUI; 561 break; 562 563 case IS_CONSOLE: 564 activeKeyHandlers_.clear(); 565 activeMouseHandlers_.clear(); 566 for (unsigned int i = 0; i < joySticksSize_; i++) 567 activeJoyStickHandlers_[i].clear(); 568 569 enableMouseHandler("keybinder"); 570 enableJoyStickHandler("keybinder", 0); 571 enableKeyHandler("buffer"); 572 stateRequest_ = IS_CONSOLE; 573 state_ = IS_CONSOLE; 574 break; 575 576 case IS_DETECT: 577 savedState_ = state_; 578 _saveState(); 579 580 activeKeyHandlers_.clear(); 581 activeMouseHandlers_.clear(); 582 for (unsigned int i = 0; i < joySticksSize_; i++) 583 activeJoyStickHandlers_[i].clear(); 584 585 enableKeyHandler("keydetector"); 586 enableMouseHandler("keydetector"); 587 enableJoyStickHandler("keydetector", 0); 588 589 stateRequest_ = IS_DETECT; 590 state_ = IS_DETECT; 591 break; 592 593 case IS_NODETECT: 594 _restoreState(); 595 keysDown_.clear(); 596 mouseButtonsDown_.clear(); 597 for (unsigned int i = 0; i < joySticksSize_; i++) 598 joyStickButtonsDown_[i].clear(); 599 state_ = IS_NODETECT; 600 stateRequest_ = savedState_; 601 break; 602 603 case IS_CALIBRATE: 604 if (joySticksSize_) 605 { 606 savedState_ = _getSingleton().state_; 607 for (unsigned int i = 0; i < 24; i++) 608 { 609 marginalsMax_[i] = INT_MIN; 610 marginalsMin_[i] = INT_MAX; 611 } 612 COUT(0) << "Move all joy stick axes in all directions a few times. " 613 << "Then put all axes in zero state and hit enter." << std::endl; 614 615 savedState_ = state_; 616 _saveState(); 617 618 activeKeyHandlers_.clear(); 619 activeMouseHandlers_.clear(); 620 for (unsigned int i = 0; i < joySticksSize_; i++) 621 activeJoyStickHandlers_[i].clear(); 622 623 enableKeyHandler("calibratorcallback"); 624 stateRequest_ = IS_CALIBRATE; 625 state_ = IS_CALIBRATE; 626 } 627 else 628 { 629 COUT(3) << "Connot calibrate, no joy stick found!" << std::endl; 630 stateRequest_ = state_; 631 } 632 break; 633 634 case IS_NOCALIBRATE: 635 _completeCalibration(); 636 _restoreState(); 637 keyBinder_->resetJoyStickAxes(); 638 state_ = IS_NOCALIBRATE; 639 stateRequest_ = savedState_; 640 break; 641 642 case IS_NONE: 643 activeKeyHandlers_.clear(); 644 activeMouseHandlers_.clear(); 645 for (unsigned int i = 0; i < joySticksSize_; i++) 646 activeJoyStickHandlers_[i].clear(); 647 state_ = IS_NONE; 648 649 default: 650 break; 651 } 539 // check for states to leave (don't use unsigned int!) 540 for (int i = stateLeaveRequests_.size() - 1; i >= 0; --i) 541 { 542 stateLeaveRequests_[i]->onLeave(); 543 // just to be sure that the state actually is registered 544 assert(inputStatesByName_.find(stateLeaveRequests_[i]->getName()) != inputStatesByName_.end()); 545 546 activeStates_.erase(stateLeaveRequests_[i]->getPriority()); 547 _updateActiveStates(); 548 stateLeaveRequests_.pop_back(); 549 } 550 551 552 // check for states to enter (don't use unsigned int!) 553 for (int i = stateEnterRequests_.size() - 1; i >= 0; --i) 554 { 555 // just to be sure that the state actually is registered 556 assert(inputStatesByName_.find(stateEnterRequests_[i]->getName()) != inputStatesByName_.end()); 557 558 activeStates_[stateEnterRequests_[i]->getPriority()] = stateEnterRequests_[i]; 559 _updateActiveStates(); 560 stateEnterRequests_[i]->onEnter(); 561 stateEnterRequests_.pop_back(); 652 562 } 653 563 654 564 // Capture all the input. This calls the event handlers in InputManager. 565 if (keyboard_) 566 keyboard_->capture(); 655 567 if (mouse_) 656 568 mouse_->capture(); 657 if (keyboard_)658 keyboard_->capture();659 569 for (unsigned int i = 0; i < joySticksSize_; i++) 660 570 joySticks_[i]->capture(); 661 571 662 if ( state_ != IS_CALIBRATE)572 if (!bCalibrating_) 663 573 { 664 574 // call all the handlers for the held key events 665 575 for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++) 666 for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++) 667 activeKeyHandlers_[iHandler]->keyHeld(KeyEvent(keysDown_[iKey], keyboardModifiers_)); 576 activeStatesTop_[Keyboard]->keyHeld(KeyEvent(keysDown_[iKey], keyboardModifiers_)); 668 577 669 578 // call all the handlers for the held mouse button events 670 579 for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++) 671 for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++) 672 activeMouseHandlers_[iHandler]->mouseButtonHeld(mouseButtonsDown_[iButton]); 580 activeStatesTop_[Mouse]->mouseButtonHeld(mouseButtonsDown_[iButton]); 673 581 674 582 // call all the handlers for the held joy stick button events 675 583 for (unsigned int iJoyStick = 0; iJoyStick < joySticksSize_; iJoyStick++) 676 584 for (unsigned int iButton = 0; iButton < joyStickButtonsDown_[iJoyStick].size(); iButton++) 677 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 678 { 679 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonHeld( 680 iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]); 681 } 682 } 683 684 // call the ticks for the handlers (need to be treated specially) 685 for (unsigned int iHandler = 0; iHandler < activeHandlers_.size(); iHandler++) 686 activeHandlers_[iHandler].first->tickInput(dt, activeHandlers_[iHandler].second); 585 activeStatesTop_[JoyStick0 + iJoyStick] 586 ->joyStickButtonHeld(iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]); 587 588 // tick the handlers for each active handler 589 for (unsigned int i = 0; i < devicesNum_; ++i) 590 activeStatesTop_[i]->tickInput(dt, i); 591 592 // tick the handler with a general tick afterwards 593 for (unsigned int i = 0; i < activeStatesTicked_.size(); ++i) 594 activeStatesTicked_[i]->tickInput(dt); 595 } 596 } 597 598 void InputManager::_updateActiveStates() 599 { 600 for (std::map<int, InputState*>::const_iterator it = activeStates_.begin(); it != activeStates_.end(); ++it) 601 for (unsigned int i = 0; i < devicesNum_; ++i) 602 if ((*it).second->isInputDeviceEnabled(i)) 603 activeStatesTop_[i] = (*it).second; 604 605 // update tickables (every state will only appear once) 606 // Using a std::set to avoid duplicates 607 std::set<InputState*> tempSet; 608 for (unsigned int i = 0; i < devicesNum_; ++i) 609 tempSet.insert(activeStatesTop_[i]); 610 611 // copy the content of the set back to the actual vector 612 activeStatesTicked_.clear(); 613 for (std::set<InputState*>::const_iterator it = tempSet.begin();it != tempSet.end(); ++it) 614 activeStatesTicked_.push_back(*it); 687 615 } 688 616 … … 744 672 cont->set(i, joySticksCalibration_[0].zeroStates[i]); 745 673 } 746 } 674 675 // restore old input state 676 requestLeaveState("calibrator"); 677 } 678 679 680 // ############################################################ 681 // ##### OIS events ##### 682 // ########## ########## 683 // ############################################################ 747 684 748 685 // ###### Key Events ###### … … 771 708 keyboardModifiers_ |= KeyboardModifier::Shift; // shift key 772 709 773 for (unsigned int i = 0; i < activeKeyHandlers_.size(); i++) 774 activeKeyHandlers_[i]->keyPressed(KeyEvent(e, keyboardModifiers_)); 710 activeStatesTop_[Keyboard]->keyPressed(KeyEvent(e, keyboardModifiers_)); 775 711 776 712 return true; … … 803 739 keyboardModifiers_ &= ~KeyboardModifier::Shift; // shift key 804 740 805 for (unsigned int i = 0; i < activeKeyHandlers_.size(); i++) 806 activeKeyHandlers_[i]->keyReleased(KeyEvent(e, keyboardModifiers_)); 741 activeStatesTop_[Keyboard]->keyReleased(KeyEvent(e, keyboardModifiers_)); 807 742 808 743 return true; … … 823 758 if (e.state.X.rel != 0 || e.state.Y.rel != 0) 824 759 { 825 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 826 { 827 activeMouseHandlers_[i]->mouseMoved(IntVector2(e.state.X.abs, e.state.Y.abs), 760 activeStatesTop_[Mouse]->mouseMoved(IntVector2(e.state.X.abs, e.state.Y.abs), 828 761 IntVector2(e.state.X.rel, e.state.Y.rel), IntVector2(e.state.width, e.state.height)); 829 }830 762 } 831 763 … … 833 765 if (e.state.Z.rel != 0) 834 766 { 835 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 836 activeMouseHandlers_[i]->mouseScrolled(e.state.Z.abs, e.state.Z.rel); 767 activeStatesTop_[Mouse]->mouseScrolled(e.state.Z.abs, e.state.Z.rel); 837 768 } 838 769 … … 857 788 mouseButtonsDown_.push_back((MouseButton::Enum)id); 858 789 859 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 860 activeMouseHandlers_[i]->mouseButtonPressed((MouseButton::Enum)id); 790 activeStatesTop_[Mouse]->mouseButtonPressed((MouseButton::Enum)id); 861 791 862 792 return true; … … 883 813 } 884 814 885 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 886 activeMouseHandlers_[i]->mouseButtonReleased((MouseButton::Enum)id); 815 activeStatesTop_[Mouse]->mouseButtonReleased((MouseButton::Enum)id); 887 816 888 817 return true; … … 898 827 unsigned int iJoyStick = 0; 899 828 while (joySticks_[iJoyStick] != joyStick) 900 {901 829 iJoyStick++; 902 if (iJoyStick == joySticksSize_) 903 { 904 CCOUT(3) << "Unknown joystick fired an event. This means there is a bug somewhere! Aborting." << std::endl; 905 abort(); 906 } 907 } 830 // assert: Unknown joystick fired an event. 831 assert(iJoyStick != joySticksSize_); 908 832 return iJoyStick; 909 833 } … … 921 845 buttonsDown.push_back(button); 922 846 923 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 924 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonPressed(iJoyStick, button); 847 activeStatesTop_[2 + iJoyStick]->joyStickButtonPressed(iJoyStick, button); 925 848 926 849 return true; … … 942 865 } 943 866 944 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 945 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonReleased(iJoyStick, button); 867 activeStatesTop_[2 + iJoyStick]->joyStickButtonReleased(iJoyStick, button); 946 868 947 869 return true; … … 950 872 void InputManager::_fireAxis(unsigned int iJoyStick, int axis, int value) 951 873 { 952 if ( state_ == IS_CALIBRATE)874 if (bCalibrating_) 953 875 { 954 876 if (value > marginalsMax_[axis]) … … 965 887 fValue *= joySticksCalibration_[iJoyStick].negativeCoeff[axis]; 966 888 967 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 968 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, axis, fValue); 889 activeStatesTop_[2 + iJoyStick]->joyStickAxisMoved(iJoyStick, axis, fValue); 969 890 } 970 891 } … … 972 893 bool InputManager::axisMoved(const OIS::JoyStickEvent &arg, int axis) 973 894 { 974 //if (arg.state.mAxes[axis].abs > 10000 || arg.state.mAxes[axis].abs < -10000)975 //{ CCOUT(3) << "axis " << axis << " moved" << arg.state.mAxes[axis].abs << std::endl;}976 977 895 unsigned int iJoyStick = _getJoystick(arg); 978 896 … … 985 903 bool InputManager::sliderMoved(const OIS::JoyStickEvent &arg, int id) 986 904 { 987 //if (arg.state.mSliders[id].abX > 10000 || arg.state.mSliders[id].abX < -10000)988 //{CCOUT(3) << "slider " << id << " moved" << arg.state.mSliders[id].abX << std::endl;}989 //CCOUT(3) << arg.state.mSliders[id].abX << "\t |" << arg.state.mSliders[id].abY << std::endl;990 991 905 unsigned int iJoyStick = _getJoystick(arg); 992 906 … … 1029 943 } 1030 944 1031 /*bool InputManager::vector3Moved(const OIS::JoyStickEvent &arg, int id) 1032 { 1033 unsigned int iJoyStick = _getJoystick(arg); 1034 1035 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 1036 { 1037 activeJoyStickHandlers_[iJoyStick][iHandler] 1038 ->joyStickVector3Moved(JoyStickState(arg.state, iJoyStick), id); 1039 } 1040 1041 return true; 1042 }*/ 1043 1044 1045 // ################################ 1046 // ### Static Interface Methods ### 1047 // ################################ 1048 // ################################ 945 946 // ############################################################ 947 // ##### Static Interface Methods ##### 948 // ########## ########## 949 // ############################################################ 1049 950 1050 951 std::string InputManager::bindingCommmandString_s = ""; … … 1053 954 bool createKeyboard, bool createMouse, bool createJoySticks) 1054 955 { 1055 return _get Singleton()._initialise(windowHnd, windowWidth, windowHeight,956 return _getInstance()._initialise(windowHnd, windowWidth, windowHeight, 1056 957 createKeyboard, createMouse, createJoySticks); 1057 958 } … … 1059 960 bool InputManager::initialiseKeyboard() 1060 961 { 1061 return _get Singleton()._initialiseKeyboard();962 return _getInstance()._initialiseKeyboard(); 1062 963 } 1063 964 1064 965 bool InputManager::initialiseMouse() 1065 966 { 1066 return _get Singleton()._initialiseMouse();967 return _getInstance()._initialiseMouse(); 1067 968 } 1068 969 1069 970 bool InputManager::initialiseJoySticks() 1070 971 { 1071 return _get Singleton()._initialiseJoySticks();972 return _getInstance()._initialiseJoySticks(); 1072 973 } 1073 974 1074 975 int InputManager::numberOfKeyboards() 1075 976 { 1076 if (_get Singleton().keyboard_ != 0)977 if (_getInstance().keyboard_ != 0) 1077 978 return 1; 1078 979 else … … 1082 983 int InputManager::numberOfMice() 1083 984 { 1084 if (_get Singleton().mouse_ != 0)985 if (_getInstance().mouse_ != 0) 1085 986 return 1; 1086 987 else … … 1090 991 int InputManager::numberOfJoySticks() 1091 992 { 1092 return _get Singleton().joySticksSize_;993 return _getInstance().joySticksSize_; 1093 994 } 1094 995 1095 996 /*bool InputManager::isKeyDown(KeyCode::Enum key) 1096 997 { 1097 if (_get Singleton().keyboard_)1098 return _get Singleton().keyboard_->isKeyDown((OIS::KeyCode)key);998 if (_getInstance().keyboard_) 999 return _getInstance().keyboard_->isKeyDown((OIS::KeyCode)key); 1099 1000 else 1100 1001 return false; … … 1103 1004 /*bool InputManager::isModifierDown(KeyboardModifier::Enum modifier) 1104 1005 { 1105 if (_get Singleton().keyboard_)1006 if (_getInstance().keyboard_) 1106 1007 return isModifierDown(modifier); 1107 1008 else … … 1111 1012 /*const MouseState InputManager::getMouseState() 1112 1013 { 1113 if (_get Singleton().mouse_)1114 return _get Singleton().mouse_->getMouseState();1014 if (_getInstance().mouse_) 1015 return _getInstance().mouse_->getMouseState(); 1115 1016 else 1116 1017 return MouseState(); … … 1119 1020 /*const JoyStickState InputManager::getJoyStickState(unsigned int ID) 1120 1021 { 1121 if (ID < _get Singleton().joySticksSize_)1122 return JoyStickState(_get Singleton().joySticks_[ID]->getJoyStickState(), ID);1022 if (ID < _getInstance().joySticksSize_) 1023 return JoyStickState(_getInstance().joySticks_[ID]->getJoyStickState(), ID); 1123 1024 else 1124 1025 return JoyStickState(); … … 1127 1028 void InputManager::destroy() 1128 1029 { 1129 _get Singleton()._destroy();1030 _getInstance()._destroy(); 1130 1031 } 1131 1032 1132 1033 void InputManager::destroyKeyboard() 1133 1034 { 1134 return _get Singleton()._destroyKeyboard();1035 return _getInstance()._destroyKeyboard(); 1135 1036 } 1136 1037 1137 1038 void InputManager::destroyMouse() 1138 1039 { 1139 return _get Singleton()._destroyMouse();1040 return _getInstance()._destroyMouse(); 1140 1041 } 1141 1042 1142 1043 void InputManager::destroyJoySticks() 1143 1044 { 1144 return _get Singleton()._destroyJoySticks();1045 return _getInstance()._destroyJoySticks(); 1145 1046 } 1146 1047 … … 1157 1058 void InputManager::setWindowExtents(const int width, const int height) 1158 1059 { 1159 if (_get Singleton().mouse_)1060 if (_getInstance().mouse_) 1160 1061 { 1161 1062 // Set mouse region (if window resizes, we should alter this to reflect as well) 1162 const OIS::MouseState &mouseState = _get Singleton().mouse_->getMouseState();1063 const OIS::MouseState &mouseState = _getInstance().mouse_->getMouseState(); 1163 1064 mouseState.width = width; 1164 1065 mouseState.height = height; … … 1166 1067 } 1167 1068 1168 /**1169 @brief1170 Sets the input mode to either GUI, inGame or Buffer1171 @param mode1172 The new input mode1173 @remarks1174 Only has an affect if the mode actually changes1175 */1176 void InputManager::setInputState(const InputState state)1177 {1178 _getSingleton().stateRequest_ = state;1179 }1180 1181 /**1182 @brief1183 Returns the current input handling method1184 @return1185 The current input mode.1186 */1187 InputManager::InputState InputManager::getInputState()1188 {1189 return _getSingleton().state_;1190 }1191 1192 1069 void InputManager::storeKeyStroke(const std::string& name) 1193 1070 { 1194 setInputState(IS_NODETECT);1071 requestLeaveState("detector"); 1195 1072 COUT(0) << "Binding string \"" << bindingCommmandString_s << "\" on key '" << name << "'" << std::endl; 1196 1073 CommandExecutor::execute("config KeyBinder " + name + " " + bindingCommmandString_s, false); … … 1200 1077 { 1201 1078 bindingCommmandString_s = command; 1202 setInputState(IS_DETECT);1079 requestEnterState("detector"); 1203 1080 COUT(0) << "Press any button/key or move a mouse/joystick axis" << std::endl; 1204 1081 } … … 1206 1083 void InputManager::calibrate() 1207 1084 { 1208 _getSingleton().setInputState(IS_CALIBRATE);1085 requestEnterState("calibrator"); 1209 1086 } 1210 1087 1211 1088 void InputManager::tick(float dt) 1212 1089 { 1213 _get Singleton()._tick(dt);1214 } 1215 1216 // ###### KeyHandler######1090 _getInstance()._tick(dt); 1091 } 1092 1093 // ###### InputStates ###### 1217 1094 1218 1095 /** … … 1226 1103 True if added, false if name already existed. 1227 1104 */ 1228 bool InputManager:: addKeyHandler(KeyHandler* handler, const std::string& name)1229 { 1230 if ( !handler)1105 bool InputManager::_configureInputState(InputState* state, const std::string& name, int priority) 1106 { 1107 if (name == "") 1231 1108 return false; 1232 if (_getSingleton().keyHandlers_.find(name) == _getSingleton().keyHandlers_.end()) 1233 { 1234 _getSingleton().keyHandlers_[name] = handler; 1235 return true; 1109 if (_getInstance().inputStatesByName_.find(name) == _getInstance().inputStatesByName_.end()) 1110 { 1111 if (_getInstance().inputStatesByPriority_.find(priority) 1112 == _getInstance().inputStatesByPriority_.end()) 1113 { 1114 _getInstance().inputStatesByName_[name] = state; 1115 _getInstance().inputStatesByPriority_[priority] = state; 1116 state->setNumOfJoySticks(numberOfJoySticks()); 1117 state->setName(name); 1118 state->setPriority(priority); 1119 return true; 1120 } 1121 else 1122 { 1123 COUT(2) << "Warning: Could not add an InputState with the same priority '" 1124 << priority << "'." << std::endl; 1125 return false; 1126 } 1236 1127 } 1237 1128 else 1129 { 1130 COUT(2) << "Warning: Could not add an InputState with the same name '" << name << "'." << std::endl; 1238 1131 return false; 1132 } 1133 } 1134 1135 SimpleInputState* InputManager::createSimpleInputState(const std::string &name, int priority) 1136 { 1137 SimpleInputState* state = new SimpleInputState(); 1138 if (_getInstance()._configureInputState(state, name, priority)) 1139 return state; 1140 else 1141 { 1142 delete state; 1143 return 0; 1144 } 1145 } 1146 1147 ExtendedInputState* InputManager::createExtendedInputState(const std::string &name, int priority) 1148 { 1149 ExtendedInputState* state = new ExtendedInputState(); 1150 if (_getInstance()._configureInputState(state, name, priority)) 1151 return state; 1152 else 1153 { 1154 delete state; 1155 return 0; 1156 } 1239 1157 } 1240 1158 … … 1247 1165 True if removal was successful, false if name was not found. 1248 1166 */ 1249 bool InputManager::removeKeyHandler(const std::string &name) 1250 { 1251 disableKeyHandler(name); 1252 std::map<std::string, KeyHandler*>::iterator it = _getSingleton().keyHandlers_.find(name); 1253 if (it != _getSingleton().keyHandlers_.end()) 1254 { 1255 _getSingleton().keyHandlers_.erase(it); 1167 bool InputManager::destroyState(const std::string& name) 1168 { 1169 if (name == "empty" || name == "calibrator" || name == "detector") 1170 { 1171 COUT(2) << "InputManager: Removing the '" << name << "' state is not allowed!" << std::endl; 1172 return false; 1173 } 1174 std::map<std::string, InputState*>::iterator it = _getInstance().inputStatesByName_.find(name); 1175 if (it != _getInstance().inputStatesByName_.end()) 1176 { 1177 _getInstance()._destroyState((*it).second); 1256 1178 return true; 1257 1179 } 1258 else 1259 return false; 1180 return false; 1260 1181 } 1261 1182 … … 1268 1189 Pointer to the instance, 0 if name was not found. 1269 1190 */ 1270 KeyHandler* InputManager::getKeyHandler(const std::string& name)1271 { 1272 std::map<std::string, KeyHandler*>::iterator it = _getSingleton().keyHandlers_.find(name);1273 if (it != _get Singleton().keyHandlers_.end())1191 InputState* InputManager::getState(const std::string& name) 1192 { 1193 std::map<std::string, InputState*>::iterator it = _getInstance().inputStatesByName_.find(name); 1194 if (it != _getInstance().inputStatesByName_.end()) 1274 1195 return (*it).second; 1275 1196 else 1276 1197 return 0; 1198 } 1199 1200 /** 1201 @brief 1202 Returns the current input handling method 1203 @return 1204 The current input mode. 1205 */ 1206 InputState* InputManager::getCurrentState() 1207 { 1208 return (*_getInstance().activeStates_.rbegin()).second; 1277 1209 } 1278 1210 … … 1285 1217 False if name was not found, true otherwise. 1286 1218 */ 1287 bool InputManager:: enableKeyHandler(const std::string& name)1219 bool InputManager::requestEnterState(const std::string& name) 1288 1220 { 1289 1221 // get pointer from the map with all stored handlers 1290 std::map<std::string, KeyHandler*>::const_iterator mapIt = _getSingleton().keyHandlers_.find(name); 1291 if (mapIt == _getSingleton().keyHandlers_.end()) 1292 return false; 1293 // see whether the handler already is in the list 1294 for (std::vector<KeyHandler*>::iterator it = _getSingleton().activeKeyHandlers_.begin(); 1295 it != _getSingleton().activeKeyHandlers_.end(); it++) 1296 { 1297 if ((*it) == (*mapIt).second) 1298 { 1299 return true; 1300 } 1301 } 1302 _getSingleton().activeKeyHandlers_.push_back((*mapIt).second); 1303 _getSingleton().stateRequest_ = IS_CUSTOM; 1304 _getSingleton()._updateTickables(); 1305 return true; 1306 } 1307 1308 /** 1309 @brief 1310 Disables a specific key handler. 1311 @param name 1312 Unique name of the handler. 1313 @return 1314 False if name was not found, true otherwise. 1315 */ 1316 bool InputManager::disableKeyHandler(const std::string &name) 1222 std::map<std::string, InputState*>::const_iterator it = _getInstance().inputStatesByName_.find(name); 1223 if (it != _getInstance().inputStatesByName_.end()) 1224 { 1225 _getInstance().stateEnterRequests_.push_back((*it).second); 1226 return true; 1227 } 1228 return false; 1229 } 1230 1231 bool InputManager::requestLeaveState(const std::string& name) 1317 1232 { 1318 1233 // get pointer from the map with all stored handlers 1319 std::map<std::string, KeyHandler*>::const_iterator mapIt = _getSingleton().keyHandlers_.find(name); 1320 if (mapIt == _getSingleton().keyHandlers_.end()) 1321 return false; 1322 // look for the handler in the list 1323 for (std::vector<KeyHandler*>::iterator it = _getSingleton().activeKeyHandlers_.begin(); 1324 it != _getSingleton().activeKeyHandlers_.end(); it++) 1325 { 1326 if ((*it) == (*mapIt).second) 1327 { 1328 _getSingleton().activeKeyHandlers_.erase(it); 1329 _getSingleton().stateRequest_ = IS_CUSTOM; 1330 _getSingleton()._updateTickables(); 1331 return true; 1332 } 1333 } 1334 return true; 1335 } 1336 1337 /** 1338 @brief 1339 Checks whether a key handler is active 1340 @param name 1341 Unique name of the handler. 1342 @return 1343 False if key handler is not active or doesn't exist, true otherwise. 1344 */ 1345 bool InputManager::isKeyHandlerActive(const std::string& name) 1346 { 1347 // get pointer from the map with all stored handlers 1348 std::map<std::string, KeyHandler*>::const_iterator mapIt = _getSingleton().keyHandlers_.find(name); 1349 if (mapIt == _getSingleton().keyHandlers_.end()) 1350 return false; 1351 // see whether the handler already is in the list 1352 for (std::vector<KeyHandler*>::iterator it = _getSingleton().activeKeyHandlers_.begin(); 1353 it != _getSingleton().activeKeyHandlers_.end(); it++) 1354 { 1355 if ((*it) == (*mapIt).second) 1356 return true; 1234 std::map<std::string, InputState*>::const_iterator it = _getInstance().inputStatesByName_.find(name); 1235 if (it != _getInstance().inputStatesByName_.end()) 1236 { 1237 _getInstance().stateLeaveRequests_.push_back((*it).second); 1238 return true; 1357 1239 } 1358 1240 return false; 1359 1241 } 1360 1361 1362 // ###### MouseHandler ######1363 /**1364 @brief1365 Adds a new mouse handler.1366 @param handler1367 Pointer to the handler object.1368 @param name1369 Unique name of the handler.1370 @return1371 True if added, false if name already existed.1372 */1373 bool InputManager::addMouseHandler(MouseHandler* handler, const std::string& name)1374 {1375 if (!handler)1376 return false;1377 if (_getSingleton().mouseHandlers_.find(name) == _getSingleton().mouseHandlers_.end())1378 {1379 _getSingleton().mouseHandlers_[name] = handler;1380 return true;1381 }1382 else1383 return false;1384 }1385 1386 /**1387 @brief1388 Removes a Mouse handler from the list.1389 @param name1390 Unique name of the handler.1391 @return1392 True if removal was successful, false if name was not found.1393 */1394 bool InputManager::removeMouseHandler(const std::string &name)1395 {1396 disableMouseHandler(name);1397 std::map<std::string, MouseHandler*>::iterator it = _getSingleton().mouseHandlers_.find(name);1398 if (it != _getSingleton().mouseHandlers_.end())1399 {1400 _getSingleton().mouseHandlers_.erase(it);1401 return true;1402 }1403 else1404 return false;1405 }1406 1407 /**1408 @brief1409 Returns the pointer to a handler.1410 @param name1411 Unique name of the handler.1412 @return1413 Pointer to the instance, 0 if name was not found.1414 */1415 MouseHandler* InputManager::getMouseHandler(const std::string& name)1416 {1417 std::map<std::string, MouseHandler*>::iterator it = _getSingleton().mouseHandlers_.find(name);1418 if (it != _getSingleton().mouseHandlers_.end())1419 {1420 return (*it).second;1421 }1422 else1423 return 0;1424 }1425 1426 /**1427 @brief1428 Enables a specific mouse handler that has already been added.1429 @param name1430 Unique name of the handler.1431 @return1432 False if name was not found, true otherwise.1433 */1434 bool InputManager::enableMouseHandler(const std::string& name)1435 {1436 // get pointer from the map with all stored handlers1437 std::map<std::string, MouseHandler*>::const_iterator mapIt = _getSingleton().mouseHandlers_.find(name);1438 if (mapIt == _getSingleton().mouseHandlers_.end())1439 return false;1440 // see whether the handler already is in the list1441 for (std::vector<MouseHandler*>::iterator it = _getSingleton().activeMouseHandlers_.begin();1442 it != _getSingleton().activeMouseHandlers_.end(); it++)1443 {1444 if ((*it) == (*mapIt).second)1445 {1446 return true;1447 }1448 }1449 _getSingleton().activeMouseHandlers_.push_back((*mapIt).second);1450 _getSingleton().stateRequest_ = IS_CUSTOM;1451 _getSingleton()._updateTickables();1452 return true;1453 }1454 1455 /**1456 @brief1457 Disables a specific mouse handler.1458 @param name1459 Unique name of the handler.1460 @return1461 False if name was not found, true otherwise.1462 */1463 bool InputManager::disableMouseHandler(const std::string &name)1464 {1465 // get pointer from the map with all stored handlers1466 std::map<std::string, MouseHandler*>::const_iterator mapIt = _getSingleton().mouseHandlers_.find(name);1467 if (mapIt == _getSingleton().mouseHandlers_.end())1468 return false;1469 // look for the handler in the list1470 for (std::vector<MouseHandler*>::iterator it = _getSingleton().activeMouseHandlers_.begin();1471 it != _getSingleton().activeMouseHandlers_.end(); it++)1472 {1473 if ((*it) == (*mapIt).second)1474 {1475 _getSingleton().activeMouseHandlers_.erase(it);1476 _getSingleton().stateRequest_ = IS_CUSTOM;1477 _getSingleton()._updateTickables();1478 return true;1479 }1480 }1481 return true;1482 }1483 1484 /**1485 @brief1486 Checks whether a mouse handler is active1487 @param name1488 Unique name of the handler.1489 @return1490 False if key handler is not active or doesn't exist, true otherwise.1491 */1492 bool InputManager::isMouseHandlerActive(const std::string& name)1493 {1494 // get pointer from the map with all stored handlers1495 std::map<std::string, MouseHandler*>::const_iterator mapIt = _getSingleton().mouseHandlers_.find(name);1496 if (mapIt == _getSingleton().mouseHandlers_.end())1497 return false;1498 // see whether the handler already is in the list1499 for (std::vector<MouseHandler*>::iterator it = _getSingleton().activeMouseHandlers_.begin();1500 it != _getSingleton().activeMouseHandlers_.end(); it++)1501 {1502 if ((*it) == (*mapIt).second)1503 return true;1504 }1505 return false;1506 }1507 1508 1509 // ###### JoyStickHandler ######1510 1511 /**1512 @brief1513 Adds a new joy stick handler.1514 @param handler1515 Pointer to the handler object.1516 @param name1517 Unique name of the handler.1518 @return1519 True if added, false if name already existed.1520 */1521 bool InputManager::addJoyStickHandler(JoyStickHandler* handler, const std::string& name)1522 {1523 if (!handler)1524 return false;1525 if (_getSingleton().joyStickHandlers_.find(name) == _getSingleton().joyStickHandlers_.end())1526 {1527 _getSingleton().joyStickHandlers_[name] = handler;1528 return true;1529 }1530 else1531 return false;1532 }1533 1534 /**1535 @brief1536 Removes a JoyStick handler from the list.1537 @param name1538 Unique name of the handler.1539 @return1540 True if removal was successful, false if name was not found.1541 */1542 bool InputManager::removeJoyStickHandler(const std::string &name)1543 {1544 for (std::vector<OIS::JoyStick*>::iterator itstick = _getSingleton().joySticks_.begin();1545 itstick != _getSingleton().joySticks_.end(); itstick++)1546 disableJoyStickHandler(name, itstick - _getSingleton().joySticks_.begin());1547 1548 std::map<std::string, JoyStickHandler*>::iterator it = _getSingleton().joyStickHandlers_.find(name);1549 if (it != _getSingleton().joyStickHandlers_.end())1550 {1551 _getSingleton().joyStickHandlers_.erase(it);1552 return true;1553 }1554 else1555 return false;1556 }1557 1558 /**1559 @brief1560 Returns the pointer to a handler.1561 @param name1562 Unique name of the handler.1563 @return1564 Pointer to the instance, 0 if name was not found.1565 */1566 JoyStickHandler* InputManager::getJoyStickHandler(const std::string& name)1567 {1568 std::map<std::string, JoyStickHandler*>::iterator it = _getSingleton().joyStickHandlers_.find(name);1569 if (it != _getSingleton().joyStickHandlers_.end())1570 {1571 return (*it).second;1572 }1573 else1574 return 0;1575 }1576 1577 /**1578 @brief1579 Enables a specific joy stick handler that has already been added.1580 @param name1581 Unique name of the handler.1582 @return1583 False if name or id was not found, true otherwise.1584 */1585 bool InputManager::enableJoyStickHandler(const std::string& name, unsigned int ID)1586 {1587 // get handler pointer from the map with all stored handlers1588 std::map<std::string, JoyStickHandler*>::const_iterator handlerIt = _getSingleton().joyStickHandlers_.find(name);1589 if (handlerIt == _getSingleton().joyStickHandlers_.end())1590 return false;1591 1592 // check for existence of the ID1593 if (ID >= _getSingleton().joySticksSize_)1594 return false;1595 1596 // see whether the handler already is in the list1597 for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ID].begin();1598 it != _getSingleton().activeJoyStickHandlers_[ID].end(); it++)1599 {1600 if ((*it) == (*handlerIt).second)1601 {1602 return true;1603 }1604 }1605 _getSingleton().activeJoyStickHandlers_[ID].push_back((*handlerIt).second);1606 _getSingleton().stateRequest_ = IS_CUSTOM;1607 _getSingleton()._updateTickables();1608 return true;1609 }1610 1611 /**1612 @brief1613 Disables a specific joy stick handler.1614 @param name1615 Unique name of the handler.1616 @return1617 False if name or id was not found, true otherwise.1618 */1619 bool InputManager::disableJoyStickHandler(const std::string &name, unsigned int ID)1620 {1621 // get handler pointer from the map with all stored handlers1622 std::map<std::string, JoyStickHandler*>::const_iterator handlerIt = _getSingleton().joyStickHandlers_.find(name);1623 if (handlerIt == _getSingleton().joyStickHandlers_.end())1624 return false;1625 1626 // check for existence of the ID1627 if (ID >= _getSingleton().joySticksSize_)1628 return false;1629 1630 // look for the handler in the list1631 for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ID].begin();1632 it != _getSingleton().activeJoyStickHandlers_[ID].end(); it++)1633 {1634 if ((*it) == (*handlerIt).second)1635 {1636 _getSingleton().activeJoyStickHandlers_[ID].erase(it);1637 _getSingleton().stateRequest_ = IS_CUSTOM;1638 _getSingleton()._updateTickables();1639 return true;1640 }1641 }1642 return true;1643 }1644 1645 /**1646 @brief1647 Checks whether a joy stick handler is active1648 @param name1649 Unique name of the handler.1650 @return1651 False if key handler is not active or doesn't exist, true otherwise.1652 */1653 bool InputManager::isJoyStickHandlerActive(const std::string& name, unsigned int ID)1654 {1655 // get handler pointer from the map with all stored handlers1656 std::map<std::string, JoyStickHandler*>::const_iterator handlerIt = _getSingleton().joyStickHandlers_.find(name);1657 if (handlerIt == _getSingleton().joyStickHandlers_.end())1658 return false;1659 1660 // check for existence of the ID1661 if (ID >= _getSingleton().joySticksSize_)1662 return false;1663 1664 // see whether the handler already is in the list1665 for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ID].begin();1666 it != _getSingleton().activeJoyStickHandlers_[ID].end(); it++)1667 {1668 if ((*it) == (*handlerIt).second)1669 return true;1670 }1671 return false;1672 }1673 1674 1242 }
Note: See TracChangeset
for help on using the changeset viewer.