From 85e175472841689c1f0b60bd8d78f9d2215f3bf8 Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Wed, 13 Sep 2023 13:30:23 -0400 Subject: [PATCH 01/12] android/config: Remove uncaught usage of stoul --- src/android/app/src/main/jni/config.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/app/src/main/jni/config.cpp b/src/android/app/src/main/jni/config.cpp index 34b425cb4..81120ab0f 100644 --- a/src/android/app/src/main/jni/config.cpp +++ b/src/android/app/src/main/jni/config.cpp @@ -282,7 +282,7 @@ void Config::ReadValues() { std::stringstream ss(title_list); std::string line; while (std::getline(ss, line, '|')) { - const auto title_id = std::stoul(line, nullptr, 16); + const auto title_id = std::strtoul(line.c_str(), nullptr, 16); const auto disabled_list = config->Get("AddOns", "disabled_" + line, ""); std::stringstream inner_ss(disabled_list); From 0098ecb6090b767f13683136c28fee97b8b127c7 Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Wed, 13 Sep 2023 13:31:46 -0400 Subject: [PATCH 02/12] settings: Retro-port Citra Settings work This has yet to be PR'd on Citra, but regressions on yuzu that have been fixed in Citra needed to appear here. --- src/common/settings_common.h | 10 ++++++++++ src/common/settings_setting.h | 36 +++++++++++++++++++++++++++-------- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/common/settings_common.h b/src/common/settings_common.h index 5b170dfd5..067234aab 100644 --- a/src/common/settings_common.h +++ b/src/common/settings_common.h @@ -225,6 +225,16 @@ public: */ [[nodiscard]] virtual constexpr u32 EnumIndex() const = 0; + /** + * @returns True if the underlying type is a floating point storage + */ + [[nodiscard]] virtual constexpr bool IsFloatingPoint() const = 0; + + /** + * @returns True if the underlying type is a integer storage + */ + [[nodiscard]] virtual constexpr bool IsIntegral() const = 0; + /* * Switchable settings */ diff --git a/src/common/settings_setting.h b/src/common/settings_setting.h index e10843c73..79d2b715f 100644 --- a/src/common/settings_setting.h +++ b/src/common/settings_setting.h @@ -10,6 +10,7 @@ #include #include #include +#include #include "common/common_types.h" #include "common/settings_common.h" #include "common/settings_enums.h" @@ -112,11 +113,12 @@ protected: return value_.has_value() ? std::to_string(*value_) : "none"; } else if constexpr (std::is_same_v) { return value_ ? "true" : "false"; - } else if constexpr (std::is_same_v) { - // Compatibility with old AudioEngine setting being a string - return CanonicalizeEnum(value_); + } else if constexpr (std::is_floating_point_v) { + return fmt::format("{:f}", value_); + } else if constexpr (std::is_enum_v) { + return std::to_string(static_cast(value_)); } else { - return std::to_string(static_cast(value_)); + return std::to_string(value_); } } @@ -180,13 +182,15 @@ public: this->SetValue(static_cast(std::stoul(input))); } else if constexpr (std::is_same_v) { this->SetValue(input == "true"); - } else if constexpr (std::is_same_v) { - this->SetValue(ToEnum(input)); + } else if constexpr (std::is_same_v) { + this->SetValue(std::stof(input)); } else { this->SetValue(static_cast(std::stoll(input))); } } catch (std::invalid_argument&) { this->SetValue(this->GetDefault()); + } catch (std::out_of_range&) { + this->SetValue(this->GetDefault()); } } @@ -215,11 +219,27 @@ public: } } + [[nodiscard]] constexpr bool IsFloatingPoint() const final { + return std::is_floating_point_v; + } + + [[nodiscard]] constexpr bool IsIntegral() const final { + return std::is_integral_v; + } + [[nodiscard]] std::string MinVal() const override final { - return this->ToString(minimum); + if constexpr (std::is_arithmetic_v && !ranged) { + return this->ToString(std::numeric_limits::min()); + } else { + return this->ToString(minimum); + } } [[nodiscard]] std::string MaxVal() const override final { - return this->ToString(maximum); + if constexpr (std::is_arithmetic_v && !ranged) { + return this->ToString(std::numeric_limits::max()); + } else { + return this->ToString(maximum); + } } [[nodiscard]] constexpr bool Ranged() const override { From 7f98f4a38bf206bef9a838f6195ae3e0c6271070 Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Wed, 13 Sep 2023 13:32:14 -0400 Subject: [PATCH 03/12] key_manager: Remove uncaught usage of stoul --- src/core/crypto/key_manager.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/crypto/key_manager.cpp b/src/core/crypto/key_manager.cpp index e13c5cdc7..43a3c5ffd 100644 --- a/src/core/crypto/key_manager.cpp +++ b/src/core/crypto/key_manager.cpp @@ -724,14 +724,14 @@ void KeyManager::LoadFromFile(const std::filesystem::path& file_path, bool is_ti continue; } - const auto index = std::stoul(out[0].substr(8, 2), nullptr, 16); + const auto index = std::strtoul(out[0].substr(8, 2).c_str(), nullptr, 16); keyblobs[index] = Common::HexStringToArray<0x90>(out[1]); } else if (out[0].compare(0, 18, "encrypted_keyblob_") == 0) { if (!ValidCryptoRevisionString(out[0], 18, 2)) { continue; } - const auto index = std::stoul(out[0].substr(18, 2), nullptr, 16); + const auto index = std::strtoul(out[0].substr(18, 2).c_str(), nullptr, 16); encrypted_keyblobs[index] = Common::HexStringToArray<0xB0>(out[1]); } else if (out[0].compare(0, 20, "eticket_extended_kek") == 0) { eticket_extended_kek = Common::HexStringToArray<576>(out[1]); @@ -750,7 +750,7 @@ void KeyManager::LoadFromFile(const std::filesystem::path& file_path, bool is_ti } if (out[0].compare(0, kv.second.size(), kv.second) == 0) { const auto index = - std::stoul(out[0].substr(kv.second.size(), 2), nullptr, 16); + std::strtoul(out[0].substr(kv.second.size(), 2).c_str(), nullptr, 16); const auto sub = kv.first.second; if (sub == 0) { s128_keys[{kv.first.first, index, 0}] = @@ -770,7 +770,7 @@ void KeyManager::LoadFromFile(const std::filesystem::path& file_path, bool is_ti const auto& match = kak_names[j]; if (out[0].compare(0, std::strlen(match), match) == 0) { const auto index = - std::stoul(out[0].substr(std::strlen(match), 2), nullptr, 16); + std::strtoul(out[0].substr(std::strlen(match), 2).c_str(), nullptr, 16); s128_keys[{S128KeyType::KeyArea, index, j}] = Common::HexStringToArray<16>(out[1]); } From 22be3008f88ed147145c21566c6ae1ac91985683 Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Wed, 13 Sep 2023 13:32:48 -0400 Subject: [PATCH 04/12] ips_layer: Remove uncaught usage of stoul/ll --- src/core/file_sys/ips_layer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/file_sys/ips_layer.cpp b/src/core/file_sys/ips_layer.cpp index efdf18cee..7be1322cc 100644 --- a/src/core/file_sys/ips_layer.cpp +++ b/src/core/file_sys/ips_layer.cpp @@ -165,7 +165,7 @@ static std::string EscapeStringSequences(std::string in) { void IPSwitchCompiler::ParseFlag(const std::string& line) { if (StartsWith(line, "@flag offset_shift ")) { // Offset Shift Flag - offset_shift = std::stoll(line.substr(19), nullptr, 0); + offset_shift = std::strtoll(line.substr(19).c_str(), nullptr, 0); } else if (StartsWith(line, "@little-endian")) { // Set values to read as little endian is_little_endian = true; @@ -263,7 +263,7 @@ void IPSwitchCompiler::Parse() { // 11 - 8 hex digit offset + space + minimum two digit overwrite val if (patch_line.length() < 11) break; - auto offset = std::stoul(patch_line.substr(0, 8), nullptr, 16); + auto offset = std::strtoul(patch_line.substr(0, 8).c_str(), nullptr, 16); offset += static_cast(offset_shift); std::vector replace; From 0eef4a6c948d020b9c9ae7aa5a314ff5b7c04c27 Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Wed, 13 Sep 2023 13:51:58 -0400 Subject: [PATCH 05/12] cheat_engine: Remove uncaught usage of stoul --- src/core/memory/cheat_engine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/memory/cheat_engine.cpp b/src/core/memory/cheat_engine.cpp index 7b52f61a7..a06e99166 100644 --- a/src/core/memory/cheat_engine.cpp +++ b/src/core/memory/cheat_engine.cpp @@ -154,7 +154,7 @@ std::vector TextCheatParser::Parse(std::string_view data) const { return {}; } - const auto value = static_cast(std::stoul(hex, nullptr, 0x10)); + const auto value = static_cast(std::strtoul(hex.c_str(), nullptr, 0x10)); out[*current_entry].definition.opcodes[out[*current_entry].definition.num_opcodes++] = value; From 2d2c176f030fd9c0559a2cf983296e16c4b835c7 Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Wed, 13 Sep 2023 13:34:01 -0400 Subject: [PATCH 06/12] configure_ui: Remove unnecessary usage of stoul --- src/yuzu/configuration/configure_ui.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/yuzu/configuration/configure_ui.cpp b/src/yuzu/configuration/configure_ui.cpp index 34ab01617..a9fde9f4f 100644 --- a/src/yuzu/configuration/configure_ui.cpp +++ b/src/yuzu/configuration/configure_ui.cpp @@ -4,6 +4,7 @@ #include "yuzu/configuration/configure_ui.h" #include +#include #include #include #include @@ -94,11 +95,7 @@ static void PopulateResolutionComboBox(QComboBox* screenshot_height, QWidget* pa } static u32 ScreenshotDimensionToInt(const QString& height) { - try { - return std::stoi(height.toStdString()); - } catch (std::invalid_argument&) { - return 0; - } + return std::strtoul(height.toUtf8(), nullptr, 0); } ConfigureUi::ConfigureUi(Core::System& system_, QWidget* parent) From 3ae3706c847431089389721e2873bc9a0549d6d9 Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Wed, 13 Sep 2023 13:50:25 -0400 Subject: [PATCH 07/12] shared_widget: Forward-port Citra changes Seemed like a good time to move these over. Also remove usage of std::sto{l,ll,ul,f,d} --- src/yuzu/configuration/shared_widget.cpp | 157 ++++++++++++++++++----- src/yuzu/configuration/shared_widget.h | 8 ++ 2 files changed, 134 insertions(+), 31 deletions(-) diff --git a/src/yuzu/configuration/shared_widget.cpp b/src/yuzu/configuration/shared_widget.cpp index d63093985..e5e071386 100644 --- a/src/yuzu/configuration/shared_widget.cpp +++ b/src/yuzu/configuration/shared_widget.cpp @@ -151,7 +151,7 @@ QWidget* Widget::CreateCombobox(std::function& serializer, return -1; }; - const u32 setting_value = std::stoi(setting.ToString()); + const u32 setting_value = std::strtoul(setting.ToString().c_str(), nullptr, 0); combobox->setCurrentIndex(find_index(setting_value)); serializer = [this, enumeration]() { @@ -160,7 +160,7 @@ QWidget* Widget::CreateCombobox(std::function& serializer, }; restore_func = [this, find_index]() { - const u32 global_value = std::stoi(RelevantDefault(setting)); + const u32 global_value = std::strtoul(RelevantDefault(setting).c_str(), nullptr, 0); combobox->setCurrentIndex(find_index(global_value)); }; @@ -209,7 +209,7 @@ QWidget* Widget::CreateRadioGroup(std::function& serializer, } }; - const u32 setting_value = std::stoi(setting.ToString()); + const u32 setting_value = std::strtoul(setting.ToString().c_str(), nullptr, 0); set_index(setting_value); serializer = [get_selected]() { @@ -218,7 +218,7 @@ QWidget* Widget::CreateRadioGroup(std::function& serializer, }; restore_func = [this, set_index]() { - const u32 global_value = std::stoi(RelevantDefault(setting)); + const u32 global_value = std::strtoul(RelevantDefault(setting).c_str(), nullptr, 0); set_index(global_value); }; @@ -255,6 +255,58 @@ QWidget* Widget::CreateLineEdit(std::function& serializer, return line_edit; } +static void CreateIntSlider(Settings::BasicSetting& setting, bool reversed, float multiplier, + QLabel* feedback, const QString& use_format, QSlider* slider, + std::function& serializer, + std::function& restore_func) { + int max_val = std::strtol(setting.MaxVal().c_str(), nullptr, 0); + + const auto update_feedback = [=](int value) { + int present = (reversed ? max_val - value : value) * multiplier + 0.5f; + feedback->setText(use_format.arg(QVariant::fromValue(present).value())); + }; + + QObject::connect(slider, &QAbstractSlider::valueChanged, update_feedback); + update_feedback(std::strtol(setting.ToString().c_str(), nullptr, 0)); + + slider->setMinimum(std::strtol(setting.MinVal().c_str(), nullptr, 0)); + slider->setMaximum(max_val); + slider->setValue(std::strtol(setting.ToString().c_str(), nullptr, 0)); + + serializer = [slider]() { return std::to_string(slider->value()); }; + restore_func = [slider, &setting]() { + slider->setValue(std::strtol(RelevantDefault(setting).c_str(), nullptr, 0)); + }; +} + +static void CreateFloatSlider(Settings::BasicSetting& setting, bool reversed, float multiplier, + QLabel* feedback, const QString& use_format, QSlider* slider, + std::function& serializer, + std::function& restore_func) { + float max_val = std::strtof(setting.MaxVal().c_str(), nullptr); + float min_val = std::strtof(setting.MinVal().c_str(), nullptr); + float use_multiplier = multiplier == default_multiplier ? default_float_multiplier : multiplier; + + const auto update_feedback = [=](float value) { + int present = (reversed ? max_val - value : value) + 0.5f; + feedback->setText(use_format.arg(QVariant::fromValue(present).value())); + }; + + QObject::connect(slider, &QAbstractSlider::valueChanged, update_feedback); + update_feedback(std::strtof(setting.ToString().c_str(), nullptr)); + + slider->setMinimum(min_val * use_multiplier); + slider->setMaximum(max_val * use_multiplier); + slider->setValue(std::strtof(setting.ToString().c_str(), nullptr) * use_multiplier); + + serializer = [slider, use_multiplier]() { + return std::to_string(slider->value() / use_multiplier); + }; + restore_func = [slider, &setting, use_multiplier]() { + slider->setValue(std::strtof(RelevantDefault(setting).c_str(), nullptr) * use_multiplier); + }; +} + QWidget* Widget::CreateSlider(bool reversed, float multiplier, const QString& given_suffix, std::function& serializer, std::function& restore_func, @@ -278,27 +330,20 @@ QWidget* Widget::CreateSlider(bool reversed, float multiplier, const QString& gi layout->setContentsMargins(0, 0, 0, 0); - int max_val = std::stoi(setting.MaxVal()); - QString suffix = given_suffix == QStringLiteral("") ? DefaultSuffix(this, setting) : given_suffix; const QString use_format = QStringLiteral("%1").append(suffix); - QObject::connect(slider, &QAbstractSlider::valueChanged, [=](int value) { - int present = (reversed ? max_val - value : value) * multiplier + 0.5f; - feedback->setText(use_format.arg(QVariant::fromValue(present).value())); - }); - - slider->setMinimum(std::stoi(setting.MinVal())); - slider->setMaximum(max_val); - slider->setValue(std::stoi(setting.ToString())); + if (setting.IsIntegral()) { + CreateIntSlider(setting, reversed, multiplier, feedback, use_format, slider, serializer, + restore_func); + } else { + CreateFloatSlider(setting, reversed, multiplier, feedback, use_format, slider, serializer, + restore_func); + } slider->setInvertedAppearance(reversed); - slider->setInvertedControls(reversed); - - serializer = [this]() { return std::to_string(slider->value()); }; - restore_func = [this]() { slider->setValue(std::stoi(RelevantDefault(setting))); }; if (!Settings::IsConfiguringGlobal()) { QObject::connect(slider, &QAbstractSlider::actionTriggered, [touch]() { touch(); }); @@ -311,11 +356,9 @@ QWidget* Widget::CreateSpinBox(const QString& given_suffix, std::function& serializer, std::function& restore_func, const std::function& touch) { - const int min_val = - setting.Ranged() ? std::stoi(setting.MinVal()) : std::numeric_limits::min(); - const int max_val = - setting.Ranged() ? std::stoi(setting.MaxVal()) : std::numeric_limits::max(); - const int default_val = std::stoi(setting.ToString()); + const auto min_val = std::strtol(setting.MinVal().c_str(), nullptr, 0); + const auto max_val = std::strtol(setting.MaxVal().c_str(), nullptr, 0); + const auto default_val = std::strtol(setting.ToString().c_str(), nullptr, 0); QString suffix = given_suffix == QStringLiteral("") ? DefaultSuffix(this, setting) : given_suffix; @@ -329,13 +372,13 @@ QWidget* Widget::CreateSpinBox(const QString& given_suffix, serializer = [this]() { return std::to_string(spinbox->value()); }; restore_func = [this]() { - auto value{std::stol(RelevantDefault(setting))}; + auto value{std::strtol(RelevantDefault(setting).c_str(), nullptr, 0)}; spinbox->setValue(value); }; if (!Settings::IsConfiguringGlobal()) { QObject::connect(spinbox, QOverload::of(&QSpinBox::valueChanged), [this, touch]() { - if (spinbox->value() != std::stoi(setting.ToStringGlobal())) { + if (spinbox->value() != std::strtol(setting.ToStringGlobal().c_str(), nullptr, 0)) { touch(); } }); @@ -344,6 +387,43 @@ QWidget* Widget::CreateSpinBox(const QString& given_suffix, return spinbox; } +QWidget* Widget::CreateDoubleSpinBox(const QString& given_suffix, + std::function& serializer, + std::function& restore_func, + const std::function& touch) { + const auto min_val = std::strtod(setting.MinVal().c_str(), nullptr); + const auto max_val = std::strtod(setting.MaxVal().c_str(), nullptr); + const auto default_val = std::strtod(setting.ToString().c_str(), nullptr); + + QString suffix = + given_suffix == QStringLiteral("") ? DefaultSuffix(this, setting) : given_suffix; + + double_spinbox = new QDoubleSpinBox(this); + double_spinbox->setRange(min_val, max_val); + double_spinbox->setValue(default_val); + double_spinbox->setSuffix(suffix); + double_spinbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + + serializer = [this]() { return fmt::format("{:f}", double_spinbox->value()); }; + + restore_func = [this]() { + auto value{std::strtod(RelevantDefault(setting).c_str(), nullptr)}; + double_spinbox->setValue(value); + }; + + if (!Settings::IsConfiguringGlobal()) { + QObject::connect(double_spinbox, QOverload::of(&QDoubleSpinBox::valueChanged), + [this, touch]() { + if (double_spinbox->value() != + std::strtod(setting.ToStringGlobal().c_str(), nullptr)) { + touch(); + } + }); + } + + return double_spinbox; +} + QWidget* Widget::CreateHexEdit(std::function& serializer, std::function& restore_func, const std::function& touch) { @@ -353,7 +433,8 @@ QWidget* Widget::CreateHexEdit(std::function& serializer, } auto to_hex = [=](const std::string& input) { - return QString::fromStdString(fmt::format("{:08x}", std::stoul(input))); + return QString::fromStdString( + fmt::format("{:08x}", std::strtoul(input.c_str(), nullptr, 0))); }; QRegularExpressionValidator* regex = new QRegularExpressionValidator( @@ -366,7 +447,7 @@ QWidget* Widget::CreateHexEdit(std::function& serializer, line_edit->setValidator(regex); auto hex_to_dec = [this]() -> std::string { - return std::to_string(std::stoul(line_edit->text().toStdString(), nullptr, 16)); + return std::to_string(std::strtoul(line_edit->text().toStdString().c_str(), nullptr, 16)); }; serializer = [hex_to_dec]() { return hex_to_dec(); }; @@ -386,7 +467,8 @@ QWidget* Widget::CreateDateTimeEdit(bool disabled, bool restrict, std::function& restore_func, const std::function& touch) { const long long current_time = QDateTime::currentSecsSinceEpoch(); - const s64 the_time = disabled ? current_time : std::stoll(setting.ToString()); + const s64 the_time = + disabled ? current_time : std::strtoll(setting.ToString().c_str(), nullptr, 0); const auto default_val = QDateTime::fromSecsSinceEpoch(the_time); date_time_edit = new QDateTimeEdit(this); @@ -399,7 +481,7 @@ QWidget* Widget::CreateDateTimeEdit(bool disabled, bool restrict, auto get_clear_val = [this, restrict, current_time]() { return QDateTime::fromSecsSinceEpoch([this, restrict, current_time]() { if (restrict && checkbox->checkState() == Qt::Checked) { - return std::stoll(RelevantDefault(setting)); + return std::strtoll(RelevantDefault(setting).c_str(), nullptr, 0); } return current_time; }()); @@ -506,8 +588,7 @@ void Widget::SetupComponent(const QString& label, std::function& load_fu } else { data_component = CreateCombobox(serializer, restore_func, touch); } - } else if (type == typeid(u32) || type == typeid(int) || type == typeid(u16) || - type == typeid(s64) || type == typeid(u8)) { + } else if (setting.IsIntegral()) { switch (request) { case RequestType::Slider: case RequestType::ReverseSlider: @@ -534,6 +615,20 @@ void Widget::SetupComponent(const QString& label, std::function& load_fu default: UNIMPLEMENTED(); } + } else if (setting.IsFloatingPoint()) { + switch (request) { + case RequestType::Default: + case RequestType::SpinBox: + data_component = CreateDoubleSpinBox(suffix, serializer, restore_func, touch); + break; + case RequestType::Slider: + case RequestType::ReverseSlider: + data_component = CreateSlider(request == RequestType::ReverseSlider, multiplier, suffix, + serializer, restore_func, touch); + break; + default: + UNIMPLEMENTED(); + } } else if (type == typeid(std::string)) { switch (request) { case RequestType::Default: diff --git a/src/yuzu/configuration/shared_widget.h b/src/yuzu/configuration/shared_widget.h index 5303dd898..86edaacc8 100644 --- a/src/yuzu/configuration/shared_widget.h +++ b/src/yuzu/configuration/shared_widget.h @@ -22,6 +22,7 @@ class QObject; class QPushButton; class QSlider; class QSpinBox; +class QDoubleSpinBox; class QRadioButton; namespace Settings { @@ -43,6 +44,9 @@ enum class RequestType { MaxEnum, }; +constexpr const float default_multiplier{1.f}; +constexpr const float default_float_multiplier{100.f}; + class Widget : public QWidget { Q_OBJECT @@ -89,6 +93,7 @@ public: QPushButton* restore_button{}; ///< Restore button for custom configurations QLineEdit* line_edit{}; ///< QLineEdit, used for LineEdit and HexEdit QSpinBox* spinbox{}; + QDoubleSpinBox* double_spinbox{}; QCheckBox* checkbox{}; QSlider* slider{}; QComboBox* combobox{}; @@ -126,6 +131,9 @@ private: const std::function& touch); QWidget* CreateSpinBox(const QString& suffix, std::function& serializer, std::function& restore_func, const std::function& touch); + QWidget* CreateDoubleSpinBox(const QString& suffix, std::function& serializer, + std::function& restore_func, + const std::function& touch); QWidget* parent; const TranslationMap& translations; From 5ffa1049ae639215f4885684a39607875cb9497b Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Wed, 13 Sep 2023 13:35:36 -0400 Subject: [PATCH 08/12] cmd/config: Remove uncaught usage of stoul --- src/yuzu_cmd/config.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/yuzu_cmd/config.cpp b/src/yuzu_cmd/config.cpp index c42d98709..0d25ff400 100644 --- a/src/yuzu_cmd/config.cpp +++ b/src/yuzu_cmd/config.cpp @@ -259,7 +259,7 @@ void Config::ReadValues() { std::stringstream ss(title_list); std::string line; while (std::getline(ss, line, '|')) { - const auto title_id = std::stoul(line, nullptr, 16); + const auto title_id = std::strtoul(line.c_str(), nullptr, 16); const auto disabled_list = sdl2_config->Get("AddOns", "disabled_" + line, ""); std::stringstream inner_ss(disabled_list); From c2961454fe006265454448ecce3f0a34834ec691 Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Wed, 13 Sep 2023 13:36:09 -0400 Subject: [PATCH 09/12] cmd/yuzu: Remove uncaught usage of stoi Also fixes a style inconsistency --- src/yuzu_cmd/yuzu.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/yuzu_cmd/yuzu.cpp b/src/yuzu_cmd/yuzu.cpp index 55d0938f7..087cfaa26 100644 --- a/src/yuzu_cmd/yuzu.cpp +++ b/src/yuzu_cmd/yuzu.cpp @@ -264,8 +264,9 @@ int main(int argc, char** argv) { nickname = match[1]; password = match[2]; address = match[3]; - if (!match[4].str().empty()) - port = static_cast(std::stoi(match[4])); + if (!match[4].str().empty()) { + port = static_cast(std::strtoul(match[4].str().c_str(), nullptr, 0)); + } std::regex nickname_re("^[a-zA-Z0-9._\\- ]+$"); if (!std::regex_match(nickname, nickname_re)) { std::cout From fe70c6f4812a7c8076be3d8c12cc914f7c3b6d19 Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Wed, 13 Sep 2023 15:59:44 -0400 Subject: [PATCH 10/12] settings_setting: Don't remove the AudioEngine workaround --- src/common/settings_setting.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/common/settings_setting.h b/src/common/settings_setting.h index 79d2b715f..7be6f26f7 100644 --- a/src/common/settings_setting.h +++ b/src/common/settings_setting.h @@ -113,6 +113,9 @@ protected: return value_.has_value() ? std::to_string(*value_) : "none"; } else if constexpr (std::is_same_v) { return value_ ? "true" : "false"; + } else if constexpr (std::is_same_v) { + // Compatibility with old AudioEngine setting being a string + return CanonicalizeEnum(value_); } else if constexpr (std::is_floating_point_v) { return fmt::format("{:f}", value_); } else if constexpr (std::is_enum_v) { From fea5b758bce5f886f6ccadd5736a4ba2c17514cb Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Thu, 14 Sep 2023 11:30:14 -0400 Subject: [PATCH 11/12] settings_common: Fix typo --- src/common/settings_common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/settings_common.h b/src/common/settings_common.h index 067234aab..1800ab10d 100644 --- a/src/common/settings_common.h +++ b/src/common/settings_common.h @@ -231,7 +231,7 @@ public: [[nodiscard]] virtual constexpr bool IsFloatingPoint() const = 0; /** - * @returns True if the underlying type is a integer storage + * @returns True if the underlying type is an integer storage */ [[nodiscard]] virtual constexpr bool IsIntegral() const = 0; From 5d52d73c4b2781fd99260534c17e35640ab17589 Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Thu, 14 Sep 2023 11:31:26 -0400 Subject: [PATCH 12/12] shared_widget: Use default literals more --- src/yuzu/configuration/shared_widget.cpp | 26 +++++++++++------------- src/yuzu/configuration/shared_widget.h | 17 +++++++++------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/yuzu/configuration/shared_widget.cpp b/src/yuzu/configuration/shared_widget.cpp index e5e071386..ea8d7add4 100644 --- a/src/yuzu/configuration/shared_widget.cpp +++ b/src/yuzu/configuration/shared_widget.cpp @@ -63,7 +63,7 @@ static QString DefaultSuffix(QWidget* parent, Settings::BasicSetting& setting) { return tr("%", context.c_str()); } - return QStringLiteral(""); + return default_suffix; } QPushButton* Widget::CreateRestoreGlobalButton(bool using_global, QWidget* parent) { @@ -71,7 +71,7 @@ QPushButton* Widget::CreateRestoreGlobalButton(bool using_global, QWidget* paren QStyle* style = parent->style(); QIcon* icon = new QIcon(style->standardIcon(QStyle::SP_LineEditClearButton)); - QPushButton* restore_button = new QPushButton(*icon, QStringLiteral(""), parent); + QPushButton* restore_button = new QPushButton(*icon, QStringLiteral(), parent); restore_button->setObjectName(QStringLiteral("RestoreButton%1").arg(restore_button_count)); restore_button->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); @@ -259,7 +259,7 @@ static void CreateIntSlider(Settings::BasicSetting& setting, bool reversed, floa QLabel* feedback, const QString& use_format, QSlider* slider, std::function& serializer, std::function& restore_func) { - int max_val = std::strtol(setting.MaxVal().c_str(), nullptr, 0); + const int max_val = std::strtol(setting.MaxVal().c_str(), nullptr, 0); const auto update_feedback = [=](int value) { int present = (reversed ? max_val - value : value) * multiplier + 0.5f; @@ -283,9 +283,10 @@ static void CreateFloatSlider(Settings::BasicSetting& setting, bool reversed, fl QLabel* feedback, const QString& use_format, QSlider* slider, std::function& serializer, std::function& restore_func) { - float max_val = std::strtof(setting.MaxVal().c_str(), nullptr); - float min_val = std::strtof(setting.MinVal().c_str(), nullptr); - float use_multiplier = multiplier == default_multiplier ? default_float_multiplier : multiplier; + const float max_val = std::strtof(setting.MaxVal().c_str(), nullptr); + const float min_val = std::strtof(setting.MinVal().c_str(), nullptr); + const float use_multiplier = + multiplier == default_multiplier ? default_float_multiplier : multiplier; const auto update_feedback = [=](float value) { int present = (reversed ? max_val - value : value) + 0.5f; @@ -330,8 +331,7 @@ QWidget* Widget::CreateSlider(bool reversed, float multiplier, const QString& gi layout->setContentsMargins(0, 0, 0, 0); - QString suffix = - given_suffix == QStringLiteral("") ? DefaultSuffix(this, setting) : given_suffix; + QString suffix = given_suffix == default_suffix ? DefaultSuffix(this, setting) : given_suffix; const QString use_format = QStringLiteral("%1").append(suffix); @@ -360,8 +360,7 @@ QWidget* Widget::CreateSpinBox(const QString& given_suffix, const auto max_val = std::strtol(setting.MaxVal().c_str(), nullptr, 0); const auto default_val = std::strtol(setting.ToString().c_str(), nullptr, 0); - QString suffix = - given_suffix == QStringLiteral("") ? DefaultSuffix(this, setting) : given_suffix; + QString suffix = given_suffix == default_suffix ? DefaultSuffix(this, setting) : given_suffix; spinbox = new QSpinBox(this); spinbox->setRange(min_val, max_val); @@ -395,8 +394,7 @@ QWidget* Widget::CreateDoubleSpinBox(const QString& given_suffix, const auto max_val = std::strtod(setting.MaxVal().c_str(), nullptr); const auto default_val = std::strtod(setting.ToString().c_str(), nullptr); - QString suffix = - given_suffix == QStringLiteral("") ? DefaultSuffix(this, setting) : given_suffix; + QString suffix = given_suffix == default_suffix ? DefaultSuffix(this, setting) : given_suffix; double_spinbox = new QDoubleSpinBox(this); double_spinbox->setRange(min_val, max_val); @@ -733,10 +731,10 @@ Widget::Widget(Settings::BasicSetting* setting_, const TranslationMap& translati return std::pair{translations.at(id).first, translations.at(id).second}; } LOG_WARNING(Frontend, "Translation table lacks entry for \"{}\"", setting_label); - return std::pair{QString::fromStdString(setting_label), QStringLiteral("")}; + return std::pair{QString::fromStdString(setting_label), QStringLiteral()}; }(); - if (label == QStringLiteral("")) { + if (label == QStringLiteral()) { LOG_DEBUG(Frontend, "Translation table has empty entry for \"{}\", skipping...", setting.GetLabel()); return; diff --git a/src/yuzu/configuration/shared_widget.h b/src/yuzu/configuration/shared_widget.h index 86edaacc8..226284cf3 100644 --- a/src/yuzu/configuration/shared_widget.h +++ b/src/yuzu/configuration/shared_widget.h @@ -44,8 +44,9 @@ enum class RequestType { MaxEnum, }; -constexpr const float default_multiplier{1.f}; -constexpr const float default_float_multiplier{100.f}; +constexpr float default_multiplier{1.f}; +constexpr float default_float_multiplier{100.f}; +static const QString default_suffix = QStringLiteral(); class Widget : public QWidget { Q_OBJECT @@ -70,8 +71,9 @@ public: const ComboboxTranslationMap& combobox_translations, QWidget* parent, bool runtime_lock, std::vector>& apply_funcs_, RequestType request = RequestType::Default, bool managed = true, - float multiplier = 1.0f, Settings::BasicSetting* other_setting = nullptr, - const QString& suffix = QStringLiteral("")); + float multiplier = default_multiplier, + Settings::BasicSetting* other_setting = nullptr, + const QString& suffix = default_suffix); virtual ~Widget(); /** @@ -153,14 +155,15 @@ public: Widget* BuildWidget(Settings::BasicSetting* setting, std::vector>& apply_funcs, RequestType request = RequestType::Default, bool managed = true, - float multiplier = 1.0f, Settings::BasicSetting* other_setting = nullptr, - const QString& suffix = QStringLiteral("")) const; + float multiplier = default_multiplier, + Settings::BasicSetting* other_setting = nullptr, + const QString& suffix = default_suffix) const; Widget* BuildWidget(Settings::BasicSetting* setting, std::vector>& apply_funcs, Settings::BasicSetting* other_setting, RequestType request = RequestType::Default, - const QString& suffix = QStringLiteral("")) const; + const QString& suffix = default_suffix) const; const ComboboxTranslationMap& ComboboxTranslations() const;