Changeset 5929 for code/trunk/src/libraries/core/input
- Timestamp:
- Oct 12, 2009, 8:20:07 PM (15 years ago)
- Location:
- code/trunk
- Files:
-
- 13 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/core5 (added) merged: 5768-5769,5772,5775-5780,5783-5785,5791-5792,5795-5807,5809-5814,5816-5832,5836-5839,5842-5853,5855-5899,5904-5922,5924-5928
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/core/input/Button.cc
r5781 r5929 170 170 171 171 // evaluate the command 172 CommandEvaluationeval = CommandExecutor::evaluate(commandStr);172 const CommandEvaluation& eval = CommandExecutor::evaluate(commandStr); 173 173 if (!eval.isValid()) 174 174 { 175 parseError("Command evaluation failed.", true);175 parseError("Command evaluation of \"" + commandStr + "\"failed.", true); 176 176 continue; 177 177 } -
code/trunk/src/libraries/core/input/CMakeLists.txt
r5781 r5929 9 9 JoyStickQuantityListener.cc 10 10 KeyBinder.cc 11 KeyBinderManager.cc 11 12 Keyboard.cc 12 13 KeyDetector.cc -
code/trunk/src/libraries/core/input/InputDevice.h
r5781 r5929 41 41 #include <ois/OISInputManager.h> 42 42 43 #include "util/Clock.h" 43 44 #include "util/Debug.h" 44 45 #include "util/Exception.h" 45 #include "core/Clock.h"46 46 #include "InputState.h" 47 47 -
code/trunk/src/libraries/core/input/InputManager.cc
r5781 r5929 41 41 #include <boost/foreach.hpp> 42 42 43 #include "util/Clock.h" 43 44 #include "util/Convert.h" 44 45 #include "util/Exception.h" 45 46 #include "util/ScopeGuard.h" 46 #include "core/Clock.h"47 47 #include "core/CoreIncludes.h" 48 48 #include "core/ConfigValueIncludes.h" … … 53 53 54 54 #include "InputBuffer.h" 55 #include "KeyDetector.h"56 55 #include "JoyStick.h" 57 56 #include "JoyStickQuantityListener.h" … … 88 87 , oisInputManager_(0) 89 88 , devices_(2) 90 , bExclusiveMouse_(false)89 , mouseMode_(MouseMode::Nonexclusive) 91 90 , emptyState_(0) 92 , keyDetector_(0)93 91 , calibratorCallbackHandler_(0) 94 92 { … … 99 97 this->setConfigValues(); 100 98 99 if (GraphicsManager::getInstance().isFullScreen()) 100 mouseMode_ = MouseMode::Exclusive; 101 101 this->loadDevices(); 102 102 … … 105 105 emptyState_->setHandler(&InputHandler::EMPTY); 106 106 activeStates_[emptyState_->getPriority()] = emptyState_; 107 108 // KeyDetector to evaluate a pressed key's name109 InputState* detector = createInputState("detector", false, false, InputStatePriority::Detector);110 // Create a callback to avoid buttonHeld events after the key has been detected111 FunctorMember<InputManager>* bufferFunctor = createFunctor(&InputManager::clearBuffers);112 bufferFunctor->setObject(this);113 detector->setLeaveFunctor(bufferFunctor);114 keyDetector_ = new KeyDetector();115 detector->setHandler(keyDetector_);116 107 117 108 // Joy stick calibration helper callback … … 124 115 this->updateActiveStates(); 125 116 126 { 127 // calibrate console command 128 FunctorMember<InputManager>* functor = createFunctor(&InputManager::calibrate); 129 functor->setObject(this); 130 this->getIdentifier()->addConsoleCommand(createConsoleCommand(functor, "calibrate"), true); 131 } 132 { 133 // reload console command 134 FunctorMember<InputManager>* functor = createFunctor(&InputManager::reload); 135 functor->setObject(this); 136 this->getIdentifier()->addConsoleCommand(createConsoleCommand(functor, "reload"), false); 137 } 117 // calibrate console command 118 this->getIdentifier()->addConsoleCommand(createConsoleCommand(createFunctor(&InputManager::calibrate, this), "calibrate"), true); 119 // reload console command 120 this->getIdentifier()->addConsoleCommand(createConsoleCommand(createFunctor(&InputManager::reload, this), "reload"), false); 138 121 139 122 CCOUT(4) << "Construction complete." << std::endl; … … 172 155 paramList.insert(std::make_pair("w32_keyboard", "DISCL_FOREGROUND")); 173 156 paramList.insert(std::make_pair("w32_mouse", "DISCL_FOREGROUND")); 174 if ( bExclusiveMouse_|| GraphicsManager::getInstance().isFullScreen())157 if (mouseMode_ == MouseMode::Exclusive || GraphicsManager::getInstance().isFullScreen()) 175 158 { 176 159 // Disable Windows key plus special keys (like play, stop, next, etc.) … … 185 168 paramList.insert(std::make_pair("XAutoRepeatOn", "true")); 186 169 187 if ( bExclusiveMouse_|| GraphicsManager::getInstance().isFullScreen())170 if (mouseMode_ == MouseMode::Exclusive || GraphicsManager::getInstance().isFullScreen()) 188 171 { 189 172 if (CommandLine::getValue("keyboard_no_grab").getBool()) … … 274 257 } 275 258 276 void InputManager::setKeyDetectorCallback(const std::string& command)277 {278 this->keyDetector_->setCallbackCommand(command);279 }280 281 259 // ############################################################ 282 260 // ##### Destruction ##### … … 289 267 290 268 // Destroy calibrator helper handler and state 291 delete keyDetector_;292 269 this->destroyState("calibrator"); 293 270 // Destroy KeyDetector and state 294 delete calibratorCallbackHandler_; 295 this->destroyState("detector"); 271 calibratorCallbackHandler_->destroy(); 296 272 // destroy the empty InputState 297 273 this->destroyStateInternal(this->emptyState_); … … 528 504 529 505 // Check whether we have to change the mouse mode 506 MouseMode::Value requestedMode = MouseMode::Dontcare; 530 507 std::vector<InputState*>& mouseStates = devices_[InputDeviceEnumerator::Mouse]->getStateListRef(); 531 if (mouseStates.empty() && bExclusiveMouse_ || 532 !mouseStates.empty() && mouseStates.front()->getIsExclusiveMouse() != bExclusiveMouse_) 533 { 534 bExclusiveMouse_ = !bExclusiveMouse_; 508 if (mouseStates.empty()) 509 requestedMode = MouseMode::Nonexclusive; 510 else 511 requestedMode = mouseStates.front()->getMouseMode(); 512 if (requestedMode != MouseMode::Dontcare && mouseMode_ != requestedMode) 513 { 514 mouseMode_ = requestedMode; 535 515 if (!GraphicsManager::getInstance().isFullScreen()) 536 516 this->reloadInternal(); … … 722 702 } 723 703 statesByName_.erase(state->getName()); 724 delete state;704 state->destroy(); 725 705 } 726 706 } -
code/trunk/src/libraries/core/input/InputManager.h
r5781 r5929 161 161 // Various getters and setters 162 162 //------------------------------- 163 //! Sets the the name of the command used by the KeyDetector as callback.164 void setKeyDetectorCallback(const std::string& command);165 163 //! Returns the number of joy stick that have been created since the c'tor or last call to reload(). 166 164 unsigned int getJoyStickQuantity() const … … 193 191 OIS::InputManager* oisInputManager_; //!< OIS input manager 194 192 std::vector<InputDevice*> devices_; //!< List of all input devices (keyboard, mouse, joy sticks) 195 bool bExclusiveMouse_;//!< Currently applied mouse mode193 MouseMode::Value mouseMode_; //!< Currently applied mouse mode 196 194 197 195 // some internally handled states and handlers 198 196 InputState* emptyState_; //!< Lowest priority states (makes handling easier) 199 KeyDetector* keyDetector_; //!< KeyDetector instance200 197 //! InputBuffer that reacts to the Enter key when calibrating the joy sticks 201 198 InputBuffer* calibratorCallbackHandler_; -
code/trunk/src/libraries/core/input/InputState.cc
r5781 r5929 37 37 , bAlwaysGetsInput_(bAlwaysGetsInput) 38 38 , bTransparent_(bTransparent) 39 , bExclusiveMouse_(true)39 , mouseMode_(MouseMode::Dontcare) 40 40 , bExpired_(true) 41 41 , handlers_(2) -
code/trunk/src/libraries/core/input/InputState.h
r5781 r5929 55 55 static const int Detector = HighPriority + 2; 56 56 }; 57 58 namespace MouseMode 59 { 60 enum Value 61 { 62 Exclusive, 63 Nonexclusive, 64 Dontcare 65 }; 66 } 57 67 58 68 /** … … 120 130 void setHandler (InputHandler* handler); 121 131 122 void set IsExclusiveMouse(bool value) { bExclusiveMouse_ = value; this->bExpired_ = true; }123 bool getIsExclusiveMouse() const { return bExclusiveMouse_; }132 void setMouseMode(MouseMode::Value value) { mouseMode_ = value; this->bExpired_ = true; } 133 MouseMode::Value getMouseMode() const { return mouseMode_; } 124 134 125 135 //! Returns the name of the state (which is unique!) … … 174 184 const bool bAlwaysGetsInput_; //!< See class declaration for explanation 175 185 const bool bTransparent_; //!< See class declaration for explanation 176 bool bExclusiveMouse_;//!< See class declaration for explanation186 MouseMode::Value mouseMode_; //!< See class declaration for explanation 177 187 int priority_; //!< Current priority (might change) 178 188 bool bExpired_; //!< See hasExpired() -
code/trunk/src/libraries/core/input/KeyBinder.cc
r5781 r5929 27 27 */ 28 28 29 /**30 @file31 @brief Implementation of the different input handlers.32 */33 34 29 #include "KeyBinder.h" 35 30 36 31 #include "util/Convert.h" 37 32 #include "util/Debug.h" 33 #include "util/Exception.h" 38 34 #include "core/ConfigValueIncludes.h" 39 35 #include "core/CoreIncludes.h" … … 48 44 Constructor that does as little as necessary. 49 45 */ 50 KeyBinder::KeyBinder( )46 KeyBinder::KeyBinder(const std::string& filename) 51 47 : deriveTime_(0.0f) 48 , filename_(filename) 52 49 { 53 50 mouseRelative_[0] = 0; … … 103 100 // set them here to use allHalfAxes_ 104 101 setConfigValues(); 102 103 // Load the bindings if filename was given 104 if (!this->filename_.empty()) 105 this->loadBindings(); 105 106 } 106 107 … … 240 241 @brief 241 242 Loads the key and button bindings. 242 @return 243 True if loading succeeded. 244 */ 245 void KeyBinder::loadBindings(const std::string& filename) 243 */ 244 void KeyBinder::loadBindings() 246 245 { 247 246 COUT(3) << "KeyBinder: Loading key bindings..." << std::endl; 248 247 249 if (filename.empty()) 250 return; 251 252 if (this->configFile_ == ConfigFileType::NoType) 253 { 254 // Get a new ConfigFileType from the ConfigFileManager 255 this->configFile_ = ConfigFileManager::getInstance().getNewConfigFileType(); 256 } 257 258 ConfigFileManager::getInstance().setFilename(this->configFile_, filename); 248 // Get a new ConfigFileType from the ConfigFileManager 249 this->configFile_ = ConfigFileManager::getInstance().getNewConfigFileType(); 250 251 ConfigFileManager::getInstance().setFilename(this->configFile_, this->filename_); 259 252 260 253 // Parse bindings and create the ConfigValueContainers if necessary 261 clearBindings();262 254 for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it) 263 255 it->second->readConfigValue(this->configFile_); -
code/trunk/src/libraries/core/input/KeyBinder.h
r5781 r5929 26 26 * 27 27 */ 28 29 /**30 @file31 @brief32 Different definitions of input processing.33 */34 28 35 29 #ifndef _KeyBinder_H__ … … 53 47 /** 54 48 @brief 55 Handles mouse, keyboard and joy stick input while in the actual game mode. 56 Manages the key bindings. 49 Maps mouse, keyboard and joy stick input to command strings and executes them. 50 51 The bindings are stored in ini-files (like the one for configValues) in the config Path. 52 @remarks 53 You cannot change the filename because the KeyBinderManager maps these filenames to the 54 KeyBinders. If you need to load other bindings, just create a new one. 57 55 */ 58 56 class _CoreExport KeyBinder : public InputHandler, public JoyStickQuantityListener 59 57 { 60 58 public: 61 KeyBinder ( );59 KeyBinder (const std::string& filename); 62 60 virtual ~KeyBinder(); 63 61 64 void loadBindings(const std::string& filename);65 62 void clearBindings(); 66 63 bool setBinding(const std::string& binding, const std::string& name, bool bTemporary = false); 64 const std::string& getBindingsFilename() 65 { return this->filename_; } 67 66 void setConfigValues(); 68 67 void resetJoyStickAxes(); 69 68 70 69 protected: // functions 70 void loadBindings(); 71 void buttonThresholdChanged(); 72 void initialiseJoyStickBindings(); 73 void compilePointerLists(); 74 // from JoyStickQuantityListener interface 75 virtual void JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList); 76 71 77 void allDevicesUpdated(float dt); 72 78 void mouseUpdated(float dt); … … 74 80 // internal 75 81 void tickHalfAxis(HalfAxis& halfAxis); 76 77 void buttonThresholdChanged();78 // from JoyStickQuantityListener interface79 virtual void JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList);80 void initialiseJoyStickBindings();81 void compilePointerLists();82 82 83 83 void buttonPressed (const KeyEvent& evt); … … 144 144 float deriveTime_; 145 145 146 //! Name of the file used in this KeyBinder (constant!) 147 const std::string filename_; 146 148 //! Config file used. ConfigFileType::NoType in case of KeyDetector. Also indicates whether we've already loaded. 147 149 ConfigFileType configFile_; … … 171 173 }; 172 174 175 173 176 inline void KeyBinder::buttonPressed (const KeyEvent& evt) 174 177 { assert(!keys_[evt.getKeyCode()].name_.empty()); keys_[evt.getKeyCode()].execute(KeybindMode::OnPress); } -
code/trunk/src/libraries/core/input/KeyDetector.cc
r5781 r5929 29 29 #include "KeyDetector.h" 30 30 31 #include " util/Debug.h"31 #include "core/ConsoleCommand.h" 32 32 #include "core/CoreIncludes.h" 33 #include "core/ScopedSingletonManager.h" 33 34 #include "Button.h" 35 #include "InputManager.h" 36 #include "InputState.h" 34 37 35 38 namespace orxonox 36 39 { 37 /**38 @brief39 Constructor40 */ 40 std::string KeyDetector::callbackCommand_s = "KeyDetectorKeyPressed"; 41 KeyDetector* KeyDetector::singletonPtr_s = 0; 42 ManageScopedSingleton(KeyDetector, ScopeID::Graphics, false); 43 41 44 KeyDetector::KeyDetector() 45 : KeyBinder("") 42 46 { 43 47 RegisterObject(KeyDetector); 48 49 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&KeyDetector::callback, this), callbackCommand_s)); 50 this->assignCommands(); 51 52 inputState_ = InputManager::getInstance().createInputState("detector", false, false, InputStatePriority::Detector); 53 // Create a callback to avoid buttonHeld events after the key has been detected 54 inputState_->setLeaveFunctor(createFunctor(&InputManager::clearBuffers, &InputManager::getInstance())); 55 inputState_->setHandler(this); 44 56 } 45 57 46 /**47 @brief48 Destructor49 */50 58 KeyDetector::~KeyDetector() 51 59 { 60 inputState_->setHandler(NULL); 61 InputManager::getInstance().destroyState("detector"); 52 62 } 53 63 54 /** 55 @brief 56 Assigns all the buttons 'command' plus the button's name. 57 */ 58 void KeyDetector::setCallbackCommand(const std::string& command) 64 void KeyDetector::assignCommands() 59 65 { 60 callbackCommand_ = command;66 // Assign every button/axis the same command, but with its name as argument 61 67 clearBindings(); 62 68 for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it) 63 69 { 64 it->second->bindingString_ = callbackCommand_ + it->second->groupName_ + "." + it->second->name_;70 it->second->bindingString_ = callbackCommand_s + " " + it->second->groupName_ + "." + it->second->name_; 65 71 it->second->parse(); 66 72 } 73 } 74 75 void KeyDetector::callback(const std::string& name) 76 { 77 // Call the registered function 78 if (this->callbackFunction_) 79 (*this->callbackFunction_)(name); 67 80 } 68 81 … … 70 83 { 71 84 KeyBinder::JoyStickQuantityChanged(joyStickList); 72 if (!callbackCommand_.empty()) 73 setCallbackCommand(callbackCommand_); 85 this->assignCommands(); 74 86 } 75 87 } -
code/trunk/src/libraries/core/input/KeyDetector.h
r5781 r5929 32 32 #include "InputPrereqs.h" 33 33 34 #include <string>34 #include "util/Singleton.h" 35 35 #include "KeyBinder.h" 36 36 37 37 namespace orxonox 38 38 { 39 class _CoreExport KeyDetector : public KeyBinder 39 class _CoreExport KeyDetector : public KeyBinder, public Singleton<KeyDetector> 40 40 { 41 friend class Singleton<KeyDetector>; 42 41 43 public: 42 44 KeyDetector(); 43 45 ~KeyDetector(); 44 void setCallbackCommand(const std::string& command); 45 void JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList);46 47 void setCallback(Functor* function) { this->callbackFunction_ = function; } 46 48 47 49 private: 48 std::string callbackCommand_; 50 KeyDetector(const KeyDetector&); 51 52 void callback(const std::string& name); 53 void JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList); 54 void assignCommands(); 55 56 Functor* callbackFunction_; 57 InputState* inputState_; 58 static std::string callbackCommand_s; 59 static KeyDetector* singletonPtr_s; 49 60 }; 50 61 } -
code/trunk/src/libraries/core/input/Mouse.cc
r5781 r5929 48 48 49 49 #ifdef ORXONOX_PLATFORM_LINUX 50 { 51 // Mouse grab console command 52 FunctorMember<Mouse>* functor = createFunctor(&Mouse::grab); 53 functor->setObject(this); 54 this->getIdentifier()->addConsoleCommand(createConsoleCommand(functor, "grab"), false); 55 } 56 { 57 // Mouse ungrab console command 58 FunctorMember<Mouse>* functor = createFunctor(&Mouse::ungrab); 59 functor->setObject(this); 60 this->getIdentifier()->addConsoleCommand(createConsoleCommand(functor, "ungrab"), false); 61 } 50 // Mouse grab console command 51 this->getIdentifier()->addConsoleCommand(createConsoleCommand(createFunctor(&Mouse::grab, this), "grab"), false); 52 // Mouse ungrab console command 53 this->getIdentifier()->addConsoleCommand(createConsoleCommand(createFunctor(&Mouse::ungrab, this), "ungrab"), false); 62 54 #endif 63 55 }
Note: See TracChangeset
for help on using the changeset viewer.