Removed line that loaded all assets

Separated template function in asset manager into hpp file
Fixed bug in checking map contains
This commit is contained in:
Xiao Qi 2022-10-23 16:55:57 +08:00
parent 304071cb0a
commit a83d1f8f04
4 changed files with 37 additions and 30 deletions

View File

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

View File

@ -76,25 +76,7 @@ namespace SHADE
// -------------------------------------------------------------------------/ // -------------------------------------------------------------------------/
template<typename T> template<typename T>
static std::enable_if_t<std::is_base_of_v<SHAssetData, T>, T const * const> GetData(AssetID id) noexcept 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]);
}
private: private:
/**************************************************************************** /****************************************************************************
* \brief Load resource data into memory * \brief Load resource data into memory
@ -121,3 +103,5 @@ namespace SHADE
static std::unordered_map<AssetID, SHAssetData * const> assetData; 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 */ /* Query Functions */
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
template<typename T> 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); const Handle GENERIC_HANDLE = Handle(handle);
auto [typedHandleMap, typedAssetIdMap] = getAssetHandleMap<T>(); auto [typedHandleMap, typedAssetIdMap] = getAssetHandleMap<T>();