From 16e357acb09ef581642e40b4c4d1f6be9542fa14 Mon Sep 17 00:00:00 2001 From: Xiao Qi Date: Mon, 14 Nov 2022 21:18:36 +0800 Subject: [PATCH] Accounted for texture compilation Changed refresh, doesnt clear asset collection anymore Checks for preexisting sub assets and asset meta in collection --- SHADE_Engine/src/Assets/SHAssetManager.cpp | 56 ++++++++++++++++--- .../src/Assets/SHAssetMetaHandler.cpp | 1 + SHADE_Engine/src/Filesystem/SHFileSystem.cpp | 21 ++----- 3 files changed, 54 insertions(+), 24 deletions(-) diff --git a/SHADE_Engine/src/Assets/SHAssetManager.cpp b/SHADE_Engine/src/Assets/SHAssetManager.cpp index a7f4d8d9..b4ea7d35 100644 --- a/SHADE_Engine/src/Assets/SHAssetManager.cpp +++ b/SHADE_Engine/src/Assets/SHAssetManager.cpp @@ -161,21 +161,39 @@ namespace SHADE newPath += PREFAB_FOLDER; newPath += name; newPath += PREFAB_EXTENSION; - data = new SHPrefabAsset(); + { + auto prefab = new SHPrefabAsset(); + prefab->name = name; + + data = prefab; + } + break; case AssetType::SCENE: newPath += SCENE_FOLDER; newPath += name; newPath += SCENE_EXTENSION; - data = new SHSceneAsset(); + + { + auto scene = new SHSceneAsset(); + scene->name = name; + + data = scene; + } break; case AssetType::MATERIAL: newPath += MATERIAL_FOLDER; newPath += name; newPath += MATERIAL_EXTENSION; - data = new SHMaterialAsset(); + + { + auto material = new SHMaterialAsset(); + material->name = name; + + data = material; + } break; default: @@ -192,7 +210,7 @@ namespace SHADE false }; - assetCollection.insert({ + auto result = assetCollection.emplace( id, SHAsset( name, @@ -201,10 +219,13 @@ namespace SHADE newPath, false ) - }); + ); assetData.emplace(id, data); + SHAssetMetaHandler::WriteMetaData(asset); + SaveAsset(id); + return id; } @@ -361,6 +382,21 @@ namespace SHADE modelPath += MODEL_EXTENSION; newPath = modelPath; } + else if (ext == DDS_EXTENSION.data()) + { + auto pathGen = SHTextureCompiler::CompileTextureAsset(path); + if (!pathGen.has_value()) + { + SHLOG_ERROR("Texture Compilation Failed for: {}", path.string()); + return; + } + newPath = pathGen.value(); + } + else + { + SHLOG_WARNING("File Type compilation not yet Implemented: {}", path.string()); + return; + } if (genMeta) { @@ -376,7 +412,7 @@ namespace SHADE void SHAssetManager::RefreshDirectory() noexcept { SHFileSystem::DestroyDirectory(folderRoot); - assetCollection.clear(); + //assetCollection.clear(); BuildAssetCollection(); } @@ -507,7 +543,7 @@ namespace SHADE { SHAsset newAsset{ path.stem().string(), - GenerateAssetID(AssetType::SHADER_BUILT_IN), + GenerateAssetID(AssetType::TEXTURE), AssetType::SHADER_BUILT_IN, path, false @@ -614,6 +650,12 @@ namespace SHADE for (auto i{ 0 }; i < asset.subAssets.size(); ++i) { auto const id = asset.subAssets[i]->id; + + if (assetCollection.contains(id)) + { + continue; + } + assetCollection[id] = *asset.subAssets[i]; delete asset.subAssets[i]; asset.subAssets[i] = &assetCollection[id]; diff --git a/SHADE_Engine/src/Assets/SHAssetMetaHandler.cpp b/SHADE_Engine/src/Assets/SHAssetMetaHandler.cpp index f3b24ed1..b5c78514 100644 --- a/SHADE_Engine/src/Assets/SHAssetMetaHandler.cpp +++ b/SHADE_Engine/src/Assets/SHAssetMetaHandler.cpp @@ -138,6 +138,7 @@ namespace SHADE metaFile.close(); meta.path = path.parent_path().string() + "/" + path.stem().string(); + meta.path.make_preferred(); return meta; } diff --git a/SHADE_Engine/src/Filesystem/SHFileSystem.cpp b/SHADE_Engine/src/Filesystem/SHFileSystem.cpp index fa5f718e..a28f70ca 100644 --- a/SHADE_Engine/src/Filesystem/SHFileSystem.cpp +++ b/SHADE_Engine/src/Filesystem/SHFileSystem.cpp @@ -152,7 +152,10 @@ namespace SHADE bool found{ false }; for (auto const& asset : assets) { - assetCollection.emplace(asset.id, asset); + if (!assetCollection.contains(asset.id)) + { + assetCollection.emplace(asset.id, asset); + } if (file.name == asset.name) { AssetPath path{ file.path }; @@ -170,22 +173,6 @@ namespace SHADE 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) {