Allow to setup/override module configuration from commandline
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
#include <Nazara/Audio/Formats/libflacLoader.hpp>
|
||||
#include <Nazara/Audio/Formats/libvorbisLoader.hpp>
|
||||
#include <Nazara/Audio/Formats/minimp3Loader.hpp>
|
||||
#include <Nazara/Core/CommandLineParameters.hpp>
|
||||
#include <Nazara/Core/Core.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/Log.hpp>
|
||||
@@ -155,4 +156,10 @@ namespace Nz
|
||||
}
|
||||
|
||||
Audio* Audio::s_instance = nullptr;
|
||||
|
||||
void Audio::Config::Override(const CommandLineParameters& parameters)
|
||||
{
|
||||
if (parameters.HasFlag("no-audio"))
|
||||
noAudio = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace Nz
|
||||
{
|
||||
ApplicationBase::ApplicationBase(int argc, const Pointer<const char>* argv) :
|
||||
m_running(true),
|
||||
m_commandLineParams(CommandLineParameters::Parse(argc, argv)),
|
||||
m_currentTime(Time::Zero())
|
||||
{
|
||||
NazaraAssert(s_instance == nullptr, "only one instance of ApplicationBase can exist at a given time");
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <Nazara/Graphics/Graphics.hpp>
|
||||
#include <Nazara/Core/AppFilesystemComponent.hpp>
|
||||
#include <Nazara/Core/CommandLineParameters.hpp>
|
||||
#include <Nazara/Graphics/GuillotineTextureAtlas.hpp>
|
||||
#include <Nazara/Graphics/MaterialInstance.hpp>
|
||||
#include <Nazara/Graphics/MaterialPipeline.hpp>
|
||||
@@ -451,4 +452,13 @@ namespace Nz
|
||||
}
|
||||
|
||||
Graphics* Graphics::s_instance = nullptr;
|
||||
|
||||
void Graphics::Config::Override(const CommandLineParameters& parameters)
|
||||
{
|
||||
if (parameters.HasFlag("use-dedicated-gpu"))
|
||||
useDedicatedRenderDevice = true;
|
||||
|
||||
if (parameters.HasFlag("use-integrated-gpu"))
|
||||
useDedicatedRenderDevice = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Core/CommandLineParameters.hpp>
|
||||
#include <Nazara/Core/DynLib.hpp>
|
||||
#include <Nazara/Core/Log.hpp>
|
||||
#include <Nazara/Core/StringExt.hpp>
|
||||
@@ -14,6 +15,8 @@
|
||||
#include <Nazara/Utility/Utility.hpp>
|
||||
#include <NazaraUtils/CallOnExit.hpp>
|
||||
#include <NazaraUtils/EnumArray.hpp>
|
||||
#include <frozen/string.h>
|
||||
#include <frozen/unordered_map.h>
|
||||
#include <filesystem>
|
||||
#include <stdexcept>
|
||||
|
||||
@@ -211,4 +214,44 @@ namespace Nz
|
||||
}
|
||||
|
||||
Renderer* Renderer::s_instance = nullptr;
|
||||
|
||||
|
||||
void Renderer::Config::Override(const CommandLineParameters& parameters)
|
||||
{
|
||||
std::string_view value;
|
||||
|
||||
if (parameters.GetParameter("render-api", &value))
|
||||
{
|
||||
constexpr auto renderAPIStr = frozen::make_unordered_map<frozen::string, RenderAPI>({
|
||||
{ "auto", RenderAPI::Unknown },
|
||||
{ "direct3d", RenderAPI::Direct3D },
|
||||
{ "mantle", RenderAPI::Mantle },
|
||||
{ "metal", RenderAPI::Metal },
|
||||
{ "opengl", RenderAPI::OpenGL },
|
||||
{ "opengles", RenderAPI::OpenGL_ES },
|
||||
{ "vulkan", RenderAPI::Vulkan }
|
||||
});
|
||||
|
||||
if (auto it = renderAPIStr.find(value); it != renderAPIStr.end())
|
||||
preferredAPI = it->second;
|
||||
else
|
||||
NazaraError("unknown render API \"" + std::string(value) + "\"");
|
||||
}
|
||||
|
||||
if (parameters.GetParameter("render-api-validation", &value))
|
||||
{
|
||||
constexpr auto validationStr = frozen::make_unordered_map<frozen::string, RenderAPIValidationLevel>({
|
||||
{ "debug", RenderAPIValidationLevel::Debug },
|
||||
{ "errors", RenderAPIValidationLevel::Errors },
|
||||
{ "none", RenderAPIValidationLevel::None },
|
||||
{ "verbose", RenderAPIValidationLevel::Verbose },
|
||||
{ "warnings", RenderAPIValidationLevel::Warnings }
|
||||
});
|
||||
|
||||
if (auto it = validationStr.find(value); it != validationStr.end())
|
||||
validationLevel = it->second;
|
||||
else
|
||||
NazaraError("unknown validation level \"" + std::string(value) + "\"");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user