Restructured Asset Manager with Generalised Template Types for Asset Data #111

Merged
XiaoQiDigipen merged 9 commits from SP3-13-Assets-Manager into main 2022-10-23 17:21:17 +08:00
4 changed files with 37 additions and 30 deletions
Showing only changes of commit a83d1f8f04 - Show all commits

View File

@ -56,18 +56,15 @@ namespace SHADE
****************************************************************************/
void SHAssetManager::Unload() noexcept
{
for (auto const& asset : assetCollection)
{
SHAssetMetaHandler::WriteMetaData(asset);
}
}
void SHAssetManager::Unload(AssetID assetId) noexcept
{
// TODO
}
void SHAssetManager::Unload(AssetID assetId) noexcept
{
// TODO
}
AssetPath SHAssetManager::GenerateLocalPath(AssetPath path) noexcept
AssetPath SHAssetManager::GenerateLocalPath(AssetPath path) noexcept
{
if (!IsRecognised(path.extension().string().c_str()))
{
@ -256,7 +253,7 @@ namespace SHADE
{
InitLoaders();
BuildAssetCollection();
LoadAllData();
//LoadAllData();
}
/****************************************************************************

View File

@ -76,25 +76,7 @@ namespace SHADE
// -------------------------------------------------------------------------/
template<typename T>
static std::enable_if_t<std::is_base_of_v<SHAssetData, T>, T const * const> GetData(AssetID id) noexcept
{
if (assetData.contains(id))
{
for (auto const& asset : assetCollection)
{
if (asset.id == id)
{
assetData.emplace(id, LoadData(asset));
return dynamic_cast<T const * const>(assetData[id]);
}
}
SHLOG_ERROR("Asset ID provided does not exist: {}", id);
return nullptr;
}
return dynamic_cast<T const * const>(assetData[id]);
}
static std::enable_if_t<std::is_base_of_v<SHAssetData, T>, T const* const> GetData(AssetID id) noexcept;
private:
/****************************************************************************
* \brief Load resource data into memory
@ -121,3 +103,5 @@ namespace SHADE
static std::unordered_map<AssetID, SHAssetData * const> assetData;
};
}
#include "SHAssetManager.hpp"

View File

@ -0,0 +1,26 @@
#include "SHAssetManager.h"
namespace SHADE
{
template<typename T>
std::enable_if_t<std::is_base_of_v<SHAssetData, T>, T const* const> SHAssetManager::GetData(AssetID id) noexcept
{
if (!assetData.contains(id))
{
for (auto const& asset : assetCollection)
{
if (asset.id == id)
{
assetData.emplace(id, LoadData(asset));
return dynamic_cast<T const* const>(assetData[id]);
}
}
SHLOG_ERROR("Asset ID provided does not exist: {}", id);
return nullptr;
}
return dynamic_cast<T const* const>(assetData[id]);
}
}

View File

@ -134,7 +134,7 @@ namespace SHADE
/* Query Functions */
/*-----------------------------------------------------------------------------------*/
template<typename T>
static std::optional<AssetID> SHResourceManager::GetAssetID(Handle<T> handle)
std::optional<AssetID> SHResourceManager::GetAssetID(Handle<T> handle)
{
const Handle GENERIC_HANDLE = Handle(handle);
auto [typedHandleMap, typedAssetIdMap] = getAssetHandleMap<T>();