diff options
| author | KiritoDv <kiritodev01@gmail.com> | 2024-03-28 23:38:32 -0600 |
|---|---|---|
| committer | Lywx <kiritodev01@gmail.com> | 2024-03-29 03:03:55 -0600 |
| commit | d8df2a4826b6967e1263eaf017ae6e49801d8e3f (patch) | |
| tree | 032d843cb3ee91a4c6ac6803d4326655f770a35f | |
| parent | 216a56a9b7b07dcfd26a15a843e92d39ce5319f6 (diff) | |
Added dep loading
| -rw-r--r-- | src/Companion.cpp | 39 |
1 files 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<uint8_t> buffer = std::vector<uint8_t>(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<uint8_t> buffer = std::vector<uint8_t>(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::string>()] = std::make_pair(dep->second.as<YAML::Node>(), false); + } + } } } } else { @@ -459,7 +469,20 @@ void Companion::PrepareCache(const std::string& path) { void Companion::StoreCache(const std::string path, const std::vector<uint8_t>& 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<const char*>(value.data()), value.size()); file.close(); } @@ -1009,6 +1032,8 @@ std::optional<std::tuple<std::string, YAML::Node>> Companion::RegisterAsset(cons auto entry = std::make_tuple(output, node); this->gAddrMap[this->gCurrentFile][node["offset"].as<uint32_t>()] = entry; + + return entry; } |
