Changeset 1413 for code/branches/network/src/core/KeyBinder.cc
- Timestamp:
- May 24, 2008, 8:12:20 PM (16 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/core/KeyBinder.cc
r1412 r1413 32 32 */ 33 33 34 #include " InputHandler.h"34 #include "KeyBinder.h" 35 35 #include <fstream> 36 36 #include "util/Convert.h" … … 472 472 clearBindings(); 473 473 474 /*std::ifstream infile;474 std::ifstream infile; 475 475 infile.open("keybindings.ini"); 476 476 if (!infile.is_open()) 477 477 { 478 ConfigFileManager::getSingleton()->setFile(CFT_Keybindings, "keybindings_def.ini");479 setConfigValues();480 } 481 infile.close(); */478 ConfigFileManager::getSingleton()->setFile(CFT_Keybindings, keybindingsDefault_); 479 ConfigFileManager::getSingleton()->save(CFT_Keybindings, "keybindings.ini"); 480 } 481 infile.close(); 482 482 ConfigFileManager::getSingleton()->setFile(CFT_Keybindings, "keybindings.ini"); 483 484 // parse key bindings 483 485 setConfigValues(); 484 486 … … 496 498 SetConfigValue(derivePeriod_, 0.1f).description("Accuracy of the mouse input deriver. The higher the more precise, but laggier."); 497 499 SetConfigValue(mouseSensitivityDerived_, 1.0f).description("Mouse sensitivity if mouse input is derived."); 498 SetConfigValue(keybindingsDefault_, " keybindings_def.ini").description("Default ini file for the keybindings.");500 SetConfigValue(keybindingsDefault_, "def_keybindings.ini").description("Default ini file for the keybindings."); 499 501 500 502 float oldThresh = buttonThreshold_; … … 542 544 @brief Overwrites all bindings with "" 543 545 */ 544 void KeyBinder::clearBindings( bool bInit)546 void KeyBinder::clearBindings() 545 547 { 546 548 for (unsigned int i = 0; i < nKeys_s; i++) … … 561 563 } 562 564 563 void KeyBinder::tick (float dt)565 void KeyBinder::tickInput(float dt, const HandlerState& state) 564 566 { 565 567 // we have to process all the analog input since there is e.g. no 'mouseDoesntMove' event. 566 for (unsigned int i = 0; i < nHalfAxes_s; i++) 568 unsigned int iBegin = 8; 569 unsigned int iEnd = 8; 570 if (state.joyStick) 571 iEnd = nHalfAxes_s; 572 if (state.mouse) 573 iBegin = 0; 574 for (unsigned int i = iBegin; i < iEnd; i++) 567 575 { 568 576 if (halfAxes_[i].hasChanged_) … … 596 604 } 597 605 598 if (bDeriveMouseInput_ )606 if (bDeriveMouseInput_ && state.mouse) 599 607 { 600 608 if (deriveTime_ > derivePeriod_) 601 609 { 602 deriveTime_ = 0.0f;603 610 //CCOUT(3) << "mouse abs: "; 604 611 for (int i = 0; i < 2; i++) … … 606 613 if (mouseRelative_[i] > 0) 607 614 { 608 halfAxes_[2*i + 0].absVal_ = mouseRelative_[i] / derive Period_ / 5000* mouseSensitivityDerived_;615 halfAxes_[2*i + 0].absVal_ = mouseRelative_[i] / deriveTime_ * 0.0005 * mouseSensitivityDerived_; 609 616 halfAxes_[2*i + 1].absVal_ = 0.0f; 610 617 } … … 612 619 { 613 620 halfAxes_[2*i + 0].absVal_ = 0.0f; 614 halfAxes_[2*i + 1].absVal_ = -mouseRelative_[i] / derive Period_ / 5000* mouseSensitivityDerived_;621 halfAxes_[2*i + 1].absVal_ = -mouseRelative_[i] / deriveTime_ * 0.0005 * mouseSensitivityDerived_; 615 622 } 616 623 else … … 622 629 mouseRelative_[i] = 0; 623 630 } 631 deriveTime_ = 0.0f; 624 632 //COUT(3) << std::endl; 625 633 } … … 633 641 634 642 // always reset the relative movement of the mouse 635 for (unsigned int i = 0; i < 8; i++) 636 halfAxes_[i].relVal_ = 0.0f; 643 if (state.mouse) 644 for (unsigned int i = 0; i < 8; i++) 645 halfAxes_[i].relVal_ = 0.0f; 637 646 } 638 647 … … 784 793 785 794 // ############################### 786 // ### GUIInputHandler###795 // ##### KeyDetector ##### 787 796 // ############################### 788 797 789 ///** 790 // @brief standard constructor 791 //*/ 792 //GUIInputHandler::GUIInputHandler() 793 //{ 794 //} 795 796 ///** 797 // @brief Destructor 798 //*/ 799 //GUIInputHandler::~GUIInputHandler() 800 //{ 801 //} 802 803 ///** 804 // @brief Event handler for the keyPressed Event. 805 // @param e Event information 806 //*/ 807 //bool GUIInputHandler::keyPressed(const OIS::KeyEvent &e) 808 //{ 809 ////CEGUI::System::getSingleton().injectKeyDown( arg.key ); 810 ////CEGUI::System::getSingleton().injectChar( arg.text ); 811 // return true; 812 //} 813 814 ///** 815 // @brief Event handler for the keyReleased Event. 816 // @param e Event information 817 //*/ 818 //bool GUIInputHandler::keyReleased(const OIS::KeyEvent &e) 819 //{ 820 ////CEGUI::System::getSingleton().injectKeyUp( arg.key ); 821 // return true; 822 //} 823 824 ///** 825 // @brief Event handler for the mouseMoved Event. 826 // @param e Event information 827 //*/ 828 //bool GUIInputHandler::mouseMoved(const OIS::MouseEvent &e) 829 //{ 830 ////CEGUI::System::getSingleton().injectMouseMove( arg.state.X.rel, arg.state.Y.rel ); 831 // return true; 832 //} 833 834 ///** 835 // @brief Event handler for the mousePressed Event. 836 // @param e Event information 837 // @param id The ID of the mouse button 838 //*/ 839 //bool GUIInputHandler::mousePressed(const OIS::MouseEvent &e, OIS::MouseButton id) 840 //{ 841 ////CEGUI::System::getSingleton().injectMouseButtonDown(convertOISMouseButtonToCegui(id)); 842 // return true; 843 //} 844 845 ///** 846 // @brief Event handler for the mouseReleased Event. 847 // @param e Event information 848 // @param id The ID of the mouse button 849 //*/ 850 //bool GUIInputHandler::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButton id) 851 //{ 852 ////CEGUI::System::getSingleton().injectMouseButtonUp(convertOISMouseButtonToCegui(id)); 853 // return true; 854 //} 855 798 /** 799 @brief Constructor 800 */ 801 KeyDetector::KeyDetector() 802 { 803 RegisterObject(KeyDetector); 804 } 805 806 /** 807 @brief Destructor 808 */ 809 KeyDetector::~KeyDetector() 810 { 811 } 812 813 /** 814 @brief Loads the key and button bindings. 815 @return True if loading succeeded. 816 */ 817 void KeyDetector::loadBindings() 818 { 819 clearBindings(); 820 setConfigValues(); 821 } 822 823 /** 824 @brief Loader for the key bindings, managed by config values. 825 */ 826 void KeyDetector::setConfigValues() 827 { 828 // keys 829 for (unsigned int i = 0; i < nKeys_s; i++) 830 readTrigger(keys_[i]); 831 // mouse buttons 832 for (unsigned int i = 0; i < nMouseButtons_s; i++) 833 readTrigger(mouseButtons_[i]); 834 // joy stick buttons 835 for (unsigned int i = 0; i < nJoyStickButtons_s; i++) 836 readTrigger(joyStickButtons_[i]); 837 // half axes 838 for (unsigned int i = 0; i < nHalfAxes_s; i++) 839 readTrigger(halfAxes_[i]); 840 } 841 842 void KeyDetector::readTrigger(Button& button) 843 { 844 // binding has changed 845 button.parse(paramCommandBuffer_); 846 SimpleCommand* cmd = new SimpleCommand(); 847 cmd->evaluation_ = CommandExecutor::evaluate("storeKeyStroke " + button.name_); 848 button.commands_[KeybindMode::OnPress] = new BaseCommand*[1]; 849 button.commands_[KeybindMode::OnPress][0] = cmd; 850 button.nCommands_[KeybindMode::OnPress] = 1; 851 } 856 852 }
Note: See TracChangeset
for help on using the changeset viewer.