UI: Ignore duplicate axis events.

We already ignore these on Windows, so this makes other platforms follow
the same logic.
This commit is contained in:
Unknown W. Brackets 2021-05-23 13:21:45 -07:00
parent e67c6593f3
commit e1e5a8b49b
4 changed files with 29 additions and 39 deletions

View File

@ -864,6 +864,16 @@ void EmuScreen::pspKey(int pspKeyCode, int flags) {
bool EmuScreen::axis(const AxisInput &axis) {
Core_NotifyActivity();
// Ignore duplicate values to prevent axis values overwriting each other.
uint64_t key = ((uint64_t)axis.axisId << 32) | axis.deviceId;
// Center value far from zero just to ensure we send the first zero.
// PSP games can't see higher resolution than this.
int value = 128 + ceilf(axis.value * 127.5f + 127.5f);
if (lastAxis_[key] == value) {
return false;
}
lastAxis_[key] = value;
if (axis.value > 0) {
processAxis(axis, 1);
return true;

View File

@ -17,9 +17,11 @@
#pragma once
#include <string>
#include <vector>
#include <cstdint>
#include <list>
#include <string>
#include <unordered_map>
#include <vector>
#include "Common/File/Path.h"
#include "Common/Input/KeyCodes.h"
@ -113,4 +115,5 @@ private:
bool autoRotatingAnalogCW_ = false;
bool autoRotatingAnalogCCW_ = false;
std::unordered_map<int64_t, int> lastAxis_;
};

View File

@ -200,9 +200,6 @@ DinputDevice::~DinputDevice() {
}
void SendNativeAxis(int deviceId, int value, int &lastValue, int axisId) {
if (value == lastValue)
return;
AxisInput axis;
axis.deviceId = deviceId;
axis.axisId = axisId;

View File

@ -282,54 +282,34 @@ void XinputDevice::UpdatePad(int pad, const XINPUT_STATE &state, XINPUT_VIBRATIO
const float STICK_INV_DEADZONE = g_Config.fXInputAnalogInverseDeadzone;
const float STICK_SENSITIVITY = g_Config.fXInputAnalogSensitivity;
AxisInput axis;
axis.deviceId = DEVICE_ID_X360_0 + pad;
auto sendAxis = [&](AndroidJoystickAxis axisId, float value) {
axis.axisId = axisId;
axis.value = value;
NativeAxis(axis);
};
if (NormalizedDeadzoneDiffers(prevState[pad].Gamepad.sThumbLX, prevState[pad].Gamepad.sThumbLY, state.Gamepad.sThumbLX, state.Gamepad.sThumbLY, STICK_DEADZONE)) {
Stick left = NormalizedDeadzoneFilter(state.Gamepad.sThumbLX, state.Gamepad.sThumbLY, STICK_DEADZONE, STICK_INV_MODE, STICK_INV_DEADZONE, STICK_SENSITIVITY);
AxisInput axis;
axis.deviceId = DEVICE_ID_X360_0 + pad;
axis.axisId = JOYSTICK_AXIS_X;
axis.value = left.x;
if (prevState[pad].Gamepad.sThumbLX != state.Gamepad.sThumbLX) {
NativeAxis(axis);
}
axis.axisId = JOYSTICK_AXIS_Y;
axis.value = left.y;
if (prevState[pad].Gamepad.sThumbLY != state.Gamepad.sThumbLY) {
NativeAxis(axis);
}
sendAxis(JOYSTICK_AXIS_X, left.x);
sendAxis(JOYSTICK_AXIS_Y, left.y);
}
if (NormalizedDeadzoneDiffers(prevState[pad].Gamepad.sThumbRX, prevState[pad].Gamepad.sThumbRY, state.Gamepad.sThumbRX, state.Gamepad.sThumbRY, STICK_DEADZONE)) {
Stick right = NormalizedDeadzoneFilter(state.Gamepad.sThumbRX, state.Gamepad.sThumbRY, STICK_DEADZONE, STICK_INV_MODE, STICK_INV_DEADZONE, STICK_SENSITIVITY);
AxisInput axis;
axis.deviceId = DEVICE_ID_X360_0 + pad;
axis.axisId = JOYSTICK_AXIS_Z;
axis.value = right.x;
if (prevState[pad].Gamepad.sThumbRX != state.Gamepad.sThumbRX) {
NativeAxis(axis);
}
axis.axisId = JOYSTICK_AXIS_RZ;
axis.value = right.y;
if (prevState[pad].Gamepad.sThumbRY != state.Gamepad.sThumbRY) {
NativeAxis(axis);
}
sendAxis(JOYSTICK_AXIS_Z, right.x);
sendAxis(JOYSTICK_AXIS_RZ, right.y);
}
if (NormalizedDeadzoneDiffers(prevState[pad].Gamepad.bLeftTrigger, state.Gamepad.bLeftTrigger, XINPUT_GAMEPAD_TRIGGER_THRESHOLD)) {
AxisInput axis;
axis.deviceId = DEVICE_ID_X360_0 + pad;
axis.axisId = JOYSTICK_AXIS_LTRIGGER;
axis.value = (float)state.Gamepad.bLeftTrigger / 255.0f;
NativeAxis(axis);
sendAxis(JOYSTICK_AXIS_LTRIGGER, (float)state.Gamepad.bLeftTrigger / 255.0f);
}
if (NormalizedDeadzoneDiffers(prevState[pad].Gamepad.bRightTrigger, state.Gamepad.bRightTrigger, XINPUT_GAMEPAD_TRIGGER_THRESHOLD)) {
AxisInput axis;
axis.deviceId = DEVICE_ID_X360_0 + pad;
axis.axisId = JOYSTICK_AXIS_RTRIGGER;
axis.value = (float)state.Gamepad.bRightTrigger / 255.0f;
NativeAxis(axis);
sendAxis(JOYSTICK_AXIS_RTRIGGER, (float)state.Gamepad.bRightTrigger / 255.0f);
}
prevState[pad] = state;