Sdk/Application: Add command-line arguments handling

Former-commit-id: 9f98c2fea531e23540c213d3c1e4c85391fc9e1a [formerly b3cb8fff86ac0a754b72baf9e6278f20b407ef17] [formerly 8665dec44d98961698bdeaa63e670e2e15de7d1d [formerly d8dfeaae490b2efd430599f2b1fa02c531aa4de6]]
Former-commit-id: 51c00f9263c4c7e193bf2ca8de860e03e9d0f402 [formerly d09b90f14e62f85c0056bf4ba872d9975efde1eb]
Former-commit-id: f82b2332083d6d6099ebece01e239c99d15f3b5f
This commit is contained in:
Lynix
2016-08-28 21:47:29 +02:00
parent 8caeba0a48
commit f0787cb505
5 changed files with 132 additions and 28 deletions

View File

@@ -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, ...
*/