diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-02-29 21:34:46 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-03-01 06:06:53 +0100 |
commit | 5afe42d6a81eeb81db08d4bd2107ac4c71f6671e (patch) | |
tree | bab0a6f354047377742fb9cbd8be5d067400c6c1 | |
parent | 74387a4aa6117abcc814bc26c3c9ede98fdfa5bc (diff) |
wip debug code
-rw-r--r-- | main/draw.cpp | 45 | ||||
-rw-r--r-- | src/critter.cpp | 25 |
2 files changed, 59 insertions, 11 deletions
diff --git a/main/draw.cpp b/main/draw.cpp index c7ca97f3..b0f97fab 100644 --- a/main/draw.cpp +++ b/main/draw.cpp @@ -217,12 +217,13 @@ bool floormat_main::check_chunk_visible(const Vector2d& offset, const Vector2i& } #ifndef FM_NO_DEBUG -static size_t good_frames, bad_frames; +static size_t good_frames, bad_frames; // NOLINT #endif void main_impl::do_update() { + // todo switch to using microseconds float dt = timeline.previousFrameDuration(); if (dt > 0) { @@ -230,7 +231,7 @@ void main_impl::do_update() { fps_sample_timeline.nextFrame(); constexpr float RC = 10; - const float alpha = 1/(1 + RC); + constexpr float alpha = 1/(1 + RC); _frame_time = _frame_time*(1-alpha) + alpha*dt; } static size_t ctr = 0; @@ -243,15 +244,15 @@ void main_impl::do_update() timeline.nextFrame(); } - if (auto d = Math::abs(dt - dt_expected.value); d <= 4e-3f) +#ifndef FM_NO_DEBUG + if (dt_expected.value == 0 || !is_log_verbose()) [[likely]] + void(); + else if (auto d = Math::abs(dt - dt_expected.value); d <= 4e-3f) { dt = dt_expected.value + 1e-6f; -#ifndef FM_NO_DEBUG ++good_frames; -#endif } -#ifndef FM_NO_DEBUG - else if (dt_expected.has_focus && dt_expected.do_sleep && is_log_verbose()) [[unlikely]] + else [[unlikely]] { if (good_frames) { @@ -263,6 +264,29 @@ void main_impl::do_update() dt = Math::clamp(dt, 1e-5f, Math::max(.2f, dt_expected.value)); + if constexpr((false)) + { + static struct + { + Timeline tl{}; + float time = 0; + unsigned frames = 0; + } t; + + if (t.frames++ == 0) + t.tl.start(); + else + t.time += dt; + + if (t.frames > 200) + { + Debug{} << "time" + << (double)t.time * 1000. / t.frames + << (double)t.tl.currentFrameDuration() * 1000. / t.frames; + t = {}; + } + } + app.update(dt); } @@ -275,7 +299,7 @@ void main_impl::drawEvent() { _shader.set_tint({1, 1, 1, 1}); - const auto clear_color = 0x222222ff_rgbaf; + constexpr auto clear_color = 0x222222ff_rgbaf; #ifdef FM_USE_DEPTH32 framebuffer.fb.clearColor(0, clear_color); #else @@ -296,7 +320,7 @@ void main_impl::drawEvent() redraw(); timeline.nextFrame(); - if (dt_expected.do_sleep) + if (dt_expected.do_sleep && (false)) { constexpr float ε = 1e-3f; const float Δt൦ = timeline.previousFrameDuration(), sleep_secs = dt_expected.value - Δt൦ - dt_expected.jitter; @@ -310,7 +334,10 @@ void main_impl::drawEvent() dt_expected.jitter = std::copysign(std::fmin(dt_expected.value, std::fabs(dt_expected.jitter)), dt_expected.jitter); } else + { dt_expected.jitter = 0; + dt_expected.value = 0; + } } ArrayView<const clickable> main_impl::clickable_scenery() const noexcept diff --git a/src/critter.cpp b/src/critter.cpp index 77933b77..1a4f77a1 100644 --- a/src/critter.cpp +++ b/src/critter.cpp @@ -9,7 +9,8 @@ #include <cmath> #include <utility> #include <algorithm> -#include <Magnum/Math/Functions.h> +#include <mg/Functions.h> +#include <mg/Timeline.h> namespace floormat { @@ -168,10 +169,13 @@ void critter::update_movement(size_t i, float dt, rotation new_r) int nframes = allocate_frame_time(dt * speed); if (nframes == 0) + { + static unsigned foo; + Debug{} << ++foo << "stopped"; return; + } const auto rotations = rotation_to_similar(new_r); - const unsigned nvecs = (int)new_r & 1 ? 3 : 1; if (r != new_r) @@ -180,6 +184,23 @@ void critter::update_movement(size_t i, float dt, rotation new_r) c->ensure_passability(); + static Timeline TL{}; + static double TIME; + static unsigned FRAMES; + + if (++FRAMES == 0) + TL.start(); + else + TIME += (double)dt; + + if (++FRAMES > 30) + { + Debug{} << "player time" << TIME; + TL.stop(); + TIME = 0; + FRAMES = 0; + } + for (int k = 0; k < nframes; k++) { for (unsigned j = 0; j < nvecs; j++) |