nested folder support + refuse to load incompatibly sized textures + general cleanups

This commit is contained in:
Khangaroo 2019-08-16 22:34:22 -04:00 committed by James Rowe
parent 8a98310a16
commit ae4aaf2fc1
8 changed files with 141 additions and 57 deletions

View file

@ -98,47 +98,6 @@ System::ResultStatus System::SingleStep() {
return RunLoop(false);
}
void System::PreloadCustomTextures() {
// Custom textures are currently stored as
// load/textures/[TitleID]/tex1_[width]x[height]_[64-bit hash]_[format].png
const std::string load_path =
fmt::format("{}textures/{:016X}/", FileUtil::GetUserPath(FileUtil::UserPath::LoadDir),
Kernel().GetCurrentProcess()->codeset->program_id);
if (FileUtil::Exists(load_path)) {
FileUtil::FSTEntry texture_files;
FileUtil::ScanDirectoryTree(load_path, texture_files);
for (const auto& file : texture_files.children) {
if (file.isDirectory)
continue;
if (file.virtualName.substr(0, 5) != "tex1_")
continue;
u32 width;
u32 height;
u64 hash;
u32 format; // unused
// TODO: more modern way of doing this
if (std::sscanf(file.virtualName.c_str(), "tex1_%ux%u_%llX_%u.png", &width, &height,
&hash, &format) == 4) {
u32 png_width;
u32 png_height;
std::vector<u8> decoded_png;
if (registered_image_interface->DecodePNG(decoded_png, png_width, png_height,
file.physicalName)) {
LOG_INFO(Render_OpenGL, "Preloaded custom texture from {}", file.physicalName);
Common::FlipRGBA8Texture(decoded_png, png_width, png_height);
custom_tex_cache->CacheTexture(hash, decoded_png, png_width, png_height);
} else {
// Error should be reported by frontend
LOG_CRITICAL(Render_OpenGL, "Failed to preload custom texture");
}
}
}
}
}
System::ResultStatus System::Load(Frontend::EmuWindow& emu_window, const std::string& filepath) {
app_loader = Loader::GetLoader(filepath);
if (!app_loader) {
@ -200,9 +159,10 @@ System::ResultStatus System::Load(Frontend::EmuWindow& emu_window, const std::st
FileUtil::CreateFullPath(fmt::format("{}textures/{:016X}/",
FileUtil::GetUserPath(FileUtil::UserPath::LoadDir),
Kernel().GetCurrentProcess()->codeset->program_id));
custom_tex_cache->FindCustomTextures();
}
if (Settings::values.preload_textures)
PreloadCustomTextures();
custom_tex_cache->PreloadTextures();
status = ResultStatus::Success;
m_emu_window = &emu_window;
m_filepath = filepath;
@ -238,8 +198,8 @@ System::ResultStatus System::Init(Frontend::EmuWindow& emu_window, u32 system_mo
timing = std::make_unique<Timing>();
kernel = std::make_unique<Kernel::KernelSystem>(*memory, *timing,
[this] { PrepareReschedule(); }, system_mode);
kernel = std::make_unique<Kernel::KernelSystem>(
*memory, *timing, [this] { PrepareReschedule(); }, system_mode);
if (Settings::values.use_cpu_jit) {
#ifdef ARCHITECTURE_x86_64