Changeset 2816
- Timestamp:
- Mar 21, 2009, 8:47:11 PM (16 years ago)
- Location:
- code/branches/gui/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/gui/src/core/input/InputManager.cc
r2814 r2816 109 109 , internalState_(Uninitialised) 110 110 , stateEmpty_(0) 111 , stateMaster_(0)112 111 , keyDetector_(0) 113 112 , calibratorCallbackBuffer_(0) … … 219 218 220 219 // Lowest priority empty InputState 221 stateEmpty_ = createInputState<SimpleInputState>("empty", InputStatePriority::Empty);220 stateEmpty_ = createInputState<SimpleInputState>("empty", false, false, InputStatePriority::Empty); 222 221 stateEmpty_->setHandler(&EMPTY_HANDLER); 223 222 activeStates_[stateEmpty_->getPriority()] = stateEmpty_; 224 223 225 // Always active master InputState226 stateMaster_ = new ExtendedInputState();227 stateMaster_->setName("master");228 stateMaster_->setNumOfJoySticks(joySticksSize_);229 230 224 // KeyDetector to evaluate a pressed key's name 231 SimpleInputState* detector = createInputState<SimpleInputState>("detector", InputStatePriority::Detector);225 SimpleInputState* detector = createInputState<SimpleInputState>("detector", false, false, InputStatePriority::Detector); 232 226 keyDetector_ = new KeyDetector(); 233 227 detector->setHandler(keyDetector_); 234 228 235 229 // Joy stick calibration helper callback 236 SimpleInputState* calibrator = createInputState<SimpleInputState>("calibrator", InputStatePriority::Calibrator);230 SimpleInputState* calibrator = createInputState<SimpleInputState>("calibrator", false, false, InputStatePriority::Calibrator); 237 231 calibrator->setHandler(&EMPTY_HANDLER); 238 232 calibratorCallbackBuffer_ = new InputBuffer(); … … 425 419 426 420 // state management 427 activeStatesT op_.resize(devicesNum_);421 activeStatesTriggered_.resize(devicesNum_); 428 422 429 423 // inform all states … … 433 427 it->second->setNumOfJoySticks(joySticksSize_); 434 428 } 435 // inform master state436 if (stateMaster_)437 this->stateMaster_->setNumOfJoySticks(joySticksSize_);438 429 439 430 // inform all JoyStick Device Number Listeners … … 550 541 // destroy the empty InputState 551 542 _destroyState(this->stateEmpty_); 552 // destroy the master input state. This might trigger a memory leak553 // because the user has forgotten to destroy the KeyBinder or any Handler!554 delete stateMaster_;555 543 556 544 // destroy all user InputStates … … 847 835 { 848 836 KeyEvent kEvt(keysDown_[iKey], keyboardModifiers_); 849 activeStatesTop_[Keyboard]->keyHeld(kEvt); 850 stateMaster_->keyHeld(kEvt); 837 838 for (unsigned int iState = 0; iState < activeStatesTriggered_[Keyboard].size(); ++iState) 839 activeStatesTriggered_[Keyboard][iState]->keyHeld(kEvt); 851 840 } 852 841 … … 854 843 for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++) 855 844 { 856 activeStatesTop_[Mouse]->mouseButtonHeld(mouseButtonsDown_[iButton]);857 stateMaster_->mouseButtonHeld(mouseButtonsDown_[iButton]);845 for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState) 846 activeStatesTriggered_[Mouse][iState]->mouseButtonHeld(mouseButtonsDown_[iButton]); 858 847 } 859 848 … … 862 851 for (unsigned int iButton = 0; iButton < joyStickButtonsDown_[iJoyStick].size(); iButton++) 863 852 { 864 activeStatesTop_[JoyStick0 + iJoyStick] 865 ->joyStickButtonHeld(iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]); 866 stateMaster_->joyStickButtonHeld(iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]); 853 for (unsigned int iState = 0; iState < activeStatesTriggered_[JoyStick0 + iJoyStick].size(); ++iState) 854 activeStatesTriggered_[JoyStick0 + iJoyStick][iState]->joyStickButtonHeld(iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]); 867 855 } 868 856 … … 870 858 for (unsigned int i = 0; i < devicesNum_; ++i) 871 859 { 872 activeStatesTop_[i]->updateInput(time.getDeltaTime(), i); 873 if (stateMaster_->isInputDeviceEnabled(i)) 874 stateMaster_->updateInput(time.getDeltaTime(), i); 860 for (unsigned int iState = 0; iState < activeStatesTriggered_[i].size(); ++iState) 861 activeStatesTriggered_[i][iState]->updateInput(time.getDeltaTime(), i); 875 862 } 876 863 … … 878 865 for (unsigned int i = 0; i < activeStatesTicked_.size(); ++i) 879 866 activeStatesTicked_[i]->updateInput(time.getDeltaTime()); 880 stateMaster_->updateInput(time.getDeltaTime());881 867 } 882 868 … … 891 877 void InputManager::_updateActiveStates() 892 878 { 893 for (std::map<int, InputState*>::const_iterator it = activeStates_.begin(); it != activeStates_.end(); ++it) 894 for (unsigned int i = 0; i < devicesNum_; ++i) 895 if (it->second->isInputDeviceEnabled(i)) 896 activeStatesTop_[i] = it->second; 879 for (unsigned int i = 0; i < devicesNum_; ++i) 880 { 881 bool occupied = false; 882 activeStatesTriggered_[i].clear(); 883 for (std::map<int, InputState*>::const_reverse_iterator rit = activeStates_.rbegin(); rit != activeStates_.rend(); ++rit) 884 { 885 if (rit->second->isInputDeviceEnabled(i) && (!occupied || rit->second->bAlwaysGetsInput_)) 886 { 887 activeStatesTriggered_[i].push_back(rit->second); 888 if (!rit->second->bTransparent_) 889 occupied = true; 890 } 891 } 892 } 897 893 898 894 // update tickables (every state will only appear once) … … 900 896 std::set<InputState*> tempSet; 901 897 for (unsigned int i = 0; i < devicesNum_; ++i) 902 tempSet.insert(activeStatesTop_[i]); 903 904 // copy the content of the set back to the actual vector 898 for (unsigned int iState = 0; iState < activeStatesTriggered_[i].size(); ++iState) 899 tempSet.insert(activeStatesTriggered_[i][iState]); 900 901 // copy the content of the std::set back to the actual vector 905 902 activeStatesTicked_.clear(); 906 903 for (std::set<InputState*>::const_iterator it = tempSet.begin();it != tempSet.end(); ++it) … … 960 957 961 958 KeyEvent kEvt(e, keyboardModifiers_); 962 activeStatesTop_[Keyboard]->keyPressed(kEvt);963 stateMaster_->keyPressed(kEvt);959 for (unsigned int iState = 0; iState < activeStatesTriggered_[Keyboard].size(); ++iState) 960 activeStatesTriggered_[Keyboard][iState]->keyPressed(kEvt); 964 961 965 962 return true; … … 993 990 994 991 KeyEvent kEvt(e, keyboardModifiers_); 995 activeStatesTop_[Keyboard]->keyReleased(kEvt);996 stateMaster_->keyReleased(kEvt);992 for (unsigned int iState = 0; iState < activeStatesTriggered_[Keyboard].size(); ++iState) 993 activeStatesTriggered_[Keyboard][iState]->keyReleased(kEvt); 997 994 998 995 return true; … … 1016 1013 IntVector2 rel(e.state.X.rel, e.state.Y.rel); 1017 1014 IntVector2 clippingSize(e.state.width, e.state.height); 1018 activeStatesTop_[Mouse]->mouseMoved(abs, rel, clippingSize);1019 stateMaster_->mouseMoved(abs, rel, clippingSize);1015 for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState) 1016 activeStatesTriggered_[Mouse][iState]->mouseMoved(abs, rel, clippingSize); 1020 1017 } 1021 1018 … … 1023 1020 if (e.state.Z.rel != 0) 1024 1021 { 1025 activeStatesTop_[Mouse]->mouseScrolled(e.state.Z.abs, e.state.Z.rel);1026 stateMaster_->mouseScrolled(e.state.Z.abs, e.state.Z.rel);1022 for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState) 1023 activeStatesTriggered_[Mouse][iState]->mouseScrolled(e.state.Z.abs, e.state.Z.rel); 1027 1024 } 1028 1025 … … 1047 1044 mouseButtonsDown_.push_back((MouseButtonCode::ByEnum)id); 1048 1045 1049 activeStatesTop_[Mouse]->mouseButtonPressed((MouseButtonCode::ByEnum)id);1050 stateMaster_->mouseButtonPressed((MouseButtonCode::ByEnum)id);1046 for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState) 1047 activeStatesTriggered_[Mouse][iState]->mouseButtonPressed((MouseButtonCode::ByEnum)id); 1051 1048 1052 1049 return true; … … 1073 1070 } 1074 1071 1075 activeStatesTop_[Mouse]->mouseButtonReleased((MouseButtonCode::ByEnum)id);1076 stateMaster_->mouseButtonReleased((MouseButtonCode::ByEnum)id);1072 for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState) 1073 activeStatesTriggered_[Mouse][iState]->mouseButtonReleased((MouseButtonCode::ByEnum)id); 1077 1074 1078 1075 return true; … … 1110 1107 buttonsDown.push_back((JoyStickButtonCode::ByEnum)button); 1111 1108 1112 activeStatesTop_[2 + iJoyStick]->joyStickButtonPressed(iJoyStick, (JoyStickButtonCode::ByEnum)button);1113 stateMaster_->joyStickButtonPressed(iJoyStick, (JoyStickButtonCode::ByEnum)button);1109 for (unsigned int iState = 0; iState < activeStatesTriggered_[2 + iJoyStick].size(); ++iState) 1110 activeStatesTriggered_[2 + iJoyStick][iState]->joyStickButtonPressed(iJoyStick, (JoyStickButtonCode::ByEnum)button); 1114 1111 1115 1112 return true; … … 1131 1128 } 1132 1129 1133 activeStatesTop_[2 + iJoyStick]->joyStickButtonReleased(iJoyStick, (JoyStickButtonCode::ByEnum)button);1134 stateMaster_->joyStickButtonReleased(iJoyStick, (JoyStickButtonCode::ByEnum)button);1130 for (unsigned int iState = 0; iState < activeStatesTriggered_[2 + iJoyStick].size(); ++iState) 1131 activeStatesTriggered_[2 + iJoyStick][iState]->joyStickButtonReleased(iJoyStick, (JoyStickButtonCode::ByEnum)button); 1135 1132 1136 1133 return true; … … 1159 1156 fValue *= joyStickCalibrations_[iJoyStick].negativeCoeff[axis]; 1160 1157 1161 activeStatesTop_[2 + iJoyStick]->joyStickAxisMoved(iJoyStick, axis, fValue);1162 stateMaster_->joyStickAxisMoved(iJoyStick, axis, fValue);1158 for (unsigned int iState = 0; iState < activeStatesTriggered_[2 + iJoyStick].size(); ++iState) 1159 activeStatesTriggered_[2 + iJoyStick][iState]->joyStickAxisMoved(iJoyStick, axis, fValue); 1163 1160 } 1164 1161 } … … 1269 1266 True if added, false if name or priority already existed. 1270 1267 */ 1271 bool InputManager::_configureInputState(InputState* state, const std::string& name, int priority)1268 bool InputManager::_configureInputState(InputState* state, const std::string& name, bool bAlwaysGetsInput, bool bTransparent, int priority) 1272 1269 { 1273 1270 if (name == "") … … 1294 1291 state->setNumOfJoySticks(numberOfJoySticks()); 1295 1292 state->setName(name); 1293 state->bAlwaysGetsInput_ = bAlwaysGetsInput; 1294 state->bTransparent_ = bTransparent; 1296 1295 if (priority >= InputStatePriority::HighPriority || priority == InputStatePriority::Empty) 1297 1296 state->setPriority(priority); -
code/branches/gui/src/core/input/InputManager.h
r2814 r2816 130 130 131 131 template <class T> 132 T* createInputState(const std::string& name, InputStatePriority priority = InputStatePriority::Dynamic);132 T* createInputState(const std::string& name, bool bAlwaysGetsInput = false, bool bTransparent = false, InputStatePriority priority = InputStatePriority::Dynamic); 133 133 134 134 InputState* getState (const std::string& name); 135 135 InputState* getCurrentState(); 136 ExtendedInputState* getMasterInputState() { return this->stateMaster_; }137 136 bool requestDestroyState (const std::string& name); 138 137 bool requestEnterState (const std::string& name); … … 179 178 180 179 void _updateActiveStates(); 181 bool _configureInputState(InputState* state, const std::string& name, int priority);180 bool _configureInputState(InputState* state, const std::string& name, bool bAlwaysGetsInput, bool bTransparent, int priority); 182 181 183 182 // input events … … 211 210 // some internally handled states and handlers 212 211 SimpleInputState* stateEmpty_; 213 ExtendedInputState* stateMaster_; //!< Always active master input state214 212 KeyDetector* keyDetector_; //!< KeyDetector instance 215 213 InputBuffer* calibratorCallbackBuffer_; … … 222 220 223 221 std::map<int, InputState*> activeStates_; 224 std::vector< InputState*> activeStatesTop_; //!< Current input states for joy stick events.225 std::vector<InputState*> activeStatesTicked_; //!< Current input states for joy stick events.222 std::vector<std::vector<InputState*> > activeStatesTriggered_; 223 std::vector<InputState*> activeStatesTicked_; 226 224 227 225 // joystick calibration … … 262 260 */ 263 261 template <class T> 264 T* InputManager::createInputState(const std::string& name, InputStatePriority priority)262 T* InputManager::createInputState(const std::string& name, bool bAlwaysGetsInput, bool bTransparent, InputStatePriority priority) 265 263 { 266 264 T* state = new T; 267 if (_configureInputState(state, name, priority))265 if (_configureInputState(state, name, bAlwaysGetsInput, bTransparent, priority)) 268 266 return state; 269 267 else -
code/branches/gui/src/core/input/InputState.h
r2800 r2816 90 90 91 91 protected: 92 InputState() : bHandlersChanged_(false), priority_(0), executorOnEnter_(0), executorOnLeave_(0) { } 92 InputState() 93 : bHandlersChanged_(false) 94 , priority_(0) 95 , bAlwaysGetsInput_(false) 96 , bTransparent_(false) 97 , executorOnEnter_(0) 98 , executorOnLeave_(0) 99 { } 93 100 virtual ~InputState() { } 94 101 … … 114 121 int priority_; 115 122 std::vector<bool> bInputDeviceEnabled_; 123 bool bAlwaysGetsInput_; 124 bool bTransparent_; 116 125 117 126 Executor* executorOnEnter_; -
code/branches/gui/src/orxonox/gamestates/GSGraphics.cc
r2805 r2816 39 39 #include "core/input/InputManager.h" 40 40 #include "core/input/KeyBinder.h" 41 #include "core/input/ ExtendedInputState.h"41 #include "core/input/SimpleInputState.h" 42 42 #include "core/Loader.h" 43 43 #include "core/XMLFile.h" … … 57 57 , graphicsManager_(0) 58 58 , masterKeyBinder_(0) 59 , masterInputState_(0) 59 60 , debugOverlay_(0) 60 61 { … … 91 92 renderWindow->getCustomAttribute("WINDOW", &windowHnd); 92 93 inputManager_->initialise(windowHnd, renderWindow->getWidth(), renderWindow->getHeight(), true); 93 // Configure master input state with a KeyBinder 94 95 masterInputState_ = InputManager::getInstance().createInputState<SimpleInputState>("master", true); 94 96 masterKeyBinder_ = new KeyBinder(); 95 97 masterKeyBinder_->loadBindings("masterKeybindings.ini"); 96 inputManager_->getMasterInputState()->addKeyHandler(masterKeyBinder_);98 masterInputState_->setKeyHandler(masterKeyBinder_); 97 99 98 100 // Load the InGameConsole … … 103 105 guiManager_ = new GUIManager(); 104 106 guiManager_->initialise(renderWindow); 107 108 InputManager::getInstance().requestEnterState("master"); 105 109 } 106 110 107 111 void GSGraphics::leave() 108 112 { 113 if (Core::showsGraphics()) 114 InputManager::getInstance().requestLeaveState("master"); 115 109 116 delete this->guiManager_; 110 117 … … 119 126 120 127 delete graphicsManager_; 128 129 if (Core::showsGraphics()) 130 { 131 masterInputState_->setHandler(0); 132 InputManager::getInstance().requestDestroyState("master"); 133 if (this->masterKeyBinder_) 134 { 135 delete this->masterKeyBinder_; 136 this->masterKeyBinder_ = 0; 137 } 138 } 121 139 } 122 140 -
code/branches/gui/src/orxonox/gamestates/GSGraphics.h
r2801 r2816 65 65 66 66 KeyBinder* masterKeyBinder_; 67 SimpleInputState* masterInputState_; 67 68 XMLFile* debugOverlay_; 68 69 }; -
code/branches/gui/src/orxonox/overlays/console/InGameConsole.cc
r2814 r2816 173 173 { 174 174 // create the corresponding input state 175 inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("console", InputStatePriority::Console);175 inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("console", false, false, InputStatePriority::Console); 176 176 inputState_->setKeyHandler(Shell::getInstance().getInputBuffer()); 177 177 bHidesAllInputChanged();
Note: See TracChangeset
for help on using the changeset viewer.