Changeset 1637 for code/branches/input/src/core
- Timestamp:
- Jul 20, 2008, 6:49:24 PM (16 years ago)
- Location:
- code/branches/input/src/core
- Files:
-
- 5 added
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/input/src/core/CMakeLists.txt
r1629 r1637 41 41 input/Button.cc 42 42 input/CalibratorCallback.cc 43 input/ExtendedInputState.cc 43 44 input/HalfAxis.cc 44 45 input/InputBuffer.cc … … 47 48 input/KeyBinder.cc 48 49 input/KeyDetector.cc 50 input/SimpleInputState.cc 49 51 50 52 tolua/tolua_bind.cc -
code/branches/input/src/core/CorePrereqs.h
r1543 r1637 158 158 159 159 // input 160 //class GUIInputHandler;161 160 class BaseCommand; 162 161 class BufferedParamCommand; 163 162 class Button; 164 163 class CalibratorCallback; 164 class ExtendedInputState; 165 165 class HalfAxis; 166 166 class InputBuffer; 167 167 class InputManager; 168 class InputState; 168 169 class JoyStickHandler; 169 170 class MouseHandler; … … 173 174 class ParamCommand; 174 175 class SimpleCommand; 176 class SimpleInputState; 175 177 } 176 178 -
code/branches/input/src/core/Shell.cc
r1540 r1637 34 34 #include "ConsoleCommand.h" 35 35 #include "input/InputInterfaces.h" 36 #include "input/SimpleInputState.h" 37 #include "input/InputManager.h" 36 38 37 39 #define SHELL_UPDATE_LISTENERS(function) \ … … 57 59 this->clearLines(); 58 60 59 this->inputBuffer_ = 0; 60 this->setInputBuffer(new InputBuffer()); 61 this->inputBuffer_ = new InputBuffer(); 62 this->configureInputBuffer(); 63 InputManager::createSimpleInputState("console", 40)->setKeyHandler(this->inputBuffer_); 61 64 62 65 this->outputBuffer_.registerListener(this); 63 66 64 67 this->setConfigValues(); 68 } 69 70 Shell::~Shell() 71 { 72 SimpleInputState * inputState = dynamic_cast<SimpleInputState*>(InputManager::getState("console")); 73 if (inputState) 74 { 75 inputState->removeAndDestroyAllHandlers(); 76 InputManager::destroyState("console"); 77 } 65 78 } 66 79 … … 97 110 } 98 111 99 void Shell::setInputBuffer(InputBuffer* buffer) 100 { 101 if (this->inputBuffer_) 102 { 103 this->inputBuffer_->unregisterListener(this); 104 // TODO: may be very dangerous. InputManager already deletes InputBuffer instance!!! 105 delete this->inputBuffer_; 106 } 107 108 this->inputBuffer_ = buffer; 112 void Shell::configureInputBuffer() 113 { 109 114 this->inputBuffer_->registerListener(this, &Shell::inputChanged, true); 110 115 this->inputBuffer_->registerListener(this, &Shell::execute, '\r', false); -
code/branches/input/src/core/Shell.h
r1535 r1637 71 71 void unregisterListener(ShellListener* listener); 72 72 73 void setInputBuffer(InputBuffer* buffer);74 73 inline InputBuffer& getInputBuffer() 75 74 { return (*this->inputBuffer_); } … … 105 104 Shell(); 106 105 Shell(const Shell& other); 107 virtual ~Shell() {} 106 virtual ~Shell(); 107 108 void configureInputBuffer(); 108 109 109 110 void addToHistory(const std::string& command); -
code/branches/input/src/core/input/Button.cc
r1630 r1637 88 88 '\\', false, '"', false, '(', ')', false, '\0'); 89 89 90 unsigned int iToken = 0;91 92 // for real axes, we can feed a ButtonThreshold argument as entire command93 if (getLowercase(tokens[0]) == "buttonthreshold")94 {95 if (tokens.size() == 1)96 continue;97 // may fail, but doesn't matter98 convertValue(&buttonThreshold_, tokens[1]);99 continue;100 }101 102 // first argument can be OnPress, OnHold OnRelease or nothing103 90 KeybindMode::Enum mode = KeybindMode::None; 104 if (getLowercase(tokens[iToken]) == "onpress")105 mode = KeybindMode::OnPress, iToken++;106 if (getLowercase(tokens[iToken]) == "onrelease")107 mode = KeybindMode::OnRelease, iToken++;108 if (getLowercase(tokens[iToken]) == "onhold")109 mode = KeybindMode::OnHold, iToken++;110 111 if (iToken == tokens.size())112 continue;113 114 // second argument can be the amplitude for the case it as an axis command115 // default amplitude is 1.0f116 91 float paramModifier = 1.0f; 117 if (getLowercase(tokens[iToken]) == "scale") 118 { 119 iToken++; 120 if (iToken == tokens.size() || !convertValue(¶mModifier, tokens[iToken])) 121 { 122 COUT(2) << "Error while parsing key binding " << name_ 123 << ". Numeric expression expected afer 'AxisAmp', switching to default value" 124 << std::endl; 92 std::string commandStr = ""; 93 94 for (unsigned int iToken = 0; iToken < tokens.size(); ++iToken) 95 { 96 std::string token = getLowercase(tokens[iToken]); 97 98 if (token == "onpress") 99 mode = KeybindMode::OnPress; 100 else if (token == "onrelease") 101 mode = KeybindMode::OnRelease; 102 else if (token == "onhold") 103 mode = KeybindMode::OnHold; 104 else if (token == "buttonthreshold") 105 { 106 // for real axes, we can feed a ButtonThreshold argument 107 ++iToken; 125 108 if (iToken == tokens.size()) 126 109 continue; 127 } 128 iToken++; 129 } 130 131 // no more arguments expected except for the actual command 132 if (iToken == tokens.size()) 110 // may fail, but doesn't matter (default value already set) 111 if (!convertValue(&buttonThreshold_, tokens[iToken + 1])) 112 parseError("Could not parse 'ButtonThreshold' argument. \ 113 Switching to default value.", true); 114 } 115 else if (token == "scale") 116 { 117 ++iToken; 118 if (iToken == tokens.size() || !convertValue(¶mModifier, tokens[iToken])) 119 parseError("Could not parse 'scale' argument. Switching to default value.", true); 120 } 121 else 122 { 123 // no input related argument 124 // we interpret everything from here as a command string 125 while (iToken != tokens.size()) 126 commandStr += tokens[iToken++] + " "; 127 } 128 } 129 130 if (commandStr == "") 131 { 132 parseError("No command string given.", false); 133 133 continue; 134 135 std::string commandStr; 136 while (iToken != tokens.size()) 137 commandStr += tokens[iToken++] + " "; 134 } 138 135 139 136 // evaluate the command 140 137 CommandEvaluation eval = CommandExecutor::evaluate(commandStr); 141 138 if (!eval.isValid()) 139 { 140 parseError("Command evaluation failed.", true); 142 141 continue; 142 } 143 143 144 144 // check for param command … … 215 215 return true; 216 216 } 217 218 inline void Button::parseError(std::string message, bool serious) 219 { 220 if (serious) 221 { 222 COUT(2) << "Error while parsing binding for button/axis" << this->name_ << ". " 223 << message << std::endl; 224 } 225 else 226 { 227 COUT(3) << "Warning while parsing binding for button/axis" << this->name_ << ". " 228 << message << std::endl; 229 } 230 } 217 231 } -
code/branches/input/src/core/input/Button.h
r1630 r1637 64 64 //! Note: This variable is here to have only one parse() function. 65 65 float buttonThreshold_; 66 67 private: 68 void parseError(std::string message, bool serious); 66 69 }; 67 70 } -
code/branches/input/src/core/input/CalibratorCallback.cc
r1630 r1637 42 42 if (evt.key == KeyCode::Return) 43 43 { 44 InputManager::setInputState(InputManager::IS_NOCALIBRATE);44 //InputManager::setInputState(InputManager::IS_NOCALIBRATE); 45 45 } 46 46 } -
code/branches/input/src/core/input/CalibratorCallback.h
r1630 r1637 52 52 void keyHeld (const KeyEvent& evt) { } 53 53 54 void tickInput(float dt , const HandlerState &state) { }54 void tickInput(float dt) { } 55 55 }; 56 56 } -
code/branches/input/src/core/input/InputBuffer.cc
r1535 r1637 220 220 @param dt Delta time 221 221 */ 222 void InputBuffer::tickInput(float dt , const HandlerState& state)222 void InputBuffer::tickInput(float dt) 223 223 { 224 224 timeSinceKeyPressed_ += dt; -
code/branches/input/src/core/input/InputBuffer.h
r1535 r1637 170 170 void processKey (const KeyEvent &e); 171 171 172 void tickInput(float dt, const HandlerState& state); 172 void tickInput(float dt); 173 void tickInput(float dt, int device) { } 173 174 174 175 std::string buffer_; -
code/branches/input/src/core/input/InputInterfaces.h
r1630 r1637 38 38 #include "core/CorePrereqs.h" 39 39 40 #include " src/ois/OISKeyboard.h"41 #include " src/ois/OISMouse.h"42 #include " src/ois/OISJoyStick.h"40 #include "ois/OISKeyboard.h" 41 #include "ois/OISMouse.h" 42 #include "ois/OISJoyStick.h" 43 43 #include "util/Math.h" 44 44 … … 222 222 }; 223 223 } 224 225 namespace InputDevice 226 { 227 enum Enum 228 { 229 Keyboard, 230 Mouse, 231 JoyStick0, 232 JoyStick1, 233 JoyStick2, 234 JoyStick3, 235 // note: No problem if there are more joy sticks. This enum is just for convenience. 236 }; 237 } 224 238 225 239 struct _CoreExport Key … … 265 279 multiple handlers) are active. 266 280 */ 267 struct HandlerState268 {269 HandlerState() : key(false), mouse(false), joyStick(false) { }270 bool key;271 bool mouse;272 bool joyStick;273 };281 //struct HandlerState 282 //{ 283 // HandlerState() : keyboard(false), mouse(false) { } 284 // bool keyboard; 285 // bool mouse; 286 // std::vector<bool> joySticks; 287 //}; 274 288 275 289 class _CoreExport InputTickable … … 277 291 public: 278 292 virtual ~InputTickable() { } 279 virtual void tickInput(float dt, const HandlerState& state) = 0; 293 virtual void tickInput(float dt) = 0; 294 //virtual void tickInput(float dt, unsigned int device) = 0; 280 295 }; 281 296 … … 291 306 virtual void keyReleased(const KeyEvent& evt) = 0; 292 307 virtual void keyHeld (const KeyEvent& evt) = 0; 293 //virtual void tickKey (float dt) { }308 virtual void tickKey (float dt) { } 294 309 }; 295 310 … … 307 322 virtual void mouseMoved (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) = 0; 308 323 virtual void mouseScrolled (int abs, int rel) = 0; 309 //virtual void tickMouse (float dt) { }324 virtual void tickMouse (float dt) { } 310 325 }; 311 326 … … 319 334 public: 320 335 virtual ~JoyStickHandler() { } 321 virtual void joyStickButtonPressed (int joyStickID, int button) = 0; 322 virtual void joyStickButtonReleased(int joyStickID, int button) = 0; 323 virtual void joyStickButtonHeld (int joyStickID, int button) = 0; 324 virtual void joyStickAxisMoved (int joyStickID, int axis, float value) = 0; 325 //virtual bool joyStickVector3Moved (int joyStickID, int index /*, fill list*/) {return true;} 326 //virtual void tickJoyStick (float dt) { } 336 virtual void joyStickButtonPressed (unsigned int joyStickID, unsigned int button) = 0; 337 virtual void joyStickButtonReleased(unsigned int joyStickID, unsigned int button) = 0; 338 virtual void joyStickButtonHeld (unsigned int joyStickID, unsigned int button) = 0; 339 virtual void joyStickAxisMoved (unsigned int joyStickID, unsigned int axis, float value) = 0; 340 //virtual bool joyStickVector3Moved (unsigned int joyStickID, unsigned int index /*, fill list*/) {return true;} 341 virtual void tickJoyStick (float dt, unsigned int device) { } 342 }; 343 344 class _CoreExport EmptyHandler : public KeyHandler, public MouseHandler, public JoyStickHandler 345 { 346 private: 347 void tickInput(float dt) { } 348 void tickInput(float dt, unsigned int device) { } 349 350 void keyPressed (const KeyEvent& evt) { } 351 void keyReleased(const KeyEvent& evt) { } 352 void keyHeld (const KeyEvent& evt) { } 353 354 void mouseButtonPressed (MouseButton::Enum id) { } 355 void mouseButtonReleased(MouseButton::Enum id) { } 356 void mouseButtonHeld (MouseButton::Enum id) { } 357 void mouseMoved (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) { } 358 void mouseScrolled (int abs, int rel) { } 359 360 void joyStickButtonPressed (unsigned int joyStickID, unsigned int button) { } 361 void joyStickButtonReleased(unsigned int joyStickID, unsigned int button) { } 362 void joyStickButtonHeld (unsigned int joyStickID, unsigned int button) { } 363 void joyStickAxisMoved (unsigned int joyStickID, unsigned int axis, float value) { } 327 364 }; 328 365 -
code/branches/input/src/core/input/InputManager.cc
r1630 r1637 38 38 #include <limits.h> 39 39 40 #include "ois/OISException.h" 41 #include "ois/OISInputManager.h" 42 40 43 #include "core/CoreIncludes.h" 41 44 #include "core/ConfigValueIncludes.h" … … 43 46 #include "core/CommandExecutor.h" 44 47 #include "core/ConsoleCommand.h" 45 #include "core/Shell.h" // hack!46 48 47 49 #include "InputBuffer.h" … … 49 51 #include "KeyDetector.h" 50 52 #include "CalibratorCallback.h" 51 52 #include " src/ois/OISException.h"53 #include " src/ois/OISInputManager.h"53 #include "InputState.h" 54 #include "SimpleInputState.h" 55 #include "ExtendedInputState.h" 54 56 55 57 namespace orxonox … … 59 61 SetConsoleCommandShortcut(InputManager, calibrate); 60 62 63 using namespace InputDevice; 64 61 65 // ############################### 62 66 // ### Internal Methods ### … … 74 78 , mouse_(0) 75 79 , joySticksSize_(0) 76 , keyBinder_(0) 77 , keyDetector_(0) 78 , buffer_(0) 79 , calibratorCallback_(0) 80 , state_(IS_UNINIT) 81 , stateRequest_(IS_UNINIT) 82 , savedState_(IS_UNINIT) 80 , devicesNum_(0) 81 , stateDetector_(0) 82 , stateCalibrator_(0) 83 , stateEmpty_(0) 83 84 , keyboardModifiers_(0) 85 , bCalibrating_(false) 84 86 { 85 87 RegisterRootObject(InputManager); … … 92 94 A reference to the only instance of the InputManager 93 95 */ 94 InputManager& InputManager::_get Singleton()96 InputManager& InputManager::_getInstance() 95 97 { 96 98 static InputManager theOnlyInstance; … … 106 108 _destroy(); 107 109 } 110 111 112 // ############################################################ 113 // ##### Initialisation ##### 114 // ########## ########## 115 // ############################################################ 108 116 109 117 /** … … 121 129 bool createKeyboard, bool createMouse, bool createJoySticks) 122 130 { 123 if ( state_ == IS_UNINIT)131 if (inputSystem_ == 0) 124 132 { 125 133 CCOUT(3) << "Initialising Input System..." << std::endl; … … 160 168 _initialiseJoySticks(); 161 169 170 // set all the std::vector list sizes now that the devices have been created 171 _redimensionLists(); 172 162 173 // Set mouse/joystick region 163 174 if (mouse_) … … 166 177 } 167 178 168 state_ = IS_NONE;169 179 CCOUT(ORX_DEBUG) << "Initialising OIS components done." << std::endl; 170 180 171 181 // InputManager holds the input buffer --> create one and add it. 172 buffer_ = new InputBuffer(); 173 addKeyHandler(buffer_, "buffer"); 174 Shell::getInstance().setInputBuffer(buffer_); 175 176 keyBinder_ = new KeyBinder(); 177 keyBinder_->loadBindings(); 178 addKeyHandler(keyBinder_, "keybinder"); 179 addMouseHandler(keyBinder_, "keybinder"); 180 addJoyStickHandler(keyBinder_, "keybinder"); 181 182 keyDetector_ = new KeyDetector(); 183 keyDetector_->loadBindings(); 184 addKeyHandler(keyDetector_, "keydetector"); 185 addMouseHandler(keyDetector_, "keydetector"); 186 addJoyStickHandler(keyDetector_, "keydetector"); 187 188 calibratorCallback_ = new CalibratorCallback(); 189 addKeyHandler(calibratorCallback_, "calibratorcallback"); 182 //buffer_ = new InputBuffer(); 183 //addKeyHandler(buffer_, "buffer"); 184 //Shell::getInstance().setInputBuffer(buffer_); 190 185 191 186 setConfigValues(); 187 188 stateEmpty_ = createSimpleInputState("empty", -1); 189 stateEmpty_->setHandler(new EmptyHandler()); 190 activeStates_[stateEmpty_->getPriority()] = stateEmpty_; 191 192 stateDetector_ = createSimpleInputState("detector", 101); 193 KeyDetector* temp = new KeyDetector(); 194 temp->loadBindings("storeKeyStroke"); 195 stateDetector_->setHandler(temp); 196 197 stateCalibrator_ = createSimpleInputState("calibrator", 100); 198 stateCalibrator_->setHandler(new EmptyHandler()); 199 InputBuffer* buffer = new InputBuffer(); 200 buffer->registerListener(this, &InputManager::_completeCalibration, '\r', true); 201 stateCalibrator_->setKeyHandler(buffer); 202 203 _updateActiveStates(); 192 204 193 205 CCOUT(ORX_DEBUG) << "Initialising complete." << std::endl; … … 232 244 catch (OIS::Exception ex) 233 245 { 234 // TODO: Test this output regarding formatting235 246 CCOUT(ORX_WARNING) << "Warning: Failed to create an OIS keyboard\n" 236 247 << "OIS error message: \"" << ex.eText << "\"" << std::endl; … … 300 311 OIS::JoyStick* stig = static_cast<OIS::JoyStick*> 301 312 (inputSystem_->createInputObject(OIS::OISJoyStick, true)); 313 CCOUT(ORX_DEBUG) << "Created OIS joy stick with ID " << stig->getID() << std::endl; 302 314 joySticks_.push_back(stig); 303 315 // register our listener in OIS. 304 316 stig->setEventCallback(this); 305 CCOUT(ORX_DEBUG) << "Created OIS joy stick with ID " << stig->getID() << std::endl;306 317 success = true; 307 318 } … … 318 329 return false; 319 330 } 331 return success; 332 } 333 334 void InputManager::_redimensionLists() 335 { 320 336 joySticksSize_ = joySticks_.size(); 321 activeJoyStickHandlers_.resize(joySticksSize_);322 joyStickButtonsDown_ .resize(joySticksSize_);323 povStates_ .resize(joySticksSize_);324 sliderStates_ .resize(joySticksSize_);337 devicesNum_ = 2 + joySticksSize_; 338 joyStickButtonsDown_ .resize(joySticksSize_); 339 povStates_ .resize(joySticksSize_); 340 sliderStates_ .resize(joySticksSize_); 325 341 joySticksCalibration_.resize(joySticksSize_); 342 326 343 for (unsigned int iJoyStick = 0; iJoyStick < joySticksSize_; iJoyStick++) 327 344 { … … 334 351 } 335 352 } 336 return success; 353 354 // state management 355 activeStatesTop_.resize(devicesNum_); 356 357 // inform all registered states 358 for (std::map<int, InputState*>::const_iterator it = inputStatesByPriority_.begin(); 359 it != inputStatesByPriority_.end(); ++it) 360 (*it).second->setNumOfJoySticks(joySticksSize_); 337 361 } 338 362 … … 392 416 } 393 417 418 419 // ############################################################ 420 // ##### Destruction ##### 421 // ########## ########## 422 // ############################################################ 423 394 424 /** 395 425 @brief … … 398 428 void InputManager::_destroy() 399 429 { 400 if ( state_ != IS_UNINIT)430 if (inputSystem_) 401 431 { 402 432 CCOUT(ORX_DEBUG) << "Destroying ..." << std::endl; 403 433 404 if (buffer_) 405 delete buffer_; 406 407 if (keyBinder_) 408 delete keyBinder_; 409 410 if (keyDetector_) 411 delete keyDetector_; 412 413 if (calibratorCallback_) 414 delete calibratorCallback_; 415 416 keyHandlers_.clear(); 417 mouseHandlers_.clear(); 418 joyStickHandlers_.clear(); 419 434 // kick all active states 'nicely' 435 for (std::map<int, InputState*>::reverse_iterator rit = activeStates_.rbegin(); 436 rit != activeStates_.rend(); ++rit) 437 (*rit).second->onLeave(); 438 activeStates_.clear(); 439 440 // destroy our own states 441 stateEmpty_->removeAndDestroyAllHandlers(); 442 stateCalibrator_->removeAndDestroyAllHandlers(); 443 stateDetector_->removeAndDestroyAllHandlers(); 444 _destroyState(stateEmpty_); 445 _destroyState(stateCalibrator_); 446 _destroyState(stateDetector_); 447 stateEmpty_ = 0; 448 stateCalibrator_ = 0; 449 stateDetector_ = 0; 450 451 // we don't remove the other states yet because the singleton might still exist. 452 // So people can still removeAndDestroy their states 453 //inputStatesByName_.clear(); 454 //inputStatesByPriority_.clear(); 455 456 // destroy the devices 420 457 _destroyKeyboard(); 421 458 _destroyMouse(); 422 459 _destroyJoySticks(); 423 460 424 activeHandlers_.clear(); 425 426 // inputSystem_ can never be 0, or else the code is mistaken 461 _redimensionLists(); 462 427 463 OIS::InputManager::destroyInputSystem(inputSystem_); 428 464 inputSystem_ = 0; 429 465 430 state_ = IS_UNINIT;431 466 CCOUT(ORX_DEBUG) << "Destroying done." << std::endl; 432 467 } … … 442 477 inputSystem_->destroyInputObject(keyboard_); 443 478 keyboard_ = 0; 444 activeKeyHandlers_.clear();445 479 keysDown_.clear(); 446 480 CCOUT(ORX_DEBUG) << "Keyboard destroyed." << std::endl; … … 456 490 inputSystem_->destroyInputObject(mouse_); 457 491 mouse_ = 0; 458 activeMouseHandlers_.clear();459 492 mouseButtonsDown_.clear(); 460 493 CCOUT(ORX_DEBUG) << "Mouse destroyed." << std::endl; … … 475 508 476 509 joySticks_.clear(); 477 joySticksSize_ = 0;478 activeJoyStickHandlers_.clear();479 joyStickButtonsDown_.clear();480 povStates_.clear();481 sliderStates_.clear();482 joySticksCalibration_.clear();483 510 } 484 511 CCOUT(ORX_DEBUG) << "Joy sticks destroyed." << std::endl; 485 512 } 486 513 487 void InputManager::_saveState() 488 { 489 savedHandlers_.activeHandlers_ = activeHandlers_; 490 savedHandlers_.activeJoyStickHandlers_ = activeJoyStickHandlers_; 491 savedHandlers_.activeKeyHandlers_ = activeKeyHandlers_; 492 savedHandlers_.activeMouseHandlers_ = activeMouseHandlers_; 493 } 494 495 void InputManager::_restoreState() 496 { 497 activeHandlers_ = savedHandlers_.activeHandlers_; 498 activeJoyStickHandlers_ = savedHandlers_.activeJoyStickHandlers_; 499 activeKeyHandlers_ = savedHandlers_.activeKeyHandlers_; 500 activeMouseHandlers_ = savedHandlers_.activeMouseHandlers_; 501 } 502 503 void InputManager::_updateTickables() 504 { 505 // we can use a map to have a list of unique pointers (an object can implement all 3 handlers) 506 std::map<InputTickable*, HandlerState> tempSet; 507 for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++) 508 tempSet[activeKeyHandlers_[iHandler]].joyStick = true; 509 for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++) 510 tempSet[activeMouseHandlers_[iHandler]].mouse = true; 511 for (unsigned int iJoyStick = 0; iJoyStick < joySticksSize_; iJoyStick++) 512 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 513 tempSet[activeJoyStickHandlers_[iJoyStick][iHandler]].joyStick = true; 514 515 // copy the content of the map back to the actual vector 516 activeHandlers_.clear(); 517 for (std::map<InputTickable*, HandlerState>::const_iterator itHandler = tempSet.begin(); 518 itHandler != tempSet.end(); itHandler++) 519 activeHandlers_.push_back(std::pair<InputTickable*, HandlerState>((*itHandler).first, (*itHandler).second)); 520 } 521 522 523 // ################################# 524 // ### Private Interface Methods ### 525 // ################################# 526 // ################################# 527 528 /** 529 @brief 530 Updates the InputManager. Tick is called by Orxonox. 514 void InputManager::_destroyState(InputState* state) 515 { 516 assert(state); 517 inputStatesByPriority_.erase(state->getPriority()); 518 inputStatesByName_.erase(state->getName()); 519 delete state; 520 } 521 522 523 // ############################################################ 524 // ##### Runtime Methods ##### 525 // ########## ########## 526 // ############################################################ 527 528 /** 529 @brief 530 Updates the InputManager. Tick is called by the Core class. 531 531 @param dt 532 532 Delta time … … 534 534 void InputManager::_tick(float dt) 535 535 { 536 if ( state_ == IS_UNINIT)536 if (inputSystem_ == 0) 537 537 return; 538 538 539 if (state_ != stateRequest_) 540 { 541 InputState sr = stateRequest_; 542 switch (sr) 543 { 544 case IS_NORMAL: 545 activeKeyHandlers_.clear(); 546 activeMouseHandlers_.clear(); 547 for (unsigned int i = 0; i < joySticksSize_; i++) 548 activeJoyStickHandlers_[i].clear(); 549 550 // normal play mode 551 // note: we assume that the handlers exist since otherwise, something's wrong anyway. 552 enableKeyHandler("keybinder"); 553 enableMouseHandler("keybinder"); 554 enableJoyStickHandler("keybinder", 0); 555 stateRequest_ = IS_NORMAL; 556 state_ = IS_NORMAL; 557 break; 558 559 case IS_GUI: 560 state_ = IS_GUI; 561 break; 562 563 case IS_CONSOLE: 564 activeKeyHandlers_.clear(); 565 activeMouseHandlers_.clear(); 566 for (unsigned int i = 0; i < joySticksSize_; i++) 567 activeJoyStickHandlers_[i].clear(); 568 569 enableMouseHandler("keybinder"); 570 enableJoyStickHandler("keybinder", 0); 571 enableKeyHandler("buffer"); 572 stateRequest_ = IS_CONSOLE; 573 state_ = IS_CONSOLE; 574 break; 575 576 case IS_DETECT: 577 savedState_ = state_; 578 _saveState(); 579 580 activeKeyHandlers_.clear(); 581 activeMouseHandlers_.clear(); 582 for (unsigned int i = 0; i < joySticksSize_; i++) 583 activeJoyStickHandlers_[i].clear(); 584 585 enableKeyHandler("keydetector"); 586 enableMouseHandler("keydetector"); 587 enableJoyStickHandler("keydetector", 0); 588 589 stateRequest_ = IS_DETECT; 590 state_ = IS_DETECT; 591 break; 592 593 case IS_NODETECT: 594 _restoreState(); 595 keysDown_.clear(); 596 mouseButtonsDown_.clear(); 597 for (unsigned int i = 0; i < joySticksSize_; i++) 598 joyStickButtonsDown_[i].clear(); 599 state_ = IS_NODETECT; 600 stateRequest_ = savedState_; 601 break; 602 603 case IS_CALIBRATE: 604 if (joySticksSize_) 605 { 606 savedState_ = _getSingleton().state_; 607 for (unsigned int i = 0; i < 24; i++) 608 { 609 marginalsMax_[i] = INT_MIN; 610 marginalsMin_[i] = INT_MAX; 611 } 612 COUT(0) << "Move all joy stick axes in all directions a few times. " 613 << "Then put all axes in zero state and hit enter." << std::endl; 614 615 savedState_ = state_; 616 _saveState(); 617 618 activeKeyHandlers_.clear(); 619 activeMouseHandlers_.clear(); 620 for (unsigned int i = 0; i < joySticksSize_; i++) 621 activeJoyStickHandlers_[i].clear(); 622 623 enableKeyHandler("calibratorcallback"); 624 stateRequest_ = IS_CALIBRATE; 625 state_ = IS_CALIBRATE; 626 } 627 else 628 { 629 COUT(3) << "Connot calibrate, no joy stick found!" << std::endl; 630 stateRequest_ = state_; 631 } 632 break; 633 634 case IS_NOCALIBRATE: 635 _completeCalibration(); 636 _restoreState(); 637 keyBinder_->resetJoyStickAxes(); 638 state_ = IS_NOCALIBRATE; 639 stateRequest_ = savedState_; 640 break; 641 642 case IS_NONE: 643 activeKeyHandlers_.clear(); 644 activeMouseHandlers_.clear(); 645 for (unsigned int i = 0; i < joySticksSize_; i++) 646 activeJoyStickHandlers_[i].clear(); 647 state_ = IS_NONE; 648 649 default: 650 break; 651 } 539 // check for states to leave (don't use unsigned int!) 540 for (int i = stateLeaveRequests_.size() - 1; i >= 0; --i) 541 { 542 stateLeaveRequests_[i]->onLeave(); 543 // just to be sure that the state actually is registered 544 assert(inputStatesByName_.find(stateLeaveRequests_[i]->getName()) != inputStatesByName_.end()); 545 546 activeStates_.erase(stateLeaveRequests_[i]->getPriority()); 547 _updateActiveStates(); 548 stateLeaveRequests_.pop_back(); 549 } 550 551 552 // check for states to enter (don't use unsigned int!) 553 for (int i = stateEnterRequests_.size() - 1; i >= 0; --i) 554 { 555 // just to be sure that the state actually is registered 556 assert(inputStatesByName_.find(stateEnterRequests_[i]->getName()) != inputStatesByName_.end()); 557 558 activeStates_[stateEnterRequests_[i]->getPriority()] = stateEnterRequests_[i]; 559 _updateActiveStates(); 560 stateEnterRequests_[i]->onEnter(); 561 stateEnterRequests_.pop_back(); 652 562 } 653 563 654 564 // Capture all the input. This calls the event handlers in InputManager. 565 if (keyboard_) 566 keyboard_->capture(); 655 567 if (mouse_) 656 568 mouse_->capture(); 657 if (keyboard_)658 keyboard_->capture();659 569 for (unsigned int i = 0; i < joySticksSize_; i++) 660 570 joySticks_[i]->capture(); 661 571 662 if ( state_ != IS_CALIBRATE)572 if (!bCalibrating_) 663 573 { 664 574 // call all the handlers for the held key events 665 575 for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++) 666 for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++) 667 activeKeyHandlers_[iHandler]->keyHeld(KeyEvent(keysDown_[iKey], keyboardModifiers_)); 576 activeStatesTop_[Keyboard]->keyHeld(KeyEvent(keysDown_[iKey], keyboardModifiers_)); 668 577 669 578 // call all the handlers for the held mouse button events 670 579 for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++) 671 for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++) 672 activeMouseHandlers_[iHandler]->mouseButtonHeld(mouseButtonsDown_[iButton]); 580 activeStatesTop_[Mouse]->mouseButtonHeld(mouseButtonsDown_[iButton]); 673 581 674 582 // call all the handlers for the held joy stick button events 675 583 for (unsigned int iJoyStick = 0; iJoyStick < joySticksSize_; iJoyStick++) 676 584 for (unsigned int iButton = 0; iButton < joyStickButtonsDown_[iJoyStick].size(); iButton++) 677 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 678 { 679 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonHeld( 680 iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]); 681 } 682 } 683 684 // call the ticks for the handlers (need to be treated specially) 685 for (unsigned int iHandler = 0; iHandler < activeHandlers_.size(); iHandler++) 686 activeHandlers_[iHandler].first->tickInput(dt, activeHandlers_[iHandler].second); 585 activeStatesTop_[JoyStick0 + iJoyStick] 586 ->joyStickButtonHeld(iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]); 587 588 // tick the handlers for each active handler 589 for (unsigned int i = 0; i < devicesNum_; ++i) 590 activeStatesTop_[i]->tickInput(dt, i); 591 592 // tick the handler with a general tick afterwards 593 for (unsigned int i = 0; i < activeStatesTicked_.size(); ++i) 594 activeStatesTicked_[i]->tickInput(dt); 595 } 596 } 597 598 void InputManager::_updateActiveStates() 599 { 600 for (std::map<int, InputState*>::const_iterator it = activeStates_.begin(); it != activeStates_.end(); ++it) 601 for (unsigned int i = 0; i < devicesNum_; ++i) 602 if ((*it).second->isInputDeviceEnabled(i)) 603 activeStatesTop_[i] = (*it).second; 604 605 // update tickables (every state will only appear once) 606 // Using a std::set to avoid duplicates 607 std::set<InputState*> tempSet; 608 for (unsigned int i = 0; i < devicesNum_; ++i) 609 tempSet.insert(activeStatesTop_[i]); 610 611 // copy the content of the set back to the actual vector 612 activeStatesTicked_.clear(); 613 for (std::set<InputState*>::const_iterator it = tempSet.begin();it != tempSet.end(); ++it) 614 activeStatesTicked_.push_back(*it); 687 615 } 688 616 … … 744 672 cont->set(i, joySticksCalibration_[0].zeroStates[i]); 745 673 } 746 } 674 675 // restore old input state 676 requestLeaveState("calibrator"); 677 } 678 679 680 // ############################################################ 681 // ##### OIS events ##### 682 // ########## ########## 683 // ############################################################ 747 684 748 685 // ###### Key Events ###### … … 771 708 keyboardModifiers_ |= KeyboardModifier::Shift; // shift key 772 709 773 for (unsigned int i = 0; i < activeKeyHandlers_.size(); i++) 774 activeKeyHandlers_[i]->keyPressed(KeyEvent(e, keyboardModifiers_)); 710 activeStatesTop_[Keyboard]->keyPressed(KeyEvent(e, keyboardModifiers_)); 775 711 776 712 return true; … … 803 739 keyboardModifiers_ &= ~KeyboardModifier::Shift; // shift key 804 740 805 for (unsigned int i = 0; i < activeKeyHandlers_.size(); i++) 806 activeKeyHandlers_[i]->keyReleased(KeyEvent(e, keyboardModifiers_)); 741 activeStatesTop_[Keyboard]->keyReleased(KeyEvent(e, keyboardModifiers_)); 807 742 808 743 return true; … … 823 758 if (e.state.X.rel != 0 || e.state.Y.rel != 0) 824 759 { 825 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 826 { 827 activeMouseHandlers_[i]->mouseMoved(IntVector2(e.state.X.abs, e.state.Y.abs), 760 activeStatesTop_[Mouse]->mouseMoved(IntVector2(e.state.X.abs, e.state.Y.abs), 828 761 IntVector2(e.state.X.rel, e.state.Y.rel), IntVector2(e.state.width, e.state.height)); 829 }830 762 } 831 763 … … 833 765 if (e.state.Z.rel != 0) 834 766 { 835 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 836 activeMouseHandlers_[i]->mouseScrolled(e.state.Z.abs, e.state.Z.rel); 767 activeStatesTop_[Mouse]->mouseScrolled(e.state.Z.abs, e.state.Z.rel); 837 768 } 838 769 … … 857 788 mouseButtonsDown_.push_back((MouseButton::Enum)id); 858 789 859 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 860 activeMouseHandlers_[i]->mouseButtonPressed((MouseButton::Enum)id); 790 activeStatesTop_[Mouse]->mouseButtonPressed((MouseButton::Enum)id); 861 791 862 792 return true; … … 883 813 } 884 814 885 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 886 activeMouseHandlers_[i]->mouseButtonReleased((MouseButton::Enum)id); 815 activeStatesTop_[Mouse]->mouseButtonReleased((MouseButton::Enum)id); 887 816 888 817 return true; … … 898 827 unsigned int iJoyStick = 0; 899 828 while (joySticks_[iJoyStick] != joyStick) 900 {901 829 iJoyStick++; 902 if (iJoyStick == joySticksSize_) 903 { 904 CCOUT(3) << "Unknown joystick fired an event. This means there is a bug somewhere! Aborting." << std::endl; 905 abort(); 906 } 907 } 830 // assert: Unknown joystick fired an event. 831 assert(iJoyStick != joySticksSize_); 908 832 return iJoyStick; 909 833 } … … 921 845 buttonsDown.push_back(button); 922 846 923 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 924 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonPressed(iJoyStick, button); 847 activeStatesTop_[2 + iJoyStick]->joyStickButtonPressed(iJoyStick, button); 925 848 926 849 return true; … … 942 865 } 943 866 944 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 945 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonReleased(iJoyStick, button); 867 activeStatesTop_[2 + iJoyStick]->joyStickButtonReleased(iJoyStick, button); 946 868 947 869 return true; … … 950 872 void InputManager::_fireAxis(unsigned int iJoyStick, int axis, int value) 951 873 { 952 if ( state_ == IS_CALIBRATE)874 if (bCalibrating_) 953 875 { 954 876 if (value > marginalsMax_[axis]) … … 965 887 fValue *= joySticksCalibration_[iJoyStick].negativeCoeff[axis]; 966 888 967 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 968 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, axis, fValue); 889 activeStatesTop_[2 + iJoyStick]->joyStickAxisMoved(iJoyStick, axis, fValue); 969 890 } 970 891 } … … 972 893 bool InputManager::axisMoved(const OIS::JoyStickEvent &arg, int axis) 973 894 { 974 //if (arg.state.mAxes[axis].abs > 10000 || arg.state.mAxes[axis].abs < -10000)975 //{ CCOUT(3) << "axis " << axis << " moved" << arg.state.mAxes[axis].abs << std::endl;}976 977 895 unsigned int iJoyStick = _getJoystick(arg); 978 896 … … 985 903 bool InputManager::sliderMoved(const OIS::JoyStickEvent &arg, int id) 986 904 { 987 //if (arg.state.mSliders[id].abX > 10000 || arg.state.mSliders[id].abX < -10000)988 //{CCOUT(3) << "slider " << id << " moved" << arg.state.mSliders[id].abX << std::endl;}989 //CCOUT(3) << arg.state.mSliders[id].abX << "\t |" << arg.state.mSliders[id].abY << std::endl;990 991 905 unsigned int iJoyStick = _getJoystick(arg); 992 906 … … 1029 943 } 1030 944 1031 /*bool InputManager::vector3Moved(const OIS::JoyStickEvent &arg, int id) 1032 { 1033 unsigned int iJoyStick = _getJoystick(arg); 1034 1035 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 1036 { 1037 activeJoyStickHandlers_[iJoyStick][iHandler] 1038 ->joyStickVector3Moved(JoyStickState(arg.state, iJoyStick), id); 1039 } 1040 1041 return true; 1042 }*/ 1043 1044 1045 // ################################ 1046 // ### Static Interface Methods ### 1047 // ################################ 1048 // ################################ 945 946 // ############################################################ 947 // ##### Static Interface Methods ##### 948 // ########## ########## 949 // ############################################################ 1049 950 1050 951 std::string InputManager::bindingCommmandString_s = ""; … … 1053 954 bool createKeyboard, bool createMouse, bool createJoySticks) 1054 955 { 1055 return _get Singleton()._initialise(windowHnd, windowWidth, windowHeight,956 return _getInstance()._initialise(windowHnd, windowWidth, windowHeight, 1056 957 createKeyboard, createMouse, createJoySticks); 1057 958 } … … 1059 960 bool InputManager::initialiseKeyboard() 1060 961 { 1061 return _get Singleton()._initialiseKeyboard();962 return _getInstance()._initialiseKeyboard(); 1062 963 } 1063 964 1064 965 bool InputManager::initialiseMouse() 1065 966 { 1066 return _get Singleton()._initialiseMouse();967 return _getInstance()._initialiseMouse(); 1067 968 } 1068 969 1069 970 bool InputManager::initialiseJoySticks() 1070 971 { 1071 return _get Singleton()._initialiseJoySticks();972 return _getInstance()._initialiseJoySticks(); 1072 973 } 1073 974 1074 975 int InputManager::numberOfKeyboards() 1075 976 { 1076 if (_get Singleton().keyboard_ != 0)977 if (_getInstance().keyboard_ != 0) 1077 978 return 1; 1078 979 else … … 1082 983 int InputManager::numberOfMice() 1083 984 { 1084 if (_get Singleton().mouse_ != 0)985 if (_getInstance().mouse_ != 0) 1085 986 return 1; 1086 987 else … … 1090 991 int InputManager::numberOfJoySticks() 1091 992 { 1092 return _get Singleton().joySticksSize_;993 return _getInstance().joySticksSize_; 1093 994 } 1094 995 1095 996 /*bool InputManager::isKeyDown(KeyCode::Enum key) 1096 997 { 1097 if (_get Singleton().keyboard_)1098 return _get Singleton().keyboard_->isKeyDown((OIS::KeyCode)key);998 if (_getInstance().keyboard_) 999 return _getInstance().keyboard_->isKeyDown((OIS::KeyCode)key); 1099 1000 else 1100 1001 return false; … … 1103 1004 /*bool InputManager::isModifierDown(KeyboardModifier::Enum modifier) 1104 1005 { 1105 if (_get Singleton().keyboard_)1006 if (_getInstance().keyboard_) 1106 1007 return isModifierDown(modifier); 1107 1008 else … … 1111 1012 /*const MouseState InputManager::getMouseState() 1112 1013 { 1113 if (_get Singleton().mouse_)1114 return _get Singleton().mouse_->getMouseState();1014 if (_getInstance().mouse_) 1015 return _getInstance().mouse_->getMouseState(); 1115 1016 else 1116 1017 return MouseState(); … … 1119 1020 /*const JoyStickState InputManager::getJoyStickState(unsigned int ID) 1120 1021 { 1121 if (ID < _get Singleton().joySticksSize_)1122 return JoyStickState(_get Singleton().joySticks_[ID]->getJoyStickState(), ID);1022 if (ID < _getInstance().joySticksSize_) 1023 return JoyStickState(_getInstance().joySticks_[ID]->getJoyStickState(), ID); 1123 1024 else 1124 1025 return JoyStickState(); … … 1127 1028 void InputManager::destroy() 1128 1029 { 1129 _get Singleton()._destroy();1030 _getInstance()._destroy(); 1130 1031 } 1131 1032 1132 1033 void InputManager::destroyKeyboard() 1133 1034 { 1134 return _get Singleton()._destroyKeyboard();1035 return _getInstance()._destroyKeyboard(); 1135 1036 } 1136 1037 1137 1038 void InputManager::destroyMouse() 1138 1039 { 1139 return _get Singleton()._destroyMouse();1040 return _getInstance()._destroyMouse(); 1140 1041 } 1141 1042 1142 1043 void InputManager::destroyJoySticks() 1143 1044 { 1144 return _get Singleton()._destroyJoySticks();1045 return _getInstance()._destroyJoySticks(); 1145 1046 } 1146 1047 … … 1157 1058 void InputManager::setWindowExtents(const int width, const int height) 1158 1059 { 1159 if (_get Singleton().mouse_)1060 if (_getInstance().mouse_) 1160 1061 { 1161 1062 // Set mouse region (if window resizes, we should alter this to reflect as well) 1162 const OIS::MouseState &mouseState = _get Singleton().mouse_->getMouseState();1063 const OIS::MouseState &mouseState = _getInstance().mouse_->getMouseState(); 1163 1064 mouseState.width = width; 1164 1065 mouseState.height = height; … … 1166 1067 } 1167 1068 1168 /**1169 @brief1170 Sets the input mode to either GUI, inGame or Buffer1171 @param mode1172 The new input mode1173 @remarks1174 Only has an affect if the mode actually changes1175 */1176 void InputManager::setInputState(const InputState state)1177 {1178 _getSingleton().stateRequest_ = state;1179 }1180 1181 /**1182 @brief1183 Returns the current input handling method1184 @return1185 The current input mode.1186 */1187 InputManager::InputState InputManager::getInputState()1188 {1189 return _getSingleton().state_;1190 }1191 1192 1069 void InputManager::storeKeyStroke(const std::string& name) 1193 1070 { 1194 setInputState(IS_NODETECT);1071 requestLeaveState("detector"); 1195 1072 COUT(0) << "Binding string \"" << bindingCommmandString_s << "\" on key '" << name << "'" << std::endl; 1196 1073 CommandExecutor::execute("config KeyBinder " + name + " " + bindingCommmandString_s, false); … … 1200 1077 { 1201 1078 bindingCommmandString_s = command; 1202 setInputState(IS_DETECT);1079 requestEnterState("detector"); 1203 1080 COUT(0) << "Press any button/key or move a mouse/joystick axis" << std::endl; 1204 1081 } … … 1206 1083 void InputManager::calibrate() 1207 1084 { 1208 _getSingleton().setInputState(IS_CALIBRATE);1085 requestEnterState("calibrator"); 1209 1086 } 1210 1087 1211 1088 void InputManager::tick(float dt) 1212 1089 { 1213 _get Singleton()._tick(dt);1214 } 1215 1216 // ###### KeyHandler######1090 _getInstance()._tick(dt); 1091 } 1092 1093 // ###### InputStates ###### 1217 1094 1218 1095 /** … … 1226 1103 True if added, false if name already existed. 1227 1104 */ 1228 bool InputManager:: addKeyHandler(KeyHandler* handler, const std::string& name)1229 { 1230 if ( !handler)1105 bool InputManager::_configureInputState(InputState* state, const std::string& name, int priority) 1106 { 1107 if (name == "") 1231 1108 return false; 1232 if (_getSingleton().keyHandlers_.find(name) == _getSingleton().keyHandlers_.end()) 1233 { 1234 _getSingleton().keyHandlers_[name] = handler; 1235 return true; 1109 if (_getInstance().inputStatesByName_.find(name) == _getInstance().inputStatesByName_.end()) 1110 { 1111 if (_getInstance().inputStatesByPriority_.find(priority) 1112 == _getInstance().inputStatesByPriority_.end()) 1113 { 1114 _getInstance().inputStatesByName_[name] = state; 1115 _getInstance().inputStatesByPriority_[priority] = state; 1116 state->setNumOfJoySticks(numberOfJoySticks()); 1117 state->setName(name); 1118 state->setPriority(priority); 1119 return true; 1120 } 1121 else 1122 { 1123 COUT(2) << "Warning: Could not add an InputState with the same priority '" 1124 << priority << "'." << std::endl; 1125 return false; 1126 } 1236 1127 } 1237 1128 else 1129 { 1130 COUT(2) << "Warning: Could not add an InputState with the same name '" << name << "'." << std::endl; 1238 1131 return false; 1132 } 1133 } 1134 1135 SimpleInputState* InputManager::createSimpleInputState(const std::string &name, int priority) 1136 { 1137 SimpleInputState* state = new SimpleInputState(); 1138 if (_getInstance()._configureInputState(state, name, priority)) 1139 return state; 1140 else 1141 { 1142 delete state; 1143 return 0; 1144 } 1145 } 1146 1147 ExtendedInputState* InputManager::createExtendedInputState(const std::string &name, int priority) 1148 { 1149 ExtendedInputState* state = new ExtendedInputState(); 1150 if (_getInstance()._configureInputState(state, name, priority)) 1151 return state; 1152 else 1153 { 1154 delete state; 1155 return 0; 1156 } 1239 1157 } 1240 1158 … … 1247 1165 True if removal was successful, false if name was not found. 1248 1166 */ 1249 bool InputManager::removeKeyHandler(const std::string &name) 1250 { 1251 disableKeyHandler(name); 1252 std::map<std::string, KeyHandler*>::iterator it = _getSingleton().keyHandlers_.find(name); 1253 if (it != _getSingleton().keyHandlers_.end()) 1254 { 1255 _getSingleton().keyHandlers_.erase(it); 1167 bool InputManager::destroyState(const std::string& name) 1168 { 1169 if (name == "empty" || name == "calibrator" || name == "detector") 1170 { 1171 COUT(2) << "InputManager: Removing the '" << name << "' state is not allowed!" << std::endl; 1172 return false; 1173 } 1174 std::map<std::string, InputState*>::iterator it = _getInstance().inputStatesByName_.find(name); 1175 if (it != _getInstance().inputStatesByName_.end()) 1176 { 1177 _getInstance()._destroyState((*it).second); 1256 1178 return true; 1257 1179 } 1258 else 1259 return false; 1180 return false; 1260 1181 } 1261 1182 … … 1268 1189 Pointer to the instance, 0 if name was not found. 1269 1190 */ 1270 KeyHandler* InputManager::getKeyHandler(const std::string& name)1271 { 1272 std::map<std::string, KeyHandler*>::iterator it = _getSingleton().keyHandlers_.find(name);1273 if (it != _get Singleton().keyHandlers_.end())1191 InputState* InputManager::getState(const std::string& name) 1192 { 1193 std::map<std::string, InputState*>::iterator it = _getInstance().inputStatesByName_.find(name); 1194 if (it != _getInstance().inputStatesByName_.end()) 1274 1195 return (*it).second; 1275 1196 else 1276 1197 return 0; 1198 } 1199 1200 /** 1201 @brief 1202 Returns the current input handling method 1203 @return 1204 The current input mode. 1205 */ 1206 InputState* InputManager::getCurrentState() 1207 { 1208 return (*_getInstance().activeStates_.rbegin()).second; 1277 1209 } 1278 1210 … … 1285 1217 False if name was not found, true otherwise. 1286 1218 */ 1287 bool InputManager:: enableKeyHandler(const std::string& name)1219 bool InputManager::requestEnterState(const std::string& name) 1288 1220 { 1289 1221 // get pointer from the map with all stored handlers 1290 std::map<std::string, KeyHandler*>::const_iterator mapIt = _getSingleton().keyHandlers_.find(name); 1291 if (mapIt == _getSingleton().keyHandlers_.end()) 1292 return false; 1293 // see whether the handler already is in the list 1294 for (std::vector<KeyHandler*>::iterator it = _getSingleton().activeKeyHandlers_.begin(); 1295 it != _getSingleton().activeKeyHandlers_.end(); it++) 1296 { 1297 if ((*it) == (*mapIt).second) 1298 { 1299 return true; 1300 } 1301 } 1302 _getSingleton().activeKeyHandlers_.push_back((*mapIt).second); 1303 _getSingleton().stateRequest_ = IS_CUSTOM; 1304 _getSingleton()._updateTickables(); 1305 return true; 1306 } 1307 1308 /** 1309 @brief 1310 Disables a specific key handler. 1311 @param name 1312 Unique name of the handler. 1313 @return 1314 False if name was not found, true otherwise. 1315 */ 1316 bool InputManager::disableKeyHandler(const std::string &name) 1222 std::map<std::string, InputState*>::const_iterator it = _getInstance().inputStatesByName_.find(name); 1223 if (it != _getInstance().inputStatesByName_.end()) 1224 { 1225 _getInstance().stateEnterRequests_.push_back((*it).second); 1226 return true; 1227 } 1228 return false; 1229 } 1230 1231 bool InputManager::requestLeaveState(const std::string& name) 1317 1232 { 1318 1233 // get pointer from the map with all stored handlers 1319 std::map<std::string, KeyHandler*>::const_iterator mapIt = _getSingleton().keyHandlers_.find(name); 1320 if (mapIt == _getSingleton().keyHandlers_.end()) 1321 return false; 1322 // look for the handler in the list 1323 for (std::vector<KeyHandler*>::iterator it = _getSingleton().activeKeyHandlers_.begin(); 1324 it != _getSingleton().activeKeyHandlers_.end(); it++) 1325 { 1326 if ((*it) == (*mapIt).second) 1327 { 1328 _getSingleton().activeKeyHandlers_.erase(it); 1329 _getSingleton().stateRequest_ = IS_CUSTOM; 1330 _getSingleton()._updateTickables(); 1331 return true; 1332 } 1333 } 1334 return true; 1335 } 1336 1337 /** 1338 @brief 1339 Checks whether a key handler is active 1340 @param name 1341 Unique name of the handler. 1342 @return 1343 False if key handler is not active or doesn't exist, true otherwise. 1344 */ 1345 bool InputManager::isKeyHandlerActive(const std::string& name) 1346 { 1347 // get pointer from the map with all stored handlers 1348 std::map<std::string, KeyHandler*>::const_iterator mapIt = _getSingleton().keyHandlers_.find(name); 1349 if (mapIt == _getSingleton().keyHandlers_.end()) 1350 return false; 1351 // see whether the handler already is in the list 1352 for (std::vector<KeyHandler*>::iterator it = _getSingleton().activeKeyHandlers_.begin(); 1353 it != _getSingleton().activeKeyHandlers_.end(); it++) 1354 { 1355 if ((*it) == (*mapIt).second) 1356 return true; 1234 std::map<std::string, InputState*>::const_iterator it = _getInstance().inputStatesByName_.find(name); 1235 if (it != _getInstance().inputStatesByName_.end()) 1236 { 1237 _getInstance().stateLeaveRequests_.push_back((*it).second); 1238 return true; 1357 1239 } 1358 1240 return false; 1359 1241 } 1360 1361 1362 // ###### MouseHandler ######1363 /**1364 @brief1365 Adds a new mouse handler.1366 @param handler1367 Pointer to the handler object.1368 @param name1369 Unique name of the handler.1370 @return1371 True if added, false if name already existed.1372 */1373 bool InputManager::addMouseHandler(MouseHandler* handler, const std::string& name)1374 {1375 if (!handler)1376 return false;1377 if (_getSingleton().mouseHandlers_.find(name) == _getSingleton().mouseHandlers_.end())1378 {1379 _getSingleton().mouseHandlers_[name] = handler;1380 return true;1381 }1382 else1383 return false;1384 }1385 1386 /**1387 @brief1388 Removes a Mouse handler from the list.1389 @param name1390 Unique name of the handler.1391 @return1392 True if removal was successful, false if name was not found.1393 */1394 bool InputManager::removeMouseHandler(const std::string &name)1395 {1396 disableMouseHandler(name);1397 std::map<std::string, MouseHandler*>::iterator it = _getSingleton().mouseHandlers_.find(name);1398 if (it != _getSingleton().mouseHandlers_.end())1399 {1400 _getSingleton().mouseHandlers_.erase(it);1401 return true;1402 }1403 else1404 return false;1405 }1406 1407 /**1408 @brief1409 Returns the pointer to a handler.1410 @param name1411 Unique name of the handler.1412 @return1413 Pointer to the instance, 0 if name was not found.1414 */1415 MouseHandler* InputManager::getMouseHandler(const std::string& name)1416 {1417 std::map<std::string, MouseHandler*>::iterator it = _getSingleton().mouseHandlers_.find(name);1418 if (it != _getSingleton().mouseHandlers_.end())1419 {1420 return (*it).second;1421 }1422 else1423 return 0;1424 }1425 1426 /**1427 @brief1428 Enables a specific mouse handler that has already been added.1429 @param name1430 Unique name of the handler.1431 @return1432 False if name was not found, true otherwise.1433 */1434 bool InputManager::enableMouseHandler(const std::string& name)1435 {1436 // get pointer from the map with all stored handlers1437 std::map<std::string, MouseHandler*>::const_iterator mapIt = _getSingleton().mouseHandlers_.find(name);1438 if (mapIt == _getSingleton().mouseHandlers_.end())1439 return false;1440 // see whether the handler already is in the list1441 for (std::vector<MouseHandler*>::iterator it = _getSingleton().activeMouseHandlers_.begin();1442 it != _getSingleton().activeMouseHandlers_.end(); it++)1443 {1444 if ((*it) == (*mapIt).second)1445 {1446 return true;1447 }1448 }1449 _getSingleton().activeMouseHandlers_.push_back((*mapIt).second);1450 _getSingleton().stateRequest_ = IS_CUSTOM;1451 _getSingleton()._updateTickables();1452 return true;1453 }1454 1455 /**1456 @brief1457 Disables a specific mouse handler.1458 @param name1459 Unique name of the handler.1460 @return1461 False if name was not found, true otherwise.1462 */1463 bool InputManager::disableMouseHandler(const std::string &name)1464 {1465 // get pointer from the map with all stored handlers1466 std::map<std::string, MouseHandler*>::const_iterator mapIt = _getSingleton().mouseHandlers_.find(name);1467 if (mapIt == _getSingleton().mouseHandlers_.end())1468 return false;1469 // look for the handler in the list1470 for (std::vector<MouseHandler*>::iterator it = _getSingleton().activeMouseHandlers_.begin();1471 it != _getSingleton().activeMouseHandlers_.end(); it++)1472 {1473 if ((*it) == (*mapIt).second)1474 {1475 _getSingleton().activeMouseHandlers_.erase(it);1476 _getSingleton().stateRequest_ = IS_CUSTOM;1477 _getSingleton()._updateTickables();1478 return true;1479 }1480 }1481 return true;1482 }1483 1484 /**1485 @brief1486 Checks whether a mouse handler is active1487 @param name1488 Unique name of the handler.1489 @return1490 False if key handler is not active or doesn't exist, true otherwise.1491 */1492 bool InputManager::isMouseHandlerActive(const std::string& name)1493 {1494 // get pointer from the map with all stored handlers1495 std::map<std::string, MouseHandler*>::const_iterator mapIt = _getSingleton().mouseHandlers_.find(name);1496 if (mapIt == _getSingleton().mouseHandlers_.end())1497 return false;1498 // see whether the handler already is in the list1499 for (std::vector<MouseHandler*>::iterator it = _getSingleton().activeMouseHandlers_.begin();1500 it != _getSingleton().activeMouseHandlers_.end(); it++)1501 {1502 if ((*it) == (*mapIt).second)1503 return true;1504 }1505 return false;1506 }1507 1508 1509 // ###### JoyStickHandler ######1510 1511 /**1512 @brief1513 Adds a new joy stick handler.1514 @param handler1515 Pointer to the handler object.1516 @param name1517 Unique name of the handler.1518 @return1519 True if added, false if name already existed.1520 */1521 bool InputManager::addJoyStickHandler(JoyStickHandler* handler, const std::string& name)1522 {1523 if (!handler)1524 return false;1525 if (_getSingleton().joyStickHandlers_.find(name) == _getSingleton().joyStickHandlers_.end())1526 {1527 _getSingleton().joyStickHandlers_[name] = handler;1528 return true;1529 }1530 else1531 return false;1532 }1533 1534 /**1535 @brief1536 Removes a JoyStick handler from the list.1537 @param name1538 Unique name of the handler.1539 @return1540 True if removal was successful, false if name was not found.1541 */1542 bool InputManager::removeJoyStickHandler(const std::string &name)1543 {1544 for (std::vector<OIS::JoyStick*>::iterator itstick = _getSingleton().joySticks_.begin();1545 itstick != _getSingleton().joySticks_.end(); itstick++)1546 disableJoyStickHandler(name, itstick - _getSingleton().joySticks_.begin());1547 1548 std::map<std::string, JoyStickHandler*>::iterator it = _getSingleton().joyStickHandlers_.find(name);1549 if (it != _getSingleton().joyStickHandlers_.end())1550 {1551 _getSingleton().joyStickHandlers_.erase(it);1552 return true;1553 }1554 else1555 return false;1556 }1557 1558 /**1559 @brief1560 Returns the pointer to a handler.1561 @param name1562 Unique name of the handler.1563 @return1564 Pointer to the instance, 0 if name was not found.1565 */1566 JoyStickHandler* InputManager::getJoyStickHandler(const std::string& name)1567 {1568 std::map<std::string, JoyStickHandler*>::iterator it = _getSingleton().joyStickHandlers_.find(name);1569 if (it != _getSingleton().joyStickHandlers_.end())1570 {1571 return (*it).second;1572 }1573 else1574 return 0;1575 }1576 1577 /**1578 @brief1579 Enables a specific joy stick handler that has already been added.1580 @param name1581 Unique name of the handler.1582 @return1583 False if name or id was not found, true otherwise.1584 */1585 bool InputManager::enableJoyStickHandler(const std::string& name, unsigned int ID)1586 {1587 // get handler pointer from the map with all stored handlers1588 std::map<std::string, JoyStickHandler*>::const_iterator handlerIt = _getSingleton().joyStickHandlers_.find(name);1589 if (handlerIt == _getSingleton().joyStickHandlers_.end())1590 return false;1591 1592 // check for existence of the ID1593 if (ID >= _getSingleton().joySticksSize_)1594 return false;1595 1596 // see whether the handler already is in the list1597 for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ID].begin();1598 it != _getSingleton().activeJoyStickHandlers_[ID].end(); it++)1599 {1600 if ((*it) == (*handlerIt).second)1601 {1602 return true;1603 }1604 }1605 _getSingleton().activeJoyStickHandlers_[ID].push_back((*handlerIt).second);1606 _getSingleton().stateRequest_ = IS_CUSTOM;1607 _getSingleton()._updateTickables();1608 return true;1609 }1610 1611 /**1612 @brief1613 Disables a specific joy stick handler.1614 @param name1615 Unique name of the handler.1616 @return1617 False if name or id was not found, true otherwise.1618 */1619 bool InputManager::disableJoyStickHandler(const std::string &name, unsigned int ID)1620 {1621 // get handler pointer from the map with all stored handlers1622 std::map<std::string, JoyStickHandler*>::const_iterator handlerIt = _getSingleton().joyStickHandlers_.find(name);1623 if (handlerIt == _getSingleton().joyStickHandlers_.end())1624 return false;1625 1626 // check for existence of the ID1627 if (ID >= _getSingleton().joySticksSize_)1628 return false;1629 1630 // look for the handler in the list1631 for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ID].begin();1632 it != _getSingleton().activeJoyStickHandlers_[ID].end(); it++)1633 {1634 if ((*it) == (*handlerIt).second)1635 {1636 _getSingleton().activeJoyStickHandlers_[ID].erase(it);1637 _getSingleton().stateRequest_ = IS_CUSTOM;1638 _getSingleton()._updateTickables();1639 return true;1640 }1641 }1642 return true;1643 }1644 1645 /**1646 @brief1647 Checks whether a joy stick handler is active1648 @param name1649 Unique name of the handler.1650 @return1651 False if key handler is not active or doesn't exist, true otherwise.1652 */1653 bool InputManager::isJoyStickHandlerActive(const std::string& name, unsigned int ID)1654 {1655 // get handler pointer from the map with all stored handlers1656 std::map<std::string, JoyStickHandler*>::const_iterator handlerIt = _getSingleton().joyStickHandlers_.find(name);1657 if (handlerIt == _getSingleton().joyStickHandlers_.end())1658 return false;1659 1660 // check for existence of the ID1661 if (ID >= _getSingleton().joySticksSize_)1662 return false;1663 1664 // see whether the handler already is in the list1665 for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ID].begin();1666 it != _getSingleton().activeJoyStickHandlers_[ID].end(); it++)1667 {1668 if ((*it) == (*handlerIt).second)1669 return true;1670 }1671 return false;1672 }1673 1674 1242 } -
code/branches/input/src/core/input/InputManager.h
r1630 r1637 41 41 #include <map> 42 42 #include <vector> 43 #include <stack> 43 44 #include "util/Math.h" 44 45 #include "core/OrxonoxClass.h" … … 68 69 }; 69 70 70 /**71 @brief72 Struct for storing a custom input state73 */74 struct StoredState75 {76 std::vector<KeyHandler*> activeKeyHandlers_;77 std::vector<MouseHandler*> activeMouseHandlers_;78 std::vector<std::vector<JoyStickHandler*> > activeJoyStickHandlers_;79 std::vector<std::pair<InputTickable*, HandlerState> > activeHandlers_;80 };81 82 71 struct JoyStickCalibration 83 72 { … … 95 84 public OIS::KeyListener, public OIS::MouseListener, public OIS::JoyStickListener 96 85 { 97 public: // enumerations 98 /** 99 @brief 100 Designates the way input is handled and redirected. 101 */ 102 enum InputState 103 { 104 IS_UNINIT, //!< InputManager has not yet been initialised. 105 IS_NONE, //!< Input is discarded. 106 IS_NORMAL, //!< Normal play state. Key and button bindings are active. 107 IS_GUI, //!< All OIS input events are passed to CEGUI. 108 IS_CONSOLE, //!< Keyboard input is redirected to the InputBuffer. 109 IS_DETECT, //!< All the input additionally goes to the KeyDetector 110 IS_NODETECT, //!< remove KeyDetector 111 IS_NOCALIBRATE, 112 IS_CALIBRATE, 113 IS_CUSTOM //!< Any possible configuration. 114 }; 115 116 public: // member functions 117 void setConfigValues(); 86 // --> setConfigValues is private 87 friend ClassIdentifier<InputManager>; 118 88 119 89 public: // static functions … … 139 109 static void setWindowExtents(const int width, const int height); 140 110 141 static void setInputState(const InputState state);142 static InputState getInputState();143 144 111 static void storeKeyStroke(const std::string& name); 145 112 static void keyBind(const std::string& command); … … 149 116 static void tick(float dt); 150 117 151 static bool addKeyHandler (KeyHandler* handler, const std::string& name); 152 static bool removeKeyHandler (const std::string& name); 153 static KeyHandler* getKeyHandler (const std::string& name); 154 static bool enableKeyHandler (const std::string& name); 155 static bool disableKeyHandler (const std::string& name); 156 static bool isKeyHandlerActive (const std::string& name); 157 158 static bool addMouseHandler (MouseHandler* handler, const std::string& name); 159 static bool removeMouseHandler (const std::string& name); 160 static MouseHandler* getMouseHandler (const std::string& name); 161 static bool enableMouseHandler (const std::string& name); 162 static bool disableMouseHandler (const std::string& name); 163 static bool isMouseHandlerActive (const std::string& name); 164 165 static bool addJoyStickHandler (JoyStickHandler* handler, const std::string& name); 166 static bool removeJoyStickHandler (const std::string& name); 167 static JoyStickHandler* getJoyStickHandler(const std::string& name); 168 static bool enableJoyStickHandler (const std::string& name, unsigned int id); 169 static bool disableJoyStickHandler (const std::string& name, unsigned int id); 170 static bool isJoyStickHandlerActive (const std::string& name, unsigned int id); 118 static SimpleInputState* createSimpleInputState (const std::string& name, int priority); 119 static ExtendedInputState* createExtendedInputState(const std::string& name, int priority); 120 static bool destroyState (const std::string& name); 121 //static bool removeState (const std::string& name); 122 static InputState* getState (const std::string& name); 123 static InputState* getCurrentState(); 124 static bool requestEnterState (const std::string& name); 125 static bool requestLeaveState (const std::string& name); 171 126 172 127 private: // functions … … 181 136 bool _initialiseMouse(); 182 137 bool _initialiseJoySticks(); 138 void _redimensionLists(); 183 139 184 140 void _destroy(); … … 186 142 void _destroyMouse(); 187 143 void _destroyJoySticks(); 188 189 void _updateTickables(); 190 191 void _saveState(); 192 void _restoreState(); 144 void _destroyState(InputState* state); 193 145 194 146 void _completeCalibration(); … … 198 150 199 151 void _tick(float dt); 152 153 void _updateActiveStates(); 154 bool _configureInputState(InputState* state, const std::string& name, int priority); 200 155 201 156 // input events … … 210 165 bool sliderMoved (const OIS::JoyStickEvent &arg, int id); 211 166 bool povMoved (const OIS::JoyStickEvent &arg, int id); 212 //bool vector3Moved (const OIS::JoyStickEvent &arg, int id); 213 214 static InputManager& _getSingleton(); 215 static InputManager * _getSingletonPtr() { return &_getSingleton(); }167 168 void setConfigValues(); 169 170 static InputManager& _getInstance(); 216 171 217 172 private: // variables … … 221 176 std::vector<OIS::JoyStick*> joySticks_; //!< OIS joy sticks 222 177 unsigned int joySticksSize_; 223 224 KeyBinder* keyBinder_; //!< KeyBinder instance 225 KeyDetector* keyDetector_; //!< KeyDetector instance 226 InputBuffer* buffer_; //!< InputBuffer instance 227 CalibratorCallback* calibratorCallback_; 228 229 InputState state_; 230 InputState stateRequest_; 231 InputState savedState_; 232 unsigned int keyboardModifiers_; 233 StoredState savedHandlers_; 178 unsigned int devicesNum_; 179 180 // some internally handled states 181 SimpleInputState* stateDetector_; //!< KeyDetector instance 182 SimpleInputState* stateCalibrator_; 183 SimpleInputState* stateEmpty_; 184 185 std::map<std::string, InputState*> inputStatesByName_; 186 std::map<int, InputState*> inputStatesByPriority_; 187 188 std::vector<InputState*> stateEnterRequests_; //!< Request to enter a new state 189 std::vector<InputState*> stateLeaveRequests_; //!< Request to leave the current state 190 191 std::map<int, InputState*> activeStates_; 192 std::vector<InputState*> activeStatesTop_; //!< Current input states for joy stick events. 193 std::vector<InputState*> activeStatesTicked_; //!< Current input states for joy stick events. 234 194 235 195 // joystick calibration … … 239 199 int marginalsMin_[24]; 240 200 bool bCalibrated_; 241 201 bool bCalibrating_; 202 203 unsigned int keyboardModifiers_; //!< Bit mask representing keyboard modifiers 242 204 //! Keeps track of the joy stick POV states 243 205 std::vector<POVStates> povStates_; … … 246 208 std::vector<JoyStickCalibration> joySticksCalibration_; 247 209 248 std::map<std::string, KeyHandler*> keyHandlers_;249 std::map<std::string, MouseHandler*> mouseHandlers_;250 std::map<std::string, JoyStickHandler*> joyStickHandlers_;251 252 std::vector<KeyHandler*> activeKeyHandlers_;253 std::vector<MouseHandler*> activeMouseHandlers_;254 std::vector<std::vector<JoyStickHandler*> > activeJoyStickHandlers_;255 std::vector<std::pair<InputTickable*, HandlerState> > activeHandlers_;256 257 210 std::vector<Key> keysDown_; 258 211 std::vector<MouseButton::Enum> mouseButtonsDown_; -
code/branches/input/src/core/input/KeyBinder.cc
r1630 r1637 333 333 } 334 334 335 void KeyBinder::tickInput(float dt, const HandlerState& state) 336 { 337 // we have to process all the analog input since there is e.g. no 'mouseDoesntMove' event. 338 unsigned int iBegin = 8; 339 unsigned int iEnd = 8; 340 if (state.joyStick) 341 iEnd = nHalfAxes_s; 342 if (state.mouse) 343 iBegin = 0; 344 for (unsigned int i = iBegin; i < iEnd; i++) 345 { 346 if (halfAxes_[i].hasChanged_) 347 { 348 if (!halfAxes_[i].wasDown_ && halfAxes_[i].absVal_ > halfAxes_[i].buttonThreshold_) 349 { 350 halfAxes_[i].wasDown_ = true; 351 if (halfAxes_[i].nCommands_[KeybindMode::OnPress]) 352 halfAxes_[i].execute(KeybindMode::OnPress); 353 } 354 else if (halfAxes_[i].wasDown_ && halfAxes_[i].absVal_ < halfAxes_[i].buttonThreshold_) 355 { 356 halfAxes_[i].wasDown_ = false; 357 if (halfAxes_[i].nCommands_[KeybindMode::OnRelease]) 358 halfAxes_[i].execute(KeybindMode::OnRelease); 359 } 360 halfAxes_[i].hasChanged_ = false; 361 } 362 363 if (halfAxes_[i].wasDown_) 364 { 365 if (halfAxes_[i].nCommands_[KeybindMode::OnHold]) 366 halfAxes_[i].execute(KeybindMode::OnHold); 367 } 368 369 // these are the actually useful axis bindings for analog input AND output 370 if (halfAxes_[i].relVal_ > analogThreshold_ || halfAxes_[i].absVal_ > analogThreshold_) 371 { 372 //COUT(3) << halfAxes_[i].name_ << "\t" << halfAxes_[i].absVal_ << std::endl; 373 halfAxes_[i].execute(); 374 } 375 } 376 377 if (bDeriveMouseInput_ && state.mouse) 335 void KeyBinder::tickMouse(float dt) 336 { 337 tickDevices(0, 8); 338 339 if (bDeriveMouseInput_) 378 340 { 379 341 if (deriveTime_ > derivePeriod_) … … 410 372 deriveTime_ += dt; 411 373 } 412 413 // execute all buffered bindings (addional parameter) 374 } 375 376 void KeyBinder::tickJoyStick(float dt, int device) 377 { 378 tickDevices(8, nHalfAxes_s); 379 } 380 381 void KeyBinder::tickInput(float dt) 382 { 383 // execute all buffered bindings (additional parameter) 414 384 for (unsigned int i = 0; i < paramCommandBuffer_.size(); i++) 415 385 paramCommandBuffer_[i]->execute(); 416 386 417 387 // always reset the relative movement of the mouse 418 if (state.mouse) 419 for (unsigned int i = 0; i < 8; i++) 420 halfAxes_[i].relVal_ = 0.0f; 388 for (unsigned int i = 0; i < 8; i++) 389 halfAxes_[i].relVal_ = 0.0f; 390 } 391 392 void KeyBinder::tickDevices(unsigned int begin, unsigned int end) 393 { 394 for (unsigned int i = begin; i < end; i++) 395 { 396 // button mode 397 // TODO: optimize out all the half axes that don't act as a button at the moment 398 if (halfAxes_[i].hasChanged_) 399 { 400 if (!halfAxes_[i].wasDown_ && halfAxes_[i].absVal_ > halfAxes_[i].buttonThreshold_) 401 { 402 halfAxes_[i].wasDown_ = true; 403 if (halfAxes_[i].nCommands_[KeybindMode::OnPress]) 404 halfAxes_[i].execute(KeybindMode::OnPress); 405 } 406 else if (halfAxes_[i].wasDown_ && halfAxes_[i].absVal_ < halfAxes_[i].buttonThreshold_) 407 { 408 halfAxes_[i].wasDown_ = false; 409 if (halfAxes_[i].nCommands_[KeybindMode::OnRelease]) 410 halfAxes_[i].execute(KeybindMode::OnRelease); 411 } 412 halfAxes_[i].hasChanged_ = false; 413 } 414 415 if (halfAxes_[i].wasDown_) 416 { 417 if (halfAxes_[i].nCommands_[KeybindMode::OnHold]) 418 halfAxes_[i].execute(KeybindMode::OnHold); 419 } 420 421 // these are the actually useful axis bindings for analog input 422 if (halfAxes_[i].relVal_ > analogThreshold_ || halfAxes_[i].absVal_ > analogThreshold_) 423 { 424 //COUT(3) << halfAxes_[i].name_ << "\t" << halfAxes_[i].absVal_ << std::endl; 425 halfAxes_[i].execute(); 426 } 427 } 421 428 } 422 429 … … 441 448 442 449 443 void KeyBinder::joyStickButtonPressed ( int joyStickID,int button)450 void KeyBinder::joyStickButtonPressed (unsigned int joyStickID, unsigned int button) 444 451 { joyStickButtons_[button].execute(KeybindMode::OnPress); } 445 452 446 void KeyBinder::joyStickButtonReleased( int joyStickID,int button)453 void KeyBinder::joyStickButtonReleased(unsigned int joyStickID, unsigned int button) 447 454 { joyStickButtons_[button].execute(KeybindMode::OnRelease); } 448 455 449 void KeyBinder::joyStickButtonHeld ( int joyStickID,int button)456 void KeyBinder::joyStickButtonHeld (unsigned int joyStickID, unsigned int button) 450 457 { joyStickButtons_[button].execute(KeybindMode::OnHold); } 451 458 … … 525 532 } 526 533 527 void KeyBinder::joyStickAxisMoved(int joyStickID, int axis, float value) 528 { 529 // TODO: Use proper calibration values instead of generally 16-bit integer 534 void KeyBinder::joyStickAxisMoved(unsigned int joyStickID, unsigned int axis, float value) 535 { 530 536 int i = 8 + axis * 2; 531 537 if (value >= 0) -
code/branches/input/src/core/input/KeyBinder.h
r1630 r1637 64 64 65 65 protected: // functions 66 void tickInput(float dt, const HandlerState& state); 66 void tickInput(float dt); 67 //void tickInput(float dt, int device); 68 void tickKey(float dt) { } 69 void tickMouse(float dt); 70 void tickJoyStick(float dt, int device); 71 void tickDevices(unsigned int begin, unsigned int end); 67 72 68 73 virtual void readTrigger(Button& button); … … 78 83 void mouseScrolled (int abs, int rel); 79 84 80 void joyStickButtonPressed ( int joyStickID,int button);81 void joyStickButtonReleased( int joyStickID,int button);82 void joyStickButtonHeld ( int joyStickID,int button);83 void joyStickAxisMoved ( int joyStickID,int axis, float value);85 void joyStickButtonPressed (unsigned int joyStickID, unsigned int button); 86 void joyStickButtonReleased(unsigned int joyStickID, unsigned int button); 87 void joyStickButtonHeld (unsigned int joyStickID, unsigned int button); 88 void joyStickAxisMoved (unsigned int joyStickID, unsigned int axis, float value); 84 89 85 90 protected: // variables -
code/branches/input/src/core/input/KeyDetector.cc
r1630 r1637 66 66 True if loading succeeded. 67 67 */ 68 void KeyDetector::loadBindings( )68 void KeyDetector::loadBindings(const std::string& command) 69 69 { 70 70 clearBindings(); 71 71 setConfigValues(); 72 this->command_ = command; 72 73 } 73 74 … … 75 76 { 76 77 SimpleCommand* cmd = new SimpleCommand(); 77 cmd->evaluation_ = CommandExecutor::evaluate( "storeKeyStroke" + button.name_);78 cmd->evaluation_ = CommandExecutor::evaluate(this->command_ + " " + button.name_); 78 79 button.commands_[KeybindMode::OnPress] = new BaseCommand*[1]; 79 80 button.commands_[KeybindMode::OnPress][0] = cmd; -
code/branches/input/src/core/input/KeyDetector.h
r1630 r1637 47 47 KeyDetector(); 48 48 ~KeyDetector(); 49 void loadBindings( );49 void loadBindings(const std::string& command); 50 50 51 51 protected: 52 52 void readTrigger(Button& button); 53 54 private: 55 std::string command_; 53 56 }; 54 57 }
Note: See TracChangeset
for help on using the changeset viewer.