1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
#include "app.hpp"
#include "compat/shared-ptr-wrapper.hpp"
#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
* wall n 0x1 - 8:0
*
* npc speed=5 bbox-offset=0 bbox-size=32x32
*
* before chunk=0x0 tile=8:15 offset=-8:8
* after chunk=0x0 tile=8:9 offset=-8:-16
*/
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 };
auto w = world();
w[{{0,0,0}, {8,9}}].t.wall_north() = W;
w[{{0,1,0}, {8,0}}].t.wall_north() = W;
constexpr point init {{0,0,0}, {8,15}, {-8, 8}};
constexpr point end {{0,0,0}, {8, 9}, {-8,-16}};
object_id id = 0;
auto player = w.ensure_player_character(id, make_proto(accel)).ptr;
auto index = player->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, int accel)
{
// TODO diagonal!
}
} // namespace
void test_app::test_critter()
{
test1(constantly(Millisecond * 1000), 1);
}
} // namespace floormat
|