From 2a0a9d0454265b51fbad19ae33125db9027e62f7 Mon Sep 17 00:00:00 2001 From: BearOso Date: Fri, 6 Jun 2025 17:23:59 -0500 Subject: [PATCH] qt: Clean up EmuConfig a bit. --- qt/src/EmuConfig.cpp | 38 +++++++++++++++++++++---------------- qt/src/EmuConfig.hpp | 14 +++++--------- qt/src/Snes9xController.cpp | 2 +- 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/qt/src/EmuConfig.cpp b/qt/src/EmuConfig.cpp index 7d90214e..b1db5072 100644 --- a/qt/src/EmuConfig.cpp +++ b/qt/src/EmuConfig.cpp @@ -324,7 +324,7 @@ bool EmuConfig::setDefaults(int section) return restart; } -void EmuConfig::config(std::string filename, bool write) +void EmuConfig::config(const std::string &filename, bool write) { QSettings settings(QString::fromStdString(filename), QSettings::IniFormat); @@ -339,25 +339,26 @@ void EmuConfig::config(std::string filename, bool write) if (write) { - Bool = [&](std::string key, bool &value) { + Bool = [&](const std::string &key, bool &value) { settings.setValue(key, value); }; - Int = [&](std::string key, int &value) { + Int = [&](const std::string &key, int &value) { settings.setValue(key, value); }; - String = [&](std::string key, std::string &value) { + String = [&](const std::string &key, std::string &value) { settings.setValue(key, QString::fromStdString(value)); }; - Enum = [&](std::string key, int &value, std::vector map) { + Enum = [&](const std::string &key, int &value, + const std::vector &map) { settings.setValue(key, map[value]); }; - Double = [&](std::string key, double &value) { + Double = [&](const std::string &key, double &value) { settings.setValue(key, value); }; - Binding = [&](std::string key, EmuBinding &binding) { + Binding = [&](const std::string &key, EmuBinding &binding) { settings.setValue(key, QString::fromStdString(binding.to_config_string())); }; - BeginSection = [&](std::string str) { + BeginSection = [&](const std::string &str) { settings.beginGroup(str); }; EndSection = [&]() { @@ -366,27 +367,28 @@ void EmuConfig::config(std::string filename, bool write) } else { - Bool = [&](std::string key, bool &value) { + Bool = [&](const std::string &key, bool &value) { if (settings.contains(key)) value = settings.value(key).toBool(); }; - Int = [&](std::string key, int &value) { + Int = [&](const std::string &key, int &value) { if (settings.contains(key)) value = settings.value(key).toInt(); }; - String = [&](std::string key, std::string &value) { + String = [&](const std::string &key, std::string &value) { if (settings.contains(key)) value = settings.value(key).toString().toStdString(); }; - Binding = [&](std::string key, EmuBinding &binding) { + Binding = [&](const std::string &key, EmuBinding &binding) { if (settings.contains(key)) binding = EmuBinding::from_config_string(settings.value(key).toString().toStdString()); }; - Double = [&](std::string key, double &value) { + Double = [&](const std::string &key, double &value) { if (settings.contains(key)) value = settings.value(key).toDouble(); }; - Enum = [&](std::string key, int &value, std::vector map) { + Enum = [&](const std::string &key, int &value, + const std::vector &map) { QString entry; if (settings.contains(key)) @@ -403,7 +405,7 @@ void EmuConfig::config(std::string filename, bool write) } } }; - BeginSection = [&](std::string str) { + BeginSection = [&](const std::string &str) { settings.beginGroup(QString::fromStdString(str)); }; EndSection = [&]() { @@ -498,7 +500,6 @@ void EmuConfig::config(std::string filename, bool write) Enum("PortConfiguration", port_configuration, { "OneController", "TwoControllers", "Mouse", "SuperScope", "Multitap" }); EndSection(); - const char *names[] = { "Up", "Down", "Left", "Right", "A", "B", "X", "Y", "L", "R", "Start", "Select", "Turbo_A", "Turbo_B", "Turbo_X", "Turbo_Y", "Turbo_L", "Turbo_R" }; for (int c = 0; c < 5; c++) { BeginSection("Controller_" + std::to_string(c)); @@ -506,6 +507,11 @@ void EmuConfig::config(std::string filename, bool write) for (int y = 0; y < num_controller_bindings; y++) for (int x = 0; x < allowed_bindings; x++) { + const char *names[] = {"Up", "Down", "Left", "Right", + "A", "B", "X", "Y", + "L", "R", "Start", "Select", + "Turbo_A", "Turbo_B", "Turbo_X", "Turbo_Y", + "Turbo_L", "Turbo_R"}; std::string keyname = names[y] + std::to_string(x); Binding(keyname, binding.controller[c].buttons[y * allowed_bindings + x]); } diff --git a/qt/src/EmuConfig.hpp b/qt/src/EmuConfig.hpp index 17953d67..5c36cf93 100644 --- a/qt/src/EmuConfig.hpp +++ b/qt/src/EmuConfig.hpp @@ -1,6 +1,4 @@ -#ifndef __EMU_CONFIG_HPP -#define __EMU_CONFIG_HPP - +#pragma once #include #include @@ -11,12 +9,12 @@ struct EmuConfig static std::string findConfigFile(); static std::string findConfigDir(); bool setDefaults(int section = -1); - void config(std::string filename, bool write); - void loadFile(std::string filename) + void config(const std::string &filename, bool write); + void loadFile(const std::string &filename) { config(filename, false); } - void saveFile(std::string filename) + void saveFile(const std::string &filename) { config(filename, true); } @@ -242,6 +240,4 @@ struct EmuConfig eStopRecording, eSeekToFrame, }; -}; - -#endif \ No newline at end of file +}; \ No newline at end of file diff --git a/qt/src/Snes9xController.cpp b/qt/src/Snes9xController.cpp index 90a9ef68..db29e7c0 100644 --- a/qt/src/Snes9xController.cpp +++ b/qt/src/Snes9xController.cpp @@ -182,7 +182,7 @@ void Snes9xController::updateSettings(const EmuConfig * const config) high_resolution_effect = config->high_resolution_effect; - config_folder = config->findConfigDir(); + config_folder = EmuConfig::findConfigDir(); auto doFolder = [&](int location, std::string &dest, const std::string &src, const char *subfolder_name) {