From 27a04888cfeca3d3db127744dde60b67fe497b94 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 24 Oct 2022 16:47:38 +0200 Subject: a --- editor/app.hpp | 2 +- editor/camera.cpp | 10 +++++----- editor/events.cpp | 8 ++++---- editor/precomp.hpp | 2 ++ editor/update.cpp | 2 +- main/floormat-events.cpp | 3 +++ main/floormat-main-impl.cpp | 36 ++++++++++++++++++++++++++++++------ main/floormat.hpp | 2 +- 8 files changed, 47 insertions(+), 18 deletions(-) diff --git a/editor/app.hpp b/editor/app.hpp index b43d0e12..b2fcf480 100644 --- a/editor/app.hpp +++ b/editor/app.hpp @@ -94,7 +94,7 @@ private: wireframe_mesh _wireframe_quad; wireframe_mesh _wireframe_box; editor _editor; - enum_bitset _keys; + enum_bitset keys; cursor_state cursor; }; diff --git a/editor/camera.cpp b/editor/camera.cpp index 07dba901..7e9d4870 100644 --- a/editor/camera.cpp +++ b/editor/camera.cpp @@ -8,19 +8,19 @@ namespace floormat { void app::do_camera(float dt) { - if (_keys[key::camera_reset]) + if (keys[key::camera_reset]) reset_camera_offset(); else { Vector2d dir{}; - if (_keys[key::camera_up]) + if (keys[key::camera_up]) dir += Vector2d{0, -1}; - else if (_keys[key::camera_down]) + else if (keys[key::camera_down]) dir += Vector2d{0, 1}; - if (_keys[key::camera_left]) + if (keys[key::camera_left]) dir += Vector2d{-1, 0}; - else if (_keys[key::camera_right]) + else if (keys[key::camera_right]) dir += Vector2d{1, 0}; if (dir != Vector2d{}) diff --git a/editor/events.cpp b/editor/events.cpp index 1df7163b..cfa0b904 100644 --- a/editor/events.cpp +++ b/editor/events.cpp @@ -101,10 +101,10 @@ void app::on_key_up_down(const floormat::key_event& event, bool is_down) noexcep case SDLK_ESCAPE: return key::quit; }); if (x != key::COUNT) - _keys[x] = is_down; + keys[x] = is_down; } else - _keys = {}; + keys = {}; } void app::on_text_input_event(const floormat::text_input_event& event) noexcept @@ -113,7 +113,7 @@ void app::on_text_input_event(const floormat::text_input_event& event) noexcept accessor(Containers::StringView, text) } e = {event.text}; if (_imgui.handleTextInputEvent(e)) - _keys = {}; + keys = {}; } void app::on_viewport_event(const Math::Vector2& size) noexcept @@ -125,7 +125,7 @@ void app::on_focus_out() noexcept { cursor.pixel = std::nullopt; recalc_cursor_tile(); - _keys = {}; + keys = {}; } void app::on_mouse_leave() noexcept diff --git a/editor/precomp.hpp b/editor/precomp.hpp index e023f45d..fcc422b6 100644 --- a/editor/precomp.hpp +++ b/editor/precomp.hpp @@ -17,3 +17,5 @@ #include #include #include + +#include diff --git a/editor/update.cpp b/editor/update.cpp index 0f723648..bed45c94 100644 --- a/editor/update.cpp +++ b/editor/update.cpp @@ -53,7 +53,7 @@ void app::update(float dt) { do_camera(dt); draw_ui(); - if (_keys[key::quit]) + if (keys[key::quit]) M->quit(0); } diff --git a/main/floormat-events.cpp b/main/floormat-events.cpp index adc1c575..0ef380fb 100644 --- a/main/floormat-events.cpp +++ b/main/floormat-events.cpp @@ -89,6 +89,9 @@ void main_impl::anyEvent(SDL_Event& event) default: return app.on_any_event({event}); } + else + return app.on_any_event({event}); } + } // namespace floormat diff --git a/main/floormat-main-impl.cpp b/main/floormat-main-impl.cpp index e24ef421..0dfd3e01 100644 --- a/main/floormat-main-impl.cpp +++ b/main/floormat-main-impl.cpp @@ -58,11 +58,11 @@ auto main_impl::make_gl_conf(const fm_settings& s) -> GLConfiguration { GLConfiguration::Flags flags{}; using f = GLConfiguration::Flag; - if (s.gpu_debug == fm_gpu_debug::on || s.gpu_debug == fm_gpu_debug::robust) + if (s.gpu_debug >= fm_gpu_debug::on) flags |= f::Debug | f::GpuValidation; if (s.gpu_debug == fm_gpu_debug::robust) flags |= f::RobustAccess; - else if (s.gpu_debug == fm_gpu_debug::no_error) + else if (s.gpu_debug <= fm_gpu_debug::off) flags |= f::NoError; return GLConfiguration{}.setFlags(flags); } @@ -79,7 +79,7 @@ void main_impl::recalc_viewport(Vector2i size) noexcept app.on_viewport_event(size); } -static int fake_argc = 0; +static int fake_argc = 0; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) main_impl::main_impl(floormat_app& app, fm_settings&& s) noexcept : Platform::Sdl2Application{Arguments{fake_argc, nullptr}, @@ -93,7 +93,7 @@ main_impl::main_impl(floormat_app& app, fm_settings&& s) noexcept : if (const auto list = GL::Context::current().extensionStrings(); std::find(list.cbegin(), list.cend(), "EXT_swap_control_tear") != list.cbegin()) (void)setSwapInterval(-1); - setMinimalLoopPeriod(4); + setMinimalLoopPeriod(0); break; case fm_tristate::off: setSwapInterval(0); @@ -173,8 +173,32 @@ void main_impl::drawEvent() timeline.nextFrame(); } - const float dt = std::clamp(timeline.previousFrameDuration(), 1e-6f, 1e-1f); - app.update(dt); + { + float dt_max; + unsigned min_loop_period; + + if (const auto flags = SDL_GetWindowFlags(window()); + flags & SDL_WINDOW_HIDDEN) + { + dt_max = 1 + 1e-3f; + min_loop_period = 1000; + } + else if (!(flags & (SDL_WINDOW_INPUT_FOCUS|SDL_WINDOW_MOUSE_FOCUS))) + { + dt_max = 1.f/10; + min_loop_period = 1000/12; + } + else + { + dt_max = 1e-1f; + min_loop_period = 0; + } + + const float dt = std::clamp(timeline.previousFrameDuration(), 1e-6f, dt_max); + setMinimalLoopPeriod(min_loop_period); + + app.update(dt); + } _shader.set_tint({1, 1, 1, 1}); diff --git a/main/floormat.hpp b/main/floormat.hpp index 9696cfbd..dffb551f 100644 --- a/main/floormat.hpp +++ b/main/floormat.hpp @@ -6,7 +6,7 @@ namespace floormat { -enum class fm_gpu_debug : char { no_error = -1, on, robust, off }; +enum class fm_gpu_debug : char { no_error = 1, off, on, robust, }; enum class fm_tristate : char { maybe = -1, on, off }; enum class fm_log_level : unsigned char { quiet, normal, verbose, }; -- cgit v1.2.3