diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-03-02 11:52:53 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-03-02 11:52:53 +0100 |
commit | a6481a7065852cb01846a5dc8a92fd415ba745fb (patch) | |
tree | 68321663f06ca3d3b54774e6a649283ef944df81 /test | |
parent | 9ff017f1d4c1502fca9797aa4b38351c97e57982 (diff) |
w
Diffstat (limited to 'test')
-rw-r--r-- | test/critter.cpp | 55 |
1 files changed, 48 insertions, 7 deletions
diff --git a/test/critter.cpp b/test/critter.cpp index 6eb42315..fe9a2b07 100644 --- a/test/critter.cpp +++ b/test/critter.cpp @@ -3,12 +3,40 @@ #include "src/critter.hpp" #include "src/world.hpp" #include "src/wall-atlas.hpp" +#include "src/timer.hpp" #include "loader/loader.hpp" namespace floormat { namespace { +constexpr auto constantly(const auto& x) noexcept { + return [x]<typename... Ts> (const Ts&...) constexpr -> const auto& { return x; }; +} + +template<typename F> +void run(StringView name, const F& make_dt, critter& npc, const uint32_t max_steps, + const point expected_pt, const Ns expected_time, + const uint32_t fuzz_pixels, const Ns fuzz_time) +{ + fm_assert(max_steps <= 1000); + + Ns time{0}; + uint32_t steps; + + Debug{} << "==>" << name; + + for (uint32_t i = 0; i < max_steps; i++) + { + auto dt = Ns{make_dt()}; + Debug{} << ">>" << i << dt; + fm_assert(dt <= Ns(1e9)); + Debug{} << " " << i << npc.position(); + } + + Debug{} << "done"; +} + /* ***** TEST 1 ***** * * wall n 0x0 - 8:9 @@ -20,7 +48,20 @@ namespace { * after chunk=0x0 tile=8:9 offset=-8:-16 */ -template<typename F> void test1(F&& make_dt) +critter_proto make_proto(int accel) +{ + critter_proto proto; + proto.atlas = loader.anim_atlas("npc-walk", loader.ANIM_PATH); + proto.name = "Player"_s; + proto.speed = accel; + proto.playable = true; + proto.offset = {}; + proto.bbox_offset = {}; + proto.bbox_size = Vector2ub(tile_size_xy/2); + return proto; +} + +template<typename F> void test1(const F& make_dt, int accel) { const auto W = wall_image_proto{ loader.wall_atlas("empty"), 0 }; @@ -28,13 +69,13 @@ template<typename F> void test1(F&& make_dt) w[{{0,0,0}, {8,9}}].t.wall_north() = W; w[{{0,1,0}, {8,0}}].t.wall_north() = W; - critter_proto cproto; - cproto.name = "Player"_s; - cproto.speed = 10; - cproto.playable = true; + constexpr point init {{0,0,0}, {8,15}, {-8, 8}}; + constexpr point end {{0,0,0}, {8, 9}, {-8,-16}}; object_id id = 0; - w.ensure_player_character(id, move(cproto)); + auto player = w.ensure_player_character(id, make_proto(accel)).ptr; + auto index = player->index(); + player->teleport_to(index, ); w[chunk_coords_{0,0,0}].mark_modified(); w[chunk_coords_{0,1,0}].mark_modified(); @@ -49,7 +90,7 @@ template<typename F> void test2(F&& make_dt) void test_app::test_critter() { - + test1(constantly(Ns::Millisecond*16.666667), 1); } } // namespace floormat |