[971] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
[1323] | 3 | * > www.orxonox.net < |
---|
[971] | 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 | |
---|
[971] | 29 | /** |
---|
| 30 | @file |
---|
[1022] | 31 | @brief Different definitions of input processing. |
---|
[971] | 32 | */ |
---|
[973] | 33 | |
---|
| 34 | #ifndef _InputHandler_H__ |
---|
| 35 | #define _InputHandler_H__ |
---|
| 36 | |
---|
[1062] | 37 | #include "CorePrereqs.h" |
---|
| 38 | |
---|
[1022] | 39 | #include <string> |
---|
[1293] | 40 | |
---|
[1219] | 41 | #include "ois/OIS.h" |
---|
[1323] | 42 | #include "util/Math.h" |
---|
[1219] | 43 | #include "OrxonoxClass.h" |
---|
| 44 | #include "CommandExecutor.h" |
---|
[1293] | 45 | #include "InputInterfaces.h" |
---|
[973] | 46 | |
---|
| 47 | namespace orxonox |
---|
| 48 | { |
---|
[1323] | 49 | struct _CoreExport AxisCommand |
---|
[1219] | 50 | { |
---|
[1323] | 51 | std::string commandStr; |
---|
| 52 | CommandEvaluation evaluation; |
---|
| 53 | bool bRelative; |
---|
| 54 | float value; |
---|
| 55 | unsigned int nValuesAdded; |
---|
| 56 | }; |
---|
[1219] | 57 | |
---|
[1323] | 58 | struct _CoreExport SimpleCommand |
---|
[1219] | 59 | { |
---|
[1323] | 60 | // for simple binding; direct |
---|
[1219] | 61 | std::string commandStr; |
---|
| 62 | CommandEvaluation evaluation; |
---|
[1323] | 63 | |
---|
| 64 | // axis binding; buffered |
---|
| 65 | AxisCommand* axisCommand; |
---|
| 66 | float axisModifier; |
---|
[1219] | 67 | }; |
---|
| 68 | |
---|
[1323] | 69 | struct _CoreExport KeyBinding |
---|
| 70 | { |
---|
| 71 | void clear() { commands = 0; nCommands = 0; } |
---|
| 72 | SimpleCommand* commands; |
---|
| 73 | unsigned int nCommands; |
---|
| 74 | }; |
---|
| 75 | |
---|
| 76 | struct _CoreExport KeyBindingBundle |
---|
| 77 | { |
---|
| 78 | KeyBinding OnPress; |
---|
| 79 | KeyBinding OnRelease; |
---|
| 80 | KeyBinding OnHold; |
---|
| 81 | }; |
---|
| 82 | |
---|
| 83 | struct _CoreExport HalfAxis |
---|
| 84 | { |
---|
| 85 | float rel; |
---|
| 86 | float abs; |
---|
| 87 | float threshold; |
---|
| 88 | bool wasDown; |
---|
| 89 | bool hasChanged; |
---|
| 90 | }; |
---|
| 91 | |
---|
| 92 | |
---|
[1219] | 93 | /** |
---|
| 94 | @brief Captures mouse, keyboard and joy stick input while in the actual game mode. |
---|
| 95 | Manages the key bindings. |
---|
| 96 | */ |
---|
| 97 | class _CoreExport KeyBinder : public KeyHandler, public MouseHandler, public JoyStickHandler, public OrxonoxClass |
---|
| 98 | { |
---|
| 99 | public: |
---|
| 100 | KeyBinder (); |
---|
| 101 | ~KeyBinder(); |
---|
[1323] | 102 | |
---|
[1022] | 103 | bool loadBindings(); |
---|
[1323] | 104 | void clearBindings(bool bInit = false); |
---|
[1022] | 105 | |
---|
[1323] | 106 | void setConfigValues(); |
---|
| 107 | |
---|
[1219] | 108 | private: // functions |
---|
[1323] | 109 | bool readBindings(std::string* names, std::string* bindingStrings, KeyBindingBundle* bindings, unsigned int size); |
---|
| 110 | bool executeBinding(KeyBinding& binding, float axisRel, float axisAbs); |
---|
| 111 | void clearBundle(KeyBindingBundle& bundle, bool bInit); |
---|
[1219] | 112 | |
---|
[1323] | 113 | void tick(float dt); |
---|
[1219] | 114 | |
---|
[1293] | 115 | bool keyPressed (const KeyEvent& evt); |
---|
| 116 | bool keyReleased(const KeyEvent& evt); |
---|
| 117 | bool keyHeld (const KeyEvent& evt); |
---|
[1022] | 118 | |
---|
[1323] | 119 | bool mouseButtonPressed (MouseButton::Enum id); |
---|
| 120 | bool mouseButtonReleased(MouseButton::Enum id); |
---|
| 121 | bool mouseButtonHeld (MouseButton::Enum id); |
---|
| 122 | bool mouseMoved (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize); |
---|
| 123 | bool mouseScrolled (int abs, int rel); |
---|
[1022] | 124 | |
---|
[1323] | 125 | bool joyStickButtonPressed (int joyStickID, int button); |
---|
| 126 | bool joyStickButtonReleased(int joyStickID, int button); |
---|
| 127 | bool joyStickButtonHeld (int joyStickID, int button); |
---|
| 128 | bool joyStickAxisMoved (int joyStickID, int axis, int value) ; |
---|
[1022] | 129 | |
---|
[1219] | 130 | private: // variables |
---|
| 131 | //! denotes the number of different keys there are in OIS. |
---|
[1323] | 132 | static const unsigned int nKeys_s = 0xEE; |
---|
| 133 | //! Actual key bindings as bundle for Press, Hold and Release |
---|
| 134 | KeyBindingBundle bindingsKeys_ [nKeys_s]; |
---|
[1219] | 135 | //! Names of the keys as strings |
---|
[1323] | 136 | std::string namesKeys_ [nKeys_s]; |
---|
| 137 | //! The configured string values |
---|
| 138 | std::string bindingStringsKeys_[nKeys_s]; |
---|
[1022] | 139 | |
---|
[1219] | 140 | //! denotes the number of different mouse buttons there are in OIS. |
---|
[1323] | 141 | static const unsigned int nMouseButtons_s = 8; |
---|
| 142 | //! Actual key bindings as bundle for Press, Hold and Release |
---|
| 143 | KeyBindingBundle bindingsMouseButtons_ [nMouseButtons_s]; |
---|
[1219] | 144 | //! Names of the mouse buttons as strings |
---|
[1323] | 145 | std::string namesMouseButtons_ [nMouseButtons_s]; |
---|
| 146 | //! The configured string values |
---|
| 147 | std::string bindingStringsMouseButtons_[nMouseButtons_s]; |
---|
[1219] | 148 | |
---|
| 149 | //! denotes the number of different joy stick buttons there are in OIS. |
---|
[1323] | 150 | static const unsigned int nJoyStickButtons_s = 32 + 4 * 4; // 32 buttons and 4 POVs with 4 buttons |
---|
| 151 | //! Actual key bindings as bundle for Press, Hold and Release |
---|
| 152 | KeyBindingBundle bindingsJoyStickButtons_ [nJoyStickButtons_s]; |
---|
[1219] | 153 | //! Names of the joy stick buttons as strings |
---|
[1323] | 154 | std::string namesJoyStickButtons_ [nJoyStickButtons_s]; |
---|
| 155 | //! The configured string values |
---|
| 156 | std::string bindingStringsJoyStickButtons_[nJoyStickButtons_s]; |
---|
[1219] | 157 | |
---|
[1323] | 158 | //! denotes the number of half axes (every axis twice) there can be. |
---|
| 159 | static const unsigned int nHalfAxes_s = 56; |
---|
| 160 | /** |
---|
| 161 | * Array with all the half axes for mouse and joy sticks. |
---|
| 162 | * Bear in mind that the positions are fixed and that the first entry is the |
---|
| 163 | * positive one and the second is negative. |
---|
| 164 | * Sequence is as follows: |
---|
| 165 | * 0 - 3: Mouse x and y |
---|
| 166 | * 4 - 7: Mouse scroll wheels 1 and 2 (2 not yet supported) |
---|
| 167 | * 8 - 23: joy stick (slider) axes 1 to 8 |
---|
| 168 | * 24 - 55: joy stick axes 1 - 16 |
---|
| 169 | */ |
---|
| 170 | HalfAxis halfAxes_[nHalfAxes_s]; |
---|
| 171 | //! Actual key bindings as bundle for Press, Hold and Release |
---|
| 172 | KeyBindingBundle bindingsHalfAxes_ [nHalfAxes_s]; |
---|
| 173 | //! Names of the half axes |
---|
| 174 | std::string namesHalfAxes_ [nHalfAxes_s]; |
---|
| 175 | //! The configured string values |
---|
| 176 | std::string bindingStringsHalfAxes_[nHalfAxes_s]; |
---|
| 177 | |
---|
| 178 | /** |
---|
| 179 | * Commands that have additional parameters (axes) are executed at the end of |
---|
| 180 | * the tick() so that all values can be buffered for single execution. |
---|
| 181 | */ |
---|
| 182 | std::vector<AxisCommand*> axisCommands_; |
---|
[973] | 183 | }; |
---|
| 184 | |
---|
| 185 | |
---|
| 186 | /** |
---|
[1022] | 187 | @brief Captures mouse and keyboard input and distributes it to the |
---|
| 188 | GUI. |
---|
[973] | 189 | */ |
---|
[1219] | 190 | //class _CoreExport GUIInputHandler : public KeyHandler, public MouseHandler, public JoyStickHandler |
---|
| 191 | //{ |
---|
| 192 | //public: |
---|
| 193 | // GUIInputHandler (); |
---|
| 194 | // ~GUIInputHandler(); |
---|
[973] | 195 | |
---|
[1219] | 196 | //private: |
---|
| 197 | // // input events |
---|
[1293] | 198 | //bool keyPressed (const OIS::KeyEvent &arg); |
---|
| 199 | //bool keyReleased (const OIS::KeyEvent &arg); |
---|
| 200 | //bool keyHeld (const OIS::KeyEvent &arg); |
---|
[973] | 201 | |
---|
[1293] | 202 | // bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButton id); |
---|
| 203 | //bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButton id); |
---|
| 204 | //bool mouseHeld (const OIS::MouseEvent &arg, OIS::MouseButton id); |
---|
[1219] | 205 | // bool mouseMoved (const OIS::MouseEvent &arg); |
---|
| 206 | |
---|
[1323] | 207 | //bool buttonPressed (const OIS::JoyStickEvent &arg, int button); |
---|
| 208 | //bool buttonReleased(const OIS::JoyStickEvent &arg, int button); |
---|
| 209 | //bool buttonHeld (const OIS::JoyStickEvent &arg, int button); |
---|
| 210 | //bool axisMoved (const OIS::JoyStickEvent &arg, int axis); |
---|
| 211 | //bool sliderMoved (const OIS::JoyStickEvent &arg, int id); |
---|
| 212 | //bool povMoved (const OIS::JoyStickEvent &arg, int id); |
---|
[1219] | 213 | //}; |
---|
| 214 | |
---|
[973] | 215 | } |
---|
| 216 | |
---|
| 217 | #endif /* _InputHandler_H__ */ |
---|