1 | /* |
---|
2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
3 | * > www.orxonox.net < |
---|
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 | */ |
---|
28 | |
---|
29 | /** |
---|
30 | @file |
---|
31 | @brief Different definitions of input processing. |
---|
32 | */ |
---|
33 | |
---|
34 | #ifndef _InputHandler_H__ |
---|
35 | #define _InputHandler_H__ |
---|
36 | |
---|
37 | #include "CorePrereqs.h" |
---|
38 | |
---|
39 | #include <string> |
---|
40 | |
---|
41 | #include "ois/OIS.h" |
---|
42 | #include "util/Math.h" |
---|
43 | #include "OrxonoxClass.h" |
---|
44 | #include "CommandExecutor.h" |
---|
45 | #include "InputInterfaces.h" |
---|
46 | |
---|
47 | namespace orxonox |
---|
48 | { |
---|
49 | struct _CoreExport AxisCommand |
---|
50 | { |
---|
51 | std::string commandStr; |
---|
52 | CommandEvaluation evaluation; |
---|
53 | bool bRelative; |
---|
54 | float value; |
---|
55 | unsigned int nValuesAdded; |
---|
56 | }; |
---|
57 | |
---|
58 | struct _CoreExport SimpleCommand |
---|
59 | { |
---|
60 | // for simple binding; direct |
---|
61 | std::string commandStr; |
---|
62 | CommandEvaluation evaluation; |
---|
63 | |
---|
64 | // axis binding; buffered |
---|
65 | AxisCommand* axisCommand; |
---|
66 | float axisModifier; |
---|
67 | }; |
---|
68 | |
---|
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 | |
---|
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(); |
---|
102 | |
---|
103 | bool loadBindings(); |
---|
104 | void clearBindings(bool bInit = false); |
---|
105 | |
---|
106 | void setConfigValues(); |
---|
107 | |
---|
108 | private: // functions |
---|
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); |
---|
112 | |
---|
113 | void tick(float dt); |
---|
114 | |
---|
115 | bool keyPressed (const KeyEvent& evt); |
---|
116 | bool keyReleased(const KeyEvent& evt); |
---|
117 | bool keyHeld (const KeyEvent& evt); |
---|
118 | |
---|
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); |
---|
124 | |
---|
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) ; |
---|
129 | |
---|
130 | private: // variables |
---|
131 | //! denotes the number of different keys there are in OIS. |
---|
132 | static const unsigned int nKeys_s = 0xEE; |
---|
133 | //! Actual key bindings as bundle for Press, Hold and Release |
---|
134 | KeyBindingBundle bindingsKeys_ [nKeys_s]; |
---|
135 | //! Names of the keys as strings |
---|
136 | std::string namesKeys_ [nKeys_s]; |
---|
137 | //! The configured string values |
---|
138 | std::string bindingStringsKeys_[nKeys_s]; |
---|
139 | |
---|
140 | //! denotes the number of different mouse buttons there are in OIS. |
---|
141 | static const unsigned int nMouseButtons_s = 8; |
---|
142 | //! Actual key bindings as bundle for Press, Hold and Release |
---|
143 | KeyBindingBundle bindingsMouseButtons_ [nMouseButtons_s]; |
---|
144 | //! Names of the mouse buttons as strings |
---|
145 | std::string namesMouseButtons_ [nMouseButtons_s]; |
---|
146 | //! The configured string values |
---|
147 | std::string bindingStringsMouseButtons_[nMouseButtons_s]; |
---|
148 | |
---|
149 | //! denotes the number of different joy stick buttons there are in OIS. |
---|
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]; |
---|
153 | //! Names of the joy stick buttons as strings |
---|
154 | std::string namesJoyStickButtons_ [nJoyStickButtons_s]; |
---|
155 | //! The configured string values |
---|
156 | std::string bindingStringsJoyStickButtons_[nJoyStickButtons_s]; |
---|
157 | |
---|
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_; |
---|
183 | }; |
---|
184 | |
---|
185 | |
---|
186 | /** |
---|
187 | @brief Captures mouse and keyboard input and distributes it to the |
---|
188 | GUI. |
---|
189 | */ |
---|
190 | //class _CoreExport GUIInputHandler : public KeyHandler, public MouseHandler, public JoyStickHandler |
---|
191 | //{ |
---|
192 | //public: |
---|
193 | // GUIInputHandler (); |
---|
194 | // ~GUIInputHandler(); |
---|
195 | |
---|
196 | //private: |
---|
197 | // // input events |
---|
198 | //bool keyPressed (const OIS::KeyEvent &arg); |
---|
199 | //bool keyReleased (const OIS::KeyEvent &arg); |
---|
200 | //bool keyHeld (const OIS::KeyEvent &arg); |
---|
201 | |
---|
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); |
---|
205 | // bool mouseMoved (const OIS::MouseEvent &arg); |
---|
206 | |
---|
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); |
---|
213 | //}; |
---|
214 | |
---|
215 | } |
---|
216 | |
---|
217 | #endif /* _InputHandler_H__ */ |
---|