Add module configurations

This commit is contained in:
Jérôme Leclercq 2020-09-17 20:10:39 +02:00
parent 7a7a67cd40
commit 36d3c51eeb
22 changed files with 102 additions and 33 deletions

View File

@ -23,7 +23,9 @@ namespace Nz
public: public:
using Dependencies = TypeList<Core>; using Dependencies = TypeList<Core>;
Audio(); struct Config {};
Audio(Config /*config*/);
~Audio(); ~Audio();
AudioFormat GetAudioFormat(unsigned int channelCount); AudioFormat GetAudioFormat(unsigned int channelCount);

View File

@ -20,7 +20,9 @@ namespace Nz
public: public:
using Dependencies = TypeList<>; using Dependencies = TypeList<>;
Core(); struct Config {};
Core(Config /*config*/);
~Core(); ~Core();
private: private:

View File

@ -19,11 +19,16 @@ namespace Nz
template<typename Module, typename... Modules> template<typename Module, typename... Modules>
struct ModuleTuple : ModuleTuple<Module>, ModuleTuple<Modules...> struct ModuleTuple : ModuleTuple<Module>, ModuleTuple<Modules...>
{ {
template<typename... ModuleConfig>
ModuleTuple(ModuleConfig&&... configs);
}; };
template<typename Module> template<typename Module>
struct ModuleTuple<Module> struct ModuleTuple<Module>
{ {
template<typename... ModuleConfig>
ModuleTuple(ModuleConfig&&... configs);
Module m; Module m;
}; };
} }
@ -32,7 +37,8 @@ namespace Nz
class Modules class Modules
{ {
public: public:
Modules() = default; template<typename... ModuleConfig>
Modules(ModuleConfig&&... configs);
~Modules() = default; ~Modules() = default;
private: private:

View File

@ -5,22 +5,65 @@
#include <Nazara/Core/Modules.hpp> #include <Nazara/Core/Modules.hpp>
#include <Nazara/Core/Debug.hpp> #include <Nazara/Core/Debug.hpp>
namespace Nz::Detail namespace Nz
{ {
template<> namespace Detail
struct BuildDepList<TypeList<>>
{ {
using Result = TypeList<>; template<typename T>
}; struct Pick
{
template<typename First, typename... Args>
static auto Get(First&& first, Args&&... args)
{
if constexpr (std::is_same_v<T, std::decay_t<First>>)
return std::forward<First>(first);
else
return Get(std::forward<Args>(args)...);
}
template<typename Module, typename... ModuleList> static auto Get()
struct BuildDepList<TypeList<Module, ModuleList...>> {
return T{};
}
};
template<typename Module, typename... Modules>
template<typename... ModuleConfig>
ModuleTuple<Module, Modules...>::ModuleTuple(ModuleConfig&&... configs) :
ModuleTuple<Module>(std::forward<ModuleConfig>(configs)...),
ModuleTuple<Modules...>(std::forward<ModuleConfig>(configs)...)
{
}
template<typename Module>
template<typename... ModuleConfig>
ModuleTuple<Module>::ModuleTuple(ModuleConfig&&... configs) :
m(Pick<Module::Config>::Get(std::forward<ModuleConfig>(configs)...))
{
}
template<>
struct BuildDepList<TypeList<>>
{
using Result = TypeList<>;
};
template<typename Module, typename... ModuleList>
struct BuildDepList<TypeList<Module, ModuleList...>>
{
using ModuleDependencies = typename BuildDepList<typename Module::Dependencies>::Result;
using ModuleDependenciesIncModule = TypeListAppend<ModuleDependencies, Module>;
using RestDependencies = typename BuildDepList<TypeList<ModuleList...>>::Result;
using Result = TypeListConcat<ModuleDependenciesIncModule, RestDependencies>;
};
}
template<typename... ModuleList>
template<typename... ModuleConfig>
Modules<ModuleList...>::Modules(ModuleConfig&&... configs) :
m_modules(std::forward<ModuleConfig>(configs)...)
{ {
using ModuleDependencies = typename BuildDepList<typename Module::Dependencies>::Result; }
using ModuleDependenciesIncModule = TypeListAppend<ModuleDependencies, Module>;
using RestDependencies = typename BuildDepList<TypeList<ModuleList...>>::Result;
using Result = TypeListConcat<ModuleDependenciesIncModule, RestDependencies>;
};
} }
#include <Nazara/Core/DebugOff.hpp> #include <Nazara/Core/DebugOff.hpp>

View File

@ -20,7 +20,9 @@ namespace Nz
public: public:
using Dependencies = TypeList<Core>; using Dependencies = TypeList<Core>;
Network(); struct Config {};
Network(Config /*config*/);
~Network(); ~Network();
private: private:

View File

@ -20,7 +20,9 @@ namespace Nz
public: public:
using Dependencies = TypeList<Core>; using Dependencies = TypeList<Core>;
Physics2D(); struct Config {};
Physics2D(Config /*config*/);
~Physics2D() = default; ~Physics2D() = default;
private: private:

View File

@ -20,7 +20,9 @@ namespace Nz
public: public:
using Dependencies = TypeList<Core>; using Dependencies = TypeList<Core>;
Physics3D(); struct Config {};
Physics3D(Config /*config*/);
~Physics3D(); ~Physics3D();
unsigned int GetMemoryUsed(); unsigned int GetMemoryUsed();

View File

@ -20,7 +20,9 @@ namespace Nz
public: public:
using Dependencies = TypeList<Utility>; using Dependencies = TypeList<Utility>;
Platform(); struct Config {};
Platform(Config /*config*/);
~Platform(); ~Platform();
private: private:

View File

@ -26,7 +26,9 @@ namespace Nz
public: public:
using Dependencies = TypeList<Platform, Shader>; using Dependencies = TypeList<Platform, Shader>;
Renderer(); struct Config {};
Renderer(Config /*config*/);
~Renderer(); ~Renderer();
inline RendererImpl* GetRendererImpl(); inline RendererImpl* GetRendererImpl();

View File

@ -20,7 +20,9 @@ namespace Nz
public: public:
using Dependencies = TypeList<Core>; using Dependencies = TypeList<Core>;
Shader(); struct Config {};
Shader(Config /*config*/);
~Shader() = default; ~Shader() = default;
private: private:

View File

@ -20,7 +20,9 @@ namespace Nz
public: public:
using Dependencies = TypeList<Core>; using Dependencies = TypeList<Core>;
Utility(); struct Config {};
Utility(Config /*config*/);
~Utility(); ~Utility();
private: private:

View File

@ -37,7 +37,9 @@ namespace Ndk
using Dependencies = Nz::TypeListConcat<CommonDependencies, ClientDependencies>; using Dependencies = Nz::TypeListConcat<CommonDependencies, ClientDependencies>;
#endif #endif
Sdk(); struct Config {};
Sdk(Config /*config*/);
~Sdk(); ~Sdk();
private: private:

View File

@ -23,7 +23,7 @@ namespace Nz
* \brief Audio class that represents the module initializer of Audio * \brief Audio class that represents the module initializer of Audio
*/ */
Audio::Audio() : Audio::Audio(Config /*config*/) :
ModuleBase("Audio", this) ModuleBase("Audio", this)
{ {
// Initialisation of OpenAL // Initialisation of OpenAL

View File

@ -19,7 +19,7 @@ namespace Nz
* \brief Core class that represents the Core module * \brief Core class that represents the Core module
*/ */
Core::Core() : Core::Core(Config /*config*/) :
ModuleBase("Core", this, ModuleBase::NoLog{}) ModuleBase("Core", this, ModuleBase::NoLog{})
{ {
Log::Initialize(); Log::Initialize();

View File

@ -31,7 +31,7 @@ namespace Nz
* \brief Network class that represents the module initializer of Network * \brief Network class that represents the module initializer of Network
*/ */
Network::Network() : Network::Network(Config /*config*/) :
ModuleBase("Network", this) ModuleBase("Network", this)
{ {
// Initialize module here // Initialize module here

View File

@ -7,7 +7,7 @@
namespace Nz namespace Nz
{ {
Physics2D::Physics2D() : Physics2D::Physics2D(Config /*config*/) :
ModuleBase("Physics2D", this) ModuleBase("Physics2D", this)
{ {
} }

View File

@ -13,7 +13,7 @@
namespace Nz namespace Nz
{ {
Physics3D::Physics3D() : Physics3D::Physics3D(Config /*config*/) :
ModuleBase("Physics3D", this) ModuleBase("Physics3D", this)
{ {
if (!Collider3D::Initialize()) if (!Collider3D::Initialize())

View File

@ -17,7 +17,7 @@ namespace Nz
* \brief Platform class that represents the module initializer of Platform * \brief Platform class that represents the module initializer of Platform
*/ */
Platform::Platform() : Platform::Platform(Config /*config*/) :
ModuleBase("Platform", this) ModuleBase("Platform", this)
{ {
if (!Window::Initialize()) if (!Window::Initialize())

View File

@ -30,7 +30,7 @@
namespace Nz namespace Nz
{ {
Renderer::Renderer() : Renderer::Renderer(Config /*config*/) :
ModuleBase("Renderer", this) ModuleBase("Renderer", this)
{ {
struct RendererImplementations struct RendererImplementations

View File

@ -7,7 +7,7 @@
namespace Nz namespace Nz
{ {
Shader::Shader() : Shader::Shader(Config /*config*/) :
ModuleBase("Shader", this) ModuleBase("Shader", this)
{ {
} }

View File

@ -36,7 +36,7 @@ namespace Nz
* \brief Utility class that represents the module initializer of Utility * \brief Utility class that represents the module initializer of Utility
*/ */
Utility::Utility() : Utility::Utility(Config /*config*/) :
ModuleBase("Utility", this) ModuleBase("Utility", this)
{ {
if (!Animation::Initialize()) if (!Animation::Initialize())

View File

@ -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 * \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) ModuleBase("SDK", this)
{ {
Nz::ErrorFlags errFlags(Nz::ErrorFlag_ThrowException, true); Nz::ErrorFlags errFlags(Nz::ErrorFlag_ThrowException, true);