Changeset 1641 for code/branches/gui/src/core/input/InputManager.cc
- Timestamp:
- Jul 22, 2008, 9:16:35 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/gui/src/core/input/InputManager.cc
r1638 r1641 91 91 /** 92 92 @brief 93 Destructor itself only called at the end of the program, after main. 94 Instance gets registered for destruction with atexit(.). 95 */ 96 InputManager::~InputManager() 97 { 98 _destroy(); 99 } 100 101 /** 102 @brief 93 103 The one instance of the InputManager is stored in this function. 104 Only for internal use. Public Interface ist static. 94 105 @return 95 106 A reference to the only instance of the InputManager … … 99 110 static InputManager theOnlyInstance; 100 111 return theOnlyInstance; 101 }102 103 /**104 @brief105 Destructor only called at the end of the program, after main.106 */107 InputManager::~InputManager()108 {109 _destroy();110 112 } 111 113 … … 133 135 { 134 136 CCOUT(3) << "Initialising Input System..." << std::endl; 135 CCOUT( ORX_DEBUG) << "Initialising OIS components..." << std::endl;137 CCOUT(4) << "Initialising OIS components..." << std::endl; 136 138 137 139 OIS::ParamList paramList; … … 180 182 CCOUT(ORX_DEBUG) << "Initialising OIS components done." << std::endl; 181 183 182 // InputManager holds the input buffer --> create one and add it.183 //buffer_ = new InputBuffer();184 //addKeyHandler(buffer_, "buffer");185 //Shell::getInstance().setInputBuffer(buffer_);186 187 184 setConfigValues(); 188 185 … … 204 201 _updateActiveStates(); 205 202 206 CCOUT( ORX_DEBUG) << "Initialising complete." << std::endl;203 CCOUT(3) << "Initialising complete." << std::endl; 207 204 } 208 205 else 209 206 { 210 CCOUT( ORX_WARNING) << "Warning: OIS compoments already initialised, skipping" << std::endl;207 CCOUT(2) << "Warning: OIS compoments already initialised, skipping" << std::endl; 211 208 } 212 209 return true; … … 333 330 } 334 331 332 /** 333 @brief 334 Sets the size of all the different lists that are dependent on the number 335 of joy stick devices created. 336 @remarks 337 No matter whether there are a mouse and/or keyboard, they will always 338 occupy 2 places in the device number dependent lists. 339 */ 335 340 void InputManager::_redimensionLists() 336 341 { … … 356 361 activeStatesTop_.resize(devicesNum_); 357 362 358 // inform all registeredstates363 // inform all states 359 364 for (std::map<int, InputState*>::const_iterator it = inputStatesByPriority_.begin(); 360 365 it != inputStatesByPriority_.end(); ++it) … … 364 369 /** 365 370 @brief 366 Sets the configurable values. Use keybindings.ini as file.. 371 Sets the configurable values. 372 This mainly concerns joy stick calibrations. 367 373 */ 368 374 void InputManager::setConfigValues() 369 375 { 370 if (joySticksSize_ )376 if (joySticksSize_ > 0) 371 377 { 372 378 std::vector<MultiTypeMath> coeffPos; … … 386 392 if (!cont) 387 393 { 388 cont = new ConfigValueContainer(CFT_ Keybindings, getIdentifier(), "CoeffPos", coeffPos);394 cont = new ConfigValueContainer(CFT_Settings, getIdentifier(), "CoeffPos", coeffPos); 389 395 getIdentifier()->addConfigValueContainer("CoeffPos", cont); 390 396 } … … 394 400 if (!cont) 395 401 { 396 cont = new ConfigValueContainer(CFT_ Keybindings, getIdentifier(), "CoeffNeg", coeffNeg);402 cont = new ConfigValueContainer(CFT_Settings, getIdentifier(), "CoeffNeg", coeffNeg); 397 403 getIdentifier()->addConfigValueContainer("CoeffNeg", cont); 398 404 } … … 402 408 if (!cont) 403 409 { 404 cont = new ConfigValueContainer(CFT_ Keybindings, getIdentifier(), "Zero", zero);410 cont = new ConfigValueContainer(CFT_Settings, getIdentifier(), "Zero", zero); 405 411 getIdentifier()->addConfigValueContainer("Zero", cont); 406 412 } … … 425 431 /** 426 432 @brief 427 Destroys all the created input devices and sets the InputManager to construction state. 433 Destroys all the created input devices. InputManager will be ready for a 434 new initialisation. 428 435 */ 429 436 void InputManager::_destroy() … … 431 438 if (inputSystem_) 432 439 { 433 CCOUT(ORX_DEBUG) << "Destroying ..." << std::endl; 434 435 // kick all active states 'nicely' 436 for (std::map<int, InputState*>::reverse_iterator rit = activeStates_.rbegin(); 437 rit != activeStates_.rend(); ++rit) 438 (*rit).second->onLeave(); 439 activeStates_.clear(); 440 441 // destroy our own states 442 stateEmpty_->removeAndDestroyAllHandlers(); 443 stateCalibrator_->removeAndDestroyAllHandlers(); 444 stateDetector_->removeAndDestroyAllHandlers(); 445 _destroyState(stateEmpty_); 446 _destroyState(stateCalibrator_); 447 _destroyState(stateDetector_); 448 stateEmpty_ = 0; 449 stateCalibrator_ = 0; 450 stateDetector_ = 0; 451 452 // we don't remove the other states yet because the singleton might still exist. 453 // So people can still removeAndDestroy their states 454 //inputStatesByName_.clear(); 455 //inputStatesByPriority_.clear(); 456 457 // destroy the devices 458 _destroyKeyboard(); 459 _destroyMouse(); 460 _destroyJoySticks(); 461 462 _redimensionLists(); 463 464 OIS::InputManager::destroyInputSystem(inputSystem_); 465 inputSystem_ = 0; 466 467 CCOUT(ORX_DEBUG) << "Destroying done." << std::endl; 440 try 441 { 442 CCOUT(3) << "Destroying ..." << std::endl; 443 444 // clear our own states 445 stateEmpty_->removeAndDestroyAllHandlers(); 446 stateCalibrator_->removeAndDestroyAllHandlers(); 447 stateDetector_->removeAndDestroyAllHandlers(); 448 449 // kick all active states 'nicely' 450 for (std::map<int, InputState*>::reverse_iterator rit = activeStates_.rbegin(); 451 rit != activeStates_.rend(); ++rit) 452 { 453 (*rit).second->onLeave(); 454 } 455 activeStates_.clear(); 456 _updateActiveStates(); 457 458 // destroy all input states 459 while (inputStatesByPriority_.size() > 0) 460 { 461 _destroyState((*inputStatesByPriority_.rbegin()).second); 462 } 463 464 stateEmpty_ = 0; 465 stateCalibrator_ = 0; 466 stateDetector_ = 0; 467 468 // destroy the devices 469 _destroyKeyboard(); 470 _destroyMouse(); 471 _destroyJoySticks(); 472 473 // 0 joy sticks now 474 _redimensionLists(); 475 476 OIS::InputManager::destroyInputSystem(inputSystem_); 477 inputSystem_ = 0; 478 479 CCOUT(3) << "Destroying done." << std::endl; 480 } 481 catch (OIS::Exception& ex) 482 { 483 CCOUT(1) << "An exception has occured while destroying:\n" << ex.what() << std::endl; 484 } 468 485 } 469 486 } … … 479 496 keyboard_ = 0; 480 497 keysDown_.clear(); 481 CCOUT( ORX_DEBUG) << "Keyboard destroyed." << std::endl;498 CCOUT(4) << "Keyboard destroyed." << std::endl; 482 499 } 483 500 … … 492 509 mouse_ = 0; 493 510 mouseButtonsDown_.clear(); 494 CCOUT( ORX_DEBUG) << "Mouse destroyed." << std::endl;511 CCOUT(4) << "Mouse destroyed." << std::endl; 495 512 } 496 513 … … 510 527 joySticks_.clear(); 511 528 } 512 CCOUT( ORX_DEBUG) << "Joy sticks destroyed." << std::endl;529 CCOUT(4) << "Joy sticks destroyed." << std::endl; 513 530 } 514 531 … … 597 614 } 598 615 616 /** 617 @brief 618 Updates the currently active states (according to activeStates_) for each device. 619 Also, a list of all active states (no duplicates!) is compiled for the general tick. 620 */ 599 621 void InputManager::_updateActiveStates() 600 622 { … … 616 638 } 617 639 640 /** 641 @brief 642 Processes the accumultated data for the joy stick calibration. 643 */ 618 644 void InputManager::_completeCalibration() 619 645 { … … 676 702 // restore old input state 677 703 requestLeaveState("calibrator"); 704 bCalibrating_ = false; 678 705 } 679 706 … … 822 849 // ###### Joy Stick Events ###### 823 850 851 /** 852 @brief 853 Returns the joy stick ID (orxonox) according to a OIS::JoyStickEvent 854 */ 824 855 inline unsigned int InputManager::_getJoystick(const OIS::JoyStickEvent& arg) 825 856 { … … 839 870 840 871 // check whether the button already is in the list (can happen when focus was lost) 841 std::vector< int>& buttonsDown = joyStickButtonsDown_[iJoyStick];872 std::vector<JoyStickButton::Enum>& buttonsDown = joyStickButtonsDown_[iJoyStick]; 842 873 unsigned int iButton = 0; 843 874 while (iButton < buttonsDown.size() && buttonsDown[iButton] != button) 844 875 iButton++; 845 876 if (iButton == buttonsDown.size()) 846 buttonsDown.push_back( button);847 848 activeStatesTop_[2 + iJoyStick]->joyStickButtonPressed(iJoyStick, button);877 buttonsDown.push_back((JoyStickButton::Enum)button); 878 879 activeStatesTop_[2 + iJoyStick]->joyStickButtonPressed(iJoyStick, (JoyStickButton::Enum)button); 849 880 850 881 return true; … … 856 887 857 888 // remove the button from the joyStickButtonsDown_ list 858 std::vector< int>& buttonsDown = joyStickButtonsDown_[iJoyStick];889 std::vector<JoyStickButton::Enum>& buttonsDown = joyStickButtonsDown_[iJoyStick]; 859 890 for (unsigned int iButton = 0; iButton < buttonsDown.size(); iButton++) 860 891 { … … 866 897 } 867 898 868 activeStatesTop_[2 + iJoyStick]->joyStickButtonReleased(iJoyStick, button);899 activeStatesTop_[2 + iJoyStick]->joyStickButtonReleased(iJoyStick, (JoyStickButton::Enum)button); 869 900 870 901 return true; 871 902 } 872 903 904 /** 905 @brief 906 Calls the states for a particular axis with our enumeration. 907 Used by OIS sliders and OIS axes. 908 */ 873 909 void InputManager::_fireAxis(unsigned int iJoyStick, int axis, int value) 874 910 { … … 919 955 920 956 // translate the POV into 8 simple buttons 957 921 958 int lastState = povStates_[iJoyStick][id]; 922 959 if (lastState & OIS::Pov::North) … … 959 996 } 960 997 961 bool InputManager::initialiseKeyboard()962 {963 return _getInstance()._initialiseKeyboard();964 }965 966 bool InputManager::initialiseMouse()967 {968 return _getInstance()._initialiseMouse();969 }970 971 bool InputManager::initialiseJoySticks()972 {973 return _getInstance()._initialiseJoySticks();974 }975 976 998 int InputManager::numberOfKeyboards() 977 999 { … … 1030 1052 { 1031 1053 _getInstance()._destroy(); 1032 }1033 1034 void InputManager::destroyKeyboard()1035 {1036 return _getInstance()._destroyKeyboard();1037 }1038 1039 void InputManager::destroyMouse()1040 {1041 return _getInstance()._destroyMouse();1042 }1043 1044 void InputManager::destroyJoySticks()1045 {1046 return _getInstance()._destroyJoySticks();1047 1054 } 1048 1055 … … 1068 1075 } 1069 1076 1077 /** 1078 @brief 1079 Method for easily storing a string with the command executor. It is used by the 1080 KeyDetector to get assign commands. The KeyDetector simply executes 1081 the command 'storeKeyStroke myName' for each button/axis. 1082 @remarks 1083 This is only a temporary hack until we thourouhgly support multiple KeyBinders. 1084 @param name 1085 The name of the button/axis. 1086 */ 1070 1087 void InputManager::storeKeyStroke(const std::string& name) 1071 1088 { … … 1075 1092 } 1076 1093 1094 /** 1095 @brief 1096 Assigns a command string to a key/button/axis. The name is determined via KeyDetector 1097 and InputManager::storeKeyStroke(.). 1098 @param command 1099 Command string that can be executed by the CommandExecutor 1100 */ 1077 1101 void InputManager::keyBind(const std::string& command) 1078 1102 { … … 1082 1106 } 1083 1107 1108 /** 1109 @brief 1110 Starts joy stick calibration. 1111 */ 1084 1112 void InputManager::calibrate() 1085 1113 { 1114 _getInstance().bCalibrating_ = true; 1086 1115 requestEnterState("calibrator"); 1087 1116 } … … 1101 1130 @param name 1102 1131 Unique name of the handler. 1132 @param priority 1133 Unique integer number. Higher means more prioritised. 1103 1134 @return 1104 True if added, false if name already existed.1135 True if added, false if name or priority already existed. 1105 1136 */ 1106 1137 bool InputManager::_configureInputState(InputState* state, const std::string& name, int priority) … … 1134 1165 } 1135 1166 1167 /** 1168 @brief 1169 Returns a new SimpleInputState and configures it first. 1170 */ 1136 1171 SimpleInputState* InputManager::createSimpleInputState(const std::string &name, int priority) 1137 1172 { … … 1146 1181 } 1147 1182 1183 /** 1184 @brief 1185 Returns a new ExtendedInputState and configures it first. 1186 */ 1148 1187 ExtendedInputState* InputManager::createExtendedInputState(const std::string &name, int priority) 1149 1188 { … … 1160 1199 /** 1161 1200 @brief 1162 Removes a Key handler from the list.1201 Removes an input state internally. 1163 1202 @param name 1164 Unique name of the handler.1203 Name of the handler. 1165 1204 @return 1166 1205 True if removal was successful, false if name was not found. 1206 @remarks 1207 You can't remove the internal states "empty", "calibrator" and "detector". 1167 1208 */ 1168 1209 bool InputManager::destroyState(const std::string& name) … … 1184 1225 /** 1185 1226 @brief 1186 Returns the pointer to a handler.1227 Returns the pointer to the requested InputState. 1187 1228 @param name 1188 Unique name of the handler.1229 Unique name of the state. 1189 1230 @return 1190 1231 Pointer to the instance, 0 if name was not found. … … 1201 1242 /** 1202 1243 @brief 1203 Returns the current input handling method1244 Returns the current input state (there might be others active too!) 1204 1245 @return 1205 The current input mode.1246 The current highest prioritised active input state. 1206 1247 */ 1207 1248 InputState* InputManager::getCurrentState() … … 1212 1253 /** 1213 1254 @brief 1214 Enables a specific key handler that has already been added. 1255 Activates a specific input state. 1256 It might not be really activated if the priority is too low! 1215 1257 @param name 1216 Unique name of the handler.1258 Unique name of the state. 1217 1259 @return 1218 1260 False if name was not found, true otherwise. … … 1230 1272 } 1231 1273 1274 /** 1275 @brief 1276 Deactivates a specific input state. 1277 @param name 1278 Unique name of the state. 1279 @return 1280 False if name was not found, true otherwise. 1281 */ 1232 1282 bool InputManager::requestLeaveState(const std::string& name) 1233 1283 {
Note: See TracChangeset
for help on using the changeset viewer.