Changeset 11071 for code/trunk/src/libraries/core/input/InputManager.cc
- Timestamp:
- Jan 17, 2016, 10:29:21 PM (9 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/core/input/InputManager.cc
r10624 r11071 39 39 #include <ois/OISException.h> 40 40 #include <ois/OISInputManager.h> 41 #include <boost/foreach.hpp>42 41 #include <loki/ScopeGuard.h> 43 42 … … 72 71 InputHandler InputHandler::EMPTY; 73 72 74 InputManager* InputManager::singletonPtr_s = 0;73 InputManager* InputManager::singletonPtr_s = nullptr; 75 74 76 75 //! Defines the |= operator for easier use. … … 94 93 InputManager::InputManager() 95 94 : internalState_(Bad) 96 , oisInputManager_( 0)95 , oisInputManager_(nullptr) 97 96 , devices_(2) 98 97 , exclusiveMouse_(false) 99 , emptyState_( 0)100 , calibratorCallbackHandler_( 0)98 , emptyState_(nullptr) 99 , calibratorCallbackHandler_(nullptr) 101 100 { 102 101 RegisterObject(InputManager); … … 149 148 // When loading the devices they should not already be loaded 150 149 assert(internalState_ & Bad); 151 assert(devices_[InputDeviceEnumerator::Mouse] == 0);152 assert(devices_[InputDeviceEnumerator::Keyboard] == 0);150 assert(devices_[InputDeviceEnumerator::Mouse] == nullptr); 151 assert(devices_[InputDeviceEnumerator::Keyboard] == nullptr); 153 152 assert(devices_.size() == InputDeviceEnumerator::FirstJoyStick); 154 153 … … 210 209 catch (const std::exception& ex) 211 210 { 212 oisInputManager_ = NULL;211 oisInputManager_ = nullptr; 213 212 internalState_ |= Bad; 214 213 ThrowException(InitialisationFailed, "Could not initialise the input system: " << ex.what()); … … 294 293 295 294 // Reset console commands 296 ModifyConsoleCommand(__CC_InputManager_name, __CC_calibrate_name).setObject( 0);297 ModifyConsoleCommand(__CC_InputManager_name, __CC_reload_name).setObject( 0);295 ModifyConsoleCommand(__CC_InputManager_name, __CC_calibrate_name).setObject(nullptr); 296 ModifyConsoleCommand(__CC_InputManager_name, __CC_reload_name).setObject(nullptr); 298 297 299 298 orxout(internal_status, context::input) << "InputManager: Destruction complete." << endl; … … 310 309 orxout(verbose, context::input) << "InputManager: Destroying devices..." << endl; 311 310 312 BOOST_FOREACH(InputDevice*& device,devices_)313 { 314 if (device == NULL)311 for (InputDevice*& device : devices_) 312 { 313 if (device == nullptr) 315 314 continue; 316 315 const std::string& className = device->getClassName(); 317 316 delete device; 318 device = 0;317 device = nullptr; 319 318 orxout(verbose, context::input) << className << " destroyed." << endl; 320 319 } 321 320 devices_.resize(InputDeviceEnumerator::FirstJoyStick); 322 321 323 assert(oisInputManager_ != NULL);322 assert(oisInputManager_ != nullptr); 324 323 try 325 324 { … … 331 330 << "Potential resource leak!" << endl; 332 331 } 333 oisInputManager_ = NULL;332 oisInputManager_ = nullptr; 334 333 335 334 internalState_ |= Bad; … … 374 373 // check whether a state has changed its EMPTY situation 375 374 bool bUpdateRequired = false; 376 for ( std::map<int, InputState*>::iterator it = activeStates_.begin(); it != activeStates_.end(); ++it)377 { 378 if ( it->second->hasExpired())379 { 380 it->second->resetExpiration();375 for (const auto& mapEntry : activeStates_) 376 { 377 if (mapEntry.second->hasExpired()) 378 { 379 mapEntry.second->resetExpiration(); 381 380 bUpdateRequired = true; 382 381 } … … 387 386 // Capture all the input and collect the function calls 388 387 // No event gets triggered here yet! 389 BOOST_FOREACH(InputDevice* device,devices_)390 if (device != NULL)388 for (InputDevice* device : devices_) 389 if (device != nullptr) 391 390 device->update(time); 392 391 393 392 // Collect function calls for the update 394 for ( unsigned int i = 0; i < activeStatesTicked_.size(); ++i)395 activeStatesTicked_[i]->update(time.getDeltaTime());393 for (InputState* state : activeStatesTicked_) 394 state->update(time.getDeltaTime()); 396 395 397 396 // Execute all cached function calls in order … … 402 401 // If we delay the calls, then OIS and and the InputStates are not anymore 403 402 // in the call stack and can therefore be edited. 404 for ( size_t i = 0; i < this->callBuffer_.size(); ++i)405 this->callBuffer_[i]();403 for (auto& function : this->callBuffer_) 404 function(); 406 405 407 406 this->callBuffer_.clear(); … … 419 418 for (unsigned int i = 0; i < devices_.size(); ++i) 420 419 { 421 if (devices_[i] == NULL)420 if (devices_[i] == nullptr) 422 421 continue; 423 422 std::vector<InputState*>& states = devices_[i]->getStateListRef(); … … 438 437 // Using an std::set to avoid duplicates 439 438 std::set<InputState*> tempSet; 440 for ( unsigned int i = 0; i < devices_.size(); ++i)441 if (device s_[i] != NULL)442 for (unsigned int iState = 0; iState < device s_[i]->getStateListRef().size(); ++iState)443 tempSet.insert(device s_[i]->getStateListRef()[iState]);439 for (InputDevice* device : devices_) 440 if (device != nullptr) 441 for (unsigned int iState = 0; iState < device->getStateListRef().size(); ++iState) 442 tempSet.insert(device->getStateListRef()[iState]); 444 443 445 444 // Copy the content of the std::set back to the actual vector 446 445 activeStatesTicked_.clear(); 447 for ( std::set<InputState*>::const_iterator it = tempSet.begin();it != tempSet.end(); ++it)448 activeStatesTicked_.push_back( *it);446 for (InputState* state : tempSet) 447 activeStatesTicked_.push_back(state); 449 448 450 449 // Check whether we have to change the mouse mode … … 466 465 void InputManager::clearBuffers() 467 466 { 468 BOOST_FOREACH(InputDevice* device,devices_)469 if (device != NULL)467 for (InputDevice* device : devices_) 468 if (device != nullptr) 470 469 device->clearBuffers(); 471 470 } … … 476 475 << "When done, put the axex in the middle position and press enter." << endl; 477 476 478 BOOST_FOREACH(InputDevice* device,devices_)479 if (device != NULL)477 for (InputDevice* device : devices_) 478 if (device != nullptr) 480 479 device->startCalibration(); 481 480 … … 487 486 void InputManager::stopCalibration() 488 487 { 489 BOOST_FOREACH(InputDevice* device,devices_)490 if (device != NULL)488 for (InputDevice* device : devices_) 489 if (device != nullptr) 491 490 device->stopCalibration(); 492 491 … … 509 508 { 510 509 Mouse* mouse = static_cast<Mouse*>(devices_[InputDeviceEnumerator::Mouse]); 511 if (mouse != NULL)510 if (mouse != nullptr) 512 511 { 513 512 const OIS::MouseState state = mouse->getOISDevice()->getMouseState(); … … 526 525 { 527 526 if (name.empty()) 528 return 0;527 return nullptr; 529 528 if (statesByName_.find(name) == statesByName_.end()) 530 529 { … … 532 531 { 533 532 // Make sure we don't add two high priority states with the same priority 534 for (std::map<std::string, InputState*>::const_iterator it = this->statesByName_.begin(); 535 it != this->statesByName_.end(); ++it) 533 for (const auto& mapEntry : this->statesByName_) 536 534 { 537 if ( it->second->getPriority() == priority)535 if (mapEntry.second->getPriority() == priority) 538 536 { 539 537 orxout(internal_warning, context::input) << "Could not add an InputState with the same priority '" 540 538 << static_cast<int>(priority) << "' != 0." << endl; 541 return 0;539 return nullptr; 542 540 } 543 541 } … … 551 549 { 552 550 orxout(internal_warning, context::input) << "Could not add an InputState with the same name '" << name << "'." << endl; 553 return 0;551 return nullptr; 554 552 } 555 553 } … … 561 559 return it->second; 562 560 else 563 return 0;561 return nullptr; 564 562 } 565 563
Note: See TracChangeset
for help on using the changeset viewer.