Changeset 3327 for code/trunk/src/core/input/KeyBinder.cc
- Timestamp:
- Jul 19, 2009, 5:31:02 PM (15 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/core4 merged: 3269,3271-3275,3278,3285,3290-3294,3310
- Property svn:mergeinfo changed
-
code/trunk/src/core/input/KeyBinder.cc
r3301 r3327 40 40 #include "core/ConfigFileManager.h" 41 41 #include "InputCommands.h" 42 #include " InputManager.h"42 #include "JoyStick.h" 43 43 44 44 namespace orxonox … … 49 49 */ 50 50 KeyBinder::KeyBinder() 51 : numberOfJoySticks_(0) 52 , deriveTime_(0.0f) 51 : deriveTime_(0.0f) 53 52 { 54 53 mouseRelative_[0] = 0; … … 56 55 mousePosition_[0] = 0; 57 56 mousePosition_[1] = 0; 57 58 joyStickButtons_.reserve(1000); 59 joyStickAxes_.reserve(1000); 58 60 59 61 RegisterRootObject(KeyBinder); … … 80 82 else 81 83 nameSuffix = mouseWheelNames[i - MouseButtonCode::numberOfButtons]; 82 mouseButtons_[i].name_ = std::string("Mouse") +nameSuffix;84 mouseButtons_[i].name_ = nameSuffix; 83 85 mouseButtons_[i].paramCommandBuffer_ = ¶mCommandBuffer_; 84 86 mouseButtons_[i].groupName_ = "MouseButtons"; … … 87 89 for (unsigned int i = 0; i < MouseAxisCode::numberOfAxes * 2; i++) 88 90 { 89 mouseAxes_[i].name_ = std::string("Mouse") +MouseAxisCode::ByString[i / 2];91 mouseAxes_[i].name_ = MouseAxisCode::ByString[i / 2]; 90 92 if (i & 1) 91 93 mouseAxes_[i].name_ += "Pos"; … … 100 102 101 103 // initialise joy sticks separatly to allow for reloading 102 numberOfJoySticks_ = InputManager::getInstance().numberOfJoySticks(); 103 initialiseJoyStickBindings(); 104 105 // collect all Buttons and HalfAxes 106 compilePointerLists(); 104 this->JoyStickQuantityChanged(this->getJoyStickList()); 107 105 108 106 // set them here to use allHalfAxes_ … … 152 150 } 153 151 154 void KeyBinder::JoyStick DeviceNumberChanged(unsigned int value)155 { 156 unsigned int oldValue = numberOfJoySticks_;157 numberOfJoySticks_ = value;152 void KeyBinder::JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList) 153 { 154 unsigned int oldValue = joySticks_.size(); 155 joySticks_ = joyStickList; 158 156 159 157 // initialise joy stick bindings … … 166 164 if (configFile_ != ConfigFileType::NoType) 167 165 { 168 for (unsigned int iDev = oldValue; iDev < numberOfJoySticks_; ++iDev)166 for (unsigned int iDev = oldValue; iDev < joySticks_.size(); ++iDev) 169 167 { 170 168 for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; ++i) … … 181 179 void KeyBinder::initialiseJoyStickBindings() 182 180 { 183 this->joyStickAxes_.resize( numberOfJoySticks_);184 this->joyStickButtons_.resize( numberOfJoySticks_);181 this->joyStickAxes_.resize(joySticks_.size()); 182 this->joyStickButtons_.resize(joySticks_.size()); 185 183 186 184 // reinitialise all joy stick binings (doesn't overwrite the old ones) 187 for (unsigned int iDev = 0; iDev < numberOfJoySticks_; iDev++)188 { 189 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(); 190 188 // joy stick buttons 191 189 for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; i++) 192 190 { 193 joyStickButtons_[iDev][i].name_ = std::string("JoyStick") + deviceNumber +JoyStickButtonCode::ByString[i];191 joyStickButtons_[iDev][i].name_ = JoyStickButtonCode::ByString[i]; 194 192 joyStickButtons_[iDev][i].paramCommandBuffer_ = ¶mCommandBuffer_; 195 joyStickButtons_[iDev][i].groupName_ = std::string("JoyStick") + deviceNumber + "Buttons";193 joyStickButtons_[iDev][i].groupName_ = "JoyStickButtons_" + deviceName; 196 194 } 197 195 // joy stick axes 198 196 for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++) 199 197 { 200 joyStickAxes_[iDev][i].name_ = std::string("JoyStick") + deviceNumber + JoyStickAxisCode::ByString[i >> 1];198 joyStickAxes_[iDev][i].name_ = JoyStickAxisCode::ByString[i / 2]; 201 199 if (i & 1) 202 200 joyStickAxes_[iDev][i].name_ += "Pos"; … … 204 202 joyStickAxes_[iDev][i].name_ += "Neg"; 205 203 joyStickAxes_[iDev][i].paramCommandBuffer_ = ¶mCommandBuffer_; 206 joyStickAxes_[iDev][i].groupName_ = std::string("JoyStick") + deviceNumber + "Axes";204 joyStickAxes_[iDev][i].groupName_ = "JoyStickAxes_" + deviceName; 207 205 } 208 206 } … … 217 215 for (unsigned int i = 0; i < KeyCode::numberOfKeys; i++) 218 216 if (!keys_[i].name_.empty()) 219 allButtons_[keys_[i]. name_] = keys_ + i;217 allButtons_[keys_[i].groupName_ + "." + keys_[i].name_] = keys_ + i; 220 218 for (unsigned int i = 0; i < numberOfMouseButtons_; i++) 221 allButtons_[mouseButtons_[i]. name_] = mouseButtons_ + i;219 allButtons_[mouseButtons_[i].groupName_ + "." + mouseButtons_[i].name_] = mouseButtons_ + i; 222 220 for (unsigned int i = 0; i < MouseAxisCode::numberOfAxes * 2; i++) 223 221 { 224 allButtons_[mouseAxes_[i]. name_] = mouseAxes_ + i;222 allButtons_[mouseAxes_[i].groupName_ + "." + mouseAxes_[i].name_] = mouseAxes_ + i; 225 223 allHalfAxes_.push_back(mouseAxes_ + i); 226 224 } 227 for (unsigned int iDev = 0; iDev < numberOfJoySticks_; iDev++)225 for (unsigned int iDev = 0; iDev < joySticks_.size(); iDev++) 228 226 { 229 227 for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; i++) 230 allButtons_[joyStickButtons_[iDev][i]. name_] = &(joyStickButtons_[iDev][i]);228 allButtons_[joyStickButtons_[iDev][i].groupName_ + "." + joyStickButtons_[iDev][i].name_] = &(joyStickButtons_[iDev][i]); 231 229 for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++) 232 230 { 233 allButtons_[joyStickAxes_[iDev][i]. name_] = &(joyStickAxes_[iDev][i]);231 allButtons_[joyStickAxes_[iDev][i].groupName_ + "." + joyStickAxes_[iDev][i].name_] = &(joyStickAxes_[iDev][i]); 234 232 allHalfAxes_.push_back(&(joyStickAxes_[iDev][i])); 235 233 } … … 301 299 void KeyBinder::resetJoyStickAxes() 302 300 { 303 for (unsigned int iDev = 0; iDev < numberOfJoySticks_; ++iDev)301 for (unsigned int iDev = 0; iDev < joySticks_.size(); ++iDev) 304 302 { 305 303 for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++) … … 311 309 } 312 310 313 void KeyBinder:: updateMouse(float dt)311 void KeyBinder::mouseUpdated(float dt) 314 312 { 315 313 if (bDeriveMouseInput_) … … 364 362 } 365 363 366 void KeyBinder:: updateJoyStick(float dt, unsigned int joyStick)364 void KeyBinder::joyStickUpdated(unsigned int joyStick, float dt) 367 365 { 368 366 for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++) … … 480 478 } 481 479 482 void KeyBinder::joyStickAxisMoved(unsigned int joyStickID, unsigned int axis, float value) 483 { 484 int i = axis * 2; 480 void KeyBinder::axisMoved(unsigned int device, unsigned int axisID, float value) 481 { 482 int i = axisID * 2; 483 JoyStickAxisVector& axis = joyStickAxes_[device]; 485 484 if (value < 0) 486 485 { 487 joyStickAxes_[joyStickID][i].absVal_ = -value;488 joyStickAxes_[joyStickID][i].relVal_ = -value;489 joyStickAxes_[joyStickID][i].hasChanged_ = true;490 if ( joyStickAxes_[joyStickID][i + 1].absVal_ > 0.0f)491 { 492 joyStickAxes_[joyStickID][i + 1].absVal_ = -0.0f;493 joyStickAxes_[joyStickID][i + 1].relVal_ = -0.0f;494 joyStickAxes_[joyStickID][i + 1].hasChanged_ = true;486 axis[i].absVal_ = -value; 487 axis[i].relVal_ = -value; 488 axis[i].hasChanged_ = true; 489 if (axis[i + 1].absVal_ > 0.0f) 490 { 491 axis[i + 1].absVal_ = -0.0f; 492 axis[i + 1].relVal_ = -0.0f; 493 axis[i + 1].hasChanged_ = true; 495 494 } 496 495 } 497 496 else 498 497 { 499 joyStickAxes_[joyStickID][i + 1].absVal_ = value;500 joyStickAxes_[joyStickID][i + 1].relVal_ = value;501 joyStickAxes_[joyStickID][i + 1].hasChanged_ = true;502 if ( joyStickAxes_[joyStickID][i].absVal_ > 0.0f)503 { 504 joyStickAxes_[joyStickID][i].absVal_ = -0.0f;505 joyStickAxes_[joyStickID][i].relVal_ = -0.0f;506 joyStickAxes_[joyStickID][i].hasChanged_ = true;498 axis[i + 1].absVal_ = value; 499 axis[i + 1].relVal_ = value; 500 axis[i + 1].hasChanged_ = true; 501 if (axis[i].absVal_ > 0.0f) 502 { 503 axis[i].absVal_ = -0.0f; 504 axis[i].relVal_ = -0.0f; 505 axis[i].hasChanged_ = true; 507 506 } 508 507 }
Note: See TracChangeset
for help on using the changeset viewer.