Changeset 1887 for code/trunk/src
- Timestamp:
- Oct 6, 2008, 12:31:32 AM (16 years ago)
- Location:
- code/trunk/src
- Files:
-
- 2 added
- 30 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/core/ArgumentCompletionFunctions.h
r1505 r1887 35 35 36 36 #define ARGUMENT_COMPLETION_FUNCTION_DECLARATION(functionname) \ 37 ArgumentCompleter* functionname(); \37 _CoreExport ArgumentCompleter* functionname(); \ 38 38 _CoreExport ArgumentCompletionList acf_##functionname 39 39 -
code/trunk/src/core/CMakeLists.txt
r1844 r1887 47 47 input/InputCommands.cc 48 48 input/InputManager.cc 49 input/JoyStickDeviceNumberListener.cc 49 50 input/KeyBinder.cc 50 51 input/KeyDetector.cc -
code/trunk/src/core/ConfigFileManager.h
r1795 r1887 45 45 CFT_Settings, 46 46 CFT_Keybindings, 47 CFT_JoyStickCalibration, 48 CFT_KeyNames 47 CFT_JoyStickCalibration 49 48 }; 50 49 -
code/trunk/src/core/ConfigValueContainer.cc
r1795 r1887 50 50 @brief Initializes the ConfigValueContainer with defaultvalues. 51 51 */ 52 void ConfigValueContainer::init(ConfigFileType type, Identifier* identifier, const std::string& varname)52 void ConfigValueContainer::init(ConfigFileType type, Identifier* identifier, const std::string& sectionname, const std::string& varname) 53 53 { 54 54 this->type_ = type; 55 55 this->identifier_ = identifier; 56 this->sectionname_ = identifier->getName();56 this->sectionname_ = sectionname; 57 57 this->varname_ = varname; 58 58 this->callback_ = 0; … … 331 331 if (!this->bAddedDescription_) 332 332 { 333 this->description_ = std::string("ConfigValueDescription::" + this-> identifier_->getName()+ "::" + this->varname_);333 this->description_ = std::string("ConfigValueDescription::" + this->sectionname_ + "::" + this->varname_); 334 334 AddLanguageEntry(this->description_, description); 335 335 this->bAddedDescription_ = true; -
code/trunk/src/core/ConfigValueContainer.h
r1747 r1887 99 99 @param type The type of the corresponding config-file 100 100 @param identifier The identifier of the class the variable belongs to 101 @param sectionname Name of the section the configValue should be put in. 101 102 @param varname The name of the variable 102 103 @param defvalue The default-value … … 104 105 */ 105 106 template <class D, class V> 106 ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, const D& defvalue, const V& value)107 { 108 this->init(type, identifier, varname);107 ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& sectionname, const std::string& varname, const D& defvalue, const V& value) 108 { 109 this->init(type, identifier, sectionname, varname); 109 110 this->initValue((V)defvalue); 110 111 } … … 118 119 */ 119 120 template <class V> 120 ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, const std::vector<V>& defvalue)121 { 122 this->init(type, identifier, varname);121 ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& sectionname, const std::string& varname, const std::vector<V>& defvalue) 122 { 123 this->init(type, identifier, sectionname, varname); 123 124 124 125 this->value_ = V(); … … 266 267 267 268 private: 268 void init(ConfigFileType type, Identifier* identifier, const std::string& varname);269 void init(ConfigFileType type, Identifier* identifier, const std::string& sectionname, const std::string& varname); 269 270 void initValue(const MultiType& defvalue); 270 271 void initVector(); -
code/trunk/src/core/ConfigValueIncludes.h
r1747 r1887 52 52 if (!container##varname) \ 53 53 { \ 54 container##varname = new orxonox::ConfigValueContainer(CFT_Settings, identifier##varname, #varname, defvalue, varname); \54 container##varname = new orxonox::ConfigValueContainer(CFT_Settings, identifier##varname, identifier##varname->getName(), #varname, defvalue, varname); \ 55 55 identifier##varname->addConfigValueContainer(#varname, container##varname); \ 56 56 } \ … … 71 71 if (!container##varname) \ 72 72 { \ 73 container##varname = new orxonox::ConfigValueContainer(CFT_Settings, identifier##varname, #varname, defvalue); \73 container##varname = new orxonox::ConfigValueContainer(CFT_Settings, identifier##varname, identifier##varname->getName(), #varname, defvalue); \ 74 74 identifier##varname->addConfigValueContainer(#varname, container##varname); \ 75 75 } \ -
code/trunk/src/core/input/Button.cc
r1783 r1887 34 34 35 35 #include "Button.h" 36 36 37 #include "util/Convert.h" 37 38 #include "util/SubString.h" … … 41 42 #include "core/CommandEvaluation.h" 42 43 #include "core/CommandExecutor.h" 43 #include " InputCommands.h"44 #include "core/ConfigValueContainer.h" 44 45 45 46 namespace orxonox 46 47 { 48 /** 49 @note 50 bButtonThresholdUser_: We set it to true so that setConfigValues in KeyBinder sets the value 51 correctly the first time. It is then set to false first and changed later in Button::parse(). 52 */ 53 Button::Button() 54 : configContainer_(0) 55 , bButtonThresholdUser_(false) 56 , paramCommandBuffer_(0) 57 { 58 nCommands_[0]=0; 59 nCommands_[1]=0; 60 nCommands_[2]=0; 61 clear(); 62 } 63 47 64 void Button::clear() 48 65 { … … 65 82 } 66 83 67 void Button::parse(std::vector<BufferedParamCommand*>& paramCommandBuffer) 68 { 84 void Button::readConfigValue() 85 { 86 // create/get ConfigValueContainer 87 if (!configContainer_) 88 { 89 configContainer_ = new ConfigValueContainer(CFT_Keybindings, 0, groupName_, name_, "", name_); 90 configContainer_->callback(this, &Button::parse); 91 } 92 configContainer_->getValue(&bindingString_, this); 93 } 94 95 void Button::parse() 96 { 97 // delete all commands 98 clear(); 99 69 100 if (isEmpty(bindingString_)) 70 {71 clear();72 101 return; 73 } 102 103 // reset this to false first when parsing (was true before when parsing for the first time) 104 bButtonThresholdUser_ = false; 74 105 75 106 // use std::vector for a temporary dynamic array 76 107 std::vector<BaseCommand*> commands[3]; 77 78 108 79 109 // separate the commands … … 112 142 parseError("Could not parse 'ButtonThreshold' argument. \ 113 143 Switching to default value.", true); 144 else 145 this->bButtonThresholdUser_ = true; 114 146 } 115 147 else if (token == "scale") … … 152 184 153 185 // add command to the buffer if not yet existing 154 for (unsigned int iParamCmd = 0; iParamCmd < paramCommandBuffer .size(); iParamCmd++)155 { 156 if (getLowercase( paramCommandBuffer[iParamCmd]->evaluation_.getOriginalCommand())186 for (unsigned int iParamCmd = 0; iParamCmd < paramCommandBuffer_->size(); iParamCmd++) 187 { 188 if (getLowercase((*paramCommandBuffer_)[iParamCmd]->evaluation_.getOriginalCommand()) 157 189 == getLowercase(commandStr)) 158 190 { 159 191 // already in list 160 cmd->paramCommand_ = paramCommandBuffer[iParamCmd];192 cmd->paramCommand_ = (*paramCommandBuffer_)[iParamCmd]; 161 193 break; 162 194 } … … 165 197 { 166 198 cmd->paramCommand_ = new BufferedParamCommand(); 167 paramCommandBuffer .push_back(cmd->paramCommand_);199 paramCommandBuffer_->push_back(cmd->paramCommand_); 168 200 cmd->paramCommand_->evaluation_ = eval; 169 201 cmd->paramCommand_->paramIndex_ = paramIndex; … … 208 240 } 209 241 210 bool Button::execute(KeybindMode::Enum mode, float abs, float rel)211 {212 // execute all the parsed commands in the string213 for (unsigned int iCommand = 0; iCommand < nCommands_[mode]; iCommand++)214 commands_[mode][iCommand]->execute(abs, rel);215 return true;216 }217 218 242 inline void Button::parseError(std::string message, bool serious) 219 243 { -
code/trunk/src/core/input/Button.h
r1755 r1887 40 40 #include <string> 41 41 #include <vector> 42 #include "InputCommands.h" 42 43 43 44 namespace orxonox … … 46 47 { 47 48 public: 48 Button() { nCommands_[0]=0; nCommands_[1]=0; nCommands_[2]=0; clear(); }49 Button(); 49 50 virtual ~Button() { clear(); } 50 51 virtual void clear(); 51 52 virtual bool addParamCommand(ParamCommand* command) { return false; } 52 void parse(std::vector<BufferedParamCommand*>& paramCommandBuffer); 53 void parse(); 54 void readConfigValue(); 53 55 bool execute(KeybindMode::Enum mode, float abs = 1.0f, float rel = 1.0f); 54 56 57 //! Container to allow for better configValue support 58 ConfigValueContainer* configContainer_; 55 59 //! The configured string value 56 60 std::string bindingString_; 57 61 //! Name of the trigger as strings 58 62 std::string name_; 63 //! Name of the group of input triggers 64 std::string groupName_; 59 65 //! Basic commands for OnPress, OnHold and OnRelease 60 66 BaseCommand** commands_[3]; … … 64 70 //! Note: This variable is here to have only one parse() function. 65 71 float buttonThreshold_; 72 bool bButtonThresholdUser_; 73 //! Pointer to the list of parametrised commands 74 std::vector<BufferedParamCommand*>* paramCommandBuffer_; 66 75 67 76 private: 68 77 void parseError(std::string message, bool serious); 69 78 }; 79 80 inline bool Button::execute(KeybindMode::Enum mode, float abs, float rel) 81 { 82 // execute all the parsed commands in the string 83 for (unsigned int iCommand = 0; iCommand < nCommands_[mode]; iCommand++) 84 commands_[mode][iCommand]->execute(abs, rel); 85 return true; 86 } 87 70 88 } 71 89 -
code/trunk/src/core/input/ExtendedInputState.cc
r1881 r1887 92 92 } 93 93 94 void ExtendedInputState::mouseButtonPressed(MouseButton ::Enum id)94 void ExtendedInputState::mouseButtonPressed(MouseButtonCode::ByEnum id) 95 95 { 96 96 for (unsigned int i = 0; i < mouseHandlers_.size(); i++) … … 98 98 } 99 99 100 void ExtendedInputState::mouseButtonReleased(MouseButton ::Enum id)100 void ExtendedInputState::mouseButtonReleased(MouseButtonCode::ByEnum id) 101 101 { 102 102 for (unsigned int i = 0; i < mouseHandlers_.size(); i++) … … 104 104 } 105 105 106 void ExtendedInputState::mouseButtonHeld(MouseButton ::Enum id)106 void ExtendedInputState::mouseButtonHeld(MouseButtonCode::ByEnum id) 107 107 { 108 108 for (unsigned int i = 0; i < mouseHandlers_.size(); i++) … … 118 118 } 119 119 120 void ExtendedInputState::joyStickButtonPressed(unsigned int joyStickID, JoyStickButton ::Enum id)120 void ExtendedInputState::joyStickButtonPressed(unsigned int joyStickID, JoyStickButtonCode::ByEnum id) 121 121 { 122 122 assert(joyStickID < joyStickHandlers_.size()); … … 125 125 } 126 126 127 void ExtendedInputState::joyStickButtonReleased(unsigned int joyStickID, JoyStickButton ::Enum id)127 void ExtendedInputState::joyStickButtonReleased(unsigned int joyStickID, JoyStickButtonCode::ByEnum id) 128 128 { 129 129 assert(joyStickID < joyStickHandlers_.size()); … … 132 132 } 133 133 134 void ExtendedInputState::joyStickButtonHeld(unsigned int joyStickID, JoyStickButton ::Enum id)134 void ExtendedInputState::joyStickButtonHeld(unsigned int joyStickID, JoyStickButtonCode::ByEnum id) 135 135 { 136 136 assert(joyStickID < joyStickHandlers_.size()); -
code/trunk/src/core/input/ExtendedInputState.h
r1881 r1887 75 75 void keyHeld (const KeyEvent& evt); 76 76 77 void mouseButtonPressed (MouseButton ::Enum id);78 void mouseButtonReleased(MouseButton ::Enum id);79 void mouseButtonHeld (MouseButton ::Enum id);77 void mouseButtonPressed (MouseButtonCode::ByEnum id); 78 void mouseButtonReleased(MouseButtonCode::ByEnum id); 79 void mouseButtonHeld (MouseButtonCode::ByEnum id); 80 80 void mouseMoved (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize); 81 81 void mouseScrolled (int abs, int rel); 82 82 83 void joyStickButtonPressed (unsigned int joyStickID, JoyStickButton ::Enum id);84 void joyStickButtonReleased(unsigned int joyStickID, JoyStickButton ::Enum id);85 void joyStickButtonHeld (unsigned int joyStickID, JoyStickButton ::Enum id);83 void joyStickButtonPressed (unsigned int joyStickID, JoyStickButtonCode::ByEnum id); 84 void joyStickButtonReleased(unsigned int joyStickID, JoyStickButtonCode::ByEnum id); 85 void joyStickButtonHeld (unsigned int joyStickID, JoyStickButtonCode::ByEnum id); 86 86 void joyStickAxisMoved (unsigned int joyStickID, unsigned int axis, float value); void updateTickables(); 87 87 -
code/trunk/src/core/input/HalfAxis.cc
r1755 r1887 35 35 #include "HalfAxis.h" 36 36 #include "core/CommandEvaluation.h" 37 #include "InputCommands.h"38 37 39 38 namespace orxonox … … 68 67 return true; 69 68 } 70 71 bool HalfAxis::execute()72 {73 bool success = true;74 for (unsigned int i = 0; i < nParamCommands_; i++)75 success = success && paramCommands_[i]->execute(absVal_, relVal_);76 return success;77 }78 69 } -
code/trunk/src/core/input/HalfAxis.h
r1755 r1887 38 38 #include "core/CorePrereqs.h" 39 39 #include "Button.h" 40 #include "InputCommands.h" 40 41 41 42 namespace orxonox … … 67 68 bool hasChanged_; 68 69 }; 70 71 inline bool HalfAxis::execute() 72 { 73 bool success = true; 74 for (unsigned int i = 0; i < nParamCommands_; i++) 75 success = paramCommands_[i]->execute(absVal_, relVal_) && success; 76 return success; 77 } 69 78 } 70 79 -
code/trunk/src/core/input/InputBuffer.h
r1755 r1887 44 44 public: 45 45 BaseInputBufferListenerTuple(bool bListenToAllChanges, bool bOnlySingleInput, 46 bool trueKeyFalseChar, char _char, KeyCode:: Enum key)46 bool trueKeyFalseChar, char _char, KeyCode::ByEnum key) 47 47 : bListenToAllChanges_(bListenToAllChanges), bOnlySingleInput_(bOnlySingleInput), 48 48 trueKeyFalseChar_(trueKeyFalseChar), char_(_char), key_(key) … … 54 54 bool trueKeyFalseChar_; 55 55 char char_; 56 KeyCode:: Enum key_;56 KeyCode::ByEnum key_; 57 57 }; 58 58 … … 62 62 public: 63 63 InputBufferListenerTuple(T* listener, void (T::*function)(), bool bListenToAllChanges, 64 bool bOnlySingleInput, bool trueKeyFalseChar, char _char, KeyCode:: Enum key)64 bool bOnlySingleInput, bool trueKeyFalseChar, char _char, KeyCode::ByEnum key) 65 65 : BaseInputBufferListenerTuple(bListenToAllChanges, bOnlySingleInput, trueKeyFalseChar, _char, key), 66 66 listener_(listener), function_(function) … … 109 109 110 110 template <class T> 111 void registerListener(T* listener, void (T::*function)(), KeyCode:: Enum key)111 void registerListener(T* listener, void (T::*function)(), KeyCode::ByEnum key) 112 112 { 113 113 InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, false, true, true, '\0', key); … … 115 115 } 116 116 template <class T> 117 void registerListener(T* listener, void (T::*function)() const, KeyCode:: Enum key)117 void registerListener(T* listener, void (T::*function)() const, KeyCode::ByEnum key) 118 118 { 119 119 InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, false, true, true, '\0', key); … … 178 178 unsigned int cursor_; 179 179 180 KeyCode:: Enum lastKey_;180 KeyCode::ByEnum lastKey_; 181 181 float timeSinceKeyPressed_; 182 182 float timeSinceKeyRepeated_; -
code/trunk/src/core/input/InputCommands.cc
r1755 r1887 65 65 66 66 // ############################### 67 // ##### SimpleCommand #####68 // ###############################69 70 /**71 @brief72 Executes a simple command with no additional paramters.73 @return74 True if command execution was successful, false otherwise.75 */76 bool SimpleCommand::execute(float abs, float rel)77 {78 return evaluation_.execute();79 }80 81 // ###############################82 67 // ##### ParamCommand ##### 83 68 // ############################### -
code/trunk/src/core/input/InputCommands.h
r1755 r1887 68 68 }; 69 69 70 /** 71 @brief 72 Executes a simple command with no additional paramters. 73 @return 74 True if command execution was successful, false otherwise. 75 */ 76 inline bool SimpleCommand::execute(float abs, float rel) 77 { 78 return evaluation_.execute(); 79 } 80 70 81 class _CoreExport ParamCommand : public BaseCommand 71 82 { -
code/trunk/src/core/input/InputInterfaces.h
r1878 r1887 47 47 namespace KeyCode 48 48 { 49 const unsigned int numberOfKeys = 0xEE; // 238 50 49 51 // note: KeyCode comments were directly copied from OISKeyboard.h 50 enum Enum52 enum ByEnum 51 53 { 52 54 Unassigned = OIS::KC_UNASSIGNED, … … 119 121 F9 = OIS::KC_F9, 120 122 F10 = OIS::KC_F10, 121 Num lock = OIS::KC_NUMLOCK,122 Scroll lock = OIS::KC_SCROLL, // Scroll Lock123 NumLock = OIS::KC_NUMLOCK, 124 ScrollLock = OIS::KC_SCROLL, // Scroll Lock 123 125 Numpad7 = OIS::KC_NUMPAD7, 124 126 Numpad8 = OIS::KC_NUMPAD8, … … 167 169 NumpadComma = OIS::KC_NUMPADCOMMA, // , on numeric keypad (NEC PC98) 168 170 Divide = OIS::KC_DIVIDE, // / on numeric keypad 169 S YSRQ= OIS::KC_SYSRQ,171 SystemRequest = OIS::KC_SYSRQ, 170 172 RightAlt = OIS::KC_RMENU, // right Alt 171 173 Pause = OIS::KC_PAUSE, // Pause … … 196 198 MediaSelect = OIS::KC_MEDIASELECT // Media Select 197 199 }; 198 } 199 200 namespace MouseButton 201 { 202 enum Enum 200 201 // Names as string. Has no real linkage! 202 const char* const ByString[] = 203 { 204 "Unassigned", 205 "Escape", 206 "NumRow1", "NumRow2", "NumRow3", "NumRow4", "NumRow5", 207 "NumRow6", "NumRow7", "NumRow8", "NumRow9", "NumRow0", 208 "Minus", "Equals", "Back", "Tab", 209 "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", 210 "LeftBracket", "RightBracket", 211 "Return", "LeftControl", 212 "A", "S", "D", "F", "G", "H", "J", "K", "L", 213 "Semicolon", "Apostrophe", "Grave", 214 "LeftShift", "Backslash", 215 "Z", "X", "C", "V", "B", "N", "M", 216 "Comma", "Period", "Slash", 217 "RightShift", 218 "Multiply", 219 "LeftAlt", 220 "Space", 221 "CapsLock", 222 "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", 223 "NumLock", "ScrollLock", 224 "Numpad7", "Numpad8", "Numpad9", 225 "NumpadSubtract", 226 "Numpad4", "Numpad5", "Numpad6", 227 "NumpadAdd", 228 "Numpad1", "Numpad2", "Numpad3", "Numpad0", 229 "NumpadPeriod", 230 "","", 231 "LessThan", 232 "F11", "F12", 233 "","","","","","","","","","","", 234 "F13", "F14", "F15", 235 "","","","","","","","","","", 236 "Kana", 237 "","", 238 "ABNT_C1", 239 "","","","","", 240 "Convert", 241 "", 242 "NoConvert", 243 "", 244 "Yen", 245 "ABNT_C2", 246 "","","","","","","","","","","","","","", 247 "NumpadEquals", 248 "","", 249 "PreviousTrack", 250 "AT", 251 "Colon", "Underline", 252 "Kanji", 253 "Stop", 254 "AX", 255 "Unlabeled", 256 "NextTrack", 257 "","", 258 "NumpadEnter", 259 "RightControl", 260 "","", 261 "Mute", 262 "Calculator", 263 "PlayPause", 264 "", 265 "MediaStop", 266 "","","","","","","","","", 267 "VolumeDown", 268 "", 269 "VolumeUp", 270 "", 271 "WebHome", 272 "NumpadComma", 273 "", 274 "Divide", 275 "", 276 "SystemRequest", 277 "RightAlt", 278 "","","","","","","","","","","","", 279 "Pause", 280 "", 281 "Home", 282 "UP", 283 "PageUp", 284 "", 285 "Left", 286 "", 287 "Right", 288 "", 289 "End", "Down", "PageDown", "Insert", "Delete", 290 "","","","","","","", 291 "LeftWindows", "RightWindows", "Apps", 292 "Power", "Sleep", 293 "","","", 294 "Wake", 295 "", 296 "WebSearch", "WebFavorites", "WebRefresh", "WebStop", "WebForward", "WebBack", 297 "MyComputer", "Mail", "MediaSelect" 298 }; 299 } 300 301 namespace MouseButtonCode 302 { 303 const unsigned int numberOfButtons = 8; 304 305 enum ByEnum 203 306 { 204 307 Left = OIS::MB_Left, … … 209 312 Button5 = OIS::MB_Button5, 210 313 Button6 = OIS::MB_Button6, 211 Button7 = OIS::MB_Button7 212 }; 213 } 214 215 namespace JoyStickButton 216 { 217 enum Enum 314 Button7 = OIS::MB_Button7, 315 }; 316 317 // Names as string. Has no real linkage! 318 const char* const ByString[] = 319 { 320 "Left", 321 "Right", 322 "Middle", 323 "Button3", 324 "Button4", 325 "Button5", 326 "Button6", 327 "Button7", 328 }; 329 } 330 331 namespace MouseAxisCode 332 { 333 const unsigned int numberOfAxes = 2; 334 335 enum ByEnum 336 { 337 X, 338 Y 339 }; 340 341 // Names as string. Has no real linkage! 342 const char* const ByString[] = 343 { 344 "X", 345 "Y" 346 }; 347 } 348 349 namespace JoyStickButtonCode 350 { 351 const unsigned int numberOfButtons = 64; 352 353 enum ByEnum 218 354 { 219 355 Button0 = 0, Button1 = 1, Button2 = 2, Button3 = 3, … … 238 374 POV3NorthEast = 60, POV3SouthEast = 61, POV3NorthWest = 62, POV3SouthWest = 63, 239 375 }; 376 377 // Names as string. Has no real linkage! 378 const char* const ByString[] = 379 { 380 "Button0", "Button1", "Button2", "Button3", 381 "Button4", "Button5", "Button6", "Button7", 382 "Button8", "Button9", "Button10", "Button11", 383 "Button12", "Button13", "Button14", "Button15", 384 "Button16", "Button17", "Button18", "Button19", 385 "Button20", "Button21", "Button22", "Button23", 386 "Button24", "Button25", "Button26", "Button27", 387 "Button28", "Button29", "Button30", "Button31", 388 "POV0North", "POV0South", "POV0East", "POV0West", 389 "POV0NorthEast", "POV0SouthEast", "POV0NorthWest", "POV0SouthWest", 390 "POV1North", "POV1South", "POV1East", "POV1West", 391 "POV1NorthEast", "POV1SouthEast", "POV1NorthWest", "POV1SouthWest", 392 "POV2North", "POV2South", "POV2East", "POV2West", 393 "POV2NorthEast", "POV2SouthEast", "POV2NorthWest", "POV2SouthWest", 394 "POV3North", "POV3South", "POV3East", "POV3West", 395 "POV3NorthEast", "POV3SouthEast", "POV3NorthWest", "POV3SouthWest" 396 }; 397 } 398 399 namespace JoyStickAxisCode 400 { 401 const unsigned int numberOfAxes = 24; 402 403 enum ByEnum 404 { 405 Slider0 = 0, Slider1 = 1, Slider2 = 2, Slider3 = 3, 406 Slider4 = 4, Slider5 = 5, Slider6 = 6, Slider7 = 7, 407 Axis0 = 8, Axis1 = 9, Axis2 = 10, Axis3 = 11, 408 Axis4 = 12, Axis5 = 13, Axis6 = 14, Axis7 = 15, 409 Axis8 = 16, Axis9 = 17, Axis10 = 18, Axis11 = 19, 410 Axis12 = 20, Axis13 = 21, Axis14 = 22, Axis15 = 23 411 }; 412 413 // Names as string. Has no real linkage! 414 const char* const ByString[] = 415 { 416 "Slider0", "Slider1", "Slider2", "Slider3", 417 "Slider4", "Slider5", "Slider6", "Slider7", 418 "Axis0", "Axis1", "Axis2", "Axis3", 419 "Axis4", "Axis5", "Axis6", "Axis7", 420 "Axis8", "Axis9", "Axis10", "Axis11", 421 "Axis12", "Axis13", "Axis14", "Axis15" 422 }; 240 423 } 241 424 … … 259 442 JoyStick1, 260 443 JoyStick2, 261 JoyStick3 ,444 JoyStick3 262 445 // note: No problem if there are more joy sticks. This enum is just for convenience. 263 446 }; … … 266 449 struct _CoreExport Key 267 450 { 268 Key(const OIS::KeyEvent& evt) : key((KeyCode:: Enum)evt.key), text(evt.text) { }269 KeyCode:: Enum key;451 Key(const OIS::KeyEvent& evt) : key((KeyCode::ByEnum)evt.key), text(evt.text) { } 452 KeyCode::ByEnum key; 270 453 unsigned int text; 271 454 }; … … 274 457 { 275 458 public: 276 KeyEvent(KeyCode:: Enum key, unsigned int text) : key(key), text(text) { }459 KeyEvent(KeyCode::ByEnum key, unsigned int text) : key(key), text(text) { } 277 460 KeyEvent(const OIS::KeyEvent& evt, unsigned int mod) 278 : key((KeyCode:: Enum)evt.key), text(evt.text), modifiers(mod) { }461 : key((KeyCode::ByEnum)evt.key), text(evt.text), modifiers(mod) { } 279 462 KeyEvent(const Key& key, unsigned int mod) : key(key.key), text(key.text), modifiers(mod) { } 280 463 bool isModifierDown(KeyboardModifier::Enum modifier) const 281 464 { return (KeyboardModifier::Enum)modifier&modifiers; } 282 465 283 const KeyCode:: Enum key;466 const KeyCode::ByEnum key; 284 467 unsigned int text; 285 468 unsigned int modifiers; … … 316 499 public: 317 500 virtual ~MouseHandler() { } 318 virtual void mouseButtonPressed (MouseButton ::Enum id) = 0;319 virtual void mouseButtonReleased(MouseButton ::Enum id) = 0;320 virtual void mouseButtonHeld (MouseButton ::Enum id) = 0;501 virtual void mouseButtonPressed (MouseButtonCode::ByEnum id) = 0; 502 virtual void mouseButtonReleased(MouseButtonCode::ByEnum id) = 0; 503 virtual void mouseButtonHeld (MouseButtonCode::ByEnum id) = 0; 321 504 virtual void mouseMoved (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) = 0; 322 505 virtual void mouseScrolled (int abs, int rel) = 0; … … 333 516 public: 334 517 virtual ~JoyStickHandler() { } 335 virtual void joyStickButtonPressed (unsigned int joyStickID, JoyStickButton ::Enum id) = 0;336 virtual void joyStickButtonReleased(unsigned int joyStickID, JoyStickButton ::Enum id) = 0;337 virtual void joyStickButtonHeld (unsigned int joyStickID, JoyStickButton ::Enum id) = 0;518 virtual void joyStickButtonPressed (unsigned int joyStickID, JoyStickButtonCode::ByEnum id) = 0; 519 virtual void joyStickButtonReleased(unsigned int joyStickID, JoyStickButtonCode::ByEnum id) = 0; 520 virtual void joyStickButtonHeld (unsigned int joyStickID, JoyStickButtonCode::ByEnum id) = 0; 338 521 virtual void joyStickAxisMoved (unsigned int joyStickID, unsigned int axis, float value) = 0; 339 522 virtual void tickJoyStick (float dt, unsigned int joyStick) = 0; … … 357 540 void keyHeld (const KeyEvent& evt) { } 358 541 359 void mouseButtonPressed (MouseButton ::Enum id) { }360 void mouseButtonReleased(MouseButton ::Enum id) { }361 void mouseButtonHeld (MouseButton ::Enum id) { }542 void mouseButtonPressed (MouseButtonCode::ByEnum id) { } 543 void mouseButtonReleased(MouseButtonCode::ByEnum id) { } 544 void mouseButtonHeld (MouseButtonCode::ByEnum id) { } 362 545 void mouseMoved (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) { } 363 546 void mouseScrolled (int abs, int rel) { } 364 547 365 void joyStickButtonPressed (unsigned int joyStickID, JoyStickButton ::Enum id) { }366 void joyStickButtonReleased(unsigned int joyStickID, JoyStickButton ::Enum id) { }367 void joyStickButtonHeld (unsigned int joyStickID, JoyStickButton ::Enum id) { }548 void joyStickButtonPressed (unsigned int joyStickID, JoyStickButtonCode::ByEnum id) { } 549 void joyStickButtonReleased(unsigned int joyStickID, JoyStickButtonCode::ByEnum id) { } 550 void joyStickButtonHeld (unsigned int joyStickID, JoyStickButtonCode::ByEnum id) { } 368 551 void joyStickAxisMoved (unsigned int joyStickID, unsigned int axis, float value) { } 369 552 }; -
code/trunk/src/core/input/InputManager.cc
r1881 r1887 56 56 #include "SimpleInputState.h" 57 57 #include "ExtendedInputState.h" 58 #include "JoyStickDeviceNumberListener.h" 58 59 59 60 namespace orxonox 60 61 { 61 SetConsoleCommand(InputManager, keyBind, true);62 SetConsoleCommand(InputManager, storeKeyStroke, true);63 62 SetConsoleCommand(InputManager, calibrate, true); 64 63 SetConsoleCommand(InputManager, reload, false); … … 165 164 if (joyStickSupport) 166 165 _initialiseJoySticks(); 166 // Do this anyway to also inform everyone if a joystick was detached. 167 _configureNumberOfJoySticks(); 167 168 168 169 // Set mouse/joystick region … … 197 198 stateMaster_ = new ExtendedInputState(); 198 199 stateMaster_->setName("master"); 200 stateMaster_->setNumOfJoySticks(joySticksSize_); 199 201 200 202 // KeyDetector to evaluate a pressed key's name 201 203 SimpleInputState* detector = createInputState<SimpleInputState>("detector", 101); 202 204 keyDetector_ = new KeyDetector(); 203 keyDetector_->loadBindings("storeKeyStroke");204 205 detector->setHandler(keyDetector_); 205 206 … … 320 321 //CCOUT(ORX_WARNING) << "Warning: Joy stick support requested, but no joy stick was found" << std::endl; 321 322 } 322 _redimensionLists();323 323 } 324 324 … … 331 331 occupy 2 places in the device number dependent lists. 332 332 */ 333 void InputManager::_ redimensionLists()333 void InputManager::_configureNumberOfJoySticks() 334 334 { 335 335 joySticksSize_ = joySticks_.size(); … … 357 357 for (std::map<int, InputState*>::const_iterator it = inputStatesByPriority_.begin(); 358 358 it != inputStatesByPriority_.end(); ++it) 359 { 359 360 it->second->setNumOfJoySticks(joySticksSize_); 361 } 362 // inform master state 363 if (stateMaster_) 364 this->stateMaster_->setNumOfJoySticks(joySticksSize_); 365 366 // inform all JoyStick Device Number Listeners 367 for (ObjectList<JoyStickDeviceNumberListener>::iterator it = ObjectList<JoyStickDeviceNumberListener>::begin(); it; ++it) 368 it->JoyStickDeviceNumberChanged(joySticksSize_); 369 360 370 } 361 371 … … 385 395 if (!cont) 386 396 { 387 cont = new ConfigValueContainer(CFT_Settings, getIdentifier(), "CoeffPos", coeffPos);397 cont = new ConfigValueContainer(CFT_Settings, getIdentifier(), getIdentifier()->getName(), "CoeffPos", coeffPos); 388 398 getIdentifier()->addConfigValueContainer("CoeffPos", cont); 389 399 } … … 393 403 if (!cont) 394 404 { 395 cont = new ConfigValueContainer(CFT_Settings, getIdentifier(), "CoeffNeg", coeffNeg);405 cont = new ConfigValueContainer(CFT_Settings, getIdentifier(), getIdentifier()->getName(), "CoeffNeg", coeffNeg); 396 406 getIdentifier()->addConfigValueContainer("CoeffNeg", cont); 397 407 } … … 401 411 if (!cont) 402 412 { 403 cont = new ConfigValueContainer(CFT_Settings, getIdentifier(), "Zero", zero);413 cont = new ConfigValueContainer(CFT_Settings, getIdentifier(), getIdentifier()->getName(), "Zero", zero); 404 414 getIdentifier()->addConfigValueContainer("Zero", cont); 405 415 } … … 515 525 516 526 joySticks_.clear(); 517 // don't use _ redimensionLists(), might mess with registered handler if527 // don't use _configureNumberOfJoySticks(), might mess with registered handler if 518 528 // downgrading from 2 to 1 joystick 519 //_ redimensionLists();529 //_configureNumberOfJoySticks(); 520 530 joySticksSize_ = 0; 521 531 } … … 875 885 // check whether the key already is in the list (can happen when focus was lost) 876 886 unsigned int iKey = 0; 877 while (iKey < keysDown_.size() && keysDown_[iKey].key != (KeyCode:: Enum)e.key)887 while (iKey < keysDown_.size() && keysDown_[iKey].key != (KeyCode::ByEnum)e.key) 878 888 iKey++; 879 889 if (iKey == keysDown_.size()) … … 912 922 for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++) 913 923 { 914 if (keysDown_[iKey].key == (KeyCode:: Enum)e.key)924 if (keysDown_[iKey].key == (KeyCode::ByEnum)e.key) 915 925 { 916 926 keysDown_.erase(keysDown_.begin() + iKey); … … 977 987 // check whether the button already is in the list (can happen when focus was lost) 978 988 unsigned int iButton = 0; 979 while (iButton < mouseButtonsDown_.size() && mouseButtonsDown_[iButton] != (MouseButton ::Enum)id)989 while (iButton < mouseButtonsDown_.size() && mouseButtonsDown_[iButton] != (MouseButtonCode::ByEnum)id) 980 990 iButton++; 981 991 if (iButton == mouseButtonsDown_.size()) 982 mouseButtonsDown_.push_back((MouseButton ::Enum)id);983 984 activeStatesTop_[Mouse]->mouseButtonPressed((MouseButton ::Enum)id);985 stateMaster_->mouseButtonPressed((MouseButton ::Enum)id);992 mouseButtonsDown_.push_back((MouseButtonCode::ByEnum)id); 993 994 activeStatesTop_[Mouse]->mouseButtonPressed((MouseButtonCode::ByEnum)id); 995 stateMaster_->mouseButtonPressed((MouseButtonCode::ByEnum)id); 986 996 987 997 return true; … … 1001 1011 for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++) 1002 1012 { 1003 if (mouseButtonsDown_[iButton] == (MouseButton ::Enum)id)1013 if (mouseButtonsDown_[iButton] == (MouseButtonCode::ByEnum)id) 1004 1014 { 1005 1015 mouseButtonsDown_.erase(mouseButtonsDown_.begin() + iButton); … … 1008 1018 } 1009 1019 1010 activeStatesTop_[Mouse]->mouseButtonReleased((MouseButton ::Enum)id);1011 stateMaster_->mouseButtonReleased((MouseButton ::Enum)id);1020 activeStatesTop_[Mouse]->mouseButtonReleased((MouseButtonCode::ByEnum)id); 1021 stateMaster_->mouseButtonReleased((MouseButtonCode::ByEnum)id); 1012 1022 1013 1023 return true; … … 1038 1048 1039 1049 // check whether the button already is in the list (can happen when focus was lost) 1040 std::vector<JoyStickButton ::Enum>& buttonsDown = joyStickButtonsDown_[iJoyStick];1050 std::vector<JoyStickButtonCode::ByEnum>& buttonsDown = joyStickButtonsDown_[iJoyStick]; 1041 1051 unsigned int iButton = 0; 1042 1052 while (iButton < buttonsDown.size() && buttonsDown[iButton] != button) 1043 1053 iButton++; 1044 1054 if (iButton == buttonsDown.size()) 1045 buttonsDown.push_back((JoyStickButton ::Enum)button);1046 1047 activeStatesTop_[2 + iJoyStick]->joyStickButtonPressed(iJoyStick, (JoyStickButton ::Enum)button);1048 stateMaster_->joyStickButtonPressed(iJoyStick, (JoyStickButton ::Enum)button);1055 buttonsDown.push_back((JoyStickButtonCode::ByEnum)button); 1056 1057 activeStatesTop_[2 + iJoyStick]->joyStickButtonPressed(iJoyStick, (JoyStickButtonCode::ByEnum)button); 1058 stateMaster_->joyStickButtonPressed(iJoyStick, (JoyStickButtonCode::ByEnum)button); 1049 1059 1050 1060 return true; … … 1056 1066 1057 1067 // remove the button from the joyStickButtonsDown_ list 1058 std::vector<JoyStickButton ::Enum>& buttonsDown = joyStickButtonsDown_[iJoyStick];1068 std::vector<JoyStickButtonCode::ByEnum>& buttonsDown = joyStickButtonsDown_[iJoyStick]; 1059 1069 for (unsigned int iButton = 0; iButton < buttonsDown.size(); iButton++) 1060 1070 { … … 1066 1076 } 1067 1077 1068 activeStatesTop_[2 + iJoyStick]->joyStickButtonReleased(iJoyStick, (JoyStickButton ::Enum)button);1069 stateMaster_->joyStickButtonReleased(iJoyStick, (JoyStickButton ::Enum)button);1078 activeStatesTop_[2 + iJoyStick]->joyStickButtonReleased(iJoyStick, (JoyStickButtonCode::ByEnum)button); 1079 stateMaster_->joyStickButtonReleased(iJoyStick, (JoyStickButtonCode::ByEnum)button); 1070 1080 1071 1081 return true; … … 1177 1187 } 1178 1188 1189 /** 1190 @brief 1191 Sets the the name of the command used by the KeyDetector as callback. 1192 @param command 1193 Command name as string 1194 */ 1195 void InputManager::setKeyDetectorCallback(const std::string& command) 1196 { 1197 this->keyDetector_->setCallbackCommand(command); 1198 } 1179 1199 1180 1200 // ###### InputStates ###### … … 1356 1376 /** 1357 1377 @brief 1358 Method for easily storing a string with the command executor. It is used by the1359 KeyDetector to get assign commands. The KeyDetector simply executes1360 the command 'storeKeyStroke myName' for each button/axis.1361 @remarks1362 This is only a temporary hack until we thourouhgly support multiple KeyBinders.1363 @param name1364 The name of the button/axis.1365 */1366 void InputManager::storeKeyStroke(const std::string& name)1367 {1368 getInstance().requestLeaveState("detector");1369 COUT(0) << "Binding string \"" << bindingCommmandString_s << "\" on key '" << name << "'" << std::endl;1370 CommandExecutor::execute("config KeyBinder " + name + " " + bindingCommmandString_s, false);1371 }1372 1373 /**1374 @brief1375 Assigns a command string to a key/button/axis. The name is determined via KeyDetector1376 and InputManager::storeKeyStroke(.).1377 @param command1378 Command string that can be executed by the CommandExecutor1379 */1380 void InputManager::keyBind(const std::string& command)1381 {1382 bindingCommmandString_s = command;1383 getInstance().requestEnterState("detector");1384 COUT(0) << "Press any button/key or move a mouse/joystick axis" << std::endl;1385 }1386 1387 /**1388 @brief1389 1378 Starts joy stick calibration. 1390 1379 */ -
code/trunk/src/core/input/InputManager.h
r1881 r1887 110 110 void clearBuffers(); 111 111 112 int numberOfKeyboards() { return keyboard_ ? 1 : 0; }113 int numberOfMice() { return mouse_ ? 1 : 0; }114 int numberOfJoySticks() { return joySticksSize_; }112 unsigned int numberOfKeyboards() { return keyboard_ ? 1 : 0; } 113 unsigned int numberOfMice() { return mouse_ ? 1 : 0; } 114 unsigned int numberOfJoySticks() { return joySticksSize_; } 115 115 116 116 void setWindowExtents(const int width, const int height); 117 void setKeyDetectorCallback(const std::string& command); 117 118 118 119 template <class T> … … 132 133 133 134 // console commands 134 static void storeKeyStroke(const std::string& name);135 static void keyBind(const std::string& command);136 135 static void calibrate(); 137 136 static void reload(bool joyStickSupport = true); … … 148 147 void _initialiseMouse(); 149 148 void _initialiseJoySticks(); 150 void _ redimensionLists();149 void _configureNumberOfJoySticks(); 151 150 152 151 void _destroyKeyboard(); … … 223 222 224 223 std::vector<Key> keysDown_; 225 std::vector<MouseButton ::Enum> mouseButtonsDown_;226 std::vector<std::vector<JoyStickButton ::Enum> > joyStickButtonsDown_;224 std::vector<MouseButtonCode::ByEnum> mouseButtonsDown_; 225 std::vector<std::vector<JoyStickButtonCode::ByEnum> > joyStickButtonsDown_; 227 226 228 227 static std::string bindingCommmandString_s; -
code/trunk/src/core/input/InputState.h
r1880 r1887 78 78 virtual void keyHeld (const KeyEvent& evt) = 0; 79 79 80 virtual void mouseButtonPressed (MouseButton ::Enum id) = 0;81 virtual void mouseButtonReleased(MouseButton ::Enum id) = 0;82 virtual void mouseButtonHeld (MouseButton ::Enum id) = 0;80 virtual void mouseButtonPressed (MouseButtonCode::ByEnum id) = 0; 81 virtual void mouseButtonReleased(MouseButtonCode::ByEnum id) = 0; 82 virtual void mouseButtonHeld (MouseButtonCode::ByEnum id) = 0; 83 83 virtual void mouseMoved (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) = 0; 84 84 virtual void mouseScrolled (int abs, int rel) = 0; 85 85 86 virtual void joyStickButtonPressed (unsigned int joyStickID, JoyStickButton ::Enum id) = 0;87 virtual void joyStickButtonReleased(unsigned int joyStickID, JoyStickButton ::Enum id) = 0;88 virtual void joyStickButtonHeld (unsigned int joyStickID, JoyStickButton ::Enum id) = 0;86 virtual void joyStickButtonPressed (unsigned int joyStickID, JoyStickButtonCode::ByEnum id) = 0; 87 virtual void joyStickButtonReleased(unsigned int joyStickID, JoyStickButtonCode::ByEnum id) = 0; 88 virtual void joyStickButtonHeld (unsigned int joyStickID, JoyStickButtonCode::ByEnum id) = 0; 89 89 virtual void joyStickAxisMoved (unsigned int joyStickID, unsigned int axis, float value) = 0; 90 90 -
code/trunk/src/core/input/KeyBinder.cc
r1795 r1887 41 41 #include "core/ConfigFileManager.h" 42 42 #include "InputCommands.h" 43 #include "InputManager.h" 43 44 44 45 namespace orxonox … … 49 50 */ 50 51 KeyBinder::KeyBinder() 51 : deriveTime_(0.0f) 52 : numberOfJoySticks_(0) 53 , deriveTime_(0.0f) 52 54 { 53 55 mouseRelative_[0] = 0; … … 58 60 RegisterRootObject(KeyBinder); 59 61 62 // intialise all buttons and half axes to avoid creating everything with 'new' 60 63 // keys 61 std::string keyNames[] = { 62 "UNASSIGNED", 63 "ESCAPE", 64 "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", 65 "MINUS", "EQUALS", "BACK", "TAB", 66 "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", 67 "LBRACKET", "RBRACKET", 68 "RETURN", "LCONTROL", 69 "A", "S", "D", "F", "G", "H", "J", "K", "L", 70 "SEMICOLON", "APOSTROPHE", "GRAVE", 71 "LSHIFT", "BACKSLASH", 72 "Z", "X", "C", "V", "B", "N", "M", 73 "COMMA", "PERIOD", "SLASH", 74 "RSHIFT", 75 "MULTIPLY", 76 "LMENU", 77 "SPACE", 78 "CAPITAL", 79 "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", 80 "NUMLOCK", "SCROLL", 81 "NUMPAD7", "NUMPAD8", "NUMPAD9", 82 "SUBTRACT", 83 "NUMPAD4", "NUMPAD5", "NUMPAD6", 84 "ADD", 85 "NUMPAD1", "NUMPAD2", "NUMPAD3", "NUMPAD0", 86 "DECIMAL", 87 "","", 88 "OEM_102", 89 "F11", "F12", 90 "","","","","","","","","","","", 91 "F13", "F14", "F15", 92 "","","","","","","","","","", 93 "KANA", 94 "","", 95 "ABNT_C1", 96 "","","","","", 97 "CONVERT", 98 "", 99 "NOCONVERT", 100 "", 101 "YEN", 102 "ABNT_C2", 103 "","","","","","","","","","","","","","", 104 "NUMPADEQUALS", 105 "","", 106 "PREVTRACK", 107 "AT", 108 "COLON", "UNDERLINE", 109 "KANJI", 110 "STOP", 111 "AX", 112 "UNLABELED", 113 "NEXTTRACK", 114 "","", 115 "NUMPADENTER", 116 "RCONTROL", 117 "","", 118 "MUTE", 119 "CALCULATOR", 120 "PLAYPAUSE", 121 "", 122 "MEDIASTOP", 123 "","","","","","","","","", 124 "VOLUMEDOWN", 125 "", 126 "VOLUMEUP", 127 "", 128 "WEBHOME", 129 "NUMPADCOMMA", 130 "", 131 "DIVIDE", 132 "", 133 "SYSRQ", 134 "RMENU", 135 "","","","","","","","","","","","", 136 "PAUSE", 137 "", 138 "HOME", 139 "UP", 140 "PGUP", 141 "", 142 "LEFT", 143 "", 144 "RIGHT", 145 "", 146 "END", "DOWN", "PGDOWN", "INSERT", "DELETE", 147 "","","","","","","", 148 "LWIN", "RWIN", "APPS", 149 "POWER", "SLEEP", 150 "","","", 151 "WAKE", 152 "", 153 "WEBSEARCH", "WEBFAVORITES", "WEBREFRESH", "WEBSTOP", "WEBFORWARD", "WEBBACK", 154 "MYCOMPUTER", "MAIL", "MEDIASELECT" 155 }; 156 for (unsigned int i = 0; i < nKeys_s; i++) 157 keys_[i].name_ = "Key" + keyNames[i]; 158 159 // mouse buttons 160 std::string mouseButtonNames[] = { 161 "MouseLeft", "MouseRight", "MouseMiddle", 162 "MouseButton3", "MouseButton4", "MouseButton5", 163 "MouseButton6", "MouseButton7", 164 "MouseWheel1Up", "MouseWheel1Down", 165 "MouseWheel2Up", "MouseWheel2Down" 166 }; 167 for (unsigned int i = 0; i < nMouseButtons_s; i++) 168 mouseButtons_[i].name_ = mouseButtonNames[i]; 169 170 // joy stick buttons 171 for (unsigned int i = 0; i < 32; i++) 172 joyStickButtons_[i].name_ = "JoyButton" + getConvertedValue<int, std::string>(i); 173 for (unsigned int i = 32; i < nJoyStickButtons_s; i += 4) 174 { 175 joyStickButtons_[i + 0].name_ = "JoyPOV" + convertToString((i - 32)/4 + 1) + "North"; 176 joyStickButtons_[i + 1].name_ = "JoyPOV" + convertToString((i - 32)/4 + 1) + "South"; 177 joyStickButtons_[i + 2].name_ = "JoyPOV" + convertToString((i - 32)/4 + 1) + "East"; 178 joyStickButtons_[i + 3].name_ = "JoyPOV" + convertToString((i - 32)/4 + 1) + "West"; 179 } 180 181 // half axes 182 std::string rawNames[nHalfAxes_s/2]; 183 rawNames[0] = "MouseX"; 184 rawNames[1] = "MouseY"; 185 rawNames[2] = "Empty1"; 186 rawNames[3] = "Empty2"; 187 for (unsigned int i = 4; i < nHalfAxes_s/2; i++) 188 rawNames[i] = "JoyAxis" + convertToString(i - 3); 189 for (unsigned int i = 0; i < nHalfAxes_s/2; i++) 190 { 191 halfAxes_[i * 2 + 0].name_ = rawNames[i] + "Pos"; 192 halfAxes_[i * 2 + 1].name_ = rawNames[i] + "Neg"; 193 } 194 195 for (unsigned int i = 0; i < this->nHalfAxes_s; i++) 196 halfAxes_[i].buttonThreshold_ = buttonThreshold_; 64 for (unsigned int i = 0; i < KeyCode::numberOfKeys; i++) 65 { 66 std::string keyname = KeyCode::ByString[i]; 67 if (!keyname.empty()) 68 { 69 keys_[i].name_ = std::string("Key") + keyname; 70 } 71 else 72 { 73 // some keys have name "" because the code is not occupied by OIS 74 // Use "Key_" plus the number as name to put it at the end of the config file section 75 std::string number = convertToString(i); 76 if (i < 100) 77 number.insert(0, "0"); 78 keys_[i].name_ = std::string("Key_") + number; 79 } 80 keys_[i].paramCommandBuffer_ = ¶mCommandBuffer_; 81 keys_[i].groupName_ = "Keys"; 82 } 83 // mouse buttons plus 4 mouse wheel buttons only 'generated' by KeyBinder 84 const char* const mouseWheelNames[] = { "Wheel1Down", "Wheel1Up", "Wheel2Down", "Wheel2Up" }; 85 for (unsigned int i = 0; i < numberOfMouseButtons_; i++) 86 { 87 std::string nameSuffix; 88 if (i < MouseButtonCode::numberOfButtons) 89 nameSuffix = MouseButtonCode::ByString[i]; 90 else 91 nameSuffix = mouseWheelNames[i - MouseButtonCode::numberOfButtons]; 92 mouseButtons_[i].name_ = std::string("Mouse") + nameSuffix; 93 mouseButtons_[i].paramCommandBuffer_ = ¶mCommandBuffer_; 94 mouseButtons_[i].groupName_ = "MouseButtons"; 95 } 96 // mouse axes 97 for (unsigned int i = 0; i < MouseAxisCode::numberOfAxes * 2; i++) 98 { 99 mouseAxes_[i].name_ = std::string("Mouse") + MouseAxisCode::ByString[i >> 1]; 100 if (i & 1) 101 mouseAxes_[i].name_ += "Pos"; 102 else 103 mouseAxes_[i].name_ += "Neg"; 104 mouseAxes_[i].paramCommandBuffer_ = ¶mCommandBuffer_; 105 mouseAxes_[i].groupName_ = "MouseAxes"; 106 } 107 108 // initialise joy sticks separatly to allow for reloading 109 numberOfJoySticks_ = InputManager::getInstance().numberOfJoySticks(); 110 initialiseJoyStickBindings(); 111 112 // collect all Buttons and HalfAxes 113 compilePointerLists(); 114 115 // set them here to use allHalfAxes_ 116 setConfigValues(); 197 117 } 198 118 … … 209 129 /** 210 130 @brief 211 Loads the key and button bindings.212 @return213 True if loading succeeded.214 */215 void KeyBinder::loadBindings()216 {217 COUT(3) << "KeyBinder: Loading key bindings..." << std::endl;218 219 clearBindings();220 221 std::ifstream infile;222 infile.open("keybindings.ini");223 if (!infile)224 {225 ConfigFileManager::getInstance().setFile(CFT_Keybindings, "def_keybindings.ini");226 ConfigFileManager::getInstance().save(CFT_Keybindings, "keybindings.ini");227 }228 else229 infile.close();230 ConfigFileManager::getInstance().setFile(CFT_Keybindings, "keybindings.ini");231 232 // parse key bindings233 setConfigValues();234 235 COUT(3) << "KeyBinder: Loading key bindings done." << std::endl;236 }237 238 /**239 @brief240 131 Loader for the key bindings, managed by config values. 241 132 */ 242 133 void KeyBinder::setConfigValues() 243 134 { 135 SetConfigValue(defaultKeybindings_, "def_keybindings.ini") 136 .description("Filename of default keybindings."); 244 137 SetConfigValue(analogThreshold_, 0.05f) 245 138 .description("Threshold for analog axes until which the state is 0."); … … 252 145 SetConfigValue(mouseSensitivityDerived_, 1.0f) 253 146 .description("Mouse sensitivity if mouse input is derived."); 254 SetConfigValue(bClipMouse_, true) 255 .description("Whether or not to clip absolute value of mouse in non derive mode."); 256 257 float oldThresh = buttonThreshold_; 147 SetConfigValue(mouseWheelStepSize_, 120.0f) 148 .description("Equals one step of the mousewheel."); 258 149 SetConfigValue(buttonThreshold_, 0.80f) 259 .description("Threshold for analog axes until which the button is not pressed."); 260 if (oldThresh != buttonThreshold_) 261 for (unsigned int i = 0; i < nHalfAxes_s; i++) 262 if (halfAxes_[i].buttonThreshold_ == oldThresh) 263 halfAxes_[i].buttonThreshold_ = buttonThreshold_; 264 265 // keys 266 for (unsigned int i = 0; i < nKeys_s; i++) 267 readTrigger(keys_[i]); 268 // mouse buttons 269 for (unsigned int i = 0; i < nMouseButtons_s; i++) 270 readTrigger(mouseButtons_[i]); 271 // joy stick buttons 272 for (unsigned int i = 0; i < nJoyStickButtons_s; i++) 273 readTrigger(joyStickButtons_[i]); 274 // half axes 275 for (unsigned int i = 0; i < nHalfAxes_s; i++) 276 readTrigger(halfAxes_[i]); 277 } 278 279 void KeyBinder::readTrigger(Button& button) 280 { 281 // config value stuff 282 ConfigValueContainer* cont 283 = ClassIdentifier<KeyBinder>::getIdentifier()->getConfigValueContainer(button.name_); 284 if (!cont) 285 { 286 cont = new ConfigValueContainer 287 (CFT_Keybindings, ClassIdentifier<KeyBinder>::getIdentifier(), button.name_, "", button.name_); 288 ClassIdentifier<KeyBinder>::getIdentifier()->addConfigValueContainer(button.name_, cont); 289 } 290 std::string old = button.bindingString_; 291 cont->getValue(&button.bindingString_, this); 292 293 // keybinder stuff 294 if (old != button.bindingString_) 295 { 296 // clear everything so we don't get old axis ParamCommands mixed up 297 button.clear(); 298 299 // binding has changed 300 button.parse(paramCommandBuffer_); 150 .description("Threshold for analog axes until which the button is not pressed.") 151 .callback(this, &KeyBinder::buttonThresholdChanged); 152 } 153 154 void KeyBinder::buttonThresholdChanged() 155 { 156 for (unsigned int i = 0; i < allHalfAxes_.size(); i++) 157 if (!allHalfAxes_[i]->bButtonThresholdUser_) 158 allHalfAxes_[i]->buttonThreshold_ = this->buttonThreshold_; 159 } 160 161 void KeyBinder::JoyStickDeviceNumberChanged(unsigned int value) 162 { 163 unsigned int oldValue = numberOfJoySticks_; 164 numberOfJoySticks_ = value; 165 166 // initialise joy stick bindings 167 initialiseJoyStickBindings(); 168 169 // collect all Buttons and HalfAxes again 170 compilePointerLists(); 171 172 // load the bindings if required 173 if (!configFile_.empty()) 174 { 175 for (unsigned int iDev = oldValue; iDev < numberOfJoySticks_; ++iDev) 176 { 177 for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; ++i) 178 joyStickButtons_[iDev][i].readConfigValue(); 179 for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; ++i) 180 joyStickAxes_[iDev][i].readConfigValue(); 181 } 182 } 183 184 // Set the button threshold for potential new axes 185 buttonThresholdChanged(); 186 } 187 188 void KeyBinder::initialiseJoyStickBindings() 189 { 190 this->joyStickAxes_.resize(numberOfJoySticks_); 191 this->joyStickButtons_.resize(numberOfJoySticks_); 192 193 // reinitialise all joy stick binings (doesn't overwrite the old ones) 194 for (unsigned int iDev = 0; iDev < numberOfJoySticks_; iDev++) 195 { 196 std::string deviceNumber = convertToString(iDev); 197 // joy stick buttons 198 for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; i++) 199 { 200 joyStickButtons_[iDev][i].name_ = std::string("JoyStick") + deviceNumber + JoyStickButtonCode::ByString[i]; 201 joyStickButtons_[iDev][i].paramCommandBuffer_ = ¶mCommandBuffer_; 202 joyStickButtons_[iDev][i].groupName_ = std::string("JoyStick") + deviceNumber + "Buttons"; 203 } 204 // joy stick axes 205 for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++) 206 { 207 joyStickAxes_[iDev][i].name_ = std::string("JoyStick") + deviceNumber + JoyStickAxisCode::ByString[i >> 1]; 208 if (i & 1) 209 joyStickAxes_[iDev][i].name_ += "Pos"; 210 else 211 joyStickAxes_[iDev][i].name_ += "Neg"; 212 joyStickAxes_[iDev][i].paramCommandBuffer_ = ¶mCommandBuffer_; 213 joyStickAxes_[iDev][i].groupName_ = std::string("JoyStick") + deviceNumber + "Axes"; 214 } 215 } 216 } 217 218 void KeyBinder::compilePointerLists() 219 { 220 allButtons_.clear(); 221 allHalfAxes_.clear(); 222 223 for (unsigned int i = 0; i < KeyCode::numberOfKeys; i++) 224 allButtons_[keys_[i].name_] = keys_ + i; 225 for (unsigned int i = 0; i < numberOfMouseButtons_; i++) 226 allButtons_[mouseButtons_[i].name_] = mouseButtons_ + i; 227 for (unsigned int i = 0; i < MouseAxisCode::numberOfAxes * 2; i++) 228 { 229 allButtons_[mouseAxes_[i].name_] = mouseAxes_ + i; 230 allHalfAxes_.push_back(mouseAxes_ + i); 231 } 232 for (unsigned int iDev = 0; iDev < numberOfJoySticks_; iDev++) 233 { 234 for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; i++) 235 allButtons_[joyStickButtons_[iDev][i].name_] = &(joyStickButtons_[iDev][i]); 236 for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++) 237 { 238 allButtons_[joyStickAxes_[iDev][i].name_] = &(joyStickAxes_[iDev][i]); 239 allHalfAxes_.push_back(&(joyStickAxes_[iDev][i])); 240 } 241 } 242 } 243 244 /** 245 @brief 246 Loads the key and button bindings. 247 @return 248 True if loading succeeded. 249 */ 250 void KeyBinder::loadBindings(const std::string& filename) 251 { 252 COUT(3) << "KeyBinder: Loading key bindings..." << std::endl; 253 254 configFile_ = filename; 255 if (configFile_.empty()) 256 return; 257 258 // get bindings from default file if filename doesn't exist. 259 std::ifstream infile; 260 infile.open(configFile_.c_str()); 261 if (!infile) 262 { 263 ConfigFileManager::getInstance().setFile(CFT_Keybindings, defaultKeybindings_); 264 ConfigFileManager::getInstance().save(CFT_Keybindings, configFile_); 265 } 266 else 267 infile.close(); 268 ConfigFileManager::getInstance().setFile(CFT_Keybindings, configFile_); 269 270 // Parse bindings and create the ConfigValueContainers if necessary 271 clearBindings(); 272 for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it) 273 it->second->readConfigValue(); 274 275 COUT(3) << "KeyBinder: Loading key bindings done." << std::endl; 276 } 277 278 bool KeyBinder::setBinding(const std::string& binding, const std::string& name, bool bTemporary) 279 { 280 std::map<std::string, Button*>::iterator it = allButtons_.find(name); 281 if (it != allButtons_.end()) 282 { 283 if (bTemporary) 284 it->second->configContainer_->tset(binding); 285 else 286 it->second->configContainer_->set(binding); 287 it->second->configContainer_->getValue(&(it->second->bindingString_), it->second); 288 return true; 289 } 290 else 291 { 292 COUT(2) << "Could not find key/button/axis with name '" << name << "'." << std::endl; 293 return false; 301 294 } 302 295 } … … 308 301 void KeyBinder::clearBindings() 309 302 { 310 for (unsigned int i = 0; i < nKeys_s; i++) 311 keys_[i].clear(); 312 313 for (unsigned int i = 0; i < nMouseButtons_s; i++) 314 mouseButtons_[i].clear(); 315 316 for (unsigned int i = 0; i < nJoyStickButtons_s; i++) 317 joyStickButtons_[i].clear(); 318 319 for (unsigned int i = 0; i < nHalfAxes_s; i++) 320 halfAxes_[i].clear(); 303 for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it) 304 it->second->clear(); 321 305 322 306 for (unsigned int i = 0; i < paramCommandBuffer_.size(); i++) … … 327 311 void KeyBinder::resetJoyStickAxes() 328 312 { 329 for (unsigned int i = 8; i < nHalfAxes_s; i++) 330 { 331 halfAxes_[i].absVal_ = 0.0f; 332 halfAxes_[i].relVal_ = 0.0f; 313 for (unsigned int iDev = 0; iDev < numberOfJoySticks_; ++iDev) 314 { 315 for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++) 316 { 317 joyStickAxes_[iDev][i].absVal_ = 0.0f; 318 joyStickAxes_[iDev][i].relVal_ = 0.0f; 319 } 333 320 } 334 321 } … … 336 323 void KeyBinder::tickMouse(float dt) 337 324 { 338 tickDevices( 0, 8);325 tickDevices(mouseAxes_, mouseAxes_ + MouseAxisCode::numberOfAxes * 2); 339 326 340 327 if (bDeriveMouseInput_) … … 342 329 if (deriveTime_ > derivePeriod_) 343 330 { 344 //CCOUT(3) << "mouse abs: ";345 331 for (int i = 0; i < 2; i++) 346 332 { 347 333 if (mouseRelative_[i] > 0) 348 334 { 349 halfAxes_[2*i + 0].absVal_335 mouseAxes_[2*i + 0].absVal_ 350 336 = mouseRelative_[i] / deriveTime_ * 0.0005 * mouseSensitivityDerived_; 351 halfAxes_[2*i + 1].absVal_ = 0.0f;337 mouseAxes_[2*i + 1].absVal_ = 0.0f; 352 338 } 353 339 else if (mouseRelative_[i] < 0) 354 340 { 355 halfAxes_[2*i + 0].absVal_ = 0.0f;356 halfAxes_[2*i + 1].absVal_341 mouseAxes_[2*i + 0].absVal_ = 0.0f; 342 mouseAxes_[2*i + 1].absVal_ 357 343 = -mouseRelative_[i] / deriveTime_ * 0.0005 * mouseSensitivityDerived_; 358 344 } 359 345 else 360 346 { 361 halfAxes_[2*i + 0].absVal_ = 0.0f;362 halfAxes_[2*i + 1].absVal_ = 0.0f;347 mouseAxes_[2*i + 0].absVal_ = 0.0f; 348 mouseAxes_[2*i + 1].absVal_ = 0.0f; 363 349 } 364 //COUT(3) << mouseRelative_[i] << " | ";365 350 mouseRelative_[i] = 0; 366 halfAxes_[2*i + 0].hasChanged_ = true;367 halfAxes_[2*i + 1].hasChanged_ = true;351 mouseAxes_[2*i + 0].hasChanged_ = true; 352 mouseAxes_[2*i + 1].hasChanged_ = true; 368 353 } 369 354 deriveTime_ = 0.0f; 370 //COUT(3) << std::endl;371 355 } 372 356 else … … 375 359 } 376 360 377 void KeyBinder::tickJoyStick(float dt, unsigned int joyStick) 378 { 379 tickDevices(8, nHalfAxes_s); 380 } 381 382 void KeyBinder::tickInput(float dt) 383 { 384 // execute all buffered bindings (additional parameter) 385 for (unsigned int i = 0; i < paramCommandBuffer_.size(); i++) 386 paramCommandBuffer_[i]->execute(); 387 388 // always reset the relative movement of the mouse 389 for (unsigned int i = 0; i < 8; i++) 390 halfAxes_[i].relVal_ = 0.0f; 391 } 392 393 void KeyBinder::tickDevices(unsigned int begin, unsigned int end) 394 { 395 for (unsigned int i = begin; i < end; i++) 361 void KeyBinder::tickDevices(HalfAxis* begin, HalfAxis* end) 362 { 363 for (HalfAxis* current = begin; current < end; ++current) // pointer arithmetic 396 364 { 397 365 // button mode 398 366 // TODO: optimize out all the half axes that don't act as a button at the moment 399 if ( halfAxes_[i].hasChanged_)400 { 401 if (! halfAxes_[i].wasDown_ && halfAxes_[i].absVal_ > halfAxes_[i].buttonThreshold_)367 if (current->hasChanged_) 368 { 369 if (!current->wasDown_ && current->absVal_ > current->buttonThreshold_) 402 370 { 403 halfAxes_[i].wasDown_ = true;404 if ( halfAxes_[i].nCommands_[KeybindMode::OnPress])405 halfAxes_[i].execute(KeybindMode::OnPress);371 current->wasDown_ = true; 372 if (current->nCommands_[KeybindMode::OnPress]) 373 current->execute(KeybindMode::OnPress); 406 374 } 407 else if ( halfAxes_[i].wasDown_ && halfAxes_[i].absVal_ < halfAxes_[i].buttonThreshold_)375 else if (current->wasDown_ && current->absVal_ < current->buttonThreshold_) 408 376 { 409 halfAxes_[i].wasDown_ = false;410 if ( halfAxes_[i].nCommands_[KeybindMode::OnRelease])411 halfAxes_[i].execute(KeybindMode::OnRelease);377 current->wasDown_ = false; 378 if (current->nCommands_[KeybindMode::OnRelease]) 379 current->execute(KeybindMode::OnRelease); 412 380 } 413 halfAxes_[i].hasChanged_ = false;414 } 415 416 if ( halfAxes_[i].wasDown_)417 { 418 if ( halfAxes_[i].nCommands_[KeybindMode::OnHold])419 halfAxes_[i].execute(KeybindMode::OnHold);381 current->hasChanged_ = false; 382 } 383 384 if (current->wasDown_) 385 { 386 if (current->nCommands_[KeybindMode::OnHold]) 387 current->execute(KeybindMode::OnHold); 420 388 } 421 389 422 390 // these are the actually useful axis bindings for analog input 423 if (halfAxes_[i].relVal_ > analogThreshold_ || halfAxes_[i].absVal_ > analogThreshold_) 424 { 425 //COUT(3) << halfAxes_[i].name_ << "\t" << halfAxes_[i].absVal_ << std::endl; 426 halfAxes_[i].execute(); 427 } 428 } 429 } 430 431 void KeyBinder::keyPressed (const KeyEvent& evt) 432 { keys_[evt.key].execute(KeybindMode::OnPress); } 433 434 void KeyBinder::keyReleased(const KeyEvent& evt) 435 { keys_[evt.key].execute(KeybindMode::OnRelease); } 436 437 void KeyBinder::keyHeld (const KeyEvent& evt) 438 { keys_[evt.key].execute(KeybindMode::OnHold); } 439 440 441 void KeyBinder::mouseButtonPressed (MouseButton::Enum id) 442 { mouseButtons_[id].execute(KeybindMode::OnPress); } 443 444 void KeyBinder::mouseButtonReleased(MouseButton::Enum id) 445 { mouseButtons_[id].execute(KeybindMode::OnRelease); } 446 447 void KeyBinder::mouseButtonHeld (MouseButton::Enum id) 448 { mouseButtons_[id].execute(KeybindMode::OnHold); } 449 450 451 void KeyBinder::joyStickButtonPressed (unsigned int joyStickID, JoyStickButton::Enum id) 452 { joyStickButtons_[id].execute(KeybindMode::OnPress); } 453 454 void KeyBinder::joyStickButtonReleased(unsigned int joyStickID, JoyStickButton::Enum id) 455 { joyStickButtons_[id].execute(KeybindMode::OnRelease); } 456 457 void KeyBinder::joyStickButtonHeld (unsigned int joyStickID, JoyStickButton::Enum id) 458 { joyStickButtons_[id].execute(KeybindMode::OnHold); } 391 if (current->relVal_ > analogThreshold_ || current->absVal_ > analogThreshold_) 392 { 393 current->execute(); 394 } 395 } 396 } 459 397 460 398 /** … … 473 411 for (int i = 0; i < 2; i++) 474 412 { 475 if (rel[i]) 413 if (rel[i]) // performance opt. if rel[i] == 0 476 414 { 477 // absolute478 halfAxes_[2*i + 0].hasChanged_ = true;479 halfAxes_[2*i + 1].hasChanged_ = true;415 // write absolute values 416 mouseAxes_[2*i + 0].hasChanged_ = true; 417 mouseAxes_[2*i + 1].hasChanged_ = true; 480 418 mousePosition_[i] += rel[i]; 481 419 482 if (bClipMouse_) 483 { 484 if (mousePosition_[i] > 1024) 485 mousePosition_[i] = 1024; 486 if (mousePosition_[i] < -1024) 487 mousePosition_[i] = -1024; 488 } 420 // clip absolute position 421 if (mousePosition_[i] > mouseClippingSize_) 422 mousePosition_[i] = mouseClippingSize_; 423 if (mousePosition_[i] < -mouseClippingSize_) 424 mousePosition_[i] = -mouseClippingSize_; 489 425 490 426 if (mousePosition_[i] >= 0) 491 427 { 492 halfAxes_[2*i + 0].absVal_ = mousePosition_[i]/1024.0f* mouseSensitivity_;493 halfAxes_[2*i + 1].absVal_ = 0.0f;428 mouseAxes_[2*i + 0].absVal_ = mousePosition_[i]/(float)mouseClippingSize_ * mouseSensitivity_; 429 mouseAxes_[2*i + 1].absVal_ = 0.0f; 494 430 } 495 431 else 496 432 { 497 halfAxes_[2*i + 0].absVal_ = 0.0f;498 halfAxes_[2*i + 1].absVal_ = -mousePosition_[i]/1024.0f* mouseSensitivity_;433 mouseAxes_[2*i + 0].absVal_ = 0.0f; 434 mouseAxes_[2*i + 1].absVal_ = -mousePosition_[i]/(float)mouseClippingSize_ * mouseSensitivity_; 499 435 } 500 436 } … … 511 447 { 512 448 if (rel[i] > 0) 513 halfAxes_[0 + 2*i].relVal_ = ((float)rel[i])/1024* mouseSensitivity_;514 else 515 halfAxes_[1 + 2*i].relVal_ = -((float)rel[i])/1024* mouseSensitivity_;449 mouseAxes_[0 + 2*i].relVal_ = ((float)rel[i])/(float)mouseClippingSize_ * mouseSensitivity_; 450 else 451 mouseAxes_[1 + 2*i].relVal_ = -((float)rel[i])/(float)mouseClippingSize_ * mouseSensitivity_; 516 452 } 517 453 } … … 523 459 void KeyBinder::mouseScrolled(int abs, int rel) 524 460 { 525 //COUT(3) << mouseButtons_[8].name_ << " " << abs << " | " << rel << std::endl;526 527 461 if (rel > 0) 528 for (int i = 0; i < rel/ 120; i++)529 mouseButtons_[8].execute(KeybindMode::OnPress, ((float)abs)/ 120.0f);462 for (int i = 0; i < rel/mouseWheelStepSize_; i++) 463 mouseButtons_[8].execute(KeybindMode::OnPress, ((float)abs)/mouseWheelStepSize_); 530 464 else 531 for (int i = 0; i < -rel/ 120; i++)532 mouseButtons_[9].execute(KeybindMode::OnPress, ((float)abs)/ 120.0f);465 for (int i = 0; i < -rel/mouseWheelStepSize_; i++) 466 mouseButtons_[9].execute(KeybindMode::OnPress, ((float)abs)/mouseWheelStepSize_); 533 467 } 534 468 535 469 void KeyBinder::joyStickAxisMoved(unsigned int joyStickID, unsigned int axis, float value) 536 470 { 537 int i = 8 +axis * 2;471 int i = axis * 2; 538 472 if (value >= 0) 539 473 { 540 //if (value > 10000) 541 //{ CCOUT(3) << halfAxes_[i].name_ << std::endl; } 542 543 halfAxes_[i].absVal_ = value; 544 halfAxes_[i].relVal_ = value; 545 halfAxes_[i].hasChanged_ = true; 546 if (halfAxes_[i + 1].absVal_ > 0.0f) 547 { 548 halfAxes_[i + 1].absVal_ = -0.0f; 549 halfAxes_[i + 1].relVal_ = -0.0f; 550 halfAxes_[i + 1].hasChanged_ = true; 474 joyStickAxes_[joyStickID][i].absVal_ = value; 475 joyStickAxes_[joyStickID][i].relVal_ = value; 476 joyStickAxes_[joyStickID][i].hasChanged_ = true; 477 if (joyStickAxes_[joyStickID][i + 1].absVal_ > 0.0f) 478 { 479 joyStickAxes_[joyStickID][i + 1].absVal_ = -0.0f; 480 joyStickAxes_[joyStickID][i + 1].relVal_ = -0.0f; 481 joyStickAxes_[joyStickID][i + 1].hasChanged_ = true; 551 482 } 552 483 } 553 484 else 554 485 { 555 //if (value < -10000) 556 //{ CCOUT(3) << halfAxes_[i + 1].name_ << std::endl; } 557 558 halfAxes_[i + 1].absVal_ = -value; 559 halfAxes_[i + 1].relVal_ = -value; 560 halfAxes_[i + 1].hasChanged_ = true; 561 if (halfAxes_[i].absVal_ > 0.0f) 562 { 563 halfAxes_[i].absVal_ = -0.0f; 564 halfAxes_[i].relVal_ = -0.0f; 565 halfAxes_[i].hasChanged_ = true; 486 joyStickAxes_[joyStickID][i + 1].absVal_ = -value; 487 joyStickAxes_[joyStickID][i + 1].relVal_ = -value; 488 joyStickAxes_[joyStickID][i + 1].hasChanged_ = true; 489 if (joyStickAxes_[joyStickID][i].absVal_ > 0.0f) 490 { 491 joyStickAxes_[joyStickID][i].absVal_ = -0.0f; 492 joyStickAxes_[joyStickID][i].relVal_ = -0.0f; 493 joyStickAxes_[joyStickID][i].hasChanged_ = true; 566 494 } 567 495 } -
code/trunk/src/core/input/KeyBinder.h
r1755 r1887 39 39 40 40 #include <vector> 41 42 #include "core/OrxonoxClass.h"43 41 #include "InputInterfaces.h" 44 42 #include "Button.h" 45 43 #include "HalfAxis.h" 44 #include "InputCommands.h" 45 #include "JoyStickDeviceNumberListener.h" 46 46 47 47 namespace orxonox … … 52 52 Manages the key bindings. 53 53 */ 54 class _CoreExport KeyBinder : public KeyHandler, public MouseHandler, public JoyStickHandler, public OrxonoxClass 54 class _CoreExport KeyBinder : public KeyHandler, public MouseHandler, public JoyStickHandler, 55 public JoyStickDeviceNumberListener 55 56 { 56 57 public: … … 58 59 virtual ~KeyBinder(); 59 60 60 void loadBindings( );61 void loadBindings(const std::string& filename); 61 62 void clearBindings(); 63 bool setBinding(const std::string& binding, const std::string& name, bool bTemporary = false); 62 64 void setConfigValues(); 63 65 void resetJoyStickAxes(); … … 65 67 protected: // functions 66 68 void tickInput(float dt); 67 //void tickInput(float dt, int device);68 69 void tickKey(float dt) { } 69 70 void tickMouse(float dt); 70 71 void tickJoyStick(float dt, unsigned int joyStick); 71 void tickDevices(unsigned int begin, unsigned int end); 72 73 virtual void readTrigger(Button& button); 72 // internal 73 void tickDevices(HalfAxis* begin, HalfAxis* end); 74 75 void buttonThresholdChanged(); 76 // from JoyStickDeviceNumberListener interface 77 virtual void JoyStickDeviceNumberChanged(unsigned int value); 78 void initialiseJoyStickBindings(); 79 void compilePointerLists(); 74 80 75 81 void keyPressed (const KeyEvent& evt); … … 77 83 void keyHeld (const KeyEvent& evt); 78 84 79 void mouseButtonPressed (MouseButton ::Enum id);80 void mouseButtonReleased(MouseButton ::Enum id);81 void mouseButtonHeld (MouseButton ::Enum id);85 void mouseButtonPressed (MouseButtonCode::ByEnum id); 86 void mouseButtonReleased(MouseButtonCode::ByEnum id); 87 void mouseButtonHeld (MouseButtonCode::ByEnum id); 82 88 void mouseMoved (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize); 83 89 void mouseScrolled (int abs, int rel); 84 90 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);91 void joyStickButtonPressed (unsigned int joyStickID, JoyStickButtonCode::ByEnum id); 92 void joyStickButtonReleased(unsigned int joyStickID, JoyStickButtonCode::ByEnum id); 93 void joyStickButtonHeld (unsigned int joyStickID, JoyStickButtonCode::ByEnum id); 88 94 void joyStickAxisMoved (unsigned int joyStickID, unsigned int axis, float value); 89 95 90 96 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]; 95 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]; 100 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]; 105 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]; 97 //! Currently active joy sticks 98 unsigned int numberOfJoySticks_; 99 100 //! Actual key bindings for keys on the keyboard 101 Button keys_ [KeyCode::numberOfKeys]; 102 //! Number of mouse buttons in KeyBinder (+4) 103 static const int numberOfMouseButtons_ = MouseButtonCode::numberOfButtons + 4; 104 //! Actual key bindings for mouse buttons including the wheel(s) 105 Button mouseButtons_ [numberOfMouseButtons_]; 106 //! Actual key bindings for mouse axes 107 HalfAxis mouseAxes_ [MouseAxisCode::numberOfAxes * 2]; 108 109 //! Helper class to use something like std:vector<Button[64]> 110 struct JoyStickButtonVector 111 { 112 Button& operator[](unsigned int index) { return buttons[index]; } 113 Button buttons[JoyStickButtonCode::numberOfButtons]; 114 }; 115 //! Actual key bindings for joy stick buttons 116 std::vector<JoyStickButtonVector> joyStickButtons_; 117 //! Helper class to use something like std:vector<HalfAxis[48]> 118 struct JoyStickAxisVector 119 { 120 HalfAxis& operator[](unsigned int index) { return halfAxes[index]; } 121 HalfAxis halfAxes[JoyStickAxisCode::numberOfAxes * 2]; 122 }; 123 //! Actual key bindings for joy stick axes (and sliders) 124 std::vector<JoyStickAxisVector> joyStickAxes_; 125 126 //! Pointer map with all Buttons, including half axes 127 std::map<std::string, Button*> allButtons_; 128 //! Pointer list with all half axes 129 std::vector<HalfAxis*> allHalfAxes_; 119 130 120 131 /** … … 131 142 float deriveTime_; 132 143 133 144 //! Config file used. "" in case of KeyDetector. Also indicates whether we've already loaded. 145 std::string configFile_; 146 147 private: 134 148 //##### ConfigValues ##### 135 149 //! Filename of default keybindings. 150 std::string defaultKeybindings_; 136 151 //! Threshold for analog triggers until which the state is 0. 137 152 float analogThreshold_; … … 146 161 //! mouse sensitivity if mouse input is derived 147 162 float mouseSensitivityDerived_; 148 //! Whether or not to clip abslute mouse values to 1024 149 bool bClipMouse_; 163 //! Equals one step of the mousewheel 164 float mouseWheelStepSize_; 165 166 //##### Constant config variables ##### 167 // Use some value at about 1000. This can be configured with mouseSensitivity_ anyway. 168 static const int mouseClippingSize_ = 1024; 150 169 }; 170 171 inline void KeyBinder::keyPressed (const KeyEvent& evt) 172 { keys_[evt.key].execute(KeybindMode::OnPress); } 173 174 inline void KeyBinder::keyReleased(const KeyEvent& evt) 175 { keys_[evt.key].execute(KeybindMode::OnRelease); } 176 177 inline void KeyBinder::keyHeld (const KeyEvent& evt) 178 { keys_[evt.key].execute(KeybindMode::OnHold); } 179 180 181 inline void KeyBinder::mouseButtonPressed (MouseButtonCode::ByEnum id) 182 { mouseButtons_[id].execute(KeybindMode::OnPress); } 183 184 inline void KeyBinder::mouseButtonReleased(MouseButtonCode::ByEnum id) 185 { mouseButtons_[id].execute(KeybindMode::OnRelease); } 186 187 inline void KeyBinder::mouseButtonHeld (MouseButtonCode::ByEnum id) 188 { mouseButtons_[id].execute(KeybindMode::OnHold); } 189 190 191 inline void KeyBinder::joyStickButtonPressed (unsigned int joyStickID, JoyStickButtonCode::ByEnum id) 192 { joyStickButtons_[joyStickID][id].execute(KeybindMode::OnPress); } 193 194 inline void KeyBinder::joyStickButtonReleased(unsigned int joyStickID, JoyStickButtonCode::ByEnum id) 195 { joyStickButtons_[joyStickID][id].execute(KeybindMode::OnRelease); } 196 197 inline void KeyBinder::joyStickButtonHeld (unsigned int joyStickID, JoyStickButtonCode::ByEnum id) 198 { joyStickButtons_[joyStickID][id].execute(KeybindMode::OnHold); } 199 200 inline void KeyBinder::tickJoyStick(float dt, unsigned int joyStick) 201 { 202 tickDevices(&joyStickAxes_[joyStick][0], &joyStickAxes_[joyStick][JoyStickAxisCode::numberOfAxes * 2]); 203 } 204 205 inline void KeyBinder::tickInput(float dt) 206 { 207 // execute all buffered bindings (additional parameter) 208 for (unsigned int i = 0; i < paramCommandBuffer_.size(); i++) 209 paramCommandBuffer_[i]->execute(); 210 211 // always reset the relative movement of the mouse 212 for (unsigned int i = 0; i < MouseAxisCode::numberOfAxes * 2; i++) 213 mouseAxes_[i].relVal_ = 0.0f; 214 } 151 215 } 152 216 -
code/trunk/src/core/input/KeyDetector.cc
r1755 r1887 62 62 /** 63 63 @brief 64 Loads the key and button bindings. 65 @return 66 True if loading succeeded. 64 Assigns all the buttons 'command' plus the button's name. 67 65 */ 68 void KeyDetector:: loadBindings(const std::string& command)66 void KeyDetector::setCallbackCommand(const std::string& command) 69 67 { 70 this->command_ = command;68 callbackCommand_ = command; 71 69 clearBindings(); 72 setConfigValues(); 70 for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it) 71 { 72 it->second->bindingString_ = callbackCommand_ + it->second->name_; 73 it->second->parse(); 74 } 73 75 } 74 76 75 void KeyDetector:: readTrigger(Button& button)77 void KeyDetector::JoyStickDeviceNumberChanged(unsigned int value) 76 78 { 77 SimpleCommand* cmd = new SimpleCommand(); 78 cmd->evaluation_ = CommandExecutor::evaluate(this->command_ + " " + button.name_); 79 button.commands_[KeybindMode::OnPress] = new BaseCommand*[1]; 80 button.commands_[KeybindMode::OnPress][0] = cmd; 81 button.nCommands_[KeybindMode::OnPress] = 1; 79 KeyBinder::JoyStickDeviceNumberChanged(value); 80 setCallbackCommand(callbackCommand_); 82 81 } 83 82 } -
code/trunk/src/core/input/KeyDetector.h
r1755 r1887 47 47 KeyDetector(); 48 48 ~KeyDetector(); 49 void loadBindings(const std::string& command); 50 51 protected: 52 void readTrigger(Button& button); 49 void setCallbackCommand(const std::string& command); 50 void JoyStickDeviceNumberChanged(unsigned int value); 53 51 54 52 private: 55 std::string c ommand_;53 std::string callbackCommand_; 56 54 }; 57 55 } -
code/trunk/src/core/input/SimpleInputState.cc
r1881 r1887 35 35 #include "SimpleInputState.h" 36 36 37 #include <assert.h>38 #include "util/Debug.h"39 #include "core/Executor.h"40 41 37 namespace orxonox 42 38 { 43 using namespace InputDevice;44 45 39 SimpleInputState::SimpleInputState() 46 40 : keyHandler_(0) … … 70 64 if (keyHandler_) 71 65 keyHandler_->keyPressed(evt); 72 }73 74 void SimpleInputState::keyReleased(const KeyEvent& evt)75 {76 if (keyHandler_)77 keyHandler_->keyReleased(evt);78 }79 80 void SimpleInputState::keyHeld(const KeyEvent& evt)81 {82 if (keyHandler_)83 keyHandler_->keyHeld(evt);84 }85 86 87 void SimpleInputState::mouseMoved(IntVector2 abs, IntVector2 rel, IntVector2 clippingSize)88 {89 if (mouseHandler_)90 mouseHandler_->mouseMoved(abs, rel, clippingSize);91 }92 93 void SimpleInputState::mouseScrolled(int abs, int rel)94 {95 if (mouseHandler_)96 mouseHandler_->mouseScrolled(abs, rel);97 }98 99 void SimpleInputState::mouseButtonPressed(MouseButton::Enum id)100 {101 if (mouseHandler_)102 mouseHandler_->mouseButtonPressed(id);103 }104 105 void SimpleInputState::mouseButtonReleased(MouseButton::Enum id)106 {107 if (mouseHandler_)108 mouseHandler_->mouseButtonReleased(id);109 }110 111 void SimpleInputState::mouseButtonHeld(MouseButton::Enum id)112 {113 if (mouseHandler_)114 mouseHandler_->mouseButtonHeld(id);115 }116 117 118 void SimpleInputState::joyStickAxisMoved(unsigned int joyStickID, unsigned int axis, float value)119 {120 assert(joyStickID < joyStickHandler_.size());121 if (joyStickHandler_[joyStickID])122 joyStickHandler_[joyStickID]->joyStickAxisMoved(joyStickID, axis, value);123 }124 125 void SimpleInputState::joyStickButtonPressed(unsigned int joyStickID, JoyStickButton::Enum id)126 {127 assert(joyStickID < joyStickHandler_.size());128 if (joyStickHandler_[joyStickID])129 joyStickHandler_[joyStickID]->joyStickButtonPressed(joyStickID, id);130 }131 132 void SimpleInputState::joyStickButtonReleased(unsigned int joyStickID, JoyStickButton::Enum id)133 {134 assert(joyStickID < joyStickHandler_.size());135 if (joyStickHandler_[joyStickID])136 joyStickHandler_[joyStickID]->joyStickButtonReleased(joyStickID, id);137 }138 139 void SimpleInputState::joyStickButtonHeld(unsigned int joyStickID, JoyStickButton::Enum id)140 {141 assert(joyStickID < joyStickHandler_.size());142 if (joyStickHandler_[joyStickID])143 joyStickHandler_[joyStickID]->joyStickButtonHeld(joyStickID, id);144 66 } 145 67 … … 199 121 } 200 122 201 void SimpleInputState::tickInput(float dt)202 {203 for (unsigned int i = 0; i < allHandlers_.size(); ++i)204 {205 allHandlers_[i]->tickInput(dt);206 }207 }208 209 void SimpleInputState::tickInput(float dt, unsigned int device)210 {211 switch (device)212 {213 case Keyboard:214 if (keyHandler_)215 keyHandler_->tickKey(dt);216 break;217 218 case Mouse:219 if (mouseHandler_)220 mouseHandler_->tickMouse(dt);221 break;222 223 default: // joy sticks224 if (joyStickHandler_[device - 2])225 joyStickHandler_[device - 2]->tickJoyStick(dt, device - 2);226 break;227 }228 }229 230 123 void SimpleInputState::update() 231 124 { … … 247 140 248 141 // update the deviceEnabled options 249 setInputDeviceEnabled( Keyboard, (keyHandler_ != 0));250 setInputDeviceEnabled( Mouse, (mouseHandler_ != 0));142 setInputDeviceEnabled(InputDevice::Keyboard, (keyHandler_ != 0)); 143 setInputDeviceEnabled(InputDevice::Mouse, (mouseHandler_ != 0)); 251 144 for (unsigned int i = 0; i < joyStickHandler_.size(); ++i) 252 145 setInputDeviceEnabled(2 + i, (joyStickHandler_[i] != 0)); -
code/trunk/src/core/input/SimpleInputState.h
r1881 r1887 38 38 39 39 #include <vector> 40 #include <cassert> 40 41 #include "InputInterfaces.h" 41 42 #include "InputState.h" … … 65 66 void keyHeld (const KeyEvent& evt); 66 67 67 void mouseButtonPressed (MouseButton ::Enum id);68 void mouseButtonReleased(MouseButton ::Enum id);69 void mouseButtonHeld (MouseButton ::Enum id);68 void mouseButtonPressed (MouseButtonCode::ByEnum id); 69 void mouseButtonReleased(MouseButtonCode::ByEnum id); 70 void mouseButtonHeld (MouseButtonCode::ByEnum id); 70 71 void mouseMoved (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize); 71 72 void mouseScrolled (int abs, int rel); 72 73 73 void joyStickButtonPressed (unsigned int joyStickID, JoyStickButton ::Enum id);74 void joyStickButtonReleased(unsigned int joyStickID, JoyStickButton ::Enum id);75 void joyStickButtonHeld (unsigned int joyStickID, JoyStickButton ::Enum id);74 void joyStickButtonPressed (unsigned int joyStickID, JoyStickButtonCode::ByEnum id); 75 void joyStickButtonReleased(unsigned int joyStickID, JoyStickButtonCode::ByEnum id); 76 void joyStickButtonHeld (unsigned int joyStickID, JoyStickButtonCode::ByEnum id); 76 77 void joyStickAxisMoved (unsigned int joyStickID, unsigned int axis, float value); 77 78 … … 83 84 std::vector<JoyStickHandler*> joyStickHandler_; 84 85 JoyStickHandler* joyStickHandlerAll_; 85 std::vector<InputHandler*> allHandlers_;86 std::vector<InputHandler*> allHandlers_; 86 87 }; 88 89 inline void SimpleInputState::tickInput(float dt) 90 { 91 for (unsigned int i = 0; i < allHandlers_.size(); ++i) 92 { 93 allHandlers_[i]->tickInput(dt); 94 } 95 } 96 97 inline void SimpleInputState::tickInput(float dt, unsigned int device) 98 { 99 switch (device) 100 { 101 case InputDevice::Keyboard: 102 if (keyHandler_) 103 keyHandler_->tickKey(dt); 104 break; 105 106 case InputDevice::Mouse: 107 if (mouseHandler_) 108 mouseHandler_->tickMouse(dt); 109 break; 110 111 default: // joy sticks 112 if (joyStickHandler_[device - 2]) 113 joyStickHandler_[device - 2]->tickJoyStick(dt, device - 2); 114 break; 115 } 116 } 117 118 inline void SimpleInputState::keyReleased(const KeyEvent& evt) 119 { 120 if (keyHandler_) 121 keyHandler_->keyReleased(evt); 122 } 123 124 inline void SimpleInputState::keyHeld(const KeyEvent& evt) 125 { 126 if (keyHandler_) 127 keyHandler_->keyHeld(evt); 128 } 129 130 inline void SimpleInputState::mouseMoved(IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) 131 { 132 if (mouseHandler_) 133 mouseHandler_->mouseMoved(abs, rel, clippingSize); 134 } 135 136 inline void SimpleInputState::mouseScrolled(int abs, int rel) 137 { 138 if (mouseHandler_) 139 mouseHandler_->mouseScrolled(abs, rel); 140 } 141 142 inline void SimpleInputState::mouseButtonPressed(MouseButtonCode::ByEnum id) 143 { 144 if (mouseHandler_) 145 mouseHandler_->mouseButtonPressed(id); 146 } 147 148 inline void SimpleInputState::mouseButtonReleased(MouseButtonCode::ByEnum id) 149 { 150 if (mouseHandler_) 151 mouseHandler_->mouseButtonReleased(id); 152 } 153 154 inline void SimpleInputState::mouseButtonHeld(MouseButtonCode::ByEnum id) 155 { 156 if (mouseHandler_) 157 mouseHandler_->mouseButtonHeld(id); 158 } 159 160 inline void SimpleInputState::joyStickAxisMoved(unsigned int joyStickID, unsigned int axis, float value) 161 { 162 assert(joyStickID < joyStickHandler_.size()); 163 if (joyStickHandler_[joyStickID]) 164 joyStickHandler_[joyStickID]->joyStickAxisMoved(joyStickID, axis, value); 165 } 166 167 inline void SimpleInputState::joyStickButtonPressed(unsigned int joyStickID, JoyStickButtonCode::ByEnum id) 168 { 169 assert(joyStickID < joyStickHandler_.size()); 170 if (joyStickHandler_[joyStickID]) 171 joyStickHandler_[joyStickID]->joyStickButtonPressed(joyStickID, id); 172 } 173 174 inline void SimpleInputState::joyStickButtonReleased(unsigned int joyStickID, JoyStickButtonCode::ByEnum id) 175 { 176 assert(joyStickID < joyStickHandler_.size()); 177 if (joyStickHandler_[joyStickID]) 178 joyStickHandler_[joyStickID]->joyStickButtonReleased(joyStickID, id); 179 } 180 181 inline void SimpleInputState::joyStickButtonHeld(unsigned int joyStickID, JoyStickButtonCode::ByEnum id) 182 { 183 assert(joyStickID < joyStickHandler_.size()); 184 if (joyStickHandler_[joyStickID]) 185 joyStickHandler_[joyStickID]->joyStickButtonHeld(joyStickID, id); 186 } 87 187 } 88 188 -
code/trunk/src/orxonox/gamestates/GSGraphics.cc
r1878 r1887 114 114 // Configure master input state with a KeyBinder 115 115 //masterKeyBinder_ = new KeyBinder(); 116 //masterKeyBinder_->loadBindings("master_keybindings.ini"); 116 117 //inputManager_->getMasterInputState()->addKeyHandler(masterKeyBinder_); 117 118 -
code/trunk/src/orxonox/gamestates/GSLevel.cc
r1826 r1887 36 36 #include "core/input/KeyBinder.h" 37 37 #include "core/Loader.h" 38 #include "core/CommandExecutor.h" 39 #include "core/ConsoleCommand.h" 40 #include "core/ConfigValueIncludes.h" 41 #include "core/CoreIncludes.h" 38 42 #include "objects/Backlight.h" 39 43 #include "objects/Tickable.h" … … 55 59 , hud_(0) 56 60 { 61 RegisterObject(GSLevel); 62 setConfigValues(); 57 63 } 58 64 59 65 GSLevel::~GSLevel() 60 66 { 67 } 68 69 void GSLevel::setConfigValues() 70 { 71 SetConfigValue(keyDetectorCallbackCode_, "KeybindBindingStringKeyName="); 61 72 } 62 73 … … 65 76 inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("game", 20); 66 77 keyBinder_ = new KeyBinder(); 67 keyBinder_->loadBindings( );78 keyBinder_->loadBindings("keybindings.ini"); 68 79 inputState_->setHandler(keyBinder_); 69 80 … … 88 99 // TODO: insert slomo console command with 89 100 // .accessLevel(AccessLevel::Offline).defaultValue(0, 1.0).axisParamIndex(0).isAxisRelative(false); 101 102 // keybind console command 103 FunctorMember<GSLevel>* functor1 = createFunctor(&GSLevel::keybind); 104 functor1->setObject(this); 105 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "keybind")); 106 FunctorMember<GSLevel>* functor2 = createFunctor(&GSLevel::tkeybind); 107 functor2->setObject(this); 108 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor2, "tkeybind")); 109 // set our console command as callback for the key detector 110 InputManager::getInstance().setKeyDetectorCallback(std::string("keybind ") + keyDetectorCallbackCode_); 90 111 } 91 112 … … 145 166 delete this->startLevel_; 146 167 } 168 169 void GSLevel::keybind(const std::string &command) 170 { 171 this->keybindInternal(command, false); 172 } 173 174 void GSLevel::tkeybind(const std::string &command) 175 { 176 this->keybindInternal(command, true); 177 } 178 179 /** 180 @brief 181 Assigns a command string to a key/button/axis. The name is determined via KeyDetector. 182 @param command 183 Command string that can be executed by the CommandExecutor 184 OR: Internal string "KeybindBindingStringKeyName=" used for the second call to identify 185 the key/button/axis that has been activated. This is configured above in enter(). 186 */ 187 void GSLevel::keybindInternal(const std::string& command, bool bTemporary) 188 { 189 static std::string bindingString = ""; 190 static bool bTemporarySaved = false; 191 static bool bound = true; 192 // note: We use a long name to make 'sure' that the user doesn't use it accidentally. 193 // Howerver there will be no real issue if it happens anyway. 194 if (command.find(keyDetectorCallbackCode_) != 0) 195 { 196 if (bound) 197 { 198 COUT(0) << "Press any button/key or move a mouse/joystick axis" << std::endl; 199 InputManager::getInstance().requestEnterState("detector"); 200 bindingString = command; 201 bTemporarySaved = bTemporary; 202 bound = false; 203 } 204 //else: We're still in a keybind command. ignore this call. 205 } 206 else 207 { 208 if (!bound) 209 { 210 // user has pressed the key 211 std::string name = command.substr(this->keyDetectorCallbackCode_.size()); 212 COUT(0) << "Binding string \"" << bindingString << "\" on key '" << name << "'" << std::endl; 213 this->keyBinder_->setBinding(bindingString, name, bTemporarySaved); 214 InputManager::getInstance().requestLeaveState("detector"); 215 bound = true; 216 } 217 // else: A key was pressed within the same tick, ignore it. 218 } 219 } 147 220 } -
code/trunk/src/orxonox/gamestates/GSLevel.h
r1755 r1887 37 37 namespace orxonox 38 38 { 39 class _OrxonoxExport GSLevel : public GameState<GSGraphics> 39 class _OrxonoxExport GSLevel : public GameState<GSGraphics>, public OrxonoxClass 40 40 { 41 friend class ClassIdentifier<GSLevel>; 41 42 public: 42 43 GSLevel(const std::string& name); … … 58 59 float timeFactor_; //!< A factor to change the gamespeed 59 60 61 // console commands 62 void keybind(const std::string& command); 63 void tkeybind(const std::string& command); 64 void keybindInternal(const std::string& command, bool bTemporary); 65 60 66 Ogre::SceneManager* sceneManager_; 61 67 KeyBinder* keyBinder_; //!< tool that loads and manages the input bindings … … 64 70 Level* startLevel_; //!< current hard coded default level 65 71 Level* hud_; //!< 'level' object fo the HUD 72 73 // config values 74 std::string keyDetectorCallbackCode_; 75 76 private: 77 void setConfigValues(); 78 66 79 }; 67 80 } -
code/trunk/src/orxonox/gui/GUIManager.cc
r1878 r1887 279 279 } 280 280 281 void GUIManager::mouseButtonPressed(MouseButton ::Enum id)281 void GUIManager::mouseButtonPressed(MouseButtonCode::ByEnum id) 282 282 { 283 283 try … … 292 292 } 293 293 294 void GUIManager::mouseButtonReleased(MouseButton ::Enum id)294 void GUIManager::mouseButtonReleased(MouseButtonCode::ByEnum id) 295 295 { 296 296 try … … 306 306 307 307 308 inline CEGUI::MouseButton GUIManager::convertButton(MouseButton ::Enum button)308 inline CEGUI::MouseButton GUIManager::convertButton(MouseButtonCode::ByEnum button) 309 309 { 310 310 switch (button) 311 311 { 312 case MouseButton ::Left:312 case MouseButtonCode::Left: 313 313 return CEGUI::LeftButton; 314 314 315 case MouseButton ::Right:315 case MouseButtonCode::Right: 316 316 return CEGUI::RightButton; 317 317 318 case MouseButton ::Middle:318 case MouseButtonCode::Middle: 319 319 return CEGUI::MiddleButton; 320 320 321 case MouseButton ::Button3:321 case MouseButtonCode::Button3: 322 322 return CEGUI::X1Button; 323 323 324 case MouseButton ::Button4:324 case MouseButtonCode::Button4: 325 325 return CEGUI::X2Button; 326 326 -
code/trunk/src/orxonox/gui/GUIManager.h
r1755 r1887 93 93 { } 94 94 95 void mouseButtonPressed (MouseButton ::Enum id);96 void mouseButtonReleased(MouseButton ::Enum id);97 void mouseButtonHeld (MouseButton ::Enum id)95 void mouseButtonPressed (MouseButtonCode::ByEnum id); 96 void mouseButtonReleased(MouseButtonCode::ByEnum id); 97 void mouseButtonHeld (MouseButtonCode::ByEnum id) 98 98 { } 99 99 void mouseMoved (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) … … 123 123 State state_; 124 124 125 static CEGUI::MouseButton convertButton(MouseButton ::Enum button);125 static CEGUI::MouseButton convertButton(MouseButtonCode::ByEnum button); 126 126 127 127 static GUIManager* singletonRef_s;
Note: See TracChangeset
for help on using the changeset viewer.