[Assets] Handle streaming resources properly
This commit is contained in:
parent
841778fe2f
commit
cc91b8d3b9
|
|
@ -4,6 +4,12 @@
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
|
template <typename TResource>
|
||||||
|
concept IsStreamingResource = requires(TResource)
|
||||||
|
{
|
||||||
|
{ TResource::OpenFromFile({}) } -> std::same_as<std::shared_ptr<TResource>>;
|
||||||
|
};
|
||||||
|
|
||||||
template <typename TResource>
|
template <typename TResource>
|
||||||
Asset<TResource> AssetCatalog::LoadFromFile(const std::filesystem::path& path)
|
Asset<TResource> AssetCatalog::LoadFromFile(const std::filesystem::path& path)
|
||||||
{
|
{
|
||||||
|
|
@ -20,11 +26,27 @@ namespace Nz
|
||||||
if (fs) // first try using a FileSystem component to load the asset
|
if (fs) // first try using a FileSystem component to load the asset
|
||||||
{
|
{
|
||||||
std::string filepath = asset.m_descriptor.path.string();
|
std::string filepath = asset.m_descriptor.path.string();
|
||||||
asset.m_resource = fs->Load<TResource>(std::string_view(filepath), asset.m_descriptor.parameters);
|
if constexpr (IsStreamingResource<TResource>)
|
||||||
|
{
|
||||||
|
asset.m_resource = fs->Open<TResource>(std::string_view(filepath), asset.m_descriptor.parameters);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
asset.m_resource = fs->Load<TResource>(std::string_view(filepath), asset.m_descriptor.parameters);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!asset) // if it fails, use the default loader
|
if (!asset) // if it fails, use the default loader
|
||||||
asset.m_resource = TResource::LoadFromFile(asset.m_descriptor.path, asset.m_descriptor.parameters);
|
{
|
||||||
|
if constexpr (IsStreamingResource<TResource>)
|
||||||
|
{
|
||||||
|
asset.m_resource = TResource::OpenFromFile(asset.m_descriptor.path, asset.m_descriptor.parameters);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
asset.m_resource = TResource::LoadFromFile(asset.m_descriptor.path, asset.m_descriptor.parameters);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return asset;
|
return asset;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue