summaryrefslogtreecommitdiffhomepage
path: root/test
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 /test
parent5afe42d6a81eeb81db08d4bd2107ac4c71f6671e (diff)
time wip
It works now, but some functionality is lost in main/draw.cpp
Diffstat (limited to 'test')
-rw-r--r--test/app.cpp1
-rw-r--r--test/app.hpp1
-rw-r--r--test/serializer.cpp7
-rw-r--r--test/time.cpp28
4 files changed, 35 insertions, 2 deletions
diff --git a/test/app.cpp b/test/app.cpp
index af5cc1f9..4677de39 100644
--- a/test/app.cpp
+++ b/test/app.cpp
@@ -53,6 +53,7 @@ int test_app::exec()
FM_TEST(test_hash),
FM_TEST(test_raycast),
FM_TEST(test_json),
+ FM_TEST(test_time),
FM_TEST(test_loader),
FM_TEST(test_region),
FM_TEST(test_wall_atlas),
diff --git a/test/app.hpp b/test/app.hpp
index e4b77614..d100ab13 100644
--- a/test/app.hpp
+++ b/test/app.hpp
@@ -42,6 +42,7 @@ struct test_app final : private FM_APPLICATION
static void test_saves();
static void test_serializer1();
static void test_tile_iter();
+ static void test_time();
static void test_wall_atlas();
static void test_wall_atlas2();
diff --git a/test/serializer.cpp b/test/serializer.cpp
index 44746449..cc9405ef 100644
--- a/test/serializer.cpp
+++ b/test/serializer.cpp
@@ -7,6 +7,7 @@
#include "src/ground-atlas.hpp"
#include "src/anim-atlas.hpp"
#include "src/tile-iterator.hpp"
+#include "src/timer.hpp"
#include <Corrade/Utility/Path.h>
namespace floormat {
@@ -52,15 +53,17 @@ chunk& test_app::make_test_chunk(world& w, chunk_coords_ ch)
auto& e = *w.make_object<scenery>(w.make_id(), {ch, {K+3, K+1}}, door);
const auto index = e.index();
const auto end = e.atlas->info().nframes-1;
+ constexpr auto second = Ns(1e9);
+ constexpr auto dt = second / 60;
fm_assert(e.frame == end);
{ auto& x = std::get<door_scenery>(e.subtype);
fm_assert(!x.active);
e.activate(e.index());
fm_assert(x.active);
- e.update(index, 1.f/60);
+ e.update(index, dt);
fm_assert(e.frame != end);
for (int i = 0; i < 60*3; i++)
- e.update(index, 1.f/60);
+ e.update(index, dt);
fm_assert(e.frame == 0);
fm_assert(!x.active);
}
diff --git a/test/time.cpp b/test/time.cpp
new file mode 100644
index 00000000..dac8a2e4
--- /dev/null
+++ b/test/time.cpp
@@ -0,0 +1,28 @@
+#include "app.hpp"
+#include "src/timer.hpp"
+#include <cstdio>
+#include <thread>
+#include <mg/TimeStl.h>
+
+namespace floormat {
+
+using namespace std::chrono_literals;
+
+void test_app::test_time()
+{
+#if 0
+ constexpr auto to_ms = [](Ns dt) { return Time::to_seconds(dt); };
+ Timer::maybe_start();
+
+ Debug{} << "";
+ auto t1 = Time::now();
+ std::this_thread::sleep_for(8ms);
+ auto t2 = Time::now();
+ Debug{} << "- foo1" << to_ms(t2 - t1);
+ Debug{} << "- foo2" << to_ms(Time::now() - t1);
+ Debug{} << "- foo3" << to_ms(Timer::since_epoch());
+ std::fputc('\t', stdout);
+#endif
+}
+
+} // namespace floormat