Move layout reload policy into platform api
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include "node.h"
|
||||
#include "node_border.h"
|
||||
#include "layout.h"
|
||||
#include "platform_api/asset_file_load_policy.h"
|
||||
|
||||
void LayoutManager::unload()
|
||||
{
|
||||
@@ -22,17 +23,13 @@ void LayoutManager::create()
|
||||
bool LayoutManager::load(const char* path)
|
||||
{
|
||||
auto abs_path = Asset::absolute(path);
|
||||
#if _WIN32 || __OSX__
|
||||
struct stat tmp_info;
|
||||
if (stat(abs_path.c_str(), &tmp_info) != 0)
|
||||
return false;
|
||||
if (tmp_info.st_mtime <= m_file_info.st_mtime)
|
||||
return false;
|
||||
m_file_info = tmp_info;
|
||||
#else
|
||||
if (m_loaded)
|
||||
return true; // already loaded
|
||||
#endif // __ANDROID__
|
||||
const auto file_load = pp::platform::plan_asset_file_load(
|
||||
abs_path,
|
||||
m_loaded,
|
||||
m_file_last_write_time);
|
||||
if (!file_load.should_read_file)
|
||||
return file_load.skipped_load_result;
|
||||
m_file_last_write_time = file_load.last_write_time;
|
||||
|
||||
if (!m_layouts.empty() && on_reloading)
|
||||
on_reloading();
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
class LayoutManager
|
||||
{
|
||||
std::string m_path;
|
||||
struct stat m_file_info { 0 };
|
||||
std::int64_t m_file_last_write_time = 0;
|
||||
public:
|
||||
std::map<uint16_t, std::shared_ptr<class Node>> m_layouts;
|
||||
bool m_loaded = false;
|
||||
|
||||
33
src/platform_api/asset_file_load_policy.cpp
Normal file
33
src/platform_api/asset_file_load_policy.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include "platform_api/asset_file_load_policy.h"
|
||||
|
||||
#include <string>
|
||||
#include <sys/stat.h>
|
||||
|
||||
namespace pp::platform {
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
}
|
||||
19
src/platform_api/asset_file_load_policy.h
Normal file
19
src/platform_api/asset_file_load_policy.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string_view>
|
||||
|
||||
namespace pp::platform {
|
||||
|
||||
struct AssetFileLoadDecision {
|
||||
bool should_read_file = true;
|
||||
bool skipped_load_result = true;
|
||||
std::int64_t last_write_time = 0;
|
||||
};
|
||||
|
||||
[[nodiscard]] AssetFileLoadDecision plan_asset_file_load(
|
||||
std::string_view absolute_path,
|
||||
bool already_loaded,
|
||||
std::int64_t previous_last_write_time);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user