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,10 +56,7 @@ namespace SHADE
****************************************************************************/
void SHAssetManager::Unload() noexcept
{
for (auto const& asset : assetCollection)
{
SHAssetMetaHandler::WriteMetaData(asset);
}
}
void SHAssetManager::Unload(AssetID assetId) noexcept
@ -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>();