From e18d68650c371776a1e5c5e8e8e3b3f9610efbc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 31 Oct 2025 11:47:56 +0100 Subject: [PATCH] wip --- Core/Config.cpp | 42 +++++++++++++++++------------------ Core/Config.h | 59 +++++++++++++++++++++++++++++++++---------------- 2 files changed, 61 insertions(+), 40 deletions(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index 15f0351f8d..e119ade120 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -1064,25 +1064,25 @@ static const ConfigSetting vrSettings[] = { // The first column says what structure the parameters are relative to. static const ConfigSectionMeta sectionMeta[] = { - { (char *)&g_Config, generalSettings, ARRAY_SIZE(generalSettings), "General" }, - { (char *)&g_Config, cpuSettings, ARRAY_SIZE(cpuSettings), "CPU" }, - { (char *)&g_Config, graphicsSettings, ARRAY_SIZE(graphicsSettings), "Graphics" }, - { (char *)&g_Config, soundSettings, ARRAY_SIZE(soundSettings), "Sound" }, - { (char *)&g_Config, controlSettings, ARRAY_SIZE(controlSettings), "Control" }, - { (char *)&g_Config, systemParamSettings, ARRAY_SIZE(systemParamSettings), "SystemParam" }, - { (char *)&g_Config, networkSettings, ARRAY_SIZE(networkSettings), "Network" }, - { (char *)&g_Config, debuggerSettings, ARRAY_SIZE(debuggerSettings), "Debugger" }, - { (char *)&g_Config, jitSettings, ARRAY_SIZE(jitSettings), "JIT" }, - { (char *)&g_Config, themeSettings, ARRAY_SIZE(themeSettings), "Theme" }, - { (char *)&g_Config, vrSettings, ARRAY_SIZE(vrSettings), "VR" }, - { (char *)&g_Config, achievementSettings, ARRAY_SIZE(achievementSettings), "Achievements" }, - { (char *)&g_Config.displayLayoutLandscape, displayLayoutSettings, ARRAY_SIZE(displayLayoutSettings), "DisplayLayout.Landscape", "Graphics" }, // We read the old settings from [Graphics], since most people played in landscape before. - { (char *)&g_Config.displayLayoutPortrait, displayLayoutSettings, ARRAY_SIZE(displayLayoutSettings), "DisplayLayout.Portrait"}, // These we don't want to read from the old settings, since for most people, those settings will be bad. + { &g_Config, generalSettings, ARRAY_SIZE(generalSettings), "General" }, + { &g_Config, cpuSettings, ARRAY_SIZE(cpuSettings), "CPU" }, + { &g_Config, graphicsSettings, ARRAY_SIZE(graphicsSettings), "Graphics" }, + { &g_Config, soundSettings, ARRAY_SIZE(soundSettings), "Sound" }, + { &g_Config, controlSettings, ARRAY_SIZE(controlSettings), "Control" }, + { &g_Config, systemParamSettings, ARRAY_SIZE(systemParamSettings), "SystemParam" }, + { &g_Config, networkSettings, ARRAY_SIZE(networkSettings), "Network" }, + { &g_Config, debuggerSettings, ARRAY_SIZE(debuggerSettings), "Debugger" }, + { &g_Config, jitSettings, ARRAY_SIZE(jitSettings), "JIT" }, + { &g_Config, themeSettings, ARRAY_SIZE(themeSettings), "Theme" }, + { &g_Config, vrSettings, ARRAY_SIZE(vrSettings), "VR" }, + { &g_Config, achievementSettings, ARRAY_SIZE(achievementSettings), "Achievements" }, + { &g_Config.displayLayoutLandscape, displayLayoutSettings, ARRAY_SIZE(displayLayoutSettings), "DisplayLayout.Landscape", "Graphics" }, // We read the old settings from [Graphics], since most people played in landscape before. + { &g_Config.displayLayoutPortrait, displayLayoutSettings, ARRAY_SIZE(displayLayoutSettings), "DisplayLayout.Portrait"}, // These we don't want to read from the old settings, since for most people, those settings will be bad. }; const size_t numSections = ARRAY_SIZE(sectionMeta); -static inline void IterateSettingsIni(IniFile &iniFile, std::function func, bool tryFallback) { +static inline void IterateSettingsIni(IniFile &iniFile, std::function func, bool tryFallback) { for (size_t i = 0; i < numSections; ++i) { Section *section = iniFile.GetSection(sectionMeta[i].section); // Not found? Try the fallback (to upgrade settings that have been moved from old sections). @@ -1094,18 +1094,18 @@ static inline void IterateSettingsIni(IniFile &iniFile, std::function func) { +static inline void IterateSettings(std::function func) { for (size_t i = 0; i < numSections; ++i) { - char *owner = sectionMeta[i].owner; + char *owner = (char *)sectionMeta[i].owner; for (size_t j = 0; j < sectionMeta[i].settingsCount; j++) { - func(owner, sectionMeta[i].settings[j]); + func(sectionMeta[i], owner, sectionMeta[i].settings[j]); } } } @@ -1118,7 +1118,7 @@ std::map &Config::getPtrLUT() { Config::Config() { // Initialize the pointer->setting lookup map. auto ref = getPtrLUT(); - IterateSettings([this, &ref](const char *owner, const ConfigSetting &setting) { + IterateSettings([this, &ref](const ConfigSectionMeta §ionDesc, const char *owner, const ConfigSetting &setting) { const void *ptr = setting.GetVoidPtr(owner); ref[ptr] = &setting; }); @@ -1594,7 +1594,7 @@ void Config::RestoreDefaults(RestoreSettingsBits whatToRestore, bool log) { Load(); } else { if (whatToRestore & RestoreSettingsBits::SETTINGS) { - IterateSettings([log](char *owner, const ConfigSetting &setting) { + IterateSettings([log](const ConfigSectionMeta §ionDesc, char *owner, const ConfigSetting &setting) { setting.RestoreToDefault(owner, log); }); } diff --git a/Core/Config.h b/Core/Config.h index a242db21d8..c298bd9e64 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -64,37 +64,58 @@ private: struct ConfigSetting; struct ConfigSectionMeta { - char *owner; + Resettable *owner; const ConfigSetting *settings; size_t settingsCount; std::string_view section; std::string_view fallbackSection; // used if section is not found (useful when moving settings into a struct from Config). }; -struct DisplayLayoutConfig { - int iDisplayFilter; // 1 = linear, 2 = nearest - bool bDisplayStretch; // Automatically matches the aspect ratio of the window. - float fDisplayOffsetX; - float fDisplayOffsetY; - float fDisplayScale; // Relative to the most constraining axis (x or y). - bool bDisplayIntegerScale; // Snaps scaling to integer scale factors in raw pixels. - float fDisplayAspectRatio; // Stored relative to the PSP's native ratio, so 1.0 is the normal pixel aspect ratio. - int iInternalScreenRotation; // The internal screen rotation angle. Useful for vertical SHMUPs and similar. - bool bIgnoreScreenInsets; // Android: Center screen disregarding insets if this is enabled. - - bool bEnableCardboardVR; // Cardboard Master Switch - int iCardboardScreenSize; // Screen Size (in %) - int iCardboardXShift; // X-Shift of Screen (in %) - int iCardboardYShift; // Y-Shift of Screen (in %) - - bool InternalRotationIsPortrait() const; +struct Resettable { + virtual ~Resettable() {} + // Return false if you didn't reset, this will fall back to the standard defaulting mechanism + virtual bool ResetToDefault(const ConfigSectionMeta &meta) = 0; }; -struct Config { +struct DisplayLayoutConfig : public Resettable { + int iDisplayFilter = 1; // 1 = linear, 2 = nearest + bool bDisplayStretch = false; // Automatically matches the aspect ratio of the window. + float fDisplayOffsetX = 0.5f; + float fDisplayOffsetY = 0.5f; + float fDisplayScale = 1.0f; // Relative to the most constraining axis (x or y). + bool bDisplayIntegerScale = false; // Snaps scaling to integer scale factors in raw pixels. + float fDisplayAspectRatio = 1.0f; // Stored relative to the PSP's native ratio, so 1.0 is the normal pixel aspect ratio. + int iInternalScreenRotation = ROTATION_LOCKED_HORIZONTAL; // The internal screen rotation angle. Useful for vertical SHMUPs and similar. + bool bIgnoreScreenInsets = true; // Android/iOS: Center screen disregarding insets if this is enabled. + + bool bEnableCardboardVR = false; // Cardboard Master Switch + int iCardboardScreenSize = 50; // Screen Size (in %) + int iCardboardXShift = 0; // X-Shift of Screen (in %) + int iCardboardYShift = 0; // Y-Shift of Screen (in %) + + bool InternalRotationIsPortrait() const; + + bool ResetToDefault(const ConfigSectionMeta &meta) override { + // Here we can reset the settings according to meta. + static const DisplayLayoutConfig defaults; + *this = defaults; + if (meta.section == "DisplayLayout.Portrait") { + fDisplayOffsetY = 0.2f; + } + return false; + } +}; + +struct Config : public Resettable { public: Config(); ~Config(); + bool ResetToDefault(const ConfigSectionMeta &meta) override { + // Do nothing: For all settings in the main config struct, we use the defaulting mechanism from ConfigSetting. + return false; + } + // Whether to save the config on close. bool bSaveSettings; bool bFirstRun;