diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-26 19:33:06 +0200 |
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-26 19:33:06 +0200 |
| commit | 8898bebd8dcb4361b35dde37bdf424d09b498d60 (patch) | |
| tree | b934672158ceda6ed42e0c7e63a5bc57318213a4 /editor | |
| parent | eb5097b993286ffe44214ad493db75e1749c8ec9 (diff) | |
simplify argv handling
Diffstat (limited to 'editor')
| -rw-r--r-- | editor/app.cpp | 53 | ||||
| -rw-r--r-- | editor/draw.cpp | 7 |
2 files changed, 17 insertions, 43 deletions
diff --git a/editor/app.cpp b/editor/app.cpp index 9ee59844..5920c6fb 100644 --- a/editor/app.cpp +++ b/editor/app.cpp @@ -30,36 +30,23 @@ 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 true_values[] = { "1", "true", "yes", "y", "Y", "on", "ON", "enable", "enabled", }; +static const char* const false_values[] = { "0", "false", "no", "n", "N", "off", "OFF", "disable", "disabled", }; 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); + 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) +static bool parse_bool(StringView name, const Corrade::Utility::Arguments& args, bool def) { + StringView str = args.value<StringView>(name); 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()); + fm_warn("invalid '--%s' argument '%s': should be true or false", name.data(), str.data()); return def; } @@ -68,25 +55,19 @@ int app::run_from_argv(const int argc, const char* const* const argv) fm_settings opts; Corrade::Utility::Arguments args{}; args.addOption("vsync", "m") - .addOption("gpu-validation", "m") + .addOption("gpu-debug", "m") .addOption("msaa", "1") .parse(argc, argv); - opts.vsync = parse_tristate("--vsync", args.value<StringView>("vsync"), opts.vsync); - opts.msaa = parse_bool("--msaa", args.value<StringView>("msaa"), opts.msaa); - { - auto str = args.value<StringView>("gpu-validation"); - if (str == "no-error" || str == "NO-ERROR") - opts.gpu_debug = fm_gpu_debug::no_error; - else if (str == "robust" || str == "ROBUST") - opts.gpu_debug = fm_gpu_debug::robust; - else switch (parse_tristate("--gpu-validation", args.value<StringView>("gpu-validation"), fm_tristate::maybe)) - { - default: - case fm_tristate::on: opts.gpu_debug = fm_gpu_debug::on; break; - case fm_tristate::off: opts.gpu_debug = fm_gpu_debug::off; break; - } - } - opts.vsync = parse_tristate("--vsync", args.value<StringView>("vsync"), opts.vsync); + opts.vsync = parse_bool("vsync", args, opts.vsync); + opts.msaa = parse_bool("msaa", args, opts.msaa); + if (auto str = args.value<StringView>("gpu-validation"); str == "no-error" || str == "NO-ERROR") + opts.gpu_debug = fm_gpu_debug::no_error; + else if (str == "robust" || str == "ROBUST") + opts.gpu_debug = fm_gpu_debug::robust; + else + opts.gpu_debug = parse_bool("gpu-validation", args, opts.gpu_debug > fm_gpu_debug::off) + ? fm_gpu_debug::on + : fm_gpu_debug::off; int ret; Pointer<floormat_main> ptr; diff --git a/editor/draw.cpp b/editor/draw.cpp index c0ee7d1a..0c356268 100644 --- a/editor/draw.cpp +++ b/editor/draw.cpp @@ -12,7 +12,6 @@ void app::draw_wireframe_quad(global_coords pos) const auto pt = pos.to_signed(); auto& shader = M->shader(); - //if (const auto& [c, tile] = _world[pos]; tile.ground_image) { const Vector3 center{pt[0]*TILE_SIZE[0], pt[1]*TILE_SIZE[1], 0}; shader.set_tint({1, 0, 0, 1}); @@ -46,13 +45,7 @@ void app::draw_msaa() void app::draw() { - const bool debug = M->settings().gpu_debug >= fm_gpu_debug::on; - if (debug) - GL::DebugOutput::setEnabled(GL::DebugOutput::Source::Api, GL::DebugOutput::Type::Other, {131185}, false); // nvidia krap render_menu(); - if (debug) - GL::DebugOutput::setEnabled(GL::DebugOutput::Source::Api, GL::DebugOutput::Type::Other, {131185}, true); // nvidia krap } } // namespace floormat - |
