Skip to content

Commit

Permalink
Some more XInput cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Nov 11, 2023
1 parent dd032dc commit 96cfdba
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
9 changes: 3 additions & 6 deletions Windows/XinputDevice.cpp
Expand Up @@ -16,8 +16,6 @@
#include "Core/KeyMap.h"
#include "Core/HLE/sceCtrl.h"

static double newVibrationTime = 0.0;

// Utilities to dynamically load XInput. Adapted from SDL.

#if !PPSSPP_PLATFORM(UWP)
Expand Down Expand Up @@ -258,11 +256,11 @@ void XinputDevice::ApplyButtons(int pad, const XINPUT_STATE &state) {

void XinputDevice::ApplyVibration(int pad, XINPUT_VIBRATION &vibration) {
if (PSP_IsInited()) {
newVibrationTime = time_now_d();
newVibrationTime_ = time_now_d();
// We have to run PPSSPP_XInputSetState at time intervals
// since it bugs otherwise with very high fast-forward speeds
// and freezes at constant vibration or no vibration at all.
if (newVibrationTime - prevVibrationTime >= 1.0 / 64.0) {
if (newVibrationTime_ - prevVibrationTime >= 1.0 / 64.0) {
if (GetUIState() == UISTATE_INGAME) {
vibration.wLeftMotorSpeed = sceCtrlGetLeftVibration(); // use any value between 0-65535 here
vibration.wRightMotorSpeed = sceCtrlGetRightVibration(); // use any value between 0-65535 here
Expand All @@ -275,7 +273,7 @@ void XinputDevice::ApplyVibration(int pad, XINPUT_VIBRATION &vibration) {
PPSSPP_XInputSetState(pad, &vibration);
prevVibration[pad] = vibration;
}
prevVibrationTime = newVibrationTime;
prevVibrationTime = newVibrationTime_;
}
} else {
DWORD dwResult = PPSSPP_XInputSetState(pad, &vibration);
Expand All @@ -284,4 +282,3 @@ void XinputDevice::ApplyVibration(int pad, XINPUT_VIBRATION &vibration) {
}
}
}

1 change: 1 addition & 0 deletions Windows/XinputDevice.h
Expand Up @@ -21,4 +21,5 @@ class XinputDevice final : public InputDevice {
float prevAxisValue_[4][6]{};
bool notified_[XUSER_MAX_COUNT]{};
u32 prevButtons_[4]{};
double newVibrationTime_ = 0.0;
};

0 comments on commit 96cfdba

Please sign in to comment.