diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-03-01 17:54:32 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-03-01 17:54:32 +0100 |
commit | 052270b2cbba325076cd5ff57b04c2df5eec2307 (patch) | |
tree | f47a587880e795801abc2e285c683b42bdcae6c9 /src | |
parent | 10e22ed4fb0bd21d9d268c5c6f1ac1c7d9e4b621 (diff) |
a
Diffstat (limited to 'src')
-rw-r--r-- | src/object.cpp | 11 | ||||
-rw-r--r-- | src/timer-ns.cpp | 11 | ||||
-rw-r--r-- | src/timer.hpp | 4 |
3 files changed, 20 insertions, 6 deletions
diff --git a/src/object.cpp b/src/object.cpp index e440ab7a..be455b9b 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -271,14 +271,17 @@ void object::move_to(Magnum::Vector2i delta) uint32_t object::allocate_frame_time(Ns dt, uint16_t& accum, uint32_t hz, float speed) { - fm_assert(hz > 0); - fm_assert(dt >= Ns{0}); + using ld = long double; constexpr auto ns_in_sec = Ns(1e9); constexpr auto u16_max = uint64_t{65535}; + + fm_assert(hz > 0); + fm_assert(dt >= Ns{0}); + //const auto count = Ns::Type{ns_in_sec / hz} + accum}; const auto from_accum = uint64_t{accum} * ns_in_sec / u16_max; - const auto from_dt = Ns(uint64_t(float{dt} * speed)); - fm_assert(from_dt <= Ns{1 << 24}); + const auto from_dt = Ns(uint64_t(ld(dt.stamp) * ld(speed))); + fm_assert(from_dt <= Ns{1 << 54}); const auto ticks = from_dt + from_accum; const auto frame_duration = ns_in_sec / hz; const auto frames = (uint32_t)(ticks / frame_duration); diff --git a/src/timer-ns.cpp b/src/timer-ns.cpp index 7a2fe087..80bd29df 100644 --- a/src/timer-ns.cpp +++ b/src/timer-ns.cpp @@ -1,5 +1,6 @@ #include "timer.hpp" #include "compat/assert.hpp" +#include "compat/debug.hpp" #include <cr/Debug.h> namespace floormat { @@ -98,4 +99,14 @@ Ns::operator uint64_t() const { return stamp; } Ns::operator float() const { return float(stamp); } uint64_t Ns::operator*() const { return stamp; } +Debug& operator<<(Debug& dbg, const Ns& box) +{ + auto flags = dbg.flags(); + dbg << ""; + dbg.setFlags(flags | Debug::Flag::NoSpace); + dbg << fraction((float)((double)box.stamp * 1e-6), 1) << " ms"; + dbg.setFlags(flags); + return dbg; +} + } // namespace floormat diff --git a/src/timer.hpp b/src/timer.hpp index 43637b36..8eef447e 100644 --- a/src/timer.hpp +++ b/src/timer.hpp @@ -29,6 +29,8 @@ struct Ns friend bool operator==(const Ns& lhs, const Ns& rhs); friend std::strong_ordering operator<=>(const Ns& lhs, const Ns& rhs); + + friend Debug& operator<<(Debug& dbg, const Ns& box); }; struct Time final @@ -48,8 +50,6 @@ private: static uint64_t init() noexcept; }; -Debug& operator<<(Debug& dbg, Ns box); - constexpr inline size_t fm_DATETIME_BUF_SIZE = 32; const char* format_datetime_to_string(char(&buf)[fm_DATETIME_BUF_SIZE]); |