summaryrefslogtreecommitdiffhomepage
path: root/main
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-02-29 21:29:56 +0100
committerStanislaw Halik <sthalik@misaki.pl>2024-03-01 06:06:53 +0100
commit486e591169af724107ffaf6f24cd1e81b24529a9 (patch)
tree012ec6c07c474d4695eb5c22b47dd35cfce2767c /main
parent5afe42d6a81eeb81db08d4bd2107ac4c71f6671e (diff)
time wip
It works now, but some functionality is lost in main/draw.cpp
Diffstat (limited to 'main')
-rw-r--r--main/ctor.cpp2
-rw-r--r--main/draw.cpp43
-rw-r--r--main/main-impl.hpp14
-rw-r--r--main/setup.cpp2
4 files changed, 35 insertions, 26 deletions
diff --git a/main/ctor.cpp b/main/ctor.cpp
index da38fb18..19a4546a 100644
--- a/main/ctor.cpp
+++ b/main/ctor.cpp
@@ -23,7 +23,7 @@ main_impl::main_impl(floormat_app& app, fm_settings&& se, int& argc, char** argv
(void)setSwapInterval(0);
set_fp_mask();
arrayReserve(_clickable_scenery, 128);
- timeline.start();
+ tm.timeline = Time::now();
}
class world& main_impl::reset_world(class world&& w) noexcept
diff --git a/main/draw.cpp b/main/draw.cpp
index b0f97fab..79e9ccfe 100644
--- a/main/draw.cpp
+++ b/main/draw.cpp
@@ -6,6 +6,7 @@
#include "main/clickable.hpp"
#include "src/light.hpp"
#include "src/log.hpp"
+#include "src/timer.hpp"
#include <Corrade/Containers/GrowableArray.h>
#include <Corrade/Containers/ArrayView.h>
#include <Magnum/GL/DefaultFramebuffer.h>
@@ -71,8 +72,7 @@ void main_impl::recalc_viewport(Vector2i fb_size, Vector2i win_size) noexcept
// -- user--
app.on_viewport_event(fb_size);
-
- fps_sample_timeline.start();
+ tm.timeline = Time::now();
}
global_coords main_impl::pixel_to_tile(Vector2d position) const noexcept
@@ -216,34 +216,33 @@ bool floormat_main::check_chunk_visible(const Vector2d& offset, const Vector2i&
return X + W > 0 && X < size[x] && Y + H > 0 && Y < size[y];
}
+#if 0
#ifndef FM_NO_DEBUG
static size_t good_frames, bad_frames; // NOLINT
#endif
+#endif
-void main_impl::do_update()
+void main_impl::do_update() // todo! move to separate file
{
-
- // todo switch to using microseconds
- float dt = timeline.previousFrameDuration();
- if (dt > 0)
+ constexpr auto eps = 1e-5f;
+ const auto dt = tm.timeline.update();
+ if (auto secs = Time::to_seconds(dt); secs > eps)
{
- if (fps_sample_timeline.currentFrameDuration() > 1.f/15)
- {
- fps_sample_timeline.nextFrame();
- constexpr float RC = 10;
- constexpr float alpha = 1/(1 + RC);
- _frame_time = _frame_time*(1-alpha) + alpha*dt;
- }
+#if 1
+ constexpr float RC = 60;
+ constexpr auto alpha = 1 / (1 + RC);
+ _frame_time = _frame_time * (1 - alpha) + alpha * secs;
+#else
+ _frame_time = secs;
+#endif
static size_t ctr = 0;
- if (dt >= 1.f/55 && !dt_expected.do_sleep)
- fm_debug("%zu frame took %.1f milliseconds", ctr++, dt*1e3f);
+ if (secs > 35e-3f /* && !dt_expected.do_sleep */)
+ fm_debug("%zu frame took %.2f milliseconds", ctr++, (double)secs*1e3);
}
else
- {
swapBuffers();
- timeline.nextFrame();
- }
+#if 0
#ifndef FM_NO_DEBUG
if (dt_expected.value == 0 || !is_log_verbose()) [[likely]]
void();
@@ -286,6 +285,7 @@ void main_impl::do_update()
t = {};
}
}
+#endif
app.update(dt);
}
@@ -295,7 +295,7 @@ void main_impl::bind() noexcept
framebuffer.fb.bind();
}
-void main_impl::drawEvent()
+void main_impl::drawEvent() // todo! move to separate file (with `do_update')
{
_shader.set_tint({1, 1, 1, 1});
@@ -318,8 +318,8 @@ void main_impl::drawEvent()
swapBuffers();
redraw();
- timeline.nextFrame();
+#if 0
if (dt_expected.do_sleep && (false))
{
constexpr float ε = 1e-3f;
@@ -338,6 +338,7 @@ void main_impl::drawEvent()
dt_expected.jitter = 0;
dt_expected.value = 0;
}
+#endif
}
ArrayView<const clickable> main_impl::clickable_scenery() const noexcept
diff --git a/main/main-impl.hpp b/main/main-impl.hpp
index 0f1bae35..01be6187 100644
--- a/main/main-impl.hpp
+++ b/main/main-impl.hpp
@@ -2,6 +2,8 @@
#include "floormat/main.hpp"
#include "floormat/settings.hpp"
#include "src/world.hpp"
+#include "src/timer-fwd.hpp"
+#include "src/timer.hpp"
#include "draw/ground.hpp"
#include "draw/wall.hpp"
#include "draw/anim.hpp"
@@ -11,7 +13,6 @@
#include "main/clickable.hpp"
#include <Corrade/Containers/Array.h>
#include <Corrade/Containers/String.h>
-#include <Magnum/Timeline.h>
#include <Magnum/Math/Range.h>
#include <Magnum/GL/DebugOutput.h>
#include <Magnum/Platform/Sdl2Application.h>
@@ -102,6 +103,12 @@ struct main_impl final : Platform::Sdl2Application, floormat_main
class astar& astar() override;
private:
+ struct {
+ Ns last_frame_duration{0};
+ Time frame_start;
+ Time timeline; // todo rename
+ } tm;
+
struct texture_unit_cache _tuc;
fm_settings s;
[[maybe_unused]] char _dummy = (register_debug_callback(), '\0');
@@ -110,7 +117,6 @@ private:
struct lightmap_shader _lightmap_shader{_tuc};
Array<clickable> _clickable_scenery;
class world _world{};
- Magnum::Timeline timeline;
uint32_t _mouse_cursor = (uint32_t)-1;
ground_mesh _ground_mesh;
wall_mesh _wall_mesh;
@@ -121,14 +127,14 @@ private:
safe_ptr<path_search> _search;
safe_ptr<class astar> _astar;
+#if 0
struct {
float value = 0;
float jitter = 0;
bool do_sleep = false;
bool has_focus = true;
} dt_expected;
-
- Timeline fps_sample_timeline;
+#endif
void recalc_viewport(Vector2i fb_size, Vector2i win_size) noexcept;
void draw_world() noexcept;
diff --git a/main/setup.cpp b/main/setup.cpp
index a16165ba..7014cc0d 100644
--- a/main/setup.cpp
+++ b/main/setup.cpp
@@ -59,6 +59,7 @@ void main_impl::update_window_state()
{
const auto flags = (SDL_WindowFlags)SDL_GetWindowFlags(window());
+#if 0
dt_expected.do_sleep = true;
dt_expected.jitter = 0;
dt_expected.has_focus = true;
@@ -83,6 +84,7 @@ void main_impl::update_window_state()
dt_expected.do_sleep = false;
dt_expected.value = 1e-1f;
}
+#endif
}
auto main_impl::meshes() noexcept -> struct meshes