From 3257244224259585d664e3f83f63be67e43375f5 Mon Sep 17 00:00:00 2001 From: Hyper <34012267+hyperbx@users.noreply.github.com> Date: Fri, 15 Nov 2024 21:07:30 +0000 Subject: [PATCH] config_detail: move implementation to cpp, relocate sources --- UnleashedRecomp/CMakeLists.txt | 9 +- UnleashedRecomp/{ => cfg}/config.cpp | 0 UnleashedRecomp/{ => cfg}/config.h | 0 UnleashedRecomp/cfg/config_detail.cpp | 106 +++++++++++++++++ UnleashedRecomp/{ => cfg}/config_detail.h | 118 ++----------------- UnleashedRecomp/{ => cfg}/config_locale.h | 0 UnleashedRecomp/gpu/video.cpp | 6 +- UnleashedRecomp/kernel/imports.cpp | 3 +- UnleashedRecomp/main.cpp | 2 +- UnleashedRecomp/patches/fps_patches.cpp | 6 +- UnleashedRecomp/patches/misc_patches.cpp | 6 +- UnleashedRecomp/patches/player_patches.cpp | 8 +- UnleashedRecomp/patches/resident_patches.cpp | 2 +- UnleashedRecomp/patches/video_patches.cpp | 6 +- UnleashedRecomp/ui/window.cpp | 2 +- UnleashedRecomp/ui/window.h | 8 +- 16 files changed, 149 insertions(+), 133 deletions(-) rename UnleashedRecomp/{ => cfg}/config.cpp (100%) rename UnleashedRecomp/{ => cfg}/config.h (100%) create mode 100644 UnleashedRecomp/cfg/config_detail.cpp rename UnleashedRecomp/{ => cfg}/config_detail.h (69%) rename UnleashedRecomp/{ => cfg}/config_locale.h (100%) diff --git a/UnleashedRecomp/CMakeLists.txt b/UnleashedRecomp/CMakeLists.txt index 5fffe2e6..ba61cd96 100644 --- a/UnleashedRecomp/CMakeLists.txt +++ b/UnleashedRecomp/CMakeLists.txt @@ -28,6 +28,11 @@ set(SWA_PRECOMPILED_HEADERS "stdafx.h" ) +set(SWA_CFG_CXX_SOURCES + "cfg/config.cpp" + "cfg/config_detail.cpp" +) + set(SWA_KERNEL_CXX_SOURCES "kernel/imports.cpp" "kernel/xdm.cpp" @@ -75,11 +80,11 @@ set(SWA_UI_CXX_SOURCES ) set(SWA_CXX_SOURCES - "config.cpp" "main.cpp" "misc_impl.cpp" "stdafx.cpp" - + + ${SWA_CFG_CXX_SOURCES} ${SWA_KERNEL_CXX_SOURCES} ${SWA_CPU_CXX_SOURCES} ${SWA_GPU_CXX_SOURCES} diff --git a/UnleashedRecomp/config.cpp b/UnleashedRecomp/cfg/config.cpp similarity index 100% rename from UnleashedRecomp/config.cpp rename to UnleashedRecomp/cfg/config.cpp diff --git a/UnleashedRecomp/config.h b/UnleashedRecomp/cfg/config.h similarity index 100% rename from UnleashedRecomp/config.h rename to UnleashedRecomp/cfg/config.h diff --git a/UnleashedRecomp/cfg/config_detail.cpp b/UnleashedRecomp/cfg/config_detail.cpp new file mode 100644 index 00000000..0e74cba0 --- /dev/null +++ b/UnleashedRecomp/cfg/config_detail.cpp @@ -0,0 +1,106 @@ +#include "config.h" +#include "config_detail.h" + +// CONFIG_DEFINE +template +ConfigDef::ConfigDef(std::string section, std::string name, T defaultValue) : Section(section), Name(name), DefaultValue(defaultValue) +{ + Config::Definitions.emplace_back(this); +} + +// CONFIG_DEFINE_LOCALISED +template +ConfigDef::ConfigDef(std::string section, std::string name, std::unordered_map* nameLocale, T defaultValue) + : Section(section), Name(name), NameLocale(nameLocale), DefaultValue(defaultValue) +{ + Config::Definitions.emplace_back(this); +} + +// CONFIG_DEFINE_ENUM +template +ConfigDef::ConfigDef(std::string section, std::string name, T defaultValue, std::unordered_map* enumTemplate) + : Section(section), Name(name), DefaultValue(defaultValue), EnumTemplate(enumTemplate) +{ + for (const auto& pair : *EnumTemplate) + EnumTemplateReverse[pair.second] = pair.first; + + Config::Definitions.emplace_back(this); +} + +// CONFIG_DEFINE_ENUM_LOCALISED +template +ConfigDef::ConfigDef(std::string section, std::string name, std::unordered_map* nameLocale, T defaultValue, std::unordered_map* enumTemplate, std::unordered_map>* enumLocale) + : Section(section), Name(name), NameLocale(nameLocale), DefaultValue(defaultValue), EnumTemplate(enumTemplate), EnumLocale(enumLocale) +{ + for (const auto& pair : *EnumTemplate) + EnumTemplateReverse[pair.second] = pair.first; + + Config::Definitions.emplace_back(this); +} + +// CONFIG_DEFINE_CALLBACK +template +ConfigDef::ConfigDef(std::string section, std::string name, T defaultValue, std::function*)> readCallback) + : Section(section), Name(name), DefaultValue(defaultValue), ReadCallback(readCallback) +{ + Config::Definitions.emplace_back(this); +} + +template +std::string ConfigDef::GetNameLocalised() const +{ + if (!NameLocale) + return Name; + + if (!NameLocale->count(Config::Language)) + { + if (NameLocale->count(ELanguage::English)) + { + return NameLocale->at(ELanguage::English); + } + else + { + return Name; + } + } + + return NameLocale->at(Config::Language); +} + +template +std::string ConfigDef::GetValueLocalised() const +{ + auto language = Config::Language; + std::unordered_map>* locale = nullptr; + + if constexpr (std::is_enum_v) + { + locale = EnumLocale; + } + else if constexpr (std::is_same_v) + { + locale = &g_bool_locale; + } + + if (!locale) + return ToString(false); + + if (!locale->count(language)) + { + if (locale->count(ELanguage::English)) + { + language = ELanguage::English; + } + else + { + return ToString(false); + } + } + + auto strings = locale->at(language); + + if (!strings.count(Value)) + return ToString(false); + + return strings.at(Value); +} diff --git a/UnleashedRecomp/config_detail.h b/UnleashedRecomp/cfg/config_detail.h similarity index 69% rename from UnleashedRecomp/config_detail.h rename to UnleashedRecomp/cfg/config_detail.h index 7da7c56d..e256bc45 100644 --- a/UnleashedRecomp/config_detail.h +++ b/UnleashedRecomp/cfg/config_detail.h @@ -180,61 +180,20 @@ public: std::unordered_map>* EnumLocale; std::function*)> ReadCallback; - ConfigDef(std::string section, std::string name, T defaultValue) - : Section(section), Name(name), DefaultValue(defaultValue) - { - Config::Definitions.emplace_back(this); - } + // CONFIG_DEFINE + ConfigDef(std::string section, std::string name, T defaultValue); - ConfigDef(std::string section, std::string name, std::unordered_map* nameLocale, T defaultValue) - : Section(section), Name(name), NameLocale(nameLocale), DefaultValue(defaultValue) - { - Config::Definitions.emplace_back(this); - } + // CONFIG_DEFINE_LOCALISED + ConfigDef(std::string section, std::string name, std::unordered_map* nameLocale, T defaultValue); - ConfigDef - ( - std::string section, - std::string name, - T defaultValue, - std::unordered_map* enumTemplate - ) - : Section(section), Name(name), DefaultValue(defaultValue), EnumTemplate(enumTemplate) - { - for (const auto& pair : *EnumTemplate) - EnumTemplateReverse[pair.second] = pair.first; + // CONFIG_DEFINE_ENUM + ConfigDef(std::string section, std::string name, T defaultValue, std::unordered_map* enumTemplate); - Config::Definitions.emplace_back(this); - } + // CONFIG_DEFINE_ENUM_LOCALISED + ConfigDef(std::string section, std::string name, std::unordered_map* nameLocale, T defaultValue, std::unordered_map* enumTemplate, std::unordered_map>* enumLocale); - ConfigDef - ( - std::string section, - std::string name, - std::unordered_map* nameLocale, - T defaultValue, - std::unordered_map* enumTemplate, - std::unordered_map>* enumLocale - ) - : Section(section), Name(name), NameLocale(nameLocale), DefaultValue(defaultValue), EnumTemplate(enumTemplate), EnumLocale(enumLocale) - { - for (const auto& pair : *EnumTemplate) - EnumTemplateReverse[pair.second] = pair.first; - - Config::Definitions.emplace_back(this); - } - - ConfigDef(std::string section, std::string name, T defaultValue, std::function*)> readCallback) - : Section(section), Name(name), DefaultValue(defaultValue), ReadCallback(readCallback) - { - Config::Definitions.emplace_back(this); - } - - ConfigDef(std::string section, std::string name, std::unordered_map nameLocale, T defaultValue, std::function*)> readCallback) - : Section(section), Name(name), NameLocale(nameLocale), DefaultValue(defaultValue), ReadCallback(readCallback) - { - Config::Definitions.emplace_back(this); - } + // CONFIG_DEFINE_CALLBACK + ConfigDef(std::string section, std::string name, T defaultValue, std::function*)> readCallback); void ReadValue(toml::v3::ex::parse_result& toml) override { @@ -277,67 +236,14 @@ public: return Name; } - std::string GetNameLocalised() const override - { - if (!NameLocale) - return Name; - - if (!NameLocale->count(Config::Language)) - { - if (NameLocale->count(ELanguage::English)) - { - return NameLocale->at(ELanguage::English); - } - else - { - return Name; - } - } - - return NameLocale->at(Config::Language); - } + std::string GetNameLocalised() const override; void* GetValue() override { return &Value; } - std::string GetValueLocalised() const override - { - auto language = Config::Language; - std::unordered_map>* locale = nullptr; - - if constexpr (std::is_enum_v) - { - locale = EnumLocale; - } - else if constexpr (std::is_same_v) - { - locale = &g_bool_locale; - } - - if (!locale) - return ToString(false); - - if (!locale->count(language)) - { - if (locale->count(ELanguage::English)) - { - language = ELanguage::English; - } - else - { - return ToString(false); - } - } - - auto strings = locale->at(language); - - if (!strings.count(Value)) - return ToString(false); - - return strings.at(Value); - } + std::string GetValueLocalised() const override; std::string GetDefinition(bool withSection = false) const override { diff --git a/UnleashedRecomp/config_locale.h b/UnleashedRecomp/cfg/config_locale.h similarity index 100% rename from UnleashedRecomp/config_locale.h rename to UnleashedRecomp/cfg/config_locale.h diff --git a/UnleashedRecomp/gpu/video.cpp b/UnleashedRecomp/gpu/video.cpp index d170ab49..715b409c 100644 --- a/UnleashedRecomp/gpu/video.cpp +++ b/UnleashedRecomp/gpu/video.cpp @@ -11,9 +11,9 @@ #include "imgui_snapshot.h" #include "imgui_common.h" -#include "gpu/video.h" -#include "ui/window.h" -#include "config.h" +#include "video.h" +#include +#include #include "shader/copy_vs.hlsl.dxil.h" #include "shader/copy_vs.hlsl.spirv.h" diff --git a/UnleashedRecomp/kernel/imports.cpp b/UnleashedRecomp/kernel/imports.cpp index c5b05f9f..277cee8d 100644 --- a/UnleashedRecomp/kernel/imports.cpp +++ b/UnleashedRecomp/kernel/imports.cpp @@ -2,7 +2,6 @@ #include #include #include -#include #include "function.h" #include "xex.h" #include "xbox.h" @@ -12,7 +11,7 @@ #include "xam.h" #include "xdm.h" #include -#include "config.h" +#include #include diff --git a/UnleashedRecomp/main.cpp b/UnleashedRecomp/main.cpp index eef5a1b4..846ed8fe 100644 --- a/UnleashedRecomp/main.cpp +++ b/UnleashedRecomp/main.cpp @@ -11,7 +11,7 @@ #include #include #include -#include "config.h" +#include #define GAME_XEX_PATH "game:\\default.xex" diff --git a/UnleashedRecomp/patches/fps_patches.cpp b/UnleashedRecomp/patches/fps_patches.cpp index 5de2f40c..f2928fdd 100644 --- a/UnleashedRecomp/patches/fps_patches.cpp +++ b/UnleashedRecomp/patches/fps_patches.cpp @@ -1,7 +1,7 @@ #include -#include "api/SWA.h" -#include "ui/window.h" -#include "config.h" +#include +#include +#include void HighFrameRateDeltaTimeFixMidAsmHook(PPCRegister& f1) { diff --git a/UnleashedRecomp/patches/misc_patches.cpp b/UnleashedRecomp/patches/misc_patches.cpp index e181c1be..3a523ef4 100644 --- a/UnleashedRecomp/patches/misc_patches.cpp +++ b/UnleashedRecomp/patches/misc_patches.cpp @@ -1,7 +1,7 @@ #include -#include "api/SWA.h" -#include "ui/window.h" -#include "config.h" +#include +#include +#include bool DisableHintsMidAsmHook() { diff --git a/UnleashedRecomp/patches/player_patches.cpp b/UnleashedRecomp/patches/player_patches.cpp index e8991df8..ca44218d 100644 --- a/UnleashedRecomp/patches/player_patches.cpp +++ b/UnleashedRecomp/patches/player_patches.cpp @@ -1,8 +1,8 @@ #include -#include "api/SWA.h" -#include "ui/window.h" -#include "ui/window_events.h" -#include "config.h" +#include +#include +#include +#include uint32_t m_lastCheckpointScore = 0; float m_lastDarkGaiaEnergy = 0.0f; diff --git a/UnleashedRecomp/patches/resident_patches.cpp b/UnleashedRecomp/patches/resident_patches.cpp index 36264d08..f1606b66 100644 --- a/UnleashedRecomp/patches/resident_patches.cpp +++ b/UnleashedRecomp/patches/resident_patches.cpp @@ -1,5 +1,5 @@ #include -#include "config.h" +#include const char* m_pStageID; diff --git a/UnleashedRecomp/patches/video_patches.cpp b/UnleashedRecomp/patches/video_patches.cpp index 8e931b70..3bf6ebe5 100644 --- a/UnleashedRecomp/patches/video_patches.cpp +++ b/UnleashedRecomp/patches/video_patches.cpp @@ -1,7 +1,7 @@ #include -#include "api/SWA.h" -#include "ui/window.h" -#include "config.h" +#include +#include +#include constexpr float m_baseAspectRatio = 16.0f / 9.0f; diff --git a/UnleashedRecomp/ui/window.cpp b/UnleashedRecomp/ui/window.cpp index 0ed84ec9..7f587044 100644 --- a/UnleashedRecomp/ui/window.cpp +++ b/UnleashedRecomp/ui/window.cpp @@ -1,6 +1,6 @@ #include "window.h" #include "sdl_listener.h" -#include +#include #include #include diff --git a/UnleashedRecomp/ui/window.h b/UnleashedRecomp/ui/window.h index 4aed02c3..cab4fbf5 100644 --- a/UnleashedRecomp/ui/window.h +++ b/UnleashedRecomp/ui/window.h @@ -1,9 +1,9 @@ #pragma once -#include "res/icon.h" -#include "res/icon_night.h" -#include "ui/window_events.h" -#include "config.h" +#include +#include +#include +#include #define DEFAULT_WIDTH 1280 #define DEFAULT_HEIGHT 720