From a8d4f9c7566358d358493e597d6133dbd691ae40 Mon Sep 17 00:00:00 2001 From: Xiao Qi Date: Sun, 13 Nov 2022 19:51:19 +0800 Subject: [PATCH] On building of asset file directory, check for recognised assets without meta file and generate --- Assets/Scripts/AIPrototype.cs.shmeta | 3 ++ Assets/Scripts/CameraControl.cs.shmeta | 3 ++ Assets/Scripts/CameraFix.cs.shmeta | 3 ++ Assets/Scripts/Item.cs.shmeta | 3 ++ Assets/Scripts/PhysicsTest.cs.shmeta | 3 ++ Assets/Scripts/PickAndThrow.cs.shmeta | 3 ++ Assets/Scripts/PlayerController.cs.shmeta | 3 ++ Assets/Scripts/PrintWhenActive.cs.shmeta | 3 ++ Assets/Scripts/RaccoonShowcase.cs.shmeta | 3 ++ Assets/Scripts/RaccoonSpin.cs.shmeta | 3 ++ Assets/Scripts/ThirdPersonCamera.cs.shmeta | 3 ++ SHADE_Engine/src/Assets/SHAssetManager.cpp | 40 +++++++++------ SHADE_Engine/src/Assets/SHAssetManager.h | 4 +- SHADE_Engine/src/Filesystem/SHFileSystem.cpp | 53 ++++++++++++++++++-- SHADE_Engine/src/Filesystem/SHFileSystem.h | 8 ++- 15 files changed, 114 insertions(+), 24 deletions(-) create mode 100644 Assets/Scripts/AIPrototype.cs.shmeta create mode 100644 Assets/Scripts/CameraControl.cs.shmeta create mode 100644 Assets/Scripts/CameraFix.cs.shmeta create mode 100644 Assets/Scripts/Item.cs.shmeta create mode 100644 Assets/Scripts/PhysicsTest.cs.shmeta create mode 100644 Assets/Scripts/PickAndThrow.cs.shmeta create mode 100644 Assets/Scripts/PlayerController.cs.shmeta create mode 100644 Assets/Scripts/PrintWhenActive.cs.shmeta create mode 100644 Assets/Scripts/RaccoonShowcase.cs.shmeta create mode 100644 Assets/Scripts/RaccoonSpin.cs.shmeta create mode 100644 Assets/Scripts/ThirdPersonCamera.cs.shmeta diff --git a/Assets/Scripts/AIPrototype.cs.shmeta b/Assets/Scripts/AIPrototype.cs.shmeta new file mode 100644 index 00000000..80a7d4b4 --- /dev/null +++ b/Assets/Scripts/AIPrototype.cs.shmeta @@ -0,0 +1,3 @@ +Name: AIPrototype +ID: 163215061 +Type: 9 diff --git a/Assets/Scripts/CameraControl.cs.shmeta b/Assets/Scripts/CameraControl.cs.shmeta new file mode 100644 index 00000000..bf68c31c --- /dev/null +++ b/Assets/Scripts/CameraControl.cs.shmeta @@ -0,0 +1,3 @@ +Name: CameraControl +ID: 158782344 +Type: 9 diff --git a/Assets/Scripts/CameraFix.cs.shmeta b/Assets/Scripts/CameraFix.cs.shmeta new file mode 100644 index 00000000..d1e5412a --- /dev/null +++ b/Assets/Scripts/CameraFix.cs.shmeta @@ -0,0 +1,3 @@ +Name: CameraFix +ID: 162231964 +Type: 9 diff --git a/Assets/Scripts/Item.cs.shmeta b/Assets/Scripts/Item.cs.shmeta new file mode 100644 index 00000000..84830b76 --- /dev/null +++ b/Assets/Scripts/Item.cs.shmeta @@ -0,0 +1,3 @@ +Name: Item +ID: 163145289 +Type: 9 diff --git a/Assets/Scripts/PhysicsTest.cs.shmeta b/Assets/Scripts/PhysicsTest.cs.shmeta new file mode 100644 index 00000000..99b809c5 --- /dev/null +++ b/Assets/Scripts/PhysicsTest.cs.shmeta @@ -0,0 +1,3 @@ +Name: PhysicsTest +ID: 159771801 +Type: 9 diff --git a/Assets/Scripts/PickAndThrow.cs.shmeta b/Assets/Scripts/PickAndThrow.cs.shmeta new file mode 100644 index 00000000..0eb38f59 --- /dev/null +++ b/Assets/Scripts/PickAndThrow.cs.shmeta @@ -0,0 +1,3 @@ +Name: PickAndThrow +ID: 165331952 +Type: 9 diff --git a/Assets/Scripts/PlayerController.cs.shmeta b/Assets/Scripts/PlayerController.cs.shmeta new file mode 100644 index 00000000..8b71915c --- /dev/null +++ b/Assets/Scripts/PlayerController.cs.shmeta @@ -0,0 +1,3 @@ +Name: PlayerController +ID: 164563088 +Type: 9 diff --git a/Assets/Scripts/PrintWhenActive.cs.shmeta b/Assets/Scripts/PrintWhenActive.cs.shmeta new file mode 100644 index 00000000..2b8c4173 --- /dev/null +++ b/Assets/Scripts/PrintWhenActive.cs.shmeta @@ -0,0 +1,3 @@ +Name: PrintWhenActive +ID: 162536221 +Type: 9 diff --git a/Assets/Scripts/RaccoonShowcase.cs.shmeta b/Assets/Scripts/RaccoonShowcase.cs.shmeta new file mode 100644 index 00000000..6ce5bc3d --- /dev/null +++ b/Assets/Scripts/RaccoonShowcase.cs.shmeta @@ -0,0 +1,3 @@ +Name: RaccoonShowcase +ID: 159969631 +Type: 9 diff --git a/Assets/Scripts/RaccoonSpin.cs.shmeta b/Assets/Scripts/RaccoonSpin.cs.shmeta new file mode 100644 index 00000000..9a1e05c8 --- /dev/null +++ b/Assets/Scripts/RaccoonSpin.cs.shmeta @@ -0,0 +1,3 @@ +Name: RaccoonSpin +ID: 157367824 +Type: 9 diff --git a/Assets/Scripts/ThirdPersonCamera.cs.shmeta b/Assets/Scripts/ThirdPersonCamera.cs.shmeta new file mode 100644 index 00000000..2f18c2fb --- /dev/null +++ b/Assets/Scripts/ThirdPersonCamera.cs.shmeta @@ -0,0 +1,3 @@ +Name: ThirdPersonCamera +ID: 154161201 +Type: 9 diff --git a/SHADE_Engine/src/Assets/SHAssetManager.cpp b/SHADE_Engine/src/Assets/SHAssetManager.cpp index 5a1bd5db..968e76dd 100644 --- a/SHADE_Engine/src/Assets/SHAssetManager.cpp +++ b/SHADE_Engine/src/Assets/SHAssetManager.cpp @@ -83,7 +83,7 @@ namespace SHADE AssetPath SHAssetManager::GenerateLocalPath(AssetPath path) noexcept { - if (!IsRecognised(path.extension().string().c_str())) + if (!SHFileSystem::IsRecognised(path.extension().string().c_str())) { //TODO:ASSERT UNRECOGNISED FILE TYPE return std::filesystem::path(); @@ -380,19 +380,6 @@ namespace SHADE BuildAssetCollection(); } - bool SHAssetManager::IsRecognised(char const* ext) noexcept - { - for (auto const& e : EXTENSIONS) - { - if (strcmp(ext, e.data()) == 0) - { - return true; - } - } - - return false; - } - SHAsset SHAssetManager::CreateAssetFromPath(AssetPath path) noexcept { SHAsset result; @@ -500,7 +487,7 @@ namespace SHADE { } - void SHAssetManager::GenerateNewMeta(AssetPath path) noexcept + std::optional SHAssetManager::GenerateNewMeta(AssetPath path) noexcept { auto const ext = path.extension().string(); if (ext == SHADER_BUILT_IN_EXTENSION.data()) @@ -561,11 +548,32 @@ namespace SHADE SHAssetMetaHandler::WriteMetaData(assetCollection[newAsset.id]); } + else if (ext == SCRIPT_EXTENSION) + { + SHAsset newAsset{ + path.stem().string(), + GenerateAssetID(AssetType::SCRIPT), + AssetType::SCRIPT, + path, + false + }; + assetCollection.emplace(newAsset.id, newAsset); + SHAssetMetaHandler::WriteMetaData(newAsset); + + return newAsset.id; + } } void SHAssetManager::BuildAssetCollection() noexcept { - SHFileSystem::BuildDirectory(ASSET_ROOT.data(), folderRoot, assetCollection); + std::vector toGenNew; + SHFileSystem::BuildDirectory(ASSET_ROOT.data(), folderRoot, assetCollection, toGenNew); + + for (auto& file : toGenNew) + { + auto newID{ GenerateNewMeta(file->path).value() }; + file->assetMeta = &assetCollection[newID]; + } for (auto& asset : std::ranges::views::values(assetCollection)) { diff --git a/SHADE_Engine/src/Assets/SHAssetManager.h b/SHADE_Engine/src/Assets/SHAssetManager.h index 5af648e4..f6ecb3a3 100644 --- a/SHADE_Engine/src/Assets/SHAssetManager.h +++ b/SHADE_Engine/src/Assets/SHAssetManager.h @@ -99,11 +99,9 @@ namespace SHADE static SHAssetData* LoadData(SHAsset const& asset) noexcept; static SHAssetData* LoadSubData(SHAsset const& asset) noexcept; static void LoadNewData(AssetPath path) noexcept; - static void GenerateNewMeta(AssetPath path) noexcept; + static std::optional GenerateNewMeta(AssetPath path) noexcept; inline static void BuildAssetCollection() noexcept; - - static bool IsRecognised(char const*) noexcept; static SHAsset CreateAssetFromPath(AssetPath path) noexcept; diff --git a/SHADE_Engine/src/Filesystem/SHFileSystem.cpp b/SHADE_Engine/src/Filesystem/SHFileSystem.cpp index 9aaf72a4..1062540b 100644 --- a/SHADE_Engine/src/Filesystem/SHFileSystem.cpp +++ b/SHADE_Engine/src/Filesystem/SHFileSystem.cpp @@ -25,6 +25,19 @@ namespace SHADE return true; } + bool SHFileSystem::IsRecognised(char const* ext) noexcept + { + for (auto const& e : EXTENSIONS) + { + if (strcmp(ext, e.data()) == 0) + { + return true; + } + } + + return false; + } + bool SHFileSystem::IsCompilable(std::string ext) noexcept { for (auto const& external : EXTERNALS) @@ -73,7 +86,11 @@ namespace SHADE return false; } - void SHFileSystem::BuildDirectory(FolderPath path, FolderPointer& root, std::unordered_map& assetCollection) noexcept + void SHFileSystem::BuildDirectory( + FolderPath path, + FolderPointer& root, + std::unordered_map& assetCollection, + std::vector& toGenerate) noexcept { std::stack folderStack; root = new SHFolder("root"); @@ -117,22 +134,50 @@ namespace SHADE folderStack.push(newFolder); } - for (auto const& asset : assets) + for (auto& file : folder->files) { - assetCollection.emplace(asset.id, asset); - for(auto& file : folder->files) + if (!IsRecognised(file.ext.c_str())) { + continue; + } + + bool found{ false }; + for (auto const& asset : assets) + { + assetCollection.emplace(asset.id, asset); if (file.name == asset.name) { AssetPath path{ file.path }; if (SHAssetMetaHandler::GetTypeFromExtension(path.extension().string()) == asset.type) { file.assetMeta = &assetCollection[asset.id]; + found = true; break; } } } + + if (!found) + { + toGenerate.push_back(&file); + } } + //for (auto const& asset : assets) + //{ + // assetCollection.emplace(asset.id, asset); + // for(auto& file : folder->files) + // { + // if (file.name == asset.name) + // { + // AssetPath path{ file.path }; + // if (SHAssetMetaHandler::GetTypeFromExtension(path.extension().string()) == asset.type) + // { + // file.assetMeta = &assetCollection[asset.id]; + // break; + // } + // } + // } + //} for (auto i {0}; i < folder->files.size(); ++i) { diff --git a/SHADE_Engine/src/Filesystem/SHFileSystem.h b/SHADE_Engine/src/Filesystem/SHFileSystem.h index d30f2164..4bace233 100644 --- a/SHADE_Engine/src/Filesystem/SHFileSystem.h +++ b/SHADE_Engine/src/Filesystem/SHFileSystem.h @@ -19,8 +19,14 @@ namespace SHADE class SHFileSystem { public: - static void BuildDirectory(FolderPath path, FolderPointer& root, std::unordered_map& assetCollection) noexcept; + static void BuildDirectory( + FolderPath path, + FolderPointer& root, + std::unordered_map& assetCollection, + std::vector& toGenerate) noexcept; static void DestroyDirectory(FolderPointer root) noexcept; + + static bool IsRecognised(char const*) noexcept; private: static bool DeleteFolder(FolderPointer location) noexcept; static bool IsCompilable(std::string ext) noexcept; -- 2.40.1