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.
This commit is contained in:
parent
d5a962cb81
commit
b82d4315fe
@ -295,14 +295,17 @@ System::ResultStatus System::Load(Frontend::EmuWindow& emu_window, const std::st
|
||||
}
|
||||
perf_stats = std::make_unique<PerfStats>(title_id);
|
||||
custom_tex_cache = std::make_unique<Core::CustomTexCache>();
|
||||
|
||||
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;
|
||||
|
@ -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);
|
||||
|
@ -10,6 +10,10 @@
|
||||
#include <vector>
|
||||
#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<u8>& 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;
|
||||
|
Loading…
Reference in New Issue
Block a user