Changeset 3274 for code/branches/core4/src/core/input
- Timestamp:
- Jul 12, 2009, 4:12:04 PM (15 years ago)
- Location:
- code/branches/core4/src/core/input
- Files:
-
- 5 added
- 1 deleted
- 15 edited
- 1 copied
- 4 moved
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core4/src/core/input/Button.h
r3257 r3274 36 36 #define _Button_H__ 37 37 38 #include " core/CorePrereqs.h"38 #include "InputPrereqs.h" 39 39 40 40 #include <string> -
code/branches/core4/src/core/input/CMakeLists.txt
r3273 r3274 5 5 InputCommands.cc 6 6 InputManager.cc 7 InputState.cc 7 8 JoyStick.cc 8 JoyStick DeviceNumberListener.cc9 JoyStickQuantityListener.cc 9 10 KeyBinder.cc 11 Keyboard.cc 10 12 KeyDetector.cc 11 SimpleInputState.cc13 Mouse.cc 12 14 ) -
code/branches/core4/src/core/input/HalfAxis.h
r3196 r3274 36 36 #define _HalfAxis_H__ 37 37 38 #include " core/CorePrereqs.h"38 #include "InputPrereqs.h" 39 39 40 40 #include "Button.h" -
code/branches/core4/src/core/input/InputBuffer.cc
r3196 r3274 184 184 185 185 186 void InputBuffer::processKey(const KeyEvent &evt)187 { 188 if (evt.isModifierDown(KeyboardModifier::Alt) && evt. key== KeyCode::Tab)186 void InputBuffer::processKey(const KeyEvent& evt) 187 { 188 if (evt.isModifierDown(KeyboardModifier::Alt) && evt.getKeyCode() == KeyCode::Tab) 189 189 return; 190 190 191 191 for (std::list<BaseInputBufferListenerTuple*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it) 192 192 { 193 if ((*it)->trueKeyFalseChar_ && ((*it)->key_ == evt. key))193 if ((*it)->trueKeyFalseChar_ && ((*it)->key_ == evt.getKeyCode())) 194 194 (*it)->callFunction(); 195 195 } … … 197 197 if (evt.isModifierDown(KeyboardModifier::Ctrl)) 198 198 { 199 if (evt. key== KeyCode::V)199 if (evt.getKeyCode() == KeyCode::V) 200 200 this->insert(fromClipboard()); 201 else if (evt. key== KeyCode::C)201 else if (evt.getKeyCode() == KeyCode::C) 202 202 toClipboard(this->buffer_); 203 else if (evt. key== KeyCode::X)203 else if (evt.getKeyCode() == KeyCode::X) 204 204 { 205 205 toClipboard(this->buffer_); … … 209 209 else if (evt.isModifierDown(KeyboardModifier::Shift)) 210 210 { 211 if (evt. key== KeyCode::Insert)211 if (evt.getKeyCode() == KeyCode::Insert) 212 212 this->insert(fromClipboard()); 213 else if (evt. key== KeyCode::Delete)213 else if (evt.getKeyCode() == KeyCode::Delete) 214 214 { 215 215 toClipboard(this->buffer_); … … 218 218 } 219 219 220 this->insert((char)evt. text);220 this->insert((char)evt.getText()); 221 221 } 222 222 … … 225 225 @param dt Delta time 226 226 */ 227 void InputBuffer:: updateInput(float dt)227 void InputBuffer::keyboardUpdated(float dt) 228 228 { 229 229 timeSinceKeyPressed_ += dt; … … 239 239 } 240 240 241 void InputBuffer:: keyPressed(const KeyEvent &evt)242 { 243 lastKey_ = evt. key;241 void InputBuffer::buttonPressed(const KeyEvent& evt) 242 { 243 lastKey_ = evt.getKeyCode(); 244 244 timeSinceKeyPressed_ = 0.0; 245 245 timeSinceKeyRepeated_ = keyRepeatDeleay_; … … 249 249 } 250 250 251 void InputBuffer:: keyHeld(const KeyEvent& evt)252 { 253 if (evt. key== lastKey_)251 void InputBuffer::buttonHeld(const KeyEvent& evt) 252 { 253 if (evt.getKeyCode() == lastKey_) 254 254 { 255 255 while (keysToRepeat_) -
code/branches/core4/src/core/input/InputBuffer.h
r3196 r3274 30 30 #define _InputBuffer_H__ 31 31 32 #include " core/CorePrereqs.h"32 #include "InputPrereqs.h" 33 33 34 34 #include <list> 35 35 #include <string> 36 36 #include "core/OrxonoxClass.h" 37 #include "Input Interfaces.h"37 #include "InputHandler.h" 38 38 39 39 namespace orxonox … … 74 74 }; 75 75 76 class _CoreExport InputBuffer : public KeyHandler, public OrxonoxClass76 class _CoreExport InputBuffer : public InputHandler, public OrxonoxClass 77 77 { 78 78 public: … … 165 165 bool charIsAllowed(const char& input); 166 166 167 void keyPressed (const KeyEvent& evt); 168 void keyReleased(const KeyEvent& evt) { } 169 void keyHeld (const KeyEvent& evt); 170 void processKey (const KeyEvent &e); 167 void buttonPressed(const KeyEvent& evt); 168 void buttonHeld (const KeyEvent& evt); 169 void processKey (const KeyEvent& evt); 171 170 172 void updateInput(float dt); 173 void updateKey(float dt) { } 171 void keyboardUpdated(float dt); 174 172 175 173 std::string buffer_; -
code/branches/core4/src/core/input/InputCommands.h
r2087 r3274 36 36 #define _InputCommands_H__ 37 37 38 #include " core/CorePrereqs.h"38 #include "InputPrereqs.h" 39 39 #include "core/CommandEvaluation.h" 40 40 -
code/branches/core4/src/core/input/InputHandler.h
r3273 r3274 33 33 */ 34 34 35 #ifndef _Input Interfaces_H__36 #define _Input Interfaces_H__35 #ifndef _InputHandler_H__ 36 #define _InputHandler_H__ 37 37 38 #include "core/CorePrereqs.h" 39 40 #include <ois/OISKeyboard.h> 41 #include <ois/OISMouse.h> 42 #include <ois/OISJoyStick.h> 38 #include "InputPrereqs.h" 43 39 #include "util/Math.h" 44 40 45 41 namespace orxonox 46 42 { 47 namespace KeyCode 48 { 49 const unsigned int numberOfKeys = 0xEE; // 238 50 51 // note: KeyCode comments were directly copied from OISKeyboard.h 52 enum ByEnum 53 { 54 Unassigned = OIS::KC_UNASSIGNED, 55 Escape = OIS::KC_ESCAPE, 56 NumRow1 = OIS::KC_1, 57 NumRow2 = OIS::KC_2, 58 NumRow3 = OIS::KC_3, 59 NumRow4 = OIS::KC_4, 60 NumRow5 = OIS::KC_5, 61 NumRow6 = OIS::KC_6, 62 NumRow7 = OIS::KC_7, 63 NumRow8 = OIS::KC_8, 64 NumRow9 = OIS::KC_9, 65 NumRow0 = OIS::KC_0, 66 Minus = OIS::KC_MINUS, // - on main keyboard 67 Equals = OIS::KC_EQUALS, 68 Back = OIS::KC_BACK, // backspace 69 Tab = OIS::KC_TAB, 70 Q = OIS::KC_Q, 71 W = OIS::KC_W, 72 E = OIS::KC_E, 73 R = OIS::KC_R, 74 T = OIS::KC_T, 75 Y = OIS::KC_Y, 76 U = OIS::KC_U, 77 I = OIS::KC_I, 78 O = OIS::KC_O, 79 P = OIS::KC_P, 80 LeftBracket = OIS::KC_LBRACKET, 81 RightBracket = OIS::KC_RBRACKET, 82 Return = OIS::KC_RETURN, // Enter on main keyboard 83 LeftControl = OIS::KC_LCONTROL, 84 A = OIS::KC_A, 85 S = OIS::KC_S, 86 D = OIS::KC_D, 87 F = OIS::KC_F, 88 G = OIS::KC_G, 89 H = OIS::KC_H, 90 J = OIS::KC_J, 91 K = OIS::KC_K, 92 L = OIS::KC_L, 93 Semicolon = OIS::KC_SEMICOLON, 94 Apostrophe = OIS::KC_APOSTROPHE, 95 Grave = OIS::KC_GRAVE, // accent 96 LeftShift = OIS::KC_LSHIFT, 97 Backslash = OIS::KC_BACKSLASH, 98 Z = OIS::KC_Z, 99 X = OIS::KC_X, 100 C = OIS::KC_C, 101 V = OIS::KC_V, 102 B = OIS::KC_B, 103 N = OIS::KC_N, 104 M = OIS::KC_M, 105 Comma = OIS::KC_COMMA, 106 Period = OIS::KC_PERIOD, // . on main keyboard 107 Slash = OIS::KC_SLASH, // / on main keyboard 108 RightShift = OIS::KC_RSHIFT, 109 Multiply = OIS::KC_MULTIPLY, // * on numeric keypad 110 LeftAlt = OIS::KC_LMENU, // left Alt 111 Space = OIS::KC_SPACE, 112 CapsLock = OIS::KC_CAPITAL, 113 F1 = OIS::KC_F1, 114 F2 = OIS::KC_F2, 115 F3 = OIS::KC_F3, 116 F4 = OIS::KC_F4, 117 F5 = OIS::KC_F5, 118 F6 = OIS::KC_F6, 119 F7 = OIS::KC_F7, 120 F8 = OIS::KC_F8, 121 F9 = OIS::KC_F9, 122 F10 = OIS::KC_F10, 123 NumLock = OIS::KC_NUMLOCK, 124 ScrollLock = OIS::KC_SCROLL, // Scroll Lock 125 Numpad7 = OIS::KC_NUMPAD7, 126 Numpad8 = OIS::KC_NUMPAD8, 127 Numpad9 = OIS::KC_NUMPAD9, 128 NumpadSubtract= OIS::KC_SUBTRACT, // - on numeric keypad 129 Numpad4 = OIS::KC_NUMPAD4, 130 Numpad5 = OIS::KC_NUMPAD5, 131 Numpad6 = OIS::KC_NUMPAD6, 132 NumpadAdd = OIS::KC_ADD, // + on numeric keypad 133 Numpad1 = OIS::KC_NUMPAD1, 134 Numpad2 = OIS::KC_NUMPAD2, 135 Numpad3 = OIS::KC_NUMPAD3, 136 Numpad0 = OIS::KC_NUMPAD0, 137 NumpadPeriod = OIS::KC_DECIMAL, // . on numeric keypad 138 LessThan = OIS::KC_OEM_102, // < > | on UK/Germany keyboards 139 F11 = OIS::KC_F11, 140 F12 = OIS::KC_F12, 141 F13 = OIS::KC_F13, // (NEC PC98) 142 F14 = OIS::KC_F14, // (NEC PC98) 143 F15 = OIS::KC_F15, // (NEC PC98) 144 Kana = OIS::KC_KANA, // (Japanese keyboard) 145 ABNT_C1 = OIS::KC_ABNT_C1, // / ? on Portugese (Brazilian) keyboards 146 Convert = OIS::KC_CONVERT, // (Japanese keyboard) 147 NoConvert = OIS::KC_NOCONVERT, // (Japanese keyboard) 148 Yen = OIS::KC_YEN, // (Japanese keyboard) 149 ABNT_C2 = OIS::KC_ABNT_C2, // Numpad . on Portugese (Brazilian) keyboards 150 NumpadEquals = OIS::KC_NUMPADEQUALS, // = on numeric keypad (NEC PC98) 151 PreviousTrack = OIS::KC_PREVTRACK, // Previous Track (KC_CIRCUMFLEX on Japanese keyboard) 152 AT = OIS::KC_AT, // (NEC PC98) 153 Colon = OIS::KC_COLON, // (NEC PC98) 154 Underline = OIS::KC_UNDERLINE, // (NEC PC98) 155 Kanji = OIS::KC_KANJI, // (Japanese keyboard) 156 Stop = OIS::KC_STOP, // (NEC PC98) 157 AX = OIS::KC_AX, // (Japan AX) 158 Unlabeled = OIS::KC_UNLABELED, // (J3100) 159 NextTrack = OIS::KC_NEXTTRACK, // Next Track 160 NumpadEnter = OIS::KC_NUMPADENTER, // Enter on numeric keypad 161 RightControl = OIS::KC_RCONTROL, 162 Mute = OIS::KC_MUTE, // Mute 163 Calculator = OIS::KC_CALCULATOR, // Calculator 164 PlayPause = OIS::KC_PLAYPAUSE, // Play / Pause 165 MediaStop = OIS::KC_MEDIASTOP, // Media Stop 166 VolumeDown = OIS::KC_VOLUMEDOWN, // Volume - 167 VolumeUp = OIS::KC_VOLUMEUP, // Volume + 168 WebHome = OIS::KC_WEBHOME, // Web home 169 NumpadComma = OIS::KC_NUMPADCOMMA, // , on numeric keypad (NEC PC98) 170 Divide = OIS::KC_DIVIDE, // / on numeric keypad 171 SystemRequest = OIS::KC_SYSRQ, 172 RightAlt = OIS::KC_RMENU, // right Alt 173 Pause = OIS::KC_PAUSE, // Pause 174 Home = OIS::KC_HOME, // Home on arrow keypad 175 Up = OIS::KC_UP, // UpArrow on arrow keypad 176 PageUp = OIS::KC_PGUP, // PgUp on arrow keypad 177 Left = OIS::KC_LEFT, // LeftArrow on arrow keypad 178 Right = OIS::KC_RIGHT, // RightArrow on arrow keypad 179 End = OIS::KC_END, // End on arrow keypad 180 Down = OIS::KC_DOWN, // DownArrow on arrow keypad 181 PageDown = OIS::KC_PGDOWN, // PgDn on arrow keypad 182 Insert = OIS::KC_INSERT, // Insert on arrow keypad 183 Delete = OIS::KC_DELETE, // Delete on arrow keypad 184 LeftWindows = OIS::KC_LWIN, // Left Windows key 185 RightWindows = OIS::KC_RWIN, // Right Windows key 186 Apps = OIS::KC_APPS, // AppMenu key 187 Power = OIS::KC_POWER, // System Power 188 Sleep = OIS::KC_SLEEP, // System Sleep 189 Wake = OIS::KC_WAKE, // System Wake 190 WebSearch = OIS::KC_WEBSEARCH, // Web Search 191 WebFavorites = OIS::KC_WEBFAVORITES, // Web Favorites 192 WebRefresh = OIS::KC_WEBREFRESH, // Web Refresh 193 WebStop = OIS::KC_WEBSTOP, // Web Stop 194 WebForward = OIS::KC_WEBFORWARD, // Web Forward 195 WebBack = OIS::KC_WEBBACK, // Web Back 196 MyComputer = OIS::KC_MYCOMPUTER, // My Computer 197 Mail = OIS::KC_MAIL, // Mail 198 MediaSelect = OIS::KC_MEDIASELECT // Media Select 199 }; 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 306 { 307 Left = OIS::MB_Left, 308 Right = OIS::MB_Right, 309 Middle = OIS::MB_Middle, 310 Button3 = OIS::MB_Button3, 311 Button4 = OIS::MB_Button4, 312 Button5 = OIS::MB_Button5, 313 Button6 = OIS::MB_Button6, 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 354 { 355 Button0 = 0, Button1 = 1, Button2 = 2, Button3 = 3, 356 Button4 = 4, Button5 = 5, Button6 = 6, Button7 = 7, 357 Button8 = 8, Button9 = 9, Button10 = 10, Button11 = 11, 358 Button12 = 12, Button13 = 13, Button14 = 14, Button15 = 15, 359 Button16 = 16, Button17 = 17, Button18 = 18, Button19 = 19, 360 Button20 = 20, Button21 = 21, Button22 = 22, Button23 = 23, 361 Button24 = 24, Button25 = 25, Button26 = 26, Button27 = 27, 362 Button28 = 28, Button29 = 29, Button30 = 30, Button31 = 31, 363 364 POV0North = 32, POV0South = 33, POV0East = 34, POV0West = 35, 365 POV0NorthEast = 36, POV0SouthEast = 37, POV0NorthWest = 38, POV0SouthWest = 39, 366 367 POV1North = 40, POV1South = 41, POV1East = 42, POV1West = 43, 368 POV1NorthEast = 44, POV1SouthEast = 45, POV1NorthWest = 46, POV1SouthWest = 47, 369 370 POV2North = 48, POV2South = 49, POV2East = 50, POV2West = 51, 371 POV2NorthEast = 52, POV2SouthEast = 53, POV2NorthWest = 54, POV2SouthWest = 55, 372 373 POV3North = 56, POV3South = 57, POV3East = 58, POV3West = 59, 374 POV3NorthEast = 60, POV3SouthEast = 61, POV3NorthWest = 62, POV3SouthWest = 63, 375 }; 376 377 // Names as string. Has no real linkage! 378 const char* const ByString[] = 379 { 380 "Button00", "Button01", "Button02", "Button03", 381 "Button04", "Button05", "Button06", "Button07", 382 "Button08", "Button09", "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 "Axis00", "Axis01", "Axis02", "Axis03", 419 "Axis04", "Axis05", "Axis06", "Axis07", 420 "Axis08", "Axis09", "Axis10", "Axis11", 421 "Axis12", "Axis13", "Axis14", "Axis15" 422 }; 423 } 424 425 namespace KeyboardModifier 426 { 427 enum Enum 428 { 429 Shift = 0x0000001, 430 Ctrl = 0x0000010, 431 Alt = 0x0000100 432 }; 433 } 434 435 namespace InputDevice 436 { 437 enum Enum 438 { 439 Keyboard, 440 Mouse, 441 JoyStick0, 442 JoyStick1, 443 JoyStick2, 444 JoyStick3 445 // note: No problem if there are more joy sticks. This enum is just for convenience. 446 }; 447 } 448 449 struct _CoreExport Key 450 { 451 Key(const OIS::KeyEvent& evt) : key((KeyCode::ByEnum)evt.key), text(evt.text) { } 452 KeyCode::ByEnum key; 453 unsigned int text; 454 }; 455 456 class _CoreExport KeyEvent 457 { 458 public: 459 KeyEvent(KeyCode::ByEnum key, unsigned int text) : key(key), text(text) { } 460 KeyEvent(const OIS::KeyEvent& evt, unsigned int mod) 461 : key((KeyCode::ByEnum)evt.key), text(evt.text), modifiers(mod) { } 462 KeyEvent(const Key& key, unsigned int mod) : key(key.key), text(key.text), modifiers(mod) { } 463 bool isModifierDown(KeyboardModifier::Enum modifier) const 464 { return (KeyboardModifier::Enum)modifier&modifiers; } 465 466 const KeyCode::ByEnum key; 467 unsigned int text; 468 unsigned int modifiers; 469 }; 470 471 43 /** 44 @brief 45 */ 472 46 class _CoreExport InputHandler 473 47 { 474 48 public: 475 49 virtual ~InputHandler() { } 476 virtual void updateInput(float dt) = 0; 50 51 template<class T> void buttonEvent(unsigned int device, const T& button, ButtonEvent::TPress) 52 { this->buttonPressed(button); } 53 template<class T> void buttonEvent(unsigned int device, const T& button, ButtonEvent::TRelease) 54 { this->buttonReleased(button); } 55 template<class T> void buttonEvent(unsigned int device, const T& button, ButtonEvent::THold) 56 { this->buttonHeld(button); } 57 void buttonEvent(unsigned int device, JoyStickButtonCode::ByEnum button, ButtonEvent::TPress) 58 { this->buttonPressed(device - InputDeviceEnumerator::FirstJoyStick, button); } 59 void buttonEvent(unsigned int device, JoyStickButtonCode::ByEnum button, ButtonEvent::TRelease) 60 { this->buttonReleased(device - InputDeviceEnumerator::FirstJoyStick, button); } 61 void buttonEvent(unsigned int device, JoyStickButtonCode::ByEnum button, ButtonEvent::THold) 62 { this->buttonHeld(device - InputDeviceEnumerator::FirstJoyStick, button); } 63 64 virtual void buttonPressed (const KeyEvent& evt) { } 65 virtual void buttonReleased(const KeyEvent& evt) { } 66 virtual void buttonHeld (const KeyEvent& evt) { } 67 68 virtual void buttonPressed (MouseButtonCode::ByEnum button) { } 69 virtual void buttonReleased(MouseButtonCode::ByEnum button) { } 70 virtual void buttonHeld (MouseButtonCode::ByEnum button) { } 71 virtual void mouseMoved (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) { } 72 virtual void mouseScrolled (int abs, int rel) { } 73 74 virtual void buttonPressed (unsigned int joyStick, JoyStickButtonCode::ByEnum button) { } 75 virtual void buttonReleased(unsigned int joyStick, JoyStickButtonCode::ByEnum button) { } 76 virtual void buttonHeld (unsigned int joyStick, JoyStickButtonCode::ByEnum button) { } 77 virtual void axisMoved (unsigned int joyStick, unsigned int axis, float value){ } 78 79 virtual void keyboardUpdated(float dt) { } 80 virtual void mouseUpdated (float dt) { } 81 virtual void joyStickUpdated(unsigned int joyStick, float dt) { } 82 83 virtual void allDevicesUpdated(float dt) { } 84 85 static InputHandler EMPTY; 477 86 }; 478 479 /**480 @brief481 Interface class used for key input listeners.482 */483 class _CoreExport KeyHandler : virtual public InputHandler484 {485 public:486 virtual ~KeyHandler() { }487 virtual void keyPressed (const KeyEvent& evt) = 0;488 virtual void keyReleased(const KeyEvent& evt) = 0;489 virtual void keyHeld (const KeyEvent& evt) = 0;490 virtual void updateKey (float dt) = 0;491 };492 493 /**494 @brief495 Interface class used for mouse input listeners.496 */497 class _CoreExport MouseHandler : virtual public InputHandler498 {499 public:500 virtual ~MouseHandler() { }501 virtual void mouseButtonPressed (MouseButtonCode::ByEnum id) = 0;502 virtual void mouseButtonReleased(MouseButtonCode::ByEnum id) = 0;503 virtual void mouseButtonHeld (MouseButtonCode::ByEnum id) = 0;504 virtual void mouseMoved (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) = 0;505 virtual void mouseScrolled (int abs, int rel) = 0;506 virtual void updateMouse (float dt) = 0;507 };508 509 510 /**511 @brief512 Interface class used for joy stick input listeners.513 */514 class _CoreExport JoyStickHandler : virtual public InputHandler515 {516 public:517 virtual ~JoyStickHandler() { }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;521 virtual void joyStickAxisMoved (unsigned int joyStickID, unsigned int axis, float value) = 0;522 virtual void updateJoyStick (float dt, unsigned int joyStick) = 0;523 };524 525 class _CoreExport EmptyHandler : public KeyHandler, public MouseHandler, public JoyStickHandler526 {527 friend class InputManager;528 private:529 EmptyHandler() { }530 EmptyHandler(EmptyHandler&);531 virtual ~EmptyHandler() { }532 533 void updateInput(float dt) { }534 void updateJoyStick(float dt, unsigned int joyStick) { }535 void updateMouse(float dt) { }536 void updateKey(float dt) { }537 538 void keyPressed (const KeyEvent& evt) { }539 void keyReleased(const KeyEvent& evt) { }540 void keyHeld (const KeyEvent& evt) { }541 542 void mouseButtonPressed (MouseButtonCode::ByEnum id) { }543 void mouseButtonReleased(MouseButtonCode::ByEnum id) { }544 void mouseButtonHeld (MouseButtonCode::ByEnum id) { }545 void mouseMoved (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) { }546 void mouseScrolled (int abs, int rel) { }547 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) { }551 void joyStickAxisMoved (unsigned int joyStickID, unsigned int axis, float value) { }552 };553 554 87 } 555 88 556 #endif /* _Input Interfaces_H__ */89 #endif /* _InputHandler_H__ */ -
code/branches/core4/src/core/input/InputManager.cc
r3272 r3274 50 50 #include "core/ConsoleCommand.h" 51 51 #include "core/CommandLine.h" 52 #include "core/Functor.h" 52 53 53 54 #include "InputBuffer.h" 54 55 #include "KeyDetector.h" 56 #include "InputHandler.h" 55 57 #include "InputState.h" 56 #include "SimpleInputState.h" 57 #include "JoyStickDeviceNumberListener.h" 58 #include "JoyStickQuantityListener.h" 58 59 #include "JoyStick.h" 60 #include "Mouse.h" 61 #include "Keyboard.h" 59 62 60 63 // HACK (include this as last, X11 seems to define some macros...) … … 73 76 SetCommandLineSwitch(keyboard_no_grab).information("Whether not to exclusively grab the keyboard"); 74 77 75 EmptyHandler InputManager::EMPTY_HANDLER;78 InputHandler InputHandler::EMPTY; 76 79 InputManager* InputManager::singletonRef_s = 0; 77 78 using namespace InputDevice;79 80 80 81 /** … … 109 110 InputManager::InputManager(size_t windowHnd, unsigned int windowWidth, unsigned int windowHeight) 110 111 : inputSystem_(0) 111 , keyboard_(0) 112 , mouse_(0) 113 , devicesNum_(0) 112 , devices_(2) 114 113 , windowHnd_(0) 115 114 , internalState_(Uninitialised) … … 117 116 , keyDetector_(0) 118 117 , calibratorCallbackBuffer_(0) 119 , keyboardModifiers_(0)120 118 { 121 119 RegisterRootObject(InputManager); … … 182 180 #endif 183 181 182 // TODO: clean this up 184 183 try 185 184 { … … 199 198 } 200 199 200 // TODO: Remove the two parameters 201 201 _initialiseMouse(windowWidth, windowHeight); 202 202 … … 220 220 221 221 // Lowest priority empty InputState 222 stateEmpty_ = createInputState <SimpleInputState>("empty", false, false, InputStatePriority::Empty);223 stateEmpty_->setHandler(& EMPTY_HANDLER);222 stateEmpty_ = createInputState("empty", false, false, InputStatePriority::Empty); 223 stateEmpty_->setHandler(&InputHandler::EMPTY); 224 224 activeStates_[stateEmpty_->getPriority()] = stateEmpty_; 225 225 226 226 // KeyDetector to evaluate a pressed key's name 227 SimpleInputState* detector = createInputState<SimpleInputState>("detector", false, false, InputStatePriority::Detector); 227 InputState* detector = createInputState("detector", false, false, InputStatePriority::Detector); 228 FunctorMember<InputManager>* bufferFunctor = createFunctor(&InputManager::clearBuffers); 229 bufferFunctor->setObject(this); 230 detector->setLeaveFunctor(bufferFunctor); 228 231 keyDetector_ = new KeyDetector(); 229 232 detector->setHandler(keyDetector_); 230 233 231 234 // Joy stick calibration helper callback 232 SimpleInputState* calibrator = createInputState<SimpleInputState>("calibrator", false, false, InputStatePriority::Calibrator);233 calibrator->setHandler(& EMPTY_HANDLER);235 InputState* calibrator = createInputState("calibrator", false, false, InputStatePriority::Calibrator); 236 calibrator->setHandler(&InputHandler::EMPTY); 234 237 calibratorCallbackBuffer_ = new InputBuffer(); 235 calibratorCallbackBuffer_->registerListener(this, &InputManager::_ completeCalibration, '\r', true);238 calibratorCallbackBuffer_->registerListener(this, &InputManager::_stopCalibration, '\r', true); 236 239 calibrator->setKeyHandler(calibratorCallbackBuffer_); 237 240 … … 246 249 } 247 250 248 /**249 @brief250 Creates a keyboard and sets the event handler.251 @return252 False if keyboard stays uninitialised, true otherwise.253 */254 251 void InputManager::_initialiseKeyboard() 255 252 { 256 if (keyboard_ != 0) 257 { 258 CCOUT(2) << "Warning: Keyboard already initialised, skipping." << std::endl; 259 return; 260 } 253 assert(devices_[InputDeviceEnumerator::Keyboard] == 0); 261 254 if (inputSystem_->getNumberOfDevices(OIS::OISKeyboard) > 0) 262 { 263 keyboard_ = (OIS::Keyboard*)inputSystem_->createInputObject(OIS::OISKeyboard, true); 264 // register our listener in OIS. 265 keyboard_->setEventCallback(this); 266 // note: OIS will not detect keys that have already been down when the keyboard was created. 267 CCOUT(ORX_DEBUG) << "Created OIS keyboard" << std::endl; 268 } 255 devices_[InputDeviceEnumerator::Keyboard] = new Keyboard(InputDeviceEnumerator::Keyboard); 269 256 else 270 {271 257 ThrowException(InitialisationFailed, "InputManager: No keyboard found, cannot proceed!"); 272 } 273 } 274 275 /** 276 @brief 277 Creates a mouse and sets the event handler. 278 @return 279 False if mouse stays uninitialised, true otherwise. 280 */ 258 } 259 281 260 void InputManager::_initialiseMouse(unsigned int windowWidth, unsigned int windowHeight) 282 261 { 283 if (mouse_ != 0) 284 { 285 CCOUT(2) << "Warning: Mouse already initialised, skipping." << std::endl; 286 return; 287 } 288 try 289 { 290 if (inputSystem_->getNumberOfDevices(OIS::OISMouse) > 0) 291 { 292 mouse_ = static_cast<OIS::Mouse*>(inputSystem_->createInputObject(OIS::OISMouse, true)); 293 // register our listener in OIS. 294 mouse_->setEventCallback(this); 295 CCOUT(ORX_DEBUG) << "Created OIS mouse" << std::endl; 296 297 // Set mouse region 298 setWindowExtents(windowWidth, windowHeight); 299 } 300 else 301 { 302 CCOUT(ORX_WARNING) << "Warning: No mouse found! Proceeding without mouse support." << std::endl; 303 } 304 } 305 catch (OIS::Exception ex) 306 { 307 CCOUT(ORX_WARNING) << "Warning: Failed to create an OIS mouse\n" 308 << "OIS error message: \"" << ex.eText << "\"\n Proceeding without mouse support." << std::endl; 309 mouse_ = 0; 310 } 262 assert(devices_[InputDeviceEnumerator::Mouse] == 0); 263 if (inputSystem_->getNumberOfDevices(OIS::OISMouse) > 0) 264 { 265 try 266 { 267 devices_[InputDeviceEnumerator::Mouse] = new Mouse(InputDeviceEnumerator::Mouse, windowWidth, windowHeight); 268 } 269 catch (const OIS::Exception& ex) 270 { 271 CCOUT(2) << "Warning: Failed to create Mouse:" << ex.eText << std::endl 272 << "Proceeding without mouse support." << std::endl; 273 } 274 } 275 else 276 CCOUT(ORX_WARNING) << "Warning: No mouse found! Proceeding without mouse support." << std::endl; 311 277 } 312 278 … … 319 285 void InputManager::_initialiseJoySticks() 320 286 { 321 if (!this->joySticks_.empty()) 322 { 323 CCOUT(2) << "Warning: Joy sticks already initialised, skipping." << std::endl; 324 return; 325 } 326 327 devicesNum_ = 2 + inputSystem_->getNumberOfDevices(OIS::OISJoyStick); 328 // state management 329 activeStatesTriggered_.resize(devicesNum_); 287 assert(devices_.size() == InputDeviceEnumerator::FirstJoyStick); 330 288 331 289 for (int i = 0; i < inputSystem_->getNumberOfDevices(OIS::OISJoyStick); i++) … … 333 291 try 334 292 { 335 joySticks_.push_back(new JoyStick(activeStatesTriggered_[2 + i],i));293 devices_.push_back(new JoyStick(InputDeviceEnumerator::FirstJoyStick + i)); 336 294 } 337 295 catch (std::exception ex) … … 342 300 343 301 // inform all JoyStick Device Number Listeners 344 for (ObjectList<JoyStick DeviceNumberListener>::iterator it = ObjectList<JoyStickDeviceNumberListener>::begin(); it; ++it)345 it->JoyStick DeviceNumberChanged(joySticks_.size());302 for (ObjectList<JoyStickQuantityListener>::iterator it = ObjectList<JoyStickQuantityListener>::begin(); it; ++it) 303 it->JoyStickQuantityChanged(devices_.size() - InputDeviceEnumerator::FirstJoyStick); 346 304 } 347 305 348 306 void InputManager::_startCalibration() 349 307 { 350 BOOST_FOREACH( JoyStick* stick, joySticks_)351 stick->startCalibration();308 BOOST_FOREACH(InputDevice* device, devices_) 309 device->startCalibration(); 352 310 353 311 getInstance().internalState_ |= Calibrating; … … 355 313 } 356 314 357 void InputManager::_ completeCalibration()358 { 359 BOOST_FOREACH( JoyStick* stick, joySticks_)360 stick->stopCalibration();315 void InputManager::_stopCalibration() 316 { 317 BOOST_FOREACH(InputDevice* device, devices_) 318 device->stopCalibration(); 361 319 362 320 // restore old input state 363 321 requestLeaveState("calibrator"); 364 322 internalState_ &= ~Calibrating; 323 // Clear buffers to prevent button hold events 324 this->clearBuffers(); 365 325 } 366 326 … … 374 334 Destroys all the created input devices and states. 375 335 */ 336 // TODO: export this to be used with reload() 376 337 InputManager::~InputManager() 377 338 { … … 379 340 { 380 341 CCOUT(3) << "Destroying ..." << std::endl; 381 382 // kick all active states 'nicely'383 for (std::map<int, InputState*>::reverse_iterator rit = activeStates_.rbegin();384 rit != activeStates_.rend(); ++rit)385 {386 (*rit).second->onLeave();387 }388 342 389 343 // Destroy calibrator helper handler and state … … 401 355 402 356 // destroy the devices 403 _destroyKeyboard(); 404 _destroyMouse(); 405 _destroyJoySticks(); 357 BOOST_FOREACH(InputDevice*& device, devices_) 358 { 359 std::string className = device->getClassName(); 360 try 361 { 362 if (device) 363 delete device; 364 device = 0; 365 CCOUT(4) << className << " destroyed." << std::endl; 366 } 367 catch (...) 368 { 369 CCOUT(1) << className << " destruction failed! Potential resource leak!" << std::endl; 370 } 371 } 372 devices_.resize(InputDeviceEnumerator::FirstJoyStick); 406 373 407 374 try … … 416 383 417 384 singletonRef_s = 0; 418 }419 420 /**421 @brief422 Destroys the keyboard and sets it to 0.423 */424 void InputManager::_destroyKeyboard()425 {426 assert(inputSystem_);427 try428 {429 if (keyboard_)430 inputSystem_->destroyInputObject(keyboard_);431 keyboard_ = 0;432 CCOUT(4) << "Keyboard destroyed." << std::endl;433 }434 catch (...)435 {436 CCOUT(1) << "Keyboard destruction failed! Potential resource leak!" << std::endl;437 }438 }439 440 /**441 @brief442 Destroys the mouse and sets it to 0.443 */444 void InputManager::_destroyMouse()445 {446 assert(inputSystem_);447 try448 {449 if (mouse_)450 inputSystem_->destroyInputObject(mouse_);451 mouse_ = 0;452 CCOUT(4) << "Mouse destroyed." << std::endl;453 }454 catch (...)455 {456 CCOUT(1) << "Mouse destruction failed! Potential resource leak!" << std::endl;457 }458 }459 460 /**461 @brief462 Destroys all the joy sticks and resizes the lists to 0.463 */464 void InputManager::_destroyJoySticks()465 {466 assert(inputSystem_);467 while (!joySticks_.empty())468 {469 try470 {471 delete joySticks_.back();472 }473 catch (...)474 {475 CCOUT(1) << "Joy stick destruction failed! Potential resource leak!" << std::endl;476 }477 joySticks_.pop_back();478 devicesNum_ = 2;479 }480 CCOUT(4) << "Joy sticks destroyed." << std::endl;481 385 } 482 386 … … 539 443 540 444 // Save mouse clipping size 541 int mouseWidth = mouse_->getMouseState().width;542 int mouseHeight = mouse_->getMouseState().height;445 int mouseWidth = static_cast<Mouse*>(devices_[InputDeviceEnumerator::Mouse])->getClippingWidth(); 446 int mouseHeight = static_cast<Mouse*>(devices_[InputDeviceEnumerator::Mouse])->getClippingHeight(); 543 447 544 448 internalState_ &= ~OISReady; 545 449 546 450 // destroy the devices 547 _destroyKeyboard(); 548 _destroyMouse(); 549 _destroyJoySticks(); 451 // destroy the devices 452 BOOST_FOREACH(InputDevice*& device, devices_) 453 { 454 try 455 { 456 if (device) 457 delete device; 458 device = 0; 459 CCOUT(4) << device->getClassName() << " destroyed." << std::endl; 460 } 461 catch (...) 462 { 463 CCOUT(1) << device->getClassName() << " destruction failed! Potential resource leak!" << std::endl; 464 } 465 } 466 devices_.resize(InputDeviceEnumerator::FirstJoyStick); 550 467 551 468 OIS::InputManager::destroyInputSystem(inputSystem_); … … 592 509 it != stateLeaveRequests_.end(); ++it) 593 510 { 594 (*it)-> onLeave();511 (*it)->left(); 595 512 // just to be sure that the state actually is registered 596 513 assert(inputStatesByName_.find((*it)->getName()) != inputStatesByName_.end()); … … 631 548 activeStates_[(*it)->getPriority()] = (*it); 632 549 _updateActiveStates(); 633 (*it)-> onEnter();550 (*it)->entered(); 634 551 } 635 552 stateEnterRequests_.clear(); … … 647 564 } 648 565 649 // check whether a state has changed its EMPTY _HANDLERsituation566 // check whether a state has changed its EMPTY situation 650 567 bool bUpdateRequired = false; 651 568 for (std::map<int, InputState*>::iterator it = activeStates_.begin(); it != activeStates_.end(); ++it) 652 569 { 653 if (it->second->ha ndlersChanged())654 { 655 it->second->reset HandlersChanged();570 if (it->second->hasExpired()) 571 { 572 it->second->resetExpiration(); 656 573 bUpdateRequired = true; 657 574 } … … 664 581 665 582 // Capture all the input. This calls the event handlers in InputManager. 666 if (keyboard_) 667 keyboard_->capture(); 668 if (mouse_) 669 mouse_->capture(); 670 BOOST_FOREACH(JoyStick* stick, joySticks_) 671 stick->capture(); 583 BOOST_FOREACH(InputDevice* device, devices_) 584 device->update(time); 672 585 673 586 if (!(internalState_ & Calibrating)) 674 587 { 675 // call all the handlers for the held key events 676 for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++) 677 { 678 KeyEvent kEvt(keysDown_[iKey], keyboardModifiers_); 679 680 for (unsigned int iState = 0; iState < activeStatesTriggered_[Keyboard].size(); ++iState) 681 activeStatesTriggered_[Keyboard][iState]->keyHeld(kEvt); 682 } 683 684 // call all the handlers for the held mouse button events 685 for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++) 686 { 687 for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState) 688 activeStatesTriggered_[Mouse][iState]->mouseButtonHeld(mouseButtonsDown_[iButton]); 689 } 690 691 // update the handlers for each active handler 692 for (unsigned int i = 0; i < devicesNum_; ++i) 693 { 694 for (unsigned int iState = 0; iState < activeStatesTriggered_[i].size(); ++iState) 695 activeStatesTriggered_[i][iState]->updateInput(time.getDeltaTime(), i); 696 } 697 698 // update the handler with a general tick afterwards 588 // update the states with a general tick afterwards 699 589 for (unsigned int i = 0; i < activeStatesTicked_.size(); ++i) 700 activeStatesTicked_[i]->update Input(time.getDeltaTime());590 activeStatesTicked_[i]->update(time.getDeltaTime()); 701 591 } 702 592 … … 711 601 void InputManager::_updateActiveStates() 712 602 { 713 for (unsigned int i = 0; i < devicesNum_; ++i) 714 { 603 // temporary resize 604 for (unsigned int i = 0; i < devices_.size(); ++i) 605 { 606 std::vector<InputState*>& states = devices_[i]->getStateListRef(); 715 607 bool occupied = false; 716 activeStatesTriggered_[i].clear();717 for (std::map<int, InputState*>:: const_reverse_iterator rit = activeStates_.rbegin(); rit != activeStates_.rend(); ++rit)608 states.clear(); 609 for (std::map<int, InputState*>::reverse_iterator rit = activeStates_.rbegin(); rit != activeStates_.rend(); ++rit) 718 610 { 719 611 if (rit->second->isInputDeviceEnabled(i) && (!occupied || rit->second->bAlwaysGetsInput_)) 720 612 { 721 activeStatesTriggered_[i].push_back(rit->second);613 states.push_back(rit->second); 722 614 if (!rit->second->bTransparent_) 723 615 occupied = true; … … 729 621 // Using a std::set to avoid duplicates 730 622 std::set<InputState*> tempSet; 731 for (unsigned int i = 0; i < devices Num_; ++i)732 for (unsigned int iState = 0; iState < activeStatesTriggered_[i].size(); ++iState)733 tempSet.insert( activeStatesTriggered_[i][iState]);623 for (unsigned int i = 0; i < devices_.size(); ++i) 624 for (unsigned int iState = 0; iState < devices_[i]->getStateListRef().size(); ++iState) 625 tempSet.insert(devices_[i]->getStateListRef()[iState]); 734 626 735 627 // copy the content of the std::set back to the actual vector … … 737 629 for (std::set<InputState*>::const_iterator it = tempSet.begin();it != tempSet.end(); ++it) 738 630 activeStatesTicked_.push_back(*it); 739 740 this->mouseButtonsDown_.clear();741 631 } 742 632 … … 747 637 void InputManager::clearBuffers() 748 638 { 749 keysDown_.clear(); 750 keyboardModifiers_ = 0; 751 mouseButtonsDown_.clear(); 752 BOOST_FOREACH(JoyStick* stick, joySticks_) 753 stick->clearBuffer(); 754 } 755 756 757 // ############################################################ 758 // ##### OIS events ##### 759 // ########## ########## 760 // ############################################################ 761 762 // ###### Key Events ###### 763 764 /** 765 @brief 766 Event handler for the keyPressed Event. 767 @param e 768 Event information 769 */ 770 bool InputManager::keyPressed(const OIS::KeyEvent &e) 771 { 772 // check whether the key already is in the list (can happen when focus was lost) 773 unsigned int iKey = 0; 774 while (iKey < keysDown_.size() && keysDown_[iKey].key != (KeyCode::ByEnum)e.key) 775 iKey++; 776 if (iKey == keysDown_.size()) 777 keysDown_.push_back(Key(e)); 778 else 779 { 780 // This happens when XAutoRepeat is set under linux. The KeyPressed event gets then sent 781 // continuously. 782 return true; 783 } 784 785 // update modifiers 786 if(e.key == OIS::KC_RMENU || e.key == OIS::KC_LMENU) 787 keyboardModifiers_ |= KeyboardModifier::Alt; // alt key 788 if(e.key == OIS::KC_RCONTROL || e.key == OIS::KC_LCONTROL) 789 keyboardModifiers_ |= KeyboardModifier::Ctrl; // ctrl key 790 if(e.key == OIS::KC_RSHIFT || e.key == OIS::KC_LSHIFT) 791 keyboardModifiers_ |= KeyboardModifier::Shift; // shift key 792 793 KeyEvent kEvt(e, keyboardModifiers_); 794 for (unsigned int iState = 0; iState < activeStatesTriggered_[Keyboard].size(); ++iState) 795 activeStatesTriggered_[Keyboard][iState]->keyPressed(kEvt); 796 797 return true; 798 } 799 800 /** 801 @brief 802 Event handler for the keyReleased Event. 803 @param e 804 Event information 805 */ 806 bool InputManager::keyReleased(const OIS::KeyEvent &e) 807 { 808 // remove the key from the keysDown_ list 809 for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++) 810 { 811 if (keysDown_[iKey].key == (KeyCode::ByEnum)e.key) 812 { 813 keysDown_.erase(keysDown_.begin() + iKey); 814 break; 815 } 816 } 817 818 // update modifiers 819 if(e.key == OIS::KC_RMENU || e.key == OIS::KC_LMENU) 820 keyboardModifiers_ &= ~KeyboardModifier::Alt; // alt key 821 if(e.key == OIS::KC_RCONTROL || e.key == OIS::KC_LCONTROL) 822 keyboardModifiers_ &= ~KeyboardModifier::Ctrl; // ctrl key 823 if(e.key == OIS::KC_RSHIFT || e.key == OIS::KC_LSHIFT) 824 keyboardModifiers_ &= ~KeyboardModifier::Shift; // shift key 825 826 KeyEvent kEvt(e, keyboardModifiers_); 827 for (unsigned int iState = 0; iState < activeStatesTriggered_[Keyboard].size(); ++iState) 828 activeStatesTriggered_[Keyboard][iState]->keyReleased(kEvt); 829 830 return true; 831 } 832 833 834 // ###### Mouse Events ###### 835 836 /** 837 @brief 838 Event handler for the mouseMoved Event. 839 @param e 840 Event information 841 */ 842 bool InputManager::mouseMoved(const OIS::MouseEvent &e) 843 { 844 // check for actual moved event 845 if (e.state.X.rel != 0 || e.state.Y.rel != 0) 846 { 847 IntVector2 abs(e.state.X.abs, e.state.Y.abs); 848 IntVector2 rel(e.state.X.rel, e.state.Y.rel); 849 IntVector2 clippingSize(e.state.width, e.state.height); 850 for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState) 851 activeStatesTriggered_[Mouse][iState]->mouseMoved(abs, rel, clippingSize); 852 } 853 854 // check for mouse scrolled event 855 if (e.state.Z.rel != 0) 856 { 857 for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState) 858 activeStatesTriggered_[Mouse][iState]->mouseScrolled(e.state.Z.abs, e.state.Z.rel); 859 } 860 861 return true; 862 } 863 864 /** 865 @brief 866 Event handler for the mousePressed Event. 867 @param e 868 Event information 869 @param id 870 The ID of the mouse button 871 */ 872 bool InputManager::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id) 873 { 874 // check whether the button already is in the list (can happen when focus was lost) 875 unsigned int iButton = 0; 876 while (iButton < mouseButtonsDown_.size() && mouseButtonsDown_[iButton] != (MouseButtonCode::ByEnum)id) 877 iButton++; 878 if (iButton == mouseButtonsDown_.size()) 879 mouseButtonsDown_.push_back((MouseButtonCode::ByEnum)id); 880 881 for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState) 882 activeStatesTriggered_[Mouse][iState]->mouseButtonPressed((MouseButtonCode::ByEnum)id); 883 884 return true; 885 } 886 887 /** 888 @brief 889 Event handler for the mouseReleased Event. 890 @param e 891 Event information 892 @param id 893 The ID of the mouse button 894 */ 895 bool InputManager::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id) 896 { 897 // remove the button from the keysDown_ list 898 for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++) 899 { 900 if (mouseButtonsDown_[iButton] == (MouseButtonCode::ByEnum)id) 901 { 902 mouseButtonsDown_.erase(mouseButtonsDown_.begin() + iButton); 903 break; 904 } 905 } 906 907 for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState) 908 activeStatesTriggered_[Mouse][iState]->mouseButtonReleased((MouseButtonCode::ByEnum)id); 909 910 return true; 639 BOOST_FOREACH(InputDevice* device, devices_) 640 device->clearBuffers(); 911 641 } 912 642 … … 923 653 Returns true if ID is ok (unique), false otherwise. 924 654 */ 925 bool InputManager::checkJoyStickID(const std::string& idString) 926 { 927 BOOST_FOREACH(JoyStick* stick, joySticks_) 928 { 929 if (stick->getIDString() == idString) 655 bool InputManager::checkJoyStickID(const std::string& idString) const 656 { 657 for (unsigned int i = InputDeviceEnumerator::FirstJoyStick; i < devices_.size(); ++i) 658 if (static_cast<JoyStick*>(devices_[i])->getIDString() == idString) 930 659 return false; 931 }932 660 return true; 933 661 } … … 938 666 // ########## ########## 939 667 // ############################################################ 940 941 /**942 @brief943 Adjusts the mouse window metrics.944 This method has to be called every time the size of the window changes.945 @param width946 The new width of the render window947 @param^height948 The new height of the render window949 */950 void InputManager::setWindowExtents(const int width, const int height)951 {952 if (mouse_)953 {954 // Set mouse region (if window resizes, we should alter this to reflect as well)955 mouse_->getMouseState().width = width;956 mouse_->getMouseState().height = height;957 }958 }959 668 960 669 /** … … 970 679 971 680 // ###### InputStates ###### 681 682 /** 683 @brief 684 Creates a new InputState by type, name and priority. 685 686 You will have to use this method because the 687 c'tors and d'tors are private. 688 @remarks 689 The InputManager will take care of the state completely. That also 690 means it gets deleted when the InputManager is destroyed! 691 @param name 692 Name of the InputState when referenced as string 693 @param priority 694 Priority matters when multiple states are active. You can specify any 695 number, but 1 - 99 is preferred (99 means high). 696 */ 697 InputState* InputManager::createInputState(const std::string& name, bool bAlwaysGetsInput, bool bTransparent, InputStatePriority priority) 698 { 699 InputState* state = new InputState; 700 if (_configureInputState(state, name, bAlwaysGetsInput, bTransparent, priority)) 701 return state; 702 else 703 { 704 delete state; 705 return 0; 706 } 707 } 972 708 973 709 /** … … 1008 744 } 1009 745 inputStatesByName_[name] = state; 1010 state->JoyStick DeviceNumberChanged(numberOfJoySticks());746 state->JoyStickQuantityChanged(devices_.size() - InputDeviceEnumerator::FirstJoyStick); 1011 747 state->setName(name); 1012 748 state->bAlwaysGetsInput_ = bAlwaysGetsInput; -
code/branches/core4/src/core/input/InputManager.h
r3270 r3274 37 37 #define _InputManager_H__ 38 38 39 #include " core/CorePrereqs.h"39 #include "InputPrereqs.h" 40 40 41 41 #include <map> … … 43 43 #include <string> 44 44 #include <vector> 45 #include <ois/OISKeyboard.h>46 #include <ois/OISMouse.h>47 #include <ois/OISJoyStick.h>48 45 49 46 #include "util/Math.h" 50 47 #include "util/OrxEnum.h" 51 48 #include "core/OrxonoxClass.h" 52 #include "InputInterfaces.h"53 49 54 50 namespace orxonox … … 71 67 Captures and distributes mouse and keyboard input. 72 68 */ 73 class _CoreExport InputManager 74 : public OrxonoxClass, 75 public OIS::KeyListener, public OIS::MouseListener 69 class _CoreExport InputManager : public OrxonoxClass 76 70 { 77 71 // --> setConfigValues is private 78 72 friend class ClassIdentifier<InputManager>; 79 friend class JoyStick;80 73 81 74 public: … … 99 92 void clearBuffers(); 100 93 101 unsigned int numberOfKeyboards() { return keyboard_ ? 1 : 0; }102 unsigned int numberOfMice() { return mouse_ ? 1 : 0; }103 unsigned int numberOfJoySticks() { return joySticks_.size(); }104 105 94 void setWindowExtents(const int width, const int height); 106 95 void setKeyDetectorCallback(const std::string& command); 107 96 108 template <class T> 109 T* createInputState(const std::string& name, bool bAlwaysGetsInput = false, bool bTransparent = false, InputStatePriority priority = InputStatePriority::Dynamic); 97 InputState* createInputState(const std::string& name, bool bAlwaysGetsInput = false, bool bTransparent = false, InputStatePriority priority = InputStatePriority::Dynamic); 110 98 111 99 InputState* getState (const std::string& name); … … 114 102 bool requestEnterState (const std::string& name); 115 103 bool requestLeaveState (const std::string& name); 104 105 OIS::InputManager* getInputSystem() { return this->inputSystem_; } 106 bool checkJoyStickID(const std::string& idString) const; 107 unsigned int getJoyStickQuantity() const 108 { return devices_.size() - InputDeviceEnumerator::FirstJoyStick; } 116 109 117 110 #ifdef ORXONOX_PLATFORM_LINUX … … 130 123 static void reload(); 131 124 132 public: // variables133 static EmptyHandler EMPTY_HANDLER;134 135 private: // functions for friends136 OIS::InputManager* getInputSystem() { return this->inputSystem_; }137 bool checkJoyStickID(const std::string&);138 139 125 private: // functions 140 126 // don't mess with a Singleton 141 InputManager 127 InputManager(const InputManager&); 142 128 143 129 // Intenal methods … … 145 131 void _initialiseMouse(unsigned int windowWidth, unsigned int windowHeight); 146 132 void _initialiseJoySticks(); 147 void _configureJoySticks();148 133 149 void _loadCalibration();150 134 void _startCalibration(); 151 void _completeCalibration(); 152 void _evaluateCalibration(); 135 void _stopCalibration(); 153 136 154 void _destroyKeyboard();155 void _destroyMouse();156 void _destroyJoySticks();157 137 void _destroyState(InputState* state); 158 138 159 139 void _reload(); 160 140 161 void _fireAxis(unsigned int iJoyStick, int axis, int value);162 unsigned int _getJoystick(const OIS::JoyStickEvent& arg);163 164 141 void _updateActiveStates(); 165 142 bool _configureInputState(InputState* state, const std::string& name, bool bAlwaysGetsInput, bool bTransparent, int priority); 166 143 167 // input events168 bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id);169 bool mouseReleased (const OIS::MouseEvent &arg, OIS::MouseButtonID id);170 bool mouseMoved (const OIS::MouseEvent &arg);171 bool keyPressed (const OIS::KeyEvent &arg);172 bool keyReleased (const OIS::KeyEvent &arg);173 174 144 void setConfigValues(); 175 void _calibrationFileCallback();176 145 177 146 private: // variables 178 147 OIS::InputManager* inputSystem_; //!< OIS input manager 179 OIS::Keyboard* keyboard_; //!< OIS mouse 180 OIS::Mouse* mouse_; //!< OIS keyboard 181 std::vector<JoyStick*> joySticks_; //!< Orxonox joy sticks 182 unsigned int devicesNum_; 148 std::vector<InputDevice*> devices_; //!< List of all input devices (keyboard, mouse, joy sticks) 183 149 size_t windowHnd_; //!< Render window handle 184 150 InputManagerState internalState_; //!< Current internal state 185 151 186 152 // some internally handled states and handlers 187 SimpleInputState*stateEmpty_;153 InputState* stateEmpty_; 188 154 KeyDetector* keyDetector_; //!< KeyDetector instance 189 155 InputBuffer* calibratorCallbackBuffer_; … … 196 162 197 163 std::map<int, InputState*> activeStates_; 198 std::vector<std::vector<InputState*> > activeStatesTriggered_;199 164 std::vector<InputState*> activeStatesTicked_; 200 201 unsigned int keyboardModifiers_; //!< Bit mask representing keyboard modifiers.202 203 std::vector<Key> keysDown_;204 std::vector<MouseButtonCode::ByEnum> mouseButtonsDown_;205 165 206 166 static InputManager* singletonRef_s; 207 167 }; 208 209 /**210 @brief211 Creates a new InputState by type, name and priority.212 213 You will have to use this method because the214 c'tors and d'tors are private.215 @remarks216 The InputManager will take care of the state completely. That also217 means it gets deleted when the InputManager is destroyed!218 @param name219 Name of the InputState when referenced as string220 @param priority221 Priority matters when multiple states are active. You can specify any222 number, but 1 - 99 is preferred (99 means high).223 */224 template <class T>225 T* InputManager::createInputState(const std::string& name, bool bAlwaysGetsInput, bool bTransparent, InputStatePriority priority)226 {227 T* state = new T;228 if (_configureInputState(state, name, bAlwaysGetsInput, bTransparent, priority))229 return state;230 else231 {232 delete state;233 return 0;234 }235 }236 168 } 237 169 -
code/branches/core4/src/core/input/InputPrereqs.h
r3251 r3274 33 33 */ 34 34 35 #ifndef _Input Interfaces_H__36 #define _Input Interfaces_H__35 #ifndef _InputPrereqs_H__ 36 #define _InputPrereqs_H__ 37 37 38 38 #include "core/CorePrereqs.h" … … 41 41 #include <ois/OISMouse.h> 42 42 #include <ois/OISJoyStick.h> 43 #include "util/Math.h"44 43 45 44 namespace orxonox 46 45 { 46 //----------------------------------------------------------------------- 47 // Code enumerations 48 //----------------------------------------------------------------------- 49 47 50 namespace KeyCode 48 51 { … … 299 302 } 300 303 304 301 305 namespace MouseButtonCode 302 306 { … … 346 350 }; 347 351 } 352 348 353 349 354 namespace JoyStickButtonCode … … 423 428 } 424 429 430 431 //----------------------------------------------------------------------- 432 // Miscellaneous 433 //----------------------------------------------------------------------- 434 435 namespace InputDeviceEnumerator 436 { 437 enum Value 438 { 439 Keyboard = 0, 440 Mouse = 1, 441 FirstJoyStick = 2 442 }; 443 } 444 445 namespace ButtonEvent 446 { 447 enum Value 448 { 449 Press, 450 Release, 451 Hold 452 }; 453 454 template <ButtonEvent::Value Event> 455 struct EnumToType { }; 456 typedef EnumToType<Press> TPress; 457 typedef EnumToType<Release> TRelease; 458 typedef EnumToType<Hold> THold; 459 } 460 461 425 462 namespace KeyboardModifier 426 463 { … … 432 469 }; 433 470 } 434 435 namespace InputDevice 436 { 437 enum Enum 438 { 439 Keyboard, 440 Mouse, 441 JoyStick0, 442 JoyStick1, 443 JoyStick2, 444 JoyStick3 445 // note: No problem if there are more joy sticks. This enum is just for convenience. 446 }; 447 } 448 449 struct _CoreExport Key 450 { 451 Key(const OIS::KeyEvent& evt) : key((KeyCode::ByEnum)evt.key), text(evt.text) { } 452 KeyCode::ByEnum key; 453 unsigned int text; 471 472 class _CoreExport KeyEvent 473 { 474 public: 475 KeyEvent(const OIS::KeyEvent& evt) 476 : key_(static_cast<KeyCode::ByEnum>(evt.key)) 477 , text_(evt.text) 478 , modifiers_(0) 479 { } 480 bool operator==(const KeyEvent& rhs) const 481 { return rhs.key_ == key_; } 482 bool operator!=(const KeyEvent& rhs) const 483 { return rhs.key_ != key_; } 484 void setModifiers(int modifiers) 485 { modifiers_ = modifiers; } 486 487 bool isModifierDown(KeyboardModifier::Enum modifier) const 488 { return static_cast<KeyboardModifier::Enum>(modifier & modifiers_); } 489 KeyCode::ByEnum getKeyCode() const 490 { return key_; } 491 unsigned int getText() const { return text_; } 492 493 private: 494 KeyCode::ByEnum key_; 495 unsigned int text_; 496 int modifiers_; 454 497 }; 455 498 456 class _CoreExport KeyEvent 457 { 458 public: 459 KeyEvent(KeyCode::ByEnum key, unsigned int text) : key(key), text(text) { } 460 KeyEvent(const OIS::KeyEvent& evt, unsigned int mod) 461 : key((KeyCode::ByEnum)evt.key), text(evt.text), modifiers(mod) { } 462 KeyEvent(const Key& key, unsigned int mod) : key(key.key), text(key.text), modifiers(mod) { } 463 bool isModifierDown(KeyboardModifier::Enum modifier) const 464 { return (KeyboardModifier::Enum)modifier&modifiers; } 465 466 const KeyCode::ByEnum key; 467 unsigned int text; 468 unsigned int modifiers; 499 500 //----------------------------------------------------------------------- 501 // Device type traits 502 //----------------------------------------------------------------------- 503 504 struct KeyboardTraits 505 { 506 typedef Keyboard DeviceClass; 507 typedef OIS::Keyboard OISDeviceClass; 508 typedef KeyEvent ButtonType; 509 typedef KeyEvent& ButtonTypeParam; 510 static const OIS::Type OISDeviceValue = OIS::OISKeyboard; 469 511 }; 470 512 471 472 class _CoreExport InputHandler 473 { 474 public: 475 virtual ~InputHandler() { } 476 virtual void updateInput(float dt) = 0; 513 struct MouseTraits 514 { 515 typedef Mouse DeviceClass; 516 typedef OIS::Mouse OISDeviceClass; 517 typedef MouseButtonCode::ByEnum ButtonType; 518 typedef MouseButtonCode::ByEnum ButtonTypeParam; 519 static const OIS::Type OISDeviceValue = OIS::OISMouse; 477 520 }; 478 521 479 /** 480 @brief 481 Interface class used for key input listeners. 482 */ 483 class _CoreExport KeyHandler : virtual public InputHandler 484 { 485 public: 486 virtual ~KeyHandler() { } 487 virtual void keyPressed (const KeyEvent& evt) = 0; 488 virtual void keyReleased(const KeyEvent& evt) = 0; 489 virtual void keyHeld (const KeyEvent& evt) = 0; 490 virtual void updateKey (float dt) = 0; 522 struct JoyStickTraits 523 { 524 typedef JoyStick DeviceClass; 525 typedef OIS::JoyStick OISDeviceClass; 526 typedef JoyStickButtonCode::ByEnum ButtonType; 527 typedef JoyStickButtonCode::ByEnum ButtonTypeParam; 528 static const OIS::Type OISDeviceValue = OIS::OISJoyStick; 491 529 }; 492 530 493 /** 494 @brief 495 Interface class used for mouse input listeners. 496 */ 497 class _CoreExport MouseHandler : virtual public InputHandler 498 { 499 public: 500 virtual ~MouseHandler() { } 501 virtual void mouseButtonPressed (MouseButtonCode::ByEnum id) = 0; 502 virtual void mouseButtonReleased(MouseButtonCode::ByEnum id) = 0; 503 virtual void mouseButtonHeld (MouseButtonCode::ByEnum id) = 0; 504 virtual void mouseMoved (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) = 0; 505 virtual void mouseScrolled (int abs, int rel) = 0; 506 virtual void updateMouse (float dt) = 0; 507 }; 508 509 510 /** 511 @brief 512 Interface class used for joy stick input listeners. 513 */ 514 class _CoreExport JoyStickHandler : virtual public InputHandler 515 { 516 public: 517 virtual ~JoyStickHandler() { } 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; 521 virtual void joyStickAxisMoved (unsigned int joyStickID, unsigned int axis, float value) = 0; 522 virtual void updateJoyStick (float dt, unsigned int joyStick) = 0; 523 }; 524 525 class _CoreExport EmptyHandler : public KeyHandler, public MouseHandler, public JoyStickHandler 526 { 527 friend class InputManager; 528 private: 529 EmptyHandler() { } 530 EmptyHandler(EmptyHandler&); 531 virtual ~EmptyHandler() { } 532 533 void updateInput(float dt) { } 534 void updateJoyStick(float dt, unsigned int joyStick) { } 535 void updateMouse(float dt) { } 536 void updateKey(float dt) { } 537 538 void keyPressed (const KeyEvent& evt) { } 539 void keyReleased(const KeyEvent& evt) { } 540 void keyHeld (const KeyEvent& evt) { } 541 542 void mouseButtonPressed (MouseButtonCode::ByEnum id) { } 543 void mouseButtonReleased(MouseButtonCode::ByEnum id) { } 544 void mouseButtonHeld (MouseButtonCode::ByEnum id) { } 545 void mouseMoved (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) { } 546 void mouseScrolled (int abs, int rel) { } 547 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) { } 551 void joyStickAxisMoved (unsigned int joyStickID, unsigned int axis, float value) { } 552 }; 553 531 // Note: Entries correspond to OIS::Type enum 532 namespace InputDeviceNames 533 { 534 const char* const values[] = { "", "Keyboard", "Mouse", "JoyStick" }; 535 } 554 536 } 555 537 556 #endif /* _Input Interfaces_H__ */538 #endif /* _InputPrereqs_H__ */ -
code/branches/core4/src/core/input/InputState.cc
r3272 r3274 27 27 */ 28 28 29 /** 30 @file 31 @brief 32 Implementation of the SimpleInputState class. 33 */ 34 35 #include "SimpleInputState.h" 36 #include "core/Executor.h" 29 #include "InputState.h" 30 #include "core/Functor.h" 37 31 38 32 namespace orxonox 39 33 { 40 SimpleInputState::SimpleInputState() 41 : keyHandler_(0) 42 , mouseHandler_(0) 34 InputState::InputState() 35 : priority_(0) 36 , bAlwaysGetsInput_(false) 37 , bTransparent_(false) 38 , bExpired_(true) 39 , handlers_(2) 43 40 , joyStickHandlerAll_(0) 41 , enterFunctor_(0) 42 , leaveFunctor_(0) 44 43 { 45 44 } 46 45 47 void SimpleInputState::numberOfJoySticksChanged(unsigned int n)46 bool InputState::isInputDeviceEnabled(unsigned int device) 48 47 { 49 unsigned int oldSize = joyStickHandler_.size(); 50 joyStickHandler_.resize(n); 48 if (device < handlers_.size()) 49 return handlers_[device] != NULL; 50 else 51 return false; 52 } 51 53 52 if (n > oldSize)53 54 // we have to add the handler in joyStickHandlerAll_ to the joyStickHandler_[>n]55 for (unsigned int i = oldSize; i < n; ++i)56 { 57 joyStickHandler_[i] = joyStickHandlerAll_;58 }59 } 60 update();54 void InputState::JoyStickQuantityChanged(unsigned int n) 55 { 56 unsigned int oldSize = handlers_.size(); 57 handlers_.resize(InputDeviceEnumerator::FirstJoyStick + n, NULL); 58 59 for (unsigned int i = oldSize; i < handlers_.size(); ++i) 60 handlers_[i] = joyStickHandlerAll_; 61 62 bExpired_ = true; 61 63 } 62 64 … … 71 73 True if added, false otherwise. 72 74 */ 73 bool SimpleInputState::setJoyStickHandler(JoyStickHandler* handler, unsigned int joyStickID)75 bool InputState::setJoyStickHandler(InputHandler* handler, unsigned int joyStick) 74 76 { 75 if (joyStickID >= joyStickHandler_.size()) 77 unsigned device = joyStick + firstJoyStickIndex_s; 78 if (joyStick >= handlers_.size() - device) 76 79 return false; 77 80 78 joyStickHandler_[joyStickID] = handler;79 update();81 handlers_[device] = handler; 82 bExpired_ = true; 80 83 return true; 81 84 } … … 89 92 True if added, false if handler already existed. 90 93 */ 91 bool SimpleInputState::setJoyStickHandler(JoyStickHandler* handler)94 bool InputState::setJoyStickHandler(InputHandler* handler) 92 95 { 93 if (handler == joyStickHandlerAll_)94 return false;95 96 96 joyStickHandlerAll_ = handler; 97 for (unsigned int i JoyStick = 0; iJoyStick < joyStickHandler_.size(); ++iJoyStick)98 setJoyStickHandler(handler, iJoyStick);99 update();97 for (unsigned int i = firstJoyStickIndex_s; i < handlers_.size(); ++i) 98 handlers_[i] = handler; 99 bExpired_ = true; 100 100 return true; 101 101 } … … 109 109 True if added, false if handler already existed. 110 110 */ 111 bool SimpleInputState::setHandler(InputHandler* handler)111 bool InputState::setHandler(InputHandler* handler) 112 112 { 113 setKeyHandler( dynamic_cast<KeyHandler*>(handler));114 setMouseHandler( dynamic_cast<MouseHandler*>(handler));115 return setJoyStickHandler( dynamic_cast<JoyStickHandler*>(handler));113 setKeyHandler(handler); 114 setMouseHandler(handler); 115 return setJoyStickHandler(handler); 116 116 } 117 117 118 void SimpleInputState::update()118 void InputState::entered() 119 119 { 120 // we can use a set to have a list of unique pointers (an object can implement all 3 handlers) 121 std::set<InputHandler*> tempSet; 122 if (keyHandler_) 123 tempSet.insert(keyHandler_); 124 if (mouseHandler_) 125 tempSet.insert(mouseHandler_); 126 for (unsigned int iJoyStick = 0; iJoyStick < joyStickHandler_.size(); iJoyStick++) 127 if (joyStickHandler_[iJoyStick]) 128 tempSet.insert(joyStickHandler_[iJoyStick]); 129 130 // copy the content of the map back to the actual vector 131 allHandlers_.clear(); 132 for (std::set<InputHandler*>::const_iterator itHandler = tempSet.begin(); 133 itHandler != tempSet.end(); itHandler++) 134 allHandlers_.push_back(*itHandler); 135 136 // update the deviceEnabled options 137 setInputDeviceEnabled(InputDevice::Keyboard, (keyHandler_ != 0)); 138 setInputDeviceEnabled(InputDevice::Mouse, (mouseHandler_ != 0)); 139 for (unsigned int i = 0; i < joyStickHandler_.size(); ++i) 140 setInputDeviceEnabled(2 + i, (joyStickHandler_[i] != 0)); 141 142 // inform InputManager that there might be changes in EMPTY_HANDLER situation 143 bHandlersChanged_ = true; 120 if (enterFunctor_) 121 (*enterFunctor_)(); 122 144 123 } 145 124 146 void SimpleInputState::onEnter()125 void InputState::left() 147 126 { 148 if (executorOnEnter_) 149 (*executorOnEnter_)(); 150 } 151 152 void SimpleInputState::onLeave() 153 { 154 if (executorOnLeave_) 155 (*executorOnLeave_)(); 127 if (leaveFunctor_) 128 (*leaveFunctor_)(); 156 129 } 157 130 } -
code/branches/core4/src/core/input/InputState.h
r3270 r3274 27 27 */ 28 28 29 /**30 @file31 @brief32 */33 34 29 #ifndef _InputState_H__ 35 30 #define _InputState_H__ 36 31 37 #include " core/CorePrereqs.h"32 #include "InputPrereqs.h" 38 33 34 #include <cassert> 39 35 #include <string> 40 36 #include <vector> 41 #include "InputInterfaces.h" 42 #include "JoyStickDeviceNumberListener.h" 37 38 #include "InputHandler.h" 39 #include "JoyStickQuantityListener.h" 43 40 44 41 namespace orxonox 45 42 { 46 class _CoreExport InputState : public JoyStick DeviceNumberListener43 class _CoreExport InputState : public JoyStickQuantityListener 47 44 { 48 45 friend class InputManager; 49 46 47 static const InputDeviceEnumerator::Value keyboardIndex_s = InputDeviceEnumerator::Keyboard; 48 static const InputDeviceEnumerator::Value mouseIndex_s = InputDeviceEnumerator::Mouse; 49 static const InputDeviceEnumerator::Value firstJoyStickIndex_s = InputDeviceEnumerator::FirstJoyStick; 50 50 51 public: 52 void setKeyHandler (InputHandler* handler) 53 { handlers_[keyboardIndex_s] = handler; bExpired_ = true; } 54 void setMouseHandler (InputHandler* handler) 55 { handlers_[mouseIndex_s] = handler; bExpired_ = true; } 56 bool setJoyStickHandler(InputHandler* handler, unsigned int joyStick); 57 bool setJoyStickHandler(InputHandler* handler); 58 bool setHandler (InputHandler* handler); 59 51 60 const std::string& getName() const { return name_; } 52 61 int getPriority() const { return priority_; } 53 62 54 bool isInputDeviceEnabled(unsigned int device) 55 { 56 if (device < bInputDeviceEnabled_.size()) 57 return bInputDeviceEnabled_[device]; 58 else 59 return false; 60 } 63 bool isInputDeviceEnabled(unsigned int device); 61 64 62 bool ha ndlersChanged() { return this->bHandlersChanged_; }63 void reset HandlersChanged() { bHandlersChanged_ = false; }65 bool hasExpired() { return this->bExpired_; } 66 void resetExpiration() { bExpired_ = false; } 64 67 65 v irtual void onEnter() = 0;66 v irtual void onLeave() = 0;68 void update(float dt, unsigned int device); 69 void update(float dt); 67 70 68 virtual void registerOnEnter(Executor* executor) { executorOnEnter_ = executor; } 69 virtual void unRegisterOnEnter() { executorOnEnter_ = 0; } 70 virtual void registerOnLeave(Executor* executor) { executorOnLeave_ = executor; } 71 virtual void unRegisterOnLeave() { executorOnLeave_ = 0; } 71 template <typename EventType, class Traits> 72 void buttonEvent(unsigned int device, const typename Traits::ButtonTypeParam button); 72 73 73 virtual void updateInput(float dt, unsigned int device) = 0; 74 virtual void updateInput(float dt) = 0; 74 void mouseMoved(IntVector2 abs, IntVector2 rel, IntVector2 clippingSize); 75 void mouseScrolled(int abs, int rel); 76 void joyStickAxisMoved(unsigned int device, unsigned int axis, float value); 75 77 76 virtual void keyPressed (const KeyEvent& evt) = 0; 77 virtual void keyReleased(const KeyEvent& evt) = 0; 78 virtual void keyHeld (const KeyEvent& evt) = 0; 79 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 virtual void mouseMoved (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) = 0; 84 virtual void mouseScrolled (int abs, int rel) = 0; 85 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 virtual void joyStickAxisMoved (unsigned int joyStickID, unsigned int axis, float value) = 0; 90 91 protected: 92 InputState() 93 : bHandlersChanged_(false) 94 , executorOnEnter_(0) 95 , executorOnLeave_(0) 96 , priority_(0) 97 , bAlwaysGetsInput_(false) 98 , bTransparent_(false) 99 { } 100 virtual ~InputState() { } 101 102 virtual void numberOfJoySticksChanged(unsigned int n) = 0; 103 void setInputDeviceEnabled(unsigned int device, bool bEnabled) 104 { 105 if (device < bInputDeviceEnabled_.size()) 106 bInputDeviceEnabled_[device] = bEnabled; 107 } 108 109 bool bHandlersChanged_; 110 Executor* executorOnEnter_; 111 Executor* executorOnLeave_; 78 // Functors 79 void entered(); 80 void left(); 81 void setEnterFunctor(Functor* functor) { this->enterFunctor_ = functor; } 82 void setLeaveFunctor(Functor* functor) { this->leaveFunctor_ = functor; } 112 83 113 84 private: 114 void JoyStickDeviceNumberChanged(unsigned int n) 85 InputState(); 86 ~InputState() { } 87 88 void JoyStickQuantityChanged(unsigned int n); 89 90 void setName(const std::string& name) { name_ = name; } 91 void setPriority(int priority) { priority_ = priority; } 92 93 std::string name_; 94 int priority_; 95 bool bAlwaysGetsInput_; 96 bool bTransparent_; 97 bool bExpired_; 98 std::vector<InputHandler*> handlers_; 99 InputHandler* joyStickHandlerAll_; 100 Functor* enterFunctor_; 101 Functor* leaveFunctor_; 102 }; 103 104 inline void InputState::update(float dt) 105 { 106 for (unsigned int i = 0; i < handlers_.size(); ++i) 107 if (handlers_[i] != NULL) 108 handlers_[i]->allDevicesUpdated(dt); 109 } 110 111 inline void InputState::update(float dt, unsigned int device) 112 { 113 switch (device) 115 114 { 116 bInputDeviceEnabled_.resize(n + 2); 117 numberOfJoySticksChanged(n); 115 case InputDeviceEnumerator::Keyboard: 116 if (handlers_[keyboardIndex_s] != NULL) 117 handlers_[keyboardIndex_s]->keyboardUpdated(dt); 118 break; 119 120 case InputDeviceEnumerator::Mouse: 121 if (handlers_[mouseIndex_s] != NULL) 122 handlers_[mouseIndex_s]->mouseUpdated(dt); 123 break; 124 125 default: // joy sticks 126 if (handlers_[device] != NULL) 127 handlers_[device]->joyStickUpdated(device - firstJoyStickIndex_s, dt); 128 break; 118 129 } 119 void setName(const std::string& name) { name_ = name; } 120 void setPriority(int priority) { priority_ = priority; } 130 } 121 131 122 std::string name_; 123 int priority_; 124 std::vector<bool> bInputDeviceEnabled_; 125 bool bAlwaysGetsInput_; 126 bool bTransparent_; 127 }; 132 template <typename EventType, class Traits> 133 inline void InputState::buttonEvent(unsigned int device, const typename Traits::ButtonTypeParam button) 134 { 135 assert(device < handlers_.size()); 136 if (handlers_[device] != NULL) 137 handlers_[device]->buttonEvent(device, button, EventType()); 138 } 139 140 inline void InputState::mouseMoved(IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) 141 { 142 if (handlers_[mouseIndex_s] != NULL) 143 handlers_[mouseIndex_s]->mouseMoved(abs, rel, clippingSize); 144 } 145 146 inline void InputState::mouseScrolled(int abs, int rel) 147 { 148 if (handlers_[mouseIndex_s] != NULL) 149 handlers_[mouseIndex_s]->mouseScrolled(abs, rel); 150 } 151 152 inline void InputState::joyStickAxisMoved(unsigned int device, unsigned int axis, float value) 153 { 154 assert(device < handlers_.size()); 155 if (handlers_[device] != NULL) 156 handlers_[device]->axisMoved(device - firstJoyStickIndex_s, axis, value); 157 } 128 158 } 129 159 -
code/branches/core4/src/core/input/JoyStick.cc
r3270 r3274 26 26 * 27 27 */ 28 29 /**30 @file31 @brief32 Implementation of the JoyStick wrapper class.33 */34 28 35 29 #include "JoyStick.h" … … 54 48 void loadCalibration(std::vector<int>& list, const std::string& sectionName, const std::string& valueName, size_t size, int defaultValue); 55 49 56 JoyStick::JoyStick(const std::vector<InputState*>& states, unsigned int id) 57 : id_(id) 58 , bCalibrating_(false) 59 , inputStates_(states) 50 JoyStick::JoyStick(unsigned int id) 51 : super(id) 60 52 { 61 53 RegisterRootObject(JoyStick); 62 54 this->setConfigValues(); 63 64 OIS::InputManager* system = InputManager::getInstance().getInputSystem(); 65 oisJoyStick_ = static_cast<OIS::JoyStick*>(system->createInputObject(OIS::OISJoyStick, true)); 66 oisJoyStick_->setEventCallback(this); 55 // Initialise POV and Slider states 56 this->clearBuffersImpl(); 67 57 68 58 idString_ = "JoyStick_"; 69 std::string name = ois JoyStick_->vendor();59 std::string name = oisDevice_->vendor(); 70 60 replaceCharacters(name, ' ', '_'); 71 61 idString_ += name + "_"; 72 idString_ += multi_cast<std::string>(ois JoyStick_->getNumberOfComponents(OIS::OIS_Button)) + "_";73 idString_ += multi_cast<std::string>(ois JoyStick_->getNumberOfComponents(OIS::OIS_Axis)) + "_";74 idString_ += multi_cast<std::string>(ois JoyStick_->getNumberOfComponents(OIS::OIS_Slider)) + "_";75 idString_ += multi_cast<std::string>(ois JoyStick_->getNumberOfComponents(OIS::OIS_POV));76 //idString_ += multi_cast<std::string>(ois JoyStick_->getNumberOfComponents(OIS::OIS_Vector3));62 idString_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Button)) + "_"; 63 idString_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Axis)) + "_"; 64 idString_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Slider)) + "_"; 65 idString_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_POV)); 66 //idString_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Vector3)); 77 67 78 68 if (InputManager::getInstance().checkJoyStickID(idString_) == false) 79 69 { 80 70 // Make the ID unique for this execution time. 81 idString_ += "_" + multi_cast<std::string>( id_);71 idString_ += "_" + multi_cast<std::string>(this->getDeviceID()); 82 72 } 83 73 … … 85 75 86 76 // Load calibration 87 size_t axes = sliderAxes_s + static_cast<size_t>(ois JoyStick_->getNumberOfComponents(OIS::OIS_Axis));77 size_t axes = sliderAxes_s + static_cast<size_t>(oisDevice_->getNumberOfComponents(OIS::OIS_Axis)); 88 78 loadCalibration(configMinValues_, idString_, "MinValue", axes, -32768); 89 79 loadCalibration(configMaxValues_, idString_, "MaxValue", axes, 32768); … … 92 82 } 93 83 94 JoyStick::~JoyStick() 95 { 96 try 97 { 98 OIS::InputManager* system = InputManager::getInstance().getInputSystem(); 99 system->destroyInputObject(oisJoyStick_); 100 } 101 catch (...) 102 { 103 COUT(1) << "Joy stick destruction failed! Potential resource leak!" << std::endl; 104 } 105 } 106 107 /** 108 @brief 109 Callback for the joy stick calibration config file. @see setConfigValues. 110 */ 84 //!< Callback for the joy stick calibration config file. 111 85 void JoyStick::calibrationFileCallback() 112 86 { … … 114 88 } 115 89 116 /**117 @brief118 Sets the configurable values.119 */120 90 void JoyStick::setConfigValues() 121 91 { … … 140 110 // fill the rest with default values 141 111 for (unsigned int i = configValueVectorSize; i < size; ++i) 142 {143 112 list[i] = defaultValue; 144 } 145 } 146 147 void JoyStick::startCalibration() 148 { 149 bCalibrating_ = true; 150 113 } 114 115 //! Called by InputDevice when calibration mode has started 116 void JoyStick::calibrationStarted() 117 { 151 118 // Set initial values 152 119 BOOST_FOREACH(int& minVal, configMinValues_) … … 158 125 } 159 126 160 void JoyStick::stopCalibration() 127 //! Called by InputDevice when calibration mode has stopped 128 void JoyStick::calibrationStopped() 161 129 { 162 130 // Get the middle positions now … … 164 132 for (unsigned int i = 0; i < sliderAxes_s/2; ++i) 165 133 { 166 configZeroValues_[iAxis++] = ois JoyStick_->getJoyStickState().mSliders[i].abX;167 configZeroValues_[iAxis++] = ois JoyStick_->getJoyStickState().mSliders[i].abY;168 } 169 // Note: joyStick MiddleValues_[iJoyStick] was already correctly resised in loadCalibration()170 assert(ois JoyStick_->getJoyStickState().mAxes.size() == configZeroValues_.size() - sliderAxes_s);134 configZeroValues_[iAxis++] = oisDevice_->getJoyStickState().mSliders[i].abX; 135 configZeroValues_[iAxis++] = oisDevice_->getJoyStickState().mSliders[i].abY; 136 } 137 // Note: joyStickZeroValues_[iJoyStick] was already correctly resised in loadCalibration() 138 assert(oisDevice_->getJoyStickState().mAxes.size() == configZeroValues_.size() - sliderAxes_s); 171 139 for (unsigned int i = 0; i < configZeroValues_.size() - sliderAxes_s; ++i) 172 configZeroValues_[iAxis++] = ois JoyStick_->getJoyStickState().mAxes[i].abs;140 configZeroValues_[iAxis++] = oisDevice_->getJoyStickState().mAxes[i].abs; 173 141 174 142 for (unsigned int i = 0; i < configMinValues_.size(); ++i) … … 192 160 193 161 this->evaluateCalibration(); 194 195 bCalibrating_ = false; 196 } 197 162 } 163 164 //! Evaluates the accumulated values during calibration 198 165 void JoyStick::evaluateCalibration() 199 166 { … … 206 173 } 207 174 208 void JoyStick::clearBuffer()209 {210 pressedButtons_.clear();175 // TODO: What do we really need to reset here? 176 void JoyStick::clearBuffersImpl() 177 { 211 178 for (int j = 0; j < 4; ++j) 212 179 { … … 217 184 } 218 185 219 220 // ###### Events ###### 221 222 void JoyStick::capture() 223 { 224 oisJoyStick_->capture(); 225 226 // call all the handlers for the held joy stick button events 227 for (unsigned int iButton = 0; iButton < pressedButtons_.size(); iButton++) 228 { 229 BOOST_FOREACH(InputState* state, inputStates_) 230 state->joyStickButtonHeld(id_, pressedButtons_[iButton]); 231 } 232 } 233 234 bool JoyStick::buttonPressed(const OIS::JoyStickEvent &arg, int button) 235 { 236 // check whether the button already is in the list (can happen when focus was lost) 237 unsigned int iButton = 0; 238 while (iButton < pressedButtons_.size() && pressedButtons_[iButton] != button) 239 iButton++; 240 if (iButton == pressedButtons_.size()) 241 pressedButtons_.push_back(static_cast<JoyStickButtonCode::ByEnum>(button)); 242 243 BOOST_FOREACH(InputState* state, inputStates_) 244 state->joyStickButtonPressed(id_, static_cast<JoyStickButtonCode::ByEnum>(button)); 245 246 return true; 247 } 248 249 bool JoyStick::buttonReleased(const OIS::JoyStickEvent &arg, int button) 250 { 251 // remove the button from the pressedButtons_ list 252 for (unsigned int iButton = 0; iButton < pressedButtons_.size(); iButton++) 253 { 254 if (static_cast<int>(pressedButtons_[iButton]) == button) 255 { 256 pressedButtons_.erase(pressedButtons_.begin() + iButton); 257 break; 258 } 259 } 260 261 BOOST_FOREACH(InputState* state, inputStates_) 262 state->joyStickButtonPressed(id_, static_cast<JoyStickButtonCode::ByEnum>(button)); 263 264 return true; 265 } 266 267 /** 268 @brief 269 Calls the states for a particular axis with our enumeration. 270 Used by OIS sliders and OIS axes. 271 */ 186 //! Generic method to forward axis events 272 187 void JoyStick::fireAxis(int axis, int value) 273 188 { 274 if ( bCalibrating_)189 if (this->isCalibrating()) 275 190 { 276 191 if (value < configMinValues_[axis]) … … 288 203 289 204 BOOST_FOREACH(InputState* state, inputStates_) 290 state->joyStickAxisMoved(id_, axis, fValue); 291 } 292 } 293 205 state->joyStickAxisMoved(this->getDeviceID(), axis, fValue); 206 } 207 } 208 209 //! OIS joy stick axis event handler 294 210 bool JoyStick::axisMoved(const OIS::JoyStickEvent &arg, int axis) 295 211 { … … 300 216 } 301 217 218 //! A Slider always has an X and an Y direction! 302 219 bool JoyStick::sliderMoved(const OIS::JoyStickEvent &arg, int id) 303 220 { … … 310 227 } 311 228 229 //! A POV is the big button that can point in all directions (but only in one at once) 312 230 bool JoyStick::povMoved(const OIS::JoyStickEvent &arg, int id) 313 231 { -
code/branches/core4/src/core/input/JoyStick.h
r3270 r3274 27 27 */ 28 28 29 /** 30 @file 31 @brief 32 */ 29 #ifndef _Core_JoyStick_H__ 30 #define _Core_JoyStick_H__ 33 31 34 #ifndef _JoyStick_H__ 35 #define _JoyStick_H__ 36 37 #include "core/CorePrereqs.h" 32 #include "InputPrereqs.h" 38 33 39 34 #include <string> 40 35 #include <vector> 41 #include "Input Interfaces.h"36 #include "InputDevice.h" 42 37 43 38 namespace orxonox 44 39 { 45 class _CoreExport JoyStick : public OrxonoxClass, public OIS::JoyStickListener 40 /** 41 @brief 42 Wraps around an OIS::JoyStick and forwards the input events to 43 a list of input states. 44 45 The class also supports joy stick calibration and stores the values 46 in an ini-file. 47 */ 48 class _CoreExport JoyStick 49 : public OrxonoxClass 50 , public InputDeviceTemplated<JoyStickTraits> 51 , public OIS::JoyStickListener 46 52 { 47 private: 48 struct JoyStickCalibration 49 { 50 }; 53 friend class InputDeviceTemplated<JoyStickTraits>; 54 //! Super class alias 55 typedef InputDeviceTemplated<JoyStickTraits> super; 51 56 52 57 public: 53 JoyStick(const std::vector<InputState*>& states, unsigned int id);54 ~JoyStick();55 58 //! Assigns a generated ID string and loads the calibration (if present) 59 JoyStick(unsigned int id); 60 ~JoyStick() { } 56 61 void setConfigValues(); 57 62 58 OIS::JoyStick* getOISJoyStick() { return this->oisJoyStick_; }63 //! Returns the generated (from the number of knobs and the device name) ID string 59 64 const std::string& getIDString() const { return this->idString_; } 60 65 61 void startCalibration(); 62 void stopCalibration(); 66 private: 67 void calibrationStarted(); 68 void calibrationStopped(); 69 void evaluateCalibration(); 63 70 64 void capture(); 65 void clearBuffer(); 66 67 private: 71 void clearBuffersImpl(); 68 72 void calibrationFileCallback(); 69 void evaluateCalibration();70 73 void fireAxis(int axis, int value); 71 74 72 bool buttonPressed (const OIS::JoyStickEvent &arg, int button); 73 bool buttonReleased(const OIS::JoyStickEvent &arg, int button); 75 //! OIS event handler 76 bool buttonPressed (const OIS::JoyStickEvent &arg, int button) 77 { 78 super::buttonPressed(static_cast<JoyStickButtonCode::ByEnum>(button)); 79 return true; 80 } 81 82 //! OIS event handler 83 bool buttonReleased(const OIS::JoyStickEvent &arg, int button) 84 { 85 super::buttonReleased(static_cast<JoyStickButtonCode::ByEnum>(button)); 86 return true; 87 } 88 74 89 bool axisMoved (const OIS::JoyStickEvent &arg, int axis); 75 90 bool sliderMoved (const OIS::JoyStickEvent &arg, int id); 76 91 bool povMoved (const OIS::JoyStickEvent &arg, int id); 77 // don't remove that! Or else add OIS as dependency library to orxonox (it actually is..)92 //!< OIS event handler (don't remove that because of OIS version issues!) 78 93 bool vector3Moved (const OIS::JoyStickEvent &arg, int id) { return true; } 79 94 80 static const unsigned int sliderAxes_s = 8; 81 82 OIS::JoyStick* oisJoyStick_; 83 const unsigned int id_; 84 std::string idString_; 95 std::string idString_; //!< ID string generated by the number of knobs and the device name 96 int povStates_[4]; //!< Internal states for the POVs 97 int sliderStates_[4][2]; //!< Internal states for the Sliders (each slider has X and Y!) 85 98 86 99 // calibration 87 bool bCalibrating_; 88 int zeroValues_[24]; 89 float positiveCoeffs_[24]; 90 float negativeCoeffs_[24]; 100 int zeroValues_[24]; //!< Axes values when the knob is in the middle 101 float positiveCoeffs_[24]; //!< Maps the negative part of an axis to a 0.0 to 1.0 floating range 102 float negativeCoeffs_[24]; //!< Maps the positive part of an axis to a 0.0 to 1.0 floating range 91 103 92 std::vector<int> configMinValues_; 93 std::vector<int> configMaxValues_; 94 std::vector<int> configZeroValues_; 95 96 int povStates_[4]; 97 int sliderStates_[4][2]; 98 std::vector<JoyStickButtonCode::ByEnum> pressedButtons_; 99 100 // InputState handling 101 const std::vector<InputState*>& inputStates_; 104 std::vector<int> configZeroValues_; //!< Config file stored axis values when the knob is in the middle 105 std::vector<int> configMinValues_; //!< Config file stored minimum axis values 106 std::vector<int> configMaxValues_; //!< Config file stored maximum axis values 102 107 103 108 // ConfigValues 104 std::string calibrationFilename_; //!< Joy stick calibration ini filename 109 std::string calibrationFilename_; //!< Joy stick calibration ini filename 110 111 //!< Maximum number of slider axes 112 static const unsigned int sliderAxes_s = 8; 105 113 }; 106 114 } 107 115 108 #endif /* _ JoyStick_H__ */116 #endif /* _Core_JoyStick_H__ */ -
code/branches/core4/src/core/input/JoyStickQuantityListener.cc
r3273 r3274 30 30 @file 31 31 @brief 32 Implementation of the JoyStick DeviceNumberListener class.32 Implementation of the JoyStickQuantityListener class. 33 33 */ 34 34 35 #include "JoyStick DeviceNumberListener.h"35 #include "JoyStickQuantityListener.h" 36 36 #include "core/CoreIncludes.h" 37 37 38 38 namespace orxonox 39 39 { 40 JoyStick DeviceNumberListener::JoyStickDeviceNumberListener()40 JoyStickQuantityListener::JoyStickQuantityListener() 41 41 { 42 RegisterObject(JoyStick DeviceNumberListener);42 RegisterObject(JoyStickQuantityListener); 43 43 } 44 44 } -
code/branches/core4/src/core/input/JoyStickQuantityListener.h
r3273 r3274 32 32 */ 33 33 34 #ifndef _JoyStick DeviceNumberListener_H__35 #define _JoyStick DeviceNumberListener_H__34 #ifndef _JoyStickQuantityListener_H__ 35 #define _JoyStickQuantityListener_H__ 36 36 37 #include " core/CorePrereqs.h"37 #include "InputPrereqs.h" 38 38 #include "core/OrxonoxClass.h" 39 39 40 40 namespace orxonox 41 41 { 42 class _CoreExport JoyStick DeviceNumberListener : virtual public OrxonoxClass42 class _CoreExport JoyStickQuantityListener : virtual public OrxonoxClass 43 43 { 44 44 public: 45 JoyStick DeviceNumberListener();46 virtual ~JoyStick DeviceNumberListener() { }45 JoyStickQuantityListener(); 46 virtual ~JoyStickQuantityListener() { } 47 47 48 virtual void JoyStick DeviceNumberChanged(unsigned int value) = 0;48 virtual void JoyStickQuantityChanged(unsigned int value) = 0; 49 49 }; 50 50 } 51 51 52 #endif /* _JoyStick DeviceNumberListener_H__ */52 #endif /* _JoyStickQuantityListener_H__ */ -
code/branches/core4/src/core/input/KeyBinder.cc
r3269 r3274 100 100 101 101 // initialise joy sticks separatly to allow for reloading 102 numberOfJoySticks_ = InputManager::getInstance(). numberOfJoySticks();102 numberOfJoySticks_ = InputManager::getInstance().getJoyStickQuantity(); 103 103 initialiseJoyStickBindings(); 104 104 … … 152 152 } 153 153 154 void KeyBinder::JoyStick DeviceNumberChanged(unsigned int value)154 void KeyBinder::JoyStickQuantityChanged(unsigned int value) 155 155 { 156 156 unsigned int oldValue = numberOfJoySticks_; … … 311 311 } 312 312 313 void KeyBinder:: updateMouse(float dt)313 void KeyBinder::mouseUpdated(float dt) 314 314 { 315 315 if (bDeriveMouseInput_) … … 364 364 } 365 365 366 void KeyBinder:: updateJoyStick(float dt, unsigned int joyStick)366 void KeyBinder::joyStickUpdated(unsigned int joyStick, float dt) 367 367 { 368 368 for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++) … … 480 480 } 481 481 482 void KeyBinder::joyStickAxisMoved(unsigned int joyStickID, unsigned int axis, float value) 483 { 484 int i = axis * 2; 482 void KeyBinder::axisMoved(unsigned int device, unsigned int axisID, float value) 483 { 484 int i = axisID * 2; 485 JoyStickAxisVector& axis = joyStickAxes_[device]; 485 486 if (value < 0) 486 487 { 487 joyStickAxes_[joyStickID][i].absVal_ = -value;488 joyStickAxes_[joyStickID][i].relVal_ = -value;489 joyStickAxes_[joyStickID][i].hasChanged_ = true;490 if ( joyStickAxes_[joyStickID][i + 1].absVal_ > 0.0f)491 { 492 joyStickAxes_[joyStickID][i + 1].absVal_ = -0.0f;493 joyStickAxes_[joyStickID][i + 1].relVal_ = -0.0f;494 joyStickAxes_[joyStickID][i + 1].hasChanged_ = true;488 axis[i].absVal_ = -value; 489 axis[i].relVal_ = -value; 490 axis[i].hasChanged_ = true; 491 if (axis[i + 1].absVal_ > 0.0f) 492 { 493 axis[i + 1].absVal_ = -0.0f; 494 axis[i + 1].relVal_ = -0.0f; 495 axis[i + 1].hasChanged_ = true; 495 496 } 496 497 } 497 498 else 498 499 { 499 joyStickAxes_[joyStickID][i + 1].absVal_ = value;500 joyStickAxes_[joyStickID][i + 1].relVal_ = value;501 joyStickAxes_[joyStickID][i + 1].hasChanged_ = true;502 if ( joyStickAxes_[joyStickID][i].absVal_ > 0.0f)503 { 504 joyStickAxes_[joyStickID][i].absVal_ = -0.0f;505 joyStickAxes_[joyStickID][i].relVal_ = -0.0f;506 joyStickAxes_[joyStickID][i].hasChanged_ = true;500 axis[i + 1].absVal_ = value; 501 axis[i + 1].relVal_ = value; 502 axis[i + 1].hasChanged_ = true; 503 if (axis[i].absVal_ > 0.0f) 504 { 505 axis[i].absVal_ = -0.0f; 506 axis[i].relVal_ = -0.0f; 507 axis[i].hasChanged_ = true; 507 508 } 508 509 } -
code/branches/core4/src/core/input/KeyBinder.h
r3196 r3274 36 36 #define _KeyBinder_H__ 37 37 38 #include " core/CorePrereqs.h"38 #include "InputPrereqs.h" 39 39 40 40 #include <cassert> … … 42 42 #include <vector> 43 43 44 #include "Input Interfaces.h"44 #include "InputHandler.h" 45 45 #include "Button.h" 46 46 #include "HalfAxis.h" 47 47 #include "InputCommands.h" 48 #include "JoyStick DeviceNumberListener.h"48 #include "JoyStickQuantityListener.h" 49 49 50 50 namespace orxonox … … 55 55 Manages the key bindings. 56 56 */ 57 class _CoreExport KeyBinder : public KeyHandler, public MouseHandler, public JoyStickHandler, 58 public JoyStickDeviceNumberListener 57 class _CoreExport KeyBinder : public InputHandler, public JoyStickQuantityListener 59 58 { 60 59 public: … … 69 68 70 69 protected: // functions 71 void updateInput(float dt); 72 void updateKey(float dt) { } 73 void updateMouse(float dt); 74 void updateJoyStick(float dt, unsigned int joyStick); 70 void allDevicesUpdated(float dt); 71 void mouseUpdated(float dt); 72 void joyStickUpdated(unsigned int joyStick, float dt); 75 73 // internal 76 74 void tickHalfAxis(HalfAxis& halfAxis); 77 75 78 76 void buttonThresholdChanged(); 79 // from JoyStick DeviceNumberListener interface80 virtual void JoyStick DeviceNumberChanged(unsigned int value);77 // from JoyStickQuantityListener interface 78 virtual void JoyStickQuantityChanged(unsigned int value); 81 79 void initialiseJoyStickBindings(); 82 80 void compilePointerLists(); 83 81 84 void keyPressed (const KeyEvent& evt);85 void keyReleased(const KeyEvent& evt);86 void keyHeld (const KeyEvent& evt);87 88 void mouseButtonPressed (MouseButtonCode::ByEnum id);89 void mouseButtonReleased(MouseButtonCode::ByEnum id);90 void mouseButtonHeld (MouseButtonCode::ByEnum id);91 void mouseMoved 92 void mouseScrolled 93 94 void joyStickButtonPressed (unsigned int joyStickID, JoyStickButtonCode::ByEnum id);95 void joyStickButtonReleased(unsigned int joyStickID, JoyStickButtonCode::ByEnum id);96 void joyStickButtonHeld (unsigned int joyStickID, JoyStickButtonCode::ByEnum id);97 void joyStickAxisMoved (unsigned int joyStickID, unsigned int axis, float value);82 void buttonPressed (const KeyEvent& evt); 83 void buttonReleased(const KeyEvent& evt); 84 void buttonHeld (const KeyEvent& evt); 85 86 void buttonPressed (MouseButtonCode::ByEnum button); 87 void buttonReleased(MouseButtonCode::ByEnum button); 88 void buttonHeld (MouseButtonCode::ByEnum button); 89 void mouseMoved (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize); 90 void mouseScrolled (int abs, int rel); 91 92 void buttonPressed (unsigned int device, JoyStickButtonCode::ByEnum button); 93 void buttonReleased(unsigned int device, JoyStickButtonCode::ByEnum button); 94 void buttonHeld (unsigned int device, JoyStickButtonCode::ByEnum button); 95 void axisMoved (unsigned int device, unsigned int axis, float value); 98 96 99 97 protected: // variables … … 172 170 }; 173 171 174 inline void KeyBinder:: keyPressed (const KeyEvent& evt)175 { assert(!keys_[evt. key].name_.empty()); keys_[evt.key].execute(KeybindMode::OnPress); }176 177 inline void KeyBinder:: keyReleased(const KeyEvent& evt)178 { assert(!keys_[evt. key].name_.empty()); keys_[evt.key].execute(KeybindMode::OnRelease); }179 180 inline void KeyBinder:: keyHeld (const KeyEvent& evt)181 { assert(!keys_[evt. key].name_.empty()); keys_[evt.key].execute(KeybindMode::OnHold); }182 183 184 inline void KeyBinder:: mouseButtonPressed (MouseButtonCode::ByEnum id)185 { mouseButtons_[ id].execute(KeybindMode::OnPress); }186 187 inline void KeyBinder:: mouseButtonReleased(MouseButtonCode::ByEnum id)188 { mouseButtons_[ id].execute(KeybindMode::OnRelease); }189 190 inline void KeyBinder:: mouseButtonHeld (MouseButtonCode::ByEnum id)191 { mouseButtons_[ id].execute(KeybindMode::OnHold); }192 193 194 inline void KeyBinder:: joyStickButtonPressed (unsigned int joyStickID, JoyStickButtonCode::ByEnum id)195 { joyStickButtons_[ joyStickID][id].execute(KeybindMode::OnPress); }196 197 inline void KeyBinder:: joyStickButtonReleased(unsigned int joyStickID, JoyStickButtonCode::ByEnum id)198 { joyStickButtons_[ joyStickID][id].execute(KeybindMode::OnRelease); }199 200 inline void KeyBinder:: joyStickButtonHeld (unsigned int joyStickID, JoyStickButtonCode::ByEnum id)201 { joyStickButtons_[ joyStickID][id].execute(KeybindMode::OnHold); }202 203 inline void KeyBinder:: updateInput(float dt)172 inline void KeyBinder::buttonPressed (const KeyEvent& evt) 173 { assert(!keys_[evt.getKeyCode()].name_.empty()); keys_[evt.getKeyCode()].execute(KeybindMode::OnPress); } 174 175 inline void KeyBinder::buttonReleased(const KeyEvent& evt) 176 { assert(!keys_[evt.getKeyCode()].name_.empty()); keys_[evt.getKeyCode()].execute(KeybindMode::OnRelease); } 177 178 inline void KeyBinder::buttonHeld (const KeyEvent& evt) 179 { assert(!keys_[evt.getKeyCode()].name_.empty()); keys_[evt.getKeyCode()].execute(KeybindMode::OnHold); } 180 181 182 inline void KeyBinder::buttonPressed (MouseButtonCode::ByEnum button) 183 { mouseButtons_[button].execute(KeybindMode::OnPress); } 184 185 inline void KeyBinder::buttonReleased(MouseButtonCode::ByEnum button) 186 { mouseButtons_[button].execute(KeybindMode::OnRelease); } 187 188 inline void KeyBinder::buttonHeld (MouseButtonCode::ByEnum button) 189 { mouseButtons_[button].execute(KeybindMode::OnHold); } 190 191 192 inline void KeyBinder::buttonPressed (unsigned int device, JoyStickButtonCode::ByEnum button) 193 { joyStickButtons_[device][button].execute(KeybindMode::OnPress); } 194 195 inline void KeyBinder::buttonReleased(unsigned int device, JoyStickButtonCode::ByEnum button) 196 { joyStickButtons_[device][button].execute(KeybindMode::OnRelease); } 197 198 inline void KeyBinder::buttonHeld (unsigned int device, JoyStickButtonCode::ByEnum button) 199 { joyStickButtons_[device][button].execute(KeybindMode::OnHold); } 200 201 inline void KeyBinder::allDevicesUpdated(float dt) 204 202 { 205 203 // execute all buffered bindings (additional parameter) -
code/branches/core4/src/core/input/KeyDetector.cc
r3196 r3274 73 73 } 74 74 75 void KeyDetector::JoyStick DeviceNumberChanged(unsigned int value)75 void KeyDetector::JoyStickQuantityChanged(unsigned int value) 76 76 { 77 KeyBinder::JoyStick DeviceNumberChanged(value);77 KeyBinder::JoyStickQuantityChanged(value); 78 78 setCallbackCommand(callbackCommand_); 79 79 } -
code/branches/core4/src/core/input/KeyDetector.h
r3196 r3274 36 36 #define _KeyDetector_H__ 37 37 38 #include " core/CorePrereqs.h"38 #include "InputPrereqs.h" 39 39 40 40 #include <string> … … 49 49 ~KeyDetector(); 50 50 void setCallbackCommand(const std::string& command); 51 void JoyStick DeviceNumberChanged(unsigned int value);51 void JoyStickQuantityChanged(unsigned int value); 52 52 53 53 private:
Note: See TracChangeset
for help on using the changeset viewer.