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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
#include "../tests-private.hpp"
#include "compat/shared-ptr-wrapper.hpp"
#include "editor/app.hpp"
#include "src/world.hpp"
#include "floormat/main.hpp"
#include "../imgui-raii.hpp"
#include <mg/Functions.h>
namespace floormat::tests {
using namespace floormat::imgui;
namespace {
struct step_s
{
uint32_t count;
Vector2b direction;
explicit constexpr operator bool() const { return count != 0 && count != -1u; }
};
constexpr inline auto empty_step = step_s{0, {}}, invalid_step = step_s{-1u, {}};
constexpr step_s next_step(Vector2i vec_in)
{
const auto vec = Vector2ui(Math::abs(vec_in));
const auto signs = Vector2b(Math::sign(vec_in));
if (vec.x() == vec.y())
return { vec.x(), Vector2b{1, 1} * signs };
else if (vec.y() == 0)
return { vec.x(), Vector2b{1, 0} * signs };
else if (vec.x() == 0)
return { vec.y(), Vector2b{0, 1} * signs };
else
{
uint32_t major_idx, minor_idx;
if (vec.x() > vec.y())
{
major_idx = 0;
minor_idx = 1;
}
else
{
major_idx = 1;
minor_idx = 0;
}
const auto major = vec[major_idx], minor = vec[minor_idx];
const auto num_axis_aligned = (uint32_t)Math::abs((int)major - (int)minor);
auto axis_aligned = Vector2b{};
axis_aligned[major] = 1;
return { num_axis_aligned, axis_aligned * signs };
}
}
struct result_s
{
bool has_value : 1 = false;
};
struct pending_s
{
bool has_value : 1 = false;
};
struct pf_test final : base_test
{
result_s result;
pending_s pending;
~pf_test() noexcept override = default;
static step_s get_next_step(point from, point to);
bool handle_key(app& a, const key_event& e, bool is_down) override;
bool handle_mouse_click(app& a, const mouse_button_event& e, bool is_down) override;
bool handle_mouse_move(app& a, const mouse_move_event&) override { return {}; }
void draw_overlay(app& a) override;
void draw_ui(app& a, float menu_bar_height) override;
void update_pre(app& a) override;
void update_post(app& a) override;
};
step_s pf_test::get_next_step(point from, point to)
{
if (from.chunk3().z != to.chunk3().z)
return invalid_step;
if (from == to)
return empty_step;
const auto vec = to.coord() - from.coord();
fm_debug_assert(!vec.isZero());
return next_step(vec);
}
bool pf_test::handle_key(app& a, const key_event& e, bool is_down)
{
(void) a; (void)e; (void)is_down;
return false;
}
bool pf_test::handle_mouse_click(app& a, const mouse_button_event& e, bool is_down)
{
(void)a; (void)e; (void)is_down;
return false;
}
void pf_test::draw_overlay(app& a)
{
(void)a;
}
void pf_test::draw_ui(app& a, float)
{
(void)a;
}
void pf_test::update_pre(app& a)
{
if (!pending.has_value)
return;
pending.has_value = false;
auto& m = a.main();
auto& c = *a.ensure_player_character(m.world()).ptr;
}
void pf_test::update_post(app& a)
{
}
} // namespace
Pointer<base_test> tests_data::make_test_pathfinding() { return Pointer<pf_test>{InPlaceInit}; }
} // namespace floormat::tests
|