Changeset 3270 for code/branches
- Timestamp:
- Jul 6, 2009, 12:03:05 PM (15 years ago)
- Location:
- code/branches/core4/src
- Files:
-
- 2 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core4/src/core/CorePrereqs.h
r3257 r3270 179 179 class InputManager; 180 180 class InputState; 181 class JoyStick; 181 182 class JoyStickHandler; 182 183 class MouseHandler; -
code/branches/core4/src/core/input/CMakeLists.txt
r3196 r3270 6 6 InputCommands.cc 7 7 InputManager.cc 8 JoyStick.cc 8 9 JoyStickDeviceNumberListener.cc 9 10 KeyBinder.cc -
code/branches/core4/src/core/input/InputManager.cc
r3255 r3270 40 40 #include <ois/OISException.h> 41 41 #include <ois/OISInputManager.h> 42 #include <boost/foreach.hpp> 42 43 43 44 #include "util/Convert.h" … … 56 57 #include "ExtendedInputState.h" 57 58 #include "JoyStickDeviceNumberListener.h" 59 #include "JoyStick.h" 58 60 59 61 // HACK (include this as last, X11 seems to define some macros...) … … 106 108 and registers the class in the class hierarchy. 107 109 */ 108 InputManager::InputManager( )110 InputManager::InputManager(size_t windowHnd, unsigned int windowWidth, unsigned int windowHeight) 109 111 : inputSystem_(0) 110 112 , keyboard_(0) 111 113 , mouse_(0) 112 , joySticksSize_(0)113 114 , devicesNum_(0) 114 115 , windowHnd_(0) … … 125 126 126 127 setConfigValues(); 128 129 initialise(windowHnd, windowWidth, windowHeight); 127 130 } 128 131 … … 133 136 void InputManager::setConfigValues() 134 137 { 135 SetConfigValue(calibrationFilename_, "joystick_calibration.ini")136 .description("Ini filename for the the joy stick calibration data.")137 .callback(this, &InputManager::_calibrationFileCallback);138 }139 140 /**141 @brief142 Callback for the joy stick calibration config file. @see setConfigValues.143 */144 void InputManager::_calibrationFileCallback()145 {146 ConfigFileManager::getInstance().setFilename(ConfigFileType::JoyStickCalibration, calibrationFilename_);147 138 } 148 139 … … 157 148 @param windowHeight 158 149 The height of the render window 159 @param joyStickSupport 160 Whether or not to load the joy sticks as well 161 */ 162 void InputManager::initialise(size_t windowHnd, int windowWidth, int windowHeight, bool joyStickSupport) 150 */ 151 void InputManager::initialise(size_t windowHnd, unsigned int windowWidth, unsigned int windowHeight) 163 152 { 164 153 CCOUT(3) << "Initialising Input System..." << std::endl; … … 211 200 } 212 201 213 _initialiseMouse(); 214 215 if (joyStickSupport) 216 _initialiseJoySticks(); 217 // Do this anyway to also inform when a joystick was detached. 218 _configureJoySticks(); 219 220 // Set mouse/joystick region 221 if (mouse_) 222 setWindowExtents(windowWidth, windowHeight); 202 _initialiseMouse(windowWidth, windowHeight); 203 204 _initialiseJoySticks(); 223 205 224 206 // clear all buffers 225 _clearBuffers();207 clearBuffers(); 226 208 227 209 internalState_ |= OISReady; … … 298 280 False if mouse stays uninitialised, true otherwise. 299 281 */ 300 void InputManager::_initialiseMouse( )282 void InputManager::_initialiseMouse(unsigned int windowWidth, unsigned int windowHeight) 301 283 { 302 284 if (mouse_ != 0) … … 313 295 mouse_->setEventCallback(this); 314 296 CCOUT(ORX_DEBUG) << "Created OIS mouse" << std::endl; 297 298 // Set mouse region 299 setWindowExtents(windowWidth, windowHeight); 315 300 } 316 301 else … … 335 320 void InputManager::_initialiseJoySticks() 336 321 { 337 if ( joySticksSize_ > 0)322 if (!this->joySticks_.empty()) 338 323 { 339 324 CCOUT(2) << "Warning: Joy sticks already initialised, skipping." << std::endl; 340 325 return; 341 326 } 342 if (inputSystem_->getNumberOfDevices(OIS::OISJoyStick) > 0) 343 { 344 for (int i = 0; i < inputSystem_->getNumberOfDevices(OIS::OISJoyStick); i++) 345 { 346 try 347 { 348 OIS::JoyStick* stig = static_cast<OIS::JoyStick*> 349 (inputSystem_->createInputObject(OIS::OISJoyStick, true)); 350 CCOUT(ORX_DEBUG) << "Created OIS joy stick with ID " << stig->getID() << std::endl; 351 joySticks_.push_back(stig); 352 // register our listener in OIS. 353 stig->setEventCallback(this); 354 } 355 catch (OIS::Exception ex) 356 { 357 CCOUT(ORX_WARNING) << "Warning: Failed to create OIS joy number" << i << "\n" 358 << "OIS error message: \"" << ex.eText << "\"" << std::endl; 359 } 360 } 361 } 362 } 363 364 /** 365 @brief 366 Helper function that loads the config value vector of one coefficient 367 */ 368 void loadCalibration(std::vector<int>& list, const std::string& sectionName, const std::string& valueName, size_t size, int defaultValue) 369 { 370 list.resize(size); 371 unsigned int configValueVectorSize = ConfigFileManager::getInstance().getVectorSize(ConfigFileType::JoyStickCalibration, sectionName, valueName); 372 if (configValueVectorSize > size) 373 configValueVectorSize = size; 374 375 for (unsigned int i = 0; i < configValueVectorSize; ++i) 376 { 377 list[i] = multi_cast<int>(ConfigFileManager::getInstance().getValue( 378 ConfigFileType::JoyStickCalibration, sectionName, valueName, i, multi_cast<std::string>(defaultValue), false)); 379 } 380 381 // fill the rest with default values 382 for (unsigned int i = configValueVectorSize; i < size; ++i) 383 { 384 list[i] = defaultValue; 385 } 386 } 387 388 /** 389 @brief 390 Sets the size of all the different lists that are dependent on the number 391 of joy stick devices created and loads the joy stick calibration. 392 @remarks 393 No matter whether there are a mouse and/or keyboard, they will always 394 occupy 2 places in the device number dependent lists. 395 */ 396 void InputManager::_configureJoySticks() 397 { 398 joySticksSize_ = joySticks_.size(); 399 devicesNum_ = 2 + joySticksSize_; 400 joyStickIDs_ .resize(joySticksSize_); 401 joyStickButtonsDown_ .resize(joySticksSize_); 402 povStates_ .resize(joySticksSize_); 403 sliderStates_ .resize(joySticksSize_); 404 joyStickMinValues_ .resize(joySticksSize_); 405 joyStickMaxValues_ .resize(joySticksSize_); 406 joyStickMiddleValues_.resize(joySticksSize_); 407 joyStickCalibrations_.resize(joySticksSize_); 408 409 for (unsigned int iJoyStick = 0; iJoyStick < joySticksSize_; iJoyStick++) 410 { 411 // Generate some sort of execution unique id per joy stick 412 std::string id = "JoyStick_"; 413 id += multi_cast<std::string>(joySticks_[iJoyStick]->getNumberOfComponents(OIS::OIS_Button)) + "_"; 414 id += multi_cast<std::string>(joySticks_[iJoyStick]->getNumberOfComponents(OIS::OIS_Axis)) + "_"; 415 id += multi_cast<std::string>(joySticks_[iJoyStick]->getNumberOfComponents(OIS::OIS_Slider)) + "_"; 416 id += multi_cast<std::string>(joySticks_[iJoyStick]->getNumberOfComponents(OIS::OIS_POV)) + "_"; 417 id += multi_cast<std::string>(joySticks_[iJoyStick]->getNumberOfComponents(OIS::OIS_Vector3)) + "_"; 418 id += joySticks_[iJoyStick]->vendor(); 419 for (unsigned int i = 0; i < iJoyStick; ++i) 420 { 421 if (id == joyStickIDs_[i]) 422 { 423 // Two joysticks are probably equal --> add the index as well 424 id += "_" + multi_cast<std::string>(iJoyStick); 425 } 426 } 427 joyStickIDs_[iJoyStick] = id; 428 429 size_t axes = sliderAxes + (size_t)this->joySticks_[iJoyStick]->getNumberOfComponents(OIS::OIS_Axis); 430 loadCalibration(joyStickMinValues_[iJoyStick], id, "MinValue", axes, -32768); 431 loadCalibration(joyStickMaxValues_[iJoyStick], id, "MaxValue", axes, 32768); 432 loadCalibration(joyStickMiddleValues_[iJoyStick], id, "MiddleValue", axes, 0); 433 } 434 435 _evaluateCalibration(); 436 327 328 devicesNum_ = 2 + inputSystem_->getNumberOfDevices(OIS::OISJoyStick); 437 329 // state management 438 330 activeStatesTriggered_.resize(devicesNum_); 439 331 440 // inform all states 441 for (std::map<std::string, InputState*>::const_iterator it = inputStatesByName_.begin(); 442 it != inputStatesByName_.end(); ++it) 443 { 444 it->second->setNumOfJoySticks(joySticksSize_); 332 for (int i = 0; i < inputSystem_->getNumberOfDevices(OIS::OISJoyStick); i++) 333 { 334 try 335 { 336 joySticks_.push_back(new JoyStick(activeStatesTriggered_[2 + i], i)); 337 } 338 catch (std::exception ex) 339 { 340 CCOUT(2) << "Warning: Failed to create joy stick: " << ex.what() << std::endl; 341 } 445 342 } 446 343 447 344 // inform all JoyStick Device Number Listeners 448 345 for (ObjectList<JoyStickDeviceNumberListener>::iterator it = ObjectList<JoyStickDeviceNumberListener>::begin(); it; ++it) 449 it->JoyStickDeviceNumberChanged(joySticksSize_); 450 451 } 452 453 void InputManager::_evaluateCalibration() 454 { 455 for (unsigned int iJoyStick = 0; iJoyStick < this->joySticksSize_; ++iJoyStick) 456 { 457 for (unsigned int i = 0; i < this->joyStickMinValues_[iJoyStick].size(); i++) 458 { 459 this->joyStickCalibrations_[iJoyStick].middleValue[i] = this->joyStickMiddleValues_[iJoyStick][i]; 460 this->joyStickCalibrations_[iJoyStick].negativeCoeff[i] = - 1.0f / (this->joyStickMinValues_[iJoyStick][i] - this->joyStickMiddleValues_[iJoyStick][i]); 461 this->joyStickCalibrations_[iJoyStick].positiveCoeff[i] = 1.0f / (this->joyStickMaxValues_[iJoyStick][i] - this->joyStickMiddleValues_[iJoyStick][i]); 462 } 463 } 346 it->JoyStickDeviceNumberChanged(joySticks_.size()); 464 347 } 465 348 466 349 void InputManager::_startCalibration() 467 350 { 468 for (unsigned int iJoyStick = 0; iJoyStick < this->joySticksSize_; ++iJoyStick) 469 { 470 // Set initial values 471 for (unsigned int i = 0; i < this->joyStickMinValues_[iJoyStick].size(); ++i) 472 this->joyStickMinValues_[iJoyStick][i] = INT_MAX; 473 for (unsigned int i = 0; i < this->joyStickMaxValues_[iJoyStick].size(); ++i) 474 this->joyStickMaxValues_[iJoyStick][i] = INT_MIN; 475 for (unsigned int i = 0; i < this->joyStickMiddleValues_[iJoyStick].size(); ++i) 476 this->joyStickMiddleValues_[iJoyStick][i] = 0; 477 } 351 BOOST_FOREACH(JoyStick* stick, joySticks_) 352 stick->startCalibration(); 478 353 479 354 getInstance().internalState_ |= Calibrating; … … 483 358 void InputManager::_completeCalibration() 484 359 { 485 for (unsigned int iJoyStick = 0; iJoyStick < this->joySticksSize_; ++iJoyStick) 486 { 487 // Get the middle positions now 488 unsigned int iAxis = 0; 489 for (unsigned int i = 0; i < sliderAxes/2; ++i) 490 { 491 this->joyStickMiddleValues_[iJoyStick][iAxis++] = this->joySticks_[iJoyStick]->getJoyStickState().mSliders[i].abX; 492 this->joyStickMiddleValues_[iJoyStick][iAxis++] = this->joySticks_[iJoyStick]->getJoyStickState().mSliders[i].abY; 493 } 494 // Note: joyStickMiddleValues_[iJoyStick] was already correctly resized in _configureJoySticks() 495 assert(joySticks_[iJoyStick]->getJoyStickState().mAxes.size() == joyStickMiddleValues_[iJoyStick].size() - sliderAxes); 496 for (unsigned int i = 0; i < joyStickMiddleValues_[iJoyStick].size() - sliderAxes; ++i) 497 { 498 this->joyStickMiddleValues_[iJoyStick][iAxis++] = this->joySticks_[iJoyStick]->getJoyStickState().mAxes[i].abs; 499 } 500 501 for (unsigned int i = 0; i < joyStickMinValues_[iJoyStick].size(); ++i) 502 { 503 // Minimum values 504 if (joyStickMinValues_[iJoyStick][i] == INT_MAX) 505 joyStickMinValues_[iJoyStick][i] = -32768; 506 ConfigFileManager::getInstance().setValue(ConfigFileType::JoyStickCalibration, 507 this->joyStickIDs_[iJoyStick], "MinValue", i, multi_cast<std::string>(joyStickMinValues_[iJoyStick][i]), false); 508 509 // Maximum values 510 if (joyStickMaxValues_[iJoyStick][i] == INT_MIN) 511 joyStickMaxValues_[iJoyStick][i] = 32767; 512 ConfigFileManager::getInstance().setValue(ConfigFileType::JoyStickCalibration, 513 this->joyStickIDs_[iJoyStick], "MaxValue", i, multi_cast<std::string>(joyStickMaxValues_[iJoyStick][i]), false); 514 515 // Middle values 516 ConfigFileManager::getInstance().setValue(ConfigFileType::JoyStickCalibration, 517 this->joyStickIDs_[iJoyStick], "MiddleValue", i, multi_cast<std::string>(joyStickMiddleValues_[iJoyStick][i]), false); 518 } 519 } 520 521 _evaluateCalibration(); 360 BOOST_FOREACH(JoyStick* stick, joySticks_) 361 stick->stopCalibration(); 522 362 523 363 // restore old input state … … 625 465 void InputManager::_destroyJoySticks() 626 466 { 627 if (joySticksSize_ > 0) 628 { 629 assert(inputSystem_); 630 for (unsigned int i = 0; i < joySticksSize_; i++) 631 { 632 try 633 { 634 if (joySticks_[i] != 0) 635 inputSystem_->destroyInputObject(joySticks_[i]); 636 } 637 catch (...) 638 { 639 CCOUT(1) << "Joy stick destruction failed! Potential resource leak!" << std::endl; 640 } 641 } 642 643 joySticks_.clear(); 644 // don't use _configureNumberOfJoySticks(), might mess with registered handler if 645 // downgrading from 2 to 1 joystick 646 //_configureNumberOfJoySticks(); 647 joySticksSize_ = 0; 467 assert(inputSystem_); 468 while (!joySticks_.empty()) 469 { 470 try 471 { 472 delete joySticks_.back(); 473 } 474 catch (...) 475 { 476 CCOUT(1) << "Joy stick destruction failed! Potential resource leak!" << std::endl; 477 } 478 joySticks_.pop_back(); 479 devicesNum_ = 2; 648 480 } 649 481 CCOUT(4) << "Joy sticks destroyed." << std::endl; … … 669 501 } 670 502 671 void InputManager::_clearBuffers()672 {673 keysDown_.clear();674 keyboardModifiers_ = 0;675 mouseButtonsDown_.clear();676 for (unsigned int i = 0; i < joySticksSize_; ++i)677 {678 joyStickButtonsDown_[i].clear();679 for (int j = 0; j < 4; ++j)680 {681 sliderStates_[i].sliderStates[j].x = 0;682 sliderStates_[i].sliderStates[j].y = 0;683 povStates_[i][j] = 0;684 }685 }686 }687 688 689 503 // ############################################################ 690 504 // ##### Reloading ##### … … 696 510 Public interface. Only reloads immediately if the call stack doesn't 697 511 include the update() method. 698 @param joyStickSupport 699 Whether or not to initialise joy sticks as well. 700 */ 701 void InputManager::reloadInputSystem(bool joyStickSupport) 512 */ 513 void InputManager::reloadInputSystem() 702 514 { 703 515 if (internalState_ & Ticking) … … 707 519 // include an OIS method. So it would be a very bad thing to destroy it.. 708 520 internalState_ |= ReloadRequest; 709 // Misuse of internalState_: We can easily store the joyStickSupport bool.710 // use Uninitialised as 0 value in order to make use of the overloaded |= operator711 internalState_ |= joyStickSupport ? JoyStickSupport : Uninitialised;712 521 } 713 522 else if (internalState_ & OISReady) 714 { 715 _reload(joyStickSupport); 716 } 523 _reload(); 717 524 else 718 525 { … … 726 533 Internal reload method. Destroys the OIS devices and loads them again. 727 534 */ 728 void InputManager::_reload( bool joyStickSupport)535 void InputManager::_reload() 729 536 { 730 537 try … … 747 554 748 555 // clear all buffers containing input information 749 _clearBuffers();750 751 initialise(windowHnd_, mouseWidth, mouseHeight , joyStickSupport);556 clearBuffers(); 557 558 initialise(windowHnd_, mouseWidth, mouseHeight); 752 559 753 560 CCOUT(3) << "Reloading done." << std::endl; … … 776 583 else if (internalState_ & ReloadRequest) 777 584 { 778 _reload( internalState_ & JoyStickSupport);585 _reload(); 779 586 internalState_ &= ~ReloadRequest; 780 internalState_ &= ~JoyStickSupport;781 587 } 782 588 … … 811 617 { 812 618 // Get smallest possible priority between 1 and maxStateStackSize_s 813 #if defined( __MINGW32__ ) // Avoid the strange mingw-stl bug with const_reverse_iterator814 619 for(std::map<int, InputState*>::reverse_iterator rit = activeStates_.rbegin(); 815 620 rit != activeStates_.rend(); ++rit) 816 #else817 for(std::map<int, InputState*>::const_reverse_iterator rit = activeStates_.rbegin();818 rit != activeStates_.rend(); ++rit)819 #endif820 621 { 821 622 if (rit->first < InputStatePriority::HighPriority) … … 868 669 if (mouse_) 869 670 mouse_->capture(); 870 for (unsigned int i = 0; i < joySticksSize_; i++)871 joySticks_[i]->capture();671 BOOST_FOREACH(JoyStick* stick, joySticks_) 672 stick->capture(); 872 673 873 674 if (!(internalState_ & Calibrating)) … … 888 689 activeStatesTriggered_[Mouse][iState]->mouseButtonHeld(mouseButtonsDown_[iButton]); 889 690 } 890 891 // call all the handlers for the held joy stick button events892 for (unsigned int iJoyStick = 0; iJoyStick < joySticksSize_; iJoyStick++)893 for (unsigned int iButton = 0; iButton < joyStickButtonsDown_[iJoyStick].size(); iButton++)894 {895 for (unsigned int iState = 0; iState < activeStatesTriggered_[JoyStick0 + iJoyStick].size(); ++iState)896 activeStatesTriggered_[JoyStick0 + iJoyStick][iState]->joyStickButtonHeld(iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]);897 }898 691 899 692 // update the handlers for each active handler … … 923 716 bool occupied = false; 924 717 activeStatesTriggered_[i].clear(); 925 #if defined( __MINGW32__ ) // Avoid the strange mingw-stl bug with const_reverse_iterator926 for (std::map<int, InputState*>::reverse_iterator rit = activeStates_.rbegin(); rit != activeStates_.rend(); ++rit)927 {928 #else929 718 for (std::map<int, InputState*>::const_reverse_iterator rit = activeStates_.rbegin(); rit != activeStates_.rend(); ++rit) 930 719 { 931 #endif932 720 if (rit->second->isInputDeviceEnabled(i) && (!occupied || rit->second->bAlwaysGetsInput_)) 933 721 { … … 960 748 void InputManager::clearBuffers() 961 749 { 962 this->keysDown_.clear(); 963 this->mouseButtonsDown_.clear(); 964 for (unsigned int i = 0; i < this->joySticksSize_; ++i) 965 this->joyStickButtonsDown_[i].clear(); 750 keysDown_.clear(); 751 keyboardModifiers_ = 0; 752 mouseButtonsDown_.clear(); 753 BOOST_FOREACH(JoyStick* stick, joySticks_) 754 stick->clearBuffer(); 966 755 } 967 756 … … 1124 913 1125 914 1126 // ###### Joy Stick Events ###### 1127 1128 /** 1129 @brief 1130 Returns the joy stick ID (orxonox) according to a OIS::JoyStickEvent 1131 */ 1132 inline unsigned int InputManager::_getJoystick(const OIS::JoyStickEvent& arg) 1133 { 1134 // use the device to identify which one called the method 1135 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 1136 unsigned int iJoyStick = 0; 1137 while (joySticks_[iJoyStick] != joyStick) 1138 iJoyStick++; 1139 // assert: Unknown joystick fired an event. 1140 assert(iJoyStick != joySticksSize_); 1141 return iJoyStick; 1142 } 1143 1144 bool InputManager::buttonPressed(const OIS::JoyStickEvent &arg, int button) 1145 { 1146 unsigned int iJoyStick = _getJoystick(arg); 1147 1148 // check whether the button already is in the list (can happen when focus was lost) 1149 std::vector<JoyStickButtonCode::ByEnum>& buttonsDown = joyStickButtonsDown_[iJoyStick]; 1150 unsigned int iButton = 0; 1151 while (iButton < buttonsDown.size() && buttonsDown[iButton] != button) 1152 iButton++; 1153 if (iButton == buttonsDown.size()) 1154 buttonsDown.push_back((JoyStickButtonCode::ByEnum)button); 1155 1156 for (unsigned int iState = 0; iState < activeStatesTriggered_[2 + iJoyStick].size(); ++iState) 1157 activeStatesTriggered_[2 + iJoyStick][iState]->joyStickButtonPressed(iJoyStick, (JoyStickButtonCode::ByEnum)button); 1158 1159 return true; 1160 } 1161 1162 bool InputManager::buttonReleased(const OIS::JoyStickEvent &arg, int button) 1163 { 1164 unsigned int iJoyStick = _getJoystick(arg); 1165 1166 // remove the button from the joyStickButtonsDown_ list 1167 std::vector<JoyStickButtonCode::ByEnum>& buttonsDown = joyStickButtonsDown_[iJoyStick]; 1168 for (unsigned int iButton = 0; iButton < buttonsDown.size(); iButton++) 1169 { 1170 if (buttonsDown[iButton] == button) 1171 { 1172 buttonsDown.erase(buttonsDown.begin() + iButton); 1173 break; 1174 } 1175 } 1176 1177 for (unsigned int iState = 0; iState < activeStatesTriggered_[2 + iJoyStick].size(); ++iState) 1178 activeStatesTriggered_[2 + iJoyStick][iState]->joyStickButtonReleased(iJoyStick, (JoyStickButtonCode::ByEnum)button); 1179 1180 return true; 1181 } 1182 1183 /** 1184 @brief 1185 Calls the states for a particular axis with our enumeration. 1186 Used by OIS sliders and OIS axes. 1187 */ 1188 void InputManager::_fireAxis(unsigned int iJoyStick, int axis, int value) 1189 { 1190 if (internalState_ & Calibrating) 1191 { 1192 if (value < joyStickMinValues_[iJoyStick][axis]) 1193 joyStickMinValues_[iJoyStick][axis] = value; 1194 if (value > joyStickMaxValues_[iJoyStick][axis]) 1195 joyStickMaxValues_[iJoyStick][axis] = value; 1196 } 1197 else 1198 { 1199 float fValue = static_cast<float>(value - joyStickCalibrations_[iJoyStick].middleValue[axis]); 1200 if (fValue > 0.0f) 1201 fValue *= joyStickCalibrations_[iJoyStick].positiveCoeff[axis]; 1202 else 1203 fValue *= joyStickCalibrations_[iJoyStick].negativeCoeff[axis]; 1204 1205 for (unsigned int iState = 0; iState < activeStatesTriggered_[2 + iJoyStick].size(); ++iState) 1206 activeStatesTriggered_[2 + iJoyStick][iState]->joyStickAxisMoved(iJoyStick, axis, fValue); 1207 } 1208 } 1209 1210 bool InputManager::axisMoved(const OIS::JoyStickEvent &arg, int axis) 1211 { 1212 unsigned int iJoyStick = _getJoystick(arg); 1213 1214 // keep in mind that the first 8 axes are reserved for the sliders 1215 _fireAxis(iJoyStick, axis + sliderAxes, arg.state.mAxes[axis].abs); 1216 1217 return true; 1218 } 1219 1220 bool InputManager::sliderMoved(const OIS::JoyStickEvent &arg, int id) 1221 { 1222 unsigned int iJoyStick = _getJoystick(arg); 1223 1224 if (sliderStates_[iJoyStick].sliderStates[id].x != arg.state.mSliders[id].abX) 1225 _fireAxis(iJoyStick, id * 2, arg.state.mSliders[id].abX); 1226 else if (sliderStates_[iJoyStick].sliderStates[id].y != arg.state.mSliders[id].abY) 1227 _fireAxis(iJoyStick, id * 2 + 1, arg.state.mSliders[id].abY); 1228 1229 return true; 1230 } 1231 1232 bool InputManager::povMoved(const OIS::JoyStickEvent &arg, int id) 1233 { 1234 unsigned int iJoyStick = _getJoystick(arg); 1235 1236 // translate the POV into 8 simple buttons 1237 1238 int lastState = povStates_[iJoyStick][id]; 1239 if (lastState & OIS::Pov::North) 1240 buttonReleased(arg, 32 + id * 4 + 0); 1241 if (lastState & OIS::Pov::South) 1242 buttonReleased(arg, 32 + id * 4 + 1); 1243 if (lastState & OIS::Pov::East) 1244 buttonReleased(arg, 32 + id * 4 + 2); 1245 if (lastState & OIS::Pov::West) 1246 buttonReleased(arg, 32 + id * 4 + 3); 1247 1248 povStates_[iJoyStick].povStates[id] = arg.state.mPOV[id].direction; 1249 1250 int currentState = povStates_[iJoyStick][id]; 1251 if (currentState & OIS::Pov::North) 1252 buttonPressed(arg, 32 + id * 4 + 0); 1253 if (currentState & OIS::Pov::South) 1254 buttonPressed(arg, 32 + id * 4 + 1); 1255 if (currentState & OIS::Pov::East) 1256 buttonPressed(arg, 32 + id * 4 + 2); 1257 if (currentState & OIS::Pov::West) 1258 buttonPressed(arg, 32 + id * 4 + 3); 1259 915 // ############################################################ 916 // ##### Friend functions ##### 917 // ########## ########## 918 // ############################################################ 919 920 /** 921 @brief 922 Checks whether there is already a joy stick with the given ID string. 923 @return 924 Returns true if ID is ok (unique), false otherwise. 925 */ 926 bool InputManager::checkJoyStickID(const std::string& idString) 927 { 928 BOOST_FOREACH(JoyStick* stick, joySticks_) 929 { 930 if (stick->getIDString() == idString) 931 return false; 932 } 1260 933 return true; 1261 934 } … … 1336 1009 } 1337 1010 inputStatesByName_[name] = state; 1338 state-> setNumOfJoySticks(numberOfJoySticks());1011 state->JoyStickDeviceNumberChanged(numberOfJoySticks()); 1339 1012 state->setName(name); 1340 1013 state->bAlwaysGetsInput_ = bAlwaysGetsInput; … … 1502 1175 Reloads the input system 1503 1176 */ 1504 void InputManager::reload( bool joyStickSupport)1505 { 1506 getInstance().reloadInputSystem( joyStickSupport);1177 void InputManager::reload() 1178 { 1179 getInstance().reloadInputSystem(); 1507 1180 } 1508 1181 -
code/branches/core4/src/core/input/InputManager.h
r3196 r3270 54 54 namespace orxonox 55 55 { 56 /**57 @brief58 Helper class to realise a vector<int[4]>59 */60 class POVStates61 {62 public:63 int& operator[](unsigned int index) { return povStates[index]; }64 int povStates[4];65 };66 67 /**68 @brief69 Helper class to realise a vector< {int[4], int[4]} >70 */71 class SliderStates72 {73 public:74 IntVector2 sliderStates[4];75 };76 77 struct JoyStickCalibration78 {79 int middleValue[24];80 float positiveCoeff[24];81 float negativeCoeff[24];82 };83 84 56 struct InputStatePriority : OrxEnum<InputStatePriority> 85 57 { … … 101 73 class _CoreExport InputManager 102 74 : public OrxonoxClass, 103 public OIS::KeyListener, public OIS::MouseListener , public OIS::JoyStickListener75 public OIS::KeyListener, public OIS::MouseListener 104 76 { 105 77 // --> setConfigValues is private 106 78 friend class ClassIdentifier<InputManager>; 79 friend class JoyStick; 107 80 108 81 public: … … 115 88 Calibrating = 0x08, 116 89 ReloadRequest = 0x10, 117 JoyStickSupport = 0x20 // used with ReloadRequest to store a bool118 90 }; 119 91 120 InputManager ( );92 InputManager (size_t windowHnd, unsigned int windowWidth, unsigned int windowHeight); 121 93 ~InputManager(); 122 94 123 void initialise(size_t windowHnd, int windowWidth, int windowHeight, bool joyStickSupport = true);124 125 void reloadInputSystem( bool joyStickSupport = true);95 void initialise(size_t windowHnd, unsigned int windowWidth, unsigned int windowHeight); 96 97 void reloadInputSystem(); 126 98 127 99 void clearBuffers(); … … 129 101 unsigned int numberOfKeyboards() { return keyboard_ ? 1 : 0; } 130 102 unsigned int numberOfMice() { return mouse_ ? 1 : 0; } 131 unsigned int numberOfJoySticks() { return joySticks Size_; }103 unsigned int numberOfJoySticks() { return joySticks_.size(); } 132 104 133 105 void setWindowExtents(const int width, const int height); … … 156 128 // console commands 157 129 static void calibrate(); 158 static void reload( bool joyStickSupport = true);130 static void reload(); 159 131 160 132 public: // variables 161 133 static EmptyHandler EMPTY_HANDLER; 162 static const unsigned int sliderAxes = 8; 134 135 private: // functions for friends 136 OIS::InputManager* getInputSystem() { return this->inputSystem_; } 137 bool checkJoyStickID(const std::string&); 163 138 164 139 private: // functions … … 168 143 // Intenal methods 169 144 void _initialiseKeyboard(); 170 void _initialiseMouse( );145 void _initialiseMouse(unsigned int windowWidth, unsigned int windowHeight); 171 146 void _initialiseJoySticks(); 172 147 void _configureJoySticks(); … … 181 156 void _destroyJoySticks(); 182 157 void _destroyState(InputState* state); 183 void _clearBuffers(); 184 185 void _reload(bool joyStickSupport); 158 159 void _reload(); 186 160 187 161 void _fireAxis(unsigned int iJoyStick, int axis, int value); … … 197 171 bool keyPressed (const OIS::KeyEvent &arg); 198 172 bool keyReleased (const OIS::KeyEvent &arg); 199 bool buttonPressed (const OIS::JoyStickEvent &arg, int button);200 bool buttonReleased(const OIS::JoyStickEvent &arg, int button);201 bool axisMoved (const OIS::JoyStickEvent &arg, int axis);202 bool sliderMoved (const OIS::JoyStickEvent &arg, int id);203 bool povMoved (const OIS::JoyStickEvent &arg, int id);204 // don't remove that! Or else add OIS as dependency library to orxonox.205 bool vector3Moved (const OIS::JoyStickEvent &arg, int id) { return true; }206 173 207 174 void setConfigValues(); … … 212 179 OIS::Keyboard* keyboard_; //!< OIS mouse 213 180 OIS::Mouse* mouse_; //!< OIS keyboard 214 std::vector<OIS::JoyStick*> joySticks_; //!< OIS joy sticks 215 unsigned int joySticksSize_; 216 std::vector<std::string> joyStickIDs_; //!< Execution unique identification strings for the joy sticks 181 std::vector<JoyStick*> joySticks_; //!< Orxonox joy sticks 217 182 unsigned int devicesNum_; 218 183 size_t windowHnd_; //!< Render window handle … … 234 199 std::vector<InputState*> activeStatesTicked_; 235 200 236 // joystick calibration237 std::vector<std::vector<int> > joyStickMinValues_;238 std::vector<std::vector<int> > joyStickMaxValues_;239 std::vector<std::vector<int> > joyStickMiddleValues_;240 std::vector<ConfigValueContainer*> calibrationConfigValueContainers_;241 std::vector<JoyStickCalibration> joyStickCalibrations_;242 243 201 unsigned int keyboardModifiers_; //!< Bit mask representing keyboard modifiers. 244 std::vector<POVStates> povStates_; //!< Keeps track of the joy stick POV states.245 std::vector<SliderStates> sliderStates_; //!< Keeps track of the possibly two slider axes.246 202 247 203 std::vector<Key> keysDown_; 248 std::vector<MouseButtonCode::ByEnum> mouseButtonsDown_; 249 std::vector<std::vector<JoyStickButtonCode::ByEnum> > joyStickButtonsDown_; 250 251 // ConfigValues 252 std::string calibrationFilename_; //!< Joy stick calibration ini filename 204 std::vector<MouseButtonCode::ByEnum> mouseButtonsDown_; 253 205 254 206 static InputManager* singletonRef_s; -
code/branches/core4/src/core/input/InputState.h
r3196 r3270 40 40 #include <vector> 41 41 #include "InputInterfaces.h" 42 #include "JoyStickDeviceNumberListener.h" 42 43 43 44 namespace orxonox 44 45 { 45 class _CoreExport InputState 46 class _CoreExport InputState : public JoyStickDeviceNumberListener 46 47 { 47 48 friend class InputManager; … … 111 112 112 113 private: 113 void setNumOfJoySticks(unsigned int n)114 void JoyStickDeviceNumberChanged(unsigned int n) 114 115 { 115 116 bInputDeviceEnabled_.resize(n + 2); -
code/branches/core4/src/core/input/SimpleInputState.cc
r3196 r3270 59 59 } 60 60 update(); 61 }62 63 void SimpleInputState::keyPressed(const KeyEvent& evt)64 {65 if (keyHandler_)66 keyHandler_->keyPressed(evt);67 61 } 68 62 -
code/branches/core4/src/core/input/SimpleInputState.h
r3196 r3270 119 119 } 120 120 121 inline void SimpleInputState::keyPressed(const KeyEvent& evt) 122 { 123 if (keyHandler_) 124 keyHandler_->keyPressed(evt); 125 } 126 121 127 inline void SimpleInputState::keyReleased(const KeyEvent& evt) 122 128 { -
code/branches/core4/src/orxonox/gamestates/GSGraphics.cc
r3254 r3270 122 122 123 123 // Calls the InputManager which sets up the input devices. 124 inputManager_ = new InputManager(); 125 inputManager_->initialise(windowHnd, renderWindow->getWidth(), renderWindow->getHeight(), true); 124 inputManager_ = new InputManager(windowHnd, renderWindow->getWidth(), renderWindow->getHeight()); 126 125 127 126 // load master key bindings -
code/branches/core4/src/util/StringUtils.cc
r3265 r3270 490 490 return std::string::npos; 491 491 } 492 493 /** 494 @brief Replaces individual charaters 495 @param str String to be manipulated 496 @param target Character to be replaced 497 @param replacement Replacement character 498 @return Number of replacements 499 */ 500 _UtilExport size_t replaceCharacters(std::string& str, char target, char replacement) 501 { 502 size_t j = 0; 503 for (size_t i = 0; i < str.size(); ++i) 504 { 505 if (str[i] == target) 506 { 507 str[i] = replacement; 508 ++j; 509 } 510 } 511 return j; 512 } 492 513 } -
code/branches/core4/src/util/StringUtils.h
r3250 r3270 77 77 _UtilExport size_t getCommentPosition(const std::string& str); 78 78 _UtilExport size_t getNextCommentPosition(const std::string& str, size_t start = 0); 79 80 _UtilExport size_t replaceCharacters(std::string& str, char target, char replacement); 79 81 } 80 82
Note: See TracChangeset
for help on using the changeset viewer.