Changeset 1215
- Timestamp:
- May 2, 2008, 9:31:20 PM (17 years ago)
- Location:
- code/branches/input
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/input/bin/keybindings.ini
r1213 r1215 3 3 R_UNASSIGNED= 4 4 H_UNASSIGNED= 5 P_ESCAPE= exit5 P_ESCAPE="exit" 6 6 R_ESCAPE= 7 7 H_ESCAPE= -
code/branches/input/src/core/InputHandler.cc
r1213 r1215 267 267 switch (j) 268 268 { 269 // note: the first element in the struct is the string, so the following pointer 270 // arithmetic works. 269 271 case 0: 270 cont->getValue( bindingsKeyPress_ + i);272 cont->getValue(&bindingsKeyPress_[i].commandStr); 271 273 break; 272 274 case 1: … … 337 339 for (int i = 0; i < numberOfKeys_s; i++) 338 340 { 339 bindingsKeyPress_ [i] = "";340 bindingsKeyRelease_[i] = "";341 bindingsKeyHold_ [i] = "";341 bindingsKeyPress_ [i].commandStr = ""; 342 bindingsKeyRelease_[i].commandStr = ""; 343 bindingsKeyHold_ [i].commandStr = ""; 342 344 } 343 345 for (int i = 0; i < numberOfMouseButtons_s; i++) … … 366 368 setConfigValues(); 367 369 370 // evaluate the key bindings 371 // TODO: what if binding is invalid? 372 //for (int i = 0; i < numberOfKeys_s; i++) 373 //{ 374 // if (bindingsKeyPress_[i].commandStr != "") 375 // { 376 // bindingsKeyPress_[i].evaluation = CommandExecutor::evaluate(bindingsKeyPress_[i].commandStr); 377 // bindingsKeyPress_[i].commandStr = bindingsKeyPress_[i].evaluation.getCommandString(); 378 // } 379 //} 380 368 381 COUT(ORX_DEBUG) << "KeyBinder: Loading key bindings done." << std::endl; 382 return true; 383 } 384 385 bool KeyBinder::executeBinding(KeyBinding& binding) 386 { 387 if (binding.commandStr != "") 388 { 389 //if (binding.commandStr != binding.evaluation.getCommandString()) 390 //{ 391 // // key binding has changed, reevaluate the command string. 392 // binding.evaluation = CommandExecutor::evaluate(binding.commandStr); 393 // binding.commandStr = binding.evaluation.getCommandString(); 394 //} 395 COUT(3) << "Executing command: " << binding.commandStr << std::endl; 396 CommandExecutor::execute(binding.commandStr); 397 } 398 369 399 return true; 370 400 } … … 379 409 COUT(3) << "Key: " << e.key << std::endl; 380 410 // find the appropriate key binding 381 std::string cmdStr = bindingsKeyPress_[int(e.key)]; 382 if (cmdStr != "") 383 { 384 CommandExecutor::execute(cmdStr); 385 COUT(3) << "Executing command: " << cmdStr << std::endl; 386 } 387 411 executeBinding(bindingsKeyPress_[int(e.key)]); 412 388 413 return true; 389 414 } … … 396 421 { 397 422 // find the appropriate key binding 398 std::string cmdStr = bindingsKeyRelease_[int(e.key)]; 399 if (cmdStr != "") 400 { 401 CommandExecutor::execute(cmdStr); 402 COUT(3) << "Executing command: " << cmdStr << std::endl; 403 } 423 executeBinding(bindingsKeyRelease_[int(e.key)]); 404 424 405 425 return true; … … 413 433 { 414 434 // find the appropriate key binding 415 std::string cmdStr = bindingsKeyHold_[int(e.key)]; 416 if (cmdStr != "") 417 { 418 CommandExecutor::execute(cmdStr); 419 COUT(3) << "Executing command: " << cmdStr << std::endl; 420 } 435 executeBinding(bindingsKeyHold_[int(e.key)]); 421 436 422 437 return true; … … 486 501 } 487 502 488 bool KeyBinder::buttonPressed( const OIS::JoyStickEvent &arg, int button)503 bool KeyBinder::buttonPressed(int joyStickID, const OIS::JoyStickEvent &arg, int button) 489 504 { 490 505 // find the appropriate key binding … … 499 514 } 500 515 501 bool KeyBinder::buttonReleased( const OIS::JoyStickEvent &arg, int button)516 bool KeyBinder::buttonReleased(int joyStickID, const OIS::JoyStickEvent &arg, int button) 502 517 { 503 518 // find the appropriate key binding … … 512 527 } 513 528 514 bool KeyBinder::buttonHeld( const OIS::JoyStickEvent &arg, int button)529 bool KeyBinder::buttonHeld(int joyStickID, const OIS::JoyStickEvent &arg, int button) 515 530 { 516 531 // find the appropriate key binding … … 525 540 } 526 541 527 bool KeyBinder::axisMoved(const OIS::JoyStickEvent &arg, int axis) 528 { 529 return true; 530 } 531 532 bool KeyBinder::sliderMoved(const OIS::JoyStickEvent &arg, int id) 533 { 534 return true; 535 } 536 537 bool KeyBinder::povMoved(const OIS::JoyStickEvent &arg, int id) 542 bool KeyBinder::axisMoved(int joyStickID, const OIS::JoyStickEvent &arg, int axis) 543 { 544 return true; 545 } 546 547 bool KeyBinder::sliderMoved(int joyStickID, const OIS::JoyStickEvent &arg, int id) 548 { 549 return true; 550 } 551 552 bool KeyBinder::povMoved(int joyStickID, const OIS::JoyStickEvent &arg, int id) 553 { 554 return true; 555 } 556 557 bool KeyBinder::vector3Moved(int joyStickID, const OIS::JoyStickEvent &arg, int id) 538 558 { 539 559 return true; -
code/branches/input/src/core/InputHandler.h
r1213 r1215 40 40 #include "ois/OIS.h" 41 41 #include "OrxonoxClass.h" 42 #include "CommandExecutor.h" 42 43 43 44 namespace orxonox … … 60 61 { 61 62 public: 63 virtual ~KeyHandler() { } 62 64 virtual bool keyHeld(const OIS::KeyEvent &arg) = 0; 63 65 }; … … 69 71 { 70 72 public: 73 virtual ~MouseHandler() { } 71 74 virtual bool mouseHeld(const OIS::MouseEvent &arg, OIS::MouseButtonID id) = 0; 72 75 }; … … 75 78 @brief Interface class used for joy stick input listeners. 76 79 */ 77 class _CoreExport JoyStickHandler : public OIS::JoyStickListener 78 { 79 public: 80 virtual bool buttonHeld(const OIS::JoyStickEvent &arg, int button) = 0; 80 class _CoreExport JoyStickHandler 81 { 82 public: 83 virtual ~JoyStickHandler() { } 84 virtual bool buttonPressed (int joyStickID, const OIS::JoyStickEvent &arg, int button) = 0; 85 virtual bool buttonReleased(int joyStickID, const OIS::JoyStickEvent &arg, int button) = 0; 86 virtual bool buttonHeld (int joyStickID, const OIS::JoyStickEvent &arg, int button) = 0; 87 virtual bool axisMoved (int joyStickID, const OIS::JoyStickEvent &arg, int axis) = 0; 88 virtual bool sliderMoved (int joyStickID, const OIS::JoyStickEvent &arg, int index) {return true;} 89 virtual bool povMoved (int joyStickID, const OIS::JoyStickEvent &arg, int index) {return true;} 90 virtual bool vector3Moved (int joyStickID, const OIS::JoyStickEvent &arg, int index) {return true;} 91 }; 92 93 struct _CoreExport KeyBinding 94 { 95 std::string commandStr; 96 CommandEvaluation evaluation; 81 97 }; 82 98 … … 100 116 101 117 private: // functions 118 119 bool executeBinding(KeyBinding &binding); 120 102 121 bool keyPressed (const OIS::KeyEvent &arg); 103 122 bool keyReleased (const OIS::KeyEvent &arg); … … 109 128 bool mouseMoved (const OIS::MouseEvent &arg); 110 129 111 bool buttonPressed (const OIS::JoyStickEvent &arg, int button); 112 bool buttonReleased(const OIS::JoyStickEvent &arg, int button); 113 bool buttonHeld (const OIS::JoyStickEvent &arg, int button); 114 bool axisMoved (const OIS::JoyStickEvent &arg, int axis); 115 bool sliderMoved (const OIS::JoyStickEvent &arg, int id); 116 bool povMoved (const OIS::JoyStickEvent &arg, int id); 130 bool buttonPressed (int joyStickID, const OIS::JoyStickEvent &arg, int button); 131 bool buttonReleased(int joyStickID, const OIS::JoyStickEvent &arg, int button); 132 bool buttonHeld (int joyStickID, const OIS::JoyStickEvent &arg, int button); 133 bool axisMoved (int joyStickID, const OIS::JoyStickEvent &arg, int axis); 134 bool sliderMoved (int joyStickID, const OIS::JoyStickEvent &arg, int id); 135 bool povMoved (int joyStickID, const OIS::JoyStickEvent &arg, int id); 136 bool vector3Moved (int joyStickID, const OIS::JoyStickEvent &arg, int id); 117 137 118 138 private: // variables … … 121 141 static const int numberOfKeys_s = 0xEE; 122 142 //! Array of input events for every pressed key 123 std::string bindingsKeyPress_ [numberOfKeys_s];143 KeyBinding bindingsKeyPress_ [numberOfKeys_s]; 124 144 //! Array of input events for every released key 125 std::string bindingsKeyRelease_[numberOfKeys_s];145 KeyBinding bindingsKeyRelease_[numberOfKeys_s]; 126 146 //! Array of input events for every held key 127 std::string bindingsKeyHold_ [numberOfKeys_s];147 KeyBinding bindingsKeyHold_ [numberOfKeys_s]; 128 148 //! Names of the keys as strings 129 149 std::string keyNames_[numberOfKeys_s]; -
code/branches/input/src/core/InputManager.cc
r1213 r1215 55 55 { 56 56 RegisterObject(InputManager); 57 58 this->joySticks_.reserve(5); 59 //this->activeJoyStickHandlers_.reserve(10); 60 this->activeKeyHandlers_.reserve(10); 61 this->activeMouseHandlers_.reserve(10); 57 62 } 58 63 … … 242 247 { 243 248 OIS::JoyStick* stig = static_cast<OIS::JoyStick*>(inputSystem_->createInputObject(OIS::OISJoyStick, true)); 244 joySticks_ [stig->getID()] = stig;249 joySticks_.push_back(stig); 245 250 // register our listener in OIS. 246 251 stig->setEventCallback(this); … … 278 283 delete keyHandlers_["keybinder"]; 279 284 280 activeKeyHandlers_.clear();281 activeMouseHandlers_.clear();282 activeJoyStickHandlers_.clear();283 285 keyHandlers_.clear(); 284 286 mouseHandlers_.clear(); 285 287 joyStickHandlers_.clear(); 286 287 keysDown_.clear();288 mouseButtonsDown_.clear();289 joyStickButtonsDown_.clear();290 288 291 289 _destroyKeyboard(); … … 314 312 inputSystem_->destroyInputObject(keyboard_); 315 313 keyboard_ = 0; 314 activeKeyHandlers_.clear(); 315 keysDown_.clear(); 316 316 CCOUT(ORX_DEBUG) << "Keyboard destroyed." << std::endl; 317 317 } … … 326 326 inputSystem_->destroyInputObject(mouse_); 327 327 mouse_ = 0; 328 activeMouseHandlers_.clear(); 329 mouseButtonsDown_.clear(); 328 330 CCOUT(ORX_DEBUG) << "Mouse destroyed." << std::endl; 329 331 } … … 337 339 { 338 340 // note: inputSystem_ can never be 0, or else the code is mistaken 339 for (std::map<int, OIS::JoyStick*>::iterator itstick = joySticks_.begin(); itstick != joySticks_.end(); itstick++) 340 { 341 if ((*itstick).second != 0) 342 inputSystem_->destroyInputObject((*itstick).second); 343 } 341 for (unsigned int i = 0; i < joySticks_.size(); i++) 342 if (joySticks_[i] != 0) 343 inputSystem_->destroyInputObject(joySticks_[i]); 344 344 345 joySticks_.clear(); 346 activeJoyStickHandlers_.clear(); 347 joyStickButtonsDown_.clear(); 345 348 } 346 349 CCOUT(ORX_DEBUG) << "Joy sticks destroyed." << std::endl; … … 375 378 case IS_NORMAL: 376 379 // normal play mode 377 if (keyHandlers_.find("keybinder") != keyHandlers_.end()) 378 activeKeyHandlers_.push_back(keyHandlers_["keybinder"]); 379 if (mouseHandlers_.find("keybinder") != mouseHandlers_.end()) 380 activeMouseHandlers_.push_back(mouseHandlers_["keybinder"]); 381 if (joyStickHandlers_.find("keybinder") != joyStickHandlers_.end()) 382 { 383 for (std::map<int, OIS::JoyStick*>::const_iterator it = joySticks_.begin(); 384 it != joySticks_.end(); it++) 385 activeJoyStickHandlers_[(*it).first].push_back(joyStickHandlers_["keybinder"]); 386 } 380 // note: we assume that the handlers exist since otherwise, something's wrong anyway. 381 activeKeyHandlers_.push_back(keyHandlers_["keybinder"]); 382 activeMouseHandlers_.push_back(mouseHandlers_["keybinder"]); 383 activeMouseHandlers_.push_back(mouseHandlers_["SpaceShip"]); 384 for (std::vector<OIS::JoyStick*>::const_iterator it = joySticks_.begin(); 385 it != joySticks_.end(); it++) 386 activeJoyStickHandlers_[*it].push_back(joyStickHandlers_["keybinder"]); 387 387 break; 388 388 … … 392 392 393 393 case IS_CONSOLE: 394 if (mouseHandlers_.find("keybinder") != mouseHandlers_.end()) 395 activeMouseHandlers_.push_back(mouseHandlers_["keybinder"]); 396 if (joyStickHandlers_.find("keybinder") != joyStickHandlers_.end()) 397 { 398 for (std::map<int, OIS::JoyStick*>::const_iterator it = joySticks_.begin(); 399 it != joySticks_.end(); it++) 400 activeJoyStickHandlers_[(*it).first].push_back(joyStickHandlers_["keybinder"]); 401 } 402 403 if (keyHandlers_.find("buffer") != keyHandlers_.end()) 404 activeKeyHandlers_.push_back(keyHandlers_["buffer"]); 405 else 406 { 407 // someone fiddled with the InputBuffer 408 CCOUT(2) << "Error: Cannot redirect input to console, InputBuffer instance missing." << std::endl; 409 if (keyHandlers_.find("keybinder") != keyHandlers_.end()) 410 activeKeyHandlers_.push_back(keyHandlers_["keybinder"]); 411 else 412 // this is bad 413 CCOUT(2) << "Error: Cannot reactivate key binder: not found!" << std::endl; 414 } 394 activeMouseHandlers_.push_back(mouseHandlers_["keybinder"]); 395 for (std::vector<OIS::JoyStick*>::const_iterator it = joySticks_.begin(); 396 it != joySticks_.end(); it++) 397 activeJoyStickHandlers_[*it].push_back(joyStickHandlers_["keybinder"]); 398 399 activeKeyHandlers_.push_back(keyHandlers_["buffer"]); 415 400 break; 416 401 … … 434 419 { 435 420 OIS::KeyEvent keyArg(keyboard_, *itKey, 0); 436 for (std::list<KeyHandler*>::const_iterator itKeyHandler = activeKeyHandlers_.begin(); 437 itKeyHandler != activeKeyHandlers_.end(); itKeyHandler++) 438 { 439 (*itKeyHandler)->keyHeld(keyArg); 440 } 421 for (unsigned int i = 0; i < activeKeyHandlers_.size(); i++) 422 activeKeyHandlers_[i]->keyHeld(keyArg); 441 423 } 442 424 … … 446 428 { 447 429 OIS::MouseEvent mouseButtonArg(mouse_, mouse_->getMouseState()); 448 for (std::list<MouseHandler*>::const_iterator itMouseHandler = activeMouseHandlers_.begin(); 449 itMouseHandler != activeMouseHandlers_.end(); itMouseHandler++) 450 { 451 (*itMouseHandler)->mouseHeld(mouseButtonArg, *itMouseButton); 452 } 430 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 431 activeMouseHandlers_[i]->mouseHeld(mouseButtonArg, *itMouseButton); 453 432 } 454 433 455 434 // call all the handlers for the held joy stick button events 456 for (std::map< int, std::list <int> >::const_iterator itJoyStick = joyStickButtonsDown_.begin();435 for (std::map< OIS::JoyStick*, std::list <int> >::const_iterator itJoyStick = joyStickButtonsDown_.begin(); 457 436 itJoyStick != joyStickButtonsDown_.end(); itJoyStick++) 458 437 { 459 int id= (*itJoyStick).first;438 OIS::JoyStick* joyStick = (*itJoyStick).first; 460 439 for (std::list<int>::const_iterator itJoyStickButton = (*itJoyStick).second.begin(); 461 440 itJoyStickButton != (*itJoyStick).second.end(); itJoyStickButton++) 462 441 { 463 OIS::JoyStickEvent joyStickButtonArg(joySticks_[id], joySticks_[id]->getJoyStickState()); 464 for (std::list<JoyStickHandler*>::const_iterator itJoyStickHandler = activeJoyStickHandlers_[id].begin(); 465 itJoyStickHandler != activeJoyStickHandlers_[id].end(); itJoyStickHandler++) 466 { 467 (*itJoyStickHandler)->buttonHeld(joyStickButtonArg, *itJoyStickButton); 468 } 469 } 470 } 471 } 472 442 OIS::JoyStickEvent joyStickButtonArg(joyStick, joyStick->getJoyStickState()); 443 for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++) 444 activeJoyStickHandlers_[joyStick][i]->buttonHeld(i, joyStickButtonArg, *itJoyStickButton); 445 } 446 } 447 } 448 449 450 // ###### Key Events ###### 473 451 474 452 /** … … 478 456 bool InputManager::keyPressed(const OIS::KeyEvent &e) 479 457 { 480 // check whether the key is alreadyin the list (can happen when focus was lost)458 // check whether the key already is in the list (can happen when focus was lost) 481 459 for (std::list<OIS::KeyCode>::iterator it = keysDown_.begin(); it != keysDown_.end(); it++) 482 460 { … … 489 467 keysDown_.push_back(e.key); 490 468 491 for ( std::list<KeyHandler*>::const_iterator it = activeKeyHandlers_.begin(); it != activeKeyHandlers_.end(); it++)492 (*it)->keyPressed(e);469 for (unsigned int i = 0; i < activeKeyHandlers_.size(); i++) 470 activeKeyHandlers_[i]->keyPressed(e); 493 471 494 472 return true; … … 511 489 } 512 490 513 for (std::list<KeyHandler*>::const_iterator it = activeKeyHandlers_.begin(); it != activeKeyHandlers_.end(); it++) 514 (*it)->keyReleased(e); 515 516 return true; 517 } 491 for (unsigned int i = 0; i < activeKeyHandlers_.size(); i++) 492 activeKeyHandlers_[i]->keyReleased(e); 493 494 return true; 495 } 496 497 498 // ###### Mouse Events ###### 518 499 519 500 /** … … 523 504 bool InputManager::mouseMoved(const OIS::MouseEvent &e) 524 505 { 525 for ( std::list<MouseHandler*>::const_iterator it = activeMouseHandlers_.begin(); it != activeMouseHandlers_.end(); it++)526 (*it)->mouseMoved(e);506 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 507 activeMouseHandlers_[i]->mouseMoved(e); 527 508 528 509 return true; … … 536 517 bool InputManager::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id) 537 518 { 538 // check whether the button is alreadyin the list (can happen when focus was lost)519 // check whether the button already is in the list (can happen when focus was lost) 539 520 for (std::list<OIS::MouseButtonID>::iterator it = mouseButtonsDown_.begin(); it != mouseButtonsDown_.end(); it++) 540 521 { … … 547 528 mouseButtonsDown_.push_back(id); 548 529 549 for ( std::list<MouseHandler*>::const_iterator it = activeMouseHandlers_.begin(); it != activeMouseHandlers_.end(); it++)550 (*it)->mousePressed(e, id);530 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 531 activeMouseHandlers_[i]->mousePressed(e, id); 551 532 552 533 return true; … … 570 551 } 571 552 572 for (std::list<MouseHandler*>::const_iterator it = activeMouseHandlers_.begin(); it != activeMouseHandlers_.end(); it++) 573 (*it)->mouseReleased(e, id); 574 575 return true; 576 } 553 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 554 activeMouseHandlers_[i]->mouseReleased(e, id); 555 556 return true; 557 } 558 559 560 // ###### Joy Stick Events ###### 577 561 578 562 bool InputManager::buttonPressed(const OIS::JoyStickEvent &arg, int button) 579 563 { 580 int devID = arg.device->getID();581 582 // check whether the button is alreadyin the list (can happen when focus was lost)583 std::list<int>& buttonsDownList = joyStickButtonsDown_[ devID];564 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 565 566 // check whether the button already is in the list (can happen when focus was lost) 567 std::list<int>& buttonsDownList = joyStickButtonsDown_[joyStick]; 584 568 for (std::list<int>::iterator it = buttonsDownList.begin(); it != buttonsDownList.end(); it++) 585 569 { … … 590 574 } 591 575 } 592 joyStickButtonsDown_[devID].push_back(button); 593 594 std::list<JoyStickHandler*>::iterator end = activeJoyStickHandlers_[devID].end(); 595 for (std::list<JoyStickHandler*>::const_iterator it = activeJoyStickHandlers_[devID].begin(); it != end; it++) 596 (*it)->buttonPressed(arg, button); 576 joyStickButtonsDown_[joyStick].push_back(button); 577 578 for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++) 579 activeJoyStickHandlers_[joyStick][i]->buttonPressed(i, arg, button); 597 580 598 581 return true; … … 601 584 bool InputManager::buttonReleased(const OIS::JoyStickEvent &arg, int button) 602 585 { 603 int devID = arg.device->getID();586 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 604 587 605 588 // remove the button from the joyStickButtonsDown_ list 606 std::list<int>& buttonsDownList = joyStickButtonsDown_[ devID];589 std::list<int>& buttonsDownList = joyStickButtonsDown_[joyStick]; 607 590 for (std::list<int>::iterator it = buttonsDownList.begin(); it != buttonsDownList.end(); it++) 608 591 { … … 614 597 } 615 598 616 std::list<JoyStickHandler*>::const_iterator end = activeJoyStickHandlers_[devID].end(); 617 for (std::list<JoyStickHandler*>::const_iterator it = activeJoyStickHandlers_[devID].begin(); it != end; it++) 618 (*it)->buttonReleased(arg, button); 599 for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++) 600 activeJoyStickHandlers_[joyStick][i]->buttonReleased(i, arg, button); 619 601 620 602 return true; … … 623 605 bool InputManager::axisMoved(const OIS::JoyStickEvent &arg, int axis) 624 606 { 625 int devID = arg.device->getID(); 626 std::list<JoyStickHandler*>::const_iterator end = activeJoyStickHandlers_[devID].end(); 627 for (std::list<JoyStickHandler*>::const_iterator it = activeJoyStickHandlers_[devID].begin(); it != end; it++) 628 (*it)->axisMoved(arg, axis); 607 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 608 for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++) 609 activeJoyStickHandlers_[joyStick][i]->axisMoved(i, arg, axis); 629 610 630 611 return true; … … 633 614 bool InputManager::sliderMoved(const OIS::JoyStickEvent &arg, int id) 634 615 { 635 int devID = arg.device->getID(); 636 std::list<JoyStickHandler*>::const_iterator end = activeJoyStickHandlers_[devID].end(); 637 for (std::list<JoyStickHandler*>::const_iterator it = activeJoyStickHandlers_[devID].begin(); it != end; it++) 638 (*it)->sliderMoved(arg, id); 616 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 617 for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++) 618 activeJoyStickHandlers_[joyStick][i]->sliderMoved(i, arg, id); 639 619 640 620 return true; … … 643 623 bool InputManager::povMoved(const OIS::JoyStickEvent &arg, int id) 644 624 { 645 int devID = arg.device->getID(); 646 std::list<JoyStickHandler*>::const_iterator end = activeJoyStickHandlers_[devID].end(); 647 for (std::list<JoyStickHandler*>::const_iterator it = activeJoyStickHandlers_[devID].begin(); it != end; it++) 648 (*it)->povMoved(arg, id); 625 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 626 for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++) 627 activeJoyStickHandlers_[joyStick][i]->povMoved(i, arg, id); 628 629 return true; 630 } 631 632 bool InputManager::vector3Moved(const OIS::JoyStickEvent &arg, int id) 633 { 634 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 635 for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++) 636 activeJoyStickHandlers_[joyStick][i]->vector3Moved(i, arg, id); 649 637 650 638 return true; … … 679 667 } 680 668 681 bool InputManager::isKeyboardInitialised() 682 { 683 return (_getSingleton().keyboard_ != 0); 684 } 685 686 bool InputManager::isMouseInitialised() 687 { 688 return (_getSingleton().mouse_ != 0); 689 } 690 691 bool InputManager::areJoySticksInitialised() 692 { 693 return (_getSingleton().joySticks_.size() > 0); 669 int InputManager::numberOfKeyboards() 670 { 671 if (_getSingleton().keyboard_ != 0) 672 return 1; 673 else 674 return 0; 675 } 676 677 int InputManager::numberOfMice() 678 { 679 if (_getSingleton().mouse_ != 0) 680 return 1; 681 else 682 return 0; 683 } 684 685 int InputManager::numberOfJoySticks() 686 { 687 return _getSingleton().joySticks_.size(); 694 688 } 695 689 … … 817 811 if (mapIt == _getSingleton().keyHandlers_.end()) 818 812 return false; 819 // see whether the handler is alreadyin the list820 for (std:: list<KeyHandler*>::iterator it = _getSingleton().activeKeyHandlers_.begin();813 // see whether the handler already is in the list 814 for (std::vector<KeyHandler*>::iterator it = _getSingleton().activeKeyHandlers_.begin(); 821 815 it != _getSingleton().activeKeyHandlers_.end(); it++) 822 816 { … … 844 838 return false; 845 839 // look for the handler in the list 846 for (std:: list<KeyHandler*>::iterator it = _getSingleton().activeKeyHandlers_.begin();840 for (std::vector<KeyHandler*>::iterator it = _getSingleton().activeKeyHandlers_.begin(); 847 841 it != _getSingleton().activeKeyHandlers_.end(); it++) 848 842 { … … 869 863 if (mapIt == _getSingleton().keyHandlers_.end()) 870 864 return false; 871 // see whether the handler is alreadyin the list872 for (std:: list<KeyHandler*>::iterator it = _getSingleton().activeKeyHandlers_.begin();865 // see whether the handler already is in the list 866 for (std::vector<KeyHandler*>::iterator it = _getSingleton().activeKeyHandlers_.begin(); 873 867 it != _getSingleton().activeKeyHandlers_.end(); it++) 874 868 { … … 943 937 if (mapIt == _getSingleton().mouseHandlers_.end()) 944 938 return false; 945 // see whether the handler is alreadyin the list946 for (std:: list<MouseHandler*>::iterator it = _getSingleton().activeMouseHandlers_.begin();939 // see whether the handler already is in the list 940 for (std::vector<MouseHandler*>::iterator it = _getSingleton().activeMouseHandlers_.begin(); 947 941 it != _getSingleton().activeMouseHandlers_.end(); it++) 948 942 { … … 970 964 return false; 971 965 // look for the handler in the list 972 for (std:: list<MouseHandler*>::iterator it = _getSingleton().activeMouseHandlers_.begin();966 for (std::vector<MouseHandler*>::iterator it = _getSingleton().activeMouseHandlers_.begin(); 973 967 it != _getSingleton().activeMouseHandlers_.end(); it++) 974 968 { … … 995 989 if (mapIt == _getSingleton().mouseHandlers_.end()) 996 990 return false; 997 // see whether the handler is alreadyin the list998 for (std:: list<MouseHandler*>::iterator it = _getSingleton().activeMouseHandlers_.begin();991 // see whether the handler already is in the list 992 for (std::vector<MouseHandler*>::iterator it = _getSingleton().activeMouseHandlers_.begin(); 999 993 it != _getSingleton().activeMouseHandlers_.end(); it++) 1000 994 { … … 1032 1026 bool InputManager::removeJoyStickHandler(const std::string &name) 1033 1027 { 1034 for (std::map<int, OIS::JoyStick*>::iterator itstick = _getSingleton().joySticks_.begin(); itstick != _getSingleton().joySticks_.end(); itstick++) 1035 disableJoyStickHandler(name, (*itstick).first); 1028 for (std::vector<OIS::JoyStick*>::iterator itstick = _getSingleton().joySticks_.begin(); 1029 itstick != _getSingleton().joySticks_.end(); itstick++) 1030 disableJoyStickHandler(name, itstick - _getSingleton().joySticks_.begin()); 1036 1031 1037 1032 std::map<std::string, JoyStickHandler*>::iterator it = _getSingleton().joyStickHandlers_.find(name); … … 1066 1061 @return False if name or id was not found, true otherwise. 1067 1062 */ 1068 bool InputManager::enableJoyStickHandler(const std::string& name, const int id)1069 { 1070 // get pointer from the map with all stored handlers1063 bool InputManager::enableJoyStickHandler(const std::string& name, const int ID) 1064 { 1065 // get handler pointer from the map with all stored handlers 1071 1066 std::map<std::string, JoyStickHandler*>::const_iterator handlerIt = _getSingleton().joyStickHandlers_.find(name); 1072 1067 if (handlerIt == _getSingleton().joyStickHandlers_.end()) 1073 1068 return false; 1074 1069 1075 // check for exist ance of the ID1076 std::map<int, OIS::JoyStick*>::const_iterator joyStickIt = _getSingleton().joySticks_.find(id);1077 if (joyStickIt == _getSingleton().joySticks_.end())1078 return false;1079 1080 // see whether the handler is alreadyin the list1081 for (std:: list<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[id].begin();1082 it != _getSingleton().activeJoyStickHandlers_[ id].end(); it++)1070 // check for existence of the ID 1071 if ((unsigned int)ID >= _getSingleton().joySticks_.size()) 1072 return false; 1073 OIS::JoyStick* joyStick = _getSingleton().joySticks_[ID]; 1074 1075 // see whether the handler already is in the list 1076 for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[joyStick].begin(); 1077 it != _getSingleton().activeJoyStickHandlers_[joyStick].end(); it++) 1083 1078 { 1084 1079 if ((*it) == (*handlerIt).second) … … 1088 1083 } 1089 1084 } 1090 _getSingleton().activeJoyStickHandlers_[ id].push_back((*handlerIt).second);1085 _getSingleton().activeJoyStickHandlers_[joyStick].push_back((*handlerIt).second); 1091 1086 _getSingleton().stateRequest_ = IS_CUSTOM; 1092 1087 return true; … … 1098 1093 @return False if name or id was not found, true otherwise. 1099 1094 */ 1100 bool InputManager::disableJoyStickHandler(const std::string &name, int id)1101 { 1102 // get pointer from the map with all stored handlers1095 bool InputManager::disableJoyStickHandler(const std::string &name, int ID) 1096 { 1097 // get handler pointer from the map with all stored handlers 1103 1098 std::map<std::string, JoyStickHandler*>::const_iterator handlerIt = _getSingleton().joyStickHandlers_.find(name); 1104 1099 if (handlerIt == _getSingleton().joyStickHandlers_.end()) 1105 1100 return false; 1106 1101 1107 // check for exist ance of the ID1108 std::map<int, OIS::JoyStick*>::const_iterator joyStickIt = _getSingleton().joySticks_.find(id);1109 if (joyStickIt == _getSingleton().joySticks_.end())1110 return false;1102 // check for existence of the ID 1103 if ((unsigned int)ID >= _getSingleton().joySticks_.size()) 1104 return false; 1105 OIS::JoyStick* joyStick = _getSingleton().joySticks_[ID]; 1111 1106 1112 1107 // look for the handler in the list 1113 for (std:: list<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[id].begin();1114 it != _getSingleton().activeJoyStickHandlers_[ id].end(); it++)1108 for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[joyStick].begin(); 1109 it != _getSingleton().activeJoyStickHandlers_[joyStick].end(); it++) 1115 1110 { 1116 1111 if ((*it) == (*handlerIt).second) 1117 1112 { 1118 _getSingleton().activeJoyStickHandlers_[ id].erase(it);1113 _getSingleton().activeJoyStickHandlers_[joyStick].erase(it); 1119 1114 _getSingleton().stateRequest_ = IS_CUSTOM; 1120 1115 return true; 1121 1116 } 1122 1117 } 1123 _getSingleton().stateRequest_ = IS_CUSTOM;1124 1118 return true; 1125 1119 } … … 1130 1124 @return False if key handler is not active or doesn't exist, true otherwise. 1131 1125 */ 1132 bool InputManager::isJoyStickHandlerActive(const std::string& name, const int id)1133 { 1134 // get pointer from the map with all stored handlers1126 bool InputManager::isJoyStickHandlerActive(const std::string& name, const int ID) 1127 { 1128 // get handler pointer from the map with all stored handlers 1135 1129 std::map<std::string, JoyStickHandler*>::const_iterator handlerIt = _getSingleton().joyStickHandlers_.find(name); 1136 1130 if (handlerIt == _getSingleton().joyStickHandlers_.end()) 1137 1131 return false; 1138 1132 1139 // check for exist ance of the ID1140 std::map<int, OIS::JoyStick*>::const_iterator joyStickIt = _getSingleton().joySticks_.find(id);1141 if (joyStickIt == _getSingleton().joySticks_.end())1142 return false;1143 1144 // see whether the handler is alreadyin the list1145 for (std:: list<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[id].begin();1146 it != _getSingleton().activeJoyStickHandlers_[ id].end(); it++)1133 // check for existence of the ID 1134 if ((unsigned int)ID >= _getSingleton().joySticks_.size()) 1135 return false; 1136 OIS::JoyStick* joyStick = _getSingleton().joySticks_[ID]; 1137 1138 // see whether the handler already is in the list 1139 for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[joyStick].begin(); 1140 it != _getSingleton().activeJoyStickHandlers_[joyStick].end(); it++) 1147 1141 { 1148 1142 if ((*it) == (*handlerIt).second) -
code/branches/input/src/core/InputManager.h
r1204 r1215 77 77 static bool initialiseMouse(); 78 78 static bool initialiseJoySticks(); 79 static bool isKeyboardInitialised();80 static bool isMouseInitialised();81 static bool areJoySticksInitialised();79 static int numberOfKeyboards(); 80 static int numberOfMice(); 81 static int numberOfJoySticks(); 82 82 83 83 static void destroy(); … … 148 148 bool sliderMoved (const OIS::JoyStickEvent &arg, int id); 149 149 bool povMoved (const OIS::JoyStickEvent &arg, int id); 150 bool vector3Moved (const OIS::JoyStickEvent &arg, int id); 150 151 151 152 static InputManager& _getSingleton(); … … 156 157 OIS::Keyboard* keyboard_; //!< OIS mouse 157 158 OIS::Mouse* mouse_; //!< OIS keyboard 158 std:: map<int, OIS::JoyStick*>joySticks_; //!< OIS joy sticks159 std::vector<OIS::JoyStick*> joySticks_; //!< OIS joy sticks 159 160 160 161 InputState state_; … … 165 166 std::map<std::string, JoyStickHandler*> joyStickHandlers_; 166 167 167 std:: list<KeyHandler*>activeKeyHandlers_;168 std:: list<MouseHandler*>activeMouseHandlers_;169 std::map< int, std::list<JoyStickHandler*> > activeJoyStickHandlers_;168 std::vector<KeyHandler*> activeKeyHandlers_; 169 std::vector<MouseHandler*> activeMouseHandlers_; 170 std::map< OIS::JoyStick*, std::vector<JoyStickHandler*> > activeJoyStickHandlers_; 170 171 171 172 std::list<OIS::KeyCode> keysDown_; 172 173 std::list<OIS::MouseButtonID> mouseButtonsDown_; 173 std::map< int, std::list<int> >joyStickButtonsDown_;174 std::map< OIS::JoyStick*, std::list<int> > joyStickButtonsDown_; 174 175 175 176 }; -
code/branches/input/src/orxonox/Orxonox.cc
r1213 r1215 398 398 ogre_->getWindowWidth(), ogre_->getWindowHeight())) 399 399 abortImmediateForce(); 400 InputManager::setInputState(InputManager::IS_CUSTOM); 401 InputManager::enableKeyHandler("keybinder"); 402 InputManager::enableMouseHandler("keybinder"); 403 InputManager::enableJoyStickHandler("keybinder", 0); 400 InputManager::setInputState(InputManager::IS_NORMAL); 404 401 } 405 402 -
code/branches/input/src/orxonox/objects/SpaceShip.cc
r1213 r1215 431 431 { 432 432 InputManager::addMouseHandler(this, "SpaceShip"); 433 InputManager::enableMouseHandler("SpaceShip");434 433 setMouseEventCallback_ = true; 435 434 }
Note: See TracChangeset
for help on using the changeset viewer.