Changeset 1349 for code/trunk/src/core/InputManager.cc
- Timestamp:
- May 21, 2008, 9:07:08 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/core/InputManager.cc
r1293 r1349 98 98 windowHndStr << (unsigned int)windowHnd; 99 99 paramList.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); 100 100 //paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_NONEXCLUSIVE"))); 101 //paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_FOREGROUND"))); 101 102 //#if defined OIS_LINUX_PLATFORM 102 103 // paramList.insert(std::make_pair(std::string("XAutoRepeatOn"), std::string("true"))); … … 126 127 127 128 // Set mouse/joystick region 128 setWindowExtents(windowWidth, windowHeight); 129 if (mouse_) 130 { 131 //// hack the mouse position 132 //((OIS::MouseState&)mouse_->getMouseState()).X.abs = windowWidth/2; 133 //((OIS::MouseState&)mouse_->getMouseState()).Y.abs = windowHeight/2; 134 setWindowExtents(windowWidth, windowHeight); 135 } 129 136 130 137 state_ = IS_NONE; … … 267 274 activeJoyStickHandlers_.resize(joySticksSize_); 268 275 joyStickButtonsDown_.resize(joySticksSize_); 276 povStates_.resize(joySticksSize_); 277 sliderStates_.resize(joySticksSize_); 269 278 return success; 270 279 } … … 350 359 } 351 360 361 void InputManager::_updateTickables() 362 { 363 // we can use a set to have a list of unique pointers (an object can implement all 3 handlers) 364 std::set<InputTickable*> tempSet; 365 for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++) 366 tempSet.insert(activeKeyHandlers_[iHandler]); 367 for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++) 368 tempSet.insert(activeMouseHandlers_[iHandler]); 369 for (unsigned int iJoyStick = 0; iJoyStick < joySticksSize_; iJoyStick++) 370 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 371 tempSet.insert(activeJoyStickHandlers_[iJoyStick][iHandler]); 372 373 // copy the content of the set back to the actual vector 374 activeHandlers_.clear(); 375 for (std::set<InputTickable*>::const_iterator itHandler = tempSet.begin(); itHandler != tempSet.end(); itHandler++) 376 activeHandlers_.push_back(*itHandler); 377 } 378 352 379 353 380 // ################################# … … 380 407 // normal play mode 381 408 // note: we assume that the handlers exist since otherwise, something's wrong anyway. 382 activeKeyHandlers_.push_back(keyHandlers_["keybinder"]); 383 activeMouseHandlers_.push_back(mouseHandlers_["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"]); 409 enableKeyHandler("keybinder"); 410 enableMouseHandler("keybinder"); 411 enableMouseHandler("SpaceShip"); 412 enableJoyStickHandler("keybinder", 0); 388 413 break; 389 414 390 415 case IS_GUI: 391 // FIXME: do stuff416 // TODO: do stuff 392 417 break; 393 418 394 419 case IS_CONSOLE: 395 activeMouseHandlers_.push_back(mouseHandlers_["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"]); 400 401 activeKeyHandlers_.push_back(keyHandlers_["buffer"]); 420 enableMouseHandler("keybinder"); 421 enableMouseHandler("SpaceShip"); 422 enableJoyStickHandler("keybinder", 0); 423 enableKeyHandler("buffer"); 402 424 break; 403 425 … … 426 448 for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++) 427 449 for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++) 428 activeMouseHandlers_[iHandler]->mouseButtonHeld(mouse _->getMouseState(), mouseButtonsDown_[iButton]);450 activeMouseHandlers_[iHandler]->mouseButtonHeld(mouseButtonsDown_[iButton]); 429 451 430 452 // call all the handlers for the held joy stick button events … … 432 454 for (unsigned int iButton = 0; iButton < joyStickButtonsDown_[iJoyStick].size(); iButton++) 433 455 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 434 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonHeld( 435 JoyStickState(joySticks_[iJoyStick]->getJoyStickState(), iJoyStick), joyStickButtonsDown_[iJoyStick][iButton]); 456 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonHeld(iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]); 457 458 459 // call the ticks 460 for (unsigned int iHandler = 0; iHandler < activeHandlers_.size(); iHandler++) 461 activeHandlers_[iHandler]->tick(dt); 436 462 } 437 463 … … 508 534 { 509 535 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 510 activeMouseHandlers_[i]->mouseMoved(e.state); 536 activeMouseHandlers_[i]->mouseMoved(IntVector2(e.state.X.abs, e.state.Y.abs), 537 IntVector2(e.state.X.rel, e.state.Y.rel), IntVector2(e.state.width, e.state.height)); 511 538 } 512 539 … … 515 542 { 516 543 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 517 activeMouseHandlers_[i]->mouseScrolled(e.state );544 activeMouseHandlers_[i]->mouseScrolled(e.state.Z.abs, e.state.Z.rel); 518 545 } 519 546 … … 536 563 537 564 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 538 activeMouseHandlers_[i]->mouseButtonPressed( e.state,(MouseButton::Enum)id);565 activeMouseHandlers_[i]->mouseButtonPressed((MouseButton::Enum)id); 539 566 540 567 return true; … … 559 586 560 587 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 561 activeMouseHandlers_[i]->mouseButtonReleased( e.state,(MouseButton::Enum)id);588 activeMouseHandlers_[i]->mouseButtonReleased((MouseButton::Enum)id); 562 589 563 590 return true; … … 584 611 585 612 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 586 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonPressed( JoyStickState(arg.state, iJoyStick), button);613 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonPressed(iJoyStick, button); 587 614 588 615 return true; … … 609 636 610 637 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 611 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonReleased( JoyStickState(arg.state, iJoyStick), button);638 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonReleased(iJoyStick, button); 612 639 613 640 return true; … … 616 643 bool InputManager::axisMoved(const OIS::JoyStickEvent &arg, int axis) 617 644 { 645 //CCOUT(3) << arg.state.mAxes[axis].abs << std::endl; 618 646 // use the device to identify which one called the method 619 647 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; … … 622 650 iJoyStick++; 623 651 652 // keep in mind that the first 8 axes are reserved for the sliders 624 653 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 625 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved( JoyStickState(arg.state, iJoyStick), axis);654 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, axis + 8, arg.state.mAxes[axis].abs); 626 655 627 656 return true; … … 630 659 bool InputManager::sliderMoved(const OIS::JoyStickEvent &arg, int id) 631 660 { 661 //CCOUT(3) << arg.state.mSliders[id].abX << "\t |" << arg.state.mSliders[id].abY << std::endl; 632 662 // use the device to identify which one called the method 633 663 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; … … 636 666 iJoyStick++; 637 667 638 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 639 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickSliderMoved(JoyStickState(arg.state, iJoyStick), id); 668 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 } 675 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 } 640 682 641 683 return true; … … 650 692 iJoyStick++; 651 693 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) 694 // translate the POV into 8 simple buttons 695 int lastState = povStates_[iJoyStick][id]; 696 if (lastState & OIS::Pov::North) 697 buttonReleased(arg, 32 + id * 4 + 0); 698 if (lastState & OIS::Pov::South) 699 buttonReleased(arg, 32 + id * 4 + 1); 700 if (lastState & OIS::Pov::East) 701 buttonReleased(arg, 32 + id * 4 + 2); 702 if (lastState & OIS::Pov::West) 703 buttonReleased(arg, 32 + id * 4 + 3); 704 705 povStates_[iJoyStick].povStates[id] = arg.state.mPOV[id].direction; 706 int currentState = povStates_[iJoyStick][id]; 707 if (currentState & OIS::Pov::North) 708 buttonPressed(arg, 32 + id * 4 + 0); 709 if (currentState & OIS::Pov::South) 710 buttonPressed(arg, 32 + id * 4 + 1); 711 if (currentState & OIS::Pov::East) 712 buttonPressed(arg, 32 + id * 4 + 2); 713 if (currentState & OIS::Pov::West) 714 buttonPressed(arg, 32 + id * 4 + 3); 715 716 return true; 717 } 718 719 /*bool InputManager::vector3Moved(const OIS::JoyStickEvent &arg, int id) 659 720 { 660 721 // use the device to identify which one called the method … … 668 729 669 730 return true; 670 } 731 }*/ 671 732 672 733 … … 735 796 } 736 797 737 const MouseState InputManager::getMouseState()798 /*const MouseState InputManager::getMouseState() 738 799 { 739 800 if (_getSingleton().mouse_) … … 741 802 else 742 803 return MouseState(); 743 } 744 745 const JoyStickState InputManager::getJoyStickState(unsigned int ID)804 }*/ 805 806 /*const JoyStickState InputManager::getJoyStickState(unsigned int ID) 746 807 { 747 808 if (ID < _getSingleton().joySticksSize_) … … 749 810 else 750 811 return JoyStickState(); 751 } 812 }*/ 752 813 753 814 … … 882 943 if ((*it) == (*mapIt).second) 883 944 { 884 _getSingleton().stateRequest_ = IS_CUSTOM;885 945 return true; 886 946 } … … 888 948 _getSingleton().activeKeyHandlers_.push_back((*mapIt).second); 889 949 _getSingleton().stateRequest_ = IS_CUSTOM; 950 _getSingleton()._updateTickables(); 890 951 return true; 891 952 } … … 910 971 _getSingleton().activeKeyHandlers_.erase(it); 911 972 _getSingleton().stateRequest_ = IS_CUSTOM; 973 _getSingleton()._updateTickables(); 912 974 return true; 913 975 } 914 976 } 915 _getSingleton().stateRequest_ = IS_CUSTOM;916 977 return true; 917 978 } … … 1010 1071 if ((*it) == (*mapIt).second) 1011 1072 { 1012 _getSingleton().stateRequest_ = IS_CUSTOM;1013 1073 return true; 1014 1074 } … … 1016 1076 _getSingleton().activeMouseHandlers_.push_back((*mapIt).second); 1017 1077 _getSingleton().stateRequest_ = IS_CUSTOM; 1078 _getSingleton()._updateTickables(); 1018 1079 return true; 1019 1080 } … … 1038 1099 _getSingleton().activeMouseHandlers_.erase(it); 1039 1100 _getSingleton().stateRequest_ = IS_CUSTOM; 1101 _getSingleton()._updateTickables(); 1040 1102 return true; 1041 1103 } 1042 1104 } 1043 _getSingleton().stateRequest_ = IS_CUSTOM;1044 1105 return true; 1045 1106 } … … 1147 1208 if ((*it) == (*handlerIt).second) 1148 1209 { 1149 _getSingleton().stateRequest_ = IS_CUSTOM;1150 1210 return true; 1151 1211 } … … 1153 1213 _getSingleton().activeJoyStickHandlers_[ID].push_back((*handlerIt).second); 1154 1214 _getSingleton().stateRequest_ = IS_CUSTOM; 1215 _getSingleton()._updateTickables(); 1155 1216 return true; 1156 1217 } … … 1180 1241 _getSingleton().activeJoyStickHandlers_[ID].erase(it); 1181 1242 _getSingleton().stateRequest_ = IS_CUSTOM; 1243 _getSingleton()._updateTickables(); 1182 1244 return true; 1183 1245 }
Note: See TracChangeset
for help on using the changeset viewer.