Changeset 1182 for code/branches/input/src/core/InputManager.h
- Timestamp:
- Apr 24, 2008, 9:40:23 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/input/src/core/InputManager.h
r1084 r1182 38 38 #include "CorePrereqs.h" 39 39 40 #include <map> 41 #include <list> 40 42 #include <OIS/OIS.h> 41 43 … … 46 48 { 47 49 /** 48 @brief Designates the way input is handled currently.49 IM_GUI: All the OIS input events are passed to CEGUI50 IM_KEYBOARD: Only keyboard input is captured and passed to the InputBuffer51 IM_INGAME: Normal game mode. Key bindings and mouse are active.52 */53 enum InputMode54 {55 IM_GUI = 0,56 IM_KEYBOARD = 1,57 IM_INGAME = 2,58 IM_UNINIT = 3,59 };60 61 /**62 50 @brief Captures and distributes mouse and keyboard input. 63 51 It resolves the key bindings to InputEvents which can be heard by … … 65 53 */ 66 54 class _CoreExport InputManager 67 : public Tickable 55 : public Tickable, 56 public OIS::MouseListener, public OIS::KeyListener, public OIS::JoyStickListener 68 57 { 69 58 public: 70 bool initialise(size_t windowHnd, int windowWidth, int windowHeight); 71 void destroy(); 59 /** 60 @brief Designates the way input is handled currently. 61 IM_GUI: All the OIS input events are passed to CEGUI 62 IM_BUFFER: Only keyboard input is captured and passed to the InputBuffer 63 IM_NORMAL: Normal game mode. Key bindings and mouse are active. 64 */ 65 enum InputState 66 { 67 IS_UNINIT, 68 IS_NONE, 69 IS_NORMAL, 70 IS_GUI, 71 IS_CONSOLE, 72 IS_CUSTOM 73 }; 74 75 public: 72 76 void tick(float dt); 73 void setWindowExtents(int width, int height);74 InputMode getInputMode();75 77 76 // temporary hack 77 void feedInputBuffer(InputBuffer* buffer); 78 static bool initialise(size_t windowHnd, int windowWidth, int windowHeight); 79 static void destroy(); 80 81 static void setWindowExtents(int width, int height); 82 static void setInputState(const InputState state); 83 static InputState getInputState(); 84 85 static bool addKeyListener(OIS::KeyListener* listener, const std::string& name); 86 //static bool removeKeyListener(OIS::KeyListener* listener); 87 static bool removeKeyListener(const std::string& name); 88 static bool enableKeyListener(const std::string& name); 89 static bool disableKeyListener(const std::string& name); 90 static OIS::KeyListener* getKeyListener(const std::string& name); 91 static bool isKeyListenerActive(const std::string& name); 92 93 static bool addMouseListener(OIS::MouseListener* listener, const std::string& name); 94 //static bool removeMouseListener(OIS::MouseListener* listener); 95 static bool removeMouseListener(const std::string& name); 96 static bool enableMouseListener(const std::string& name); 97 static bool disableMouseListener(const std::string& name); 98 static OIS::MouseListener* getMouseListener(const std::string& name); 99 static bool isMouseListenerActive(const std::string& name); 100 101 static bool addJoyStickListener(OIS::JoyStickListener* listener, const std::string& name); 102 //static bool removeJoyStickListener(OIS::JoyStickListener* listener); 103 static bool removeJoyStickListener(const std::string& name); 104 static bool enableJoyStickListener(const std::string& name); 105 static bool disableJoyStickListener(const std::string& name); 106 static OIS::JoyStickListener* getJoyStickListener(const std::string& name); 107 static bool isJoyStickListenerActive(const std::string& name); 78 108 79 109 // Temporary solutions. Will be removed soon! 80 OIS::Mouse *getMouse() { return this->mouse_ ; } 81 OIS::Keyboard *getKeyboard() { return this->keyboard_; } 82 83 static InputManager& getSingleton(); 84 static InputManager* getSingletonPtr() { return &getSingleton(); } 85 static void setInputMode(int mode); 110 static OIS::Mouse* getMouse() { return _getSingleton().mouse_ ; } 111 static OIS::Keyboard* getKeyboard() { return _getSingleton().keyboard_; } 86 112 87 113 private: … … 91 117 ~InputManager(); 92 118 93 OIS::InputManager *inputSystem_; //!< OIS input manager 94 OIS::Keyboard *keyboard_; //!< OIS mouse 95 OIS::Mouse *mouse_; //!< OIS keyboard 119 bool _initialise(size_t windowHnd, int windowWidth, int windowHeight); 120 void _destroy(); 121 void _setDefaultState(); 122 void _loadBindings(); 96 123 97 InputMode currentMode_; //!< Input mode currently used 98 InputMode setMode_; //!< Input mode that has been set lately 99 InputHandlerGUI *handlerGUI_; //!< Handles the input if in GUI mode 100 // FIXME: insert the InputBuffer once merged with core2 101 InputBuffer *handlerBuffer_; //!< Handles the input if in Buffer mode 102 InputHandlerGame *handlerGame_; //!< Handles the input if in Game mode 124 // input events 125 bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id); 126 bool mouseReleased (const OIS::MouseEvent &arg, OIS::MouseButtonID id); 127 bool mouseMoved (const OIS::MouseEvent &arg); 128 bool keyPressed (const OIS::KeyEvent &arg); 129 bool keyReleased (const OIS::KeyEvent &arg); 130 bool buttonPressed (const OIS::JoyStickEvent &arg, int button); 131 bool buttonReleased(const OIS::JoyStickEvent &arg, int button); 132 bool axisMoved (const OIS::JoyStickEvent &arg, int axis); 133 bool sliderMoved (const OIS::JoyStickEvent &arg, int id); 134 bool povMoved (const OIS::JoyStickEvent &arg, int id); 103 135 104 //! Pointer to the instance of the singleton 105 //static InputManager *singletonRef_s; 136 static InputManager& _getSingleton(); 137 static InputManager* _getSingletonPtr() { return &_getSingleton(); } 138 139 private: 140 OIS::InputManager* inputSystem_; //!< OIS input manager 141 OIS::Keyboard* keyboard_; //!< OIS mouse 142 OIS::Mouse* mouse_; //!< OIS keyboard 143 144 InputState state_; 145 InputState stateRequest_; 146 147 std::list<OIS::KeyCode> keysDown_; 148 149 bool bDefaultKeyInput; 150 bool bDefaultMouseInput; 151 bool bDefaultJoyStickInput; 152 153 std::map<std::string, OIS::KeyListener*> keyListeners_; 154 std::list<OIS::KeyListener*> activeKeyListeners_; 155 std::map<std::string, OIS::MouseListener*> mouseListeners_; 156 std::list<OIS::MouseListener*> activeMouseListeners_; 157 std::map<std::string, OIS::JoyStickListener*> joystickListeners_; 158 std::list<OIS::JoyStickListener*> activeJoyStickListeners_; 159 160 161 /** denotes the maximum number of different keys there are in OIS. 162 256 should be ok since the highest number in the enum is 237. */ 163 static const int numberOfKeys_s = 256; 164 //! Array of input events for every pressed key 165 std::string bindingsKeyPress_ [numberOfKeys_s]; 166 //! Array of input events for every released key 167 std::string bindingsKeyRelease_[numberOfKeys_s]; 168 //! Array of input events for every held key 169 std::string bindingsKeyHold_ [numberOfKeys_s]; 170 171 /** denotes the maximum number of different buttons there are in OIS. 172 16 should be ok since the highest number in the enum is 7. */ 173 static const int numberOfMouseButtons_s = 16; 174 //! Array of input events for every pressed mouse button 175 std::string bindingsMouseButtonPress_ [numberOfMouseButtons_s]; 176 //! Array of input events for every released mouse button 177 std::string bindingsMouseButtonRelease_[numberOfMouseButtons_s]; 178 //! Array of input events for every held mouse button 179 std::string bindingsMouseButtonHold_ [numberOfMouseButtons_s]; 180 181 /** denotes the maximum number of different buttons there are in OIS. 182 32 should be ok. */ 183 static const int numberOfJoyStickButtons_s = 32; 184 //! Array of input events for every pressed joystick button 185 std::string bindingsJoyStickButtonPress_ [numberOfJoyStickButtons_s]; 186 //! Array of input events for every released joystick button 187 std::string bindingsJoyStickButtonRelease_[numberOfJoyStickButtons_s]; 188 //! Array of input events for every held joystick button 189 std::string bindingsJoyStickButtonHold_ [numberOfJoyStickButtons_s]; 190 106 191 }; 107 192 }
Note: See TracChangeset
for help on using the changeset viewer.