mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-05-01 00:38:34 +00:00
Core / DolphinQt / InputCommon: reduce the number disk writes when using DynamicInputTextures
This commit is contained in:
parent
18979129f3
commit
d03f9032c1
15 changed files with 102 additions and 42 deletions
|
@ -10,7 +10,6 @@
|
|||
#include <picojson.h>
|
||||
|
||||
#include "Common/CommonPaths.h"
|
||||
#include "Common/FileUtil.h"
|
||||
#include "Common/IniFile.h"
|
||||
#include "Common/JsonUtil.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
|
@ -68,26 +67,30 @@ Configuration::Configuration(const std::string& json_path)
|
|||
|
||||
Configuration::~Configuration() = default;
|
||||
|
||||
bool Configuration::GenerateTextures(const Common::IniFile& file,
|
||||
const std::vector<std::string>& controller_names) const
|
||||
void Configuration::GenerateTextures(const Common::IniFile& file,
|
||||
const std::vector<std::string>& controller_names,
|
||||
OutputDetails* output) const
|
||||
{
|
||||
bool any_dirty = false;
|
||||
for (const auto& texture_data : m_dynamic_input_textures)
|
||||
{
|
||||
any_dirty |= GenerateTexture(file, controller_names, texture_data);
|
||||
GenerateTexture(file, controller_names, texture_data, output);
|
||||
}
|
||||
|
||||
return any_dirty;
|
||||
}
|
||||
|
||||
bool Configuration::GenerateTexture(const Common::IniFile& file,
|
||||
void Configuration::GenerateTexture(const Common::IniFile& file,
|
||||
const std::vector<std::string>& controller_names,
|
||||
const Data& texture_data) const
|
||||
const Data& texture_data, OutputDetails* output) const
|
||||
{
|
||||
// Two copies of the loaded texture
|
||||
// The first one is used as a fallback if a key or device isn't mapped
|
||||
// the second one is used as the final image to write to the textures directory
|
||||
const auto original_image = LoadImage(m_base_path + texture_data.m_image_name);
|
||||
if (!original_image)
|
||||
{
|
||||
ERROR_LOG_FMT(VIDEO, "Failed to load image '{}' needed for dynamic input texture generation",
|
||||
texture_data.m_image_name);
|
||||
return;
|
||||
}
|
||||
auto image_to_write = original_image;
|
||||
|
||||
bool dirty = false;
|
||||
|
@ -179,25 +182,8 @@ bool Configuration::GenerateTexture(const Common::IniFile& file,
|
|||
|
||||
if (dirty)
|
||||
{
|
||||
const std::string& game_id = SConfig::GetInstance().GetGameID();
|
||||
const auto hi_res_folder =
|
||||
File::GetUserPath(D_HIRESTEXTURES_IDX) + texture_data.m_generated_folder_name;
|
||||
if (!File::IsDirectory(hi_res_folder))
|
||||
{
|
||||
File::CreateDir(hi_res_folder);
|
||||
}
|
||||
WriteImage(hi_res_folder + DIR_SEP + texture_data.m_hires_texture_name, *image_to_write);
|
||||
|
||||
const auto game_id_folder = hi_res_folder + DIR_SEP + "gameids";
|
||||
if (!File::IsDirectory(game_id_folder))
|
||||
{
|
||||
File::CreateDir(game_id_folder);
|
||||
}
|
||||
File::CreateEmptyFile(game_id_folder + DIR_SEP + game_id + ".txt");
|
||||
|
||||
return true;
|
||||
(*output)[texture_data.m_generated_folder_name][texture_data.m_hires_texture_name] =
|
||||
std::move(*image_to_write);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
} // namespace InputCommon::DynamicInputTextures
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue