diff --git a/rpcs3/xinput_pad_handler.cpp b/rpcs3/xinput_pad_handler.cpp index 128ade86dd..1313d5e188 100644 --- a/rpcs3/xinput_pad_handler.cpp +++ b/rpcs3/xinput_pad_handler.cpp @@ -415,28 +415,28 @@ void xinput_pad_handler::ThreadProc() // The left motor is the low-frequency rumble motor. The right motor is the high-frequency rumble motor. // The two motors are not the same, and they create different vibration effects. Values range between 0 to 65535. - int idx_l = profile->switch_vibration_motors ? 1 : 0; - int idx_s = profile->switch_vibration_motors ? 0 : 1; + size_t idx_l = profile->switch_vibration_motors ? 1 : 0; + size_t idx_s = profile->switch_vibration_motors ? 0 : 1; - int speed_large = profile->enable_vibration_motor_large ? pad->m_vibrateMotors[idx_l].m_value * 257 : vibration_min; - int speed_small = profile->enable_vibration_motor_small ? pad->m_vibrateMotors[idx_s].m_value * 257 : vibration_min; + u16 speed_large = profile->enable_vibration_motor_large ? pad->m_vibrateMotors[idx_l].m_value : static_cast(vibration_min); + u16 speed_small = profile->enable_vibration_motor_small ? pad->m_vibrateMotors[idx_s].m_value : static_cast(vibration_min); - m_dev->newVibrateData = m_dev->newVibrateData || m_dev->largeVibrate != speed_large || m_dev->smallVibrate != speed_small; + m_dev->newVibrateData |= m_dev->largeVibrate != speed_large || m_dev->smallVibrate != speed_small; m_dev->largeVibrate = speed_large; m_dev->smallVibrate = speed_small; // XBox One Controller can't handle faster vibration updates than ~10ms. Elite is even worse. So I'll use 20ms to be on the safe side. No lag was noticable. - if (m_dev->newVibrateData && (clock() - m_dev->last_vibration > 20)) + if (m_dev->newVibrateData && (std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - m_dev->last_vibration) > 20ms)) { XINPUT_VIBRATION vibrate; - vibrate.wLeftMotorSpeed = speed_large; - vibrate.wRightMotorSpeed = speed_small; + vibrate.wLeftMotorSpeed = speed_large * 257; + vibrate.wRightMotorSpeed = speed_small * 257; if ((*xinputSetState)(padnum, &vibrate) == ERROR_SUCCESS) { m_dev->newVibrateData = false; - m_dev->last_vibration = clock(); + m_dev->last_vibration = std::chrono::high_resolution_clock::now(); } } break; diff --git a/rpcs3/xinput_pad_handler.h b/rpcs3/xinput_pad_handler.h index eb9d6c6f27..ad94d9222b 100644 --- a/rpcs3/xinput_pad_handler.h +++ b/rpcs3/xinput_pad_handler.h @@ -5,7 +5,7 @@ #define NOMINMAX #include #include -#include +#include namespace XINPUT_INFO { @@ -91,9 +91,9 @@ class xinput_pad_handler final : public PadHandlerBase { u32 deviceNumber{ 0 }; bool newVibrateData{ true }; - u8 largeVibrate{ 0 }; - u8 smallVibrate{ 0 }; - clock_t last_vibration{ 0 }; + u16 largeVibrate{ 0 }; + u16 smallVibrate{ 0 }; + std::chrono::high_resolution_clock::time_point last_vibration; pad_config* config{ nullptr }; };