Merge pull request #188 from SHADE-DP/SP3-13-Assets-Manager
SP3-13 Assets Management Added data member to SHFile to indicate whether file can be compiled Added asset directory refresh (rebuilds asset collection and directory) Fixed File link to meta Fixed extension to type conversion
This commit is contained in:
commit
7da61f4a22
|
@ -51,6 +51,7 @@ enum class AssetType : AssetTypeMeta
|
||||||
SCENE,
|
SCENE,
|
||||||
PREFAB,
|
PREFAB,
|
||||||
MATERIAL,
|
MATERIAL,
|
||||||
|
SCRIPT,
|
||||||
MESH,
|
MESH,
|
||||||
MAX_COUNT
|
MAX_COUNT
|
||||||
};
|
};
|
||||||
|
@ -91,12 +92,12 @@ constexpr std::string_view EXTENSIONS[] = {
|
||||||
AUDIO_EXTENSION,
|
AUDIO_EXTENSION,
|
||||||
SHADER_EXTENSION,
|
SHADER_EXTENSION,
|
||||||
SHADER_BUILT_IN_EXTENSION,
|
SHADER_BUILT_IN_EXTENSION,
|
||||||
MATERIAL_EXTENSION,
|
|
||||||
TEXTURE_EXTENSION,
|
TEXTURE_EXTENSION,
|
||||||
MODEL_EXTENSION,
|
MODEL_EXTENSION,
|
||||||
SCRIPT_EXTENSION,
|
|
||||||
SCENE_EXTENSION,
|
SCENE_EXTENSION,
|
||||||
PREFAB_EXTENSION,
|
PREFAB_EXTENSION,
|
||||||
|
MATERIAL_EXTENSION,
|
||||||
|
SCRIPT_EXTENSION,
|
||||||
AUDIO_WAV_EXTENSION,
|
AUDIO_WAV_EXTENSION,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -338,7 +338,7 @@ namespace SHADE
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHAssetManager::CompileAsset(AssetPath const& path) noexcept
|
void SHAssetManager::CompileAsset(AssetPath const& path, bool genMeta) noexcept
|
||||||
{
|
{
|
||||||
if (!std::filesystem::exists(path))
|
if (!std::filesystem::exists(path))
|
||||||
{
|
{
|
||||||
|
@ -360,10 +360,12 @@ namespace SHADE
|
||||||
std::string modelPath = path.string().substr(0, path.string().find_last_of('.'));
|
std::string modelPath = path.string().substr(0, path.string().find_last_of('.'));
|
||||||
modelPath += MODEL_EXTENSION;
|
modelPath += MODEL_EXTENSION;
|
||||||
newPath = modelPath;
|
newPath = modelPath;
|
||||||
|
|
||||||
GenerateNewMeta(newPath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (genMeta)
|
||||||
|
{
|
||||||
|
GenerateNewMeta(newPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FolderPointer SHAssetManager::GetRootFolder() noexcept
|
FolderPointer SHAssetManager::GetRootFolder() noexcept
|
||||||
|
@ -371,6 +373,13 @@ namespace SHADE
|
||||||
return folderRoot;
|
return folderRoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SHAssetManager::RefreshDirectory() noexcept
|
||||||
|
{
|
||||||
|
SHFileSystem::DestroyDirectory(folderRoot);
|
||||||
|
assetCollection.clear();
|
||||||
|
BuildAssetCollection();
|
||||||
|
}
|
||||||
|
|
||||||
bool SHAssetManager::IsRecognised(char const* ext) noexcept
|
bool SHAssetManager::IsRecognised(char const* ext) noexcept
|
||||||
{
|
{
|
||||||
for (auto const& e : EXTENSIONS)
|
for (auto const& e : EXTENSIONS)
|
||||||
|
|
|
@ -87,9 +87,10 @@ namespace SHADE
|
||||||
static std::vector<SHAssetData const*> GetAllDataOfType(AssetType type) noexcept;
|
static std::vector<SHAssetData const*> GetAllDataOfType(AssetType type) noexcept;
|
||||||
static std::vector<SHAsset> GetAllRecordOfType(AssetType type) noexcept;
|
static std::vector<SHAsset> GetAllRecordOfType(AssetType type) noexcept;
|
||||||
|
|
||||||
static void CompileAsset(AssetPath const& path) noexcept;
|
static void CompileAsset(AssetPath const& path, bool genMeta) noexcept;
|
||||||
|
|
||||||
static FolderPointer GetRootFolder() noexcept;
|
static FolderPointer GetRootFolder() noexcept;
|
||||||
|
static void RefreshDirectory() noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "SHFileSystem.h"
|
#include "SHFileSystem.h"
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
#include <stack>
|
||||||
|
|
||||||
#include "Assets/SHAssetMetaHandler.h"
|
#include "Assets/SHAssetMetaHandler.h"
|
||||||
|
|
||||||
|
@ -24,23 +25,37 @@ namespace SHADE
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SHFileSystem::IsCompilable(std::string ext) noexcept
|
||||||
|
{
|
||||||
|
for (auto const& external : EXTERNALS)
|
||||||
|
{
|
||||||
|
if (ext == external)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void SHFileSystem::BuildDirectory(FolderPath path, FolderPointer& root, std::unordered_map<AssetID, SHAsset>& assetCollection) noexcept
|
void SHFileSystem::BuildDirectory(FolderPath path, FolderPointer& root, std::unordered_map<AssetID, SHAsset>& assetCollection) noexcept
|
||||||
{
|
{
|
||||||
std::queue<FolderPointer> folderQueue;
|
std::stack<FolderPointer> folderStack;
|
||||||
root = new SHFolder("root");
|
root = new SHFolder("root");
|
||||||
root->path = path;
|
root->path = path;
|
||||||
folderQueue.push(root);
|
folderStack.push(root);
|
||||||
|
|
||||||
while (!folderQueue.empty())
|
while (!folderStack.empty())
|
||||||
{
|
{
|
||||||
auto const folder = folderQueue.front();
|
auto const folder = folderStack.top();
|
||||||
folderQueue.pop();
|
folderStack.pop();
|
||||||
|
|
||||||
std::vector<SHAsset> assets;
|
std::vector<SHAsset> assets;
|
||||||
|
|
||||||
for (auto const& dirEntry : std::filesystem::directory_iterator(folder->path))
|
for (auto& dirEntry : std::filesystem::directory_iterator(folder->path))
|
||||||
{
|
{
|
||||||
auto const& path = dirEntry.path();
|
auto path = dirEntry.path();
|
||||||
|
path.make_preferred();
|
||||||
if (!dirEntry.is_directory())
|
if (!dirEntry.is_directory())
|
||||||
{
|
{
|
||||||
if (path.extension().string() == META_EXTENSION)
|
if (path.extension().string() == META_EXTENSION)
|
||||||
|
@ -55,14 +70,15 @@ namespace SHADE
|
||||||
path.stem().string(),
|
path.stem().string(),
|
||||||
path.string(),
|
path.string(),
|
||||||
path.extension().string(),
|
path.extension().string(),
|
||||||
nullptr
|
nullptr,
|
||||||
|
IsCompilable(path.extension().string())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto newFolder{ folder->CreateSubFolderHere(path.stem().string()) };
|
auto newFolder{ folder->CreateSubFolderHere(path.stem().string()) };
|
||||||
folderQueue.push(newFolder);
|
folderStack.push(newFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto const& asset : assets)
|
for (auto const& asset : assets)
|
||||||
|
@ -71,6 +87,9 @@ namespace SHADE
|
||||||
for(auto& file : folder->files)
|
for(auto& file : folder->files)
|
||||||
{
|
{
|
||||||
if (file.name == asset.name)
|
if (file.name == asset.name)
|
||||||
|
{
|
||||||
|
AssetPath path{ file.path };
|
||||||
|
if (SHAssetMetaHandler::GetTypeFromExtension(path.extension().string()) == asset.type)
|
||||||
{
|
{
|
||||||
file.assetMeta = &assetCollection[asset.id];
|
file.assetMeta = &assetCollection[asset.id];
|
||||||
break;
|
break;
|
||||||
|
@ -80,3 +99,23 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SHFileSystem::DestroyDirectory(FolderPointer root) noexcept
|
||||||
|
{
|
||||||
|
std::stack<FolderPointer> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -20,9 +20,9 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void BuildDirectory(FolderPath path, FolderPointer& root, std::unordered_map<AssetID, SHAsset>& assetCollection) noexcept;
|
static void BuildDirectory(FolderPath path, FolderPointer& root, std::unordered_map<AssetID, SHAsset>& assetCollection) noexcept;
|
||||||
|
static void DestroyDirectory(FolderPointer root) noexcept;
|
||||||
private:
|
private:
|
||||||
static bool DeleteFolder(FolderPointer location) noexcept;
|
static bool DeleteFolder(FolderPointer location) noexcept;
|
||||||
|
static bool IsCompilable(std::string ext) noexcept;
|
||||||
};
|
};
|
||||||
}
|
}
|
|
@ -33,6 +33,7 @@ namespace SHADE
|
||||||
FilePath path;
|
FilePath path;
|
||||||
FileExt ext;
|
FileExt ext;
|
||||||
SHAsset const* assetMeta;
|
SHAsset const* assetMeta;
|
||||||
|
bool compilable;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SHFolder
|
class SHFolder
|
||||||
|
|
Loading…
Reference in New Issue