From 6df3f3d4174c7ae4f5e5e4b3c2f50eeb7c46ef5a Mon Sep 17 00:00:00 2001 From: Xiao Qi Date: Fri, 11 Nov 2022 10:47:03 +0800 Subject: [PATCH 1/3] Fixed get type from extension bug in asset handler --- SHADE_Engine/src/Assets/SHAssetMacros.h | 2 ++ SHADE_Engine/src/Assets/SHAssetMetaHandler.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/SHADE_Engine/src/Assets/SHAssetMacros.h b/SHADE_Engine/src/Assets/SHAssetMacros.h index 7ffdb5f1..7e5befab 100644 --- a/SHADE_Engine/src/Assets/SHAssetMacros.h +++ b/SHADE_Engine/src/Assets/SHAssetMacros.h @@ -102,6 +102,8 @@ constexpr std::string_view EXTENSIONS[] = { AUDIO_WAV_EXTENSION, }; +constexpr size_t EXTENSIONS_COUNT{ 11 }; + // EXTERNAL EXTENSIONS constexpr std::string_view GLSL_EXTENSION{ ".glsl" }; constexpr std::string_view DDS_EXTENSION{ ".dds" }; diff --git a/SHADE_Engine/src/Assets/SHAssetMetaHandler.cpp b/SHADE_Engine/src/Assets/SHAssetMetaHandler.cpp index b75ee1ad..f3b24ed1 100644 --- a/SHADE_Engine/src/Assets/SHAssetMetaHandler.cpp +++ b/SHADE_Engine/src/Assets/SHAssetMetaHandler.cpp @@ -38,7 +38,7 @@ namespace SHADE ****************************************************************************/ AssetType SHAssetMetaHandler::GetTypeFromExtension(AssetExtension ext) noexcept { - for (int i{0}; i < EXTENSIONS->size(); ++i) + for (auto i{0}; i < EXTENSIONS_COUNT; ++i) { if (strcmp(ext.c_str(), EXTENSIONS[i].data()) == 0) { From 9fe5dc385bf6f55b1e91f461cead7743877882b0 Mon Sep 17 00:00:00 2001 From: Xiao Qi Date: Fri, 11 Nov 2022 10:52:57 +0800 Subject: [PATCH 2/3] Implemented check for raw asset if compiled --- SHADE_Engine/src/Filesystem/SHFileSystem.cpp | 63 +++++++++++++++++++- SHADE_Engine/src/Filesystem/SHFileSystem.h | 1 + SHADE_Engine/src/Filesystem/SHFolder.h | 3 +- 3 files changed, 64 insertions(+), 3 deletions(-) diff --git a/SHADE_Engine/src/Filesystem/SHFileSystem.cpp b/SHADE_Engine/src/Filesystem/SHFileSystem.cpp index c4bcc5dc..9144b0d8 100644 --- a/SHADE_Engine/src/Filesystem/SHFileSystem.cpp +++ b/SHADE_Engine/src/Filesystem/SHFileSystem.cpp @@ -38,6 +38,41 @@ namespace SHADE return false; } + bool SHFileSystem::MatchExtention(FileExt raw, FileExt compiled) noexcept + { + if (raw == GLSL_EXTENSION) + { + if (compiled == SHADER_EXTENSION || + compiled == SHADER_BUILT_IN_EXTENSION) + { + return true; + } + } + else if (raw == DDS_EXTENSION) + { + if (compiled == TEXTURE_EXTENSION) + { + return true; + } + } + else if (raw == FBX_EXTENSION) + { + if (compiled == MODEL_EXTENSION) + { + return true; + } + } + else if (raw == GLTF_EXTENSION) + { + if (compiled == MODEL_EXTENSION) + { + return true; + } + } + + return false; + } + void SHFileSystem::BuildDirectory(FolderPath path, FolderPointer& root, std::unordered_map& assetCollection) noexcept { std::stack folderStack; @@ -52,6 +87,7 @@ namespace SHADE std::vector assets; + // Get all subfolders/files in this current folder for (auto& dirEntry : std::filesystem::directory_iterator(folder->path)) { auto path = dirEntry.path(); @@ -60,8 +96,6 @@ namespace SHADE { if (path.extension().string() == META_EXTENSION) { - //auto asset = SHAssetMetaHandler::RetrieveMetaData(path); - //assetCollection.insert({ asset.id, asset }); assets.push_back(SHAssetMetaHandler::RetrieveMetaData(path)); } else @@ -77,6 +111,7 @@ namespace SHADE continue; } + // If item is folder auto newFolder{ folder->CreateSubFolderHere(path.stem().string()) }; folderStack.push(newFolder); } @@ -97,6 +132,30 @@ namespace SHADE } } } + + for (auto i {0}; i < folder->files.size(); ++i) + { + auto& file = folder->files[i]; + if (file.compilable) + { + for (auto j{ 0 }; j < folder->files.size(); ++j) + { + auto& check = folder->files[j]; + if (i == j || check.compilable) + { + continue; + } + + if (file.name == check.name) + { + if (MatchExtention(file.ext, check.ext)) + { + file.compiled = true; + } + } + } + } + } } } diff --git a/SHADE_Engine/src/Filesystem/SHFileSystem.h b/SHADE_Engine/src/Filesystem/SHFileSystem.h index 87d13f42..d30f2164 100644 --- a/SHADE_Engine/src/Filesystem/SHFileSystem.h +++ b/SHADE_Engine/src/Filesystem/SHFileSystem.h @@ -24,5 +24,6 @@ namespace SHADE private: static bool DeleteFolder(FolderPointer location) noexcept; static bool IsCompilable(std::string ext) noexcept; + static bool MatchExtention(FileExt raw, FileExt compiled) noexcept; }; } \ No newline at end of file diff --git a/SHADE_Engine/src/Filesystem/SHFolder.h b/SHADE_Engine/src/Filesystem/SHFolder.h index 5c702b51..234e6f19 100644 --- a/SHADE_Engine/src/Filesystem/SHFolder.h +++ b/SHADE_Engine/src/Filesystem/SHFolder.h @@ -33,7 +33,8 @@ namespace SHADE FilePath path; FileExt ext; SHAsset const* assetMeta; - bool compilable; + bool compilable; + bool compiled; }; class SHFolder From 94b64e92dd51ac837aadaa266d696f93dc49a9a8 Mon Sep 17 00:00:00 2001 From: Xiao Qi Date: Fri, 11 Nov 2022 10:55:19 +0800 Subject: [PATCH 3/3] Initialise files to not compiled --- SHADE_Engine/src/Filesystem/SHFileSystem.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SHADE_Engine/src/Filesystem/SHFileSystem.cpp b/SHADE_Engine/src/Filesystem/SHFileSystem.cpp index 9144b0d8..9aaf72a4 100644 --- a/SHADE_Engine/src/Filesystem/SHFileSystem.cpp +++ b/SHADE_Engine/src/Filesystem/SHFileSystem.cpp @@ -105,7 +105,8 @@ namespace SHADE path.string(), path.extension().string(), nullptr, - IsCompilable(path.extension().string()) + IsCompilable(path.extension().string()), + false ); } continue;