summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerEmu/Setting
diff options
context:
space:
mode:
authorJordan Woyak <jordan.woyak@gmail.com>2019-03-26 19:31:03 -0500
committerJordan Woyak <jordan.woyak@gmail.com>2019-04-07 09:32:49 -0500
commit5efb717873691fa42447ca0d9d9810b5ad501b42 (patch)
tree4d3f306850c0a1f876489327d7de98ca1c0cba6a /Source/Core/InputCommon/ControllerEmu/Setting
parent75e74315e69df1dc03bbda4373528e9e26274d7d (diff)
InputCommon: Clean up how numeric settings are handled. Add units of measure to UI. Eliminate hidden magic values of the IR cursor.
Diffstat (limited to 'Source/Core/InputCommon/ControllerEmu/Setting')
-rw-r--r--Source/Core/InputCommon/ControllerEmu/Setting/BooleanSetting.cpp38
-rw-r--r--Source/Core/InputCommon/ControllerEmu/Setting/BooleanSetting.h38
-rw-r--r--Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.cpp31
-rw-r--r--Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.h126
-rw-r--r--Source/Core/InputCommon/ControllerEmu/Setting/Setting.h15
5 files changed, 135 insertions, 113 deletions
diff --git a/Source/Core/InputCommon/ControllerEmu/Setting/BooleanSetting.cpp b/Source/Core/InputCommon/ControllerEmu/Setting/BooleanSetting.cpp
deleted file mode 100644
index d9aa61b9f6..0000000000
--- a/Source/Core/InputCommon/ControllerEmu/Setting/BooleanSetting.cpp
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright 2017 Dolphin Emulator Project
-// Licensed under GPLv2+
-// Refer to the license.txt file included.
-
-#include "InputCommon/ControllerEmu/Setting/BooleanSetting.h"
-
-namespace ControllerEmu
-{
-BooleanSetting::BooleanSetting(const std::string& setting_name, const std::string& ui_name,
- const bool default_value, const SettingType setting_type,
- const bool exclusive)
- : m_type(setting_type), m_name(setting_name), m_ui_name(ui_name),
- m_default_value(default_value), m_value(default_value), m_exclusive(exclusive)
-{
-}
-
-BooleanSetting::BooleanSetting(const std::string& setting_name, const bool default_value,
- const SettingType setting_type, const bool exclusive)
- : BooleanSetting(setting_name, setting_name, default_value, setting_type, exclusive)
-{
-}
-
-bool BooleanSetting::GetValue() const
-{
- return m_value;
-}
-
-bool BooleanSetting::IsExclusive() const
-{
- return m_exclusive;
-}
-
-void BooleanSetting::SetValue(bool value)
-{
- m_value = value;
-}
-
-} // namespace ControllerEmu
diff --git a/Source/Core/InputCommon/ControllerEmu/Setting/BooleanSetting.h b/Source/Core/InputCommon/ControllerEmu/Setting/BooleanSetting.h
deleted file mode 100644
index a2729a588e..0000000000
--- a/Source/Core/InputCommon/ControllerEmu/Setting/BooleanSetting.h
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright 2017 Dolphin Emulator Project
-// Licensed under GPLv2+
-// Refer to the license.txt file included.
-
-#pragma once
-
-#include <string>
-
-#include "InputCommon/ControllerEmu/Setting/Setting.h"
-#include "InputCommon/ControllerInterface/Device.h"
-
-namespace ControllerEmu
-{
-class BooleanSetting
-{
-public:
- BooleanSetting(const std::string& setting_name, const std::string& ui_name,
- const bool default_value, const SettingType setting_type = SettingType::NORMAL,
- const bool exclusive = false);
- BooleanSetting(const std::string& setting_name, const bool default_value,
- const SettingType setting_type = SettingType::NORMAL,
- const bool exclusive = false);
-
- bool GetValue() const;
- void SetValue(bool value);
- bool IsExclusive() const;
-
- const SettingType m_type;
- const std::string m_name;
- const std::string m_ui_name;
- const bool m_default_value;
- bool m_value;
-
-private:
- const bool m_exclusive;
-};
-
-} // namespace ControllerEmu
diff --git a/Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.cpp b/Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.cpp
index a15dd13f2f..3459040824 100644
--- a/Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.cpp
+++ b/Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.cpp
@@ -6,20 +6,35 @@
namespace ControllerEmu
{
-NumericSetting::NumericSetting(const std::string& setting_name, const ControlState default_value,
- const u32 low, const u32 high, const SettingType setting_type)
- : m_type(setting_type), m_name(setting_name), m_default_value(default_value), m_low(low),
- m_high(high), m_value(default_value)
+NumericSettingBase::NumericSettingBase(const NumericSettingDetails& details) : m_details(details)
{
}
-ControlState NumericSetting::GetValue() const
+const char* NumericSettingBase::GetUIName() const
{
- return m_value;
+ return m_details.ui_name;
}
-void NumericSetting::SetValue(ControlState value)
+
+const char* NumericSettingBase::GetUISuffix() const
+{
+ return m_details.ui_suffix;
+}
+
+const char* NumericSettingBase::GetUIDescription() const
+{
+ return m_details.ui_description;
+}
+
+template <>
+SettingType NumericSetting<double>::GetType() const
+{
+ return SettingType::Double;
+}
+
+template <>
+SettingType NumericSetting<bool>::GetType() const
{
- m_value = value;
+ return SettingType::Bool;
}
} // namespace ControllerEmu
diff --git a/Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.h b/Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.h
index 2e84d383ba..ccc46634ed 100644
--- a/Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.h
+++ b/Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.h
@@ -4,29 +4,127 @@
#pragma once
+#include <atomic>
#include <string>
#include "Common/CommonTypes.h"
-#include "InputCommon/ControllerEmu/Setting/Setting.h"
+#include "Common/IniFile.h"
#include "InputCommon/ControllerInterface/Device.h"
namespace ControllerEmu
{
-class NumericSetting
+enum class SettingType
+{
+ Double,
+ Bool,
+};
+
+struct NumericSettingDetails
+{
+ NumericSettingDetails(const char* const _ini_name, const char* const _ui_suffix = nullptr,
+ const char* const _ui_description = nullptr,
+ const char* const _ui_name = nullptr)
+ : ini_name(_ini_name), ui_suffix(_ui_suffix), ui_description(_ui_description),
+ ui_name(_ui_name ? _ui_name : _ini_name)
+ {
+ }
+
+ // The name used in ini files.
+ const char* const ini_name;
+
+ // A string applied to the number in the UI (unit of measure).
+ const char* const ui_suffix;
+
+ // Detailed description of the setting.
+ const char* const ui_description;
+
+ // The name used in the UI (if different from ini file).
+ const char* const ui_name;
+};
+
+class NumericSettingBase
{
public:
- NumericSetting(const std::string& setting_name, const ControlState default_value,
- const u32 low = 0, const u32 high = 100,
- const SettingType setting_type = SettingType::NORMAL);
-
- ControlState GetValue() const;
- void SetValue(ControlState value);
- const SettingType m_type;
- const std::string m_name;
- const ControlState m_default_value;
- const u32 m_low;
- const u32 m_high;
- ControlState m_value;
+ NumericSettingBase(const NumericSettingDetails& details);
+
+ virtual ~NumericSettingBase() = default;
+
+ virtual void LoadFromIni(const IniFile::Section& section, const std::string& group_name) = 0;
+ virtual void SaveToIni(IniFile::Section& section, const std::string& group_name) const = 0;
+
+ virtual SettingType GetType() const = 0;
+
+ const char* GetUIName() const;
+ const char* GetUISuffix() const;
+ const char* GetUIDescription() const;
+
+protected:
+ NumericSettingDetails m_details;
+};
+
+template <typename T>
+class SettingValue;
+
+template <typename T>
+class NumericSetting : public NumericSettingBase
+{
+public:
+ using ValueType = T;
+
+ static_assert(std::is_same<ValueType, double>() || std::is_same<ValueType, bool>(),
+ "NumericSetting is only implemented for double and bool.");
+
+ NumericSetting(SettingValue<ValueType>* value, const NumericSettingDetails& details,
+ ValueType default_value, ValueType min_value, ValueType max_value)
+ : NumericSettingBase(details), m_value(*value), m_default_value(default_value),
+ m_min_value(min_value), m_max_value(max_value)
+ {
+ }
+
+ void LoadFromIni(const IniFile::Section& section, const std::string& group_name) override
+ {
+ ValueType value;
+ section.Get(group_name + m_details.ini_name, &value, m_default_value);
+ SetValue(value);
+ }
+
+ void SaveToIni(IniFile::Section& section, const std::string& group_name) const override
+ {
+ section.Set(group_name + m_details.ini_name, GetValue(), m_default_value);
+ }
+
+ ValueType GetValue() const { return m_value.GetValue(); }
+ void SetValue(ValueType value) { m_value.SetValue(value); }
+
+ ValueType GetDefaultValue() const { return m_default_value; }
+ ValueType GetMinValue() const { return m_min_value; }
+ ValueType GetMaxValue() const { return m_max_value; }
+
+ SettingType GetType() const override;
+
+private:
+ SettingValue<ValueType>& m_value;
+
+ const ValueType m_default_value;
+ const ValueType m_min_value;
+ const ValueType m_max_value;
+};
+
+template <typename T>
+class SettingValue
+{
+ using ValueType = T;
+
+ friend class NumericSetting<T>;
+
+public:
+ ValueType GetValue() const { return m_value; }
+
+private:
+ void SetValue(ValueType value) { m_value = value; }
+
+ // Values are R/W by both UI and CPU threads.
+ std::atomic<ValueType> m_value;
};
} // namespace ControllerEmu
diff --git a/Source/Core/InputCommon/ControllerEmu/Setting/Setting.h b/Source/Core/InputCommon/ControllerEmu/Setting/Setting.h
deleted file mode 100644
index 955e3d8c8b..0000000000
--- a/Source/Core/InputCommon/ControllerEmu/Setting/Setting.h
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright 2017 Dolphin Emulator Project
-// Licensed under GPLv2+
-// Refer to the license.txt file included.
-
-#pragma once
-
-namespace ControllerEmu
-{
-enum class SettingType
-{
- NORMAL, // normal settings are saved to configuration files
- VIRTUAL, // virtual settings are not saved at all
-};
-
-} // namespace ControllerEmu