Changeset 1323 for code/branches/input/src/core/InputManager.cc
- Timestamp:
- May 19, 2008, 10:50:09 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/input/src/core/InputManager.cc
r1293 r1323 267 267 activeJoyStickHandlers_.resize(joySticksSize_); 268 268 joyStickButtonsDown_.resize(joySticksSize_); 269 povStates_.resize(joySticksSize_); 270 sliderStates_.resize(joySticksSize_); 269 271 return success; 270 272 } … … 348 350 } 349 351 CCOUT(ORX_DEBUG) << "Joy sticks destroyed." << std::endl; 352 } 353 354 void InputManager::_updateTickables() 355 { 356 // we can use a set to have a list of unique pointers (an object can implement all 3 handlers) 357 std::set<InputTickable*> tempSet; 358 for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++) 359 tempSet.insert(activeKeyHandlers_[iHandler]); 360 for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++) 361 tempSet.insert(activeMouseHandlers_[iHandler]); 362 for (unsigned int iJoyStick = 0; iJoyStick < joySticksSize_; iJoyStick++) 363 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 364 tempSet.insert(activeJoyStickHandlers_[iJoyStick][iHandler]); 365 366 // copy the content of the set back to the actual vector 367 activeHandlers_.clear(); 368 for (std::set<InputTickable*>::const_iterator itHandler = tempSet.begin(); itHandler != tempSet.end(); itHandler++) 369 activeHandlers_.push_back(*itHandler); 350 370 } 351 371 … … 389 409 390 410 case IS_GUI: 391 // FIXME: do stuff411 // TODO: do stuff 392 412 break; 393 413 … … 426 446 for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++) 427 447 for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++) 428 activeMouseHandlers_[iHandler]->mouseButtonHeld(mouse _->getMouseState(), mouseButtonsDown_[iButton]);448 activeMouseHandlers_[iHandler]->mouseButtonHeld(mouseButtonsDown_[iButton]); 429 449 430 450 // call all the handlers for the held joy stick button events … … 432 452 for (unsigned int iButton = 0; iButton < joyStickButtonsDown_[iJoyStick].size(); iButton++) 433 453 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 434 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonHeld( 435 JoyStickState(joySticks_[iJoyStick]->getJoyStickState(), iJoyStick), joyStickButtonsDown_[iJoyStick][iButton]); 454 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonHeld(iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]); 455 456 457 // call the ticks 458 for (unsigned int iHandler = 0; iHandler < activeHandlers_.size(); iHandler++) 459 activeHandlers_[iHandler]->tick(dt); 436 460 } 437 461 … … 508 532 { 509 533 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 510 activeMouseHandlers_[i]->mouseMoved(e.state); 534 activeMouseHandlers_[i]->mouseMoved(IntVector2(e.state.X.abs, e.state.Y.abs), 535 IntVector2(e.state.X.rel, e.state.Y.rel), IntVector2(e.state.width, e.state.height)); 511 536 } 512 537 … … 515 540 { 516 541 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 517 activeMouseHandlers_[i]->mouseScrolled(e.state );542 activeMouseHandlers_[i]->mouseScrolled(e.state.Z.abs, e.state.Z.rel); 518 543 } 519 544 … … 536 561 537 562 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 538 activeMouseHandlers_[i]->mouseButtonPressed( e.state,(MouseButton::Enum)id);563 activeMouseHandlers_[i]->mouseButtonPressed((MouseButton::Enum)id); 539 564 540 565 return true; … … 559 584 560 585 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 561 activeMouseHandlers_[i]->mouseButtonReleased( e.state,(MouseButton::Enum)id);586 activeMouseHandlers_[i]->mouseButtonReleased((MouseButton::Enum)id); 562 587 563 588 return true; … … 584 609 585 610 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 586 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonPressed( JoyStickState(arg.state, iJoyStick), button);611 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonPressed(iJoyStick, button); 587 612 588 613 return true; … … 609 634 610 635 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 611 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonReleased( JoyStickState(arg.state, iJoyStick), button);636 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonReleased(iJoyStick, button); 612 637 613 638 return true; … … 616 641 bool InputManager::axisMoved(const OIS::JoyStickEvent &arg, int axis) 617 642 { 643 //CCOUT(3) << arg.state.mAxes[axis].abs << std::endl; 618 644 // use the device to identify which one called the method 619 645 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; … … 622 648 iJoyStick++; 623 649 650 // keep in mind that the first 8 axes are reserved for the sliders 624 651 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 625 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved( JoyStickState(arg.state, iJoyStick), axis);652 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, axis + 8, arg.state.mAxes[axis].abs); 626 653 627 654 return true; … … 630 657 bool InputManager::sliderMoved(const OIS::JoyStickEvent &arg, int id) 631 658 { 659 //CCOUT(3) << arg.state.mSliders[id].abX << "\t |" << arg.state.mSliders[id].abY << std::endl; 632 660 // use the device to identify which one called the method 633 661 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; … … 636 664 iJoyStick++; 637 665 638 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 639 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickSliderMoved(JoyStickState(arg.state, iJoyStick), id); 666 if (sliderStates_[iJoyStick].sliderStates[id].x != arg.state.mSliders[id].abX) 667 { 668 // slider X axis changed 669 sliderStates_[iJoyStick].sliderStates[id].x = arg.state.mSliders[id].abX; 670 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 671 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, id * 2, arg.state.mSliders[id].abX); 672 } 673 else if (sliderStates_[iJoyStick].sliderStates[id].y != arg.state.mSliders[id].abY) 674 { 675 // slider Y axis changed 676 sliderStates_[iJoyStick].sliderStates[id].y = arg.state.mSliders[id].abY; 677 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 678 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, id * 2 + 1, arg.state.mSliders[id].abY); 679 } 640 680 641 681 return true; … … 650 690 iJoyStick++; 651 691 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) 692 // translate the POV into 8 simple buttons 693 int lastState = povStates_[iJoyStick][id]; 694 if (lastState & OIS::Pov::North) 695 buttonReleased(arg, 32 + id * 4 + 0); 696 if (lastState & OIS::Pov::South) 697 buttonReleased(arg, 32 + id * 4 + 1); 698 if (lastState & OIS::Pov::East) 699 buttonReleased(arg, 32 + id * 4 + 2); 700 if (lastState & OIS::Pov::West) 701 buttonReleased(arg, 32 + id * 4 + 3); 702 703 povStates_[iJoyStick].povStates[id] = arg.state.mPOV[id].direction; 704 int currentState = povStates_[iJoyStick][id]; 705 if (currentState & OIS::Pov::North) 706 buttonPressed(arg, 32 + id * 4 + 0); 707 if (currentState & OIS::Pov::South) 708 buttonPressed(arg, 32 + id * 4 + 1); 709 if (currentState & OIS::Pov::East) 710 buttonPressed(arg, 32 + id * 4 + 2); 711 if (currentState & OIS::Pov::West) 712 buttonPressed(arg, 32 + id * 4 + 3); 713 714 return true; 715 } 716 717 /*bool InputManager::vector3Moved(const OIS::JoyStickEvent &arg, int id) 659 718 { 660 719 // use the device to identify which one called the method … … 668 727 669 728 return true; 670 } 729 }*/ 671 730 672 731 … … 735 794 } 736 795 737 const MouseState InputManager::getMouseState()796 /*const MouseState InputManager::getMouseState() 738 797 { 739 798 if (_getSingleton().mouse_) … … 741 800 else 742 801 return MouseState(); 743 } 744 745 const JoyStickState InputManager::getJoyStickState(unsigned int ID)802 }*/ 803 804 /*const JoyStickState InputManager::getJoyStickState(unsigned int ID) 746 805 { 747 806 if (ID < _getSingleton().joySticksSize_) … … 749 808 else 750 809 return JoyStickState(); 751 } 810 }*/ 752 811 753 812 … … 882 941 if ((*it) == (*mapIt).second) 883 942 { 884 _getSingleton().stateRequest_ = IS_CUSTOM;885 943 return true; 886 944 } … … 888 946 _getSingleton().activeKeyHandlers_.push_back((*mapIt).second); 889 947 _getSingleton().stateRequest_ = IS_CUSTOM; 948 _getSingleton()._updateTickables(); 890 949 return true; 891 950 } … … 910 969 _getSingleton().activeKeyHandlers_.erase(it); 911 970 _getSingleton().stateRequest_ = IS_CUSTOM; 971 _getSingleton()._updateTickables(); 912 972 return true; 913 973 } 914 974 } 915 _getSingleton().stateRequest_ = IS_CUSTOM;916 975 return true; 917 976 } … … 1010 1069 if ((*it) == (*mapIt).second) 1011 1070 { 1012 _getSingleton().stateRequest_ = IS_CUSTOM;1013 1071 return true; 1014 1072 } … … 1016 1074 _getSingleton().activeMouseHandlers_.push_back((*mapIt).second); 1017 1075 _getSingleton().stateRequest_ = IS_CUSTOM; 1076 _getSingleton()._updateTickables(); 1018 1077 return true; 1019 1078 } … … 1038 1097 _getSingleton().activeMouseHandlers_.erase(it); 1039 1098 _getSingleton().stateRequest_ = IS_CUSTOM; 1099 _getSingleton()._updateTickables(); 1040 1100 return true; 1041 1101 } 1042 1102 } 1043 _getSingleton().stateRequest_ = IS_CUSTOM;1044 1103 return true; 1045 1104 } … … 1147 1206 if ((*it) == (*handlerIt).second) 1148 1207 { 1149 _getSingleton().stateRequest_ = IS_CUSTOM;1150 1208 return true; 1151 1209 } … … 1153 1211 _getSingleton().activeJoyStickHandlers_[ID].push_back((*handlerIt).second); 1154 1212 _getSingleton().stateRequest_ = IS_CUSTOM; 1213 _getSingleton()._updateTickables(); 1155 1214 return true; 1156 1215 } … … 1180 1239 _getSingleton().activeJoyStickHandlers_[ID].erase(it); 1181 1240 _getSingleton().stateRequest_ = IS_CUSTOM; 1241 _getSingleton()._updateTickables(); 1182 1242 return true; 1183 1243 }
Note: See TracChangeset
for help on using the changeset viewer.