Merge pull request #18655 from hrydgard/joystick-fix-inverse-deadzone

Stick calibration/input: Fix inverse deadzone
This commit is contained in:
Henrik Rydgård 2023-12-31 17:16:59 +01:00 committed by GitHub
commit 02c10adebc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -229,6 +229,7 @@ void ManagedTexture::DeviceLost() {
INFO_LOG(G3D, "ManagedTexture::DeviceLost(%s)", filename_.c_str());
if (taskWaitable_) {
taskWaitable_->WaitAndRelease();
taskWaitable_ = nullptr;
pendingImage_.Free();
}
if (texture_)

View File

@ -109,13 +109,23 @@ static bool IsSignedAxis(int axis) {
}
// This is applied on the circular radius, not directly on the axes.
// TODO: Share logic with tilt?
static float MapAxisValue(float v) {
const float deadzone = g_Config.fAnalogDeadzone;
const float invDeadzone = g_Config.fAnalogInverseDeadzone;
const float sensitivity = g_Config.fAnalogSensitivity;
const float sign = v >= 0.0f ? 1.0f : -1.0f;
return sign * Clamp(invDeadzone + (fabsf(v) - deadzone) / (1.0f - deadzone) * (sensitivity - invDeadzone), 0.0f, 1.0f);
// Apply deadzone.
v = Clamp((fabsf(v) - deadzone) / (1.0f - deadzone), 0.0f, 1.0f);
// Apply sensitivity and inverse deadzone.
if (v != 0.0f) {
v = Clamp(invDeadzone + v * (sensitivity - invDeadzone), 0.0f, 1.0f);
}
return sign * v;
}
void ConvertAnalogStick(float x, float y, float *outX, float *outY) {