diff --git a/SHADE_Engine/src/Assets/SHAssetManager.cpp b/SHADE_Engine/src/Assets/SHAssetManager.cpp index dbe9dd27..f4727417 100644 --- a/SHADE_Engine/src/Assets/SHAssetManager.cpp +++ b/SHADE_Engine/src/Assets/SHAssetManager.cpp @@ -373,6 +373,13 @@ namespace SHADE return folderRoot; } + void SHAssetManager::RefreshDirectory() noexcept + { + SHFileSystem::DestroyDirectory(folderRoot); + assetCollection.clear(); + BuildAssetCollection(); + } + bool SHAssetManager::IsRecognised(char const* ext) noexcept { for (auto const& e : EXTENSIONS) diff --git a/SHADE_Engine/src/Assets/SHAssetManager.h b/SHADE_Engine/src/Assets/SHAssetManager.h index 7fd7d039..a891ec23 100644 --- a/SHADE_Engine/src/Assets/SHAssetManager.h +++ b/SHADE_Engine/src/Assets/SHAssetManager.h @@ -90,6 +90,7 @@ namespace SHADE static void CompileAsset(AssetPath const& path, bool genMeta) noexcept; static FolderPointer GetRootFolder() noexcept; + static void RefreshDirectory() noexcept; private: diff --git a/SHADE_Engine/src/Filesystem/SHFileSystem.cpp b/SHADE_Engine/src/Filesystem/SHFileSystem.cpp index fe9b67f5..c4bcc5dc 100644 --- a/SHADE_Engine/src/Filesystem/SHFileSystem.cpp +++ b/SHADE_Engine/src/Filesystem/SHFileSystem.cpp @@ -12,6 +12,7 @@ #include "SHFileSystem.h" #include #include +#include #include "Assets/SHAssetMetaHandler.h" @@ -39,15 +40,15 @@ namespace SHADE void SHFileSystem::BuildDirectory(FolderPath path, FolderPointer& root, std::unordered_map& assetCollection) noexcept { - std::queue folderQueue; + std::stack folderStack; root = new SHFolder("root"); root->path = path; - folderQueue.push(root); + folderStack.push(root); - while (!folderQueue.empty()) + while (!folderStack.empty()) { - auto const folder = folderQueue.front(); - folderQueue.pop(); + auto const folder = folderStack.top(); + folderStack.pop(); std::vector assets; @@ -77,7 +78,7 @@ namespace SHADE } auto newFolder{ folder->CreateSubFolderHere(path.stem().string()) }; - folderQueue.push(newFolder); + folderStack.push(newFolder); } for (auto const& asset : assets) @@ -98,4 +99,23 @@ namespace SHADE } } } + + void SHFileSystem::DestroyDirectory(FolderPointer root) noexcept + { + std::stack folderStack; + folderStack.push(root); + + while(!folderStack.empty()) + { + auto const folder = folderStack.top(); + folderStack.pop(); + + for (auto const& ptr : folder->subFolders) + { + folderStack.push(ptr); + } + + delete folder; + } + } } diff --git a/SHADE_Engine/src/Filesystem/SHFileSystem.h b/SHADE_Engine/src/Filesystem/SHFileSystem.h index 3f2e1c5b..87d13f42 100644 --- a/SHADE_Engine/src/Filesystem/SHFileSystem.h +++ b/SHADE_Engine/src/Filesystem/SHFileSystem.h @@ -20,7 +20,7 @@ namespace SHADE { public: static void BuildDirectory(FolderPath path, FolderPointer& root, std::unordered_map& assetCollection) noexcept; - + static void DestroyDirectory(FolderPointer root) noexcept; private: static bool DeleteFolder(FolderPointer location) noexcept; static bool IsCompilable(std::string ext) noexcept;