From 36d3c51eebde60e930f77f4bd04b392047341b46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Thu, 17 Sep 2020 20:10:39 +0200 Subject: [PATCH] Add module configurations --- include/Nazara/Audio/Audio.hpp | 4 +- include/Nazara/Core/Core.hpp | 4 +- include/Nazara/Core/Modules.hpp | 8 ++- include/Nazara/Core/Modules.inl | 67 +++++++++++++++++++++----- include/Nazara/Network/Network.hpp | 4 +- include/Nazara/Physics2D/Physics2D.hpp | 4 +- include/Nazara/Physics3D/Physics3D.hpp | 4 +- include/Nazara/Platform/Platform.hpp | 4 +- include/Nazara/Renderer/Renderer.hpp | 4 +- include/Nazara/Shader/Shader.hpp | 4 +- include/Nazara/Utility/Utility.hpp | 4 +- include/NazaraSDK/Sdk.hpp | 4 +- src/Nazara/Audio/Audio.cpp | 2 +- src/Nazara/Core/Core.cpp | 2 +- src/Nazara/Network/Network.cpp | 2 +- src/Nazara/Physics2D/Physics2D.cpp | 2 +- src/Nazara/Physics3D/Physics3D.cpp | 2 +- src/Nazara/Platform/Platform.cpp | 2 +- src/Nazara/Renderer/Renderer.cpp | 2 +- src/Nazara/Shader/Shader.cpp | 2 +- src/Nazara/Utility/Utility.cpp | 2 +- src/NazaraSDK/Sdk.cpp | 2 +- 22 files changed, 102 insertions(+), 33 deletions(-) diff --git a/include/Nazara/Audio/Audio.hpp b/include/Nazara/Audio/Audio.hpp index 87539a8fd..cda4110e9 100644 --- a/include/Nazara/Audio/Audio.hpp +++ b/include/Nazara/Audio/Audio.hpp @@ -23,7 +23,9 @@ namespace Nz public: using Dependencies = TypeList; - Audio(); + struct Config {}; + + Audio(Config /*config*/); ~Audio(); AudioFormat GetAudioFormat(unsigned int channelCount); diff --git a/include/Nazara/Core/Core.hpp b/include/Nazara/Core/Core.hpp index e30dad53d..10cc2eb65 100644 --- a/include/Nazara/Core/Core.hpp +++ b/include/Nazara/Core/Core.hpp @@ -20,7 +20,9 @@ namespace Nz public: using Dependencies = TypeList<>; - Core(); + struct Config {}; + + Core(Config /*config*/); ~Core(); private: diff --git a/include/Nazara/Core/Modules.hpp b/include/Nazara/Core/Modules.hpp index 6838d1836..218427a5e 100644 --- a/include/Nazara/Core/Modules.hpp +++ b/include/Nazara/Core/Modules.hpp @@ -19,11 +19,16 @@ namespace Nz template struct ModuleTuple : ModuleTuple, ModuleTuple { + template + ModuleTuple(ModuleConfig&&... configs); }; template struct ModuleTuple { + template + ModuleTuple(ModuleConfig&&... configs); + Module m; }; } @@ -32,7 +37,8 @@ namespace Nz class Modules { public: - Modules() = default; + template + Modules(ModuleConfig&&... configs); ~Modules() = default; private: diff --git a/include/Nazara/Core/Modules.inl b/include/Nazara/Core/Modules.inl index fa2645455..c262fcd50 100644 --- a/include/Nazara/Core/Modules.inl +++ b/include/Nazara/Core/Modules.inl @@ -5,22 +5,65 @@ #include #include -namespace Nz::Detail +namespace Nz { - template<> - struct BuildDepList> + namespace Detail { - using Result = TypeList<>; - }; + template + struct Pick + { + template + static auto Get(First&& first, Args&&... args) + { + if constexpr (std::is_same_v>) + return std::forward(first); + else + return Get(std::forward(args)...); + } - template - struct BuildDepList> + static auto Get() + { + return T{}; + } + }; + + template + template + ModuleTuple::ModuleTuple(ModuleConfig&&... configs) : + ModuleTuple(std::forward(configs)...), + ModuleTuple(std::forward(configs)...) + { + } + + template + template + ModuleTuple::ModuleTuple(ModuleConfig&&... configs) : + m(Pick::Get(std::forward(configs)...)) + { + } + + template<> + struct BuildDepList> + { + using Result = TypeList<>; + }; + + template + struct BuildDepList> + { + using ModuleDependencies = typename BuildDepList::Result; + using ModuleDependenciesIncModule = TypeListAppend; + using RestDependencies = typename BuildDepList>::Result; + using Result = TypeListConcat; + }; + } + + template + template + Modules::Modules(ModuleConfig&&... configs) : + m_modules(std::forward(configs)...) { - using ModuleDependencies = typename BuildDepList::Result; - using ModuleDependenciesIncModule = TypeListAppend; - using RestDependencies = typename BuildDepList>::Result; - using Result = TypeListConcat; - }; + } } #include diff --git a/include/Nazara/Network/Network.hpp b/include/Nazara/Network/Network.hpp index edaf344b5..3fe62d8cf 100644 --- a/include/Nazara/Network/Network.hpp +++ b/include/Nazara/Network/Network.hpp @@ -20,7 +20,9 @@ namespace Nz public: using Dependencies = TypeList; - Network(); + struct Config {}; + + Network(Config /*config*/); ~Network(); private: diff --git a/include/Nazara/Physics2D/Physics2D.hpp b/include/Nazara/Physics2D/Physics2D.hpp index cc8e3471d..02ee3c112 100644 --- a/include/Nazara/Physics2D/Physics2D.hpp +++ b/include/Nazara/Physics2D/Physics2D.hpp @@ -20,7 +20,9 @@ namespace Nz public: using Dependencies = TypeList; - Physics2D(); + struct Config {}; + + Physics2D(Config /*config*/); ~Physics2D() = default; private: diff --git a/include/Nazara/Physics3D/Physics3D.hpp b/include/Nazara/Physics3D/Physics3D.hpp index 9dd119a82..0a1dac109 100644 --- a/include/Nazara/Physics3D/Physics3D.hpp +++ b/include/Nazara/Physics3D/Physics3D.hpp @@ -20,7 +20,9 @@ namespace Nz public: using Dependencies = TypeList; - Physics3D(); + struct Config {}; + + Physics3D(Config /*config*/); ~Physics3D(); unsigned int GetMemoryUsed(); diff --git a/include/Nazara/Platform/Platform.hpp b/include/Nazara/Platform/Platform.hpp index 46bac08c5..cf3f47968 100644 --- a/include/Nazara/Platform/Platform.hpp +++ b/include/Nazara/Platform/Platform.hpp @@ -20,7 +20,9 @@ namespace Nz public: using Dependencies = TypeList; - Platform(); + struct Config {}; + + Platform(Config /*config*/); ~Platform(); private: diff --git a/include/Nazara/Renderer/Renderer.hpp b/include/Nazara/Renderer/Renderer.hpp index efcc089ad..363a9ae76 100644 --- a/include/Nazara/Renderer/Renderer.hpp +++ b/include/Nazara/Renderer/Renderer.hpp @@ -26,7 +26,9 @@ namespace Nz public: using Dependencies = TypeList; - Renderer(); + struct Config {}; + + Renderer(Config /*config*/); ~Renderer(); inline RendererImpl* GetRendererImpl(); diff --git a/include/Nazara/Shader/Shader.hpp b/include/Nazara/Shader/Shader.hpp index 4d465552a..c7b538bf0 100644 --- a/include/Nazara/Shader/Shader.hpp +++ b/include/Nazara/Shader/Shader.hpp @@ -20,7 +20,9 @@ namespace Nz public: using Dependencies = TypeList; - Shader(); + struct Config {}; + + Shader(Config /*config*/); ~Shader() = default; private: diff --git a/include/Nazara/Utility/Utility.hpp b/include/Nazara/Utility/Utility.hpp index a5eb94a95..9c2ebb2b4 100644 --- a/include/Nazara/Utility/Utility.hpp +++ b/include/Nazara/Utility/Utility.hpp @@ -20,7 +20,9 @@ namespace Nz public: using Dependencies = TypeList; - Utility(); + struct Config {}; + + Utility(Config /*config*/); ~Utility(); private: diff --git a/include/NazaraSDK/Sdk.hpp b/include/NazaraSDK/Sdk.hpp index d7668f3b0..4d86229d1 100644 --- a/include/NazaraSDK/Sdk.hpp +++ b/include/NazaraSDK/Sdk.hpp @@ -37,7 +37,9 @@ namespace Ndk using Dependencies = Nz::TypeListConcat; #endif - Sdk(); + struct Config {}; + + Sdk(Config /*config*/); ~Sdk(); private: diff --git a/src/Nazara/Audio/Audio.cpp b/src/Nazara/Audio/Audio.cpp index e5d0f9091..3eff5dc3a 100644 --- a/src/Nazara/Audio/Audio.cpp +++ b/src/Nazara/Audio/Audio.cpp @@ -23,7 +23,7 @@ namespace Nz * \brief Audio class that represents the module initializer of Audio */ - Audio::Audio() : + Audio::Audio(Config /*config*/) : ModuleBase("Audio", this) { // Initialisation of OpenAL diff --git a/src/Nazara/Core/Core.cpp b/src/Nazara/Core/Core.cpp index d6604c0c4..17db66a9f 100644 --- a/src/Nazara/Core/Core.cpp +++ b/src/Nazara/Core/Core.cpp @@ -19,7 +19,7 @@ namespace Nz * \brief Core class that represents the Core module */ - Core::Core() : + Core::Core(Config /*config*/) : ModuleBase("Core", this, ModuleBase::NoLog{}) { Log::Initialize(); diff --git a/src/Nazara/Network/Network.cpp b/src/Nazara/Network/Network.cpp index d555fa9d0..6d5b6b076 100644 --- a/src/Nazara/Network/Network.cpp +++ b/src/Nazara/Network/Network.cpp @@ -31,7 +31,7 @@ namespace Nz * \brief Network class that represents the module initializer of Network */ - Network::Network() : + Network::Network(Config /*config*/) : ModuleBase("Network", this) { // Initialize module here diff --git a/src/Nazara/Physics2D/Physics2D.cpp b/src/Nazara/Physics2D/Physics2D.cpp index 398c03b91..ec53aa3be 100644 --- a/src/Nazara/Physics2D/Physics2D.cpp +++ b/src/Nazara/Physics2D/Physics2D.cpp @@ -7,7 +7,7 @@ namespace Nz { - Physics2D::Physics2D() : + Physics2D::Physics2D(Config /*config*/) : ModuleBase("Physics2D", this) { } diff --git a/src/Nazara/Physics3D/Physics3D.cpp b/src/Nazara/Physics3D/Physics3D.cpp index b9e8df451..d54bb2c7c 100644 --- a/src/Nazara/Physics3D/Physics3D.cpp +++ b/src/Nazara/Physics3D/Physics3D.cpp @@ -13,7 +13,7 @@ namespace Nz { - Physics3D::Physics3D() : + Physics3D::Physics3D(Config /*config*/) : ModuleBase("Physics3D", this) { if (!Collider3D::Initialize()) diff --git a/src/Nazara/Platform/Platform.cpp b/src/Nazara/Platform/Platform.cpp index fcd9f2d61..bd24c74d9 100644 --- a/src/Nazara/Platform/Platform.cpp +++ b/src/Nazara/Platform/Platform.cpp @@ -17,7 +17,7 @@ namespace Nz * \brief Platform class that represents the module initializer of Platform */ - Platform::Platform() : + Platform::Platform(Config /*config*/) : ModuleBase("Platform", this) { if (!Window::Initialize()) diff --git a/src/Nazara/Renderer/Renderer.cpp b/src/Nazara/Renderer/Renderer.cpp index 91e3ff853..8a021234a 100644 --- a/src/Nazara/Renderer/Renderer.cpp +++ b/src/Nazara/Renderer/Renderer.cpp @@ -30,7 +30,7 @@ namespace Nz { - Renderer::Renderer() : + Renderer::Renderer(Config /*config*/) : ModuleBase("Renderer", this) { struct RendererImplementations diff --git a/src/Nazara/Shader/Shader.cpp b/src/Nazara/Shader/Shader.cpp index 76c9653aa..18d36d4ed 100644 --- a/src/Nazara/Shader/Shader.cpp +++ b/src/Nazara/Shader/Shader.cpp @@ -7,7 +7,7 @@ namespace Nz { - Shader::Shader() : + Shader::Shader(Config /*config*/) : ModuleBase("Shader", this) { } diff --git a/src/Nazara/Utility/Utility.cpp b/src/Nazara/Utility/Utility.cpp index e83778c60..f07f27fe5 100644 --- a/src/Nazara/Utility/Utility.cpp +++ b/src/Nazara/Utility/Utility.cpp @@ -36,7 +36,7 @@ namespace Nz * \brief Utility class that represents the module initializer of Utility */ - Utility::Utility() : + Utility::Utility(Config /*config*/) : ModuleBase("Utility", this) { if (!Animation::Initialize()) diff --git a/src/NazaraSDK/Sdk.cpp b/src/NazaraSDK/Sdk.cpp index 0fc94559c..5c44bf3c8 100644 --- a/src/NazaraSDK/Sdk.cpp +++ b/src/NazaraSDK/Sdk.cpp @@ -32,7 +32,7 @@ namespace Ndk * \brief NDK class that represents the software development kit, a set of tools made to ease the conception of application */ - Sdk::Sdk() : + Sdk::Sdk(Config /*config*/) : ModuleBase("SDK", this) { Nz::ErrorFlags errFlags(Nz::ErrorFlag_ThrowException, true);