Changeset 1637 for code/branches/input/src/core/input/KeyBinder.cc
- Timestamp:
- Jul 20, 2008, 6:49:24 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/input/src/core/input/KeyBinder.cc
r1630 r1637 333 333 } 334 334 335 void KeyBinder::tickInput(float dt, const HandlerState& state) 336 { 337 // we have to process all the analog input since there is e.g. no 'mouseDoesntMove' event. 338 unsigned int iBegin = 8; 339 unsigned int iEnd = 8; 340 if (state.joyStick) 341 iEnd = nHalfAxes_s; 342 if (state.mouse) 343 iBegin = 0; 344 for (unsigned int i = iBegin; i < iEnd; i++) 345 { 346 if (halfAxes_[i].hasChanged_) 347 { 348 if (!halfAxes_[i].wasDown_ && halfAxes_[i].absVal_ > halfAxes_[i].buttonThreshold_) 349 { 350 halfAxes_[i].wasDown_ = true; 351 if (halfAxes_[i].nCommands_[KeybindMode::OnPress]) 352 halfAxes_[i].execute(KeybindMode::OnPress); 353 } 354 else if (halfAxes_[i].wasDown_ && halfAxes_[i].absVal_ < halfAxes_[i].buttonThreshold_) 355 { 356 halfAxes_[i].wasDown_ = false; 357 if (halfAxes_[i].nCommands_[KeybindMode::OnRelease]) 358 halfAxes_[i].execute(KeybindMode::OnRelease); 359 } 360 halfAxes_[i].hasChanged_ = false; 361 } 362 363 if (halfAxes_[i].wasDown_) 364 { 365 if (halfAxes_[i].nCommands_[KeybindMode::OnHold]) 366 halfAxes_[i].execute(KeybindMode::OnHold); 367 } 368 369 // these are the actually useful axis bindings for analog input AND output 370 if (halfAxes_[i].relVal_ > analogThreshold_ || halfAxes_[i].absVal_ > analogThreshold_) 371 { 372 //COUT(3) << halfAxes_[i].name_ << "\t" << halfAxes_[i].absVal_ << std::endl; 373 halfAxes_[i].execute(); 374 } 375 } 376 377 if (bDeriveMouseInput_ && state.mouse) 335 void KeyBinder::tickMouse(float dt) 336 { 337 tickDevices(0, 8); 338 339 if (bDeriveMouseInput_) 378 340 { 379 341 if (deriveTime_ > derivePeriod_) … … 410 372 deriveTime_ += dt; 411 373 } 412 413 // execute all buffered bindings (addional parameter) 374 } 375 376 void KeyBinder::tickJoyStick(float dt, int device) 377 { 378 tickDevices(8, nHalfAxes_s); 379 } 380 381 void KeyBinder::tickInput(float dt) 382 { 383 // execute all buffered bindings (additional parameter) 414 384 for (unsigned int i = 0; i < paramCommandBuffer_.size(); i++) 415 385 paramCommandBuffer_[i]->execute(); 416 386 417 387 // always reset the relative movement of the mouse 418 if (state.mouse) 419 for (unsigned int i = 0; i < 8; i++) 420 halfAxes_[i].relVal_ = 0.0f; 388 for (unsigned int i = 0; i < 8; i++) 389 halfAxes_[i].relVal_ = 0.0f; 390 } 391 392 void KeyBinder::tickDevices(unsigned int begin, unsigned int end) 393 { 394 for (unsigned int i = begin; i < end; i++) 395 { 396 // button mode 397 // TODO: optimize out all the half axes that don't act as a button at the moment 398 if (halfAxes_[i].hasChanged_) 399 { 400 if (!halfAxes_[i].wasDown_ && halfAxes_[i].absVal_ > halfAxes_[i].buttonThreshold_) 401 { 402 halfAxes_[i].wasDown_ = true; 403 if (halfAxes_[i].nCommands_[KeybindMode::OnPress]) 404 halfAxes_[i].execute(KeybindMode::OnPress); 405 } 406 else if (halfAxes_[i].wasDown_ && halfAxes_[i].absVal_ < halfAxes_[i].buttonThreshold_) 407 { 408 halfAxes_[i].wasDown_ = false; 409 if (halfAxes_[i].nCommands_[KeybindMode::OnRelease]) 410 halfAxes_[i].execute(KeybindMode::OnRelease); 411 } 412 halfAxes_[i].hasChanged_ = false; 413 } 414 415 if (halfAxes_[i].wasDown_) 416 { 417 if (halfAxes_[i].nCommands_[KeybindMode::OnHold]) 418 halfAxes_[i].execute(KeybindMode::OnHold); 419 } 420 421 // these are the actually useful axis bindings for analog input 422 if (halfAxes_[i].relVal_ > analogThreshold_ || halfAxes_[i].absVal_ > analogThreshold_) 423 { 424 //COUT(3) << halfAxes_[i].name_ << "\t" << halfAxes_[i].absVal_ << std::endl; 425 halfAxes_[i].execute(); 426 } 427 } 421 428 } 422 429 … … 441 448 442 449 443 void KeyBinder::joyStickButtonPressed ( int joyStickID,int button)450 void KeyBinder::joyStickButtonPressed (unsigned int joyStickID, unsigned int button) 444 451 { joyStickButtons_[button].execute(KeybindMode::OnPress); } 445 452 446 void KeyBinder::joyStickButtonReleased( int joyStickID,int button)453 void KeyBinder::joyStickButtonReleased(unsigned int joyStickID, unsigned int button) 447 454 { joyStickButtons_[button].execute(KeybindMode::OnRelease); } 448 455 449 void KeyBinder::joyStickButtonHeld ( int joyStickID,int button)456 void KeyBinder::joyStickButtonHeld (unsigned int joyStickID, unsigned int button) 450 457 { joyStickButtons_[button].execute(KeybindMode::OnHold); } 451 458 … … 525 532 } 526 533 527 void KeyBinder::joyStickAxisMoved(int joyStickID, int axis, float value) 528 { 529 // TODO: Use proper calibration values instead of generally 16-bit integer 534 void KeyBinder::joyStickAxisMoved(unsigned int joyStickID, unsigned int axis, float value) 535 { 530 536 int i = 8 + axis * 2; 531 537 if (value >= 0)
Note: See TracChangeset
for help on using the changeset viewer.