Skip to content

Commit

Permalink
Merge pull request #18621 from hrydgard/analog-trigger-sensitivity
Browse files Browse the repository at this point in the history
Add "Analog trigger threshold" setting, for conversion of analog trigger inputs to digital button inputs.
  • Loading branch information
hrydgard committed Dec 28, 2023
2 parents ce72887 + 549071e commit 62019c9
Show file tree
Hide file tree
Showing 53 changed files with 107 additions and 15 deletions.
1 change: 1 addition & 0 deletions Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,7 @@ static const ConfigSetting controlSettings[] = {
ConfigSetting("AnalogAutoRotSpeed", &g_Config.fAnalogAutoRotSpeed, 8.0f, CfgFlag::PER_GAME),

ConfigSetting("AnalogLimiterDeadzone", &g_Config.fAnalogLimiterDeadzone, 0.6f, CfgFlag::DEFAULT),
ConfigSetting("AnalogTriggerThreshold", &g_Config.fAnalogTriggerThreshold, 0.75f, CfgFlag::DEFAULT),

ConfigSetting("AllowMappingCombos", &g_Config.bAllowMappingCombos, false, CfgFlag::DEFAULT),

Expand Down
3 changes: 3 additions & 0 deletions Core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,9 @@ struct Config {
// Sets up how much the analog limiter button restricts digital->analog input.
float fAnalogLimiterDeadzone;

// Trigger configuration
float fAnalogTriggerThreshold;

// Sets whether combo mapping is enabled.
bool bAllowMappingCombos;

Expand Down
26 changes: 20 additions & 6 deletions Core/ControlMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,23 @@

using KeyMap::MultiInputMapping;

// TODO: Possibly make these thresholds configurable?
static float GetDeviceAxisThreshold(int device) {
return device == DEVICE_ID_MOUSE ? AXIS_BIND_THRESHOLD_MOUSE : AXIS_BIND_THRESHOLD;
const float AXIS_BIND_THRESHOLD = 0.75f;
const float AXIS_BIND_THRESHOLD_MOUSE = 0.01f;

float GetDeviceAxisThreshold(int device, const InputMapping &mapping) {
if (device == DEVICE_ID_MOUSE) {
return AXIS_BIND_THRESHOLD_MOUSE;
}
if (mapping.IsAxis()) {
switch (KeyMap::GetAxisType((InputAxis)mapping.Axis(nullptr))) {
case KeyMap::AxisType::TRIGGER:
return g_Config.fAnalogTriggerThreshold;
default:
return AXIS_BIND_THRESHOLD;
}
} else {
return AXIS_BIND_THRESHOLD;
}
}

static int GetOppositeVKey(int vkey) {
Expand Down Expand Up @@ -311,7 +325,7 @@ bool ControlMapper::UpdatePSPState(const InputMapping &changedMapping, double no
} else {
curTime = iter->second.timestamp;
}
bool down = iter->second.value > GetDeviceAxisThreshold(iter->first.deviceId);
bool down = iter->second.value > GetDeviceAxisThreshold(iter->first.deviceId, mapping);
if (!down)
all = false;
}
Expand Down Expand Up @@ -364,7 +378,7 @@ bool ControlMapper::UpdatePSPState(const InputMapping &changedMapping, double no
}

if (mapping.IsAxis()) {
threshold = GetDeviceAxisThreshold(iter->first.deviceId);
threshold = GetDeviceAxisThreshold(iter->first.deviceId, mapping);
float value = MapAxisValue(iter->second.value, idForMapping, mapping, changedMapping, &touchedByMapping);
product *= value;
} else {
Expand Down Expand Up @@ -510,7 +524,7 @@ void ControlMapper::ToggleSwapAxes() {
void ControlMapper::UpdateCurInputAxis(const InputMapping &mapping, float value, double timestamp) {
InputSample &input = curInput_[mapping];
input.value = value;
if (value > GetDeviceAxisThreshold(mapping.deviceId)) {
if (value >= GetDeviceAxisThreshold(mapping.deviceId, mapping)) {
if (input.timestamp == 0.0) {
input.timestamp = time_now_d();
}
Expand Down
1 change: 1 addition & 0 deletions Core/ControlMapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,4 @@ class ControlMapper {
};

void ConvertAnalogStick(float x, float y, float *outX, float *outY);
float GetDeviceAxisThreshold(int device, const InputMapping &mapping);
21 changes: 20 additions & 1 deletion Core/KeyMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,25 @@ std::set<std::string> g_seenPads;
std::map<InputDeviceID, std::string> g_padNames;
std::set<InputDeviceID> g_seenDeviceIds;

AxisType GetAxisType(InputAxis input) {
switch (input) {
case JOYSTICK_AXIS_GAS:
case JOYSTICK_AXIS_BRAKE:
case JOYSTICK_AXIS_LTRIGGER:
case JOYSTICK_AXIS_RTRIGGER:
return AxisType::TRIGGER;
case JOYSTICK_AXIS_X:
case JOYSTICK_AXIS_Y:
case JOYSTICK_AXIS_Z:
case JOYSTICK_AXIS_RX:
case JOYSTICK_AXIS_RY:
case JOYSTICK_AXIS_RZ:
return AxisType::STICK;
default:
return AxisType::OTHER;
}
}

// Utility for UI navigation
void SingleInputMappingFromPspButton(int btn, std::vector<InputMapping> *mappings, bool ignoreMouse) {
std::vector<MultiInputMapping> multiMappings;
Expand Down Expand Up @@ -874,7 +893,7 @@ bool HasChanged(int &prevGeneration) {
return false;
}

static const char *g_vKeyNames[] = {
static const char * const g_vKeyNames[] = {
"AXIS_X_MIN",
"AXIS_Y_MIN",
"AXIS_X_MAX",
Expand Down
13 changes: 9 additions & 4 deletions Core/KeyMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ enum {
VIRTKEY_COUNT = VIRTKEY_LAST - VIRTKEY_FIRST
};

const float AXIS_BIND_THRESHOLD = 0.75f;
const float AXIS_BIND_RELEASE_THRESHOLD = 0.35f; // Used during mapping only to detect a "key-up" reliably.
const float AXIS_BIND_THRESHOLD_MOUSE = 0.01f;

struct MappedAnalogAxis {
int axisId;
int direction;
Expand Down Expand Up @@ -224,4 +220,13 @@ namespace KeyMap {
bool IsKeyMapped(InputDeviceID device, int key);

bool HasChanged(int &prevGeneration);

// Used for setting thresholds. Technically we could allow a setting per axis, but this is a reasonable compromise.
enum class AxisType {
TRIGGER,
STICK,
OTHER,
};

AxisType GetAxisType(InputAxis axis);
} // namespace KeyMap
1 change: 1 addition & 0 deletions GPU/Common/TextureReplacer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ ReplacedTexture *TextureReplacer::FindReplacement(u64 cachekey, u32 hash, int w,
desc.hashfiles = hashfiles;
}

_dbg_assert_(!hashfiles.empty());
// OK, we might already have a matching texture, we use hashfiles as a key. Look it up in the level cache.
auto iter = levelCache_.find(hashfiles);
if (iter != levelCache_.end()) {
Expand Down
8 changes: 4 additions & 4 deletions Tools/langtool/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions UI/ControlMappingScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,10 @@ bool KeyMappingNewMouseKeyDialog::key(const KeyInput &key) {
return true;
}

// Only used during the bind process. In other places, it's configurable for some types of axis, like trigger.
const float AXIS_BIND_THRESHOLD = 0.75f;
const float AXIS_BIND_RELEASE_THRESHOLD = 0.35f; // Used during mapping only to detect a "key-up" reliably.

void KeyMappingNewKeyDialog::axis(const AxisInput &axis) {
if (time_now_d() < delayUntil_)
return;
Expand Down
1 change: 1 addition & 0 deletions UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ void GameSettingsScreen::CreateControlsSettings(UI::ViewGroup *controlsSettings)
controlsSettings->Add(new ItemHeader(ms->T("Controls")));
controlsSettings->Add(new Choice(co->T("Control Mapping")))->OnClick.Handle(this, &GameSettingsScreen::OnControlMapping);
controlsSettings->Add(new Choice(co->T("Calibrate Analog Stick")))->OnClick.Handle(this, &GameSettingsScreen::OnCalibrateAnalogs);
controlsSettings->Add(new PopupSliderChoiceFloat(&g_Config.fAnalogTriggerThreshold, 0.25f, 0.98f, 0.75f, co->T("Analog trigger threshold"), screenManager()));

#if defined(USING_WIN_UI) || (PPSSPP_PLATFORM(LINUX) && !PPSSPP_PLATFORM(ANDROID))
controlsSettings->Add(new CheckBox(&g_Config.bSystemControls, co->T("Enable standard shortcut keys")));
Expand Down
1 change: 1 addition & 0 deletions assets/lang/ar_AE.ini
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ Analog Limiter = ‎محدد التناظري
Analog Settings = Analog Settings
Analog Stick = ‎عصا تناظرية
Analog Style = Analog Style
Analog trigger threshold = Analog trigger threshold
AnalogLimiter Tip = ‎حينما يتم ضغط زر تحديد التناظر
Auto = ‎تلقائي
Auto-centering analog stick = ‎تنصيف العصا التناظرية تلقائياً
Expand Down
1 change: 1 addition & 0 deletions assets/lang/az_AZ.ini
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Analog Limiter = Analog limiter
Analog Settings = Analog Settings
Analog Stick = Analog stick
Analog Style = Analog Style
Analog trigger threshold = Analog trigger threshold
AnalogLimiter Tip = When the analog limiter button is pressed
Auto = Auto
Auto-centering analog stick = Auto-centering analog stick
Expand Down
1 change: 1 addition & 0 deletions assets/lang/bg_BG.ini
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Analog Limiter = Analog limiter
Analog Settings = Analog Settings
Analog Stick = Analog stick
Analog Style = Analog Style
Analog trigger threshold = Analog trigger threshold
AnalogLimiter Tip = When the analog limiter button is pressed
Auto = Автоматично
Auto-centering analog stick = Auto-centering analog stick
Expand Down
1 change: 1 addition & 0 deletions assets/lang/ca_ES.ini
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Analog Limiter = Limitador analògic
Analog Settings = Configuració de l'stick
Analog Stick = Palanca analògica
Analog Style = Estil de l'stick
Analog trigger threshold = Analog trigger threshold
AnalogLimiter Tip = Quan es prem el botó del limitador de l'stick
Auto = Automàtic
Auto-centering analog stick = Auto centrat de l'stick
Expand Down
1 change: 1 addition & 0 deletions assets/lang/cz_CZ.ini
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Analog Limiter = Analogový omezovač
Analog Settings = Analog Settings
Analog Stick = Analogová páčka
Analog Style = Analog Style
Analog trigger threshold = Analog trigger threshold
AnalogLimiter Tip = When the analog limiter button is pressed
Auto = Auto
Auto-centering analog stick = Automatické vystředění analogové páčky
Expand Down
1 change: 1 addition & 0 deletions assets/lang/da_DK.ini
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Analog Limiter = Analog begrænser
Analog Settings = Analog Settings
Analog Stick = Analog stick
Analog Style = Analog Style
Analog trigger threshold = Analog trigger threshold
AnalogLimiter Tip = Når den analoge begrænser knap er trykket ned
Auto = Automatisk
Auto-centering analog stick = Auto-centering analog stick
Expand Down
1 change: 1 addition & 0 deletions assets/lang/de_DE.ini
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Analog Limiter = Analogbegrenzer
Analog Settings = Analog Einstellungen
Analog Stick = Analogstick
Analog Style = Analog Style
Analog trigger threshold = Analog trigger threshold
AnalogLimiter Tip = Wenn die Analogbegrenzer-Taste gedrückt ist
Auto = Automatisch
Auto-centering analog stick = Analogstick automatisch zentrieren
Expand Down
1 change: 1 addition & 0 deletions assets/lang/dr_ID.ini
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Analog Limiter = Analog limiter
Analog Settings = Analog Settings
Analog Stick = Analog stick
Analog Style = Analog Style
Analog trigger threshold = Analog trigger threshold
AnalogLimiter Tip = When the analog limiter button is pressed
Auto = Auto
Auto-centering analog stick = Auto-centering analog stick
Expand Down
1 change: 1 addition & 0 deletions assets/lang/en_US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ Analog Limiter = Analog limiter
Analog Settings = Analog Settings
Analog Stick = Analog stick
Analog Style = Analog Style
Analog trigger threshold = Analog trigger threshold
AnalogLimiter Tip = When the analog limiter button is pressed
Auto = Auto
Auto-centering analog stick = Auto-centering analog stick
Expand Down
1 change: 1 addition & 0 deletions assets/lang/es_ES.ini
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ WASAPI (fast) = WASAPI (rápido)
Analog Binding = Asignar stick
Analog Settings = Ajustes de stick
Analog Style = Estilo de stick
Analog trigger threshold = Analog trigger threshold
Auto-rotation speed = Velocidad auto rotación del stick
Analog Limiter = Limitador del stick
Analog Stick = Stick izquierdo
Expand Down
1 change: 1 addition & 0 deletions assets/lang/es_LA.ini
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ WASAPI (fast) = WASAPI (rápido)
Analog Binding = Asignar análogo
Analog Settings = Config. del análogo
Analog Style = Estilo del análogo
Analog trigger threshold = Analog trigger threshold
Auto-rotation speed = Vel. de rotación auto. del análogo
Analog Limiter = Limitador del análogo
Analog Stick = Analog stick
Expand Down
1 change: 1 addition & 0 deletions assets/lang/fa_IR.ini
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Analog Limiter = ‎محدود کننده آنالوگ
Analog Settings = تنظیمات انالوگ
Analog Stick = ‎دسته آنالوگ
Analog Style = Analog Style
Analog trigger threshold = Analog trigger threshold
AnalogLimiter Tip = ‎هنگامی که دکمه محدود کننده آنالوگ فشرده شود
Auto = ‎اتوماتیک
Auto-centering analog stick = ‎تنظیم مرکز آنالوگ به صورت خودکار
Expand Down
1 change: 1 addition & 0 deletions assets/lang/fi_FI.ini
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Analog Limiter = Analoginen rajoitin
Analog Settings = Analogisen asetukset
Analog Stick = Analoginen sauva
Analog Style = Analogisen tyyli
Analog trigger threshold = Analog trigger threshold
AnalogLimiter Tip = Kun analogisen rajoittimen näppäintä painetaan
Auto = Automaattinen
Auto-centering analog stick = Automaattisesti keskittävä analoginen sauva
Expand Down
1 change: 1 addition & 0 deletions assets/lang/fr_FR.ini
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ WASAPI (fast) = WASAPI (rapide)
Analog Binding = Analog Binding
Analog Settings = Analog Settings
Analog Style = Analog Style
Analog trigger threshold = Analog trigger threshold
Auto-rotation speed = Vitesse de rotation automatique du stick analogique
Analog Limiter = Limiteur analogique
Analog Stick = Stick analogique
Expand Down
1 change: 1 addition & 0 deletions assets/lang/gl_ES.ini
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Analog Limiter = Limitador analóxico
Analog Settings = Analog Settings
Analog Stick = Stick analóxico
Analog Style = Analog Style
Analog trigger threshold = Analog trigger threshold
AnalogLimiter Tip = When the analog limiter button is pressed
Auto = Automática
Auto-centering analog stick = Auto-centering analog stick
Expand Down
1 change: 1 addition & 0 deletions assets/lang/gr_EL.ini
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Analog Limiter = Περιορισμός αναλογικού
Analog Settings = Analog Settings
Analog Stick = Αναλογικός μοχλός
Analog Style = Analog Style
Analog trigger threshold = Analog trigger threshold
AnalogLimiter Tip = Όταν το κουμπί περιορισμού αναλογικού είναι πατημένο
Auto = Αυτόματο
Auto-centering analog stick = Αυτόματος κεντρισμός αναλογικού μοχλού
Expand Down
1 change: 1 addition & 0 deletions assets/lang/he_IL.ini
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Analog Limiter = Analog limiter
Analog Settings = Analog Settings
Analog Stick = Analog stick
Analog Style = Analog Style
Analog trigger threshold = Analog trigger threshold
AnalogLimiter Tip = When the analog limiter button is pressed
Auto = Auto
Auto-centering analog stick = Auto-centering analog stick
Expand Down
1 change: 1 addition & 0 deletions assets/lang/he_IL_invert.ini
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Analog Limiter = Analog limiter
Analog Settings = Analog Settings
Analog Stick = Analog stick
Analog Style = Analog Style
Analog trigger threshold = Analog trigger threshold
AnalogLimiter Tip = When the analog limiter button is pressed
Auto = Auto
Auto-centering analog stick = Auto-centering analog stick
Expand Down
1 change: 1 addition & 0 deletions assets/lang/hr_HR.ini
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ WASAPI (fast) = WASAPI (brzo)
Analog Binding = Analog Binding
Analog Settings = Analog Settings
Analog Style = Analog Style
Analog trigger threshold = Analog trigger threshold
Auto-rotation speed = Auto-Rotacija analogne brzine
Analog Limiter = Analogni ograničivač
Analog Stick = Analogni stick
Expand Down
1 change: 1 addition & 0 deletions assets/lang/hu_HU.ini
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ WASAPI (fast) = WASAPI (gyors)
Analog Binding = Analog Binding
Analog Settings = Analog Settings
Analog Style = Analog Style
Analog trigger threshold = Analog trigger threshold
Auto-rotation speed = Automata analóg forgató sebessége
Analog Limiter = Analóg korlátozó
Analog Stick = Analóg kar
Expand Down
1 change: 1 addition & 0 deletions assets/lang/id_ID.ini
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Analog Limiter = Pembatas analog
Analog Settings = Pengaturan analog
Analog Stick = Stik analog
Analog Style = Gaya analog
Analog trigger threshold = Analog trigger threshold
AnalogLimiter Tip = Ketika tombol pembatas analog ditekan
Auto = Otomatis
Auto-centering analog stick = Penengahan otomatis stik analog
Expand Down
1 change: 1 addition & 0 deletions assets/lang/it_IT.ini
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Analog Limiter = Limitatore Analogico
Analog Settings = Impostazioni Analogico
Analog Stick = Stick Analogico
Analog Style = Stile Analogico
Analog trigger threshold = Analog trigger threshold
AnalogLimiter Tip = Quando viene premuto il tasto del limitatore analogico
Auto = Automatico
Auto-centering analog stick = Auto-centramento dello stick analogico
Expand Down
1 change: 1 addition & 0 deletions assets/lang/ja_JP.ini
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ WASAPI (fast) = WASAPI (高速)
Analog Binding = 右アナログパッドへの対応ボタン割り当て
Analog Settings = アナログパッドの設定
Analog Style = 右アナログパッドのスタイル
Analog trigger threshold = Analog trigger threshold
Auto-rotation speed = アナログの自動回転速度
Analog Limiter = アナログパッドのリミッタ
Analog Stick = アナログパッド
Expand Down
1 change: 1 addition & 0 deletions assets/lang/jv_ID.ini
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Analog Limiter = Analog limiter
Analog Settings = Analog Settings
Analog Stick = Analog stick
Analog Style = Analog Style
Analog trigger threshold = Analog trigger threshold
AnalogLimiter Tip = When the analog limiter button is pressed
Auto = Otomatis
Auto-centering analog stick = Otomatis Analog stick nang tengah
Expand Down
1 change: 1 addition & 0 deletions assets/lang/ko_KR.ini
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Analog Limiter = 아날로그 리미터
Analog Settings = 아날로그 설정
Analog Stick = 아날로그 스틱
Analog Style = 아날로그 스타일
Analog trigger threshold = Analog trigger threshold
AnalogLimiter Tip = 아날로그 리미터 버튼을 눌렀을 때
Auto = 자동
Auto-centering analog stick = 자동 센터링 아날로그 스틱
Expand Down
1 change: 1 addition & 0 deletions assets/lang/lo_LA.ini
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Analog Limiter = ໂຕຈຳກັດອະນາລ໋ອກ
Analog Settings = Analog Settings
Analog Stick = ປຸ່ມອະນາລ໋ອກ
Analog Style = Analog Style
Analog trigger threshold = Analog trigger threshold
AnalogLimiter Tip = ເມື່ອກົດທີ່ຂອບປຸ່ມອະນາລ໋ອກ ໂຕຈຳກັດອະນາລ໋ອກຈະເຮັດວຽກ
Auto = ອັດຕະໂນມັດ
Auto-centering analog stick = ອະນາລ໋ອກກັບຄືນຈຸດສູນກາງອັດຕະໂນມັດ
Expand Down
Loading

0 comments on commit 62019c9

Please sign in to comment.