Converting dead_zone from float to int storage in cfg file with min/max range of 0-100.

This commit is contained in:
Adam Pooley 2020-07-07 12:30:55 +01:00
parent bd35dfbce3
commit a1f0053be6
4 changed files with 7 additions and 32 deletions

View File

@ -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");

View File

@ -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);

View File

@ -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<std::shared_ptr<GamepadDevice>> _gamepads;
static std::mutex _gamepads_mutex;

View File

@ -136,7 +136,12 @@ void InputMapping::load(FILE* fp)
mf.parse(fp);
this->name = mf.get("emulator", "mapping_name", "<Unknown>");
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++)
{