mirror of
https://github.com/citra-emu/citra-nightly.git
synced 2024-12-26 02:15:35 +00:00
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);
|
perf_stats = std::make_unique<PerfStats>(title_id);
|
||||||
custom_tex_cache = std::make_unique<Core::CustomTexCache>();
|
custom_tex_cache = std::make_unique<Core::CustomTexCache>();
|
||||||
|
|
||||||
if (Settings::values.custom_textures) {
|
if (Settings::values.custom_textures) {
|
||||||
FileUtil::CreateFullPath(fmt::format("{}textures/{:016X}/",
|
const u64 program_id = Kernel().GetCurrentProcess()->codeset->program_id;
|
||||||
FileUtil::GetUserPath(FileUtil::UserPath::LoadDir),
|
FileUtil::CreateFullPath(fmt::format(
|
||||||
Kernel().GetCurrentProcess()->codeset->program_id));
|
"{}textures/{:016X}/", FileUtil::GetUserPath(FileUtil::UserPath::LoadDir), program_id));
|
||||||
custom_tex_cache->FindCustomTextures();
|
custom_tex_cache->FindCustomTextures(program_id);
|
||||||
}
|
}
|
||||||
if (Settings::values.preload_textures)
|
if (Settings::values.preload_textures) {
|
||||||
custom_tex_cache->PreloadTextures();
|
custom_tex_cache->PreloadTextures(*GetImageInterface());
|
||||||
|
}
|
||||||
|
|
||||||
status = ResultStatus::Success;
|
status = ResultStatus::Success;
|
||||||
m_emu_window = &emu_window;
|
m_emu_window = &emu_window;
|
||||||
m_filepath = filepath;
|
m_filepath = filepath;
|
||||||
|
|
|
@ -40,13 +40,12 @@ void CustomTexCache::AddTexturePath(u64 hash, const std::string& path) {
|
||||||
custom_texture_paths[hash] = {path, hash};
|
custom_texture_paths[hash] = {path, hash};
|
||||||
}
|
}
|
||||||
|
|
||||||
void CustomTexCache::FindCustomTextures() {
|
void CustomTexCache::FindCustomTextures(u64 program_id) {
|
||||||
// Custom textures are currently stored as
|
// Custom textures are currently stored as
|
||||||
// [TitleID]/tex1_[width]x[height]_[64-bit hash]_[format].png
|
// [TitleID]/tex1_[width]x[height]_[64-bit hash]_[format].png
|
||||||
|
|
||||||
const std::string load_path =
|
const std::string load_path = fmt::format(
|
||||||
fmt::format("{}textures/{:016X}/", FileUtil::GetUserPath(FileUtil::UserPath::LoadDir),
|
"{}textures/{:016X}/", FileUtil::GetUserPath(FileUtil::UserPath::LoadDir), program_id);
|
||||||
Core::System::GetInstance().Kernel().GetCurrentProcess()->codeset->program_id);
|
|
||||||
|
|
||||||
if (FileUtil::Exists(load_path)) {
|
if (FileUtil::Exists(load_path)) {
|
||||||
FileUtil::FSTEntry texture_dir;
|
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) {
|
for (const auto& path : custom_texture_paths) {
|
||||||
const auto& image_interface = Core::System::GetInstance().GetImageInterface();
|
|
||||||
const auto& path_info = path.second;
|
const auto& path_info = path.second;
|
||||||
Core::CustomTexInfo tex_info;
|
Core::CustomTexInfo tex_info;
|
||||||
if (image_interface->DecodePNG(tex_info.tex, tex_info.width, tex_info.height,
|
if (image_interface.DecodePNG(tex_info.tex, tex_info.width, tex_info.height,
|
||||||
path_info.path)) {
|
path_info.path)) {
|
||||||
// Make sure the texture size is a power of 2
|
// Make sure the texture size is a power of 2
|
||||||
std::bitset<32> width_bits(tex_info.width);
|
std::bitset<32> width_bits(tex_info.width);
|
||||||
std::bitset<32> height_bits(tex_info.height);
|
std::bitset<32> height_bits(tex_info.height);
|
||||||
|
|
|
@ -10,6 +10,10 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
|
|
||||||
|
namespace Frontend {
|
||||||
|
class ImageInterface;
|
||||||
|
} // namespace Frontend
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
struct CustomTexInfo {
|
struct CustomTexInfo {
|
||||||
u32 width;
|
u32 width;
|
||||||
|
@ -37,8 +41,8 @@ public:
|
||||||
void CacheTexture(u64 hash, const std::vector<u8>& tex, u32 width, u32 height);
|
void CacheTexture(u64 hash, const std::vector<u8>& tex, u32 width, u32 height);
|
||||||
|
|
||||||
void AddTexturePath(u64 hash, const std::string& path);
|
void AddTexturePath(u64 hash, const std::string& path);
|
||||||
void FindCustomTextures();
|
void FindCustomTextures(u64 program_id);
|
||||||
void PreloadTextures();
|
void PreloadTextures(Frontend::ImageInterface& image_interface);
|
||||||
bool CustomTextureExists(u64 hash) const;
|
bool CustomTextureExists(u64 hash) const;
|
||||||
const CustomTexPathInfo& LookupTexturePathInfo(u64 hash) const;
|
const CustomTexPathInfo& LookupTexturePathInfo(u64 hash) const;
|
||||||
bool IsTexturePathMapEmpty() const;
|
bool IsTexturePathMapEmpty() const;
|
||||||
|
|
Loading…
Reference in a new issue