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