diff options
Diffstat (limited to 'editor/tests')
-rw-r--r-- | editor/tests/path-test.cpp | 19 | ||||
-rw-r--r-- | editor/tests/walk-test.cpp | 48 |
2 files changed, 28 insertions, 39 deletions
diff --git a/editor/tests/path-test.cpp b/editor/tests/path-test.cpp index 84886a65..0b836932 100644 --- a/editor/tests/path-test.cpp +++ b/editor/tests/path-test.cpp @@ -8,6 +8,7 @@ #include "src/critter.hpp" #include "shaders/shader.hpp" #include "../imgui-raii.hpp" +#include <cr/Optional.h> #include <mg/Functions.h> #include <mg/Color.h> @@ -36,7 +37,7 @@ struct path_test final : base_test struct result_s { point from, to; - path_search_result res; + Optional<path_search_result> res; } result; bool has_result : 1 = false, has_pending : 1 = false; }; @@ -103,6 +104,8 @@ void path_test::draw_overlay(app& a) { if (!has_result) return; + fm_assert(result.res); + const auto& res = *result.res; const auto line_color = ImGui::ColorConvertFloat4ToU32({0, 0, 1, 1}); const auto dot_color = ImGui::ColorConvertFloat4ToU32({1, 0, 0, 1}); @@ -112,7 +115,9 @@ 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.res.path()) + + + for (auto pt : res.path()) { auto pos = a.point_screen_pos(pt); draw.AddLine({pos.x(), pos.y()}, {last.x(), last.y()}, line_color, line_thickness); @@ -120,9 +125,9 @@ void path_test::draw_overlay(app& a) last = pos; } - if (!result.res.is_found() && !result.res.path().isEmpty()) + if (!res.is_found() && !res.path().isEmpty()) { - auto pos = a.point_screen_pos(result.res.path().back()); + auto pos = a.point_screen_pos(res.path().back()); constexpr float spacing = 12, size1 = 7, size2 = 3, spacing2 = spacing + size2; draw.AddLine({pos.x() - spacing2, pos.y() - spacing2}, @@ -157,7 +162,7 @@ void path_test::update_pre(app& a, const Ns&) result = { .from = pending.from, .to = pending.to, - .res = move(res), + .res = has_result ? move(res) : Optional<path_search_result>{}, }; } @@ -168,11 +173,13 @@ void path_test::draw_ui(app&, float) constexpr auto colflags_0 = colflags_1 | ImGuiTableColumnFlags_WidthFixed; char buf[128]; - const auto& res = result.res; if (!has_result) return; + fm_assert(result.res); + const auto& res = *result.res; + 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()); diff --git a/editor/tests/walk-test.cpp b/editor/tests/walk-test.cpp index 47cd753d..e3b6f8d5 100644 --- a/editor/tests/walk-test.cpp +++ b/editor/tests/walk-test.cpp @@ -2,6 +2,8 @@ #include "compat/shared-ptr-wrapper.hpp" #include "editor/app.hpp" #include "src/critter.hpp" +#include "src/critter-script.hpp" +#include "src/search-result.hpp" #include "floormat/main.hpp" #include "../imgui-raii.hpp" @@ -11,16 +13,8 @@ using namespace floormat::imgui; namespace { -struct pending_s -{ - point dest; - bool has_value : 1 = false; -}; - struct pf_test final : base_test { - pending_s current; - ~pf_test() noexcept override = default; bool handle_key(app& a, const key_event& e, bool is_down) override; @@ -40,19 +34,25 @@ bool pf_test::handle_key(app& a, const key_event& e, bool is_down) bool pf_test::handle_mouse_click(app& a, const mouse_button_event& e, bool is_down) { + auto& m = a.main(); + if (e.button == mouse_button_left && is_down) { if (auto ptʹ = a.cursor_state().point()) { - current = { - .dest = *ptʹ, - .has_value = true, - }; + + auto C = a.ensure_player_character(m.world()).ptr; + fm_assert(C->is_dynamic()); + auto S = critter_script::make_walk_script(*ptʹ, {}, critter_script::walk_mode::line); + C->script.do_reassign(move(S), move(C)); return true; } } else if (e.button == mouse_button_right && is_down) - current = {}; + { + auto C = a.ensure_player_character(m.world()).ptr; + C->script.do_clear(C); + } return false; } @@ -76,26 +76,8 @@ void pf_test::draw_ui(app& a, float) void pf_test::update_pre(app& a, const Ns& dt) { - if (!current.has_value) - return; - - auto& m = a.main(); - auto& C = *a.ensure_player_character(m.world()).ptr; - fm_assert(C.is_dynamic()); - - if (C.movement.L | C.movement.R | C.movement.U | C.movement.D) [[unlikely]] - { - current.has_value = false; - return; - } - - auto index = C.index(); - critter::move_result result; - - if (current.dest == C.position() || - (void(result = C.move_toward(index, dt, current.dest)), result.blocked) || - result.moved && current.dest == C.position()) - current.has_value = false; + (void)a; + (void)dt; } } // namespace |