[918] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
[1056] | 3 | * > www.orxonox.net < |
---|
[918] | 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Reto Grieder |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
[973] | 28 | |
---|
[918] | 29 | /** |
---|
| 30 | @file |
---|
| 31 | @brief Implementation of a little Input handler that distributes everything |
---|
| 32 | coming from OIS. |
---|
| 33 | */ |
---|
[973] | 34 | |
---|
| 35 | #ifndef _InputManager_H__ |
---|
| 36 | #define _InputManager_H__ |
---|
| 37 | |
---|
[1062] | 38 | #include "CorePrereqs.h" |
---|
| 39 | |
---|
[1219] | 40 | #include <map> |
---|
[1272] | 41 | #include <vector> |
---|
[973] | 42 | |
---|
[1219] | 43 | #include "ois/OIS.h" |
---|
[1062] | 44 | #include "Tickable.h" |
---|
[1272] | 45 | #include "InputInterfaces.h" |
---|
[973] | 46 | |
---|
| 47 | namespace orxonox |
---|
| 48 | { |
---|
| 49 | /** |
---|
| 50 | @brief Captures and distributes mouse and keyboard input. |
---|
| 51 | */ |
---|
| 52 | class _CoreExport InputManager |
---|
[1272] | 53 | : public TickableReal, |
---|
[1219] | 54 | public OIS::KeyListener, public OIS::MouseListener, public OIS::JoyStickListener |
---|
[973] | 55 | { |
---|
[1219] | 56 | public: // enumerations |
---|
| 57 | /** |
---|
| 58 | @brief Designates the way input is handled and redirected. |
---|
| 59 | */ |
---|
| 60 | enum InputState |
---|
| 61 | { |
---|
| 62 | IS_UNINIT, //!< InputManager has not yet been initialised. |
---|
| 63 | IS_NONE, //!< Input is discarded. |
---|
| 64 | IS_NORMAL, //!< Normal play state. Key and button bindings are active. |
---|
| 65 | IS_GUI, //!< All OIS input events are passed to CEGUI. |
---|
| 66 | IS_CONSOLE, //!< Keyboard input is redirected to the InputBuffer. |
---|
| 67 | IS_CUSTOM //!< Any possible configuration. |
---|
| 68 | }; |
---|
[973] | 69 | |
---|
[1219] | 70 | public: // static functions |
---|
[1272] | 71 | static bool initialise(const size_t windowHnd, int windowWidth, int windowHeight, |
---|
| 72 | bool createKeyboard = true, bool createMouse = true, bool createJoySticks = false); |
---|
[1219] | 73 | static bool initialiseKeyboard(); |
---|
| 74 | static bool initialiseMouse(); |
---|
| 75 | static bool initialiseJoySticks(); |
---|
| 76 | static int numberOfKeyboards(); |
---|
| 77 | static int numberOfMice(); |
---|
| 78 | static int numberOfJoySticks(); |
---|
[1066] | 79 | |
---|
[1219] | 80 | static void destroy(); |
---|
| 81 | static void destroyKeyboard(); |
---|
| 82 | static void destroyMouse(); |
---|
| 83 | static void destroyJoySticks(); |
---|
| 84 | |
---|
[1272] | 85 | static bool isModifierDown(KeyboardModifier::Enum modifier); |
---|
| 86 | static bool isKeyDown(KeyCode::Enum key); |
---|
| 87 | static const MouseState getMouseState(); |
---|
| 88 | static const JoyStickState getJoyStickState(unsigned int ID); |
---|
| 89 | |
---|
[1219] | 90 | static void setWindowExtents(const int width, const int height); |
---|
| 91 | |
---|
| 92 | static void setInputState(const InputState state); |
---|
| 93 | static InputState getInputState(); |
---|
| 94 | |
---|
| 95 | static bool addKeyHandler (KeyHandler* handler, const std::string& name); |
---|
| 96 | static bool removeKeyHandler (const std::string& name); |
---|
| 97 | static KeyHandler* getKeyHandler (const std::string& name); |
---|
| 98 | static bool enableKeyHandler (const std::string& name); |
---|
| 99 | static bool disableKeyHandler (const std::string& name); |
---|
| 100 | static bool isKeyHandlerActive (const std::string& name); |
---|
| 101 | |
---|
| 102 | static bool addMouseHandler (MouseHandler* handler, const std::string& name); |
---|
| 103 | static bool removeMouseHandler (const std::string& name); |
---|
| 104 | static MouseHandler* getMouseHandler (const std::string& name); |
---|
| 105 | static bool enableMouseHandler (const std::string& name); |
---|
| 106 | static bool disableMouseHandler (const std::string& name); |
---|
| 107 | static bool isMouseHandlerActive (const std::string& name); |
---|
| 108 | |
---|
| 109 | static bool addJoyStickHandler (JoyStickHandler* handler, const std::string& name); |
---|
| 110 | static bool removeJoyStickHandler (const std::string& name); |
---|
| 111 | static JoyStickHandler* getJoyStickHandler(const std::string& name); |
---|
[1272] | 112 | static bool enableJoyStickHandler (const std::string& name, unsigned int id); |
---|
| 113 | static bool disableJoyStickHandler (const std::string& name, unsigned int id); |
---|
| 114 | static bool isJoyStickHandlerActive (const std::string& name, unsigned int id); |
---|
[1219] | 115 | |
---|
| 116 | private: // functions |
---|
[973] | 117 | // don't mess with a Singleton |
---|
| 118 | InputManager (); |
---|
| 119 | InputManager (const InputManager&); |
---|
| 120 | ~InputManager(); |
---|
| 121 | |
---|
[1219] | 122 | // Intenal methods |
---|
[1272] | 123 | bool _initialise(const size_t, int, int, bool, bool, bool); |
---|
[1219] | 124 | bool _initialiseKeyboard(); |
---|
| 125 | bool _initialiseMouse(); |
---|
| 126 | bool _initialiseJoySticks(); |
---|
[973] | 127 | |
---|
[1219] | 128 | void _destroy(); |
---|
| 129 | void _destroyKeyboard(); |
---|
| 130 | void _destroyMouse(); |
---|
| 131 | void _destroyJoySticks(); |
---|
[973] | 132 | |
---|
[1219] | 133 | void tick(float dt); |
---|
| 134 | |
---|
| 135 | // input events |
---|
[1272] | 136 | bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id); |
---|
| 137 | bool mouseReleased (const OIS::MouseEvent &arg, OIS::MouseButtonID id); |
---|
[1219] | 138 | bool mouseMoved (const OIS::MouseEvent &arg); |
---|
[1272] | 139 | bool keyPressed (const OIS::KeyEvent &arg); |
---|
| 140 | bool keyReleased (const OIS::KeyEvent &arg); |
---|
| 141 | bool buttonPressed (const OIS::JoyStickEvent &arg, int button); |
---|
| 142 | bool buttonReleased(const OIS::JoyStickEvent &arg, int button); |
---|
| 143 | bool axisMoved (const OIS::JoyStickEvent &arg, int axis); |
---|
| 144 | bool sliderMoved (const OIS::JoyStickEvent &arg, int id); |
---|
| 145 | bool povMoved (const OIS::JoyStickEvent &arg, int id); |
---|
| 146 | bool vector3Moved (const OIS::JoyStickEvent &arg, int id); |
---|
[1219] | 147 | |
---|
| 148 | static InputManager& _getSingleton(); |
---|
| 149 | static InputManager* _getSingletonPtr() { return &_getSingleton(); } |
---|
| 150 | |
---|
| 151 | private: // variables |
---|
| 152 | OIS::InputManager* inputSystem_; //!< OIS input manager |
---|
| 153 | OIS::Keyboard* keyboard_; //!< OIS mouse |
---|
| 154 | OIS::Mouse* mouse_; //!< OIS keyboard |
---|
| 155 | std::vector<OIS::JoyStick*> joySticks_; //!< OIS joy sticks |
---|
[1272] | 156 | unsigned int joySticksSize_; |
---|
[1219] | 157 | |
---|
| 158 | InputState state_; |
---|
| 159 | InputState stateRequest_; |
---|
[1272] | 160 | unsigned int keyboardModifiers_; |
---|
[1219] | 161 | |
---|
| 162 | std::map<std::string, KeyHandler*> keyHandlers_; |
---|
| 163 | std::map<std::string, MouseHandler*> mouseHandlers_; |
---|
| 164 | std::map<std::string, JoyStickHandler*> joyStickHandlers_; |
---|
| 165 | |
---|
| 166 | std::vector<KeyHandler*> activeKeyHandlers_; |
---|
| 167 | std::vector<MouseHandler*> activeMouseHandlers_; |
---|
[1272] | 168 | std::vector<std::vector<JoyStickHandler*> > activeJoyStickHandlers_; |
---|
[1219] | 169 | |
---|
[1272] | 170 | std::vector<Key> keysDown_; |
---|
| 171 | std::vector<MouseButton::Enum> mouseButtonsDown_; |
---|
| 172 | std::vector<std::vector<int> > joyStickButtonsDown_; |
---|
[1219] | 173 | |
---|
[973] | 174 | }; |
---|
[1272] | 175 | |
---|
[973] | 176 | } |
---|
| 177 | |
---|
| 178 | #endif /* _InputManager_H__ */ |
---|