Changeset 3281 for code/branches/core4/src
- Timestamp:
- Jul 13, 2009, 1:57:53 PM (15 years ago)
- Location:
- code/branches/core4/src/core/input
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core4/src/core/input/InputManager.cc
r3279 r3281 30 30 @file 31 31 @brief 32 Implementation of the InputManager that captures all the input from OIS 33 and redirects it to handlers. 34 */ 32 Implementation of the InputManager and a static variable from the InputHandler. 33 */ 35 34 36 35 #include "InputManager.h" … … 60 59 namespace orxonox 61 60 { 62 // TODO: Add console commands again as member commands63 //SetConsoleCommand(InputManager, calibrate, true);64 //SetConsoleCommand(InputManager, reload, false);65 61 SetCommandLineSwitch(keyboard_no_grab).information("Whether not to exclusively grab the keyboard"); 66 62 … … 70 66 InputManager* InputManager::singletonRef_s = 0; 71 67 72 /** 73 @brief 74 Defines the |= operator for easier use. 75 */ 68 //! Defines the |= operator for easier use. 76 69 inline InputManager::State operator|=(InputManager::State& lval, InputManager::State rval) 77 70 { … … 79 72 } 80 73 81 /** 82 @brief 83 Defines the &= operator for easier use. 84 */ 74 //! Defines the &= operator for easier use. 85 75 inline InputManager::State operator&=(InputManager::State& lval, int rval) 86 76 { … … 92 82 // ########## ########## 93 83 // ############################################################ 94 /**95 @brief96 Constructor only sets member fields to initial zero values97 and registers the class in the class hierarchy.98 */99 84 InputManager::InputManager(size_t windowHnd, unsigned int windowWidth, unsigned int windowHeight) 100 85 : internalState_(Bad) … … 157 142 } 158 143 159 /**160 @brief161 Sets the configurable values.162 */163 144 void InputManager::setConfigValues() 164 145 { … … 168 149 @brief 169 150 Creates the OIS::InputMananger, the keyboard, the mouse and 170 the joys ticks and assigns the key bindings.151 the joys ticks. If either of the first two fail, this method throws an exception. 171 152 @param windowHnd 172 153 The window handle of the render window … … 244 225 } 245 226 227 //! Creates a new orxonox::Mouse 246 228 void InputManager::loadMouse(unsigned int windowWidth, unsigned int windowHeight) 247 229 { … … 262 244 } 263 245 264 /** 265 @brief 266 Creates all joy sticks and sets the event handler. 267 @return 268 False joy stick stay uninitialised, true otherwise. 269 */ 246 //! Creates as many joy sticks as are available. 270 247 void InputManager::loadJoySticks() 271 248 { … … 287 264 } 288 265 289 /**290 @brief291 Checks whether there is already a joy stick with the given ID string.292 @return293 Returns true if ID is ok (unique), false otherwise.294 */295 266 bool InputManager::checkJoyStickID(const std::string& idString) const 296 267 { … … 301 272 } 302 273 303 /**304 @brief305 Sets the the name of the command used by the KeyDetector as callback.306 @param command307 Command name as string308 */309 274 void InputManager::setKeyDetectorCallback(const std::string& command) 310 275 { … … 317 282 // ############################################################ 318 283 319 /**320 @brief321 Destroys all the created input devices and states.322 */323 // TODO: export this to be used with reload()324 284 InputManager::~InputManager() 325 285 { … … 346 306 } 347 307 308 /** 309 @brief 310 Destoys all input devices (joy sticks, mouse, keyboard and OIS::InputManager) 311 @throw 312 Method does not throw 313 */ 348 314 void InputManager::destroyDevices() 349 315 { … … 388 354 // ############################################################ 389 355 390 /**391 @brief392 Public interface. Only reloads immediately if the call stack doesn't393 include the update() method.394 */395 356 void InputManager::reload() 396 357 { … … 408 369 } 409 370 410 /** 411 @brief 412 Internal reload method. Destroys the OIS devices and loads them again. 413 */ 371 //! Internal reload method. Destroys the OIS devices and loads them again. 414 372 void InputManager::reloadInternal() 415 373 { … … 438 396 // ############################################################ 439 397 440 /**441 @brief442 Updates the states and the InputState situation.443 @param time444 Clock holding the current time.445 */446 398 void InputManager::update(const Clock& time) 447 399 { … … 581 533 } 582 534 583 /**584 @brief585 Clears all buffers that store what keys/buttons are being pressed at the moment.586 */587 535 void InputManager::clearBuffers() 588 536 { … … 592 540 } 593 541 594 /**595 @brief596 Starts joy stick calibration.597 */598 542 void InputManager::calibrate() 599 543 { … … 609 553 } 610 554 555 //! Tells all devices to stop the calibration and evaluate it. Buffers are being cleared as well! 611 556 void InputManager::stopCalibration() 612 557 { … … 627 572 // ############################################################ 628 573 629 /**630 @brief631 Creates a new InputState by type, name and priority.632 633 You will have to use this method because the634 c'tors and d'tors are private.635 @remarks636 The InputManager will take care of the state completely. That also637 means it gets deleted when the InputManager is destroyed!638 @param name639 Name of the InputState when referenced as string640 @param priority641 Priority matters when multiple states are active. You can specify any642 number, but 1 - 99 is preferred (99 means high).643 */644 574 InputState* InputManager::createInputState(const std::string& name, bool bAlwaysGetsInput, bool bTransparent, InputStatePriority priority) 645 575 { 646 InputState* state = new InputState; 647 if (configureInputState(state, name, bAlwaysGetsInput, bTransparent, priority)) 648 return state; 649 else 650 { 651 delete state; 576 if (name == "") 652 577 return 0; 653 }654 }655 656 /**657 @brief658 Adds a new key handler.659 @param handler660 Pointer to the handler object.661 @param name662 Unique name of the handler.663 @param priority664 Determines which InputState gets the input. Higher is better.665 Use 0 to handle it implicitely by the order of activation.666 Otherwise numbers larger than maxStateStackSize_s have to be used!667 @return668 True if added, false if name or priority already existed.669 */670 bool InputManager::configureInputState(InputState* state, const std::string& name, bool bAlwaysGetsInput, bool bTransparent, int priority)671 {672 if (name == "")673 return false;674 if (!state)675 return false;676 578 if (statesByName_.find(name) == statesByName_.end()) 677 579 { 580 InputState* state = new InputState; 678 581 if (priority >= InputStatePriority::HighPriority || priority == InputStatePriority::Empty) 679 582 { … … 685 588 { 686 589 COUT(2) << "Warning: Could not add an InputState with the same priority '" 687 << priority<< "' != 0." << std::endl;590 << static_cast<int>(priority) << "' != 0." << std::endl; 688 591 return false; 689 592 } … … 697 600 if (priority >= InputStatePriority::HighPriority || priority == InputStatePriority::Empty) 698 601 state->setPriority(priority); 699 return true; 602 603 return state; 700 604 } 701 605 else 702 606 { 703 607 COUT(2) << "Warning: Could not add an InputState with the same name '" << name << "'." << std::endl; 704 return false; 705 } 706 } 707 708 /** 709 @brief 710 Returns the pointer to the requested InputState. 711 @param name 712 Unique name of the state. 713 @return 714 Pointer to the instance, 0 if name was not found. 715 */ 608 return 0; 609 } 610 } 611 716 612 InputState* InputManager::getState(const std::string& name) 717 613 { … … 723 619 } 724 620 725 /**726 @brief727 Activates a specific input state.728 It might not be really activated if the priority is too low!729 @param name730 Unique name of the state.731 @return732 False if name was not found, true otherwise.733 */734 621 bool InputManager::enterState(const std::string& name) 735 622 { … … 754 641 } 755 642 756 /**757 @brief758 Deactivates a specific input state.759 @param name760 Unique name of the state.761 @return762 False if name was not found, true otherwise.763 */764 643 bool InputManager::leaveState(const std::string& name) 765 644 { … … 784 663 } 785 664 786 /**787 @brief788 Removes and destroys an input state.789 @param name790 Name of the handler.791 @return792 True if removal was successful, false if name was not found.793 @remarks794 You can't remove the internal states "empty", "calibrator" and "detector".795 The removal process is being postponed if InputManager::update() is currently running.796 */797 665 bool InputManager::destroyState(const std::string& name) 798 666 { … … 824 692 } 825 693 826 /** 827 @brief 828 Destroys an InputState internally 829 */ 694 //! Destroys an InputState internally. 830 695 void InputManager::destroyStateInternal(InputState* state) 831 696 { -
code/branches/core4/src/core/input/InputManager.h
r3279 r3281 27 27 */ 28 28 29 /**30 @file31 @brief32 Implementation of a little Input handler that distributes everything33 coming from OIS.34 */35 36 29 #ifndef _InputManager_H__ 37 30 #define _InputManager_H__ … … 51 44 /** 52 45 @brief 53 Captures and distributes mouse and keyboard input. 46 Manages the input devices (mouse, keyboard, joy sticks) and the input states. 47 48 Every input device has its own wrapper class which does the actualy input event 49 distribution. The InputManager only creates reloads (on request) those devices. 50 51 The other functionality concerns handling InputStates. They act as a layer 52 between InputHandlers (like the KeyBinder or the GUIManager) and InputDevices. 53 InputStates are memory managed by the IputManager. You cannot create or destroy 54 them on your own. Therefore all states get destroyed with the InputManager d'tor. 55 @note 56 - The actual lists containing all the InputStates for a specific device are stored 57 in the InputDevices themselves. 58 - The devices_ vector always has at least two elements: Keyboard (first) and mouse. 59 You best access them intenally with InputDeviceEnumerator::Keyboard/Mouse 60 The first joy stick is accessed with InputDeviceEnumerator::FirstJoyStick. 61 - Keyboard construction is mandatory , mouse and joy sticks are not. 62 If the OIS::InputManager or the Keyboard fail, an exception is thrown. 54 63 */ 55 64 class _CoreExport InputManager : public OrxonoxClass 56 65 { 57 66 public: 67 //! Represents internal states of the InputManager. 58 68 enum State 59 69 { … … 65 75 }; 66 76 67 InputManager (size_t windowHnd, unsigned int windowWidth, unsigned int windowHeight); 77 /** 78 @brief 79 Loads the devices and initialises the KeyDetector and the Calibrator. 80 81 If either the OIS input system and/or the keyboard could not be created, 82 the constructor fails with an std::exception. 83 */ 84 InputManager(size_t windowHnd, unsigned int windowWidth, unsigned int windowHeight); 85 //! Destroys all devices AND all input states! 68 86 ~InputManager(); 69 87 void setConfigValues(); 70 88 89 /** 90 @brief 91 Updates the devices (which distribute the input events) and the input states. 92 93 Any InpuStates changes (destroy, enter, leave) and happens here. If a reload request 94 was submitted while updating, the request wil be postponed until the next update call. 95 */ 71 96 void update(const Clock& time); 97 //! Clears all input device buffers. This usually only includes the pressed button list. 72 98 void clearBuffers(); 99 //! Starts joy stick calibration. 73 100 void calibrate(); 101 /** 102 @brief 103 Reloads all the input devices. Use this method to initialise new joy sticks. 104 @note 105 Only reloads immediately if the call stack doesn't include the update() method. 106 */ 74 107 void reload(); 75 108 … … 77 110 // Input States 78 111 //------------------------------- 112 /** 113 @brief 114 Creates a new InputState that gets managed by the InputManager. 115 @remarks 116 The InputManager will take care of the state completely. That also 117 means it gets deleted when the InputManager is destroyed! 118 @param name 119 Unique name of the InputState when referenced as string 120 @param priority 121 Priority matters when multiple states are active. You can specify any 122 number, but 1 - 99 is preferred (99 means high priority). 123 */ 79 124 InputState* createInputState(const std::string& name, bool bAlwaysGetsInput = false, bool bTransparent = false, InputStatePriority priority = InputStatePriority::Dynamic); 125 /** 126 @brief 127 Returns a pointer to a InputState referenced by name. 128 @return 129 Returns NULL if state was not found. 130 */ 80 131 InputState* getState(const std::string& name); 81 bool enterState (const std::string& name); 82 bool leaveState (const std::string& name); 83 bool destroyState (const std::string& name); 132 /** 133 @brief 134 Activates a specific input state. 135 It might not be actually activated if the priority is too low! 136 @return 137 False if name was not found, true otherwise. 138 */ 139 bool enterState(const std::string& name); 140 /** 141 @brief 142 Deactivates a specific input state. 143 @return 144 False if name was not found, true otherwise. 145 */ 146 bool leaveState(const std::string& name); 147 /** 148 @brief 149 Removes and destroys an input state. 150 @return 151 True if removal was successful, false if name was not found. 152 @remarks 153 - You can't remove the internal states "empty", "calibrator" and "detector". 154 - The removal process is being postponed if InputManager::update() is currently running. 155 */ 156 bool destroyState(const std::string& name); 84 157 85 158 //------------------------------- 86 159 // Various getters and setters 87 160 //------------------------------- 161 //! Sets the the name of the command used by the KeyDetector as callback. 88 162 void setKeyDetectorCallback(const std::string& command); 163 /** 164 @brief 165 Checks whether there is already a joy stick with the given ID string. 166 @return 167 Returns true if ID is ok (unique), false otherwise. 168 */ 89 169 bool checkJoyStickID(const std::string& idString) const; 170 //! Returns the number of joy stick that have been created since the c'tor or last call to reload(). 90 171 unsigned int getJoyStickQuantity() const 91 172 { return devices_.size() - InputDeviceEnumerator::FirstJoyStick; } 173 //! Returns a pointer to the OIS InputManager. Only you if you know what you're doing! 92 174 OIS::InputManager* getOISInputManager() 93 175 { return this->oisInputManager_; } 94 176 95 static InputManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; } 177 //! Returns a reference to the singleton instance 178 static InputManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; } 96 179 97 180 private: // functions … … 106 189 107 190 void stopCalibration(); 191 void reloadInternal(); 108 192 109 193 void destroyStateInternal(InputState* state); 110 194 void updateActiveStates(); 111 bool configureInputState(InputState* state, const std::string& name, bool bAlwaysGetsInput, bool bTransparent, int priority);112 113 void reloadInternal();114 195 115 196 private: // variables … … 117 198 OIS::InputManager* oisInputManager_; //!< OIS input manager 118 199 std::vector<InputDevice*> devices_; //!< List of all input devices (keyboard, mouse, joy sticks) 119 size_t windowHnd_; //!< Render window handle 200 // TODO: Get this from the GraphicsManager during reload 201 size_t windowHnd_; //!< Render window handle (used to reload the InputManager) 120 202 121 203 // some internally handled states and handlers 122 InputState* emptyState_; 204 InputState* emptyState_; //!< Lowest priority states (makes handling easier) 123 205 KeyDetector* keyDetector_; //!< KeyDetector instance 206 //! InputBuffer that reacts to the Enter key when calibrating the joy sticks 124 207 InputBuffer* calibratorCallbackHandler_; 125 208 126 std::map<std::string, InputState*> statesByName_; 127 std::map<int, InputState*> activeStates_; 128 std::vector<InputState*> activeStatesTicked_; 129 130 std::set<InputState*> stateEnterRequests_; //!< Request to enter a new state131 std::set<InputState*> stateLeaveRequests_; //!< Request to leave a running state132 std::set<InputState*> stateDestroyRequests_; //!< Request to destroy a state133 134 static InputManager* singletonRef_s; 209 std::map<std::string, InputState*> statesByName_; //!< Contains all the created input states by name 210 std::map<int, InputState*> activeStates_; //!< Contains all active input states by priority (std::map is sorted!) 211 std::vector<InputState*> activeStatesTicked_; //!< Like activeStates_, but only contains the ones that currently receive events 212 213 std::set<InputState*> stateEnterRequests_; //!< Requests to enter a new state 214 std::set<InputState*> stateLeaveRequests_; //!< Requests to leave a running state 215 std::set<InputState*> stateDestroyRequests_; //!< Requests to destroy a state 216 217 static InputManager* singletonRef_s; //!< Pointer reference to the singleton 135 218 }; 136 219 }
Note: See TracChangeset
for help on using the changeset viewer.