Changeset 1413 for code/branches/network/src/core/InputManager.cc
- Timestamp:
- May 24, 2008, 8:12:20 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/core/InputManager.cc
r1398 r1413 37 37 #include "Debug.h" 38 38 #include "InputBuffer.h" 39 #include " InputHandler.h"39 #include "KeyBinder.h" 40 40 41 41 namespace orxonox … … 52 52 InputManager::InputManager() : 53 53 inputSystem_(0), keyboard_(0), mouse_(0), 54 keyBinder_(0), buffer_(0), 54 55 joySticksSize_(0), 55 56 state_(IS_UNINIT), stateRequest_(IS_UNINIT), … … 144 145 145 146 // 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 them 155 //if (!_loadBindings()) 156 // return false; 147 buffer_ = new InputBuffer(); 148 addKeyHandler(buffer_, "buffer"); 149 150 keyBinder_ = new KeyBinder(); 151 keyBinder_->loadBindings(); 152 addKeyHandler(keyBinder_, "keybinder"); 153 addMouseHandler(keyBinder_, "keybinder"); 154 addJoyStickHandler(keyBinder_, "keybinder"); 155 156 keyDetector_ = new KeyDetector(); 157 keyDetector_->loadBindings(); 158 addKeyHandler(keyDetector_, "keydetector"); 159 addMouseHandler(keyDetector_, "keydetector"); 160 addJoyStickHandler(keyDetector_, "keydetector"); 157 161 158 162 CCOUT(ORX_DEBUG) << "Initialising complete." << std::endl; … … 288 292 CCOUT(ORX_DEBUG) << "Destroying ..." << std::endl; 289 293 290 if (keyHandlers_.find("buffer") != keyHandlers_.end()) 291 delete keyHandlers_["buffer"]; 292 293 if (keyHandlers_.find("keybinder") != keyHandlers_.end()) 294 delete keyHandlers_["keybinder"]; 294 if (buffer_) 295 delete buffer_; 296 297 if (keyBinder_) 298 delete keyBinder_; 299 300 if (keyDetector_) 301 delete keyDetector_; 295 302 296 303 keyHandlers_.clear(); … … 361 368 void InputManager::_updateTickables() 362 369 { 363 // we can use a setto have a list of unique pointers (an object can implement all 3 handlers)364 std:: set<InputTickable*> tempSet;370 // we can use a map to have a list of unique pointers (an object can implement all 3 handlers) 371 std::map<InputTickable*, HandlerState> tempSet; 365 372 for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++) 366 tempSet .insert(activeKeyHandlers_[iHandler]);373 tempSet[activeKeyHandlers_[iHandler]].joyStick = true; 367 374 for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++) 368 tempSet .insert(activeMouseHandlers_[iHandler]);375 tempSet[activeMouseHandlers_[iHandler]].mouse = true; 369 376 for (unsigned int iJoyStick = 0; iJoyStick < joySticksSize_; iJoyStick++) 370 377 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 vector378 tempSet[activeJoyStickHandlers_[iJoyStick][iHandler]].joyStick = true; 379 380 // copy the content of the map back to the actual vector 374 381 activeHandlers_.clear(); 375 for (std::set<InputTickable*>::const_iterator itHandler = tempSet.begin(); itHandler != tempSet.end(); itHandler++) 376 activeHandlers_.push_back(*itHandler); 382 for (std::map<InputTickable*, HandlerState>::const_iterator itHandler = tempSet.begin(); 383 itHandler != tempSet.end(); itHandler++) 384 activeHandlers_.push_back(std::pair<InputTickable*, HandlerState>((*itHandler).first, (*itHandler).second)); 377 385 } 378 386 … … 422 430 break; 423 431 432 case IS_DETECTION: 433 if (mouse_) 434 mouse_->capture(); 435 if (keyboard_) 436 keyboard_->capture(); 437 for (unsigned int i = 0; i < joySticksSize_; i++) 438 joySticks_[i]->capture(); 439 440 lastStroke_ = ""; 441 enableKeyHandler("keydetector"); 442 enableMouseHandler("keydetector"); 443 enableJoyStickHandler("keydetector", 0); 444 break; 445 424 446 default: 425 447 break; … … 455 477 456 478 457 // call the ticks 479 // call the ticks for the handlers (need to be treated specially) 458 480 for (unsigned int iHandler = 0; iHandler < activeHandlers_.size(); iHandler++) 459 activeHandlers_[iHandler]->tick(dt); 481 activeHandlers_[iHandler].first->tickInput(dt, activeHandlers_[iHandler].second); 482 483 /*for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++) 484 activeKeyHandlers_[iHandler]->tickKey(dt); 485 for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++) 486 activeMouseHandlers_[iHandler]->tickMouse(dt); 487 for (unsigned int iJoyStick = 0; iJoyStick < joySticksSize_; iJoyStick++) 488 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 489 activeJoyStickHandlers_[iJoyStick][iHandler]->tickJoyStick(dt);*/ 460 490 } 461 491 … … 781 811 } 782 812 783 bool InputManager::isKeyDown(KeyCode::Enum key)813 /*bool InputManager::isKeyDown(KeyCode::Enum key) 784 814 { 785 815 if (_getSingleton().keyboard_) … … 787 817 else 788 818 return false; 789 } 790 791 bool InputManager::isModifierDown(KeyboardModifier::Enum modifier)819 }*/ 820 821 /*bool InputManager::isModifierDown(KeyboardModifier::Enum modifier) 792 822 { 793 823 if (_getSingleton().keyboard_) … … 795 825 else 796 826 return false; 797 } 827 }*/ 798 828 799 829 /*const MouseState InputManager::getMouseState() … … 812 842 return JoyStickState(); 813 843 }*/ 814 815 844 816 845 void InputManager::destroy() … … 871 900 } 872 901 902 void InputManager::storeKeyStroke(const std::string& name) 903 { 904 if (_getSingleton().lastStroke_ == "") 905 _getSingleton().lastStroke_ = name; 906 } 907 908 const std::string& InputManager::getLastKeyStroke() 909 { 910 return _getSingleton().lastStroke_; 911 } 912 873 913 874 914 // ###### KeyHandler ######
Note: See TracChangeset
for help on using the changeset viewer.