MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / rumble

Method rumble

Engine/source/platformWin32/winDirectInput.cpp:522–575  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

520
521//------------------------------------------------------------------------------
522bool DInputManager::rumble( const char *pDeviceName, F32 x, F32 y )
523{
524 // Determine the device
525 U32 deviceType;
526 U32 deviceInst;
527
528 // Find the requested device
529 if ( !ActionMap::getDeviceTypeAndInstance(pDeviceName, deviceType, deviceInst) )
530 {
531 Con::printf("DInputManager::rumble: unknown device: %s", pDeviceName);
532 return false;
533 }
534
535 // clamp (x, y) to the range of [0 ... 1] each
536 x = mClampF(x, 0.f, 1.f);
537 y = mClampF(y, 0.f, 1.f);
538
539 // Easy path for xinput devices.
540 if(deviceType == GamepadDeviceType)
541 {
542 XINPUT_VIBRATION vibration;
543 vibration.wLeftMotorSpeed = static_cast<int>(x * 65535);
544 vibration.wRightMotorSpeed = static_cast<int>(y * 65535);
545 return ( mfnXInputSetState(deviceInst, &vibration) == ERROR_SUCCESS );
546 }
547
548 switch ( deviceType )
549 {
550 case JoystickDeviceType:
551
552 // Find the device and shake it!
553 DInputDevice* dptr;
554 for ( iterator ptr = begin(); ptr != end(); ptr++ )
555 {
556 dptr = dynamic_cast<DInputDevice*>( *ptr );
557 if ( dptr )
558 {
559 if (deviceType == dptr->getDeviceType() && deviceInst == dptr->getDeviceID())
560 {
561 dptr->rumble(x, y);
562 return true;
563 }
564 }
565 }
566
567 // We should never get here... something's really messed up
568 Con::errorf( "DInputManager::rumbleJoystick - Couldn't find device to rumble! This should never happen!\n" );
569 return false;
570
571 default:
572 Con::printf("DInputManager::rumble - only supports joystick and xinput/gamepad devices");
573 return false;
574 }
575}
576
577void DInputManager::buildXInputEvent( U32 deviceInst, InputEventType objType, InputObjectInstances objInst, InputActionType action, F32 fValue )
578{

Callers 1

winDirectInput.cppFile · 0.45

Calls 7

printfFunction · 0.85
mClampFFunction · 0.85
beginFunction · 0.85
endFunction · 0.85
getDeviceIDMethod · 0.80
errorfFunction · 0.50
getDeviceTypeMethod · 0.45

Tested by

no test coverage detected