From b82d4315fefb4fc8803e2b65e0dc9252548bd402 Mon Sep 17 00:00:00 2001 From: Mat M Date: Mon, 20 Apr 2020 22:50:16 -0400 Subject: [PATCH] custom_tex_cache: Remove reliance on the global system instance (#5252) Removes direct usages of Core::System::GetInstance() and instead passes the direct necessities through the interface. --- src/core/core.cpp | 15 +++++++++------ src/core/custom_tex_cache.cpp | 14 ++++++-------- src/core/custom_tex_cache.h | 8 ++++++-- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/core/core.cpp b/src/core/core.cpp index 03b70d2a8..6a20dc374 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -295,14 +295,17 @@ System::ResultStatus System::Load(Frontend::EmuWindow& emu_window, const std::st } perf_stats = std::make_unique(title_id); custom_tex_cache = std::make_unique(); + if (Settings::values.custom_textures) { - FileUtil::CreateFullPath(fmt::format("{}textures/{:016X}/", - FileUtil::GetUserPath(FileUtil::UserPath::LoadDir), - Kernel().GetCurrentProcess()->codeset->program_id)); - custom_tex_cache->FindCustomTextures(); + const u64 program_id = Kernel().GetCurrentProcess()->codeset->program_id; + FileUtil::CreateFullPath(fmt::format( + "{}textures/{:016X}/", FileUtil::GetUserPath(FileUtil::UserPath::LoadDir), program_id)); + custom_tex_cache->FindCustomTextures(program_id); } - if (Settings::values.preload_textures) - custom_tex_cache->PreloadTextures(); + if (Settings::values.preload_textures) { + custom_tex_cache->PreloadTextures(*GetImageInterface()); + } + status = ResultStatus::Success; m_emu_window = &emu_window; m_filepath = filepath; diff --git a/src/core/custom_tex_cache.cpp b/src/core/custom_tex_cache.cpp index c878016f7..9045df836 100644 --- a/src/core/custom_tex_cache.cpp +++ b/src/core/custom_tex_cache.cpp @@ -40,13 +40,12 @@ void CustomTexCache::AddTexturePath(u64 hash, const std::string& path) { custom_texture_paths[hash] = {path, hash}; } -void CustomTexCache::FindCustomTextures() { +void CustomTexCache::FindCustomTextures(u64 program_id) { // Custom textures are currently stored as // [TitleID]/tex1_[width]x[height]_[64-bit hash]_[format].png - const std::string load_path = - fmt::format("{}textures/{:016X}/", FileUtil::GetUserPath(FileUtil::UserPath::LoadDir), - Core::System::GetInstance().Kernel().GetCurrentProcess()->codeset->program_id); + const std::string load_path = fmt::format( + "{}textures/{:016X}/", FileUtil::GetUserPath(FileUtil::UserPath::LoadDir), program_id); if (FileUtil::Exists(load_path)) { FileUtil::FSTEntry texture_dir; @@ -74,13 +73,12 @@ void CustomTexCache::FindCustomTextures() { } } -void CustomTexCache::PreloadTextures() { +void CustomTexCache::PreloadTextures(Frontend::ImageInterface& image_interface) { for (const auto& path : custom_texture_paths) { - const auto& image_interface = Core::System::GetInstance().GetImageInterface(); const auto& path_info = path.second; Core::CustomTexInfo tex_info; - if (image_interface->DecodePNG(tex_info.tex, tex_info.width, tex_info.height, - path_info.path)) { + if (image_interface.DecodePNG(tex_info.tex, tex_info.width, tex_info.height, + path_info.path)) { // Make sure the texture size is a power of 2 std::bitset<32> width_bits(tex_info.width); std::bitset<32> height_bits(tex_info.height); diff --git a/src/core/custom_tex_cache.h b/src/core/custom_tex_cache.h index 2e0e5dd65..d23ad7b91 100644 --- a/src/core/custom_tex_cache.h +++ b/src/core/custom_tex_cache.h @@ -10,6 +10,10 @@ #include #include "common/common_types.h" +namespace Frontend { +class ImageInterface; +} // namespace Frontend + namespace Core { struct CustomTexInfo { u32 width; @@ -37,8 +41,8 @@ public: void CacheTexture(u64 hash, const std::vector& tex, u32 width, u32 height); void AddTexturePath(u64 hash, const std::string& path); - void FindCustomTextures(); - void PreloadTextures(); + void FindCustomTextures(u64 program_id); + void PreloadTextures(Frontend::ImageInterface& image_interface); bool CustomTextureExists(u64 hash) const; const CustomTexPathInfo& LookupTexturePathInfo(u64 hash) const; bool IsTexturePathMapEmpty() const;