Changeset 3306 for code/branches/core4/src/core/input
- Timestamp:
- Jul 19, 2009, 1:13:43 AM (15 years ago)
- Location:
- code/branches/core4/src/core/input
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core4/src/core/input/JoyStick.cc
r3286 r3306 43 43 void loadCalibration(std::vector<int>& list, const std::string& sectionName, const std::string& valueName, size_t size, int defaultValue); 44 44 45 std::vector<std::string> JoyStick:: idStrings_s;45 std::vector<std::string> JoyStick::deviceNames_s; 46 46 47 47 JoyStick::JoyStick(unsigned int id, OIS::InputManager* oisInputManager) … … 53 53 this->clearBuffersImpl(); 54 54 55 idString_ = "JoyStick_"; 56 std::string name = oisDevice_->vendor(); 57 replaceCharacters(name, ' ', '_'); 58 idString_ += name + "_"; 59 idString_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Button)) + "_"; 60 idString_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Axis)) + "_"; 61 idString_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Slider)) + "_"; 62 idString_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_POV)); 63 //idString_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Vector3)); 64 65 66 BOOST_FOREACH(std::string& idString, idStrings_s) 67 { 68 if (idString_ == idString) 55 // Generate unique name 56 if (oisDevice_->vendor().empty()) 57 deviceName_ = "Unknown_"; 58 else 59 { 60 std::string name = oisDevice_->vendor(); 61 replaceCharacters(name, ' ', '_'); 62 deviceName_ = name + "_"; 63 } 64 deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Button)) + "_"; 65 deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Axis)) + "_"; 66 deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Slider)) + "_"; 67 deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_POV)); 68 //deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Vector3)); 69 70 BOOST_FOREACH(std::string& idString, deviceNames_s) 71 { 72 if (deviceName_ == idString) 69 73 { 70 74 // Make the ID unique for this execution time. 71 idString_ += "_" + multi_cast<std::string>(this->getDeviceID());75 deviceName_ += "_" + multi_cast<std::string>(this->getDeviceName()); 72 76 break; 73 77 } 74 78 } 75 79 76 COUT(4) << "Created OIS joy stick with ID " << idString_ << std::endl;80 COUT(4) << "Created OIS joy stick with ID " << deviceName_ << std::endl; 77 81 78 82 // Load calibration 79 83 size_t axes = sliderAxes_s + static_cast<size_t>(oisDevice_->getNumberOfComponents(OIS::OIS_Axis)); 80 loadCalibration(configMinValues_, idString_, "MinValue", axes, -32768);81 loadCalibration(configMaxValues_, idString_, "MaxValue", axes, 32768);82 loadCalibration(configZeroValues_, idString_, "ZeroValue", axes, 0);84 loadCalibration(configMinValues_, deviceName_, "MinValue", axes, -32768); 85 loadCalibration(configMaxValues_, deviceName_, "MaxValue", axes, 32768); 86 loadCalibration(configZeroValues_, deviceName_, "ZeroValue", axes, 0); 83 87 this->evaluateCalibration(); 84 88 } … … 148 152 configMinValues_[i] = -32768; 149 153 ConfigFileManager::getInstance().setValue(ConfigFileType::JoyStickCalibration, 150 idString_, "MinValue", i, multi_cast<std::string>(configMinValues_[i]), false);154 deviceName_, "MinValue", i, multi_cast<std::string>(configMinValues_[i]), false); 151 155 152 156 // Maximum values … … 154 158 configMaxValues_[i] = 32767; 155 159 ConfigFileManager::getInstance().setValue(ConfigFileType::JoyStickCalibration, 156 idString_, "MaxValue", i, multi_cast<std::string>(configMaxValues_[i]), false);160 deviceName_, "MaxValue", i, multi_cast<std::string>(configMaxValues_[i]), false); 157 161 158 162 // Middle values 159 163 ConfigFileManager::getInstance().setValue(ConfigFileType::JoyStickCalibration, 160 idString_, "ZeroValue", i, multi_cast<std::string>(configZeroValues_[i]), false);164 deviceName_, "ZeroValue", i, multi_cast<std::string>(configZeroValues_[i]), false); 161 165 } 162 166 -
code/branches/core4/src/core/input/JoyStick.h
r3286 r3306 71 71 void setConfigValues(); 72 72 73 //! Returns the ID stringgenerated from the number of knobs and the device name74 const std::string& get IDString() const { return this->idString_; }73 //! Returns the name generated from the number of knobs and the device name 74 const std::string& getDeviceName() const { return this->deviceName_; } 75 75 76 76 private: … … 106 106 static std::string getClassNameImpl() { return "JoyStick"; } 107 107 108 std::string idString_; //!< ID stringgenerated by the number of knobs and the device name108 std::string deviceName_; //!< Name generated by the number of knobs and the device name 109 109 int povStates_[4]; //!< Internal states for the POVs 110 110 int sliderStates_[4][2]; //!< Internal states for the Sliders (each slider has X and Y!) … … 122 122 std::string calibrationFilename_; //!< Joy stick calibration ini filename 123 123 124 //! Contains a list of all ID strings to avoid duplicates125 static std::vector<std::string> idStrings_s;124 //! Contains a list of all names to avoid duplicates 125 static std::vector<std::string> deviceNames_s; 126 126 127 127 //!< Maximum number of slider axes -
code/branches/core4/src/core/input/KeyBinder.cc
r3288 r3306 40 40 #include "core/ConfigFileManager.h" 41 41 #include "InputCommands.h" 42 #include "JoyStick.h" 42 43 43 44 namespace orxonox … … 48 49 */ 49 50 KeyBinder::KeyBinder() 50 : numberOfJoySticks_(0) 51 , deriveTime_(0.0f) 51 : deriveTime_(0.0f) 52 52 { 53 53 mouseRelative_[0] = 0; … … 82 82 else 83 83 nameSuffix = mouseWheelNames[i - MouseButtonCode::numberOfButtons]; 84 mouseButtons_[i].name_ = std::string("Mouse") +nameSuffix;84 mouseButtons_[i].name_ = nameSuffix; 85 85 mouseButtons_[i].paramCommandBuffer_ = ¶mCommandBuffer_; 86 86 mouseButtons_[i].groupName_ = "MouseButtons"; … … 89 89 for (unsigned int i = 0; i < MouseAxisCode::numberOfAxes * 2; i++) 90 90 { 91 mouseAxes_[i].name_ = std::string("Mouse") +MouseAxisCode::ByString[i / 2];91 mouseAxes_[i].name_ = MouseAxisCode::ByString[i / 2]; 92 92 if (i & 1) 93 93 mouseAxes_[i].name_ += "Pos"; … … 102 102 103 103 // initialise joy sticks separatly to allow for reloading 104 numberOfJoySticks_ = this->getJoyStickList().size(); 105 initialiseJoyStickBindings(); 106 107 // collect all Buttons and HalfAxes 108 compilePointerLists(); 104 this->JoyStickQuantityChanged(this->getJoyStickList()); 109 105 110 106 // set them here to use allHalfAxes_ … … 156 152 void KeyBinder::JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList) 157 153 { 158 unsigned int oldValue = numberOfJoySticks_;159 numberOfJoySticks_ = joyStickList.size();154 unsigned int oldValue = joySticks_.size(); 155 joySticks_ = joyStickList; 160 156 161 157 // initialise joy stick bindings … … 168 164 if (configFile_ != ConfigFileType::NoType) 169 165 { 170 for (unsigned int iDev = oldValue; iDev < numberOfJoySticks_; ++iDev)166 for (unsigned int iDev = oldValue; iDev < joySticks_.size(); ++iDev) 171 167 { 172 168 for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; ++i) … … 183 179 void KeyBinder::initialiseJoyStickBindings() 184 180 { 185 this->joyStickAxes_.resize( numberOfJoySticks_);186 this->joyStickButtons_.resize( numberOfJoySticks_);181 this->joyStickAxes_.resize(joySticks_.size()); 182 this->joyStickButtons_.resize(joySticks_.size()); 187 183 188 184 // reinitialise all joy stick binings (doesn't overwrite the old ones) 189 for (unsigned int iDev = 0; iDev < numberOfJoySticks_; iDev++)190 { 191 std::string deviceN umber = multi_cast<std::string>(iDev);185 for (unsigned int iDev = 0; iDev < joySticks_.size(); iDev++) 186 { 187 std::string deviceName = joySticks_[iDev]->getDeviceName(); 192 188 // joy stick buttons 193 189 for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; i++) 194 190 { 195 joyStickButtons_[iDev][i].name_ = std::string("JoyStick") + deviceNumber +JoyStickButtonCode::ByString[i];191 joyStickButtons_[iDev][i].name_ = JoyStickButtonCode::ByString[i]; 196 192 joyStickButtons_[iDev][i].paramCommandBuffer_ = ¶mCommandBuffer_; 197 joyStickButtons_[iDev][i].groupName_ = std::string("JoyStick") + deviceNumber + "Buttons";193 joyStickButtons_[iDev][i].groupName_ = "JoyStickButtons_" + deviceName; 198 194 } 199 195 // joy stick axes 200 196 for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++) 201 197 { 202 joyStickAxes_[iDev][i].name_ = std::string("JoyStick") + deviceNumber + JoyStickAxisCode::ByString[i >> 1];198 joyStickAxes_[iDev][i].name_ = JoyStickAxisCode::ByString[i / 2]; 203 199 if (i & 1) 204 200 joyStickAxes_[iDev][i].name_ += "Pos"; … … 206 202 joyStickAxes_[iDev][i].name_ += "Neg"; 207 203 joyStickAxes_[iDev][i].paramCommandBuffer_ = ¶mCommandBuffer_; 208 joyStickAxes_[iDev][i].groupName_ = std::string("JoyStick") + deviceNumber + "Axes";204 joyStickAxes_[iDev][i].groupName_ = "JoyStickAxes_" + deviceName; 209 205 } 210 206 } … … 219 215 for (unsigned int i = 0; i < KeyCode::numberOfKeys; i++) 220 216 if (!keys_[i].name_.empty()) 221 allButtons_[keys_[i]. name_] = keys_ + i;217 allButtons_[keys_[i].groupName_ + "." + keys_[i].name_] = keys_ + i; 222 218 for (unsigned int i = 0; i < numberOfMouseButtons_; i++) 223 allButtons_[mouseButtons_[i]. name_] = mouseButtons_ + i;219 allButtons_[mouseButtons_[i].groupName_ + "." + mouseButtons_[i].name_] = mouseButtons_ + i; 224 220 for (unsigned int i = 0; i < MouseAxisCode::numberOfAxes * 2; i++) 225 221 { 226 allButtons_[mouseAxes_[i]. name_] = mouseAxes_ + i;222 allButtons_[mouseAxes_[i].groupName_ + "." + mouseAxes_[i].name_] = mouseAxes_ + i; 227 223 allHalfAxes_.push_back(mouseAxes_ + i); 228 224 } 229 for (unsigned int iDev = 0; iDev < numberOfJoySticks_; iDev++)225 for (unsigned int iDev = 0; iDev < joySticks_.size(); iDev++) 230 226 { 231 227 for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; i++) 232 allButtons_[joyStickButtons_[iDev][i]. name_] = &(joyStickButtons_[iDev][i]);228 allButtons_[joyStickButtons_[iDev][i].groupName_ + "." + joyStickButtons_[iDev][i].name_] = &(joyStickButtons_[iDev][i]); 233 229 for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++) 234 230 { 235 allButtons_[joyStickAxes_[iDev][i]. name_] = &(joyStickAxes_[iDev][i]);231 allButtons_[joyStickAxes_[iDev][i].groupName_ + "." + joyStickAxes_[iDev][i].name_] = &(joyStickAxes_[iDev][i]); 236 232 allHalfAxes_.push_back(&(joyStickAxes_[iDev][i])); 237 233 } … … 303 299 void KeyBinder::resetJoyStickAxes() 304 300 { 305 for (unsigned int iDev = 0; iDev < numberOfJoySticks_; ++iDev)301 for (unsigned int iDev = 0; iDev < joySticks_.size(); ++iDev) 306 302 { 307 303 for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++) -
code/branches/core4/src/core/input/KeyBinder.h
r3288 r3306 97 97 protected: // variables 98 98 //! Currently active joy sticks 99 unsigned int numberOfJoySticks_;99 std::vector<JoyStick*> joySticks_; 100 100 101 101 //! Actual key bindings for keys on the keyboard -
code/branches/core4/src/core/input/KeyDetector.cc
r3288 r3306 26 26 * 27 27 */ 28 29 /**30 @file31 @brief32 Implementation of the different input handlers.33 */34 28 35 29 #include "KeyDetector.h" … … 68 62 for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it) 69 63 { 70 it->second->bindingString_ = callbackCommand_ + it->second-> name_;64 it->second->bindingString_ = callbackCommand_ + it->second->groupName_ + "." + it->second->name_; 71 65 it->second->parse(); 72 66 } -
code/branches/core4/src/core/input/KeyDetector.h
r3288 r3306 27 27 */ 28 28 29 /**30 @file31 @brief32 Different definitions of input processing.33 */34 35 29 #ifndef _KeyDetector_H__ 36 30 #define _KeyDetector_H__
Note: See TracChangeset
for help on using the changeset viewer.