diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-03-28 15:02:03 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-04-04 00:14:45 +0200 |
commit | 5e0008adc0019e2d769f3b274d1cf0c120c0b020 (patch) | |
tree | 5d37671e6336ee66050898c11e76de9284b41ce3 /editor/tests/path-test.cpp | |
parent | e3743cc6717ca7a7a655d9c22e10fe1e8356174a (diff) |
implement simplifying A* result path
Diffstat (limited to 'editor/tests/path-test.cpp')
-rw-r--r-- | editor/tests/path-test.cpp | 36 |
1 files changed, 14 insertions, 22 deletions
diff --git a/editor/tests/path-test.cpp b/editor/tests/path-test.cpp index cc7dc796..ac95bcd9 100644 --- a/editor/tests/path-test.cpp +++ b/editor/tests/path-test.cpp @@ -36,12 +36,8 @@ struct path_test final : base_test struct result_s { point from, to; - std::vector<point> path; - float time; - uint32_t cost, distance; - bool found : 1; + path_search_result res; } result; - bool has_result : 1 = false, has_pending : 1 = false; }; @@ -116,7 +112,7 @@ void path_test::draw_overlay(app& a) auto last = a.point_screen_pos(result.from); draw.AddCircleFilled({last.x(), last.y()}, dot_radius, dot_color); - for (auto pt : result.path) + for (auto pt : result.res.path()) { auto pos = a.point_screen_pos(pt); draw.AddLine({pos.x(), pos.y()}, {last.x(), last.y()}, line_color, line_thickness); @@ -124,9 +120,9 @@ void path_test::draw_overlay(app& a) last = pos; } - if (!result.found && !result.path.empty()) + if (!result.res.is_found() && !result.res.path().isEmpty()) { - auto pos = a.point_screen_pos(result.path.back()); + auto pos = a.point_screen_pos(result.res.path().back()); constexpr float spacing = 12, size1 = 7, size2 = 3, spacing2 = spacing + size2; draw.AddLine({pos.x() - spacing2, pos.y() - spacing2}, @@ -161,11 +157,7 @@ void path_test::update_pre(app& a, const Ns&) result = { .from = pending.from, .to = pending.to, - .path = move(res.raw_path().vec), - .time = res.time(), - .cost = res.cost(), - .distance = res.distance(), - .found = res.is_found(), + .res = move(res), }; } @@ -176,14 +168,14 @@ void path_test::draw_ui(app&, float) constexpr auto colflags_0 = colflags_1 | ImGuiTableColumnFlags_WidthFixed; char buf[128]; - const auto& res = result; + const auto& res = result.res; if (!has_result) return; - auto from_c = Vector3i(res.from.chunk3()), to_c = Vector3i(res.to.chunk3()); - auto from_l = Vector2i(res.from.local()), to_l = Vector2i(res.to.local()); - auto from_p = Vector2i(res.from.offset()), to_p = Vector2i(res.to.offset()); + auto from_c = Vector3i(result.from.chunk3()), to_c = Vector3i(result.to.chunk3()); + auto from_l = Vector2i(result.from.local()), to_l = Vector2i(result.to.local()); + auto from_p = Vector2i(result.from.offset()), to_p = Vector2i(result.to.offset()); constexpr auto print_coord = [](auto&& buf, Vector3i c, Vector2i l, Vector2i p) { @@ -212,7 +204,7 @@ void path_test::draw_ui(app&, float) text(buf); do_column("found?"); - if (res.found) + if (res.is_found()) { auto b = push_style_color(ImGuiCol_Text, 0x00ff00ff_rgbaf); text("yes"); @@ -226,21 +218,21 @@ void path_test::draw_ui(app&, float) { auto b = push_style_color(ImGuiCol_Text, 0xffff00ff_rgbaf); do_column("dist"); - std::snprintf(buf, std::size(buf), "%d", (int)res.distance); + std::snprintf(buf, std::size(buf), "%d", (int)res.distance()); text(buf); } } do_column("cost"); - std::snprintf(buf, std::size(buf), "%d", (int)res.cost); + std::snprintf(buf, std::size(buf), "%d", (int)res.cost()); text(buf); do_column("length"); - std::snprintf(buf, std::size(buf), "%d", (int)res.path.size()); + std::snprintf(buf, std::size(buf), "%d", (int)res.path().size()); text(buf); do_column("time"); - std::snprintf(buf, std::size(buf), "%.1f ms", (double)(1000 * res.time)); + std::snprintf(buf, std::size(buf), "%.1f ms", (double)(1000 * res.time())); text(buf); } } |