Split asset reload platform policy
This commit is contained in:
@@ -5,29 +5,75 @@
|
||||
|
||||
namespace pp::platform {
|
||||
|
||||
AssetFileLoadDecision plan_asset_file_load_with_probe(
|
||||
PlatformFamily family,
|
||||
bool already_loaded,
|
||||
std::int64_t previous_last_write_time,
|
||||
AssetFileTimestampProbe probe) noexcept
|
||||
{
|
||||
if (platform_uses_asset_file_mtime_reload(family))
|
||||
{
|
||||
if (!probe.file_exists)
|
||||
return { false, false, previous_last_write_time };
|
||||
|
||||
if (probe.last_write_time <= previous_last_write_time)
|
||||
return { false, false, previous_last_write_time };
|
||||
|
||||
return { true, true, probe.last_write_time };
|
||||
}
|
||||
|
||||
if (already_loaded)
|
||||
return { false, true, previous_last_write_time };
|
||||
|
||||
return { true, true, previous_last_write_time };
|
||||
}
|
||||
|
||||
AssetFileLoadDecision plan_asset_file_load_for_platform(
|
||||
PlatformFamily family,
|
||||
std::string_view absolute_path,
|
||||
bool already_loaded,
|
||||
std::int64_t previous_last_write_time)
|
||||
{
|
||||
if (!platform_uses_asset_file_mtime_reload(family))
|
||||
{
|
||||
return plan_asset_file_load_with_probe(
|
||||
family,
|
||||
already_loaded,
|
||||
previous_last_write_time,
|
||||
{});
|
||||
}
|
||||
|
||||
struct stat file_info {};
|
||||
const std::string path(absolute_path);
|
||||
if (stat(path.c_str(), &file_info) != 0)
|
||||
{
|
||||
return plan_asset_file_load_with_probe(
|
||||
family,
|
||||
already_loaded,
|
||||
previous_last_write_time,
|
||||
{});
|
||||
}
|
||||
|
||||
return plan_asset_file_load_with_probe(
|
||||
family,
|
||||
already_loaded,
|
||||
previous_last_write_time,
|
||||
{
|
||||
true,
|
||||
static_cast<std::int64_t>(file_info.st_mtime),
|
||||
});
|
||||
}
|
||||
|
||||
AssetFileLoadDecision plan_asset_file_load(
|
||||
std::string_view absolute_path,
|
||||
bool already_loaded,
|
||||
std::int64_t previous_last_write_time)
|
||||
{
|
||||
#if defined(_WIN32) || defined(__OSX__)
|
||||
struct stat file_info {};
|
||||
const std::string path(absolute_path);
|
||||
if (stat(path.c_str(), &file_info) != 0)
|
||||
return { false, false, previous_last_write_time };
|
||||
|
||||
const auto current_last_write_time = static_cast<std::int64_t>(file_info.st_mtime);
|
||||
if (current_last_write_time <= previous_last_write_time)
|
||||
return { false, false, previous_last_write_time };
|
||||
|
||||
return { true, true, current_last_write_time };
|
||||
#else
|
||||
if (already_loaded)
|
||||
return { false, true, previous_last_write_time };
|
||||
|
||||
(void)absolute_path;
|
||||
return { true, true, previous_last_write_time };
|
||||
#endif
|
||||
return plan_asset_file_load_for_platform(
|
||||
current_platform_family(),
|
||||
absolute_path,
|
||||
already_loaded,
|
||||
previous_last_write_time);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user