Break out EmuScreen's key/axis inputs to ControlMapper.cpp/h

Additionally, break out the analog stick mapping to the same file.

This will make more sense soon when I change where the analog mapping
is called from, but want this refactor in separately for testing.
This commit is contained in:
Henrik Rydgård committed 2021-07-08 22:24:00 +02:00
1 parent dea13f7197
commit 98372c465f
12 files changed
+422 -321

No files matched your search

+1 -29
View File
@@ -78,6 +78,7 @@
#include "Common/OSVersion.h"
#include "Common/GPU/ShaderTranslation.h"
#include "Core/ControlMapper.h"
#include "Core/Config.h"
#include "Core/ConfigValues.h"
#include "Core/Core.h"
@@ -1326,35 +1327,6 @@ bool NativeKey(const KeyInput &key) {
return retval;
}
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 + (abs(v) - deadzone) / (1.0f - deadzone) * (sensitivity - invDeadzone), 0.0f, 1.0f);
}
static void ConvertAnalogStick(float &x, float &y) {
const bool isCircular = g_Config.bAnalogIsCircular;
float norm = std::max(fabsf(x), fabsf(y));
if (norm == 0.0f)
return;
if (isCircular) {
float newNorm = sqrtf(x * x + y * y);
float factor = newNorm / norm;
x *= factor;
y *= factor;
norm = newNorm;
}
float mappedNorm = MapAxisValue(norm);
x = Clamp(x / norm * mappedNorm, -1.0f, 1.0f);
y = Clamp(y / norm * mappedNorm, -1.0f, 1.0f);
}
static bool AnalogStickAxis(const AxisInput &axis) {
static float history[JOYSTICK_AXIS_MAX+1] = { 0.0f };