Changeset 6412 for code/branches/pickup2/src/libraries/core/input
- Timestamp:
- Dec 25, 2009, 1:18:03 PM (15 years ago)
- Location:
- code/branches/pickup2
- Files:
-
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pickup2
- Property svn:mergeinfo changed
-
code/branches/pickup2/src/libraries/core/input/Button.cc
r5929 r6412 116 116 for (unsigned int iCommand = 0; iCommand < commandStrings.size(); iCommand++) 117 117 { 118 if ( commandStrings[iCommand] != "")118 if (!commandStrings[iCommand].empty()) 119 119 { 120 120 SubString tokens(commandStrings[iCommand], " ", SubString::WhiteSpaces, false, … … 123 123 KeybindMode::Value mode = KeybindMode::None; 124 124 float paramModifier = 1.0f; 125 std::string commandStr = "";125 std::string commandStr; 126 126 127 127 for (unsigned int iToken = 0; iToken < tokens.size(); ++iToken) 128 128 { 129 std::stringtoken = getLowercase(tokens[iToken]);129 const std::string& token = getLowercase(tokens[iToken]); 130 130 131 131 if (token == "onpress") … … 159 159 // we interpret everything from here as a command string 160 160 while (iToken != tokens.size()) 161 commandStr += tokens[iToken++] + " ";162 } 163 } 164 165 if (commandStr == "")161 commandStr += tokens[iToken++] + ' '; 162 } 163 } 164 165 if (commandStr.empty()) 166 166 { 167 167 parseError("No command string given.", false); … … 242 242 } 243 243 244 inline void Button::parseError( std::stringmessage, bool serious)244 inline void Button::parseError(const std::string& message, bool serious) 245 245 { 246 246 if (serious) -
code/branches/pickup2/src/libraries/core/input/Button.h
r5781 r6412 76 76 77 77 private: 78 void parseError( std::stringmessage, bool serious);78 void parseError(const std::string& message, bool serious); 79 79 }; 80 80 -
code/branches/pickup2/src/libraries/core/input/InputBuffer.cc
r5781 r6412 39 39 RegisterRootObject(InputBuffer); 40 40 41 this->buffer_ = "";42 41 this->cursor_ = 0; 42 this->maxLength_ = 1024; 43 43 this->allowedChars_ = "abcdefghijklmnopqrstuvwxyz \ 44 44 ABCDEFGHIJKLMNOPQRSTUVWXYZ \ … … 59 59 RegisterRootObject(InputBuffer); 60 60 61 this->maxLength_ = 1024; 61 62 this->allowedChars_ = allowedChars; 62 this->buffer_ = "";63 63 this->cursor_ = 0; 64 64 … … 80 80 void InputBuffer::setConfigValues() 81 81 { 82 SetConfigValue(keyRepeatDeleay_, 0.4).description("Key repeat del eay of the input buffer");82 SetConfigValue(keyRepeatDeleay_, 0.4).description("Key repeat delay of the input buffer"); 83 83 SetConfigValue(keyRepeatTime_, 0.022).description("Key repeat time of the input buffer"); 84 84 … … 91 91 ResetConfigValue(keyRepeatTime_); 92 92 } 93 } 94 95 void InputBuffer::setMaxLength(unsigned int length) 96 { 97 this->maxLength_ = length; 98 if (this->buffer_.size() > length) 99 this->buffer_.resize(length); 93 100 } 94 101 … … 117 124 if (this->charIsAllowed(input)) 118 125 { 126 if (this->buffer_.size() >= this->maxLength_) 127 return; 119 128 this->buffer_.insert(this->cursor_, 1, input); 120 129 ++this->cursor_; … … 127 136 void InputBuffer::clear(bool update) 128 137 { 129 this->buffer_ = "";138 this->buffer_.clear(); 130 139 this->cursor_ = 0; 131 140 … … 177 186 bool InputBuffer::charIsAllowed(const char& input) 178 187 { 179 if (this->allowedChars_ == "")188 if (this->allowedChars_.empty()) 180 189 return true; 181 190 else … … 186 195 void InputBuffer::processKey(const KeyEvent& evt) 187 196 { 197 // Prevent disaster when switching applications 188 198 if (evt.isModifierDown(KeyboardModifier::Alt) && evt.getKeyCode() == KeyCode::Tab) 189 199 return; … … 222 232 223 233 /** 224 @brief This update() function is called by the Input Managerif the InputBuffer is active.234 @brief This update() function is called by the InputState if the InputBuffer is active. 225 235 @param dt Delta time 226 236 */ -
code/branches/pickup2/src/libraries/core/input/InputBuffer.h
r5781 r6412 83 83 void setConfigValues(); 84 84 85 unsigned int getMaxLength() const { return this->maxLength_; } 86 void setMaxLength(unsigned int length); 87 85 88 template <class T> 86 89 void registerListener(T* listener, void (T::*function)(), bool bOnlySingleInput) … … 162 165 { if (this->cursor_ > 0) { --this->cursor_; } } 163 166 167 void buttonPressed(const KeyEvent& evt); 168 164 169 private: 165 170 bool charIsAllowed(const char& input); 166 171 167 void buttonPressed(const KeyEvent& evt);168 172 void buttonHeld (const KeyEvent& evt); 169 173 void processKey (const KeyEvent& evt); … … 174 178 std::list<BaseInputBufferListenerTuple*> listeners_; 175 179 std::string allowedChars_; 180 unsigned int maxLength_; 176 181 unsigned int cursor_; 177 182 -
code/branches/pickup2/src/libraries/core/input/InputCommands.h
r5781 r6412 71 71 @brief 72 72 Executes a simple command with no additional paramters. 73 @return 73 @return 74 74 True if command execution was successful, false otherwise. 75 75 */ -
code/branches/pickup2/src/libraries/core/input/InputDevice.h
r5929 r6412 203 203 { 204 204 // remove the button from the pressedButtons_ list 205 bool found = false; 205 206 for (unsigned int iButton = 0; iButton < pressedButtons_.size(); iButton++) 206 207 { … … 208 209 { 209 210 pressedButtons_.erase(pressedButtons_.begin() + iButton); 211 found = true; 210 212 break; 211 213 } 212 214 } 215 if (!found) 216 return; // We ignore release strokes when the press was not captured 213 217 214 218 // Call states -
code/branches/pickup2/src/libraries/core/input/InputHandler.h
r5781 r6412 73 73 , modifiers_(0) 74 74 { } 75 KeyEvent(KeyCode::ByEnum key, unsigned int text, int modifiers) 76 : key_(key) 77 , text_(text) 78 , modifiers_(modifiers) 79 { } 75 80 bool operator==(const KeyEvent& rhs) const 76 81 { return rhs.key_ == key_; } … … 97 102 98 103 Derive from this class if you wish to receive input events. 99 But keep in mind that this is pointless wi htout first having an InputState.104 But keep in mind that this is pointless without first having an InputState. 100 105 @note 101 106 The definitions for the button events with the weird arguments are simply 102 to avoid redun ant code in the input devices.107 to avoid redundant code in the input devices. 103 108 */ 104 109 class _CoreExport InputHandler -
code/branches/pickup2/src/libraries/core/input/InputManager.cc
r5929 r6412 48 48 #include "core/ConfigValueIncludes.h" 49 49 #include "core/ConsoleCommand.h" 50 #include "core/CommandLine .h"50 #include "core/CommandLineParser.h" 51 51 #include "core/Functor.h" 52 52 #include "core/GraphicsManager.h" … … 170 170 if (mouseMode_ == MouseMode::Exclusive || GraphicsManager::getInstance().isFullScreen()) 171 171 { 172 if (CommandLine ::getValue("keyboard_no_grab").getBool())172 if (CommandLineParser::getValue("keyboard_no_grab").getBool()) 173 173 paramList.insert(std::make_pair("x11_keyboard_grab", "false")); 174 174 else … … 190 190 // Exception-safety 191 191 Loki::ScopeGuard guard = Loki::MakeGuard(OIS::InputManager::destroyInputSystem, oisInputManager_); 192 CCOUT( ORX_DEBUG) << "Created OIS input manager." << std::endl;192 CCOUT(4) << "Created OIS input manager." << std::endl; 193 193 194 194 if (oisInputManager_->getNumberOfDevices(OIS::OISKeyboard) > 0) … … 232 232 } 233 233 else 234 CCOUT( ORX_WARNING) << "Warning: No mouse found! Proceeding without mouse support." << std::endl;234 CCOUT(2) << "Warning: No mouse found! Proceeding without mouse support." << std::endl; 235 235 } 236 236 … … 275 275 // destroy all user InputStates 276 276 while (statesByName_.size() > 0) 277 this->destroyStateInternal( (*statesByName_.rbegin()).second);277 this->destroyStateInternal(statesByName_.rbegin()->second); 278 278 279 279 if (!(internalState_ & Bad)) … … 297 297 if (device == NULL) 298 298 continue; 299 std::stringclassName = device->getClassName();299 const std::string& className = device->getClassName(); 300 300 try 301 301 { … … 366 366 // ############################################################ 367 367 368 void InputManager:: update(const Clock& time)368 void InputManager::preUpdate(const Clock& time) 369 369 { 370 370 if (internalState_ & Bad) … … 466 466 @brief 467 467 Updates the currently active states (according to activeStates_) for each device. 468 Also, a list of all active states (no duplicates!) is compiled for the general update().468 Also, a list of all active states (no duplicates!) is compiled for the general preUpdate(). 469 469 */ 470 470 void InputManager::updateActiveStates() … … 508 508 if (mouseStates.empty()) 509 509 requestedMode = MouseMode::Nonexclusive; 510 else 510 else 511 511 requestedMode = mouseStates.front()->getMouseMode(); 512 512 if (requestedMode != MouseMode::Dontcare && mouseMode_ != requestedMode) … … 554 554 } 555 555 556 //! Gets called by WindowEventListener upon focus change --> clear buffers 556 //! Gets called by WindowEventListener upon focus change --> clear buffers 557 557 void InputManager::windowFocusChanged() 558 558 { … … 579 579 InputState* InputManager::createInputState(const std::string& name, bool bAlwaysGetsInput, bool bTransparent, InputStatePriority priority) 580 580 { 581 if (name == "")581 if (name.empty()) 582 582 return 0; 583 583 if (statesByName_.find(name) == statesByName_.end()) … … 631 631 { 632 632 // not scheduled for destruction 633 // prevents a state being added multiple times633 // prevents a state from being added multiple times 634 634 stateEnterRequests_.insert(it->second); 635 635 return true; 636 636 } 637 637 } 638 else if (this->stateLeaveRequests_.find(it->second) != this->stateLeaveRequests_.end()) 639 { 640 // State already scheduled for leaving --> cancel 641 this->stateLeaveRequests_.erase(this->stateLeaveRequests_.find(it->second)); 642 } 638 643 } 639 644 return false; … … 658 663 return true; 659 664 } 665 else if (this->stateEnterRequests_.find(it->second) != this->stateEnterRequests_.end()) 666 { 667 // State already scheduled for entering --> cancel 668 this->stateEnterRequests_.erase(this->stateEnterRequests_.find(it->second)); 669 } 660 670 } 661 671 return false; -
code/branches/pickup2/src/libraries/core/input/InputManager.h
r5929 r6412 41 41 #include "InputState.h" 42 42 43 // tolua_begin 43 44 namespace orxonox 44 45 { … … 47 48 Manages the input devices (mouse, keyboard, joy sticks) and the input states. 48 49 49 Every input device has its own wrapper class which does the actual y input event50 Every input device has its own wrapper class which does the actually input event 50 51 distribution. The InputManager only creates reloads (on request) those devices. 51 52 … … 58 59 in the InputDevices themselves. 59 60 - The devices_ vector always has at least two elements: Keyboard (first) and mouse. 60 You best access them inte nally with InputDeviceEnumerator::Keyboard/Mouse61 You best access them internally with InputDeviceEnumerator::Keyboard/Mouse 61 62 The first joy stick is accessed with InputDeviceEnumerator::FirstJoyStick. 62 63 - Keyboard construction is mandatory , mouse and joy sticks are not. 63 64 If the OIS::InputManager or the Keyboard fail, an exception is thrown. 64 65 */ 65 class _CoreExport InputManager : public Singleton<InputManager>, public WindowEventListener 66 { 66 class _CoreExport InputManager 67 // tolua_end 68 : public Singleton<InputManager>, public WindowEventListener 69 { // tolua_export 67 70 friend class Singleton<InputManager>; 68 71 public: … … 80 83 @brief 81 84 Loads the devices and initialises the KeyDetector and the Calibrator. 82 85 83 86 If either the OIS input system and/or the keyboard could not be created, 84 87 the constructor fails with an std::exception. … … 94 97 95 98 Any InpuStates changes (destroy, enter, leave) and happens here. If a reload request 96 was submitted while updating, the request wil be postponed until the next update call.97 */ 98 void update(const Clock& time);99 was submitted while updating, the request will be postponed until the next update call. 100 */ 101 void preUpdate(const Clock& time); 99 102 //! Clears all input device buffers. This usually only includes the pressed button list. 100 103 void clearBuffers(); … … 105 108 Reloads all the input devices. Use this method to initialise new joy sticks. 106 109 @note 107 Only reloads immediately if the call stack doesn't include the update() method.110 Only reloads immediately if the call stack doesn't include the preUpdate() method. 108 111 */ 109 112 void reload(); … … 135 138 @brief 136 139 Activates a specific input state. 137 It might not be actuallyactivated if the priority is too low!140 It might not actually be activated if the priority is too low! 138 141 @return 139 142 False if name was not found, true otherwise. 140 143 */ 141 bool enterState(const std::string& name); 144 bool enterState(const std::string& name); // tolua_export 142 145 /** 143 146 @brief … … 146 149 False if name was not found, true otherwise. 147 150 */ 148 bool leaveState(const std::string& name); 151 bool leaveState(const std::string& name); // tolua_export 149 152 /** 150 153 @brief … … 154 157 @remarks 155 158 - You can't remove the internal states "empty", "calibrator" and "detector". 156 - The removal process is being postponed if InputManager:: update() is currently running.159 - The removal process is being postponed if InputManager::preUpdate() is currently running. 157 160 */ 158 161 bool destroyState(const std::string& name); … … 168 171 std::pair<int, int> getMousePosition() const; 169 172 173 static InputManager& getInstance() { return Singleton<InputManager>::getInstance(); } // tolua_export 174 170 175 private: // functions 171 176 // don't mess with a Singleton 172 177 InputManager(const InputManager&); 173 178 174 // Inte nal methods179 // Internal methods 175 180 void loadDevices(); 176 181 void loadMouse(); … … 207 212 208 213 static InputManager* singletonPtr_s; //!< Pointer reference to the singleton 209 }; 210 } 214 }; // tolua_export 215 } // tolua_export 211 216 212 217 #endif /* _InputManager_H__ */ -
code/branches/pickup2/src/libraries/core/input/InputPrereqs.h
r5781 r6412 202 202 MediaSelect = OIS::KC_MEDIASELECT // Media Select 203 203 }; 204 204 205 205 //! Key codes as strings 206 206 const char* const ByString[] = -
code/branches/pickup2/src/libraries/core/input/InputState.cc
r5929 r6412 102 102 if (enterFunctor_) 103 103 (*enterFunctor_)(); 104 104 105 105 } 106 106 -
code/branches/pickup2/src/libraries/core/input/JoyStick.cc
r5781 r6412 33 33 #include <boost/foreach.hpp> 34 34 35 #include "util/StringUtils.h" 35 36 #include "core/ConfigFileManager.h" 36 37 #include "core/ConfigValueIncludes.h" … … 61 62 std::string name = oisDevice_->vendor(); 62 63 replaceCharacters(name, ' ', '_'); 63 deviceName_ = name + "_";64 } 65 deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Button)) + "_";66 deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Axis)) + "_";67 deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Slider)) + "_";64 deviceName_ = name + '_'; 65 } 66 deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Button)) + '_'; 67 deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Axis)) + '_'; 68 deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Slider)) + '_'; 68 69 deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_POV)); 69 70 //deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Vector3)); … … 74 75 { 75 76 // Make the ID unique for this execution time. 76 deviceName_ += "_"+ multi_cast<std::string>(this->getDeviceName());77 deviceName_ += '_' + multi_cast<std::string>(this->getDeviceName()); 77 78 break; 78 79 } -
code/branches/pickup2/src/libraries/core/input/JoyStickQuantityListener.h
r5781 r6412 29 29 /** 30 30 @file 31 @brief 31 @brief 32 32 */ 33 33 -
code/branches/pickup2/src/libraries/core/input/KeyBinder.cc
r5929 r6412 29 29 #include "KeyBinder.h" 30 30 31 #include <algorithm> 32 #include <sstream> 31 33 #include "util/Convert.h" 32 34 #include "util/Debug.h" … … 50 52 mouseRelative_[0] = 0; 51 53 mouseRelative_[1] = 0; 52 mousePosition_[0] = 0 ;53 mousePosition_[1] = 0 ;54 mousePosition_[0] = 0.0; 55 mousePosition_[1] = 0.0; 54 56 55 57 RegisterRootObject(KeyBinder); … … 59 61 for (unsigned int i = 0; i < KeyCode::numberOfKeys; i++) 60 62 { 61 std::stringkeyname = KeyCode::ByString[i];63 const std::string& keyname = KeyCode::ByString[i]; 62 64 if (!keyname.empty()) 63 65 keys_[i].name_ = std::string("Key") + keyname; 64 66 else 65 keys_[i].name_ = "";67 keys_[i].name_.clear(); 66 68 keys_[i].paramCommandBuffer_ = ¶mCommandBuffer_; 67 69 keys_[i].groupName_ = "Keys"; … … 126 128 SetConfigValue(bFilterAnalogNoise_, false) 127 129 .description("Specifies whether to filter small analog values like joy stick fluctuations."); 128 SetConfigValue(mouseSensitivity_, 1.0f)130 SetConfigValue(mouseSensitivity_, 3.0f) 129 131 .description("Mouse sensitivity."); 132 this->totalMouseSensitivity_ = this->mouseSensitivity_ / this->mouseClippingSize_; 130 133 SetConfigValue(bDeriveMouseInput_, false) 131 134 .description("Whether or not to derive moues movement for the absolute value."); … … 185 188 this->joyStickButtons_.resize(joySticks_.size()); 186 189 187 // reinitialise all joy stick bin ings (doesn't overwrite the old ones)190 // reinitialise all joy stick bindings (doesn't overwrite the old ones) 188 191 for (unsigned int iDev = 0; iDev < joySticks_.size(); iDev++) 189 192 { 190 std::stringdeviceName = joySticks_[iDev]->getDeviceName();193 const std::string& deviceName = joySticks_[iDev]->getDeviceName(); 191 194 // joy stick buttons 192 195 for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; i++) … … 218 221 for (unsigned int i = 0; i < KeyCode::numberOfKeys; i++) 219 222 if (!keys_[i].name_.empty()) 220 allButtons_[keys_[i].groupName_ + "."+ keys_[i].name_] = keys_ + i;223 allButtons_[keys_[i].groupName_ + '.' + keys_[i].name_] = keys_ + i; 221 224 for (unsigned int i = 0; i < numberOfMouseButtons_; i++) 222 allButtons_[mouseButtons_[i].groupName_ + "."+ mouseButtons_[i].name_] = mouseButtons_ + i;225 allButtons_[mouseButtons_[i].groupName_ + '.' + mouseButtons_[i].name_] = mouseButtons_ + i; 223 226 for (unsigned int i = 0; i < MouseAxisCode::numberOfAxes * 2; i++) 224 227 { 225 allButtons_[mouseAxes_[i].groupName_ + "."+ mouseAxes_[i].name_] = mouseAxes_ + i;228 allButtons_[mouseAxes_[i].groupName_ + '.' + mouseAxes_[i].name_] = mouseAxes_ + i; 226 229 allHalfAxes_.push_back(mouseAxes_ + i); 227 230 } … … 229 232 { 230 233 for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; i++) 231 allButtons_[(*joyStickButtons_[iDev])[i].groupName_ + "."+ (*joyStickButtons_[iDev])[i].name_] = &((*joyStickButtons_[iDev])[i]);234 allButtons_[(*joyStickButtons_[iDev])[i].groupName_ + '.' + (*joyStickButtons_[iDev])[i].name_] = &((*joyStickButtons_[iDev])[i]); 232 235 for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++) 233 236 { 234 allButtons_[(*joyStickAxes_[iDev])[i].groupName_ + "."+ (*joyStickAxes_[iDev])[i].name_] = &((*joyStickAxes_[iDev])[i]);237 allButtons_[(*joyStickAxes_[iDev])[i].groupName_ + '.' + (*joyStickAxes_[iDev])[i].name_] = &((*joyStickAxes_[iDev])[i]); 235 238 allHalfAxes_.push_back(&((*joyStickAxes_[iDev])[i])); 236 239 } … … 253 256 // Parse bindings and create the ConfigValueContainers if necessary 254 257 for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it) 258 { 255 259 it->second->readConfigValue(this->configFile_); 260 addButtonToCommand(it->second->bindingString_, it->second); 261 } 256 262 257 263 COUT(3) << "KeyBinder: Loading key bindings done." << std::endl; … … 263 269 if (it != allButtons_.end()) 264 270 { 271 addButtonToCommand(binding, it->second); 265 272 if (bTemporary) 266 273 it->second->configContainer_->tset(binding); … … 275 282 return false; 276 283 } 284 } 285 286 void KeyBinder::addButtonToCommand(const std::string& command, Button* button) 287 { 288 std::ostringstream stream; 289 stream << button->groupName_ << '.' << button->name_; 290 291 std::vector<std::string>& oldKeynames = this->allCommands_[button->bindingString_]; 292 std::vector<std::string>::iterator it = std::find(oldKeynames.begin(), oldKeynames.end(), stream.str()); 293 if(it != oldKeynames.end()) 294 { 295 oldKeynames.erase(it); 296 } 297 298 if (!command.empty()) 299 { 300 std::vector<std::string>& keynames = this->allCommands_[command]; 301 if( std::find(keynames.begin(), keynames.end(), stream.str()) == keynames.end()) 302 { 303 this->allCommands_[command].push_back(stream.str()); 304 } 305 } 306 } 307 308 /** 309 @brief 310 Return the first key name for a specific command 311 */ 312 const std::string& KeyBinder::getBinding(const std::string& commandName) 313 { 314 if( this->allCommands_.find(commandName) != this->allCommands_.end()) 315 { 316 std::vector<std::string>& keynames = this->allCommands_[commandName]; 317 return keynames.front(); 318 } 319 320 return BLANKSTRING; 321 } 322 323 /** 324 @brief 325 Return the key name for a specific command at a given index. 326 @param commandName 327 The command name the key name is returned for. 328 @param index 329 The index at which the key name is returned for. 330 */ 331 const std::string& KeyBinder::getBinding(const std::string& commandName, unsigned int index) 332 { 333 if( this->allCommands_.find(commandName) != this->allCommands_.end()) 334 { 335 std::vector<std::string>& keynames = this->allCommands_[commandName]; 336 if(index < keynames.size()) 337 { 338 return keynames[index]; 339 } 340 341 return BLANKSTRING; 342 } 343 344 return BLANKSTRING; 345 } 346 347 /** 348 @brief 349 Get the number of different key bindings of a specific command. 350 @param commandName 351 The command. 352 */ 353 unsigned int KeyBinder::getNumberOfBindings(const std::string& commandName) 354 { 355 if( this->allCommands_.find(commandName) != this->allCommands_.end()) 356 { 357 std::vector<std::string>& keynames = this->allCommands_[commandName]; 358 return keynames.size(); 359 } 360 361 return 0; 277 362 } 278 363 … … 395 480 396 481 // these are the actually useful axis bindings for analog input 397 if (!bFilterAnalogNoise_ || halfAxis.relVal_ > analogThreshold_ || halfAxis.absVal_ > analogThreshold_) 398 { 399 halfAxis.execute(); 400 } 482 halfAxis.execute(); 401 483 } 402 484 … … 426 508 mouseAxes_[2*i + 0].hasChanged_ = true; 427 509 mouseAxes_[2*i + 1].hasChanged_ = true; 428 mousePosition_[i] += rel[i] ;510 mousePosition_[i] += rel[i] * totalMouseSensitivity_; 429 511 430 512 // clip absolute position 431 if (mousePosition_[i] > mouseClippingSize_)432 mousePosition_[i] = mouseClippingSize_;433 if (mousePosition_[i] < - mouseClippingSize_)434 mousePosition_[i] = - mouseClippingSize_;435 436 if (mousePosition_[i] < 0 )513 if (mousePosition_[i] > 1.0) 514 mousePosition_[i] = 1.0; 515 if (mousePosition_[i] < -1.0) 516 mousePosition_[i] = -1.0; 517 518 if (mousePosition_[i] < 0.0) 437 519 { 438 mouseAxes_[2*i + 0].absVal_ = -mouse Sensitivity_ * mousePosition_[i] / mouseClippingSize_;520 mouseAxes_[2*i + 0].absVal_ = -mousePosition_[i]; 439 521 mouseAxes_[2*i + 1].absVal_ = 0.0f; 440 522 } … … 442 524 { 443 525 mouseAxes_[2*i + 0].absVal_ = 0.0f; 444 mouseAxes_[2*i + 1].absVal_ = mouse Sensitivity_ * mousePosition_[i] / mouseClippingSize_;526 mouseAxes_[2*i + 1].absVal_ = mousePosition_[i]; 445 527 } 446 528 } … … 452 534 { 453 535 if (rel[i] < 0) 454 mouseAxes_[0 + 2*i].relVal_ = - mouseSensitivity_ * rel[i] / mouseClippingSize_;536 mouseAxes_[0 + 2*i].relVal_ = -rel[i] * totalMouseSensitivity_; 455 537 else 456 mouseAxes_[1 + 2*i].relVal_ = mouseSensitivity_ * rel[i] / mouseClippingSize_;538 mouseAxes_[1 + 2*i].relVal_ = rel[i] * totalMouseSensitivity_; 457 539 } 458 540 } … … 474 556 void KeyBinder::axisMoved(unsigned int device, unsigned int axisID, float value) 475 557 { 558 // Filter analog noise 559 if (this->bFilterAnalogNoise_ && std::abs(value) < this->analogThreshold_) 560 value = 0.0; 476 561 int i = axisID * 2; 477 562 JoyStickAxisVector& axis = *joyStickAxes_[device]; -
code/branches/pickup2/src/libraries/core/input/KeyBinder.h
r5929 r6412 35 35 #include <string> 36 36 #include <vector> 37 #include <map> 37 38 #include <boost/shared_ptr.hpp> 38 39 … … 43 44 #include "JoyStickQuantityListener.h" 44 45 46 // tolua_begin 45 47 namespace orxonox 46 48 { 49 // tolua_end 47 50 /** 48 51 @brief … … 54 57 KeyBinders. If you need to load other bindings, just create a new one. 55 58 */ 56 class _CoreExport KeyBinder : public InputHandler, public JoyStickQuantityListener 57 { 59 class _CoreExport KeyBinder // tolua_export 60 : public InputHandler, public JoyStickQuantityListener 61 { // tolua_export 58 62 public: 59 63 KeyBinder (const std::string& filename); … … 62 66 void clearBindings(); 63 67 bool setBinding(const std::string& binding, const std::string& name, bool bTemporary = false); 68 const std::string& getBinding(const std::string& commandName); //tolua_export 69 const std::string& getBinding(const std::string& commandName, unsigned int index); //tolua_export 70 unsigned int getNumberOfBindings(const std::string& commandName); //tolua_export 71 64 72 const std::string& getBindingsFilename() 65 73 { return this->filename_; } … … 130 138 //! Pointer list with all half axes 131 139 std::vector<HalfAxis*> allHalfAxes_; 140 //! Maps input commands to all Button names, including half axes 141 std::map< std::string, std::vector<std::string> > allCommands_; 132 142 133 143 /** … … 138 148 std::vector<BufferedParamCommand*> paramCommandBuffer_; 139 149 140 //! Keeps track of the absolute mouse value (incl. scroll wheel)141 int mousePosition_[2];150 //! Keeps track of the absolute mouse value 151 float mousePosition_[2]; 142 152 //! Used to derive mouse input if requested 143 153 int mouseRelative_[2]; … … 150 160 151 161 private: 162 void addButtonToCommand(const std::string& command, Button* button); 163 152 164 //##### ConfigValues ##### 153 165 //! Whether to filter small value analog input … … 165 177 //! mouse sensitivity if mouse input is derived 166 178 float mouseSensitivityDerived_; 167 //! Equals one step of the mouse wheel179 //! Equals one step of the mouse wheel 168 180 int mouseWheelStepSize_; 181 182 //! Multiplication of mouse sensitivity and clipping size 183 float totalMouseSensitivity_; 169 184 170 185 //##### Constant config variables ##### 171 186 // Use some value at about 1000. This can be configured with mouseSensitivity_ anyway. 172 187 static const int mouseClippingSize_ = 1024; 173 }; 188 };// tolua_export 174 189 175 190 … … 216 231 mouseAxes_[i].relVal_ = 0.0f; 217 232 } 218 } 233 }// tolua_export 219 234 220 235 #endif /* _KeyBinder_H__ */ -
code/branches/pickup2/src/libraries/core/input/KeyBinderManager.cc
r5929 r6412 40 40 namespace orxonox 41 41 { 42 KeyBinderManager* KeyBinderManager::singletonPtr_s = 0;43 42 ManageScopedSingleton(KeyBinderManager, ScopeID::Graphics, false); 44 43 … … 48 47 , bBinding_(false) 49 48 { 50 this->callbackFunction_ = createFunctor(&KeyBinderManager::callback, this);51 52 49 RegisterObject(KeyBinderManager); 53 50 this->setConfigValues(); … … 57 54 .defaultValues(""); 58 55 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&KeyBinderManager::tkeybind, this), "tkeybind")) 56 .defaultValues(""); 57 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&KeyBinderManager::unbind, this), "unbind")) 58 .defaultValues(""); 59 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&KeyBinderManager::tunbind, this), "tunbind")) 59 60 .defaultValues(""); 60 61 … … 68 69 for (std::map<std::string, KeyBinder*>::const_iterator it = this->binders_.begin(); it != this->binders_.end(); ++it) 69 70 delete it->second; 70 delete this->callbackFunction_;71 71 } 72 72 … … 91 91 else 92 92 this->bDefaultFileLoaded_ = false; 93 } 94 95 inline void KeyBinderManager::unbind(const std::string& binding) 96 { 97 this->currentBinder_->setBinding("", binding, false); 98 } 99 100 inline void KeyBinderManager::tunbind(const std::string& binding) 101 { 102 this->currentBinder_->setBinding("", binding, true); 93 103 } 94 104 … … 146 156 { 147 157 COUT(0) << "Press any button/key or move a mouse/joystick axis" << std::endl; 148 KeyDetector::getInstance().setCallback( callbackFunction_);158 KeyDetector::getInstance().setCallback(shared_ptr<Functor>(createFunctor(&KeyBinderManager::keybindKeyPressed, this))); 149 159 InputManager::getInstance().enterState("detector"); 150 160 this->command_ = command; … … 156 166 157 167 // Gets called by the KeyDetector (registered with a Functor) 158 void KeyBinderManager:: callback(const std::string& keyName)168 void KeyBinderManager::keybindKeyPressed(const std::string& keyName) 159 169 { 160 170 if (this->bBinding_) 161 171 { 162 COUT(0) << "Binding string \"" << command_ << "\" on key '" << keyName << "'" << std::endl; 163 this->currentBinder_->setBinding(command_, keyName, bTemporary_); 172 if (keyName == "Keys.KeyEscape") 173 { 174 COUT(0) << "Keybinding aborted." << std::endl; 175 } 176 else 177 { 178 COUT(0) << "Binding string \"" << command_ << "\" on key '" << keyName << "'" << std::endl; 179 this->currentBinder_->setBinding(command_, keyName, bTemporary_); 180 } 164 181 InputManager::getInstance().leaveState("detector"); 182 // inform whatever was calling the command 183 if (this->callbackFunction_) 184 (*this->callbackFunction_)(); 165 185 this->bBinding_ = false; 166 186 } -
code/branches/pickup2/src/libraries/core/input/KeyBinderManager.h
r5929 r6412 34 34 #include <map> 35 35 #include <string> 36 #include <boost/shared_ptr.hpp> 37 36 38 #include "util/Singleton.h" 37 39 #include "core/OrxonoxClass.h" 38 40 39 namespace orxonox 40 { 41 namespace orxonox //tolua_export 42 { //tolua_export 41 43 /** 42 44 @brief … … 46 48 maps to the currently active KeyBinder. You can set that with setCurrent(). 47 49 There is also a default one, retrieved with getDefault(). The idea is that 48 mostly the default KeyBinder is active except for special situ tations (mini-game for inst).50 mostly the default KeyBinder is active except for special situations (mini-game for inst). 49 51 @remarks 50 52 You are not forced to use the KeyBinder imposed by getCurrent(). But be aware that "keybind" 51 53 will not work as expected! 52 54 */ 53 class _CoreExport KeyBinderManager : public Singleton<KeyBinderManager>, public OrxonoxClass 54 { 55 class _CoreExport KeyBinderManager //tolua_export 56 : public Singleton<KeyBinderManager>, public OrxonoxClass 57 { //tolua_export 55 58 friend class Singleton<KeyBinderManager>; 56 59 public: … … 59 62 void setConfigValues(); 60 63 64 static KeyBinderManager& getInstance() { return Singleton<KeyBinderManager>::getInstance(); } //tolua_export 61 65 //! Returns the currently selected KeyBinder 62 KeyBinder* getCurrent() 63 { return this->currentBinder_; } 66 KeyBinder* getCurrent() { return this->currentBinder_; } //tolua_export 64 67 //! Like getCurrent(), but returns it as InputHandler* (so you don't have to include KeyBinder.h) 65 68 InputHandler* getCurrentAsHandler(); … … 68 71 69 72 //! Returns the default KeyBinder 70 KeyBinder* 73 KeyBinder* getDefault() 71 74 { return binders_[this->defaultFilename_]; } 72 75 //! Returns the default KeyBinder as InputHandler* (so you don't have to include KeyBinder.h) … … 80 83 81 84 //! Returns a pointer to a KeyBinder (creates it if not yet loaded) 82 KeyBinder* 85 KeyBinder* get(const std::string& name); 83 86 //! Like get() but return value is of type InputHandler* (so you don't have to include KeyBinder.h) 84 87 InputHandler* getAsHandler(const std::string& name); 85 88 86 89 //! Loads a KeyBinder by creating it (no different from get() except for the return value) 87 void load 90 void load(const std::string& filename); 88 91 //! Destroys a KeyBinder completely (does nothing if not yet loaded) 89 92 void unload(const std::string& filename); 90 93 91 94 //! Bind 'command' to any key pressed after this call (use with care!) 92 inline void keybind(const std::string& command) 93 { this->keybindInternal(command, false); } 95 inline void keybind(const std::string& command) { this->keybindInternal(command, false); } //tolua_export 94 96 //! Bind 'command' to any key pressed after this call (use with care!), but temporarily (no file save) 95 97 inline void tkeybind(const std::string& command) 96 98 { this->keybindInternal(command, true); } 99 void unbind(const std::string& binding); //tolua_export 100 void tunbind(const std::string& binding); 101 inline void registerKeybindCallback(Functor* function) { this->callbackFunction_.reset(function); } // tolua_export 97 102 98 103 private: 99 104 KeyBinderManager(const KeyBinderManager&); 100 105 void keybindInternal(const std::string& command, bool bTemporary); 101 void callback(const std::string& keyName);106 void keybindKeyPressed(const std::string& keyName); 102 107 void defaultFilenameChanged(); 103 108 … … 109 114 110 115 // keybind command related 111 Functor* callbackFunction_;//! Function to be called when key was pressed after "keybind" command116 shared_ptr<Functor> callbackFunction_; //! Function to be called when key was pressed after "keybind" command 112 117 bool bBinding_; //! Tells whether a key binding process is active 113 118 bool bTemporary_; //! Stores tkeybind/keybind value … … 115 120 116 121 static KeyBinderManager* singletonPtr_s; 117 }; 118 } 122 }; //tolua_export 123 } //tolua_export 119 124 120 125 #endif /* _KeyBinderManager_H__ */ -
code/branches/pickup2/src/libraries/core/input/KeyDetector.cc
r5929 r6412 39 39 { 40 40 std::string KeyDetector::callbackCommand_s = "KeyDetectorKeyPressed"; 41 KeyDetector* KeyDetector::singletonPtr_s = 0;42 41 ManageScopedSingleton(KeyDetector, ScopeID::Graphics, false); 43 42 … … 68 67 for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it) 69 68 { 70 it->second->bindingString_ = callbackCommand_s + " "+ it->second->groupName_ + "." + it->second->name_;69 it->second->bindingString_ = callbackCommand_s + ' ' + it->second->groupName_ + "." + it->second->name_; 71 70 it->second->parse(); 72 71 } -
code/branches/pickup2/src/libraries/core/input/KeyDetector.h
r5929 r6412 32 32 #include "InputPrereqs.h" 33 33 34 #include <boost/shared_ptr.hpp> 34 35 #include "util/Singleton.h" 35 36 #include "KeyBinder.h" … … 45 46 ~KeyDetector(); 46 47 47 void setCallback( Functor*function) { this->callbackFunction_ = function; }48 void setCallback(const shared_ptr<Functor>& function) { this->callbackFunction_ = function; } 48 49 49 50 private: … … 54 55 void assignCommands(); 55 56 56 Functor*callbackFunction_;57 shared_ptr<Functor> callbackFunction_; 57 58 InputState* inputState_; 58 59 static std::string callbackCommand_s; -
code/branches/pickup2/src/libraries/core/input/Keyboard.cc
r5781 r6412 43 43 modifiers_ |= KeyboardModifier::Shift; // shift key 44 44 45 // Do not distribute the alt+tab event (messes with the operating system) 46 if ((modifiers_ & KeyboardModifier::Alt) != 0 && arg.key == OIS::KC_TAB) 47 return true; 48 45 49 KeyEvent evt(arg); 46 50 super::buttonPressed(evt);
Note: See TracChangeset
for help on using the changeset viewer.