summaryrefslogtreecommitdiffhomepage
path: root/editor
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-03-19 16:18:13 +0100
committerStanislaw Halik <sthalik@misaki.pl>2023-03-19 16:18:13 +0100
commit86bd6a4411badecfc76fe3a9d29b4aa30c8fdba7 (patch)
tree468c23d67bab654f98126c1fa7ab58e9043b3f6a /editor
parentf1da751349fb52a8a88b10bc3289288a4fcd2396 (diff)
work on entity reodering
Diffstat (limited to 'editor')
-rw-r--r--editor/imgui-inspect.cpp8
-rw-r--r--editor/imgui.cpp8
-rw-r--r--editor/update.cpp27
3 files changed, 37 insertions, 6 deletions
diff --git a/editor/imgui-inspect.cpp b/editor/imgui-inspect.cpp
index 7ef24913..d95bc441 100644
--- a/editor/imgui-inspect.cpp
+++ b/editor/imgui-inspect.cpp
@@ -21,6 +21,7 @@ void app::draw_inspector()
{
auto end = inspectors.begin() + (ptrdiff_t)size - max_inspectors;
inspectors.erase(inspectors.begin(), end);
+ fm_assert(inspectors.size() <= max_inspectors);
}
const auto dpi = M->dpi_scale();
@@ -46,7 +47,12 @@ void app::draw_inspector()
{
auto& s2 = static_cast<scenery&>(s);
if (auto b2 = begin_window(buf, &is_open))
- entities::inspect_type(s2);
+ {
+ auto idx = s.index();
+ bool ret = entities::inspect_type(s2);
+ if (ret)
+ e->reposition(idx);
+ }
}
else
is_open = false;
diff --git a/editor/imgui.cpp b/editor/imgui.cpp
index 9700a8f7..696460a7 100644
--- a/editor/imgui.cpp
+++ b/editor/imgui.cpp
@@ -164,13 +164,17 @@ void app::do_popup_menu()
void app::kill_popups(bool hard)
{
+ const bool imgui = _imgui.context() != nullptr;
+
_popup_target = {};
- ImGui::CloseCurrentPopup();
+ if (imgui)
+ ImGui::CloseCurrentPopup();
if (hard)
inspectors.clear();
- ImGui::FocusWindow(nullptr);
+ if (imgui)
+ ImGui::FocusWindow(nullptr);
}
} // namespace floormat
diff --git a/editor/update.cpp b/editor/update.cpp
index 2393c6ce..15ffe89e 100644
--- a/editor/update.cpp
+++ b/editor/update.cpp
@@ -6,6 +6,7 @@
#include "floormat/events.hpp"
#include "floormat/main.hpp"
#include "character.hpp"
+#include <cmath>
namespace floormat {
@@ -107,8 +108,10 @@ void app::do_rotate(bool backward)
else if (auto* cl = find_clickable_scenery(*cursor.pixel))
{
auto& e = *cl->e;
+ auto i = e.index();
auto r = backward ? e.atlas->prev_rotation_from(e.r) : e.atlas->next_rotation_from(e.r);
- e.rotate(e.index(), r);
+ e.rotate(i, r);
+ e.reposition(i);
}
}
}
@@ -176,6 +179,7 @@ void app::apply_commands(const key_set& keys)
void app::update_world(float dt)
{
auto& world = M->world();
+ const auto curframe = world.increment_frame_no();
auto [minx, maxx, miny, maxy] = M->get_draw_bounds();
minx--; miny--; maxx++; maxy++;
for (int16_t y = miny; y <= maxy; y++)
@@ -184,10 +188,27 @@ void app::update_world(float dt)
auto& c = world[chunk_coords{x, y}];
const auto& es = c.entities();
const auto size = es.size();
- for (auto i = size-1; i != (size_t)-1; i--)
+
+start: for (auto i = size-1; i != (size_t)-1; i--)
{
auto& e = *es[i];
- e.update(i, dt);
+ fm_debug_assert(!(e.last_update > curframe));
+ if (curframe > e.last_update) [[likely]]
+ {
+ auto off = e.ordinal_offset({});
+ e.last_update = curframe;
+ auto status = e.update(i, dt);
+ if (status == entity_update_status::updated_repositioning)
+ {
+ //Debug{} << "reposition after update" << e.ordinal_offset({}) << off;
+ e.reposition(i);
+ }
+ if (status >= entity_update_status::updated_repositioned)
+ {
+ //Debug{} << "goto start";
+ goto start;
+ }
+ }
}
}
}