Changeset 1349 for code/trunk/src/core
- Timestamp:
- May 21, 2008, 9:07:08 PM (17 years ago)
- Location:
- code/trunk/src/core
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/core/CommandExecutor.cc
r1214 r1349 31 31 #include "util/String.h" 32 32 #include "util/Convert.h" 33 #include "util/SubString.h" 33 34 #include "Identifier.h" 34 35 #include "Language.h" … … 173 174 } 174 175 175 KeybindMode CommandEvaluation::getKeybindMode()176 KeybindMode::Enum CommandEvaluation::getKeybindMode() 176 177 { 177 178 if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished) … … 198 199 } 199 200 // FIXME: Had to insert a return statement 200 return (KeybindMode )0;201 return (KeybindMode::Enum)0; 201 202 } 202 203 -
code/trunk/src/core/CommandExecutor.h
r1293 r1349 70 70 std::string read(const std::string& filename); 71 71 72 enum KeybindMode {}; // temporary73 74 72 /////////////////////// 75 73 // CommandEvaluation // … … 82 80 CommandEvaluation(); 83 81 84 KeybindMode getKeybindMode();82 KeybindMode::Enum getKeybindMode(); 85 83 bool isValid() const; 86 84 … … 89 87 inline std::string getAdditionalParameter() const 90 88 { return (this->additionalParameter_ != "") ? (" " + this->additionalParameter_) : ""; } 91 inline std::string getCommandString() const { return this->processedCommand_; } 89 inline ExecutorStatic* getEvaluatedExecutor() { return evaluatedExecutor_; } 90 inline std::string getCommandString() { return this->processedCommand_; } 92 91 93 92 void setEvaluatedParameter(unsigned int index, MultiTypeMath param); -
code/trunk/src/core/CorePrereqs.h
r1293 r1349 78 78 #endif 79 79 80 namespace KeybindMode 81 { 82 enum Enum 83 { 84 OnPress, 85 OnHold, 86 OnRelease, 87 None 88 }; 89 }; 90 80 91 typedef std::string LanguageEntryLabel; 81 92 -
code/trunk/src/core/Executor.cc
r1062 r1349 39 39 this->name_ = name; 40 40 this->accessLevel_ = level; 41 this->keybindMode_ = KeybindMode::OnPress; 42 this->axisParamIndex_ = -1; 43 this->bAxisRelative_ = false; 41 44 42 45 this->bAddedDescription_ = false; -
code/trunk/src/core/Executor.h
r1062 r1349 204 204 { return this->accessLevel_; } 205 205 206 inline Executor& setKeybindMode(KeybindMode::Enum mode) 207 { this->keybindMode_ = mode; return *this; } 208 inline KeybindMode::Enum getKeybindMode() const 209 { return this->keybindMode_; } 210 211 inline Executor& setAxisParamIndex(int index) 212 { this->axisParamIndex_ = index; return *this; } 213 inline int getAxisParamIndex() const 214 { return this->axisParamIndex_; } 215 216 inline Executor& setIsAxisRelative(bool val) 217 { this->bAxisRelative_ = val; return *this; } 218 inline int getIsAxisRelative() const 219 { return this->bAxisRelative_; } 220 206 221 Executor& setDefaultValues(const MultiTypeMath& param1); 207 222 Executor& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2); … … 233 248 MultiTypeMath defaultValue_[MAX_FUNCTOR_ARGUMENTS]; 234 249 bool bAddedDefaultValue_[MAX_FUNCTOR_ARGUMENTS]; 250 251 KeybindMode::Enum keybindMode_; 252 int axisParamIndex_; 253 bool bAxisRelative_; 235 254 236 255 private: -
code/trunk/src/core/InputBuffer.cc
r1293 r1349 173 173 } 174 174 175 /** 176 * This tick() function is called by the InputManager if the InputBuffer is active. 177 * @param dt Delta time 178 */ 175 179 void InputBuffer::tick(float dt) 176 180 { … … 187 191 } 188 192 189 boolInputBuffer::keyPressed(const KeyEvent &evt)193 void InputBuffer::keyPressed(const KeyEvent &evt) 190 194 { 191 195 lastKey_ = evt.key; … … 195 199 196 200 processKey(evt); 197 return true; 198 } 199 200 bool InputBuffer::keyHeld(const KeyEvent& evt) 201 } 202 203 void InputBuffer::keyHeld(const KeyEvent& evt) 201 204 { 202 205 if (evt.key == lastKey_) … … 208 211 } 209 212 } 210 return true;211 213 } 212 214 -
code/trunk/src/core/InputBuffer.h
r1293 r1349 43 43 {}; 44 44 45 class _CoreExport InputBuffer : public KeyHandler, public TickableReal45 class _CoreExport InputBuffer : public KeyHandler, public OrxonoxClass 46 46 { 47 47 struct InputBufferListenerTuple … … 101 101 bool charIsAllowed(const char& input); 102 102 103 boolkeyPressed (const KeyEvent& evt);104 bool keyReleased(const KeyEvent& evt) { return true;}105 boolkeyHeld (const KeyEvent& evt);103 void keyPressed (const KeyEvent& evt); 104 void keyReleased(const KeyEvent& evt) { } 105 void keyHeld (const KeyEvent& evt); 106 106 void processKey (const KeyEvent &e); 107 107 -
code/trunk/src/core/InputHandler.cc
r1293 r1349 34 34 #include "InputHandler.h" 35 35 #include "util/Convert.h" 36 #include "util/SubString.h" 37 #include "util/String.h" 36 38 #include "Debug.h" 37 39 #include "ConfigValueIncludes.h" 38 40 #include "CoreIncludes.h" 39 41 #include "CommandExecutor.h" 42 #include "Executor.h" 40 43 41 44 namespace orxonox 42 45 { 43 46 // ############################### 47 // ###### Button ###### 48 // ############################### 49 50 bool BufferedParamCommand::execute() 51 { 52 if (nValuesAdded_) 53 { 54 BufferedParamCommand& cmd = *this; 55 cmd.evaluation_.setEvaluatedParameter(cmd.paramIndex_, cmd.value_); 56 // reset 57 cmd.nValuesAdded_ = 0; 58 cmd.value_ = 0; 59 return CommandExecutor::execute(cmd.evaluation_); 60 } 61 else 62 return true; 63 } 64 65 bool SimpleCommand::execute(float abs, float rel) 66 { 67 return CommandExecutor::execute(evaluation_); 68 } 69 70 bool ParamCommand::execute(float abs, float rel) 71 { 72 BufferedParamCommand& paramCommand = *paramCommand_; 73 // command has an additional parameter 74 if (bRelative_ && (rel > 0 || rel < 0)) 75 { 76 // we have to calculate a relative movement. 77 // paramModifier_ says how much one keystroke is 78 paramCommand.value_ += paramModifier_ * rel; 79 } 80 else if (abs > 0 || abs < 0) 81 { 82 // we have to calculate absolute position of the axis. 83 // Since there might be another axis that is affected, we have to wait and 84 // store the result in a temporary place 85 paramCommand.value_ = (paramCommand.value_ * paramCommand.nValuesAdded_ + paramModifier_ * abs) 86 /++paramCommand.nValuesAdded_; 87 } 88 return true; 89 } 90 91 void Button::clear() 92 { 93 for (unsigned int j = 0; j < 3; j++) 94 { 95 if (nCommands_[j]) 96 { 97 // delete all commands and the command pointer array 98 for (unsigned int i = 0; i < nCommands_[j]; i++) 99 delete commands_[j][i]; 100 delete[] commands_[j]; 101 commands_[j] = 0; 102 nCommands_[j] = 0; 103 } 104 else 105 { 106 commands_[j] = 0; 107 } 108 } 109 } 110 111 void Button::parse(std::vector<BufferedParamCommand*>& paramCommandBuffer) 112 { 113 if (isEmpty(bindingString_)) 114 { 115 clear(); 116 return; 117 } 118 119 // use std::vector for a temporary dynamic array 120 std::vector<BaseCommand*> commands[3]; 121 122 123 // separate the commands 124 SubString commandStrings(bindingString_, "|", SubString::WhiteSpaces, false, 125 '\\', false, '"', false, '(', ')', false, '\0'); 126 127 for (unsigned int iCommand = 0; iCommand < commandStrings.size(); iCommand++) 128 { 129 if (commandStrings[iCommand] != "") 130 { 131 SubString tokens(commandStrings[iCommand], " ", SubString::WhiteSpaces, false, 132 '\\', false, '"', false, '(', ')', false, '\0'); 133 134 unsigned int iToken = 0; 135 136 // for real axes, we can feed a ButtonThreshold argument as entire command 137 if (getLowercase(tokens[0]) == "buttonthreshold") 138 { 139 if (tokens.size() == 1) 140 continue; 141 // may fail, but doesn't matter 142 convertValue(&buttonThreshold_, tokens[1]); 143 continue; 144 } 145 146 // first argument can be OnPress, OnHold OnRelease or nothing 147 KeybindMode::Enum mode = KeybindMode::None; 148 if (getLowercase(tokens[iToken]) == "onpress") 149 mode = KeybindMode::OnPress, iToken++; 150 if (getLowercase(tokens[iToken]) == "onrelease") 151 mode = KeybindMode::OnRelease, iToken++; 152 if (getLowercase(tokens[iToken]) == "onhold") 153 mode = KeybindMode::OnHold, iToken++; 154 155 if (iToken == tokens.size()) 156 continue; 157 158 // second argument can be the amplitude for the case it as an axis command 159 // default amplitude is 1.0f 160 float paramModifier = 1.0f; 161 if (getLowercase(tokens[iToken]) == "axisamp") 162 { 163 iToken++; 164 if (iToken == tokens.size() || !convertValue(¶mModifier, tokens[iToken])) 165 { 166 COUT(2) << "Error while parsing key binding " << name_ 167 << ". Numeric expression expected afer 'AxisAmp', switching to default value" << std::endl; 168 if (iToken == tokens.size()) 169 continue; 170 } 171 iToken++; 172 } 173 174 // no more arguments expected except for the actual command 175 if (iToken == tokens.size()) 176 continue; 177 178 std::string commandStr; 179 while (iToken != tokens.size()) 180 commandStr += tokens[iToken++] + " "; 181 182 // evaluate the command 183 CommandEvaluation eval = CommandExecutor::evaluate(commandStr); 184 if (!eval.isValid()) 185 continue; 186 187 // check for param command 188 int paramIndex = eval.getEvaluatedExecutor()->getAxisParamIndex(); 189 // TODO: check in Executor for correct paramIndex 190 if (paramIndex >= 0) 191 { 192 // parameter supported command 193 ParamCommand* cmd = new ParamCommand(); 194 cmd->paramModifier_ = paramModifier; 195 cmd->bRelative_ = eval.getEvaluatedExecutor()->getIsAxisRelative(); 196 197 // add command to the buffer if not yet existing 198 for (unsigned int iParamCmd = 0; iParamCmd < paramCommandBuffer.size(); iParamCmd++) 199 { 200 if (getLowercase(paramCommandBuffer[iParamCmd]->evaluation_.getCommandString()) 201 == getLowercase(commandStr)) 202 { 203 // already in list 204 cmd->paramCommand_ = paramCommandBuffer[iParamCmd]; 205 break; 206 } 207 } 208 if (cmd->paramCommand_ == 0) 209 { 210 cmd->paramCommand_ = new BufferedParamCommand(); 211 paramCommandBuffer.push_back(cmd->paramCommand_); 212 cmd->paramCommand_->evaluation_ = eval; 213 cmd->paramCommand_->paramIndex_ = paramIndex; 214 } 215 216 217 // we don't know whether this is an actual axis or just a button 218 if (mode == KeybindMode::None) 219 { 220 if (!addParamCommand(cmd)) 221 { 222 mode = eval.getEvaluatedExecutor()->getKeybindMode(); 223 commands[mode].push_back(cmd); 224 } 225 } 226 } 227 else 228 { 229 SimpleCommand* cmd = new SimpleCommand(); 230 cmd->evaluation_ = eval; 231 232 //TODO: check CommandEvaluation for correct KeybindMode 233 if (mode == KeybindMode::None) 234 mode = eval.getEvaluatedExecutor()->getKeybindMode(); 235 236 commands[mode].push_back(cmd); 237 } 238 } 239 } 240 241 for (unsigned int j = 0; j < 3; j++) 242 { 243 nCommands_[j] = commands[j].size(); 244 if (nCommands_[j]) 245 { 246 commands_[j] = new BaseCommand*[nCommands_[j]]; 247 for (unsigned int i = 0; i < commands[j].size(); i++) 248 commands_[j][i] = commands[j][i]; 249 } 250 else 251 commands_[j] = 0; 252 } 253 } 254 255 bool Button::execute(KeybindMode::Enum mode, float abs, float rel) 256 { 257 // execute all the parsed commands in the string 258 for (unsigned int iCommand = 0; iCommand < nCommands_[mode]; iCommand++) 259 commands_[mode][iCommand]->execute(abs, rel); 260 return true; 261 } 262 263 void HalfAxis::clear() 264 { 265 Button::clear(); 266 if (nParamCommands_) 267 { 268 // delete all commands and the command pointer array 269 for (unsigned int i = 0; i < nParamCommands_; i++) 270 delete paramCommands_[i]; 271 delete[] paramCommands_; 272 } 273 else 274 { 275 nParamCommands_ = 0; nParamCommands_ = 0; 276 } 277 } 278 279 bool HalfAxis::addParamCommand(ParamCommand* command) 280 { 281 ParamCommand** cmds = paramCommands_; 282 paramCommands_ = new ParamCommand*[++nParamCommands_]; 283 unsigned int i; 284 for (i = 0; i < nParamCommands_ - 1; i++) 285 paramCommands_[i] = cmds[i]; 286 paramCommands_[i] = command; 287 delete[] cmds; 288 return true; 289 } 290 291 bool HalfAxis::execute() 292 { 293 bool success = true; 294 for (unsigned int i = 0; i < nParamCommands_; i++) 295 success = success && paramCommands_[i]->execute(absVal_, relVal_); 296 return success; 297 } 298 299 300 // ############################### 44 301 // ###### KeyBinder ###### 45 302 // ############################### … … 48 305 @brief Constructor that does as little as necessary. 49 306 */ 50 KeyBinder::KeyBinder() 307 KeyBinder::KeyBinder() : deriveTime_(0.0f) 51 308 { 52 309 RegisterObject(KeyBinder); 53 clearBindings(); 54 310 311 // keys 55 312 std::string keyNames[] = { 56 "UNASSIGNED", 57 "ESCAPE", 58 "1", 59 "2", 60 "3", 61 "4", 62 "5", 63 "6", 64 "7", 65 "8", 66 "9", 67 "0", 68 "MINUS", 69 "EQUALS", 70 "BACK", 71 "TAB", 72 "Q", 73 "W", 74 "E", 75 "R", 76 "T", 77 "Y", 78 "U", 79 "I", 80 "O", 81 "P", 82 "LBRACKET", 83 "RBRACKET", 84 "RETURN", 85 "LCONTROL", 86 "A", 87 "S", 88 "D", 89 "F", 90 "G", 91 "H", 92 "J", 93 "K", 94 "L", 95 "SEMICOLON", 96 "APOSTROPHE", 97 "GRAVE", 98 "LSHIFT", 99 "BACKSLASH", 100 "Z", 101 "X", 102 "C", 103 "V", 104 "B", 105 "N", 106 "M", 107 "COMMA", 108 "PERIOD", 109 "SLASH", 110 "RSHIFT", 111 "MULTIPLY", 112 "LMENU", 113 "SPACE", 114 "CAPITAL", 115 "F1", 116 "F2", 117 "F3", 118 "F4", 119 "F5", 120 "F6", 121 "F7", 122 "F8", 123 "F9", 124 "F10", 125 "NUMLOCK", 126 "SCROLL", 127 "NUMPAD7", 128 "NUMPAD8", 129 "NUMPAD9", 130 "SUBTRACT", 131 "NUMPAD4", 132 "NUMPAD5", 133 "NUMPAD6", 134 "ADD", 135 "NUMPAD1", 136 "NUMPAD2", 137 "NUMPAD3", 138 "NUMPAD0", 139 "DECIMAL", 140 "","", 141 "OEM_102", 142 "F11", 143 "F12", 144 "","","","","","","","","","","", 145 "F13", 146 "F14", 147 "F15", 148 "","","","","","","","","","", 149 "KANA", 150 "","", 151 "ABNT_C1", 152 "","","","","", 153 "CONVERT", 154 "", 155 "NOCONVERT", 156 "", 157 "YEN", 158 "ABNT_C2", 159 "","","","","","","","","","","","","","", 160 "NUMPADEQUALS", 161 "","", 162 "PREVTRACK", 163 "AT", 164 "COLON", 165 "UNDERLINE", 166 "KANJI", 167 "STOP", 168 "AX", 169 "UNLABELED", 170 "NEXTTRACK", 171 "","", 172 "NUMPADENTER", 173 "RCONTROL", 174 "","", 175 "MUTE", 176 "CALCULATOR", 177 "PLAYPAUSE", 178 "", 179 "MEDIASTOP", 180 "","","","","","","","","", 181 "VOLUMEDOWN", 182 "", 183 "VOLUMEUP", 184 "", 185 "WEBHOME", 186 "NUMPADCOMMA", 187 "", 188 "DIVIDE", 189 "", 190 "SYSRQ", 191 "RMENU", 192 "","","","","","","","","","","","", 193 "PAUSE", 194 "", 195 "HOME", 196 "UP", 197 "PGUP", 198 "", 199 "LEFT", 200 "", 201 "RIGHT", 202 "", 203 "END", 204 "DOWN", 205 "PGDOWN", 206 "INSERT", 207 "DELETE", 208 "","","","","","","", 209 "LWIN", 210 "RWIN", 211 "APPS", 212 "POWER", 213 "SLEEP", 214 "","","", 215 "WAKE", 216 "", 217 "WEBSEARCH", 218 "WEBFAVORITES", 219 "WEBREFRESH", 220 "WEBSTOP", 221 "WEBFORWARD", 222 "WEBBACK", 223 "MYCOMPUTER", 224 "MAIL", 225 "MEDIASELECT" 313 "UNASSIGNED", 314 "ESCAPE", 315 "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", 316 "MINUS", "EQUALS", "BACK", "TAB", 317 "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", 318 "LBRACKET", "RBRACKET", 319 "RETURN", "LCONTROL", 320 "A", "S", "D", "F", "G", "H", "J", "K", "L", 321 "SEMICOLON", "APOSTROPHE", "GRAVE", 322 "LSHIFT", "BACKSLASH", 323 "Z", "X", "C", "V", "B", "N", "M", 324 "COMMA", "PERIOD", "SLASH", 325 "RSHIFT", 326 "MULTIPLY", 327 "LMENU", 328 "SPACE", 329 "CAPITAL", 330 "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", 331 "NUMLOCK", "SCROLL", 332 "NUMPAD7", "NUMPAD8", "NUMPAD9", 333 "SUBTRACT", 334 "NUMPAD4", "NUMPAD5", "NUMPAD6", 335 "ADD", 336 "NUMPAD1", "NUMPAD2", "NUMPAD3", "NUMPAD0", 337 "DECIMAL", 338 "","", 339 "OEM_102", 340 "F11", "F12", 341 "","","","","","","","","","","", 342 "F13", "F14", "F15", 343 "","","","","","","","","","", 344 "KANA", 345 "","", 346 "ABNT_C1", 347 "","","","","", 348 "CONVERT", 349 "", 350 "NOCONVERT", 351 "", 352 "YEN", 353 "ABNT_C2", 354 "","","","","","","","","","","","","","", 355 "NUMPADEQUALS", 356 "","", 357 "PREVTRACK", 358 "AT", 359 "COLON", "UNDERLINE", 360 "KANJI", 361 "STOP", 362 "AX", 363 "UNLABELED", 364 "NEXTTRACK", 365 "","", 366 "NUMPADENTER", 367 "RCONTROL", 368 "","", 369 "MUTE", 370 "CALCULATOR", 371 "PLAYPAUSE", 372 "", 373 "MEDIASTOP", 374 "","","","","","","","","", 375 "VOLUMEDOWN", 376 "", 377 "VOLUMEUP", 378 "", 379 "WEBHOME", 380 "NUMPADCOMMA", 381 "", 382 "DIVIDE", 383 "", 384 "SYSRQ", 385 "RMENU", 386 "","","","","","","","","","","","", 387 "PAUSE", 388 "", 389 "HOME", 390 "UP", 391 "PGUP", 392 "", 393 "LEFT", 394 "", 395 "RIGHT", 396 "", 397 "END", "DOWN", "PGDOWN", "INSERT", "DELETE", 398 "","","","","","","", 399 "LWIN", "RWIN", "APPS", 400 "POWER", "SLEEP", 401 "","","", 402 "WAKE", 403 "", 404 "WEBSEARCH", "WEBFAVORITES", "WEBREFRESH", "WEBSTOP", "WEBFORWARD", "WEBBACK", 405 "MYCOMPUTER", "MAIL", "MEDIASELECT" 226 406 }; 227 for (int i = 0; i < numberOfKeys_s; i++) 228 keyNames_[i] = keyNames[i]; 229 407 for (unsigned int i = 0; i < nKeys_s; i++) 408 keys_[i].name_ = "Key" + keyNames[i]; 409 410 // mouse buttons 230 411 std::string mouseButtonNames[] = { 231 412 "MouseLeft", "MouseRight", "MouseMiddle", 232 413 "MouseButton3", "MouseButton4", "MouseButton5", 233 "MouseButton6", "MouseButton7" }; 234 for (int i = 0; i < numberOfMouseButtons_s; i++) 235 mouseButtonNames_[i] = mouseButtonNames[i]; 236 237 for (int i = 0; i < numberOfJoyStickButtons_s; i++) 238 joyStickButtonNames_[i] = "JoyStick" + getConvertedValue<int, std::string>(i); 414 "MouseButton6", "MouseButton7", 415 "MouseWheel1Up", "MouseWheel1Down", 416 "MouseWheel2Up", "MouseWheel2Down" }; 417 for (unsigned int i = 0; i < nMouseButtons_s; i++) 418 mouseButtons_[i].name_ = mouseButtonNames[i]; 419 420 // joy stick buttons 421 for (unsigned int i = 0; i < 32; i++) 422 joyStickButtons_[i].name_ = "JoyButton" + getConvertedValue<int, std::string>(i); 423 for (unsigned int i = 32; i < nJoyStickButtons_s; i += 4) 424 { 425 joyStickButtons_[i + 0].name_ = "JoyPOV" + getConvertedValue<int, std::string>((i - 32)/4 + 1) + "North"; 426 joyStickButtons_[i + 1].name_ = "JoyPOV" + getConvertedValue<int, std::string>((i - 32)/4 + 1) + "South"; 427 joyStickButtons_[i + 2].name_ = "JoyPOV" + getConvertedValue<int, std::string>((i - 32)/4 + 1) + "East"; 428 joyStickButtons_[i + 3].name_ = "JoyPOV" + getConvertedValue<int, std::string>((i - 32)/4 + 1) + "West"; 429 } 430 431 // half axes 432 std::string rawNames[nHalfAxes_s/2]; 433 rawNames[0] = "MouseX"; 434 rawNames[1] = "MouseY"; 435 rawNames[2] = "Empty1"; 436 rawNames[3] = "Empty2"; 437 for (unsigned int i = 4; i < nHalfAxes_s/2; i++) 438 rawNames[i] = "JoyAxis" + getConvertedValue<int, std::string>(i - 3); 439 for (unsigned int i = 0; i < nHalfAxes_s/2; i++) 440 { 441 halfAxes_[i * 2 + 0].name_ = rawNames[i] + "Pos"; 442 halfAxes_[i * 2 + 1].name_ = rawNames[i] + "Neg"; 443 } 444 445 for (unsigned int i = 0; i < this->nHalfAxes_s; i++) 446 halfAxes_[i].buttonThreshold_ = buttonThreshold_; 239 447 } 240 448 … … 244 452 KeyBinder::~KeyBinder() 245 453 { 454 // almost no destructors required because most of the arrays are static. 455 clearBindings(); // does some destruction work 456 } 457 458 /** 459 @brief Loads the key and button bindings. 460 @return True if loading succeeded. 461 */ 462 void KeyBinder::loadBindings() 463 { 464 COUT(3) << "KeyBinder: Loading key bindings..." << std::endl; 465 466 ConfigFileManager::getSingleton()->setFile(CFT_Keybindings, "keybindings.ini"); 467 clearBindings(); 468 setConfigValues(); 469 470 COUT(3) << "KeyBinder: Loading key bindings done." << std::endl; 246 471 } 247 472 … … 251 476 void KeyBinder::setConfigValues() 252 477 { 253 ConfigValueContainer* cont; 254 std::string modes[] = {"P_", "R_", "H_"}; 478 SetConfigValue(analogThreshold_, 0.01f) .description("Threshold for analog axes until which the state is 0."); 479 SetConfigValue(bDeriveMouseInput_, false).description("Whether or not to derive moues movement for the absolute value."); 480 SetConfigValue(derivePeriod_, 0.1f) .description("Accuracy of the mouse input deriver. The higher the more precise, but laggier."); 481 SetConfigValue(mouseSensitivity_, 1.0f) .description("Mouse sensitivity."); 482 483 float oldThresh = buttonThreshold_; 484 SetConfigValue(buttonThreshold_, 0.80f).description("Threshold for analog axes until which the button is not pressed."); 485 if (oldThresh != buttonThreshold_) 486 for (unsigned int i = 0; i < nHalfAxes_s; i++) 487 if (halfAxes_[i].buttonThreshold_ == oldThresh) 488 halfAxes_[i].buttonThreshold_ = buttonThreshold_; 255 489 256 490 // keys 257 for (int i = 0; i < numberOfKeys_s; i++) 258 { 259 for (int j = 0; j < 3; j++) 260 { 261 cont = getIdentifier()->getConfigValueContainer(modes[j] + keyNames_[i]); 262 if (!cont) 263 { 264 cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), modes[j] + keyNames_[i], ""); 265 getIdentifier()->addConfigValueContainer(modes[j] + keyNames_[i], cont); 266 } 267 switch (j) 268 { 269 case 0: 270 cont->getValue(&bindingsKeyPress_[i].commandStr); 271 break; 272 case 1: 273 cont->getValue(&bindingsKeyRelease_[i].commandStr); 274 break; 275 case 2: 276 cont->getValue(&bindingsKeyHold_[i].commandStr); 277 } 278 } 279 } 280 491 for (unsigned int i = 0; i < nKeys_s; i++) 492 readTrigger(keys_[i]); 281 493 // mouse buttons 282 for (int i = 0; i < numberOfMouseButtons_s; i++) 283 { 284 for (int j = 0; j < 3; j++) 285 { 286 cont = getIdentifier()->getConfigValueContainer(modes[j] + mouseButtonNames_[i]); 287 if (!cont) 288 { 289 cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), modes[j] + mouseButtonNames_[i], ""); 290 getIdentifier()->addConfigValueContainer(modes[j] + mouseButtonNames_[i], cont); 291 } 292 switch (j) 293 { 294 case 0: 295 cont->getValue(&bindingsMouseButtonPress_[i].commandStr); 296 break; 297 case 1: 298 cont->getValue(&bindingsMouseButtonRelease_[i].commandStr); 299 break; 300 case 2: 301 cont->getValue(&bindingsMouseButtonHold_[i].commandStr); 302 } 303 } 304 } 305 494 for (unsigned int i = 0; i < nMouseButtons_s; i++) 495 readTrigger(mouseButtons_[i]); 306 496 // joy stick buttons 307 for (int i = 0; i < numberOfJoyStickButtons_s; i++) 308 { 309 for (int j = 0; j < 3; j++) 310 { 311 cont = getIdentifier()->getConfigValueContainer(modes[j] + joyStickButtonNames_[i]); 312 if (!cont) 313 { 314 cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), modes[j] + joyStickButtonNames_[i], ""); 315 getIdentifier()->addConfigValueContainer(modes[j] + joyStickButtonNames_[i], cont); 316 } 317 switch (j) 318 { 319 case 0: 320 cont->getValue(&bindingsJoyStickButtonPress_[i].commandStr); 321 break; 322 case 1: 323 cont->getValue(&bindingsJoyStickButtonRelease_[i].commandStr); 324 break; 325 case 2: 326 cont->getValue(&bindingsJoyStickButtonHold_[i].commandStr); 327 } 328 } 497 for (unsigned int i = 0; i < nJoyStickButtons_s; i++) 498 readTrigger(joyStickButtons_[i]); 499 // half axes 500 for (unsigned int i = 0; i < nHalfAxes_s; i++) 501 readTrigger(halfAxes_[i]); 502 } 503 504 void KeyBinder::readTrigger(Button& button) 505 { 506 // config value stuff 507 ConfigValueContainer* cont = getIdentifier()->getConfigValueContainer(button.name_); 508 if (!cont) 509 { 510 cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), button.name_, ""); 511 getIdentifier()->addConfigValueContainer(button.name_, cont); 512 } 513 std::string old = button.bindingString_; 514 cont->getValue(&button.bindingString_); 515 516 // keybinder stuff 517 if (old != button.bindingString_) 518 { 519 // binding has changed 520 button.parse(paramCommandBuffer_); 329 521 } 330 522 } … … 333 525 @brief Overwrites all bindings with "" 334 526 */ 335 void KeyBinder::clearBindings() 336 { 337 for (int i = 0; i < numberOfKeys_s; i++) 338 { 339 bindingsKeyPress_ [i].commandStr = ""; 340 bindingsKeyRelease_[i].commandStr = ""; 341 bindingsKeyHold_ [i].commandStr = ""; 342 } 343 for (int i = 0; i < numberOfMouseButtons_s; i++) 344 { 345 bindingsMouseButtonPress_ [i].commandStr = ""; 346 bindingsMouseButtonRelease_[i].commandStr = ""; 347 bindingsMouseButtonHold_ [i].commandStr = ""; 348 } 349 for (int i = 0; i < numberOfJoyStickButtons_s; i++) 350 { 351 bindingsJoyStickButtonPress_ [i].commandStr = ""; 352 bindingsJoyStickButtonRelease_[i].commandStr = ""; 353 bindingsJoyStickButtonHold_ [i].commandStr = ""; 354 } 355 } 356 357 /** 358 @brief Loads the key and button bindings. 359 @return True if loading succeeded. 360 */ 361 bool KeyBinder::loadBindings() 362 { 363 COUT(ORX_DEBUG) << "KeyBinder: Loading key bindings..." << std::endl; 364 365 ConfigFileManager::getSingleton()->setFile(CFT_Keybindings, "keybindings.ini"); 366 setConfigValues(); 367 368 // evaluate the key bindings 369 // TODO: what if binding is invalid? 370 for (int i = 0; i < numberOfKeys_s; i++) 371 { 372 if (bindingsKeyPress_[i].commandStr != "") 527 void KeyBinder::clearBindings(bool bInit) 528 { 529 for (unsigned int i = 0; i < nKeys_s; i++) 530 keys_[i].clear(); 531 532 for (unsigned int i = 0; i < nMouseButtons_s; i++) 533 mouseButtons_[i].clear(); 534 535 for (unsigned int i = 0; i < nJoyStickButtons_s; i++) 536 joyStickButtons_[i].clear(); 537 538 for (unsigned int i = 0; i < nHalfAxes_s; i++) 539 halfAxes_[i].clear(); 540 541 for (unsigned int i = 0; i < paramCommandBuffer_.size(); i++) 542 delete paramCommandBuffer_[i]; 543 paramCommandBuffer_.clear(); 544 } 545 546 void KeyBinder::tick(float dt) 547 { 548 // we have to process all the analog input since there is e.g. no 'mouseDoesntMove' event. 549 for (unsigned int i = 0; i < nHalfAxes_s; i++) 550 { 551 if (halfAxes_[i].hasChanged_) 373 552 { 374 bindingsKeyPress_[i].evaluation = CommandExecutor::evaluate(bindingsKeyPress_[i].commandStr); 375 bindingsKeyPress_[i].commandStr = bindingsKeyPress_[i].evaluation.getCommandString(); 553 if (!halfAxes_[i].wasDown_ && halfAxes_[i].absVal_ > halfAxes_[i].buttonThreshold_) 554 { 555 halfAxes_[i].wasDown_ = true; 556 if (halfAxes_[i].nCommands_[KeybindMode::OnPress]) 557 halfAxes_[i].execute(KeybindMode::OnPress); 558 } 559 else if (halfAxes_[i].wasDown_ && halfAxes_[i].absVal_ < halfAxes_[i].buttonThreshold_) 560 { 561 halfAxes_[i].wasDown_ = false; 562 if (halfAxes_[i].nCommands_[KeybindMode::OnRelease]) 563 halfAxes_[i].execute(KeybindMode::OnRelease); 564 } 565 if (halfAxes_[i].wasDown_) 566 { 567 if (halfAxes_[i].nCommands_[KeybindMode::OnHold]) 568 halfAxes_[i].execute(KeybindMode::OnHold); 569 } 570 halfAxes_[i].hasChanged_ = false; 376 571 } 377 } 378 379 COUT(ORX_DEBUG) << "KeyBinder: Loading key bindings done." << std::endl; 380 return true; 381 } 382 383 bool KeyBinder::executeSimpleBinding(KeyBinding& binding) 384 { 385 if (binding.commandStr != "") 386 { 387 if (binding.commandStr != binding.evaluation.getCommandString()) 572 573 // these are the actually useful axis bindings for analog input AND output 574 if (halfAxes_[i].relVal_ > analogThreshold_ || halfAxes_[i].absVal_ > analogThreshold_) 388 575 { 389 // key binding has changed, reevaluate the command string. 390 binding.evaluation = CommandExecutor::evaluate(binding.commandStr); 391 binding.commandStr = binding.evaluation.getCommandString(); 576 halfAxes_[i].execute(); 392 577 } 393 COUT(ORX_DEBUG) << "Keybinding: Executing command: " << binding.commandStr << std::endl; 394 CommandExecutor::execute(binding.commandStr); 395 } 396 397 return true; 398 } 399 400 401 /** 402 @brief Event handler for the keyPressed Event. 403 @param e Event information 404 */ 405 bool KeyBinder::keyPressed(const KeyEvent& evt) 406 { 407 // find the appropriate key binding 408 executeSimpleBinding(bindingsKeyPress_[int(evt.key)]); 409 410 return true; 411 } 412 413 /** 414 @brief Event handler for the keyReleased Event. 415 @param e Event information 416 */ 417 bool KeyBinder::keyReleased(const KeyEvent& evt) 418 { 419 // find the appropriate key binding 420 executeSimpleBinding(bindingsKeyRelease_[int(evt.key)]); 421 422 return true; 423 } 424 425 /** 426 @brief Event handler for the keyHeld Event. 427 @param e Mouse state information 428 */ 429 bool KeyBinder::keyHeld(const KeyEvent& evt) 430 { 431 // find the appropriate key binding 432 executeSimpleBinding(bindingsKeyHold_[int(evt.key)]); 433 434 return true; 435 } 578 } 579 580 if (bDeriveMouseInput_) 581 { 582 if (deriveTime_ > derivePeriod_) 583 { 584 deriveTime_ = 0.0f; 585 //CCOUT(3) << "mouse abs: "; 586 for (int i = 0; i < 2; i++) 587 { 588 if (mouseRelative_[i] > 0) 589 { 590 halfAxes_[2*i + 0].absVal_ = mouseRelative_[i] * derivePeriod_ / 500 * mouseSensitivity_; 591 halfAxes_[2*i + 1].absVal_ = 0.0f; 592 } 593 else if (mouseRelative_[0] < 0) 594 { 595 halfAxes_[2*i + 0].absVal_ = 0.0f; 596 halfAxes_[2*i + 1].absVal_ = -mouseRelative_[i] * derivePeriod_ / 500 * mouseSensitivity_; 597 } 598 //COUT(3) << mouseRelative_[i] << " | "; 599 mouseRelative_[i] = 0; 600 } 601 //COUT(3) << std::endl; 602 } 603 else 604 deriveTime_ += dt; 605 } 606 607 // execute all buffered bindings (addional parameter) 608 for (unsigned int i = 0; i < paramCommandBuffer_.size(); i++) 609 paramCommandBuffer_[i]->execute(); 610 611 // always reset the relative movement of the mouse 612 for (unsigned int i = 0; i < 8; i++) 613 halfAxes_[i].relVal_ = 0.0f; 614 } 615 616 void KeyBinder::keyPressed (const KeyEvent& evt) 617 { keys_[evt.key].execute(KeybindMode::OnPress); } 618 619 void KeyBinder::keyReleased(const KeyEvent& evt) 620 { keys_[evt.key].execute(KeybindMode::OnRelease); } 621 622 void KeyBinder::keyHeld (const KeyEvent& evt) 623 { keys_[evt.key].execute(KeybindMode::OnHold); } 624 625 626 void KeyBinder::mouseButtonPressed (MouseButton::Enum id) 627 { mouseButtons_[id].execute(KeybindMode::OnPress); } 628 629 void KeyBinder::mouseButtonReleased(MouseButton::Enum id) 630 { mouseButtons_[id].execute(KeybindMode::OnRelease); } 631 632 void KeyBinder::mouseButtonHeld (MouseButton::Enum id) 633 { mouseButtons_[id].execute(KeybindMode::OnHold); } 634 635 636 void KeyBinder::joyStickButtonPressed (int joyStickID, int button) 637 { joyStickButtons_[button].execute(KeybindMode::OnPress); } 638 639 void KeyBinder::joyStickButtonReleased(int joyStickID, int button) 640 { joyStickButtons_[button].execute(KeybindMode::OnRelease); } 641 642 void KeyBinder::joyStickButtonHeld (int joyStickID, int button) 643 { joyStickButtons_[button].execute(KeybindMode::OnHold); } 436 644 437 645 /** … … 439 647 @param e Mouse state information 440 648 */ 441 bool KeyBinder::mouseMoved(const MouseState &evt) 442 { 443 /*if (bindingMouseMoved_.commandStr != "") 444 { 445 if (bindingMouseMoved_.commandStr != bindingMouseMoved_.evaluation.getCommandString()) 649 void KeyBinder::mouseMoved(IntVector2 abs_, IntVector2 rel_, IntVector2 clippingSize) 650 { 651 if (!bDeriveMouseInput_) 652 { 653 // y axis of mouse input is inverted 654 int rel[] = { rel_.x, -rel_.y }; 655 656 //COUT(3) << rel[0] << " | " << rel[1] << std::endl; 657 658 for (int i = 0; i < 2; i++) 446 659 { 447 // key binding has changed, reevaluate the command string. 448 bindingMouseMoved_.evaluation = CommandExecutor::evaluate(bindingMouseMoved_.commandStr); 449 bindingMouseMoved_.commandStr = bindingMouseMoved_.evaluation.getCommandString(); 660 if (rel[i]) 661 { 662 // absolute 663 if (mousePosition_[i] >= 0) 664 { 665 mousePosition_[i] += rel[i]; 666 halfAxes_[0 + 2*i].hasChanged_ = true; 667 if (mousePosition_[i] < 0) 668 { 669 halfAxes_[1 + 2*i].hasChanged_ = true; 670 halfAxes_[1 + 2*i].absVal_ = -((float)mousePosition_[i])/1024 * mouseSensitivity_; 671 halfAxes_[0 + 2*i].absVal_ = 0.0f; 672 } 673 else 674 halfAxes_[1 + 2*i].absVal_ = ((float)mousePosition_[i])/1024 * mouseSensitivity_; 675 } 676 else 677 { 678 mousePosition_[i] += rel[i]; 679 halfAxes_[1 + 2*i].hasChanged_ = true; 680 if (mousePosition_[i] > 0) 681 { 682 halfAxes_[0 + 2*i].hasChanged_ = true; 683 halfAxes_[0 + 2*i].absVal_ = ((float)mousePosition_[i])/1024 * mouseSensitivity_; 684 halfAxes_[1 + 2*i].absVal_ = 0.0f; 685 } 686 else 687 halfAxes_[1 + 2*i].absVal_ = -((float)mousePosition_[i])/1024 * mouseSensitivity_; 688 } 689 690 // relative 691 if (rel[i] > 0) 692 halfAxes_[0 + 2*i].relVal_ = ((float)rel[i])/1024 * mouseSensitivity_; 693 else 694 halfAxes_[1 + 2*i].relVal_ = -((float)rel[i])/1024 * mouseSensitivity_; 695 } 450 696 } 451 COUT(3) << "Executing command: " << bindingMouseMoved_.commandStr << std::endl; 452 453 bindingMouseMoved_.evaluation.setEvaluatedParameter( 454 CommandExecutor::execute(bindingMouseMoved_.commandStr); 455 }*/ 456 457 return true; 697 } 698 else 699 { 700 mouseRelative_[0] += rel_.x; 701 mouseRelative_[1] -= rel_.y; 702 } 458 703 } 459 704 … … 462 707 @param e Mouse state information 463 708 */ 464 bool KeyBinder::mouseScrolled(const MouseState &evt) 465 { 466 return true; 467 } 468 469 /** 470 @brief Event handler for the mousePressed Event. 471 @param e Event information 472 @param id The ID of the mouse button 473 */ 474 bool KeyBinder::mouseButtonPressed(const MouseState& state, MouseButton::Enum id) 475 { 476 // find the appropriate key binding 477 executeSimpleBinding(bindingsMouseButtonPress_[int(id)]); 478 479 return true; 480 } 481 482 /** 483 @brief Event handler for the mouseReleased Event. 484 @param e Event information 485 @param id The ID of the mouse button 486 */ 487 bool KeyBinder::mouseButtonReleased(const MouseState& state, MouseButton::Enum id) 488 { 489 // find the appropriate key binding 490 executeSimpleBinding(bindingsMouseButtonRelease_[int(id)]); 491 492 return true; 493 } 494 495 /** 496 @brief Event handler for the mouseHeld Event. 497 @param e Event information 498 @param id The ID of the mouse button 499 */ 500 bool KeyBinder::mouseButtonHeld(const MouseState& state, MouseButton::Enum id) 501 { 502 // find the appropriate key binding 503 executeSimpleBinding(bindingsMouseButtonHold_[int(id)]); 504 505 return true; 506 } 507 508 bool KeyBinder::joyStickButtonPressed(const JoyStickState& state, int button) 509 { 510 // find the appropriate key binding 511 executeSimpleBinding(bindingsJoyStickButtonPress_[button]); 512 513 return true; 514 } 515 516 bool KeyBinder::joyStickButtonReleased(const JoyStickState& state, int button) 517 { 518 // find the appropriate key binding 519 executeSimpleBinding(bindingsJoyStickButtonRelease_[button]); 520 521 return true; 522 } 523 524 bool KeyBinder::joyStickButtonHeld(const JoyStickState& state, int button) 525 { 526 // find the appropriate key binding 527 executeSimpleBinding(bindingsJoyStickButtonHold_[button]); 528 529 return true; 530 } 531 532 bool KeyBinder::joyStickAxisMoved(const JoyStickState& state, int axis) 533 { 534 return true; 535 } 536 537 bool KeyBinder::joyStickSliderMoved(const JoyStickState& state, int index) 538 { 539 return true; 540 } 541 542 bool KeyBinder::joyStickPovMoved(const JoyStickState& state, int index) 543 { 544 return true; 545 } 546 547 bool KeyBinder::joyStickVector3Moved(const JoyStickState& state, int index) 548 { 549 return true; 550 } 551 709 void KeyBinder::mouseScrolled(int abs, int rel) 710 { 711 //COUT(3) << mouseButtons_[8].name_ << " " << abs << " | " << rel << std::endl; 712 713 if (rel > 0) 714 for (int i = 0; i < rel/120; i++) 715 mouseButtons_[8].execute(KeybindMode::OnPress, ((float)abs)/120.0f); 716 else 717 for (int i = 0; i < -rel/120; i++) 718 mouseButtons_[9].execute(KeybindMode::OnPress, ((float)abs)/120.0f); 719 } 720 721 void KeyBinder::joyStickAxisMoved(int joyStickID, int axis, int value) 722 { 723 // TODO: check whether 16 bit integer as general axis value is a good idea (works under windows) 724 CCOUT(3) << halfAxes_[8 + axis].name_ << std::endl; 725 if (value >= 0) 726 { 727 halfAxes_[8 + axis].absVal_ = ((float)value)/0x8000; 728 halfAxes_[8 + axis].relVal_ = ((float)value)/0x8000; 729 halfAxes_[8 + axis].hasChanged_ = true; 730 } 731 else 732 { 733 halfAxes_[8 + axis + 1].absVal_ = -((float)value)/0x8000; 734 halfAxes_[8 + axis + 1].relVal_ = -((float)value)/0x8000; 735 halfAxes_[8 + axis + 1].hasChanged_ = true; 736 } 737 } 552 738 553 739 -
code/trunk/src/core/InputHandler.h
r1293 r1349 38 38 39 39 #include <string> 40 #include <vector> 40 41 41 42 #include "ois/OIS.h" 43 #include "util/Math.h" 42 44 #include "OrxonoxClass.h" 43 45 #include "CommandExecutor.h" … … 46 48 namespace orxonox 47 49 { 48 namespace KeybindSetting 49 { 50 enum KeybindSetting 51 { 52 None, 53 OnPress, 54 OnRelease, 55 Continuous, 56 }; 57 } 58 59 struct _CoreExport KeyBinding 60 { 61 std::string commandStr; 62 CommandEvaluation evaluation; 63 }; 64 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 63 float value_; 64 unsigned int nValuesAdded_; 65 int paramIndex_; 66 CommandEvaluation evaluation_; 67 }; 68 69 class _CoreExport SimpleCommand : public BaseCommand 70 { 71 public: 72 bool execute(float abs = 1.0f, float rel = 1.0f); 73 74 CommandEvaluation evaluation_; 75 }; 76 77 class _CoreExport ParamCommand : public BaseCommand 78 { 79 public: 80 ParamCommand() : bRelative_(false), paramModifier_(1.0f), paramCommand_(0) { } 81 bool execute(float abs = 1.0f, float rel = 1.0f); 82 83 bool bRelative_; 84 float paramModifier_; 85 BufferedParamCommand* paramCommand_; 86 }; 87 88 class _CoreExport Button 89 { 90 public: 91 Button() { nCommands_[0]=0; nCommands_[1]=0; nCommands_[2]=0; clear(); } 92 virtual ~Button() { clear(); } 93 virtual void clear(); 94 virtual bool addParamCommand(ParamCommand* command) { return false; } 95 void parse(std::vector<BufferedParamCommand*>& paramCommandBuffer); 96 bool execute(KeybindMode::Enum mode, float abs = 1.0f, float rel = 1.0f); 97 98 //! The configured string value 99 std::string bindingString_; 100 //! Name of the trigger as strings 101 std::string name_; 102 //! Basic commands for OnPress, OnHold and OnRelease 103 BaseCommand** commands_[3]; 104 //! Number of basic commands 105 unsigned int nCommands_[3]; 106 //! Says how much it takes for an analog axis to trigger a button 107 //! Note: This variable is here to have only one parse() function. 108 float buttonThreshold_; 109 }; 110 111 112 class _CoreExport HalfAxis : public Button 113 { 114 public: 115 HalfAxis() : relVal_(0.0f), absVal_(0.0f), paramCommands_(0), nParamCommands_(0), 116 wasDown_(false), hasChanged_(false) { } 117 using Button::execute; 118 bool execute(); 119 //bool execute(KeybindMode::Enum mode) { return Button::execute(mode); } 120 bool addParamCommand(ParamCommand* command); 121 void clear(); 122 123 // axis related 124 float relVal_; 125 float absVal_; 126 ParamCommand** paramCommands_; 127 unsigned int nParamCommands_; 128 129 // button related 130 bool wasDown_; 131 bool hasChanged_; 132 }; 133 65 134 66 135 /** 67 @brief Captures mouse, keyboard and joy stick input while in the actual game mode.136 @brief Handles mouse, keyboard and joy stick input while in the actual game mode. 68 137 Manages the key bindings. 69 138 */ … … 74 143 ~KeyBinder(); 75 144 76 boolloadBindings();77 void clearBindings( );145 void loadBindings(); 146 void clearBindings(bool bInit = false); 78 147 79 148 void setConfigValues(); 80 149 81 150 private: // functions 82 83 bool executeSimpleBinding(KeyBinding &binding); 84 85 bool keyPressed (const KeyEvent& evt); 86 bool keyReleased(const KeyEvent& evt); 87 bool keyHeld (const KeyEvent& evt); 88 89 bool mouseButtonPressed (const MouseState& state, MouseButton::Enum id); 90 bool mouseButtonReleased(const MouseState& state, MouseButton::Enum id); 91 bool mouseButtonHeld (const MouseState& state, MouseButton::Enum id); 92 bool mouseMoved (const MouseState& state); 93 bool mouseScrolled (const MouseState& state); 94 95 bool joyStickButtonPressed (const JoyStickState& state, int button); 96 bool joyStickButtonReleased(const JoyStickState& state, int button); 97 bool joyStickButtonHeld (const JoyStickState& state, int button); 98 bool joyStickAxisMoved (const JoyStickState& state, int axis) ; 99 bool joyStickSliderMoved (const JoyStickState& state, int index) ; 100 bool joyStickPovMoved (const JoyStickState& state, int index) ; 101 bool joyStickVector3Moved (const JoyStickState& state, int index) ; 151 void readTrigger(Button& button); 152 153 //static void clearBundle(KeyBindingBundle& bundle, bool bInit); 154 //static void redimensionBinding(KeyBinding& binding); 155 156 void tick(float dt); 157 158 void keyPressed (const KeyEvent& evt); 159 void keyReleased(const KeyEvent& evt); 160 void keyHeld (const KeyEvent& evt); 161 162 void mouseButtonPressed (MouseButton::Enum id); 163 void mouseButtonReleased(MouseButton::Enum id); 164 void mouseButtonHeld (MouseButton::Enum id); 165 void mouseMoved (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize); 166 void mouseScrolled (int abs, int rel); 167 168 void joyStickButtonPressed (int joyStickID, int button); 169 void joyStickButtonReleased(int joyStickID, int button); 170 void joyStickButtonHeld (int joyStickID, int button); 171 void joyStickAxisMoved (int joyStickID, int axis, int value); 102 172 103 173 private: // variables 104 105 174 //! denotes the number of different keys there are in OIS. 106 static const int numberOfKeys_s = 0xEE; 107 //! Array of input events for every pressed key 108 KeyBinding bindingsKeyPress_ [numberOfKeys_s]; 109 //! Array of input events for every released key 110 KeyBinding bindingsKeyRelease_[numberOfKeys_s]; 111 //! Array of input events for every held key 112 KeyBinding bindingsKeyHold_ [numberOfKeys_s]; 113 //! Names of the keys as strings 114 std::string keyNames_[numberOfKeys_s]; 175 static const unsigned int nKeys_s = 0xEE; 176 //! Actual key bindings as bundle for Press, Hold and Release 177 Button keys_ [nKeys_s]; 115 178 116 179 //! denotes the number of different mouse buttons there are in OIS. 117 static const int numberOfMouseButtons_s = 8; 118 //! Array of input events for every pressed mouse button 119 KeyBinding bindingsMouseButtonPress_ [numberOfMouseButtons_s]; 120 //! Array of input events for every released mouse button 121 KeyBinding bindingsMouseButtonRelease_[numberOfMouseButtons_s]; 122 //! Array of input events for every held mouse button 123 KeyBinding bindingsMouseButtonHold_ [numberOfMouseButtons_s]; 124 //! Key binding for mouse moved event 125 KeyBinding bindingMouseMoved_; 126 //! Key binding for mouse scrolled event 127 KeyBinding bindingMouseScrolled_; 128 //! Names of the mouse buttons as strings 129 std::string mouseButtonNames_[numberOfMouseButtons_s]; 180 static const unsigned int nMouseButtons_s = 8 + 2*2; // 8 buttons and 2 scroll wheels 181 //! Actual key bindings as bundle for Press, Hold and Release 182 Button mouseButtons_ [nMouseButtons_s]; 130 183 131 184 //! denotes the number of different joy stick buttons there are in OIS. 132 static const int numberOfJoyStickButtons_s = 32; 133 //! Array of input events for every pressed joy stick button 134 KeyBinding bindingsJoyStickButtonPress_ [numberOfJoyStickButtons_s]; 135 //! Array of input events for every released joy stick button 136 KeyBinding bindingsJoyStickButtonRelease_[numberOfJoyStickButtons_s]; 137 //! Array of input events for every held joy stick button 138 KeyBinding bindingsJoyStickButtonHold_ [numberOfJoyStickButtons_s]; 139 //! Names of the joy stick buttons as strings 140 std::string joyStickButtonNames_[numberOfJoyStickButtons_s]; 141 185 static const unsigned int nJoyStickButtons_s = 32 + 4 * 4; // 32 buttons and 4 POVs with 4 buttons 186 //! Actual key bindings as bundle for Press, Hold and Release 187 Button joyStickButtons_ [nJoyStickButtons_s]; 188 189 //! denotes the number of half axes (every axis twice) there can be. 190 static const unsigned int nHalfAxes_s = 56; 191 /** 192 * Array with all the half axes for mouse and joy sticks. 193 * Keep in mind that the positions are fixed and that the first entry is the 194 * positive one and the second is negative. 195 * Sequence is as follows: 196 * 0 - 3: Mouse x and y 197 * 4 - 7: empty 198 * 8 - 23: joy stick (slider) axes 1 to 8 199 * 24 - 55: joy stick axes 1 - 16 200 */ 201 HalfAxis halfAxes_[nHalfAxes_s]; 202 203 /** 204 * Commands that have additional parameters (axes) are executed at the end of 205 * the tick() so that all values can be buffered for single execution. 206 */ 207 std::vector<BufferedParamCommand*> paramCommandBuffer_; 208 209 //! Keeps track of the absolute mouse value (incl. scroll wheel) 210 int mousePosition_[3]; 211 //! Used to derive mouse input if requested 212 int mouseRelative_[2]; 213 float deriveTime_; 214 215 //##### ConfigValues ##### 216 //! Threshold for analog triggers until which the state is 0. 217 float analogThreshold_; 218 //! Threshold for analog triggers until which the button is not pressed. 219 float buttonThreshold_; 220 //! Derive mouse input for absolute values? 221 bool bDeriveMouseInput_; 222 //! Accuracy of the mouse input deriver. The higher the more precise, but laggier. 223 float derivePeriod_; 224 //! mouse sensitivity 225 float mouseSensitivity_; 142 226 }; 143 227 -
code/trunk/src/core/InputInterfaces.h
r1293 r1349 38 38 39 39 #include "ois/OIS.h" 40 #include "util/Math.h" 40 41 41 42 namespace orxonox … … 239 240 }; 240 241 241 typedef OIS::MouseState MouseState;242 243 class _CoreExport JoyStickState : OIS::JoyStickState242 //typedef OIS::MouseState MouseState; 243 244 /*class _CoreExport JoyStickState 244 245 { 245 246 public: … … 247 248 JoyStickState() { clear(); } 248 249 int mJoyStickID; 250 JoyStickState() { clear(); } 251 252 std::vector<bool> mButtons; 253 int axes[16]; 254 std::vector<Vector3> mVectors; 255 };*/ 256 257 class _CoreExport InputTickable 258 { 259 public: 260 virtual ~InputTickable() { } 261 virtual void tick(float dt) = 0; 249 262 }; 250 263 … … 252 265 @brief Interface class used for key input listeners. 253 266 */ 254 class _CoreExport KeyHandler 267 class _CoreExport KeyHandler : virtual public InputTickable 255 268 { 256 269 public: 257 270 virtual ~KeyHandler() { } 258 virtual boolkeyPressed (const KeyEvent& evt) = 0;259 virtual boolkeyReleased(const KeyEvent& evt) = 0;260 virtual boolkeyHeld (const KeyEvent& evt) = 0;271 virtual void keyPressed (const KeyEvent& evt) = 0; 272 virtual void keyReleased(const KeyEvent& evt) = 0; 273 virtual void keyHeld (const KeyEvent& evt) = 0; 261 274 }; 262 275 … … 264 277 @brief Interface class used for mouse input listeners. 265 278 */ 266 class _CoreExport MouseHandler 279 class _CoreExport MouseHandler : virtual public InputTickable 267 280 { 268 281 public: 269 282 virtual ~MouseHandler() { } 270 virtual bool mouseButtonPressed (const MouseState& state,MouseButton::Enum id) = 0;271 virtual bool mouseButtonReleased(const MouseState& state,MouseButton::Enum id) = 0;272 virtual bool mouseButtonHeld (const MouseState& state,MouseButton::Enum id) = 0;273 virtual bool mouseMoved (const MouseState& state) = 0;274 virtual bool mouseScrolled (const MouseState& state)= 0;283 virtual void mouseButtonPressed (MouseButton::Enum id) = 0; 284 virtual void mouseButtonReleased(MouseButton::Enum id) = 0; 285 virtual void mouseButtonHeld (MouseButton::Enum id) = 0; 286 virtual void mouseMoved (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) = 0; 287 virtual void mouseScrolled (int abs, int rel) = 0; 275 288 }; 276 289 … … 279 292 @brief Interface class used for joy stick input listeners. 280 293 */ 281 class _CoreExport JoyStickHandler 294 class _CoreExport JoyStickHandler : virtual public InputTickable 282 295 { 283 296 public: 284 297 virtual ~JoyStickHandler() { } 285 virtual bool joyStickButtonPressed (const JoyStickState& state, int button) = 0; 286 virtual bool joyStickButtonReleased(const JoyStickState& state, int button) = 0; 287 virtual bool joyStickButtonHeld (const JoyStickState& state, int button) = 0; 288 virtual bool joyStickAxisMoved (const JoyStickState& state, int axis) = 0; 289 virtual bool joyStickSliderMoved (const JoyStickState& state, int index) {return true;} 290 virtual bool joyStickPovMoved (const JoyStickState& state, int index) {return true;} 291 virtual bool joyStickVector3Moved (const JoyStickState& state, int index) {return true;} 298 virtual void joyStickButtonPressed (int joyStickID, int button) = 0; 299 virtual void joyStickButtonReleased(int joyStickID, int button) = 0; 300 virtual void joyStickButtonHeld (int joyStickID, int button) = 0; 301 virtual void joyStickAxisMoved (int joyStickID, int axis, int value) = 0; 302 //virtual bool joyStickVector3Moved (int joyStickID, int index /*, fill list*/) {return true;} 292 303 }; 293 304 -
code/trunk/src/core/InputManager.cc
r1293 r1349 98 98 windowHndStr << (unsigned int)windowHnd; 99 99 paramList.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); 100 100 //paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_NONEXCLUSIVE"))); 101 //paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_FOREGROUND"))); 101 102 //#if defined OIS_LINUX_PLATFORM 102 103 // paramList.insert(std::make_pair(std::string("XAutoRepeatOn"), std::string("true"))); … … 126 127 127 128 // Set mouse/joystick region 128 setWindowExtents(windowWidth, windowHeight); 129 if (mouse_) 130 { 131 //// hack the mouse position 132 //((OIS::MouseState&)mouse_->getMouseState()).X.abs = windowWidth/2; 133 //((OIS::MouseState&)mouse_->getMouseState()).Y.abs = windowHeight/2; 134 setWindowExtents(windowWidth, windowHeight); 135 } 129 136 130 137 state_ = IS_NONE; … … 267 274 activeJoyStickHandlers_.resize(joySticksSize_); 268 275 joyStickButtonsDown_.resize(joySticksSize_); 276 povStates_.resize(joySticksSize_); 277 sliderStates_.resize(joySticksSize_); 269 278 return success; 270 279 } … … 350 359 } 351 360 361 void InputManager::_updateTickables() 362 { 363 // we can use a set to have a list of unique pointers (an object can implement all 3 handlers) 364 std::set<InputTickable*> tempSet; 365 for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++) 366 tempSet.insert(activeKeyHandlers_[iHandler]); 367 for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++) 368 tempSet.insert(activeMouseHandlers_[iHandler]); 369 for (unsigned int iJoyStick = 0; iJoyStick < joySticksSize_; iJoyStick++) 370 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 371 tempSet.insert(activeJoyStickHandlers_[iJoyStick][iHandler]); 372 373 // copy the content of the set back to the actual vector 374 activeHandlers_.clear(); 375 for (std::set<InputTickable*>::const_iterator itHandler = tempSet.begin(); itHandler != tempSet.end(); itHandler++) 376 activeHandlers_.push_back(*itHandler); 377 } 378 352 379 353 380 // ################################# … … 380 407 // normal play mode 381 408 // note: we assume that the handlers exist since otherwise, something's wrong anyway. 382 activeKeyHandlers_.push_back(keyHandlers_["keybinder"]); 383 activeMouseHandlers_.push_back(mouseHandlers_["keybinder"]); 384 if (getMouseHandler("SpaceShip")) 385 activeMouseHandlers_.push_back(mouseHandlers_["SpaceShip"]); 386 for (unsigned int i = 0; i < joySticksSize_; i++) 387 activeJoyStickHandlers_[i].push_back(joyStickHandlers_["keybinder"]); 409 enableKeyHandler("keybinder"); 410 enableMouseHandler("keybinder"); 411 enableMouseHandler("SpaceShip"); 412 enableJoyStickHandler("keybinder", 0); 388 413 break; 389 414 390 415 case IS_GUI: 391 // FIXME: do stuff416 // TODO: do stuff 392 417 break; 393 418 394 419 case IS_CONSOLE: 395 activeMouseHandlers_.push_back(mouseHandlers_["keybinder"]); 396 if (getMouseHandler("SpaceShip")) 397 activeMouseHandlers_.push_back(mouseHandlers_["SpaceShip"]); 398 for (unsigned int i = 0; i < joySticksSize_; i++) 399 activeJoyStickHandlers_[i].push_back(joyStickHandlers_["keybinder"]); 400 401 activeKeyHandlers_.push_back(keyHandlers_["buffer"]); 420 enableMouseHandler("keybinder"); 421 enableMouseHandler("SpaceShip"); 422 enableJoyStickHandler("keybinder", 0); 423 enableKeyHandler("buffer"); 402 424 break; 403 425 … … 426 448 for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++) 427 449 for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++) 428 activeMouseHandlers_[iHandler]->mouseButtonHeld(mouse _->getMouseState(), mouseButtonsDown_[iButton]);450 activeMouseHandlers_[iHandler]->mouseButtonHeld(mouseButtonsDown_[iButton]); 429 451 430 452 // call all the handlers for the held joy stick button events … … 432 454 for (unsigned int iButton = 0; iButton < joyStickButtonsDown_[iJoyStick].size(); iButton++) 433 455 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 434 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonHeld( 435 JoyStickState(joySticks_[iJoyStick]->getJoyStickState(), iJoyStick), joyStickButtonsDown_[iJoyStick][iButton]); 456 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonHeld(iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]); 457 458 459 // call the ticks 460 for (unsigned int iHandler = 0; iHandler < activeHandlers_.size(); iHandler++) 461 activeHandlers_[iHandler]->tick(dt); 436 462 } 437 463 … … 508 534 { 509 535 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 510 activeMouseHandlers_[i]->mouseMoved(e.state); 536 activeMouseHandlers_[i]->mouseMoved(IntVector2(e.state.X.abs, e.state.Y.abs), 537 IntVector2(e.state.X.rel, e.state.Y.rel), IntVector2(e.state.width, e.state.height)); 511 538 } 512 539 … … 515 542 { 516 543 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 517 activeMouseHandlers_[i]->mouseScrolled(e.state );544 activeMouseHandlers_[i]->mouseScrolled(e.state.Z.abs, e.state.Z.rel); 518 545 } 519 546 … … 536 563 537 564 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 538 activeMouseHandlers_[i]->mouseButtonPressed( e.state,(MouseButton::Enum)id);565 activeMouseHandlers_[i]->mouseButtonPressed((MouseButton::Enum)id); 539 566 540 567 return true; … … 559 586 560 587 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 561 activeMouseHandlers_[i]->mouseButtonReleased( e.state,(MouseButton::Enum)id);588 activeMouseHandlers_[i]->mouseButtonReleased((MouseButton::Enum)id); 562 589 563 590 return true; … … 584 611 585 612 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 586 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonPressed( JoyStickState(arg.state, iJoyStick), button);613 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonPressed(iJoyStick, button); 587 614 588 615 return true; … … 609 636 610 637 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 611 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonReleased( JoyStickState(arg.state, iJoyStick), button);638 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonReleased(iJoyStick, button); 612 639 613 640 return true; … … 616 643 bool InputManager::axisMoved(const OIS::JoyStickEvent &arg, int axis) 617 644 { 645 //CCOUT(3) << arg.state.mAxes[axis].abs << std::endl; 618 646 // use the device to identify which one called the method 619 647 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; … … 622 650 iJoyStick++; 623 651 652 // keep in mind that the first 8 axes are reserved for the sliders 624 653 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 625 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved( JoyStickState(arg.state, iJoyStick), axis);654 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, axis + 8, arg.state.mAxes[axis].abs); 626 655 627 656 return true; … … 630 659 bool InputManager::sliderMoved(const OIS::JoyStickEvent &arg, int id) 631 660 { 661 //CCOUT(3) << arg.state.mSliders[id].abX << "\t |" << arg.state.mSliders[id].abY << std::endl; 632 662 // use the device to identify which one called the method 633 663 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; … … 636 666 iJoyStick++; 637 667 638 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 639 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickSliderMoved(JoyStickState(arg.state, iJoyStick), id); 668 if (sliderStates_[iJoyStick].sliderStates[id].x != arg.state.mSliders[id].abX) 669 { 670 // slider X axis changed 671 sliderStates_[iJoyStick].sliderStates[id].x = arg.state.mSliders[id].abX; 672 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 673 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, id * 2, arg.state.mSliders[id].abX); 674 } 675 else if (sliderStates_[iJoyStick].sliderStates[id].y != arg.state.mSliders[id].abY) 676 { 677 // slider Y axis changed 678 sliderStates_[iJoyStick].sliderStates[id].y = arg.state.mSliders[id].abY; 679 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 680 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, id * 2 + 1, arg.state.mSliders[id].abY); 681 } 640 682 641 683 return true; … … 650 692 iJoyStick++; 651 693 652 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 653 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickPovMoved(JoyStickState(arg.state, iJoyStick), id); 654 655 return true; 656 } 657 658 bool InputManager::vector3Moved(const OIS::JoyStickEvent &arg, int id) 694 // translate the POV into 8 simple buttons 695 int lastState = povStates_[iJoyStick][id]; 696 if (lastState & OIS::Pov::North) 697 buttonReleased(arg, 32 + id * 4 + 0); 698 if (lastState & OIS::Pov::South) 699 buttonReleased(arg, 32 + id * 4 + 1); 700 if (lastState & OIS::Pov::East) 701 buttonReleased(arg, 32 + id * 4 + 2); 702 if (lastState & OIS::Pov::West) 703 buttonReleased(arg, 32 + id * 4 + 3); 704 705 povStates_[iJoyStick].povStates[id] = arg.state.mPOV[id].direction; 706 int currentState = povStates_[iJoyStick][id]; 707 if (currentState & OIS::Pov::North) 708 buttonPressed(arg, 32 + id * 4 + 0); 709 if (currentState & OIS::Pov::South) 710 buttonPressed(arg, 32 + id * 4 + 1); 711 if (currentState & OIS::Pov::East) 712 buttonPressed(arg, 32 + id * 4 + 2); 713 if (currentState & OIS::Pov::West) 714 buttonPressed(arg, 32 + id * 4 + 3); 715 716 return true; 717 } 718 719 /*bool InputManager::vector3Moved(const OIS::JoyStickEvent &arg, int id) 659 720 { 660 721 // use the device to identify which one called the method … … 668 729 669 730 return true; 670 } 731 }*/ 671 732 672 733 … … 735 796 } 736 797 737 const MouseState InputManager::getMouseState()798 /*const MouseState InputManager::getMouseState() 738 799 { 739 800 if (_getSingleton().mouse_) … … 741 802 else 742 803 return MouseState(); 743 } 744 745 const JoyStickState InputManager::getJoyStickState(unsigned int ID)804 }*/ 805 806 /*const JoyStickState InputManager::getJoyStickState(unsigned int ID) 746 807 { 747 808 if (ID < _getSingleton().joySticksSize_) … … 749 810 else 750 811 return JoyStickState(); 751 } 812 }*/ 752 813 753 814 … … 882 943 if ((*it) == (*mapIt).second) 883 944 { 884 _getSingleton().stateRequest_ = IS_CUSTOM;885 945 return true; 886 946 } … … 888 948 _getSingleton().activeKeyHandlers_.push_back((*mapIt).second); 889 949 _getSingleton().stateRequest_ = IS_CUSTOM; 950 _getSingleton()._updateTickables(); 890 951 return true; 891 952 } … … 910 971 _getSingleton().activeKeyHandlers_.erase(it); 911 972 _getSingleton().stateRequest_ = IS_CUSTOM; 973 _getSingleton()._updateTickables(); 912 974 return true; 913 975 } 914 976 } 915 _getSingleton().stateRequest_ = IS_CUSTOM;916 977 return true; 917 978 } … … 1010 1071 if ((*it) == (*mapIt).second) 1011 1072 { 1012 _getSingleton().stateRequest_ = IS_CUSTOM;1013 1073 return true; 1014 1074 } … … 1016 1076 _getSingleton().activeMouseHandlers_.push_back((*mapIt).second); 1017 1077 _getSingleton().stateRequest_ = IS_CUSTOM; 1078 _getSingleton()._updateTickables(); 1018 1079 return true; 1019 1080 } … … 1038 1099 _getSingleton().activeMouseHandlers_.erase(it); 1039 1100 _getSingleton().stateRequest_ = IS_CUSTOM; 1101 _getSingleton()._updateTickables(); 1040 1102 return true; 1041 1103 } 1042 1104 } 1043 _getSingleton().stateRequest_ = IS_CUSTOM;1044 1105 return true; 1045 1106 } … … 1147 1208 if ((*it) == (*handlerIt).second) 1148 1209 { 1149 _getSingleton().stateRequest_ = IS_CUSTOM;1150 1210 return true; 1151 1211 } … … 1153 1213 _getSingleton().activeJoyStickHandlers_[ID].push_back((*handlerIt).second); 1154 1214 _getSingleton().stateRequest_ = IS_CUSTOM; 1215 _getSingleton()._updateTickables(); 1155 1216 return true; 1156 1217 } … … 1180 1241 _getSingleton().activeJoyStickHandlers_[ID].erase(it); 1181 1242 _getSingleton().stateRequest_ = IS_CUSTOM; 1243 _getSingleton()._updateTickables(); 1182 1244 return true; 1183 1245 } -
code/trunk/src/core/InputManager.h
r1293 r1349 42 42 43 43 #include "ois/OIS.h" 44 #include "util/Math.h" 44 45 #include "Tickable.h" 45 46 #include "InputInterfaces.h" … … 47 48 namespace orxonox 48 49 { 50 /** 51 * Helper class to realise a vector<int[4]> 52 */ 53 class POVStates 54 { 55 public: 56 int operator[](unsigned int index) { return povStates[index]; } 57 int povStates[4]; 58 }; 59 60 /** 61 * Helper class to realise a vector< {int[4], int[4]} > 62 */ 63 class SliderStates 64 { 65 public: 66 IntVector2 sliderStates[4]; 67 }; 68 49 69 /** 50 70 @brief Captures and distributes mouse and keyboard input. … … 85 105 static bool isModifierDown(KeyboardModifier::Enum modifier); 86 106 static bool isKeyDown(KeyCode::Enum key); 87 static const MouseState getMouseState();88 static const JoyStickState getJoyStickState(unsigned int ID);107 //static const MouseState getMouseState(); 108 //static const JoyStickState getJoyStickState(unsigned int ID); 89 109 90 110 static void setWindowExtents(const int width, const int height); … … 130 150 void _destroyMouse(); 131 151 void _destroyJoySticks(); 152 153 void _updateTickables(); 132 154 133 155 void tick(float dt); … … 144 166 bool sliderMoved (const OIS::JoyStickEvent &arg, int id); 145 167 bool povMoved (const OIS::JoyStickEvent &arg, int id); 146 bool vector3Moved (const OIS::JoyStickEvent &arg, int id);168 //bool vector3Moved (const OIS::JoyStickEvent &arg, int id); 147 169 148 170 static InputManager& _getSingleton(); … … 160 182 unsigned int keyboardModifiers_; 161 183 184 //! Keeps track of the joy stick POV states 185 std::vector<POVStates> povStates_; 186 //! Keeps track of the possibly two slider axes 187 std::vector<SliderStates> sliderStates_; 188 162 189 std::map<std::string, KeyHandler*> keyHandlers_; 163 190 std::map<std::string, MouseHandler*> mouseHandlers_; … … 167 194 std::vector<MouseHandler*> activeMouseHandlers_; 168 195 std::vector<std::vector<JoyStickHandler*> > activeJoyStickHandlers_; 196 std::vector<InputTickable*> activeHandlers_; 169 197 170 198 std::vector<Key> keysDown_; -
code/trunk/src/core/SignalHandler.cc
r1293 r1349 150 150 { 151 151 std::cout << "Trying to restore XAutoKeyRepeat" << std::endl; 152 153 154 { 155 156 152 Display* display; 153 if ((display = XOpenDisplay(0))) 154 { 155 XAutoRepeatOn(display); 156 XCloseDisplay(display); 157 157 } 158 158 } … … 320 320 321 321 std::string timeString = "\n\n\n\n" 322 323 324 322 "=======================================================\n" 323 "= time: " + std::string(ctime(&now)) + 324 "=======================================================\n"; 325 325 bt.insert(0, timeString); 326 326
Note: See TracChangeset
for help on using the changeset viewer.