From 8bc953240d20d02eadbeca79189f2a7071b46fde Mon Sep 17 00:00:00 2001 From: SirLynix Date: Sun, 29 Jan 2023 18:13:35 +0100 Subject: [PATCH] Core/FilesystemComponent: Add a way to fix indices accross DLL boundaries --- .../Nazara/Core/AppFilesystemComponent.hpp | 3 +- .../Nazara/Core/AppFilesystemComponent.inl | 62 ++++++++++--------- src/Nazara/Graphics/Graphics.cpp | 2 + 3 files changed, 36 insertions(+), 31 deletions(-) diff --git a/include/Nazara/Core/AppFilesystemComponent.hpp b/include/Nazara/Core/AppFilesystemComponent.hpp index 6ef996c4f..aa943171f 100644 --- a/include/Nazara/Core/AppFilesystemComponent.hpp +++ b/include/Nazara/Core/AppFilesystemComponent.hpp @@ -48,9 +48,10 @@ namespace Nz AppFilesystemComponent& operator=(const AppFilesystemComponent&) = delete; AppFilesystemComponent& operator=(AppFilesystemComponent&&) = delete; + static inline void RegisterResourceTypes(); + private: template std::shared_ptr GetOrLoadImpl(std::string_view assetPath, const typename T::Params& params); - inline void RegisterResourceTypes(); std::vector> m_defaultParameters; VirtualDirectoryPtr m_rootDirectory; diff --git a/include/Nazara/Core/AppFilesystemComponent.inl b/include/Nazara/Core/AppFilesystemComponent.inl index cb48e65b3..5e37944be 100644 --- a/include/Nazara/Core/AppFilesystemComponent.inl +++ b/include/Nazara/Core/AppFilesystemComponent.inl @@ -82,6 +82,38 @@ namespace Nz m_defaultParameters[resourceIndex] = std::make_unique(std::move(params)); } + inline void AppFilesystemComponent::RegisterResourceTypes() + { + // TODO: Switch to hash-based approach like entt? + + if (ResourceRegistry::GetResourceId() != 0) + throw std::runtime_error("Font has wrong resource index, please initialize AppFilesystemComponent before using ResourceRegistry"); + + if (ResourceRegistry::GetResourceId() != 1) + throw std::runtime_error("Image has wrong resource index, please initialize AppFilesystemComponent before using ResourceRegistry"); + + if (ResourceRegistry::GetResourceId() != 2) + throw std::runtime_error("ImageStream has wrong resource index, please initialize AppFilesystemComponent before using ResourceRegistry"); + + if (ResourceRegistry::GetResourceId() != 3) + throw std::runtime_error("Material has wrong resource index, please initialize AppFilesystemComponent before using ResourceRegistry"); + + if (ResourceRegistry::GetResourceId() != 4) + throw std::runtime_error("MaterialInstance has wrong resource index, please initialize AppFilesystemComponent before using ResourceRegistry"); + + if (ResourceRegistry::GetResourceId() != 5) + throw std::runtime_error("Mesh has wrong resource index, please initialize AppFilesystemComponent before using ResourceRegistry"); + + if (ResourceRegistry::GetResourceId() != 6) + throw std::runtime_error("SoundBuffer has wrong resource index, please initialize AppFilesystemComponent before using ResourceRegistry"); + + if (ResourceRegistry::GetResourceId() != 7) + throw std::runtime_error("SoundStream has wrong resource index, please initialize AppFilesystemComponent before using ResourceRegistry"); + + if (ResourceRegistry::GetResourceId() != 8) + throw std::runtime_error("Texture has wrong resource index, please initialize AppFilesystemComponent before using ResourceRegistry"); + } + template std::shared_ptr AppFilesystemComponent::GetOrLoadImpl(std::string_view assetPath, const typename T::Params& params) { @@ -122,36 +154,6 @@ namespace Nz m_rootDirectory->GetEntry(assetPath, callback); return resource; } - - inline void AppFilesystemComponent::RegisterResourceTypes() - { - if (ResourceRegistry::GetResourceId() != 0) - throw std::runtime_error("Font has wrong resource index, please initialize AppFilesystemComponent before using ResourceRegistry"); - - if (ResourceRegistry::GetResourceId() != 1) - throw std::runtime_error("Image has wrong resource index, please initialize AppFilesystemComponent before using ResourceRegistry"); - - if (ResourceRegistry::GetResourceId() != 2) - throw std::runtime_error("ImageStream has wrong resource index, please initialize AppFilesystemComponent before using ResourceRegistry"); - - if (ResourceRegistry::GetResourceId() != 3) - throw std::runtime_error("Material has wrong resource index, please initialize AppFilesystemComponent before using ResourceRegistry"); - - if (ResourceRegistry::GetResourceId() != 4) - throw std::runtime_error("MaterialInstance has wrong resource index, please initialize AppFilesystemComponent before using ResourceRegistry"); - - if (ResourceRegistry::GetResourceId() != 5) - throw std::runtime_error("Mesh has wrong resource index, please initialize AppFilesystemComponent before using ResourceRegistry"); - - if (ResourceRegistry::GetResourceId() != 6) - throw std::runtime_error("SoundBuffer has wrong resource index, please initialize AppFilesystemComponent before using ResourceRegistry"); - - if (ResourceRegistry::GetResourceId() != 7) - throw std::runtime_error("SoundStream has wrong resource index, please initialize AppFilesystemComponent before using ResourceRegistry"); - - if (ResourceRegistry::GetResourceId() != 8) - throw std::runtime_error("Texture has wrong resource index, please initialize AppFilesystemComponent before using ResourceRegistry"); - } } #include diff --git a/src/Nazara/Graphics/Graphics.cpp b/src/Nazara/Graphics/Graphics.cpp index cb8938569..df5af50d5 100644 --- a/src/Nazara/Graphics/Graphics.cpp +++ b/src/Nazara/Graphics/Graphics.cpp @@ -177,6 +177,8 @@ namespace Nz void Graphics::RegisterComponent(AppFilesystemComponent& component) { + AppFilesystemComponent::RegisterResourceTypes(); + TextureParams defaultTexParams; defaultTexParams.renderDevice = m_renderDevice;