Refactor asset handling

This commit is contained in:
Thraix
2024-10-01 19:48:21 +02:00
parent b256b90abb
commit 9133bce7fc
22 changed files with 196 additions and 125 deletions
@@ -0,0 +1,59 @@
#pragma once
#include "copium/asset/AssetMeta.h"
#include "copium/asset/AssetManager.h"
namespace Copium
{
template <typename AssetType>
class AssetHandle
{
public:
AssetHandle()
: id{NULL_ASSET_ID}
{}
AssetHandle(const std::string& assetName)
: id{AssetManager::LoadAsset(assetName).GetId()}
{}
AssetHandle(const Uuid& uuid)
: id{AssetManager::LoadAsset(uuid).GetId()}
{}
AssetHandle(AssetType& asset)
: id{AssetManager::DuplicateAsset(asset.GetId())}
{}
AssetHandle(const std::string& name, std::unique_ptr<AssetType>&& runtimeAsset)
: id{AssetManager::RegisterRuntimeAsset(name, std::move(runtimeAsset)).GetId()}
{}
AssetHandle(AssetId id)
: id{AssetManager::DuplicateAsset(id)}
{}
AssetId GetId() const
{
return id;
}
AssetType& GetAsset() const
{
return AssetManager::GetAsset<AssetType>(id);
}
void UnloadAsset()
{
AssetManager::UnloadAsset(id);
id = NULL_ASSET_ID;
}
bool Valid() const
{
return id != NULL_ASSET_ID;
}
private:
AssetId id;
};
}