Sdk/Application: Add command-line arguments handling
Former-commit-id: 40feef03dfa4e0537490689cc1af8f68131007c7 [formerly ea93fa9625bce277d27cb1747ee34ee884fdfc28] [formerly 721b1b3400e2e6aed984b37f61cd54986e5c0e2e [formerly 50614ac42a3d1a2564e4c38d9c7c0675e44b2fb8]] Former-commit-id: d64cc60dbd82cffc23e081f270d0e173b9e2a6a5 [formerly a9ff7af1ab1ebbd1687d120a8e8e036e6c6926b5] Former-commit-id: 45f34e16b8d6a91d407df30c36e598ff3270e50f
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/Application.hpp>
|
||||
#include <regex>
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#include <NDK/Components/CameraComponent.hpp>
|
||||
@@ -21,6 +22,54 @@ namespace Ndk
|
||||
* \brief NDK class that represents the application, it offers a set of tools to ease the development
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Constructs an Application object with command-line arguments
|
||||
*
|
||||
* Pass the argc and argv arguments from the main function.
|
||||
*
|
||||
* Command-line arguments can be retrieved by application methods
|
||||
*
|
||||
* This calls Sdk::Initialize()
|
||||
*
|
||||
* \remark Only one Application instance can exist at a time
|
||||
*/
|
||||
inline Application::Application(int argc, char* argv[]) :
|
||||
Application()
|
||||
{
|
||||
std::regex optionRegex(R"(-(\w+))");
|
||||
std::regex valueRegex(R"(-(\w+)\s*=\s*(.+))");
|
||||
|
||||
std::smatch results;
|
||||
|
||||
for (int i = 1; i < argc; ++i)
|
||||
{
|
||||
std::string argument(argv[i]);
|
||||
if (std::regex_match(argument, results, valueRegex))
|
||||
{
|
||||
Nz::String key(results[1].str());
|
||||
Nz::String value(results[2].str());
|
||||
|
||||
m_parameters[key.ToLower()] = value;
|
||||
NazaraDebug("Registred parameter from command-line: " + key.ToLower() + "=" + value);
|
||||
}
|
||||
else if (std::regex_match(argument, results, optionRegex))
|
||||
{
|
||||
Nz::String option(results[1].str());
|
||||
|
||||
m_options.insert(option);
|
||||
NazaraDebug("Registred option from command-line: " + option);
|
||||
}
|
||||
else
|
||||
NazaraWarning("Ignored command-line argument #" + Nz::String::Number(i) + " \"" + argument + '"');
|
||||
}
|
||||
|
||||
if (HasOption("console"))
|
||||
EnableConsole(true);
|
||||
|
||||
if (HasOption("fpscounter"))
|
||||
EnableFPSCounter(true);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Runs the application by updating worlds, taking care about windows, ...
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user