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