rawinput: reimplement analog relative mode and delay (#674)

## Link to GitHub Issue or related Pull Request, if one exists
#181 

## Description of change
Implement analog relative mode and delay option using a new
millisecond-based algorithm.

## Testing
WIP
This commit is contained in:
bicarus
2026-05-04 22:50:11 -07:00
committed by GitHub
parent 5f94ef4478
commit 96950b6b4e
13 changed files with 250 additions and 132 deletions
+40
View File
@@ -1,5 +1,6 @@
#pragma once
#include <cstdint>
#include <array>
#include <string>
#include <cmath>
@@ -34,6 +35,11 @@ struct AnalogMovingAverage {
float cosine;
};
struct AnalogDelayEntry {
double time_in_ms;
float value;
};
class Analog {
private:
std::string name;
@@ -63,6 +69,15 @@ private:
float divisor_previous_value = 0.5f;
unsigned short divisor_region = 0;
// relative input mode
float rel_mode_absolute_value = 0.5f;
float rel_mode_last_read_time_s = 0.f;
bool relative_mode = false;
// delay
uint32_t delay_ms = 0;
std::queue<AnalogDelayEntry> delayed_inputs;
float calculateAngularDifference(float old_rads, float new_rads);
float normalizeAngle(float rads);
float normalizeAnalogValue(float value);
@@ -83,6 +98,8 @@ public:
float applyAngularSensitivity(float raw_rads);
float applyMultiplier(float raw_value);
float applyDeadzone(float raw_value);
float getRelativeModeValue(float raw_value);
float getDelayedValue(float raw_value);
inline bool isSet() {
if (this->override_enabled) {
@@ -98,7 +115,9 @@ public:
smoothing = false;
deadzone_mirror = false;
setMultiplier(1);
setRelativeMode(false);
setLastState(0.5f);
setDelayMs(0);
}
inline void clearBindings() {
@@ -195,6 +214,19 @@ public:
this->last_state = last_state;
}
inline bool isRelativeMode() const {
return this->relative_mode;
}
inline void setRelativeMode(bool relative_mode) {
if (relative_mode) {
this->smoothing = false;
}
this->relative_mode = relative_mode;
this->rel_mode_absolute_value = 0.5f;
this->rel_mode_last_read_time_s = 0.f;
}
inline GameAPI::Analogs::AnalogType getType() const {
return this->type;
}
@@ -202,4 +234,12 @@ public:
inline void setType(GameAPI::Analogs::AnalogType type) {
this->type = type;
}
inline uint32_t getDelayMs() const {
return this->delay_ms;
}
inline void setDelayMs(uint32_t delay_ms) {
this->delay_ms = delay_ms;
}
};