diff options
Diffstat (limited to 'main')
-rw-r--r-- | main/app.cpp | 37 | ||||
-rw-r--r-- | main/app.hpp | 22 | ||||
-rw-r--r-- | main/debug.cpp | 7 | ||||
-rw-r--r-- | main/draw.cpp | 14 | ||||
-rw-r--r-- | main/imgui.cpp | 16 |
5 files changed, 73 insertions, 23 deletions
diff --git a/main/app.cpp b/main/app.cpp index 84831978..c6e561c3 100644 --- a/main/app.cpp +++ b/main/app.cpp @@ -1,6 +1,9 @@ #include <cstddef> +#include "compat/sysexits.hpp" #include "app.hpp" #include "compat/fpu.hpp" +#include <Corrade/Utility/Arguments.h> +#include <Corrade/Utility/DebugStl.h> #include <Magnum/GL/DefaultFramebuffer.h> #include <Magnum/ImGuiIntegration/Context.h> #include <Magnum/ImGuiIntegration/Context.hpp> @@ -9,7 +12,25 @@ namespace floormat { -app::app(const Arguments& arguments): +int app::run_from_argv(int argc, char** argv) +{ + Corrade::Utility::Arguments args{}; + app_settings opts; + args.addSkippedPrefix("magnum") + .addOption("vsync", opts.vsync ? "1" : "0") + .parse(argc, argv); + opts.vsync = args.value<bool>("vsync"); + app x{{argc, argv}, std::move(opts)}; // NOLINT(performance-move-const-arg) + return x.exec(); +} + +void app::usage(const Utility::Arguments& args) +{ + Error{Error::Flag::NoNewlineAtTheEnd} << args.usage(); + std::exit(EX_USAGE); // NOLINT(concurrency-mt-unsafe) +} + +app::app(const Arguments& arguments, app_settings opts): Platform::Application{ arguments, Configuration{} @@ -21,8 +42,13 @@ app::app(const Arguments& arguments): .setFlags(GLConfiguration::Flag::GpuValidation) } { - if (!setSwapInterval(-1)) - (void)setSwapInterval(1); + if (opts.vsync) + { + if (!setSwapInterval(-1)) + (void)setSwapInterval(1); + } + else + setSwapInterval(0); set_fp_mask(); reset_camera_offset(); update_window_scale(windowSize()); @@ -152,7 +178,10 @@ void app::event_mouse_enter() } // namespace floormat -MAGNUM_APPLICATION_MAIN(floormat::app) +int main(int argc, char** argv) +{ + return floormat::app::run_from_argv(argc, argv); +} #ifdef _MSC_VER #include <cstdlib> // for __arg{c,v} diff --git a/main/app.hpp b/main/app.hpp index 7417962e..bf8ea7d0 100644 --- a/main/app.hpp +++ b/main/app.hpp @@ -19,14 +19,20 @@ namespace floormat { -struct app final : Platform::Application +struct app final : private Platform::Application { + static int run_from_argv(int argc, char** argv); + virtual ~app(); + +private: + struct app_settings; + + [[maybe_unused]] static void usage(const Utility::Arguments& args); + explicit app(const Arguments& arguments, app_settings opts); + using dpi_policy = Platform::Implementation::Sdl2DpiScalingPolicy; using tile_atlas_ = std::shared_ptr<tile_atlas>; - explicit app(const Arguments& arguments); - virtual ~app(); - void update(float dt); void do_key(KeyEvent::Key k, KeyEvent::Modifiers m, bool pressed, bool repeated); @@ -68,6 +74,8 @@ struct app final : Platform::Application void debug_callback(GL::DebugOutput::Source src, GL::DebugOutput::Type type, UnsignedInt id, GL::DebugOutput::Severity severity, const std::string& str) const; + static void _debug_callback(GL::DebugOutput::Source src, GL::DebugOutput::Type type, UnsignedInt id, + GL::DebugOutput::Severity severity, const std::string& str, const void* self); void* register_debug_callback(); global_coords pixel_to_tile(Vector2d position) const; @@ -102,6 +110,12 @@ struct app final : Platform::Application float _frame_time = 0; bool _cursor_in_imgui = false; + struct app_settings { + bool vsync = true; + }; + + app_settings _settings; + static constexpr std::int16_t BASE_X = 0, BASE_Y = 0; }; diff --git a/main/debug.cpp b/main/debug.cpp index 24deb775..e8d48d3e 100644 --- a/main/debug.cpp +++ b/main/debug.cpp @@ -18,6 +18,9 @@ void app::debug_callback(GL::DebugOutput::Source src, GL::DebugOutput::Type type static thread_local auto clock = std::chrono::steady_clock{}; static const auto t0 = clock.now(); + if (id == 131185 && severity == GL::DebugOutput::Severity::Notification) + return; + #if 0 [[maybe_unused]] volatile auto _type = type; [[maybe_unused]] volatile auto _id = id; @@ -58,8 +61,8 @@ void app::debug_callback(GL::DebugOutput::Source src, GL::DebugOutput::Type type std::fputs("", stdout); // put breakpoint here } -static void _debug_callback(GL::DebugOutput::Source src, GL::DebugOutput::Type type, UnsignedInt id, - GL::DebugOutput::Severity severity, const std::string& str, const void* self) +void app::_debug_callback(GL::DebugOutput::Source src, GL::DebugOutput::Type type, UnsignedInt id, + GL::DebugOutput::Severity severity, const std::string& str, const void* self) { static_cast<const app*>(self)->debug_callback(src, type, id, severity, str); } diff --git a/main/draw.cpp b/main/draw.cpp index b68c0b2b..4077da16 100644 --- a/main/draw.cpp +++ b/main/draw.cpp @@ -53,17 +53,19 @@ void app::draw_world() for (std::int16_t y = miny; y <= maxy; y++) for (std::int16_t x = minx; x <= maxx; x++) { - if (!_world.contains(chunk_coords{x, y})) - make_test_chunk(*_world[chunk_coords{x, y}]); - const with_shifted_camera_offset o{_shader, x, y}; - _floor_mesh.draw(_shader, *_world[chunk_coords{x, y}]); + const chunk_coords c{x, y}; + if (!_world.contains(c)) + make_test_chunk(*_world[c]); + const with_shifted_camera_offset o{_shader, c}; + _floor_mesh.draw(_shader, *_world[c]); } for (std::int16_t y = miny; y <= maxy; y++) for (std::int16_t x = minx; x <= maxx; x++) { - const with_shifted_camera_offset o{_shader, x, y}; - _wall_mesh.draw(_shader, *_world[chunk_coords{x, y}]); + const chunk_coords c{x, y}; + const with_shifted_camera_offset o{_shader, c}; + _wall_mesh.draw(_shader, *_world[c]); } #endif } diff --git a/main/imgui.cpp b/main/imgui.cpp index 8d2cb97e..13a09a8b 100644 --- a/main/imgui.cpp +++ b/main/imgui.cpp @@ -146,23 +146,25 @@ void app::draw_editor_pane(tile_type& type, float main_menu_height) void app::draw_fps() { - const ImVec2 max_size = ImGui::CalcTextSize("999.1 FPS"); auto c1 = push_style_var(ImGuiStyleVar_FramePadding, {0, 0}); auto c2 = push_style_var(ImGuiStyleVar_WindowPadding, {0, 0}); auto c3 = push_style_var(ImGuiStyleVar_WindowBorderSize, 0); auto c4 = push_style_var(ImGuiStyleVar_WindowMinSize, {1, 1}); auto c5 = push_style_var(ImGuiStyleVar_ScrollbarSize, 0); auto c6 = push_style_color(ImGuiCol_Text, {0, 1, 0, 1}); - ImGui::SetNextWindowPos({windowSize()[0] - 5 - max_size.x, 3}); - ImGui::SetNextWindowSize(max_size); + + char buf[16]; + const double dt = _frame_time > 1e-6 ? std::round(1/double(_frame_time)*10.)*.1 + 0.05 : 999; + snprintf(buf, sizeof(buf), "%.1f FPS", dt); + const ImVec2 size = ImGui::CalcTextSize(buf); + + ImGui::SetNextWindowPos({windowSize()[0] - size.x - 4, 3}); + ImGui::SetNextWindowSize(size); + if (auto flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBackground; auto b = begin_window("framerate", ImGuiWindowFlags_(flags))) { - const double dt = _frame_time > 1e-6 ? std::round(1/double(_frame_time)*10.)*.1 + 0.05 : 999; - char buf[16]; - snprintf(buf, sizeof(buf), "%.1f FPS", dt); - ImGui::SameLine(max_size.x - ImGui::CalcTextSize(buf).x); ImGui::Text("%s", buf); } } |