From a1f0053be638be1dd52c8cb755706a2466f02a6a Mon Sep 17 00:00:00 2001 From: Adam Pooley Date: Tue, 7 Jul 2020 12:30:55 +0100 Subject: [PATCH] Converting dead_zone from float to int storage in cfg file with min/max range of 0-100. --- core/cfg/ini.cpp | 26 -------------------------- core/cfg/ini.h | 3 --- core/input/gamepad_device.h | 1 - core/input/mapping.cpp | 9 +++++++-- 4 files changed, 7 insertions(+), 32 deletions(-) diff --git a/core/cfg/ini.cpp b/core/cfg/ini.cpp index eb9e97140..e698231c4 100644 --- a/core/cfg/ini.cpp +++ b/core/cfg/ini.cpp @@ -39,12 +39,6 @@ bool ConfigEntry::get_bool() } } -float ConfigEntry::get_float() -{ - return strtof(this->value.c_str(), NULL); - //return atof(this->value.c_str()); -} - /* ConfigSection */ bool ConfigSection::has_entry(const std::string& name) @@ -164,19 +158,6 @@ int ConfigFile::get_int(const std::string& section_name, const std::string& entr } } -float ConfigFile::get_float(const std::string& section_name, const std::string& entry_name, float default_value) -{ - ConfigEntry* entry = this->get_entry(section_name, entry_name); - if (entry == NULL) - { - return default_value; - } - else - { - return entry->get_float(); - } -} - bool ConfigFile::get_bool(const std::string& section_name, const std::string& entry_name, bool default_value) { ConfigEntry* entry = this->get_entry(section_name, entry_name); @@ -207,13 +188,6 @@ void ConfigFile::set_int(const std::string& section_name, const std::string& ent this->set(section_name, entry_name, str_value.str(), is_virtual); } -void ConfigFile::set_float(const std::string& section_name, const std::string& entry_name, float value, bool is_virtual) -{ - std::stringstream str_value; - str_value << value; - this->set(section_name, entry_name, str_value.str(), is_virtual); -} - void ConfigFile::set_bool(const std::string& section_name, const std::string& entry_name, bool value, bool is_virtual) { std::string str_value = (value ? "yes" : "no"); diff --git a/core/cfg/ini.h b/core/cfg/ini.h index 385d4aeef..e9951723d 100644 --- a/core/cfg/ini.h +++ b/core/cfg/ini.h @@ -8,7 +8,6 @@ struct ConfigEntry { std::string value; const std::string& get_string() const; int get_int(); - float get_float(); bool get_bool(); }; @@ -39,12 +38,10 @@ struct ConfigFile { /* getting values */ std::string get(const std::string& section_name, const std::string& entry_name, const std::string& default_value = ""); int get_int(const std::string& section_name, const std::string& entry_name, int default_value = 0); - float get_float(const std::string& section_name, const std::string& entry_name, float default_value = 0.0f); bool get_bool(const std::string& section_name, const std::string& entry_name, bool default_value = false); /* setting values */ void set(const std::string& section_name, const std::string& entry_name, const std::string& value, bool is_virtual = false); void set_int(const std::string& section_name, const std::string& entry_name, int value, bool is_virtual = false); - void set_float(const std::string& section_name, const std::string& entry_name, float value, bool is_virtual = false); void set_bool(const std::string& section_name, const std::string& entry_name, bool value, bool is_virtual = false); void delete_section(const std::string& section_name); diff --git a/core/input/gamepad_device.h b/core/input/gamepad_device.h index 113dfecaa..2b6880184 100644 --- a/core/input/gamepad_device.h +++ b/core/input/gamepad_device.h @@ -89,7 +89,6 @@ private: double _detection_start_time = 0.0; input_detected_cb _input_detected; bool _remappable; - //float _dead_zone = 0.1f; static std::vector> _gamepads; static std::mutex _gamepads_mutex; diff --git a/core/input/mapping.cpp b/core/input/mapping.cpp index 31e828b86..23a9e0690 100644 --- a/core/input/mapping.cpp +++ b/core/input/mapping.cpp @@ -136,7 +136,12 @@ void InputMapping::load(FILE* fp) mf.parse(fp); this->name = mf.get("emulator", "mapping_name", ""); - this->dead_zone = mf.get_float("emulator", "dead_zone", 0.0f); + + int dz = mf.get_int("emulator", "dead_zone", 10); + dz = std::min(dz, 100); + dz = std::max(dz, 0); + + this->dead_zone = ((float) dz) / 100; for (u32 i = 0; i < ARRAY_SIZE(button_list); i++) { @@ -213,7 +218,7 @@ bool InputMapping::save(const char *name) ConfigFile mf; mf.set("emulator", "mapping_name", this->name); - mf.set_float("emulator", "dead_zone", this->dead_zone); + mf.set_int("emulator", "dead_zone", this->dead_zone * 100); for (u32 i = 0; i < ARRAY_SIZE(button_list); i++) {