Allow to setup/override module configuration from commandline
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class CommandLineParameters;
|
||||
|
||||
class NAZARA_AUDIO_API Audio : public ModuleBase<Audio>
|
||||
{
|
||||
friend ModuleBase;
|
||||
@@ -45,8 +47,10 @@ namespace Nz
|
||||
Audio& operator=(const Audio&) = delete;
|
||||
Audio& operator=(Audio&&) = delete;
|
||||
|
||||
struct Config
|
||||
struct NAZARA_AUDIO_API Config
|
||||
{
|
||||
void Override(const CommandLineParameters& parameters);
|
||||
|
||||
bool allowDummyDevice = true;
|
||||
bool noAudio = false;
|
||||
};
|
||||
|
||||
@@ -25,16 +25,8 @@ namespace Nz
|
||||
if constexpr (ModuleHasRegister<Module, C>::value)
|
||||
modules.template Get<Module>().RegisterComponent(component);
|
||||
|
||||
ModuleRegisterer<TypeList<Rest...>>::Register(modules, component);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct ModuleRegisterer<TypeList<>>
|
||||
{
|
||||
template<typename T, typename C>
|
||||
static void Register(T& /*modules*/, C& /*component*/)
|
||||
{
|
||||
if constexpr (sizeof...(Rest) > 0)
|
||||
ModuleRegisterer<TypeList<Rest...>>::Register(modules, component);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -50,7 +42,7 @@ namespace Nz
|
||||
template<typename... ModuleConfig>
|
||||
Application<ModuleList...>::Application(int argc, char** argv, ModuleConfig&&... configs) :
|
||||
ApplicationBase(argc, argv),
|
||||
m_modules(std::forward<ModuleConfig>(configs)...)
|
||||
m_modules(GetCommandLineParameters(), std::forward<ModuleConfig>(configs)...)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -58,7 +50,7 @@ namespace Nz
|
||||
template<typename... ModuleConfig>
|
||||
Application<ModuleList...>::Application(int argc, const Pointer<const char>* argv, ModuleConfig&&... configs) :
|
||||
ApplicationBase(argc, argv),
|
||||
m_modules(std::forward<ModuleConfig>(configs)...)
|
||||
m_modules(GetCommandLineParameters(), std::forward<ModuleConfig>(configs)...)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,9 @@
|
||||
#include <Nazara/Core/ApplicationComponent.hpp>
|
||||
#include <Nazara/Core/ApplicationUpdater.hpp>
|
||||
#include <Nazara/Core/Clock.hpp>
|
||||
#include <Nazara/Core/CommandLineParameters.hpp>
|
||||
#include <atomic>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
@@ -36,6 +38,7 @@ namespace Nz
|
||||
|
||||
inline void ClearComponents();
|
||||
|
||||
inline const CommandLineParameters& GetCommandLineParameters() const;
|
||||
template<typename T> T& GetComponent();
|
||||
template<typename T> const T& GetComponent() const;
|
||||
|
||||
@@ -66,6 +69,7 @@ namespace Nz
|
||||
std::atomic_bool m_running;
|
||||
std::vector<std::unique_ptr<ApplicationComponent>> m_components;
|
||||
std::vector<Updater> m_updaters;
|
||||
CommandLineParameters m_commandLineParams;
|
||||
HighPrecisionClock m_clock;
|
||||
Time m_currentTime;
|
||||
|
||||
|
||||
@@ -50,6 +50,11 @@ namespace Nz
|
||||
m_components.clear();
|
||||
}
|
||||
|
||||
inline const CommandLineParameters& ApplicationBase::GetCommandLineParameters() const
|
||||
{
|
||||
return m_commandLineParams;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T& ApplicationBase::GetComponent()
|
||||
{
|
||||
|
||||
@@ -11,13 +11,15 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class CommandLineParameters;
|
||||
|
||||
namespace Detail
|
||||
{
|
||||
template<typename Module, typename... Modules>
|
||||
struct ModuleTuple : ModuleTuple<Module>, ModuleTuple<Modules...>
|
||||
{
|
||||
template<typename... ModuleConfig>
|
||||
ModuleTuple(ModuleConfig&&... configs);
|
||||
template<typename... ModuleConfig> ModuleTuple(ModuleConfig&&... configs);
|
||||
template<typename... ModuleConfig> ModuleTuple(const CommandLineParameters& parameters, ModuleConfig&&... configs);
|
||||
|
||||
template<typename T> T& Get();
|
||||
};
|
||||
@@ -25,8 +27,8 @@ namespace Nz
|
||||
template<typename Module>
|
||||
struct ModuleTuple<Module>
|
||||
{
|
||||
template<typename... ModuleConfig>
|
||||
ModuleTuple(ModuleConfig&&... configs);
|
||||
template<typename... ModuleConfig> ModuleTuple(ModuleConfig&&... configs);
|
||||
template<typename... ModuleConfig> ModuleTuple(const CommandLineParameters& parameters, ModuleConfig&&... configs);
|
||||
|
||||
template<typename T> T& Get();
|
||||
|
||||
@@ -42,8 +44,8 @@ namespace Nz
|
||||
class Modules
|
||||
{
|
||||
public:
|
||||
template<typename... ModuleConfig>
|
||||
Modules(ModuleConfig&&... configs);
|
||||
template<typename... ModuleConfig> Modules(ModuleConfig&&... configs);
|
||||
template<typename... ModuleConfig> Modules(const CommandLineParameters& parameters, ModuleConfig&&... configs);
|
||||
~Modules() = default;
|
||||
|
||||
template<typename T> T& Get();
|
||||
|
||||
@@ -9,6 +9,21 @@ namespace Nz
|
||||
{
|
||||
namespace Detail
|
||||
{
|
||||
template<typename, typename = void>
|
||||
struct ModuleConfigHasOverride : std::false_type {};
|
||||
|
||||
template<typename T>
|
||||
struct ModuleConfigHasOverride<T, std::void_t<decltype(std::declval<T>().Override(std::declval<const CommandLineParameters&>()))>> : std::true_type {};
|
||||
|
||||
template<typename T>
|
||||
auto OverrideModuleConfig(T&& module, const CommandLineParameters& params)
|
||||
{
|
||||
if constexpr (!std::is_const_v<T> && ModuleConfigHasOverride<T>::value)
|
||||
module.Override(params);
|
||||
|
||||
return std::forward<T>(module);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
struct Pick
|
||||
{
|
||||
@@ -24,10 +39,27 @@ namespace Nz
|
||||
}
|
||||
}
|
||||
|
||||
template<typename First, typename... Args>
|
||||
static auto Get(const CommandLineParameters& parameters, First&& first, Args&&... args)
|
||||
{
|
||||
if constexpr (std::is_same_v<T, std::decay_t<First>>)
|
||||
return OverrideModuleConfig<First>(first, parameters);
|
||||
else
|
||||
{
|
||||
NazaraUnused(first);
|
||||
return Get(parameters, std::forward<Args>(args)...);
|
||||
}
|
||||
}
|
||||
|
||||
static auto Get()
|
||||
{
|
||||
return T{};
|
||||
}
|
||||
|
||||
static auto Get(const CommandLineParameters& parameters)
|
||||
{
|
||||
return OverrideModuleConfig(T{}, parameters);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Module, typename... Modules>
|
||||
@@ -37,6 +69,14 @@ namespace Nz
|
||||
ModuleTuple<Modules...>(std::forward<ModuleConfig>(configs)...)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename Module, typename... Modules>
|
||||
template<typename... ModuleConfig>
|
||||
ModuleTuple<Module, Modules...>::ModuleTuple(const CommandLineParameters& parameters, ModuleConfig&&... configs) :
|
||||
ModuleTuple<Module>(parameters, std::forward<ModuleConfig>(configs)...),
|
||||
ModuleTuple<Modules...>(parameters, std::forward<ModuleConfig>(configs)...)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename Module, typename... Modules>
|
||||
template<typename T>
|
||||
@@ -55,6 +95,13 @@ namespace Nz
|
||||
m(Pick<typename Module::Config>::Get(std::forward<ModuleConfig>(configs)...))
|
||||
{
|
||||
}
|
||||
|
||||
template<typename Module>
|
||||
template<typename... ModuleConfig>
|
||||
ModuleTuple<Module>::ModuleTuple(const CommandLineParameters& parameters, ModuleConfig&&... configs) :
|
||||
m(Pick<typename Module::Config>::Get(parameters, std::forward<ModuleConfig>(configs)...))
|
||||
{
|
||||
}
|
||||
|
||||
template<typename Module>
|
||||
template<typename T>
|
||||
@@ -71,6 +118,13 @@ namespace Nz
|
||||
m_modules(std::forward<ModuleConfig>(configs)...)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename... ModuleList>
|
||||
template<typename... ModuleConfig>
|
||||
Modules<ModuleList...>::Modules(const CommandLineParameters& parameters, ModuleConfig&&... configs) :
|
||||
m_modules(parameters, std::forward<ModuleConfig>(configs)...)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename... ModuleList>
|
||||
template<typename T>
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
namespace Nz
|
||||
{
|
||||
class AppFilesystemComponent;
|
||||
class CommandLineParameters;
|
||||
class RenderBuffer;
|
||||
|
||||
class NAZARA_GRAPHICS_API Graphics : public ModuleBase<Graphics>
|
||||
@@ -59,8 +60,10 @@ namespace Nz
|
||||
|
||||
void RegisterComponent(AppFilesystemComponent& component);
|
||||
|
||||
struct Config
|
||||
struct NAZARA_GRAPHICS_API Config
|
||||
{
|
||||
void Override(const CommandLineParameters& parameters);
|
||||
|
||||
RenderDeviceFeatures forceDisableFeatures;
|
||||
bool useDedicatedRenderDevice = true;
|
||||
};
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
namespace Nz
|
||||
{
|
||||
class Buffer;
|
||||
class CommandLineParameters;
|
||||
class RendererImpl;
|
||||
|
||||
class NAZARA_RENDERER_API Renderer : public ModuleBase<Renderer>
|
||||
@@ -42,8 +43,10 @@ namespace Nz
|
||||
|
||||
const std::vector<RenderDeviceInfo>& QueryRenderDevices() const;
|
||||
|
||||
struct Config
|
||||
struct NAZARA_RENDERER_API Config
|
||||
{
|
||||
void Override(const CommandLineParameters& parameters);
|
||||
|
||||
ParameterList customParameters;
|
||||
RenderAPI preferredAPI = RenderAPI::Unknown;
|
||||
#ifdef NAZARA_DEBUG
|
||||
|
||||
Reference in New Issue
Block a user