Added data member to signal whether asset file can be compiled

Properly linked meta file to file in directory

Fixed extension to type conversion bug
This commit is contained in:
Xiao Qi 2022-11-10 16:44:16 +08:00
parent 35bcdc5239
commit 0e5609995f
6 changed files with 38 additions and 15 deletions

View File

@ -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,
TEXTURE_EXTENSION,
MODEL_EXTENSION,
SCRIPT_EXTENSION,
SCENE_EXTENSION,
SCENE_EXTENSION,
PREFAB_EXTENSION,
MATERIAL_EXTENSION,
SCRIPT_EXTENSION,
AUDIO_WAV_EXTENSION,
};

View File

@ -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

View File

@ -87,7 +87,7 @@ 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;

View File

@ -24,7 +24,20 @@ namespace SHADE
return true;
}
void SHFileSystem::BuildDirectory(FolderPath path, FolderPointer& root, std::unordered_map<AssetID, SHAsset>& assetCollection) noexcept
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;
root = new SHFolder("root");
@ -38,9 +51,10 @@ namespace SHADE
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,7 +69,8 @@ namespace SHADE
path.stem().string(),
path.string(),
path.extension().string(),
nullptr
nullptr,
IsCompilable(path.extension().string())
);
}
continue;
@ -72,8 +87,12 @@ namespace SHADE
{
if (file.name == asset.name)
{
file.assetMeta = &assetCollection[asset.id];
break;
AssetPath path{ file.path };
if (SHAssetMetaHandler::GetTypeFromExtension(path.extension().string()) == asset.type)
{
file.assetMeta = &assetCollection[asset.id];
break;
}
}
}
}

View File

@ -23,6 +23,6 @@ namespace SHADE
private:
static bool DeleteFolder(FolderPointer location) noexcept;
static bool IsCompilable(std::string ext) noexcept;
};
}

View File

@ -33,6 +33,7 @@ namespace SHADE
FilePath path;
FileExt ext;
SHAsset const* assetMeta;
bool compilable;
};
class SHFolder