Add constant for input detect threshold. Possible fix for issue on linux with binding triggers. Change unique_mapping to std::set

This commit is contained in:
Anon 2017-01-14 21:53:05 -06:00
parent 233985129e
commit bd94a96d3c
5 changed files with 15 additions and 14 deletions

View File

@ -52,7 +52,7 @@ void Keyboard::Clear() {
Settings::InputDeviceMapping Keyboard::GetInput() { Settings::InputDeviceMapping Keyboard::GetInput() {
auto result = ProcessInput(); auto result = ProcessInput();
for (const auto& entry : result) { for (const auto& entry : result) {
if (entry.second > 0.5) if (entry.second > 0.0)
return entry.first; return entry.first;
} }
return Settings::InputDeviceMapping(""); return Settings::InputDeviceMapping("");

View File

@ -60,7 +60,7 @@ std::map<Settings::InputDeviceMapping, float> SDLGamepad::ProcessInput() {
fmaxf(-1, static_cast<float>(SDL_GameControllerGetAxis(gamepad, axis) / 32767.0)); fmaxf(-1, static_cast<float>(SDL_GameControllerGetAxis(gamepad, axis) / 32767.0));
input_device_mapping.key = static_cast<int>( input_device_mapping.key = static_cast<int>(
gamepadinput_to_sdlname_mapping[SDL_GameControllerGetStringForAxis(axis)]); gamepadinput_to_sdlname_mapping[SDL_GameControllerGetStringForAxis(axis)]);
if (strength < 0) { if (strength < 0 && i < 4) {
button_status.emplace(input_device_mapping, 0); button_status.emplace(input_device_mapping, 0);
input_device_mapping.key += 1; // minus axis value is always one greater input_device_mapping.key += 1; // minus axis value is always one greater
button_status.emplace(input_device_mapping, abs(strength)); button_status.emplace(input_device_mapping, abs(strength));
@ -114,9 +114,9 @@ Settings::InputDeviceMapping SDLGamepad::GetInput() {
return Settings::InputDeviceMapping(""); return Settings::InputDeviceMapping("");
auto results = ProcessInput(); auto results = ProcessInput();
for (const auto& input : results) { for (const auto& entry : results) {
if (input.second > 0.5) if (entry.second > input_detect_threshold)
return input.first; return entry.first;
} }
return Settings::InputDeviceMapping(""); return Settings::InputDeviceMapping("");
} }

View File

@ -82,6 +82,7 @@ private:
keys_pressed; ///< Map of keys that were pressed on previous iteration keys_pressed; ///< Map of keys that were pressed on previous iteration
_SDL_GameController* gamepad = nullptr; _SDL_GameController* gamepad = nullptr;
int number; ///< Index of gamepad connection int number; ///< Index of gamepad connection
float input_detect_threshold = 0.8;
static void LoadGameControllerDB(); static void LoadGameControllerDB();
}; };

View File

@ -149,24 +149,23 @@ void InputCore::SetTouchState(std::tuple<u16, u16, bool> value) {
std::tie(touch_x, touch_y, touch_pressed) = value; std::tie(touch_x, touch_y, touch_pressed) = value;
} }
bool InputCore::CheckIfMappingExists( bool InputCore::CheckIfMappingExists(const std::set<Settings::InputDeviceMapping>& unique_mapping,
const std::vector<Settings::InputDeviceMapping>& unique_mapping,
Settings::InputDeviceMapping mapping_to_check) { Settings::InputDeviceMapping mapping_to_check) {
return std::any_of( return std::any_of(
unique_mapping.begin(), unique_mapping.end(), unique_mapping.begin(), unique_mapping.end(),
[mapping_to_check](const auto& mapping) { return mapping == mapping_to_check; }); [mapping_to_check](const auto& mapping) { return mapping == mapping_to_check; });
} }
std::vector<Settings::InputDeviceMapping> InputCore::GatherUniqueMappings() { std::set<Settings::InputDeviceMapping> InputCore::GatherUniqueMappings() {
std::vector<Settings::InputDeviceMapping> unique_mappings; std::set<Settings::InputDeviceMapping> unique_mappings;
for (const auto& mapping : Settings::values.input_mappings) { for (const auto& mapping : Settings::values.input_mappings) {
if (!CheckIfMappingExists(unique_mappings, mapping)) { if (!CheckIfMappingExists(unique_mappings, mapping)) {
unique_mappings.push_back(mapping); unique_mappings.insert(mapping);
} }
} }
if (!CheckIfMappingExists(unique_mappings, Settings::values.pad_circle_modifier)) { 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; return unique_mappings;
} }

View File

@ -7,6 +7,7 @@
#include <functional> #include <functional>
#include <memory> #include <memory>
#include <mutex> #include <mutex>
#include <set>
#include <tuple> #include <tuple>
#include "core/hle/service/hid/hid.h" #include "core/hle/service/hid/hid.h"
@ -106,10 +107,10 @@ private:
/** /**
* Helper methodto check if device was already initialized * Helper methodto check if device was already initialized
*/ */
static bool CheckIfMappingExists(const std::vector<Settings::InputDeviceMapping>& uniqueMapping, static bool CheckIfMappingExists(const std::set<Settings::InputDeviceMapping>& uniqueMapping,
Settings::InputDeviceMapping mappingToCheck); Settings::InputDeviceMapping mappingToCheck);
static std::vector<Settings::InputDeviceMapping> static std::set<Settings::InputDeviceMapping>
GatherUniqueMappings(); /// Get unique input mappings from settings GatherUniqueMappings(); /// Get unique input mappings from settings
static void BuildKeyMapping(); /// Builds map of input keys to 3ds buttons for unique device static void BuildKeyMapping(); /// Builds map of input keys to 3ds buttons for unique device