diff options
Diffstat (limited to 'editor')
| -rw-r--r-- | editor/app.cpp | 55 | ||||
| -rw-r--r-- | editor/app.hpp | 7 | ||||
| -rw-r--r-- | editor/update.cpp | 5 |
3 files changed, 64 insertions, 3 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 diff --git a/editor/app.hpp b/editor/app.hpp index f3c95d6f..ff5326ac 100644 --- a/editor/app.hpp +++ b/editor/app.hpp @@ -36,6 +36,7 @@ struct app final : floormat_app fm_DECLARE_DEPRECATED_MOVE_ASSIGNMENT(app); void update(float dt) override; + void maybe_init_chunk(const chunk_coords& pos, chunk& c) override; void draw_msaa() override; void draw() override; @@ -52,6 +53,10 @@ struct app final : floormat_app void on_mouse_leave() noexcept override; void on_mouse_enter() noexcept override; + int exec(); + + static int run_from_argv(int argv, const char* const* argc); + private: using tile_atlas_ = std::shared_ptr<tile_atlas>; @@ -68,7 +73,7 @@ private: void do_mouse_release(int button); void do_mouse_move(global_coords pos); - void do_camera(double dt); + void do_camera(float dt); void reset_camera_offset(); void recalc_cursor_tile(); void init_imgui(Vector2i size); diff --git a/editor/update.cpp b/editor/update.cpp index affcff57..d93c34e2 100644 --- a/editor/update.cpp +++ b/editor/update.cpp @@ -3,6 +3,7 @@ #include "src/tile-atlas.hpp" #include "main/floormat-events.hpp" #include "main/floormat-main.hpp" +#include <Magnum/Platform/Sdl2Application.h> namespace floormat { @@ -52,8 +53,8 @@ void app::update(float dt) { do_camera(dt); draw_ui(); - if (keys[key::quit]) - Platform::Sdl2Application::exit(0); + if (_keys[key::quit]) + M->quit(0); } } // namespace floormat |
