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 |
---|
32 | Different definitions of input processing. |
---|
33 | */ |
---|
34 | |
---|
35 | #ifndef _KeyBinder_H__ |
---|
36 | #define _KeyBinder_H__ |
---|
37 | |
---|
38 | #include "core/CorePrereqs.h" |
---|
39 | |
---|
40 | #include <vector> |
---|
41 | |
---|
42 | #include "core/OrxonoxClass.h" |
---|
43 | #include "InputInterfaces.h" |
---|
44 | #include "Button.h" |
---|
45 | #include "HalfAxis.h" |
---|
46 | |
---|
47 | namespace orxonox |
---|
48 | { |
---|
49 | /** |
---|
50 | @brief |
---|
51 | Handles mouse, keyboard and joy stick input while in the actual game mode. |
---|
52 | Manages the key bindings. |
---|
53 | */ |
---|
54 | class _CoreExport KeyBinder : public KeyHandler, public MouseHandler, public JoyStickHandler, public OrxonoxClass |
---|
55 | { |
---|
56 | public: |
---|
57 | KeyBinder (); |
---|
58 | virtual ~KeyBinder(); |
---|
59 | |
---|
60 | void loadBindings(); |
---|
61 | void clearBindings(); |
---|
62 | void setConfigValues(); |
---|
63 | void resetJoyStickAxes(); |
---|
64 | |
---|
65 | protected: // functions |
---|
66 | void tickInput(float dt, const HandlerState& state); |
---|
67 | |
---|
68 | virtual void readTrigger(Button& button); |
---|
69 | |
---|
70 | void keyPressed (const KeyEvent& evt); |
---|
71 | void keyReleased(const KeyEvent& evt); |
---|
72 | void keyHeld (const KeyEvent& evt); |
---|
73 | |
---|
74 | void mouseButtonPressed (MouseButton::Enum id); |
---|
75 | void mouseButtonReleased(MouseButton::Enum id); |
---|
76 | void mouseButtonHeld (MouseButton::Enum id); |
---|
77 | void mouseMoved (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize); |
---|
78 | void mouseScrolled (int abs, int rel); |
---|
79 | |
---|
80 | void joyStickButtonPressed (int joyStickID, int button); |
---|
81 | void joyStickButtonReleased(int joyStickID, int button); |
---|
82 | void joyStickButtonHeld (int joyStickID, int button); |
---|
83 | void joyStickAxisMoved (int joyStickID, int axis, float value); |
---|
84 | |
---|
85 | protected: // variables |
---|
86 | //! denotes the number of different keys there are in OIS. |
---|
87 | static const unsigned int nKeys_s = 0xEE; |
---|
88 | //! Actual key bindings as bundle for Press, Hold and Release |
---|
89 | Button keys_ [nKeys_s]; |
---|
90 | |
---|
91 | //! denotes the number of different mouse buttons there are in OIS. |
---|
92 | static const unsigned int nMouseButtons_s = 8 + 2*2; // 8 buttons and 2 scroll wheels |
---|
93 | //! Actual key bindings as bundle for Press, Hold and Release |
---|
94 | Button mouseButtons_ [nMouseButtons_s]; |
---|
95 | |
---|
96 | //! denotes the number of different joy stick buttons there are in OIS. |
---|
97 | static const unsigned int nJoyStickButtons_s = 32 + 4 * 4; // 32 buttons and 4 POVs with 4 buttons |
---|
98 | //! Actual key bindings as bundle for Press, Hold and Release |
---|
99 | Button joyStickButtons_ [nJoyStickButtons_s]; |
---|
100 | |
---|
101 | //! denotes the number of half axes (every axis twice) there can be. |
---|
102 | static const unsigned int nHalfAxes_s = 56; |
---|
103 | /** |
---|
104 | * Array with all the half axes for mouse and joy sticks. |
---|
105 | * Keep in mind that the positions are fixed and that the first entry is the |
---|
106 | * positive one and the second is negative. |
---|
107 | * Sequence is as follows: |
---|
108 | * 0 - 3: Mouse x and y |
---|
109 | * 4 - 7: empty |
---|
110 | * 8 - 23: joy stick slider axes 1 to 8 |
---|
111 | * 24 - 55: joy stick axes 1 - 16 |
---|
112 | */ |
---|
113 | HalfAxis halfAxes_[nHalfAxes_s]; |
---|
114 | |
---|
115 | /** |
---|
116 | @brief |
---|
117 | Commands that have additional parameters (axes) are executed at the end of |
---|
118 | the tick() so that all values can be buffered for single execution. |
---|
119 | */ |
---|
120 | std::vector<BufferedParamCommand*> paramCommandBuffer_; |
---|
121 | |
---|
122 | //! Keeps track of the absolute mouse value (incl. scroll wheel) |
---|
123 | int mousePosition_[2]; |
---|
124 | //! Used to derive mouse input if requested |
---|
125 | int mouseRelative_[2]; |
---|
126 | float deriveTime_; |
---|
127 | |
---|
128 | |
---|
129 | //##### ConfigValues ##### |
---|
130 | |
---|
131 | //! Threshold for analog triggers until which the state is 0. |
---|
132 | float analogThreshold_; |
---|
133 | //! Threshold for analog triggers until which the button is not pressed. |
---|
134 | float buttonThreshold_; |
---|
135 | //! Derive mouse input for absolute values? |
---|
136 | bool bDeriveMouseInput_; |
---|
137 | //! Accuracy of the mouse input deriver. The higher the more precise, but laggier. |
---|
138 | float derivePeriod_; |
---|
139 | //! mouse sensitivity |
---|
140 | float mouseSensitivity_; |
---|
141 | //! mouse sensitivity if mouse input is derived |
---|
142 | float mouseSensitivityDerived_; |
---|
143 | //! Whether or not to clip abslute mouse values to 1024 |
---|
144 | bool bClipMouse_; |
---|
145 | }; |
---|
146 | } |
---|
147 | |
---|
148 | #endif /* _KeyBinder_H__ */ |
---|