Changeset 5695 for code/trunk/src/core/input/InputManager.cc
- Timestamp:
- Aug 30, 2009, 2:22:00 AM (16 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/resource2 (added) merged: 3373-3374,5594,5597,5610-5611,5614,5624,5641,5644-5646,5650-5664,5667-5672,5682-5684,5688-5691,5694
- Property svn:mergeinfo changed
-
code/trunk/src/core/input/InputManager.cc
r3370 r5695 41 41 #include <boost/foreach.hpp> 42 42 43 #include "util/Convert.h" 43 44 #include "util/Exception.h" 44 45 #include "util/ScopeGuard.h" … … 49 50 #include "core/CommandLine.h" 50 51 #include "core/Functor.h" 52 #include "core/GraphicsManager.h" 51 53 52 54 #include "InputBuffer.h" … … 82 84 // ########## ########## 83 85 // ############################################################ 84 InputManager::InputManager( size_t windowHnd)86 InputManager::InputManager() 85 87 : internalState_(Bad) 86 88 , oisInputManager_(0) 87 89 , devices_(2) 88 , windowHnd_(0)90 , bExclusiveMouse_(false) 89 91 , emptyState_(0) 90 92 , keyDetector_(0) … … 97 99 this->setConfigValues(); 98 100 99 this->loadDevices( windowHnd);101 this->loadDevices(); 100 102 101 103 // Lowest priority empty InputState … … 147 149 Creates the OIS::InputMananger, the keyboard, the mouse and 148 150 the joys ticks. If either of the first two fail, this method throws an exception. 149 @param windowHnd150 The window handle of the render window151 151 @param windowWidth 152 152 The width of the render window … … 154 154 The height of the render window 155 155 */ 156 void InputManager::loadDevices( size_t windowHnd)157 { 158 CCOUT( 3) << "Loading input devices..." << std::endl;156 void InputManager::loadDevices() 157 { 158 CCOUT(4) << "Loading input devices..." << std::endl; 159 159 160 160 // When loading the devices they should not already be loaded … … 164 164 assert(devices_.size() == InputDeviceEnumerator::FirstJoyStick); 165 165 166 // store handle internally so we can reload OIS 167 windowHnd_ = windowHnd; 168 166 // Fill parameter list 169 167 OIS::ParamList paramList; 170 std::ostringstream windowHndStr; 171 172 // Fill parameter list 173 windowHndStr << static_cast<unsigned int>(windowHnd); 174 paramList.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); 168 size_t windowHnd = GraphicsManager::getInstance().getRenderWindowHandle(); 169 paramList.insert(std::make_pair("WINDOW", multi_cast<std::string>(windowHnd))); 175 170 #if defined(ORXONOX_PLATFORM_WINDOWS) 176 //paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_NONEXCLUSIVE"))); 177 //paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_FOREGROUND"))); 178 //paramList.insert(std::make_pair(std::string("w32_keyboard"), std::string("DISCL_NONEXCLUSIVE"))); 179 //paramList.insert(std::make_pair(std::string("w32_keyboard"), std::string("DISCL_FOREGROUND"))); 171 paramList.insert(std::make_pair("w32_keyboard", "DISCL_NONEXCLUSIVE")); 172 paramList.insert(std::make_pair("w32_keyboard", "DISCL_FOREGROUND")); 173 paramList.insert(std::make_pair("w32_mouse", "DISCL_FOREGROUND")); 174 if (bExclusiveMouse_ || GraphicsManager::getInstance().isFullScreen()) 175 { 176 // Disable Windows key plus special keys (like play, stop, next, etc.) 177 paramList.insert(std::make_pair("w32_keyboard", "DISCL_NOWINKEY")); 178 paramList.insert(std::make_pair("w32_mouse", "DISCL_EXCLUSIVE")); 179 } 180 else 181 paramList.insert(std::make_pair("w32_mouse", "DISCL_NONEXCLUSIVE")); 180 182 #elif defined(ORXONOX_PLATFORM_LINUX) 181 paramList.insert(std::make_pair(std::string("XAutoRepeatOn"), std::string("true"))); 182 paramList.insert(std::make_pair(std::string("x11_mouse_grab"), "true")); 183 paramList.insert(std::make_pair(std::string("x11_mouse_hide"), "true")); 184 bool kbNoGrab; 185 CommandLine::getValue("keyboard_no_grab", &kbNoGrab); 186 if (kbNoGrab) 187 paramList.insert(std::make_pair(std::string("x11_keyboard_grab"), std::string("false"))); 183 // Enabling this is probably a bad idea, but whenever orxonox crashes, the setting stays on 184 // Trouble might be that the Pressed event occurs a bit too often... 185 paramList.insert(std::make_pair("XAutoRepeatOn", "true")); 186 187 if (bExclusiveMouse_ || GraphicsManager::getInstance().isFullScreen()) 188 { 189 if (CommandLine::getValue("keyboard_no_grab").getBool()) 190 paramList.insert(std::make_pair("x11_keyboard_grab", "false")); 191 else 192 paramList.insert(std::make_pair("x11_keyboard_grab", "true")); 193 paramList.insert(std::make_pair("x11_mouse_grab", "true")); 194 paramList.insert(std::make_pair("x11_mouse_hide", "true")); 195 } 188 196 else 189 paramList.insert(std::make_pair(std::string("x11_keyboard_grab"), std::string("true"))); 197 { 198 paramList.insert(std::make_pair("x11_keyboard_grab", "false")); 199 paramList.insert(std::make_pair("x11_mouse_grab", "false")); 200 paramList.insert(std::make_pair("x11_mouse_hide", "false")); 201 } 190 202 #endif 191 203 … … 212 224 } 213 225 214 // TODO: Remove the two parameters215 226 this->loadMouse(); 216 227 this->loadJoySticks(); … … 219 230 this->updateActiveStates(); 220 231 221 CCOUT( 3) << "Input devices loaded." << std::endl;232 CCOUT(4) << "Input devices loaded." << std::endl; 222 233 } 223 234 … … 275 286 InputManager::~InputManager() 276 287 { 277 CCOUT( 4) << "Destroying..." << std::endl;288 CCOUT(3) << "Destroying..." << std::endl; 278 289 279 290 // Destroy calibrator helper handler and state … … 293 304 this->destroyDevices(); 294 305 295 CCOUT( 4) << "Destruction complete." << std::endl;306 CCOUT(3) << "Destruction complete." << std::endl; 296 307 } 297 308 … … 304 315 void InputManager::destroyDevices() 305 316 { 306 CCOUT( 3) << "Destroying devices..." << std::endl;317 CCOUT(4) << "Destroying devices..." << std::endl; 307 318 308 319 BOOST_FOREACH(InputDevice*& device, devices_) … … 336 347 337 348 internalState_ |= Bad; 338 CCOUT( 3) << "Destroyed devices." << std::endl;349 CCOUT(4) << "Destroyed devices." << std::endl; 339 350 } 340 351 … … 365 376 366 377 this->destroyDevices(); 367 this->loadDevices( windowHnd_);378 this->loadDevices(); 368 379 369 380 internalState_ &= ~Bad; 370 381 internalState_ &= ~ReloadRequest; 371 CCOUT( 3) << "Reloading complete." << std::endl;382 CCOUT(4) << "Reloading complete." << std::endl; 372 383 } 373 384 … … 481 492 void InputManager::updateActiveStates() 482 493 { 494 assert((internalState_ & InputManager::Ticking) == 0); 483 495 // temporary resize 484 496 for (unsigned int i = 0; i < devices_.size(); ++i) … … 512 524 for (std::set<InputState*>::const_iterator it = tempSet.begin();it != tempSet.end(); ++it) 513 525 activeStatesTicked_.push_back(*it); 526 527 // Check whether we have to change the mouse mode 528 std::vector<InputState*>& mouseStates = devices_[InputDeviceEnumerator::Mouse]->getStateListRef(); 529 if (mouseStates.empty() && bExclusiveMouse_ || 530 !mouseStates.empty() && mouseStates.front()->getIsExclusiveMouse() != bExclusiveMouse_) 531 { 532 bExclusiveMouse_ = !bExclusiveMouse_; 533 if (!GraphicsManager::getInstance().isFullScreen()) 534 this->reloadInternal(); 535 } 514 536 } 515 537 … … 556 578 } 557 579 558 // ############################################################ 559 // ##### Iput States ##### 580 std::pair<int, int> InputManager::getMousePosition() const 581 { 582 Mouse* mouse = static_cast<Mouse*>(devices_[InputDeviceEnumerator::Mouse]); 583 if (mouse != NULL) 584 { 585 const OIS::MouseState state = mouse->getOISDevice()->getMouseState(); 586 return std::make_pair(state.X.abs, state.Y.abs); 587 } 588 else 589 return std::make_pair(0, 0); 590 } 591 592 // ############################################################ 593 // ##### Input States ##### 560 594 // ########## ########## 561 595 // ############################################################
Note: See TracChangeset
for help on using the changeset viewer.