diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-24 09:32:13 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-24 09:32:13 +0200 |
commit | cecd124c0c043ef261256fb9e3f1108cde1265c1 (patch) | |
tree | 7fcba9f0904efa254d260feb1fc4eef444dd5339 /editor/app.cpp | |
parent | 203701d221b5f982abf44379ce738f76e0db027a (diff) |
a
Diffstat (limited to 'editor/app.cpp')
-rw-r--r-- | editor/app.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/editor/app.cpp b/editor/app.cpp index 324471cd..d6884edb 100644 --- a/editor/app.cpp +++ b/editor/app.cpp @@ -1,6 +1,9 @@ #include "app.hpp" +#include "compat/assert.hpp" #include "main/floormat-main.hpp" +#include "main/floormat.hpp" #include "src/loader.hpp" +#include <Corrade/Utility/Arguments.h> namespace floormat { @@ -19,4 +22,56 @@ app::~app() loader_::destroy(); } +int app::exec() +{ + return M->exec(); +} + +static const char* const true_values[] = { "1", "true", "yes", "y", "Y", "on", "ON", }; +static const char* const false_values[] = { "0", "false", "no", "n", "N", "off", "OFF", }; +static const char* const maybe_values[] = { "maybe", "m", "M", "default", }; + +template<typename T, typename U> +static inline bool find_arg(const T& list, const U& value) { + return std::find_if(std::cbegin(list), std::cend(list), + [&](const auto& x) { return x == value; }) != std::cend(list); +} + +static fm_tristate parse_tristate(StringView name, StringView str, fm_tristate def) +{ + if (find_arg(true_values, str)) + return fm_tristate::on; + else if (find_arg(false_values, str)) + return fm_tristate::off; + else if (find_arg(maybe_values, str)) + return fm_tristate::maybe; + + fm_warn("invalid '%s' argument '%s': should be true, false or default", name.data(), str.data()); + return def; +} + +static bool parse_bool(StringView name, StringView str, bool def) +{ + if (find_arg(true_values, str)) + return true; + else if (find_arg(false_values, str)) + return false; + fm_warn("invalid '%s' argument '%s': should be true or false", name.data(), str.data()); + return def; +} + +int app::run_from_argv(const int argc, const char* const* const argv) +{ + fm_options opts; + { + Corrade::Utility::Arguments args{}; + args.addOption("vsync", "default") + .addOption("gpu-validation", "true") + .parse(argc, argv); + opts.vsync = parse_tristate("--vsync", args.value<StringView>("vsync"), opts.vsync); + } + app application; + return application.exec(); +} + } // namespace floormat |