summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/object.cpp2
-rw-r--r--src/timer-ns.cpp23
-rw-r--r--src/timer.hpp44
-rw-r--r--test/critter.cpp8
4 files changed, 44 insertions, 33 deletions
diff --git a/src/object.cpp b/src/object.cpp
index 208f4fe2..9d8f2f16 100644
--- a/src/object.cpp
+++ b/src/object.cpp
@@ -222,7 +222,7 @@ void object::teleport_to(size_t& i, global_coords coord_, Vector2b offset_, rota
{
if (new_r == rotation_COUNT)
new_r = r;
- else if (!atlas->check_rotation(new_r) || true)
+ else if (!atlas->check_rotation(new_r))
{
const auto& info = atlas->info();
const auto *obj = info.object_name.data(), *anim = info.anim_name.data();
diff --git a/src/timer-ns.cpp b/src/timer-ns.cpp
index 45d0411c..6a24f3c9 100644
--- a/src/timer-ns.cpp
+++ b/src/timer-ns.cpp
@@ -41,29 +41,6 @@ Ns operator-(const Ns& lhs, const Ns& rhs)
return Ns{a - b};
}
-Ns operator*(const Ns& lhs, uint64_t b)
-{
- auto a = lhs.stamp;
- auto x = a * b;
- //fm_assert(!(a != 0 && x / a != b));
- fm_assert(a == 0 || x / a == b);
- return Ns{x};
-}
-
-Ns operator*(uint64_t a, const Ns& rhs)
-{
- auto b = rhs.stamp;
- return Ns{a} * b;
-}
-
-Ns operator*(const Ns& lhs, float b_)
-{
- long double a(lhs.stamp), b(b_);
- auto x = a * b;
- fm_assert(x <= 1 << 24 && x >= 0);
- return Ns{uint64_t(x)};
-}
-
uint64_t operator/(const Ns& lhs, const Ns& rhs)
{
auto a = lhs.stamp, b = rhs.stamp;
diff --git a/src/timer.hpp b/src/timer.hpp
index a05cc507..45c41459 100644
--- a/src/timer.hpp
+++ b/src/timer.hpp
@@ -1,4 +1,5 @@
#pragma once
+#include "compat/assert.hpp"
#include <compare>
namespace floormat {
@@ -15,10 +16,43 @@ struct Ns
friend Ns operator+(const Ns& lhs, const Ns& rhs);
friend Ns operator-(const Ns& lhs, const Ns& rhs);
- friend Ns operator*(const Ns& lhs, uint64_t rhs);
- friend Ns operator*(uint64_t lhs, const Ns& rhs);
- friend Ns operator*(const Ns& lhs, float rhs);
- friend Ns operator*(float lhs, const Ns& rhs);
+
+ friend Ns operator*(const Ns&, const Ns&) = delete;
+
+ template<typename T>
+ requires (std::is_integral_v<T> && std::is_unsigned_v<T>)
+ friend Ns operator*(const Ns& lhs, T rhs)
+ {
+ auto a = lhs.stamp, b = uint64_t{rhs};
+ auto x = a * b;
+ fm_assert(b == 0 || x / b == a);
+ return Ns{x};
+ }
+
+ template<typename T>
+ requires (std::is_integral_v<T> && std::is_signed_v<T> && sizeof(T) < sizeof(uint64_t))
+ friend Ns operator*(const Ns& lhs, T rhs)
+ {
+ fm_assert(rhs >= T{0});
+ return lhs * uint64_t(rhs);
+ }
+
+ template<typename T>
+ friend Ns operator*(T lhs, const Ns& rhs) { return rhs * lhs; }
+
+ template<typename T>
+ requires std::is_same_v<float, T>
+ friend Ns operator*(const Ns& lhs, T rhs)
+ {
+ auto a = lhs.stamp;
+ auto x = float(a) * float{rhs};
+ fm_assert(x <= 1 << 24 && x >= 0);
+ return Ns{uint64_t(x)};
+ }
+
+ template<typename T>
+ requires std::is_same_v<float, T>
+ friend Ns operator*(T lhs, const Ns& rhs) { return rhs * lhs; }
friend uint64_t operator/(const Ns& lhs, const Ns& rhs);
friend Ns operator/(const Ns& lhs, uint64_t rhs);
@@ -30,8 +64,6 @@ struct Ns
friend Debug& operator<<(Debug& dbg, const Ns& box);
uint64_t stamp;
-
- static constexpr uint64_t Min = 0, Max = (uint64_t)-1;
};
constexpr inline Ns Second{1000000000}, Millisecond{1000000};
diff --git a/test/critter.cpp b/test/critter.cpp
index fe9a2b07..a545248a 100644
--- a/test/critter.cpp
+++ b/test/critter.cpp
@@ -75,13 +75,15 @@ template<typename F> void test1(const F& make_dt, int accel)
object_id id = 0;
auto player = w.ensure_player_character(id, make_proto(accel)).ptr;
auto index = player->index();
- player->teleport_to(index, );
+ player->teleport_to(index, init, rotation_COUNT);
w[chunk_coords_{0,0,0}].mark_modified();
w[chunk_coords_{0,1,0}].mark_modified();
+
+ run("test1"_s, make_dt, *player, 10, end, Second*7, 16, Millisecond*350);
}
-template<typename F> void test2(F&& make_dt)
+template<typename F> void test2(F&& make_dt, int accel)
{
// TODO diagonal!
}
@@ -90,7 +92,7 @@ template<typename F> void test2(F&& make_dt)
void test_app::test_critter()
{
- test1(constantly(Ns::Millisecond*16.666667), 1);
+ test1(constantly(Millisecond * 1000), 1);
}
} // namespace floormat