Add Asset system
- Add Abstract Asset class which defines Assets - Add AssetManager class to keep track of all the Asset - Add AssetFile class to cache the asset without loading it - Add UUID class to uniquely identify assets - Add MetaFile class to load meta asset files
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
#include "copium/asset/AssetFile.h"
|
||||
|
||||
#include "copium/util/FileSystem.h"
|
||||
|
||||
namespace Copium
|
||||
{
|
||||
AssetFile::AssetFile(const std::string& path)
|
||||
: path{path}
|
||||
{
|
||||
Load();
|
||||
}
|
||||
|
||||
bool AssetFile::NeedReload() const
|
||||
{
|
||||
return dateModified < FileSystem::DateModified(path);
|
||||
}
|
||||
|
||||
void AssetFile::Load()
|
||||
{
|
||||
const std::vector<std::pair<std::string, AssetType>> strToType{{"Texture2D", AssetType::Texture2D}};
|
||||
MetaFile metaFile{path};
|
||||
for (auto&& [str, type] : strToType)
|
||||
{
|
||||
if (!metaFile.HasMetaClass(str))
|
||||
continue;
|
||||
|
||||
Load(metaFile, str, type);
|
||||
return;
|
||||
}
|
||||
CP_ABORT("Load : Unknown Asset type");
|
||||
}
|
||||
|
||||
const std::string& AssetFile::GetPath() const
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
UUID AssetFile::GetUUID() const
|
||||
{
|
||||
return uuid;
|
||||
}
|
||||
|
||||
void AssetFile::Load(const MetaFile& metaFile, const std::string& className, AssetType assetType)
|
||||
{
|
||||
const MetaFileClass& metaClass = metaFile.GetMetaClass(className);
|
||||
uuid = UUID{metaClass.GetValue("uuid")};
|
||||
type = assetType;
|
||||
dateModified = FileSystem::DateModified(path);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user