From cc91b8d3b9301d3ea3f3c0c01a3f9c0d4b5ad9e7 Mon Sep 17 00:00:00 2001 From: SweetId <2630750+SweetId@users.noreply.github.com> Date: Mon, 11 Mar 2024 17:14:56 -0400 Subject: [PATCH] [Assets] Handle streaming resources properly --- include/Nazara/Core/AssetCatalog.inl | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/include/Nazara/Core/AssetCatalog.inl b/include/Nazara/Core/AssetCatalog.inl index eb42851f6..292d6b73b 100644 --- a/include/Nazara/Core/AssetCatalog.inl +++ b/include/Nazara/Core/AssetCatalog.inl @@ -4,6 +4,12 @@ namespace Nz { + template + concept IsStreamingResource = requires(TResource) + { + { TResource::OpenFromFile({}) } -> std::same_as>; + }; + template Asset 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 { std::string filepath = asset.m_descriptor.path.string(); - asset.m_resource = fs->Load(std::string_view(filepath), asset.m_descriptor.parameters); + if constexpr (IsStreamingResource) + { + asset.m_resource = fs->Open(std::string_view(filepath), asset.m_descriptor.parameters); + } + else + { + asset.m_resource = fs->Load(std::string_view(filepath), asset.m_descriptor.parameters); + } } 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) + { + 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; }