Changeset 1340 for code/branches/input/src/core/InputHandler.h
- Timestamp:
- May 21, 2008, 12:23:29 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/input/src/core/InputHandler.h
r1323 r1340 38 38 39 39 #include <string> 40 #include <vector> 40 41 41 42 #include "ois/OIS.h" … … 47 48 namespace orxonox 48 49 { 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; 50 class _CoreExport BaseCommand 51 { 52 public: 53 virtual ~BaseCommand() { } 54 virtual bool execute(float abs = 1.0f, float rel = 1.0f) = 0; 55 }; 56 57 class _CoreExport BufferedParamCommand 58 { 59 public: 60 BufferedParamCommand() : value_(0.0f), nValuesAdded_(0), paramIndex_(-1) { } 61 bool execute(); 62 float value_; 63 unsigned int nValuesAdded_; 64 int paramIndex_; 65 CommandEvaluation evaluation_; 66 }; 67 68 class _CoreExport SimpleCommand : public BaseCommand 69 { 70 public: 71 bool execute(float abs = 1.0f, float rel = 1.0f); 72 73 CommandEvaluation evaluation_; 74 }; 75 76 class _CoreExport ParamCommand : public BaseCommand 77 { 78 public: 79 ParamCommand() : bRelative_(false), paramModifier_(1.0f), paramCommand_(0) { } 80 bool execute(float abs = 1.0f, float rel = 1.0f); 81 82 bool bRelative_; 83 float paramModifier_; 84 BufferedParamCommand* paramCommand_; 85 }; 86 87 class _CoreExport Button 88 { 89 public: 90 Button() { nCommands_[0]=0; nCommands_[1]=0; nCommands_[2]=0; clear(); } 91 virtual ~Button() { clear(); } 92 virtual void clear(); 93 virtual bool addParamCommand(ParamCommand* command) { return false; } 94 void parse(std::vector<BufferedParamCommand*>& paramCommandBuffer); 95 bool execute(KeybindMode::Enum mode); 96 97 //! The configured string value 98 std::string bindingString_; 99 //! Name of the trigger as strings 100 std::string name_; 101 //! Basic commands for OnPress, OnHold and OnRelease 102 BaseCommand** commands_[3]; 103 //! Number of basic commands 104 unsigned int nCommands_[3]; 105 //! Says how much it takes for an analog axis to trigger a button 106 //! Note: This variable is here to have only one parse() function. 107 float buttonThreshold_; 108 }; 109 110 111 class _CoreExport HalfAxis : public Button 112 { 113 public: 114 HalfAxis() : relVal_(0.0f), absVal_(0.0f), paramCommands_(0), nParamCommands_(0), 115 wasDown_(false), hasChanged_(false) { } 116 bool execute(); 117 bool execute(KeybindMode::Enum mode) { return Button::execute(mode); } 118 bool addParamCommand(ParamCommand* command); 119 void clear(); 120 121 // axis related 122 float relVal_; 123 float absVal_; 124 ParamCommand** paramCommands_; 125 unsigned int nParamCommands_; 126 127 // button related 128 bool wasDown_; 129 bool hasChanged_; 90 130 }; 91 131 92 132 93 133 /** 94 @brief Captures mouse, keyboard and joy stick input while in the actual game mode.134 @brief Handles mouse, keyboard and joy stick input while in the actual game mode. 95 135 Manages the key bindings. 96 136 */ … … 101 141 ~KeyBinder(); 102 142 103 boolloadBindings();143 void loadBindings(); 104 144 void clearBindings(bool bInit = false); 105 145 … … 107 147 108 148 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); 149 void readTrigger(Button& button); 150 151 //static void clearBundle(KeyBindingBundle& bundle, bool bInit); 152 //static void redimensionBinding(KeyBinding& binding); 112 153 113 154 void tick(float dt); 114 155 115 boolkeyPressed (const KeyEvent& evt);116 boolkeyReleased(const KeyEvent& evt);117 boolkeyHeld (const KeyEvent& evt);118 119 boolmouseButtonPressed (MouseButton::Enum id);120 boolmouseButtonReleased(MouseButton::Enum id);121 boolmouseButtonHeld (MouseButton::Enum id);122 boolmouseMoved (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize);123 boolmouseScrolled (int abs, int rel);124 125 booljoyStickButtonPressed (int joyStickID, int button);126 booljoyStickButtonReleased(int joyStickID, int button);127 booljoyStickButtonHeld (int joyStickID, int button);128 bool joyStickAxisMoved (int joyStickID, int axis, int value);156 void keyPressed (const KeyEvent& evt); 157 void keyReleased(const KeyEvent& evt); 158 void keyHeld (const KeyEvent& evt); 159 160 void mouseButtonPressed (MouseButton::Enum id); 161 void mouseButtonReleased(MouseButton::Enum id); 162 void mouseButtonHeld (MouseButton::Enum id); 163 void mouseMoved (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize); 164 void mouseScrolled (int abs, int rel); 165 166 void joyStickButtonPressed (int joyStickID, int button); 167 void joyStickButtonReleased(int joyStickID, int button); 168 void joyStickButtonHeld (int joyStickID, int button); 169 void joyStickAxisMoved (int joyStickID, int axis, int value); 129 170 130 171 private: // variables … … 132 173 static const unsigned int nKeys_s = 0xEE; 133 174 //! 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]; 175 Button keys_ [nKeys_s]; 139 176 140 177 //! denotes the number of different mouse buttons there are in OIS. 141 178 static const unsigned int nMouseButtons_s = 8; 142 179 //! 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]; 180 Button mouseButtons_ [nMouseButtons_s]; 148 181 149 182 //! denotes the number of different joy stick buttons there are in OIS. 150 183 static const unsigned int nJoyStickButtons_s = 32 + 4 * 4; // 32 buttons and 4 POVs with 4 buttons 151 184 //! 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]; 185 Button joyStickButtons_ [nJoyStickButtons_s]; 157 186 158 187 //! denotes the number of half axes (every axis twice) there can be. … … 160 189 /** 161 190 * Array with all the half axes for mouse and joy sticks. 162 * Bearin mind that the positions are fixed and that the first entry is the191 * Keep in mind that the positions are fixed and that the first entry is the 163 192 * positive one and the second is negative. 164 193 * Sequence is as follows: … … 169 198 */ 170 199 HalfAxis halfAxes_[nHalfAxes_s]; 171 //! Actual key bindings as bundle for Press, Hold and Release172 KeyBindingBundle bindingsHalfAxes_ [nHalfAxes_s];173 //! Names of the half axes174 std::string namesHalfAxes_ [nHalfAxes_s];175 //! The configured string values176 std::string bindingStringsHalfAxes_[nHalfAxes_s];177 200 178 201 /** … … 180 203 * the tick() so that all values can be buffered for single execution. 181 204 */ 182 std::vector<AxisCommand*> axisCommands_; 205 std::vector<BufferedParamCommand*> paramCommandBuffer_; 206 207 //! Threshold for analog triggers until which the state is 0. 208 float analogThreshold_; 209 //! Threshold for analog triggers until which the button is not pressed. 210 float buttonThreshold_; 183 211 }; 184 212
Note: See TracChangeset
for help on using the changeset viewer.