Changeset 1502 for code/trunk/src/core/InputManager.cc
- Timestamp:
- Jun 1, 2008, 3:54:20 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/core/InputManager.cc
r1349 r1502 34 34 35 35 #include "InputManager.h" 36 #include "util/Convert.h" 36 37 #include "CoreIncludes.h" 38 #include "ConfigValueIncludes.h" 37 39 #include "Debug.h" 38 40 #include "InputBuffer.h" 39 #include "InputHandler.h" 41 #include "KeyBinder.h" 42 #include "CommandExecutor.h" 43 #include "ConsoleCommand.h" 44 #include "Shell.h" 40 45 41 46 namespace orxonox 42 47 { 48 SetConsoleCommandShortcut(InputManager, keyBind); 49 SetConsoleCommandShortcut(InputManager, storeKeyStroke); 50 SetConsoleCommandShortcut(InputManager, calibrate); 51 43 52 // ############################### 44 53 // ### Internal Methods ### … … 53 62 inputSystem_(0), keyboard_(0), mouse_(0), 54 63 joySticksSize_(0), 55 state_(IS_UNINIT), stateRequest_(IS_UNINIT), 64 keyBinder_(0), keyDetector_(0), buffer_(0), calibratorCallback_(0), 65 state_(IS_UNINIT), stateRequest_(IS_UNINIT), savedState_(IS_UNINIT), 56 66 keyboardModifiers_(0) 57 67 { … … 129 139 if (mouse_) 130 140 { 131 //// hack the mouse position132 //((OIS::MouseState&)mouse_->getMouseState()).X.abs = windowWidth/2;133 //((OIS::MouseState&)mouse_->getMouseState()).Y.abs = windowHeight/2;134 141 setWindowExtents(windowWidth, windowHeight); 135 142 } … … 137 144 state_ = IS_NONE; 138 145 CCOUT(ORX_DEBUG) << "Initialising OIS components done." << std::endl; 146 147 // InputManager holds the input buffer --> create one and add it. 148 buffer_ = new InputBuffer(); 149 addKeyHandler(buffer_, "buffer"); 150 Shell::getInstance().setInputBuffer(buffer_); 151 152 keyBinder_ = new KeyBinder(); 153 keyBinder_->loadBindings(); 154 addKeyHandler(keyBinder_, "keybinder"); 155 addMouseHandler(keyBinder_, "keybinder"); 156 addJoyStickHandler(keyBinder_, "keybinder"); 157 158 keyDetector_ = new KeyDetector(); 159 keyDetector_->loadBindings(); 160 addKeyHandler(keyDetector_, "keydetector"); 161 addMouseHandler(keyDetector_, "keydetector"); 162 addJoyStickHandler(keyDetector_, "keydetector"); 163 164 calibratorCallback_ = new CalibratorCallback(); 165 addKeyHandler(calibratorCallback_, "calibratorcallback"); 166 167 setConfigValues(); 168 169 CCOUT(ORX_DEBUG) << "Initialising complete." << std::endl; 139 170 } 140 171 else … … 142 173 CCOUT(ORX_WARNING) << "Warning: OIS compoments already initialised, skipping" << std::endl; 143 174 } 144 145 // InputManager holds the input buffer --> create one and add it.146 addKeyHandler(new InputBuffer(), "buffer");147 148 KeyBinder* binder = new KeyBinder();149 binder->loadBindings();150 addKeyHandler(binder, "keybinder");151 addMouseHandler(binder, "keybinder");152 addJoyStickHandler(binder, "keybinder");153 154 // Read all the key bindings and assign them155 //if (!_loadBindings())156 // return false;157 158 CCOUT(ORX_DEBUG) << "Initialising complete." << std::endl;159 175 return true; 160 176 } … … 216 232 // register our listener in OIS. 217 233 mouse_->setEventCallback(this); 218 CCOUT(ORX_DEBUG) << "Created OIS keyboard" << std::endl;234 CCOUT(ORX_DEBUG) << "Created OIS mouse" << std::endl; 219 235 return true; 220 236 } … … 276 292 povStates_.resize(joySticksSize_); 277 293 sliderStates_.resize(joySticksSize_); 294 joySticksCalibration_.resize(joySticksSize_); 295 for (unsigned int iJoyStick = 0; iJoyStick < joySticksSize_; iJoyStick++) 296 { 297 // reset the calibration with default values 298 for (unsigned int i = 0; i < 24; i++) 299 { 300 joySticksCalibration_[iJoyStick].negativeCoeff[i] = 1.0f/32767.0f; 301 joySticksCalibration_[iJoyStick].positiveCoeff[i] = 1.0f/32768.0f; 302 joySticksCalibration_[iJoyStick].zeroStates[i] = 0; 303 } 304 } 278 305 return success; 279 306 } 280 307 281 308 /** 309 @brief Sets the configurable values. Use keybindings.ini as file.. 310 */ 311 void InputManager::setConfigValues() 312 { 313 if (joySticksSize_) 314 { 315 std::vector<MultiTypeMath> coeffPos; 316 std::vector<MultiTypeMath> coeffNeg; 317 std::vector<MultiTypeMath> zero; 318 coeffPos.resize(24); 319 coeffNeg.resize(24); 320 zero.resize(24); 321 for (unsigned int i = 0; i < 24; i++) 322 { 323 coeffPos[i] = 1.0f/32767.0f; 324 coeffNeg[i] = 1.0f/32768.0f; 325 zero[i] = 0; 326 } 327 328 ConfigValueContainer* cont = getIdentifier()->getConfigValueContainer("CoeffPos"); 329 if (!cont) 330 { 331 cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), "CoeffPos", coeffPos); 332 getIdentifier()->addConfigValueContainer("CoeffPos", cont); 333 } 334 cont->getValue(&coeffPos); 335 336 cont = getIdentifier()->getConfigValueContainer("CoeffNeg"); 337 if (!cont) 338 { 339 cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), "CoeffNeg", coeffNeg); 340 getIdentifier()->addConfigValueContainer("CoeffNeg", cont); 341 } 342 cont->getValue(&coeffNeg); 343 344 cont = getIdentifier()->getConfigValueContainer("Zero"); 345 if (!cont) 346 { 347 cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), "Zero", zero); 348 getIdentifier()->addConfigValueContainer("Zero", cont); 349 } 350 cont->getValue(&zero); 351 352 // copy values to our own variables 353 for (unsigned int i = 0; i < 24; i++) 354 { 355 joySticksCalibration_[0].positiveCoeff[i] = coeffPos[i]; 356 joySticksCalibration_[0].negativeCoeff[i] = coeffNeg[i]; 357 joySticksCalibration_[0].zeroStates[i] = zero[i]; 358 } 359 } 360 } 361 362 /** 282 363 @brief Destroys all the created input devices and sets the InputManager to construction state. 283 364 */ … … 288 369 CCOUT(ORX_DEBUG) << "Destroying ..." << std::endl; 289 370 290 if (keyHandlers_.find("buffer") != keyHandlers_.end()) 291 delete keyHandlers_["buffer"]; 292 293 if (keyHandlers_.find("keybinder") != keyHandlers_.end()) 294 delete keyHandlers_["keybinder"]; 371 if (buffer_) 372 delete buffer_; 373 374 if (keyBinder_) 375 delete keyBinder_; 376 377 if (keyDetector_) 378 delete keyDetector_; 379 380 if (calibratorCallback_) 381 delete calibratorCallback_; 295 382 296 383 keyHandlers_.clear(); … … 301 388 _destroyMouse(); 302 389 _destroyJoySticks(); 390 391 activeHandlers_.clear(); 303 392 304 393 // inputSystem_ can never be 0, or else the code is mistaken … … 355 444 activeJoyStickHandlers_.clear(); 356 445 joyStickButtonsDown_.clear(); 446 povStates_.clear(); 447 sliderStates_.clear(); 448 joySticksCalibration_.clear(); 357 449 } 358 450 CCOUT(ORX_DEBUG) << "Joy sticks destroyed." << std::endl; 359 451 } 360 452 453 void InputManager::_saveState() 454 { 455 savedHandlers_.activeHandlers_ = activeHandlers_; 456 savedHandlers_.activeJoyStickHandlers_ = activeJoyStickHandlers_; 457 savedHandlers_.activeKeyHandlers_ = activeKeyHandlers_; 458 savedHandlers_.activeMouseHandlers_ = activeMouseHandlers_; 459 } 460 461 void InputManager::_restoreState() 462 { 463 activeHandlers_ = savedHandlers_.activeHandlers_; 464 activeJoyStickHandlers_ = savedHandlers_.activeJoyStickHandlers_; 465 activeKeyHandlers_ = savedHandlers_.activeKeyHandlers_; 466 activeMouseHandlers_ = savedHandlers_.activeMouseHandlers_; 467 } 468 361 469 void InputManager::_updateTickables() 362 470 { 363 // we can use a setto have a list of unique pointers (an object can implement all 3 handlers)364 std:: set<InputTickable*> tempSet;471 // we can use a map to have a list of unique pointers (an object can implement all 3 handlers) 472 std::map<InputTickable*, HandlerState> tempSet; 365 473 for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++) 366 tempSet .insert(activeKeyHandlers_[iHandler]);474 tempSet[activeKeyHandlers_[iHandler]].joyStick = true; 367 475 for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++) 368 tempSet .insert(activeMouseHandlers_[iHandler]);476 tempSet[activeMouseHandlers_[iHandler]].mouse = true; 369 477 for (unsigned int iJoyStick = 0; iJoyStick < joySticksSize_; iJoyStick++) 370 478 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 371 tempSet .insert(activeJoyStickHandlers_[iJoyStick][iHandler]);372 373 // copy the content of the setback to the actual vector479 tempSet[activeJoyStickHandlers_[iJoyStick][iHandler]].joyStick = true; 480 481 // copy the content of the map back to the actual vector 374 482 activeHandlers_.clear(); 375 for (std::set<InputTickable*>::const_iterator itHandler = tempSet.begin(); itHandler != tempSet.end(); itHandler++) 376 activeHandlers_.push_back(*itHandler); 483 for (std::map<InputTickable*, HandlerState>::const_iterator itHandler = tempSet.begin(); 484 itHandler != tempSet.end(); itHandler++) 485 activeHandlers_.push_back(std::pair<InputTickable*, HandlerState>((*itHandler).first, (*itHandler).second)); 377 486 } 378 487 … … 392 501 return; 393 502 394 // reset the game if it has changed395 503 if (state_ != stateRequest_) 396 504 { 397 if (stateRequest_ != IS_CUSTOM) 398 { 505 InputState sr = stateRequest_; 506 switch (sr) 507 { 508 case IS_NORMAL: 399 509 activeKeyHandlers_.clear(); 400 510 activeMouseHandlers_.clear(); … … 402 512 activeJoyStickHandlers_[i].clear(); 403 513 404 switch (stateRequest_) 514 // normal play mode 515 // note: we assume that the handlers exist since otherwise, something's wrong anyway. 516 enableKeyHandler("keybinder"); 517 enableMouseHandler("keybinder"); 518 enableJoyStickHandler("keybinder", 0); 519 stateRequest_ = IS_NORMAL; 520 state_ = IS_NORMAL; 521 break; 522 523 case IS_GUI: 524 state_ = IS_GUI; 525 break; 526 527 case IS_CONSOLE: 528 activeKeyHandlers_.clear(); 529 activeMouseHandlers_.clear(); 530 for (unsigned int i = 0; i < joySticksSize_; i++) 531 activeJoyStickHandlers_[i].clear(); 532 533 enableMouseHandler("keybinder"); 534 enableJoyStickHandler("keybinder", 0); 535 enableKeyHandler("buffer"); 536 stateRequest_ = IS_CONSOLE; 537 state_ = IS_CONSOLE; 538 break; 539 540 case IS_DETECT: 541 savedState_ = state_; 542 _saveState(); 543 544 activeKeyHandlers_.clear(); 545 activeMouseHandlers_.clear(); 546 for (unsigned int i = 0; i < joySticksSize_; i++) 547 activeJoyStickHandlers_[i].clear(); 548 549 enableKeyHandler("keydetector"); 550 enableMouseHandler("keydetector"); 551 enableJoyStickHandler("keydetector", 0); 552 553 stateRequest_ = IS_DETECT; 554 state_ = IS_DETECT; 555 break; 556 557 case IS_NODETECT: 558 _restoreState(); 559 keysDown_.clear(); 560 mouseButtonsDown_.clear(); 561 joyStickButtonsDown_[0].clear(); 562 state_ = IS_NODETECT; 563 stateRequest_ = savedState_; 564 break; 565 566 case IS_CALIBRATE: 567 if (joySticksSize_) 405 568 { 406 case IS_NORMAL: 407 // normal play mode 408 // note: we assume that the handlers exist since otherwise, something's wrong anyway. 409 enableKeyHandler("keybinder"); 410 enableMouseHandler("keybinder"); 411 enableMouseHandler("SpaceShip"); 412 enableJoyStickHandler("keybinder", 0); 413 break; 414 415 case IS_GUI: 416 // TODO: do stuff 417 break; 418 419 case IS_CONSOLE: 420 enableMouseHandler("keybinder"); 421 enableMouseHandler("SpaceShip"); 422 enableJoyStickHandler("keybinder", 0); 423 enableKeyHandler("buffer"); 424 break; 425 426 default: 427 break; 569 savedState_ = _getSingleton().state_; 570 for (unsigned int i = 0; i < 24; i++) 571 { 572 marginalsMax_[i] = INT_MIN; 573 marginalsMin_[i] = INT_MAX; 574 } 575 COUT(0) << "Move all joy stick axes in all directions a few times. " 576 << "Then put all axes in zero state and hit enter." << std::endl; 577 578 savedState_ = state_; 579 _saveState(); 580 581 activeKeyHandlers_.clear(); 582 activeMouseHandlers_.clear(); 583 for (unsigned int i = 0; i < joySticksSize_; i++) 584 activeJoyStickHandlers_[i].clear(); 585 586 enableKeyHandler("calibratorcallback"); 587 stateRequest_ = IS_CALIBRATE; 588 state_ = IS_CALIBRATE; 428 589 } 429 state_ = stateRequest_; 590 else 591 { 592 COUT(3) << "Connot calibrate, no joy stick found!" << std::endl; 593 stateRequest_ = state_; 594 } 595 break; 596 597 case IS_NOCALIBRATE: 598 _completeCalibration(); 599 _restoreState(); 600 keyBinder_->resetJoyStickAxes(); 601 state_ = IS_NOCALIBRATE; 602 stateRequest_ = savedState_; 603 break; 604 605 case IS_NONE: 606 activeKeyHandlers_.clear(); 607 activeMouseHandlers_.clear(); 608 for (unsigned int i = 0; i < joySticksSize_; i++) 609 activeJoyStickHandlers_[i].clear(); 610 state_ = IS_NONE; 611 612 default: 613 break; 430 614 } 431 615 } … … 439 623 joySticks_[i]->capture(); 440 624 441 442 // call all the handlers for the held key events 443 for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++) 444 for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++) 445 activeKeyHandlers_[iHandler]->keyHeld(KeyEvent(keysDown_[iKey], keyboardModifiers_)); 446 447 // call all the handlers for the held mouse button events 448 for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++) 449 for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++) 450 activeMouseHandlers_[iHandler]->mouseButtonHeld(mouseButtonsDown_[iButton]); 451 452 // call all the handlers for the held joy stick button events 453 for (unsigned int iJoyStick = 0; iJoyStick < joySticksSize_; iJoyStick++) 454 for (unsigned int iButton = 0; iButton < joyStickButtonsDown_[iJoyStick].size(); iButton++) 455 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 456 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonHeld(iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]); 457 458 459 // call the ticks 625 if (state_ != IS_CALIBRATE) 626 { 627 // call all the handlers for the held key events 628 for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++) 629 for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++) 630 activeKeyHandlers_[iHandler]->keyHeld(KeyEvent(keysDown_[iKey], keyboardModifiers_)); 631 632 // call all the handlers for the held mouse button events 633 for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++) 634 for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++) 635 activeMouseHandlers_[iHandler]->mouseButtonHeld(mouseButtonsDown_[iButton]); 636 637 // call all the handlers for the held joy stick button events 638 for (unsigned int iJoyStick = 0; iJoyStick < joySticksSize_; iJoyStick++) 639 for (unsigned int iButton = 0; iButton < joyStickButtonsDown_[iJoyStick].size(); iButton++) 640 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 641 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonHeld(iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]); 642 } 643 644 // call the ticks for the handlers (need to be treated specially) 460 645 for (unsigned int iHandler = 0; iHandler < activeHandlers_.size(); iHandler++) 461 activeHandlers_[iHandler]->tick(dt); 646 activeHandlers_[iHandler].first->tickInput(dt, activeHandlers_[iHandler].second); 647 } 648 649 void InputManager::_completeCalibration() 650 { 651 for (unsigned int i = 0; i < 24; i++) 652 { 653 // positive coefficient 654 if (marginalsMax_[i] == INT_MIN) 655 marginalsMax_[i] = 32767; 656 // coefficients 657 if (marginalsMax_[i] - joySticksCalibration_[0].zeroStates[i]) 658 joySticksCalibration_[0].positiveCoeff[i] = 1.0f/(marginalsMax_[i] - joySticksCalibration_[0].zeroStates[i]); 659 else 660 joySticksCalibration_[0].positiveCoeff[i] = 1.0f; 661 662 // config value 663 ConfigValueContainer* cont = getIdentifier()->getConfigValueContainer("CoeffPos"); 664 assert(cont); 665 cont->set(i, joySticksCalibration_[0].positiveCoeff[i]); 666 667 // negative coefficient 668 if (marginalsMin_[i] == INT_MAX) 669 marginalsMin_[i] = -32768; 670 // coefficients 671 if (marginalsMin_[i] - joySticksCalibration_[0].zeroStates[i]) 672 joySticksCalibration_[0].negativeCoeff[i] = -1.0f/(marginalsMin_[i] - joySticksCalibration_[0].zeroStates[i]); 673 else 674 joySticksCalibration_[0].negativeCoeff[i] = 1.0f; 675 // config value 676 cont = getIdentifier()->getConfigValueContainer("CoeffNeg"); 677 assert(cont); 678 cont->set(i, joySticksCalibration_[0].negativeCoeff[i]); 679 680 // zero states 681 if (i < 8) 682 { 683 if (!(i & 1)) 684 joySticksCalibration_[0].zeroStates[i] = joySticks_[0]->getJoyStickState().mSliders[i/2].abX; 685 else 686 joySticksCalibration_[0].zeroStates[i] = joySticks_[0]->getJoyStickState().mSliders[i/2].abY; 687 } 688 else 689 { 690 if (i - 8 < joySticks_[0]->getJoyStickState().mAxes.size()) 691 joySticksCalibration_[0].zeroStates[i] = joySticks_[0]->getJoyStickState().mAxes[i - 8].abs; 692 else 693 joySticksCalibration_[0].zeroStates[i] = 0; 694 } 695 // config value 696 cont = getIdentifier()->getConfigValueContainer("Zero"); 697 assert(cont); 698 cont->set(i, joySticksCalibration_[0].zeroStates[i]); 699 } 462 700 } 463 701 … … 594 832 // ###### Joy Stick Events ###### 595 833 596 bool InputManager::buttonPressed(const OIS::JoyStickEvent &arg, int button)834 inline unsigned int InputManager::_getJoystick(const OIS::JoyStickEvent& arg) 597 835 { 598 836 // use the device to identify which one called the method … … 600 838 unsigned int iJoyStick = 0; 601 839 while (joySticks_[iJoyStick] != joyStick) 840 { 602 841 iJoyStick++; 842 if (iJoyStick == joySticksSize_) 843 { 844 CCOUT(3) << "Unknown joystick fired an event. This means there is a bug somewhere! Aborting." << std::endl; 845 abort(); 846 } 847 } 848 return iJoyStick; 849 } 850 851 bool InputManager::buttonPressed(const OIS::JoyStickEvent &arg, int button) 852 { 853 unsigned int iJoyStick = _getJoystick(arg); 603 854 604 855 // check whether the button already is in the list (can happen when focus was lost) 605 std::vector<int> buttonsDown = joyStickButtonsDown_[iJoyStick];856 std::vector<int>& buttonsDown = joyStickButtonsDown_[iJoyStick]; 606 857 unsigned int iButton = 0; 607 858 while (iButton < buttonsDown.size() && buttonsDown[iButton] != button) … … 618 869 bool InputManager::buttonReleased(const OIS::JoyStickEvent &arg, int button) 619 870 { 620 // use the device to identify which one called the method 621 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 622 unsigned int iJoyStick = 0; 623 while (joySticks_[iJoyStick] != joyStick) 624 iJoyStick++; 871 unsigned int iJoyStick = _getJoystick(arg); 625 872 626 873 // remove the button from the joyStickButtonsDown_ list 627 std::vector<int> buttonsDown = joyStickButtonsDown_[iJoyStick];874 std::vector<int>& buttonsDown = joyStickButtonsDown_[iJoyStick]; 628 875 for (unsigned int iButton = 0; iButton < buttonsDown.size(); iButton++) 629 876 { … … 641 888 } 642 889 890 void InputManager::_fireAxis(unsigned int iJoyStick, int axis, int value) 891 { 892 if (state_ == IS_CALIBRATE) 893 { 894 if (value > marginalsMax_[axis]) 895 marginalsMax_[axis] = value; 896 if (value < marginalsMin_[axis]) 897 marginalsMin_[axis] = value; 898 } 899 else 900 { 901 float fValue = value - joySticksCalibration_[iJoyStick].zeroStates[axis]; 902 if (fValue > 0.0f) 903 fValue *= joySticksCalibration_[iJoyStick].positiveCoeff[axis]; 904 else 905 fValue *= joySticksCalibration_[iJoyStick].negativeCoeff[axis]; 906 907 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 908 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, axis, fValue); 909 } 910 } 911 643 912 bool InputManager::axisMoved(const OIS::JoyStickEvent &arg, int axis) 644 913 { 645 //CCOUT(3) << arg.state.mAxes[axis].abs << std::endl; 646 // use the device to identify which one called the method 647 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 648 unsigned int iJoyStick = 0; 649 while (joySticks_[iJoyStick] != joyStick) 650 iJoyStick++; 914 //if (arg.state.mAxes[axis].abs > 10000 || arg.state.mAxes[axis].abs < -10000) 915 //{ CCOUT(3) << "axis " << axis << " moved" << arg.state.mAxes[axis].abs << std::endl;} 916 917 unsigned int iJoyStick = _getJoystick(arg); 651 918 652 919 // keep in mind that the first 8 axes are reserved for the sliders 653 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 654 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, axis + 8, arg.state.mAxes[axis].abs); 920 _fireAxis(iJoyStick, axis + 8, arg.state.mAxes[axis].abs); 655 921 656 922 return true; … … 659 925 bool InputManager::sliderMoved(const OIS::JoyStickEvent &arg, int id) 660 926 { 927 //if (arg.state.mSliders[id].abX > 10000 || arg.state.mSliders[id].abX < -10000) 928 //{CCOUT(3) << "slider " << id << " moved" << arg.state.mSliders[id].abX << std::endl;} 661 929 //CCOUT(3) << arg.state.mSliders[id].abX << "\t |" << arg.state.mSliders[id].abY << std::endl; 662 // use the device to identify which one called the method 663 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 664 unsigned int iJoyStick = 0; 665 while (joySticks_[iJoyStick] != joyStick) 666 iJoyStick++; 930 931 unsigned int iJoyStick = _getJoystick(arg); 667 932 668 933 if (sliderStates_[iJoyStick].sliderStates[id].x != arg.state.mSliders[id].abX) 669 { 670 // slider X axis changed 671 sliderStates_[iJoyStick].sliderStates[id].x = arg.state.mSliders[id].abX; 672 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 673 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, id * 2, arg.state.mSliders[id].abX); 674 } 934 _fireAxis(iJoyStick, id * 2, arg.state.mSliders[id].abX); 675 935 else if (sliderStates_[iJoyStick].sliderStates[id].y != arg.state.mSliders[id].abY) 676 { 677 // slider Y axis changed 678 sliderStates_[iJoyStick].sliderStates[id].y = arg.state.mSliders[id].abY; 679 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 680 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, id * 2 + 1, arg.state.mSliders[id].abY); 681 } 936 _fireAxis(iJoyStick, id * 2 + 1, arg.state.mSliders[id].abY); 682 937 683 938 return true; … … 686 941 bool InputManager::povMoved(const OIS::JoyStickEvent &arg, int id) 687 942 { 688 // use the device to identify which one called the method 689 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 690 unsigned int iJoyStick = 0; 691 while (joySticks_[iJoyStick] != joyStick) 692 iJoyStick++; 943 unsigned int iJoyStick = _getJoystick(arg); 693 944 694 945 // translate the POV into 8 simple buttons … … 702 953 if (lastState & OIS::Pov::West) 703 954 buttonReleased(arg, 32 + id * 4 + 3); 704 955 705 956 povStates_[iJoyStick].povStates[id] = arg.state.mPOV[id].direction; 957 706 958 int currentState = povStates_[iJoyStick][id]; 707 959 if (currentState & OIS::Pov::North) … … 719 971 /*bool InputManager::vector3Moved(const OIS::JoyStickEvent &arg, int id) 720 972 { 721 // use the device to identify which one called the method 722 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 723 unsigned int iJoyStick = 0; 724 while (joySticks_[iJoyStick] != joyStick) 725 iJoyStick++; 973 unsigned int iJoyStick = _getJoystick(arg); 726 974 727 975 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) … … 737 985 // ################################ 738 986 987 std::string InputManager::bindingCommmandString_s = ""; 988 739 989 bool InputManager::initialise(const size_t windowHnd, int windowWidth, int windowHeight, 740 990 bool createKeyboard, bool createMouse, bool createJoySticks) … … 780 1030 } 781 1031 782 bool InputManager::isKeyDown(KeyCode::Enum key)1032 /*bool InputManager::isKeyDown(KeyCode::Enum key) 783 1033 { 784 1034 if (_getSingleton().keyboard_) … … 786 1036 else 787 1037 return false; 788 } 789 790 bool InputManager::isModifierDown(KeyboardModifier::Enum modifier)1038 }*/ 1039 1040 /*bool InputManager::isModifierDown(KeyboardModifier::Enum modifier) 791 1041 { 792 1042 if (_getSingleton().keyboard_) … … 794 1044 else 795 1045 return false; 796 } 1046 }*/ 797 1047 798 1048 /*const MouseState InputManager::getMouseState() … … 811 1061 return JoyStickState(); 812 1062 }*/ 813 814 1063 815 1064 void InputManager::destroy() … … 870 1119 } 871 1120 1121 void InputManager::storeKeyStroke(const std::string& name) 1122 { 1123 setInputState(IS_NODETECT); 1124 COUT(0) << "Binding string \"" << bindingCommmandString_s << "\" on key '" << name << "'" << std::endl; 1125 CommandExecutor::execute("config KeyBinder " + name + " " + bindingCommmandString_s, false); 1126 } 1127 1128 void InputManager::keyBind(const std::string& command) 1129 { 1130 bindingCommmandString_s = command; 1131 setInputState(IS_DETECT); 1132 COUT(0) << "Press any button/key or move a mouse/joystick axis" << std::endl; 1133 } 1134 1135 void InputManager::calibrate() 1136 { 1137 _getSingleton().setInputState(IS_CALIBRATE); 1138 } 872 1139 873 1140 // ###### KeyHandler ######
Note: See TracChangeset
for help on using the changeset viewer.