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,
|
||||
PREFAB,
|
||||
MATERIAL,
|
||||
SCRIPT,
|
||||
MESH,
|
||||
MAX_COUNT
|
||||
};
|
||||
|
@ -91,12 +92,12 @@ constexpr std::string_view EXTENSIONS[] = {
|
|||
AUDIO_EXTENSION,
|
||||
SHADER_EXTENSION,
|
||||
SHADER_BUILT_IN_EXTENSION,
|
||||
MATERIAL_EXTENSION,
|
||||
TEXTURE_EXTENSION,
|
||||
MODEL_EXTENSION,
|
||||
SCRIPT_EXTENSION,
|
||||
SCENE_EXTENSION,
|
||||
PREFAB_EXTENSION,
|
||||
MATERIAL_EXTENSION,
|
||||
SCRIPT_EXTENSION,
|
||||
AUDIO_WAV_EXTENSION,
|
||||
};
|
||||
|
||||
|
|
|
@ -338,7 +338,7 @@ namespace SHADE
|
|||
return result;
|
||||
}
|
||||
|
||||
void SHAssetManager::CompileAsset(AssetPath const& path) noexcept
|
||||
void SHAssetManager::CompileAsset(AssetPath const& path, bool genMeta) noexcept
|
||||
{
|
||||
if (!std::filesystem::exists(path))
|
||||
{
|
||||
|
@ -360,10 +360,12 @@ namespace SHADE
|
|||
std::string modelPath = path.string().substr(0, path.string().find_last_of('.'));
|
||||
modelPath += MODEL_EXTENSION;
|
||||
newPath = modelPath;
|
||||
|
||||
GenerateNewMeta(newPath);
|
||||
}
|
||||
|
||||
if (genMeta)
|
||||
{
|
||||
GenerateNewMeta(newPath);
|
||||
}
|
||||
}
|
||||
|
||||
FolderPointer SHAssetManager::GetRootFolder() noexcept
|
||||
|
@ -371,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)
|
||||
|
|
|
@ -87,9 +87,10 @@ namespace SHADE
|
|||
static std::vector<SHAssetData const*> GetAllDataOfType(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 void RefreshDirectory() noexcept;
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "SHFileSystem.h"
|
||||
#include <filesystem>
|
||||
#include <queue>
|
||||
#include <stack>
|
||||
|
||||
#include "Assets/SHAssetMetaHandler.h"
|
||||
|
||||
|
@ -24,23 +25,37 @@ namespace SHADE
|
|||
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
|
||||
{
|
||||
std::queue<FolderPointer> folderQueue;
|
||||
std::stack<FolderPointer> 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<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 (path.extension().string() == META_EXTENSION)
|
||||
|
@ -55,14 +70,15 @@ namespace SHADE
|
|||
path.stem().string(),
|
||||
path.string(),
|
||||
path.extension().string(),
|
||||
nullptr
|
||||
nullptr,
|
||||
IsCompilable(path.extension().string())
|
||||
);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
auto newFolder{ folder->CreateSubFolderHere(path.stem().string()) };
|
||||
folderQueue.push(newFolder);
|
||||
folderStack.push(newFolder);
|
||||
}
|
||||
|
||||
for (auto const& asset : assets)
|
||||
|
@ -71,6 +87,9 @@ namespace SHADE
|
|||
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;
|
||||
|
@ -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:
|
||||
static void BuildDirectory(FolderPath path, FolderPointer& root, std::unordered_map<AssetID, SHAsset>& assetCollection) noexcept;
|
||||
|
||||
static void DestroyDirectory(FolderPointer root) noexcept;
|
||||
private:
|
||||
static bool DeleteFolder(FolderPointer location) noexcept;
|
||||
|
||||
static bool IsCompilable(std::string ext) noexcept;
|
||||
};
|
||||
}
|
|
@ -33,6 +33,7 @@ namespace SHADE
|
|||
FilePath path;
|
||||
FileExt ext;
|
||||
SHAsset const* assetMeta;
|
||||
bool compilable;
|
||||
};
|
||||
|
||||
class SHFolder
|
||||
|
|
Loading…
Reference in New Issue