Changeset 1204 for code/branches/input
- Timestamp:
- Apr 30, 2008, 9:58:13 AM (17 years ago)
- Location:
- code/branches/input
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/input/src/core/CorePrereqs.h
r1062 r1204 114 114 class Identifier; 115 115 class IdentifierDistributor; 116 class InputBuffer;117 class InputBufferListener;118 class InputHandlerGame;119 class InputHandlerGUI;120 class InputManager;121 116 template <class T> 122 117 class Iterator; … … 146 141 class XMLPortObjectContainer; 147 142 class XMLPortParamContainer; 143 144 // input 145 class InputBuffer; 146 class InputBufferListener; 147 class InputManager; 148 class KeyBinder; 149 class GUIInputHandler; 150 class KeyHandler; 151 class MouseHandler; 152 class JoyStickHandler; 153 148 154 } 149 155 -
code/branches/input/src/core/InputManager.cc
r1203 r1204 30 30 @file 31 31 @brief Implementation of the InputManager that captures all the input from OIS 32 and redirects it to listeners if necessary.32 and redirects it to handlers if necessary. 33 33 */ 34 34 … … 37 37 #include "Debug.h" 38 38 #include "InputBuffer.h" 39 #include "ConsoleCommand.h" 40 #include "util/Convert.h" 39 #include "InputHandler.h" 41 40 42 41 namespace orxonox … … 83 82 @param windowHeight The height of the render window 84 83 */ 85 bool InputManager::_initialise( size_t windowHnd, int windowWidth,int windowHeight,86 bool createKeyboard, bool createMouse,bool createJoySticks)84 bool InputManager::_initialise(const size_t windowHnd, const int windowWidth, const int windowHeight, 85 const bool createKeyboard, const bool createMouse, const bool createJoySticks) 87 86 { 88 87 if (state_ == IS_UNINIT) … … 135 134 136 135 // InputManager holds the input buffer --> create one and add it. 137 addKey Listener(new InputBuffer(), "buffer");136 addKeyHandler(new InputBuffer(), "buffer"); 138 137 139 138 KeyBinder* binder = new KeyBinder(); 140 139 binder->loadBindings(); 141 addKey Listener(binder, "keybinder");142 addMouse Listener(binder, "keybinder");140 addKeyHandler(binder, "keybinder"); 141 addMouseHandler(binder, "keybinder"); 143 142 144 143 // Read all the key bindings and assign them … … 273 272 if (state_ != IS_UNINIT) 274 273 { 275 if ( listenersKey_.find("buffer") != listenersKey_.end())276 delete listenersKey_["buffer"];277 278 if ( listenersKey_.find("keybinder") != listenersKey_.end())279 delete listenersKey_["keybinder"];280 281 listenersKeyActive_.clear();282 listenersMouseActive_.clear();283 listenersJoySticksActive_.clear();284 listenersKey_.clear();285 listenersMouse_.clear();286 listenersJoySticks_.clear();274 if (keyHandlers_.find("buffer") != keyHandlers_.end()) 275 delete keyHandlers_["buffer"]; 276 277 if (keyHandlers_.find("keybinder") != keyHandlers_.end()) 278 delete keyHandlers_["keybinder"]; 279 280 activeKeyHandlers_.clear(); 281 activeMouseHandlers_.clear(); 282 activeJoyStickHandlers_.clear(); 283 keyHandlers_.clear(); 284 mouseHandlers_.clear(); 285 joyStickHandlers_.clear(); 287 286 288 287 keysDown_.clear(); 289 288 mouseButtonsDown_.clear(); 290 joyStick sButtonsDown_.clear();289 joyStickButtonsDown_.clear(); 291 290 292 291 _destroyKeyboard(); … … 368 367 if (stateRequest_ != IS_CUSTOM) 369 368 { 370 listenersKeyActive_.clear();371 listenersMouseActive_.clear();372 listenersJoySticksActive_.clear();369 activeKeyHandlers_.clear(); 370 activeMouseHandlers_.clear(); 371 activeJoyStickHandlers_.clear(); 373 372 374 373 switch (stateRequest_) … … 376 375 case IS_NORMAL: 377 376 // normal play mode 378 if ( listenersKey_.find("keybinder") != listenersKey_.end())379 listenersKeyActive_.push_back(listenersKey_["keybinder"]);380 if ( listenersMouse_.find("keybinder") != listenersMouse_.end())381 listenersMouseActive_.push_back(listenersMouse_["keybinder"]);382 if ( listenersJoySticks_.find("keybinder") != listenersJoySticks_.end())377 if (keyHandlers_.find("keybinder") != keyHandlers_.end()) 378 activeKeyHandlers_.push_back(keyHandlers_["keybinder"]); 379 if (mouseHandlers_.find("keybinder") != mouseHandlers_.end()) 380 activeMouseHandlers_.push_back(mouseHandlers_["keybinder"]); 381 if (joyStickHandlers_.find("keybinder") != joyStickHandlers_.end()) 383 382 { 384 383 for (std::map<int, OIS::JoyStick*>::const_iterator it = joySticks_.begin(); 385 384 it != joySticks_.end(); it++) 386 listenersJoySticksActive_[(*it).first].push_back(listenersJoySticks_["keybinder"]);385 activeJoyStickHandlers_[(*it).first].push_back(joyStickHandlers_["keybinder"]); 387 386 } 388 387 break; … … 393 392 394 393 case IS_CONSOLE: 395 if ( listenersMouse_.find("keybinder") != listenersMouse_.end())396 listenersMouseActive_.push_back(listenersMouse_["keybinder"]);397 if ( listenersJoySticks_.find("keybinder") != listenersJoySticks_.end())394 if (mouseHandlers_.find("keybinder") != mouseHandlers_.end()) 395 activeMouseHandlers_.push_back(mouseHandlers_["keybinder"]); 396 if (joyStickHandlers_.find("keybinder") != joyStickHandlers_.end()) 398 397 { 399 398 for (std::map<int, OIS::JoyStick*>::const_iterator it = joySticks_.begin(); 400 399 it != joySticks_.end(); it++) 401 listenersJoySticksActive_[(*it).first].push_back(listenersJoySticks_["keybinder"]);400 activeJoyStickHandlers_[(*it).first].push_back(joyStickHandlers_["keybinder"]); 402 401 } 403 402 404 if ( listenersKey_.find("buffer") != listenersKey_.end())405 listenersKeyActive_.push_back(listenersKey_["buffer"]);403 if (keyHandlers_.find("buffer") != keyHandlers_.end()) 404 activeKeyHandlers_.push_back(keyHandlers_["buffer"]); 406 405 else 407 406 { 408 407 // someone fiddled with the InputBuffer 409 408 CCOUT(2) << "Error: Cannot redirect input to console, InputBuffer instance missing." << std::endl; 410 if ( listenersKey_.find("keybinder") != listenersKey_.end())411 listenersKeyActive_.push_back(listenersKey_["keybinder"]);409 if (keyHandlers_.find("keybinder") != keyHandlers_.end()) 410 activeKeyHandlers_.push_back(keyHandlers_["keybinder"]); 412 411 else 413 412 // this is bad … … 430 429 431 430 432 // call all the listeners for the held key events431 // call all the handlers for the held key events 433 432 for (std::list<OIS::KeyCode>::const_iterator itKey = keysDown_.begin(); 434 433 itKey != keysDown_.end(); itKey++) 435 434 { 436 435 OIS::KeyEvent keyArg(keyboard_, *itKey, 0); 437 for (std::list<KeyHandler*>::const_iterator itKeyHandler = listenersKeyActive_.begin();438 itKeyHandler != listenersKeyActive_.end(); itKeyHandler++)436 for (std::list<KeyHandler*>::const_iterator itKeyHandler = activeKeyHandlers_.begin(); 437 itKeyHandler != activeKeyHandlers_.end(); itKeyHandler++) 439 438 { 440 439 (*itKeyHandler)->keyHeld(keyArg); … … 442 441 } 443 442 444 // call all the listeners for the held mouse button events443 // call all the handlers for the held mouse button events 445 444 for (std::list<OIS::MouseButtonID>::const_iterator itMouseButton = mouseButtonsDown_.begin(); 446 445 itMouseButton != mouseButtonsDown_.end(); itMouseButton++) 447 446 { 448 447 OIS::MouseEvent mouseButtonArg(mouse_, mouse_->getMouseState()); 449 for (std::list<MouseHandler*>::const_iterator itMouseHandler = listenersMouseActive_.begin();450 itMouseHandler != listenersMouseActive_.end(); itMouseHandler++)448 for (std::list<MouseHandler*>::const_iterator itMouseHandler = activeMouseHandlers_.begin(); 449 itMouseHandler != activeMouseHandlers_.end(); itMouseHandler++) 451 450 { 452 451 (*itMouseHandler)->mouseHeld(mouseButtonArg, *itMouseButton); … … 454 453 } 455 454 456 // call all the listeners for the held joy stick button events457 for (std::map<int, std::list <int> >::const_iterator itJoyStick = joyStick sButtonsDown_.begin();458 itJoyStick != joyStick sButtonsDown_.end(); itJoyStick++)455 // call all the handlers for the held joy stick button events 456 for (std::map<int, std::list <int> >::const_iterator itJoyStick = joyStickButtonsDown_.begin(); 457 itJoyStick != joyStickButtonsDown_.end(); itJoyStick++) 459 458 { 460 459 int id = (*itJoyStick).first; … … 463 462 { 464 463 OIS::JoyStickEvent joyStickButtonArg(joySticks_[id], joySticks_[id]->getJoyStickState()); 465 for (std::list<JoyStickHandler*>::const_iterator itJoyStickHandler = listenersJoySticksActive_[id].begin();466 itJoyStickHandler != listenersJoySticksActive_[id].end(); itJoyStickHandler++)464 for (std::list<JoyStickHandler*>::const_iterator itJoyStickHandler = activeJoyStickHandlers_[id].begin(); 465 itJoyStickHandler != activeJoyStickHandlers_[id].end(); itJoyStickHandler++) 467 466 { 468 467 (*itJoyStickHandler)->buttonHeld(joyStickButtonArg, *itJoyStickButton); … … 490 489 keysDown_.push_back(e.key); 491 490 492 for (std::list<KeyHandler*>::const_iterator it = listenersKeyActive_.begin(); it != listenersKeyActive_.end(); it++)491 for (std::list<KeyHandler*>::const_iterator it = activeKeyHandlers_.begin(); it != activeKeyHandlers_.end(); it++) 493 492 (*it)->keyPressed(e); 494 493 … … 512 511 } 513 512 514 for (std::list<KeyHandler*>::const_iterator it = listenersKeyActive_.begin(); it != listenersKeyActive_.end(); it++)513 for (std::list<KeyHandler*>::const_iterator it = activeKeyHandlers_.begin(); it != activeKeyHandlers_.end(); it++) 515 514 (*it)->keyReleased(e); 516 515 … … 524 523 bool InputManager::mouseMoved(const OIS::MouseEvent &e) 525 524 { 526 for (std::list<MouseHandler*>::const_iterator it = listenersMouseActive_.begin(); it != listenersMouseActive_.end(); it++)525 for (std::list<MouseHandler*>::const_iterator it = activeMouseHandlers_.begin(); it != activeMouseHandlers_.end(); it++) 527 526 (*it)->mouseMoved(e); 528 527 … … 548 547 mouseButtonsDown_.push_back(id); 549 548 550 for (std::list<MouseHandler*>::const_iterator it = listenersMouseActive_.begin(); it != listenersMouseActive_.end(); it++)549 for (std::list<MouseHandler*>::const_iterator it = activeMouseHandlers_.begin(); it != activeMouseHandlers_.end(); it++) 551 550 (*it)->mousePressed(e, id); 552 551 … … 571 570 } 572 571 573 for (std::list<MouseHandler*>::const_iterator it = listenersMouseActive_.begin(); it != listenersMouseActive_.end(); it++)572 for (std::list<MouseHandler*>::const_iterator it = activeMouseHandlers_.begin(); it != activeMouseHandlers_.end(); it++) 574 573 (*it)->mouseReleased(e, id); 575 574 … … 582 581 583 582 // check whether the button is already in the list (can happen when focus was lost) 584 std::list<int>& buttonsDownList = joyStick sButtonsDown_[devID];583 std::list<int>& buttonsDownList = joyStickButtonsDown_[devID]; 585 584 for (std::list<int>::iterator it = buttonsDownList.begin(); it != buttonsDownList.end(); it++) 586 585 { … … 591 590 } 592 591 } 593 joyStick sButtonsDown_[devID].push_back(button);594 595 std::list<JoyStickHandler*>::iterator end = listenersJoySticksActive_[devID].end();596 for (std::list<JoyStickHandler*>::const_iterator it = listenersJoySticksActive_[devID].begin(); it != end; it++)592 joyStickButtonsDown_[devID].push_back(button); 593 594 std::list<JoyStickHandler*>::iterator end = activeJoyStickHandlers_[devID].end(); 595 for (std::list<JoyStickHandler*>::const_iterator it = activeJoyStickHandlers_[devID].begin(); it != end; it++) 597 596 (*it)->buttonPressed(arg, button); 598 597 … … 604 603 int devID = arg.device->getID(); 605 604 606 // remove the button from the joyStick sButtonsDown_ list607 std::list<int>& buttonsDownList = joyStick sButtonsDown_[devID];605 // remove the button from the joyStickButtonsDown_ list 606 std::list<int>& buttonsDownList = joyStickButtonsDown_[devID]; 608 607 for (std::list<int>::iterator it = buttonsDownList.begin(); it != buttonsDownList.end(); it++) 609 608 { … … 615 614 } 616 615 617 std::list<JoyStickHandler*>::const_iterator end = listenersJoySticksActive_[devID].end();618 for (std::list<JoyStickHandler*>::const_iterator it = listenersJoySticksActive_[devID].begin(); it != end; it++)616 std::list<JoyStickHandler*>::const_iterator end = activeJoyStickHandlers_[devID].end(); 617 for (std::list<JoyStickHandler*>::const_iterator it = activeJoyStickHandlers_[devID].begin(); it != end; it++) 619 618 (*it)->buttonReleased(arg, button); 620 619 … … 625 624 { 626 625 int devID = arg.device->getID(); 627 std::list<JoyStickHandler*>::const_iterator end = listenersJoySticksActive_[devID].end();628 for (std::list<JoyStickHandler*>::const_iterator it = listenersJoySticksActive_[devID].begin(); it != end; it++)626 std::list<JoyStickHandler*>::const_iterator end = activeJoyStickHandlers_[devID].end(); 627 for (std::list<JoyStickHandler*>::const_iterator it = activeJoyStickHandlers_[devID].begin(); it != end; it++) 629 628 (*it)->axisMoved(arg, axis); 630 629 … … 635 634 { 636 635 int devID = arg.device->getID(); 637 std::list<JoyStickHandler*>::const_iterator end = listenersJoySticksActive_[devID].end();638 for (std::list<JoyStickHandler*>::const_iterator it = listenersJoySticksActive_[devID].begin(); it != end; it++)636 std::list<JoyStickHandler*>::const_iterator end = activeJoyStickHandlers_[devID].end(); 637 for (std::list<JoyStickHandler*>::const_iterator it = activeJoyStickHandlers_[devID].begin(); it != end; it++) 639 638 (*it)->sliderMoved(arg, id); 640 639 … … 645 644 { 646 645 int devID = arg.device->getID(); 647 std::list<JoyStickHandler*>::const_iterator end = listenersJoySticksActive_[devID].end();648 for (std::list<JoyStickHandler*>::const_iterator it = listenersJoySticksActive_[devID].begin(); it != end; it++)646 std::list<JoyStickHandler*>::const_iterator end = activeJoyStickHandlers_[devID].end(); 647 for (std::list<JoyStickHandler*>::const_iterator it = activeJoyStickHandlers_[devID].begin(); it != end; it++) 649 648 (*it)->povMoved(arg, id); 650 649 … … 658 657 // ################################ 659 658 660 bool InputManager::initialise( size_t windowHnd, int windowWidth,int windowHeight,661 bool createKeyboard, bool createMouse,bool createJoySticks)659 bool InputManager::initialise(const size_t windowHnd, const int windowWidth, const int windowHeight, 660 const bool createKeyboard, const bool createMouse, const bool createJoySticks) 662 661 { 663 662 return _getSingleton()._initialise(windowHnd, windowWidth, windowHeight, … … 678 677 { 679 678 return _getSingleton()._initialiseJoySticks(); 679 } 680 681 bool InputManager::isKeyboardInitialised() 682 { 683 return (_getSingleton().keyboard_ != 0); 684 } 685 686 bool InputManager::isMouseInitialised() 687 { 688 return (_getSingleton().mouse_ != 0); 689 } 690 691 bool InputManager::areJoySticksInitialised() 692 { 693 return (_getSingleton().joySticks_.size() > 0); 680 694 } 681 695 … … 708 722 @param height the new height of the render window 709 723 */ 710 void InputManager::setWindowExtents( int width,int height)724 void InputManager::setWindowExtents(const int width, const int height) 711 725 { 712 726 if (_getSingleton().mouse_) … … 742 756 743 757 /** 744 @brief Adds a new key listener.745 @param listener Pointer to the listener object.746 @param name Unique name of the listener.758 @brief Adds a new key handler. 759 @param handler Pointer to the handler object. 760 @param name Unique name of the handler. 747 761 @return True if added, false if name already existed. 748 762 */ 749 bool InputManager::addKey Listener(KeyHandler* listener, const std::string& name)750 { 751 if (_getSingleton(). listenersKey_.find(name) == _getSingleton().listenersKey_.end())752 { 753 _getSingleton(). listenersKey_[name] = listener;763 bool InputManager::addKeyHandler(KeyHandler* handler, const std::string& name) 764 { 765 if (_getSingleton().keyHandlers_.find(name) == _getSingleton().keyHandlers_.end()) 766 { 767 _getSingleton().keyHandlers_[name] = handler; 754 768 return true; 755 769 } … … 759 773 760 774 /** 761 @brief Removes a Key Listener from the list.762 @param name Unique name of the listener.775 @brief Removes a Key handler from the list. 776 @param name Unique name of the handler. 763 777 @return True if removal was successful, false if name was not found. 764 778 */ 765 bool InputManager::removeKey Listener(const std::string &name)766 { 767 disableKey Listener(name);768 std::map<std::string, KeyHandler*>::iterator it = _getSingleton(). listenersKey_.find(name);769 if (it != _getSingleton(). listenersKey_.end())770 { 771 _getSingleton(). listenersKey_.erase(it);779 bool InputManager::removeKeyHandler(const std::string &name) 780 { 781 disableKeyHandler(name); 782 std::map<std::string, KeyHandler*>::iterator it = _getSingleton().keyHandlers_.find(name); 783 if (it != _getSingleton().keyHandlers_.end()) 784 { 785 _getSingleton().keyHandlers_.erase(it); 772 786 return true; 773 787 } … … 777 791 778 792 /** 779 @brief Returns the pointer to a listener.780 @param name Unique name of the listener.793 @brief Returns the pointer to a handler. 794 @param name Unique name of the handler. 781 795 @return Pointer to the instance, 0 if name was not found. 782 796 */ 783 KeyHandler* InputManager::getKey Listener(const std::string& name)784 { 785 std::map<std::string, KeyHandler*>::iterator it = _getSingleton(). listenersKey_.find(name);786 if (it != _getSingleton(). listenersKey_.end())797 KeyHandler* InputManager::getKeyHandler(const std::string& name) 798 { 799 std::map<std::string, KeyHandler*>::iterator it = _getSingleton().keyHandlers_.find(name); 800 if (it != _getSingleton().keyHandlers_.end()) 787 801 { 788 802 return (*it).second; … … 793 807 794 808 /** 795 @brief Enables a specific key listener that has already been added.796 @param name Unique name of the listener.809 @brief Enables a specific key handler that has already been added. 810 @param name Unique name of the handler. 797 811 @return False if name was not found, true otherwise. 798 812 */ 799 bool InputManager::enableKey Listener(const std::string& name)800 { 801 // get pointer from the map with all stored listeners802 std::map<std::string, KeyHandler*>::const_iterator mapIt = _getSingleton(). listenersKey_.find(name);803 if (mapIt == _getSingleton(). listenersKey_.end())804 return false; 805 // see whether the listener is already in the list806 for (std::list<KeyHandler*>::iterator it = _getSingleton(). listenersKeyActive_.begin();807 it != _getSingleton(). listenersKeyActive_.end(); it++)813 bool InputManager::enableKeyHandler(const std::string& name) 814 { 815 // get pointer from the map with all stored handlers 816 std::map<std::string, KeyHandler*>::const_iterator mapIt = _getSingleton().keyHandlers_.find(name); 817 if (mapIt == _getSingleton().keyHandlers_.end()) 818 return false; 819 // see whether the handler is already in the list 820 for (std::list<KeyHandler*>::iterator it = _getSingleton().activeKeyHandlers_.begin(); 821 it != _getSingleton().activeKeyHandlers_.end(); it++) 808 822 { 809 823 if ((*it) == (*mapIt).second) 810 824 return true; 811 825 } 812 _getSingleton(). listenersKeyActive_.push_back((*mapIt).second);813 return true; 814 } 815 816 /** 817 @brief Disables a specific key listener.818 @param name Unique name of the listener.826 _getSingleton().activeKeyHandlers_.push_back((*mapIt).second); 827 return true; 828 } 829 830 /** 831 @brief Disables a specific key handler. 832 @param name Unique name of the handler. 819 833 @return False if name was not found, true otherwise. 820 834 */ 821 bool InputManager::disableKey Listener(const std::string &name)822 { 823 // get pointer from the map with all stored listeners824 std::map<std::string, KeyHandler*>::const_iterator mapIt = _getSingleton(). listenersKey_.find(name);825 if (mapIt == _getSingleton(). listenersKey_.end())826 return false; 827 // look for the listener in the list828 for (std::list<KeyHandler*>::iterator it = _getSingleton(). listenersKeyActive_.begin();829 it != _getSingleton(). listenersKeyActive_.end(); it++)835 bool InputManager::disableKeyHandler(const std::string &name) 836 { 837 // get pointer from the map with all stored handlers 838 std::map<std::string, KeyHandler*>::const_iterator mapIt = _getSingleton().keyHandlers_.find(name); 839 if (mapIt == _getSingleton().keyHandlers_.end()) 840 return false; 841 // look for the handler in the list 842 for (std::list<KeyHandler*>::iterator it = _getSingleton().activeKeyHandlers_.begin(); 843 it != _getSingleton().activeKeyHandlers_.end(); it++) 830 844 { 831 845 if ((*it) == (*mapIt).second) 832 846 { 833 _getSingleton(). listenersKeyActive_.erase(it);847 _getSingleton().activeKeyHandlers_.erase(it); 834 848 return true; 835 849 } … … 838 852 } 839 853 854 /** 855 @brief Checks whether a key handler is active 856 @param name Unique name of the handler. 857 @return False if key handler is not active or doesn't exist, true otherwise. 858 */ 859 bool InputManager::isKeyHandlerActive(const std::string& name) 860 { 861 // get pointer from the map with all stored handlers 862 std::map<std::string, KeyHandler*>::const_iterator mapIt = _getSingleton().keyHandlers_.find(name); 863 if (mapIt == _getSingleton().keyHandlers_.end()) 864 return false; 865 // see whether the handler is already in the list 866 for (std::list<KeyHandler*>::iterator it = _getSingleton().activeKeyHandlers_.begin(); 867 it != _getSingleton().activeKeyHandlers_.end(); it++) 868 { 869 if ((*it) == (*mapIt).second) 870 return true; 871 } 872 return false; 873 } 874 840 875 841 876 // ###### MouseHandler ###### 842 877 /** 843 @brief Adds a new mouse listener.844 @param listener Pointer to the listener object.845 @param name Unique name of the listener.878 @brief Adds a new mouse handler. 879 @param handler Pointer to the handler object. 880 @param name Unique name of the handler. 846 881 @return True if added, false if name already existed. 847 882 */ 848 bool InputManager::addMouse Listener(MouseHandler* listener, const std::string& name)849 { 850 if (_getSingleton(). listenersMouse_.find(name) == _getSingleton().listenersMouse_.end())851 { 852 _getSingleton(). listenersMouse_[name] = listener;883 bool InputManager::addMouseHandler(MouseHandler* handler, const std::string& name) 884 { 885 if (_getSingleton().mouseHandlers_.find(name) == _getSingleton().mouseHandlers_.end()) 886 { 887 _getSingleton().mouseHandlers_[name] = handler; 853 888 return true; 854 889 } … … 858 893 859 894 /** 860 @brief Removes a Mouse Listener from the list.861 @param name Unique name of the listener.895 @brief Removes a Mouse handler from the list. 896 @param name Unique name of the handler. 862 897 @return True if removal was successful, false if name was not found. 863 898 */ 864 bool InputManager::removeMouse Listener(const std::string &name)865 { 866 disableMouse Listener(name);867 std::map<std::string, MouseHandler*>::iterator it = _getSingleton(). listenersMouse_.find(name);868 if (it != _getSingleton(). listenersMouse_.end())869 { 870 _getSingleton(). listenersMouse_.erase(it);899 bool InputManager::removeMouseHandler(const std::string &name) 900 { 901 disableMouseHandler(name); 902 std::map<std::string, MouseHandler*>::iterator it = _getSingleton().mouseHandlers_.find(name); 903 if (it != _getSingleton().mouseHandlers_.end()) 904 { 905 _getSingleton().mouseHandlers_.erase(it); 871 906 return true; 872 907 } … … 876 911 877 912 /** 878 @brief Returns the pointer to a listener.879 @param name Unique name of the listener.913 @brief Returns the pointer to a handler. 914 @param name Unique name of the handler. 880 915 @return Pointer to the instance, 0 if name was not found. 881 916 */ 882 MouseHandler* InputManager::getMouse Listener(const std::string& name)883 { 884 std::map<std::string, MouseHandler*>::iterator it = _getSingleton(). listenersMouse_.find(name);885 if (it != _getSingleton(). listenersMouse_.end())917 MouseHandler* InputManager::getMouseHandler(const std::string& name) 918 { 919 std::map<std::string, MouseHandler*>::iterator it = _getSingleton().mouseHandlers_.find(name); 920 if (it != _getSingleton().mouseHandlers_.end()) 886 921 { 887 922 return (*it).second; … … 892 927 893 928 /** 894 @brief Enables a specific mouse listener that has already been added.895 @param name Unique name of the listener.929 @brief Enables a specific mouse handler that has already been added. 930 @param name Unique name of the handler. 896 931 @return False if name was not found, true otherwise. 897 932 */ 898 bool InputManager::enableMouse Listener(const std::string& name)899 { 900 // get pointer from the map with all stored listeners901 std::map<std::string, MouseHandler*>::const_iterator mapIt = _getSingleton(). listenersMouse_.find(name);902 if (mapIt == _getSingleton(). listenersMouse_.end())903 return false; 904 // see whether the listener is already in the list905 for (std::list<MouseHandler*>::iterator it = _getSingleton(). listenersMouseActive_.begin();906 it != _getSingleton(). listenersMouseActive_.end(); it++)933 bool InputManager::enableMouseHandler(const std::string& name) 934 { 935 // get pointer from the map with all stored handlers 936 std::map<std::string, MouseHandler*>::const_iterator mapIt = _getSingleton().mouseHandlers_.find(name); 937 if (mapIt == _getSingleton().mouseHandlers_.end()) 938 return false; 939 // see whether the handler is already in the list 940 for (std::list<MouseHandler*>::iterator it = _getSingleton().activeMouseHandlers_.begin(); 941 it != _getSingleton().activeMouseHandlers_.end(); it++) 907 942 { 908 943 if ((*it) == (*mapIt).second) 909 944 return true; 910 945 } 911 _getSingleton(). listenersMouseActive_.push_back((*mapIt).second);912 return true; 913 } 914 915 /** 916 @brief Disables a specific mouse listener.917 @param name Unique name of the listener.946 _getSingleton().activeMouseHandlers_.push_back((*mapIt).second); 947 return true; 948 } 949 950 /** 951 @brief Disables a specific mouse handler. 952 @param name Unique name of the handler. 918 953 @return False if name was not found, true otherwise. 919 954 */ 920 bool InputManager::disableMouse Listener(const std::string &name)921 { 922 // get pointer from the map with all stored listeners923 std::map<std::string, MouseHandler*>::const_iterator mapIt = _getSingleton(). listenersMouse_.find(name);924 if (mapIt == _getSingleton(). listenersMouse_.end())925 return false; 926 // look for the listener in the list927 for (std::list<MouseHandler*>::iterator it = _getSingleton(). listenersMouseActive_.begin();928 it != _getSingleton(). listenersMouseActive_.end(); it++)955 bool InputManager::disableMouseHandler(const std::string &name) 956 { 957 // get pointer from the map with all stored handlers 958 std::map<std::string, MouseHandler*>::const_iterator mapIt = _getSingleton().mouseHandlers_.find(name); 959 if (mapIt == _getSingleton().mouseHandlers_.end()) 960 return false; 961 // look for the handler in the list 962 for (std::list<MouseHandler*>::iterator it = _getSingleton().activeMouseHandlers_.begin(); 963 it != _getSingleton().activeMouseHandlers_.end(); it++) 929 964 { 930 965 if ((*it) == (*mapIt).second) 931 966 { 932 _getSingleton(). listenersMouseActive_.erase(it);967 _getSingleton().activeMouseHandlers_.erase(it); 933 968 return true; 934 969 } … … 937 972 } 938 973 974 /** 975 @brief Checks whether a mouse handler is active 976 @param name Unique name of the handler. 977 @return False if key handler is not active or doesn't exist, true otherwise. 978 */ 979 bool InputManager::isMouseHandlerActive(const std::string& name) 980 { 981 // get pointer from the map with all stored handlers 982 std::map<std::string, MouseHandler*>::const_iterator mapIt = _getSingleton().mouseHandlers_.find(name); 983 if (mapIt == _getSingleton().mouseHandlers_.end()) 984 return false; 985 // see whether the handler is already in the list 986 for (std::list<MouseHandler*>::iterator it = _getSingleton().activeMouseHandlers_.begin(); 987 it != _getSingleton().activeMouseHandlers_.end(); it++) 988 { 989 if ((*it) == (*mapIt).second) 990 return true; 991 } 992 return false; 993 } 994 939 995 940 996 // ###### JoyStickHandler ###### 941 997 942 998 /** 943 @brief Adds a new joy stick listener.944 @param listener Pointer to the listener object.945 @param name Unique name of the listener.999 @brief Adds a new joy stick handler. 1000 @param handler Pointer to the handler object. 1001 @param name Unique name of the handler. 946 1002 @return True if added, false if name already existed. 947 1003 */ 948 bool InputManager::addJoyStick Listener(JoyStickHandler* listener, const std::string& name)949 { 950 if (_getSingleton(). listenersJoySticks_.find(name) == _getSingleton().listenersJoySticks_.end())951 { 952 _getSingleton(). listenersJoySticks_[name] = listener;1004 bool InputManager::addJoyStickHandler(JoyStickHandler* handler, const std::string& name) 1005 { 1006 if (_getSingleton().joyStickHandlers_.find(name) == _getSingleton().joyStickHandlers_.end()) 1007 { 1008 _getSingleton().joyStickHandlers_[name] = handler; 953 1009 return true; 954 1010 } … … 958 1014 959 1015 /** 960 @brief Removes a JoyStick Listener from the list.961 @param name Unique name of the listener.1016 @brief Removes a JoyStick handler from the list. 1017 @param name Unique name of the handler. 962 1018 @return True if removal was successful, false if name was not found. 963 1019 */ 964 bool InputManager::removeJoyStick Listener(const std::string &name)1020 bool InputManager::removeJoyStickHandler(const std::string &name) 965 1021 { 966 1022 for (std::map<int, OIS::JoyStick*>::iterator itstick = _getSingleton().joySticks_.begin(); itstick != _getSingleton().joySticks_.end(); itstick++) 967 disableJoyStick Listener(name, (*itstick).first);968 969 std::map<std::string, JoyStickHandler*>::iterator it = _getSingleton(). listenersJoySticks_.find(name);970 if (it != _getSingleton(). listenersJoySticks_.end())971 { 972 _getSingleton(). listenersJoySticks_.erase(it);1023 disableJoyStickHandler(name, (*itstick).first); 1024 1025 std::map<std::string, JoyStickHandler*>::iterator it = _getSingleton().joyStickHandlers_.find(name); 1026 if (it != _getSingleton().joyStickHandlers_.end()) 1027 { 1028 _getSingleton().joyStickHandlers_.erase(it); 973 1029 return true; 974 1030 } … … 978 1034 979 1035 /** 980 @brief Returns the pointer to a listener.981 @param name Unique name of the listener.1036 @brief Returns the pointer to a handler. 1037 @param name Unique name of the handler. 982 1038 @return Pointer to the instance, 0 if name was not found. 983 1039 */ 984 JoyStickHandler* InputManager::getJoyStick Listener(const std::string& name)985 { 986 std::map<std::string, JoyStickHandler*>::iterator it = _getSingleton(). listenersJoySticks_.find(name);987 if (it != _getSingleton(). listenersJoySticks_.end())1040 JoyStickHandler* InputManager::getJoyStickHandler(const std::string& name) 1041 { 1042 std::map<std::string, JoyStickHandler*>::iterator it = _getSingleton().joyStickHandlers_.find(name); 1043 if (it != _getSingleton().joyStickHandlers_.end()) 988 1044 { 989 1045 return (*it).second; … … 994 1050 995 1051 /** 996 @brief Enables a specific joy stick listener that has already been added.997 @param name Unique name of the listener.1052 @brief Enables a specific joy stick handler that has already been added. 1053 @param name Unique name of the handler. 998 1054 @return False if name or id was not found, true otherwise. 999 1055 */ 1000 bool InputManager::enableJoyStick Listener(const std::string& name, const int id)1001 { 1002 // get pointer from the map with all stored listeners1003 std::map<std::string, JoyStickHandler*>::const_iterator listenerIt = _getSingleton().listenersJoySticks_.find(name);1004 if ( listenerIt == _getSingleton().listenersJoySticks_.end())1056 bool InputManager::enableJoyStickHandler(const std::string& name, const int id) 1057 { 1058 // get pointer from the map with all stored handlers 1059 std::map<std::string, JoyStickHandler*>::const_iterator handlerIt = _getSingleton().joyStickHandlers_.find(name); 1060 if (handlerIt == _getSingleton().joyStickHandlers_.end()) 1005 1061 return false; 1006 1062 … … 1010 1066 return false; 1011 1067 1012 // see whether the listener is already in the list1013 for (std::list<JoyStickHandler*>::iterator it = _getSingleton(). listenersJoySticksActive_[id].begin();1014 it != _getSingleton(). listenersJoySticksActive_[id].end(); it++)1015 { 1016 if ((*it) == (* listenerIt).second)1068 // see whether the handler is already in the list 1069 for (std::list<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[id].begin(); 1070 it != _getSingleton().activeJoyStickHandlers_[id].end(); it++) 1071 { 1072 if ((*it) == (*handlerIt).second) 1017 1073 return true; 1018 1074 } 1019 _getSingleton(). listenersJoySticksActive_[id].push_back((*listenerIt).second);1020 return true; 1021 } 1022 1023 /** 1024 @brief Disables a specific joy stick listener.1025 @param name Unique name of the listener.1075 _getSingleton().activeJoyStickHandlers_[id].push_back((*handlerIt).second); 1076 return true; 1077 } 1078 1079 /** 1080 @brief Disables a specific joy stick handler. 1081 @param name Unique name of the handler. 1026 1082 @return False if name or id was not found, true otherwise. 1027 1083 */ 1028 bool InputManager::disableJoyStick Listener(const std::string &name, int id)1029 { 1030 // get pointer from the map with all stored listeners1031 std::map<std::string, JoyStickHandler*>::const_iterator listenerIt = _getSingleton().listenersJoySticks_.find(name);1032 if ( listenerIt == _getSingleton().listenersJoySticks_.end())1084 bool InputManager::disableJoyStickHandler(const std::string &name, int id) 1085 { 1086 // get pointer from the map with all stored handlers 1087 std::map<std::string, JoyStickHandler*>::const_iterator handlerIt = _getSingleton().joyStickHandlers_.find(name); 1088 if (handlerIt == _getSingleton().joyStickHandlers_.end()) 1033 1089 return false; 1034 1090 … … 1038 1094 return false; 1039 1095 1040 // look for the listener in the list1041 for (std::list<JoyStickHandler*>::iterator it = _getSingleton(). listenersJoySticksActive_[id].begin();1042 it != _getSingleton(). listenersJoySticksActive_[id].end(); it++)1043 { 1044 if ((*it) == (* listenerIt).second)1045 { 1046 _getSingleton(). listenersJoySticksActive_[id].erase(it);1096 // look for the handler in the list 1097 for (std::list<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[id].begin(); 1098 it != _getSingleton().activeJoyStickHandlers_[id].end(); it++) 1099 { 1100 if ((*it) == (*handlerIt).second) 1101 { 1102 _getSingleton().activeJoyStickHandlers_[id].erase(it); 1047 1103 return true; 1048 1104 } … … 1051 1107 } 1052 1108 1109 /** 1110 @brief Checks whether a joy stick handler is active 1111 @param name Unique name of the handler. 1112 @return False if key handler is not active or doesn't exist, true otherwise. 1113 */ 1114 bool InputManager::isJoyStickHandlerActive(const std::string& name, const int id) 1115 { 1116 // get pointer from the map with all stored handlers 1117 std::map<std::string, JoyStickHandler*>::const_iterator handlerIt = _getSingleton().joyStickHandlers_.find(name); 1118 if (handlerIt == _getSingleton().joyStickHandlers_.end()) 1119 return false; 1120 1121 // check for existance of the ID 1122 std::map<int, OIS::JoyStick*>::const_iterator joyStickIt = _getSingleton().joySticks_.find(id); 1123 if (joyStickIt == _getSingleton().joySticks_.end()) 1124 return false; 1125 1126 // see whether the handler is already in the list 1127 for (std::list<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[id].begin(); 1128 it != _getSingleton().activeJoyStickHandlers_[id].end(); it++) 1129 { 1130 if ((*it) == (*handlerIt).second) 1131 return true; 1132 } 1133 return false; 1134 } 1135 1053 1136 } -
code/branches/input/src/core/InputManager.h
r1203 r1204 43 43 #include "ois/OIS.h" 44 44 #include "Tickable.h" 45 //#include "InputEvent.h"46 #include "InputHandler.h"47 45 48 46 namespace orxonox … … 54 52 /** 55 53 @brief Captures and distributes mouse and keyboard input. 56 It resolves the key bindings to InputEvents which can be heard by57 implementing the InputEventListener interface.58 54 */ 59 55 class _CoreExport InputManager 60 56 : public Tickable, 61 public OIS:: MouseListener, public OIS::KeyListener, public OIS::JoyStickListener57 public OIS::KeyListener, public OIS::MouseListener, public OIS::JoyStickListener 62 58 { 63 59 public: // enumerations … … 76 72 77 73 public: // static functions 78 static bool initialise( size_t windowHnd, int windowWidth,int windowHeight,79 bool createKeyboard = true, bool createMouse = true,bool createJoySticks = false);74 static bool initialise(const size_t windowHnd, const int windowWidth, const int windowHeight, 75 const bool createKeyboard = true, const bool createMouse = true, const bool createJoySticks = false); 80 76 static bool initialiseKeyboard(); 81 77 static bool initialiseMouse(); 82 78 static bool initialiseJoySticks(); 79 static bool isKeyboardInitialised(); 80 static bool isMouseInitialised(); 81 static bool areJoySticksInitialised(); 83 82 84 83 static void destroy(); … … 87 86 static void destroyJoySticks(); 88 87 89 static void setWindowExtents( int width,int height);88 static void setWindowExtents(const int width, const int height); 90 89 91 90 static void setInputState(const InputState state); 92 91 static InputState getInputState(); 93 static void setKeyBindingState (bool bActive);94 static void setMouseButtonBindingState (bool bActive);95 static void setJoyStickButtonBindingState(bool bActive);96 92 97 static bool addKey Listener(KeyHandler* listener, const std::string& name);98 static bool removeKey Listener(const std::string& name);99 static bool enableKeyListener(const std::string& name);100 static bool disableKeyListener(const std::string& name);101 static bool isKeyListenerActive(const std::string& name);102 static KeyHandler* getKeyListener(const std::string& name);93 static bool addKeyHandler (KeyHandler* handler, const std::string& name); 94 static bool removeKeyHandler (const std::string& name); 95 static KeyHandler* getKeyHandler (const std::string& name); 96 static bool enableKeyHandler (const std::string& name); 97 static bool disableKeyHandler (const std::string& name); 98 static bool isKeyHandlerActive (const std::string& name); 103 99 104 static bool addMouse Listener(MouseHandler* listener, const std::string& name);105 static bool removeMouse Listener(const std::string& name);106 static bool enableMouseListener(const std::string& name);107 static bool disableMouseListener(const std::string& name);108 static bool isMouseListenerActive(const std::string& name);109 static MouseHandler* getMouseListener(const std::string& name);100 static bool addMouseHandler (MouseHandler* handler, const std::string& name); 101 static bool removeMouseHandler (const std::string& name); 102 static MouseHandler* getMouseHandler (const std::string& name); 103 static bool enableMouseHandler (const std::string& name); 104 static bool disableMouseHandler (const std::string& name); 105 static bool isMouseHandlerActive (const std::string& name); 110 106 111 static bool addJoyStick Listener(JoyStickHandler* listener, const std::string& name);112 static bool removeJoyStick Listener(const std::string& name);113 static bool enableJoyStickListener (const std::string& name, const int id);114 static bool disableJoyStickListener(const std::string& name, const int id);115 static bool isJoyStickListenerActive(const std::string& name);116 static JoyStickHandler* getJoyStickListener(const std::string& name);107 static bool addJoyStickHandler (JoyStickHandler* handler, const std::string& name); 108 static bool removeJoyStickHandler (const std::string& name); 109 static JoyStickHandler* getJoyStickHandler(const std::string& name); 110 static bool enableJoyStickHandler (const std::string& name, const int id); 111 static bool disableJoyStickHandler (const std::string& name, const int id); 112 static bool isJoyStickHandlerActive (const std::string& name, const int id); 117 113 118 114 // Temporary solutions. Will be removed soon! … … 127 123 128 124 // Intenal methods 129 bool _initialise( size_t, int, int, bool, bool,bool);125 bool _initialise(const size_t, const int, const int, const bool, const bool, const bool); 130 126 bool _initialiseKeyboard(); 131 127 bool _initialiseMouse(); … … 157 153 158 154 private: // variables 159 OIS::InputManager* inputSystem_;//!< OIS input manager160 OIS::Keyboard* keyboard_;//!< OIS mouse161 OIS::Mouse* mouse_;//!< OIS keyboard162 std::map<int, OIS::JoyStick*> joySticks_; //!< OIS joy sticks155 OIS::InputManager* inputSystem_; //!< OIS input manager 156 OIS::Keyboard* keyboard_; //!< OIS mouse 157 OIS::Mouse* mouse_; //!< OIS keyboard 158 std::map<int, OIS::JoyStick*> joySticks_; //!< OIS joy sticks 163 159 164 160 InputState state_; 165 161 InputState stateRequest_; 166 162 167 std::map<std::string, KeyHandler*> listenersKey_;168 std::map<std::string, MouseHandler*> listenersMouse_;169 std::map<std::string, JoyStickHandler*> listenersJoySticks_;163 std::map<std::string, KeyHandler*> keyHandlers_; 164 std::map<std::string, MouseHandler*> mouseHandlers_; 165 std::map<std::string, JoyStickHandler*> joyStickHandlers_; 170 166 171 std::list<KeyHandler*> listenersKeyActive_;172 std::list<MouseHandler*> listenersMouseActive_;173 std::map< int, std::list<JoyStickHandler*> > listenersJoySticksActive_;167 std::list<KeyHandler*> activeKeyHandlers_; 168 std::list<MouseHandler*> activeMouseHandlers_; 169 std::map<int, std::list<JoyStickHandler*> > activeJoyStickHandlers_; 174 170 175 std::list<OIS::KeyCode> keysDown_;176 std::list<OIS::MouseButtonID> mouseButtonsDown_;177 std::map< int, std::list<int> > joySticksButtonsDown_;171 std::list<OIS::KeyCode> keysDown_; 172 std::list<OIS::MouseButtonID> mouseButtonsDown_; 173 std::map< int, std::list<int> > joyStickButtonsDown_; 178 174 179 175 }; -
code/branches/input/src/orxonox/Orxonox.cc
r1182 r1204 414 414 void Orxonox::startRenderLoop() 415 415 { 416 InputBuffer* ib = dynamic_cast<InputBuffer*>(InputManager::getKey Listener("buffer"));416 InputBuffer* ib = dynamic_cast<InputBuffer*>(InputManager::getKeyHandler("buffer")); 417 417 console_ = new Testconsole(ib); 418 418 ib->registerListener(console_, &Testconsole::listen, true); -
code/branches/input/src/orxonox/Orxonox.h
r1182 r1204 44 44 45 45 #include "GraphicsEngine.h" 46 #include "core/InputEventListener.h"47 48 46 49 47 namespace orxonox { -
code/branches/input/visual_studio/vc8/core.vcproj
r1203 r1204 149 149 > 150 150 <File 151 RelativePath="..\..\src\core\asdf.cc"152 >153 <FileConfiguration154 Name="Debug|Win32"155 ExcludedFromBuild="true"156 >157 <Tool158 Name="VCCLCompilerTool"159 />160 </FileConfiguration>161 <FileConfiguration162 Name="Release|Win32"163 ExcludedFromBuild="true"164 >165 <Tool166 Name="VCCLCompilerTool"167 />168 </FileConfiguration>169 </File>170 <File171 151 RelativePath="..\..\src\core\BaseObject.cc" 172 152 > … … 217 197 </File> 218 198 <File 219 RelativePath="..\..\src\core\InputEventListener.cc"220 >221 <FileConfiguration222 Name="Debug|Win32"223 ExcludedFromBuild="true"224 >225 <Tool226 Name="VCCLCompilerTool"227 />228 </FileConfiguration>229 <FileConfiguration230 Name="Release|Win32"231 ExcludedFromBuild="true"232 >233 <Tool234 Name="VCCLCompilerTool"235 />236 </FileConfiguration>237 </File>238 <File239 199 RelativePath="..\..\src\core\InputHandler.cc" 240 200 > 241 <FileConfiguration242 Name="Debug|Win32"243 >244 <Tool245 Name="VCCLCompilerTool"246 />247 </FileConfiguration>248 <FileConfiguration249 Name="Release|Win32"250 >251 <Tool252 Name="VCCLCompilerTool"253 />254 </FileConfiguration>255 201 </File> 256 202 <File … … 317 263 > 318 264 <File 319 RelativePath="..\..\src\core\asdf.h"320 >321 </File>322 <File323 265 RelativePath="..\..\src\core\BaseObject.h" 324 266 > … … 398 340 <File 399 341 RelativePath="..\..\src\core\InputBuffer.h" 400 >401 </File>402 <File403 RelativePath="..\..\src\core\InputEvent.h"404 >405 </File>406 <File407 RelativePath="..\..\src\core\InputEventListener.h"408 342 > 409 343 </File> -
code/branches/input/visual_studio/vc8/orxonox.vcproj
r1203 r1204 434 434 > 435 435 </File> 436 <File437 RelativePath="..\..\src\orxonox\Steerable.h"438 >439 </File>440 436 <Filter 441 437 Name="hud"
Note: See TracChangeset
for help on using the changeset viewer.