diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-17 18:07:53 +0200 |
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-17 18:07:53 +0200 |
| commit | 6cadd1270b8ac5c5f49f5c07e74e7bd236dd0eb3 (patch) | |
| tree | f705ecd3e5ff75fdc393daf59a20ae00dfb19bb3 | |
| parent | 5dd1ade46d1c21b840cfdd4acfaf3012a2955f7c (diff) | |
a
| -rw-r--r-- | main/app.hpp | 12 | ||||
| -rw-r--r-- | main/draw.cpp | 14 | ||||
| -rw-r--r-- | main/gui.cpp | 3 |
3 files changed, 22 insertions, 7 deletions
diff --git a/main/app.hpp b/main/app.hpp index 2a2a97f9..f57aaa4d 100644 --- a/main/app.hpp +++ b/main/app.hpp @@ -29,12 +29,12 @@ struct app final : Platform::Application void update(float dt); - void reset_camera_offset(); - void update_window_scale(Vector2i window_size); - - void do_camera(float dt); void do_key(KeyEvent::Key k, KeyEvent::Modifiers m, bool pressed, bool repeated); void do_mouse_click(global_coords pos, int button); + + void do_camera(float dt); + void reset_camera_offset(); + void update_window_scale(Vector2i window_size); void recalc_cursor_tile(); void keyPressEvent(KeyEvent& event) override; @@ -46,13 +46,14 @@ struct app final : Platform::Application void textInputEvent(TextInputEvent& event) override; void viewportEvent(ViewportEvent& event) override; void anyEvent(SDL_Event& event) override; + void event_leave(); void event_enter(); void event_mouse_enter(); void event_mouse_leave(); - void drawEvent() override; std::array<std::int16_t, 4> get_draw_bounds() const noexcept; + void drawEvent() override; void draw_world(); void draw_cursor_tile(); void draw_wireframe_quad(global_coords pt); @@ -96,6 +97,7 @@ struct app final : Platform::Application editor _editor; std::optional<Vector2i> _cursor_pos; std::optional<global_coords> _cursor_tile; + float _frame_time = 0; static constexpr std::int16_t BASE_X = 0, BASE_Y = 0; }; diff --git a/main/draw.cpp b/main/draw.cpp index e2bcdd31..82c4efc9 100644 --- a/main/draw.cpp +++ b/main/draw.cpp @@ -7,8 +7,20 @@ namespace floormat { void app::drawEvent() { + + if (const float dt = timeline.previousFrameDuration(); dt > 0) + { + constexpr float RC = 0.5f; + const float alpha = dt/(dt + RC); + + if (_frame_time > 0) + _frame_time = _frame_time*(1-alpha) + alpha*dt; + else + _frame_time = dt; + } + { - const float dt = std::min(1.f/10, timeline.previousFrameDuration()); + const float dt = std::clamp(timeline.previousFrameDuration(), 1e-3f, 1e-1f); update(dt); } diff --git a/main/gui.cpp b/main/gui.cpp index 22bb95fd..ea65a1b6 100644 --- a/main/gui.cpp +++ b/main/gui.cpp @@ -149,8 +149,9 @@ void app::draw_fps([[maybe_unused]] float main_menu_height) 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", 0.f); + snprintf(buf, sizeof(buf), "%.1f FPS", dt); ImGui::SameLine(max_size.x - ImGui::CalcTextSize(buf).x); ImGui::Text("%s", buf); } |
