summaryrefslogtreecommitdiffhomepage
path: root/editor
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-05-06 03:22:09 +0200
committerStanislaw Halik <sthalik@misaki.pl>2024-05-06 03:22:09 +0200
commitf18be9b4686fa11f6fd3caf67396894e38a65d3a (patch)
treec5f108bcf3c8189afc02d6b45bd55076c12b300d /editor
parent518e8cd4cc14bf04dd08f2f8db793430fea175fd (diff)
bad
Diffstat (limited to 'editor')
-rw-r--r--editor/tests/path-test.cpp19
-rw-r--r--editor/tests/walk-test.cpp48
-rw-r--r--editor/update.cpp10
3 files changed, 35 insertions, 42 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
diff --git a/editor/update.cpp b/editor/update.cpp
index 4d1cb3ad..ce9fa874 100644
--- a/editor/update.cpp
+++ b/editor/update.cpp
@@ -239,9 +239,10 @@ void app::update_world(Ns dt)
continue;
auto& c = *cʹ;
const auto& es = c.objects();
- auto size = (uint32_t)es.size();
+start: auto size = (uint32_t)es.size();
for (auto i = 0u; i < size; i++)
{
+ Debug{} << "world::update start";
auto eʹ = es[i];
auto index = size_t{i};
auto& e = *eʹ;
@@ -251,9 +252,12 @@ void app::update_world(Ns dt)
e.update(eʹ, index, dt); // objects can't delete themselves during update()
if (&e.chunk() != cʹ || index > i) [[unlikely]]
{
- i--;
- size = (uint32_t)es.size();
+ Debug{} << "changed" << c.coord() << "to" << e.chunk().coord();
+ goto start;
}
+ else
+ Debug{} << "unchanged";
+ Debug{} << "world::update end";
}
}