Changeset 1428
- Timestamp:
- May 26, 2008, 11:36:50 AM (17 years ago)
- Location:
- code/branches/network/src/core
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/core/ConfigValueIncludes.h
r1062 r1428 53 53 container##varname = new orxonox::ConfigValueContainer(CFT_Settings, this->getIdentifier(), #varname, varname = defvalue); \ 54 54 this->getIdentifier()->addConfigValueContainer(#varname, container##varname); \ 55 } \ 56 container##varname->getValue(&varname) 57 58 /** 59 @brief Assigns the value, defined in the config-file, to the variable (or the default-value, if there is no entry in the file). 60 @param classname name in which the config value should be stored 61 @param varname The name of the variable 62 @param defvalue The default-value of the variable 63 */ 64 #define SetConfigValueGeneric(classname, varname, defvalue) \ 65 orxonox::ConfigValueContainer* container##varname = ClassManager<classname>::getIdentifier()->getConfigValueContainer(#varname); \ 66 if (!container##varname) \ 67 { \ 68 container##varname = new orxonox::ConfigValueContainer(CFT_Settings, ClassManager<classname>::getIdentifier(), #varname, varname = defvalue); \ 69 ClassManager<classname>::getIdentifier()->addConfigValueContainer(#varname, container##varname); \ 55 70 } \ 56 71 container##varname->getValue(&varname) -
code/branches/network/src/core/InputManager.cc
r1426 r1428 371 371 } 372 372 373 void InputManager::_saveState() 374 { 375 savedHandlers_.activeHandlers_ = activeHandlers_; 376 savedHandlers_.activeJoyStickHandlers_ = activeJoyStickHandlers_; 377 savedHandlers_.activeKeyHandlers_ = activeKeyHandlers_; 378 savedHandlers_.activeMouseHandlers_ = activeMouseHandlers_; 379 } 380 381 void InputManager::_restoreState() 382 { 383 activeHandlers_ = savedHandlers_.activeHandlers_; 384 activeJoyStickHandlers_ = savedHandlers_.activeJoyStickHandlers_; 385 activeKeyHandlers_ = savedHandlers_.activeKeyHandlers_; 386 activeMouseHandlers_ = savedHandlers_.activeMouseHandlers_; 387 } 388 373 389 void InputManager::_updateTickables() 374 390 { … … 405 421 return; 406 422 407 // reset the game if it has changed408 423 if (state_ != stateRequest_) 409 424 { 410 425 if (stateRequest_ != IS_CUSTOM) 411 426 { 412 if (stateRequest_ != IS_ NODETECT && stateRequest_ != IS_DETECT)427 if (stateRequest_ != IS_DETECT) 413 428 { 414 429 activeKeyHandlers_.clear(); … … 439 454 case IS_DETECT: 440 455 savedState_ = state_; 456 _saveState(); 457 458 activeKeyHandlers_.clear(); 459 activeMouseHandlers_.clear(); 460 for (unsigned int i = 0; i < joySticksSize_; i++) 461 activeJoyStickHandlers_[i].clear(); 462 441 463 enableKeyHandler("keydetector"); 442 464 enableMouseHandler("keydetector"); … … 445 467 446 468 case IS_NODETECT: 447 disableKeyHandler("keydetector"); 448 disableMouseHandler("keydetector"); 449 disableJoyStickHandler("keydetector", 0); 469 _restoreState(); 450 470 break; 451 471 -
code/branches/network/src/core/InputManager.h
r1426 r1428 65 65 public: 66 66 IntVector2 sliderStates[4]; 67 }; 68 69 /** 70 * Struct for storing a custom input state 71 */ 72 struct StoredState 73 { 74 std::vector<KeyHandler*> activeKeyHandlers_; 75 std::vector<MouseHandler*> activeMouseHandlers_; 76 std::vector<std::vector<JoyStickHandler*> > activeJoyStickHandlers_; 77 std::vector<std::pair<InputTickable*, HandlerState> > activeHandlers_; 67 78 }; 68 79 … … 158 169 void _updateTickables(); 159 170 171 void _saveState(); 172 void _restoreState(); 173 160 174 void tick(float dt); 161 175 … … 191 205 unsigned int keyboardModifiers_; 192 206 InputState savedState_; 207 StoredState savedHandlers_; 193 208 194 209 //! Keeps track of the joy stick POV states -
code/branches/network/src/core/KeyBinder.cc
r1426 r1428 321 321 delete paramCommands_[i]; 322 322 delete[] paramCommands_; 323 nParamCommands_ = 0; 323 324 } 324 325 else … … 543 544 void KeyBinder::setConfigValues() 544 545 { 545 SetConfigValue(analogThreshold_, 0.01f) .description("Threshold for analog axes until which the state is 0."); 546 SetConfigValue(mouseSensitivity_, 1.0f) .description("Mouse sensitivity."); 547 SetConfigValue(bDeriveMouseInput_, false).description("Whether or not to derive moues movement for the absolute value."); 548 SetConfigValue(derivePeriod_, 0.5f).description("Accuracy of the mouse input deriver. The higher the more precise, but laggier."); 549 SetConfigValue(mouseSensitivityDerived_, 1.0f).description("Mouse sensitivity if mouse input is derived."); 546 SetConfigValueGeneric(KeyBinder, analogThreshold_, 0.01f) .description("Threshold for analog axes until which the state is 0."); 547 SetConfigValueGeneric(KeyBinder, mouseSensitivity_, 1.0f) .description("Mouse sensitivity."); 548 SetConfigValueGeneric(KeyBinder, bDeriveMouseInput_, false).description("Whether or not to derive moues movement for the absolute value."); 549 SetConfigValueGeneric(KeyBinder, derivePeriod_, 0.5f).description("Accuracy of the mouse input deriver. The higher the more precise, but laggier."); 550 SetConfigValueGeneric(KeyBinder, mouseSensitivityDerived_, 1.0f).description("Mouse sensitivity if mouse input is derived."); 551 SetConfigValueGeneric(KeyBinder, bClipMouse_, true).description("Whether or not to clip absolute value of mouse in non derive mode."); 550 552 551 553 float oldThresh = buttonThreshold_; 552 SetConfigValue (buttonThreshold_, 0.80f).description("Threshold for analog axes until which the button is not pressed.");554 SetConfigValueGeneric(KeyBinder, buttonThreshold_, 0.80f).description("Threshold for analog axes until which the button is not pressed."); 553 555 if (oldThresh != buttonThreshold_) 554 556 for (unsigned int i = 0; i < nHalfAxes_s; i++) … … 573 575 { 574 576 // config value stuff 575 ConfigValueContainer* cont = getIdentifier()->getConfigValueContainer(button.name_);577 ConfigValueContainer* cont = ClassManager<KeyBinder>::getIdentifier()->getConfigValueContainer(button.name_); 576 578 if (!cont) 577 579 { 578 cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), button.name_, "");579 getIdentifier()->addConfigValueContainer(button.name_, cont);580 cont = new ConfigValueContainer(CFT_Keybindings, ClassManager<KeyBinder>::getIdentifier(), button.name_, ""); 581 ClassManager<KeyBinder>::getIdentifier()->addConfigValueContainer(button.name_, cont); 580 582 } 581 583 std::string old = button.bindingString_; … … 585 587 if (old != button.bindingString_) 586 588 { 589 // clear everything so we don't get old axis ParamCommands mixed up 590 button.clear(); 591 587 592 // binding has changed 588 593 button.parse(paramCommandBuffer_); … … 678 683 //COUT(3) << mouseRelative_[i] << " | "; 679 684 mouseRelative_[i] = 0; 685 halfAxes_[2*i + 0].hasChanged_ = true; 686 halfAxes_[2*i + 1].hasChanged_ = true; 680 687 } 681 688 deriveTime_ = 0.0f; … … 731 738 void KeyBinder::mouseMoved(IntVector2 abs_, IntVector2 rel_, IntVector2 clippingSize) 732 739 { 740 // y axis of mouse input is inverted 741 int rel[] = { rel_.x, -rel_.y }; 742 733 743 if (!bDeriveMouseInput_) 734 744 { 735 // y axis of mouse input is inverted736 int rel[] = { rel_.x, -rel_.y };737 738 //COUT(3) << rel[0] << " | " << rel[1] << std::endl;739 740 745 for (int i = 0; i < 2; i++) 741 746 { … … 743 748 { 744 749 // absolute 750 halfAxes_[2*i + 0].hasChanged_ = true; 751 halfAxes_[2*i + 1].hasChanged_ = true; 752 mousePosition_[i] += rel[i]; 753 754 if (bClipMouse_) 755 { 756 if (mousePosition_[i] > 1024) 757 mousePosition_[i] = 1024; 758 if (mousePosition_[i] < -1024) 759 mousePosition_[i] = -1024; 760 } 761 745 762 if (mousePosition_[i] >= 0) 746 763 { 747 mousePosition_[i] += rel[i]; 748 halfAxes_[0 + 2*i].hasChanged_ = true; 749 if (mousePosition_[i] < 0) 750 { 751 halfAxes_[1 + 2*i].hasChanged_ = true; 752 halfAxes_[1 + 2*i].absVal_ = -((float)mousePosition_[i])/1024 * mouseSensitivity_; 753 halfAxes_[0 + 2*i].absVal_ = 0.0f; 754 } 755 else 756 halfAxes_[0 + 2*i].absVal_ = ((float)mousePosition_[i])/1024 * mouseSensitivity_; 764 halfAxes_[2*i + 0].absVal_ = mousePosition_[i]/1024.0f * mouseSensitivity_; 765 halfAxes_[2*i + 1].absVal_ = 0.0f; 757 766 } 758 767 else 759 768 { 760 mousePosition_[i] += rel[i]; 761 halfAxes_[1 + 2*i].hasChanged_ = true; 762 if (mousePosition_[i] > 0) 763 { 764 halfAxes_[0 + 2*i].hasChanged_ = true; 765 halfAxes_[0 + 2*i].absVal_ = ((float)mousePosition_[i])/1024 * mouseSensitivity_; 766 halfAxes_[1 + 2*i].absVal_ = 0.0f; 767 } 768 else 769 halfAxes_[1 + 2*i].absVal_ = -((float)mousePosition_[i])/1024 * mouseSensitivity_; 770 } 771 //COUT(3) << "half axis 0: " << halfAxes_[0].absVal_ << std::endl; 772 //COUT(3) << "half axis 1: " << halfAxes_[1].absVal_ << std::endl; 773 //COUT(3) << "half axis 2: " << halfAxes_[2].absVal_ << std::endl; 774 //COUT(3) << "half axis 3: " << halfAxes_[3].absVal_ << std::endl; 775 776 // relative 777 if (rel[i] > 0) 778 halfAxes_[0 + 2*i].relVal_ = ((float)rel[i])/1024 * mouseSensitivity_; 779 else 780 halfAxes_[1 + 2*i].relVal_ = -((float)rel[i])/1024 * mouseSensitivity_; 769 halfAxes_[2*i + 0].absVal_ = 0.0f; 770 halfAxes_[2*i + 1].absVal_ = -mousePosition_[i]/1024.0f * mouseSensitivity_; 771 } 781 772 } 782 773 } … … 784 775 else 785 776 { 786 mouseRelative_[0] += rel_.x; 787 mouseRelative_[1] -= rel_.y; 777 mouseRelative_[0] += rel[0]; 778 mouseRelative_[1] += rel[1]; 779 } 780 781 // relative 782 for (int i = 0; i < 2; i++) 783 { 784 if (rel[i] > 0) 785 halfAxes_[0 + 2*i].relVal_ = ((float)rel[i])/1024 * mouseSensitivity_; 786 else 787 halfAxes_[1 + 2*i].relVal_ = -((float)rel[i])/1024 * mouseSensitivity_; 788 788 } 789 789 } … … 871 871 } 872 872 873 /**874 @brief Loader for the key bindings, managed by config values.875 */876 void KeyDetector::setConfigValues()877 {878 // keys879 for (unsigned int i = 0; i < nKeys_s; i++)880 readTrigger(keys_[i]);881 // mouse buttons882 for (unsigned int i = 0; i < nMouseButtons_s; i++)883 readTrigger(mouseButtons_[i]);884 // joy stick buttons885 for (unsigned int i = 0; i < nJoyStickButtons_s; i++)886 readTrigger(joyStickButtons_[i]);887 // half axes888 for (unsigned int i = 0; i < nHalfAxes_s; i++)889 readTrigger(halfAxes_[i]);890 }891 892 873 void KeyDetector::readTrigger(Button& button) 893 874 { 894 // binding has changed895 button.parse(paramCommandBuffer_);896 875 SimpleCommand* cmd = new SimpleCommand(); 897 876 cmd->evaluation_ = CommandExecutor::evaluate("storeKeyStroke " + button.name_); -
code/branches/network/src/core/KeyBinder.h
r1426 r1428 150 150 void tickInput(float dt, const HandlerState& state); 151 151 152 v oid readTrigger(Button& button);152 virtual void readTrigger(Button& button); 153 153 154 154 void keyPressed (const KeyEvent& evt); … … 222 222 //! mouse sensitivity if mouse input is derived 223 223 float mouseSensitivityDerived_; 224 //! Whether or not to clip abslute mouse values to 1024 225 bool bClipMouse_; 224 226 }; 225 227 … … 231 233 ~KeyDetector(); 232 234 void loadBindings(); 233 void setConfigValues();234 235 235 236 protected:
Note: See TracChangeset
for help on using the changeset viewer.