Sdk/Application: Add command-line arguments handling

Former-commit-id: efe6c5a1d911bb78314f8819575699874f5101e8 [formerly a9b33eea0b4b261d3e3a63d8949512f737dbe1e1] [formerly bd00d4e8009ff0efa74e6a27d78960f6d3d72c17 [formerly 17b26899d0c158c77ea0ab4cfa243e92c2145b6b]]
Former-commit-id: 4caea7e656e3718e1d462c5ed280aa6353368166 [formerly b82d884df55141a10251e84e54e0a40f84db2a5e]
Former-commit-id: 3798d603338416b18a4d427cf8b3cb87bac12ff6
This commit is contained in:
Lynix
2016-08-28 21:47:29 +02:00
parent cba0190f03
commit d9d2347688
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, ...
*/