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:
parent
304071cb0a
commit
a83d1f8f04
|
@ -56,10 +56,7 @@ 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
|
||||||
|
@ -256,7 +253,7 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
InitLoaders();
|
InitLoaders();
|
||||||
BuildAssetCollection();
|
BuildAssetCollection();
|
||||||
LoadAllData();
|
//LoadAllData();
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|
|
@ -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"
|
||||||
|
|
|
@ -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]);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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>();
|
||||||
|
|
Loading…
Reference in New Issue