From d8df2a4826b6967e1263eaf017ae6e49801d8e3f Mon Sep 17 00:00:00 2001 From: KiritoDv Date: Thu, 28 Mar 2024 23:38:32 -0600 Subject: Added dep loading --- src/Companion.cpp | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/src/Companion.cpp b/src/Companion.cpp index e5dcf3d..8d96b3c 100644 --- a/src/Companion.cpp +++ b/src/Companion.cpp @@ -432,12 +432,22 @@ void Companion::PrepareCache(const std::string& path) { fs::create_directories(tdir); } else { for(auto& entry : fs::directory_iterator("tcache/" + cache)) { - std::ifstream file(entry.path(), std::ios::binary); - std::vector buffer = std::vector(std::istreambuf_iterator(file), {}); - file.close(); - std::string cpath = entry.path().filename().string(); - std::replace(cpath.begin(), cpath.end(), '+', '/'); - this->gCacheData[cache][cpath] = buffer; + const auto ext = entry.path().extension().string(); + + if(ext == ".data") { + std::ifstream file(entry.path(), std::ios::binary); + std::vector buffer = std::vector(std::istreambuf_iterator(file), {}); + file.close(); + std::string cpath = entry.path().filename().string(); + std::replace(cpath.begin(), cpath.end(), '+', '/'); + this->gCacheData[cache][cpath] = buffer; + } else if(ext == ".yaml") { + std::ifstream file(entry.path(), std::ios::binary); + YAML::Node dependencies = YAML::LoadFile(entry.path().string()); + for(auto dep = dependencies.begin(); dep != dependencies.end(); ++dep) { + this->gAssetDependencies[this->gCurrentFile][dep->first.as()] = std::make_pair(dep->second.as(), false); + } + } } } } else { @@ -459,7 +469,20 @@ void Companion::PrepareCache(const std::string& path) { void Companion::StoreCache(const std::string path, const std::vector& value) { std::string outpath = path; std::replace(outpath.begin(), outpath.end(), '/', '+'); - std::ofstream file("tcache/" + this->gCurrentCacheHash + "/" + outpath, std::ios::binary); + + + YAML::Node dependencies = YAML::Node(); + + // Dump asset dependencies + for (auto [fst, snd] : this->gAssetDependencies[this->gCurrentFile]) { + dependencies[fst] = snd.first; + } + + std::ofstream deps("tcache/" + this->gCurrentCacheHash + "/" + outpath + "-deps.yaml", std::ios::binary); + deps << dependencies; + deps.close(); + + std::ofstream file("tcache/" + this->gCurrentCacheHash + "/" + outpath + ".data", std::ios::binary); file.write(reinterpret_cast(value.data()), value.size()); file.close(); } @@ -1009,6 +1032,8 @@ std::optional> Companion::RegisterAsset(cons auto entry = std::make_tuple(output, node); this->gAddrMap[this->gCurrentFile][node["offset"].as()] = entry; + + return entry; } -- cgit v1.2.3