From bd94a96d3c6c0ee9d5ec74f53476ee8ed73177a1 Mon Sep 17 00:00:00 2001 From: Anon Date: Sat, 14 Jan 2017 21:53:05 -0600 Subject: [PATCH] Add constant for input detect threshold. Possible fix for issue on linux with binding triggers. Change unique_mapping to std::set --- src/input_core/devices/keyboard.cpp | 2 +- src/input_core/devices/sdl_gamepad.cpp | 8 ++++---- src/input_core/devices/sdl_gamepad.h | 1 + src/input_core/input_core.cpp | 13 ++++++------- src/input_core/input_core.h | 5 +++-- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/input_core/devices/keyboard.cpp b/src/input_core/devices/keyboard.cpp index aedbeb8c5..2d32626be 100644 --- a/src/input_core/devices/keyboard.cpp +++ b/src/input_core/devices/keyboard.cpp @@ -52,7 +52,7 @@ void Keyboard::Clear() { Settings::InputDeviceMapping Keyboard::GetInput() { auto result = ProcessInput(); for (const auto& entry : result) { - if (entry.second > 0.5) + if (entry.second > 0.0) return entry.first; } return Settings::InputDeviceMapping(""); diff --git a/src/input_core/devices/sdl_gamepad.cpp b/src/input_core/devices/sdl_gamepad.cpp index 11b3989db..7e02ea5fc 100644 --- a/src/input_core/devices/sdl_gamepad.cpp +++ b/src/input_core/devices/sdl_gamepad.cpp @@ -60,7 +60,7 @@ std::map SDLGamepad::ProcessInput() { fmaxf(-1, static_cast(SDL_GameControllerGetAxis(gamepad, axis) / 32767.0)); input_device_mapping.key = static_cast( gamepadinput_to_sdlname_mapping[SDL_GameControllerGetStringForAxis(axis)]); - if (strength < 0) { + if (strength < 0 && i < 4) { button_status.emplace(input_device_mapping, 0); input_device_mapping.key += 1; // minus axis value is always one greater button_status.emplace(input_device_mapping, abs(strength)); @@ -114,9 +114,9 @@ Settings::InputDeviceMapping SDLGamepad::GetInput() { return Settings::InputDeviceMapping(""); auto results = ProcessInput(); - for (const auto& input : results) { - if (input.second > 0.5) - return input.first; + for (const auto& entry : results) { + if (entry.second > input_detect_threshold) + return entry.first; } return Settings::InputDeviceMapping(""); } diff --git a/src/input_core/devices/sdl_gamepad.h b/src/input_core/devices/sdl_gamepad.h index b40ffd0ef..ab02602d2 100644 --- a/src/input_core/devices/sdl_gamepad.h +++ b/src/input_core/devices/sdl_gamepad.h @@ -82,6 +82,7 @@ private: keys_pressed; ///< Map of keys that were pressed on previous iteration _SDL_GameController* gamepad = nullptr; int number; ///< Index of gamepad connection + float input_detect_threshold = 0.8; static void LoadGameControllerDB(); }; diff --git a/src/input_core/input_core.cpp b/src/input_core/input_core.cpp index 0bc343aa3..77482240e 100644 --- a/src/input_core/input_core.cpp +++ b/src/input_core/input_core.cpp @@ -149,24 +149,23 @@ void InputCore::SetTouchState(std::tuple value) { std::tie(touch_x, touch_y, touch_pressed) = value; } -bool InputCore::CheckIfMappingExists( - const std::vector& unique_mapping, - Settings::InputDeviceMapping mapping_to_check) { +bool InputCore::CheckIfMappingExists(const std::set& unique_mapping, + Settings::InputDeviceMapping mapping_to_check) { return std::any_of( unique_mapping.begin(), unique_mapping.end(), [mapping_to_check](const auto& mapping) { return mapping == mapping_to_check; }); } -std::vector InputCore::GatherUniqueMappings() { - std::vector unique_mappings; +std::set InputCore::GatherUniqueMappings() { + std::set unique_mappings; for (const auto& mapping : Settings::values.input_mappings) { if (!CheckIfMappingExists(unique_mappings, mapping)) { - unique_mappings.push_back(mapping); + unique_mappings.insert(mapping); } } if (!CheckIfMappingExists(unique_mappings, Settings::values.pad_circle_modifier)) { - unique_mappings.push_back(Settings::values.pad_circle_modifier); + unique_mappings.insert(Settings::values.pad_circle_modifier); } return unique_mappings; } diff --git a/src/input_core/input_core.h b/src/input_core/input_core.h index 63dfbeec1..24ad191c9 100644 --- a/src/input_core/input_core.h +++ b/src/input_core/input_core.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "core/hle/service/hid/hid.h" @@ -106,10 +107,10 @@ private: /** * Helper methodto check if device was already initialized */ - static bool CheckIfMappingExists(const std::vector& uniqueMapping, + static bool CheckIfMappingExists(const std::set& uniqueMapping, Settings::InputDeviceMapping mappingToCheck); - static std::vector + static std::set GatherUniqueMappings(); /// Get unique input mappings from settings static void BuildKeyMapping(); /// Builds map of input keys to 3ds buttons for unique device