summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--editor/app.hpp2
-rw-r--r--editor/imgui-inspect.cpp26
-rw-r--r--editor/imgui.cpp24
-rw-r--r--editor/update.cpp2
-rw-r--r--src/world.hpp4
5 files changed, 34 insertions, 24 deletions
diff --git a/editor/app.hpp b/editor/app.hpp
index a4d7c440..ac3abdb3 100644
--- a/editor/app.hpp
+++ b/editor/app.hpp
@@ -45,7 +45,7 @@ enum class popup_target_type : unsigned char {
};
struct popup_target final {
- entity* e;
+ object_id id;
popup_target_type target = popup_target_type::none;
bool operator==(const popup_target&) const;
};
diff --git a/editor/imgui-inspect.cpp b/editor/imgui-inspect.cpp
index cb5b9ce7..a1adbba3 100644
--- a/editor/imgui-inspect.cpp
+++ b/editor/imgui-inspect.cpp
@@ -25,31 +25,37 @@ void app::draw_inspector()
}
const auto dpi = M->dpi_scale();
+ auto& w = M->world();
for (auto i = inspectors.size()-1; i != -1uz; i--)
{
- auto [e, target] = inspectors[i];
- fm_debug_assert(e);
- auto& s = *e;
- chunk_coords ch = e->coord.chunk();
- local_coords pos = e->coord.local();
- auto z = e->coord.z();
+ auto [id, target] = inspectors[i];
+ auto e_ = w.find_entity(id);
+ if (!e_)
+ {
+ inspectors.erase(inspectors.begin() + ptrdiff_t(i));
+ continue;
+ }
+ auto& e = *e_;
+ chunk_coords ch = e.coord.chunk();
+ local_coords pos = e.coord.local();
+ auto z = e.coord.z();
char buf[32];
- snformat(buf, "inspector-{:08x}"_cf, s.id);
+ snformat(buf, "inspector-{:08x}"_cf, e.id);
auto b1 = push_id(buf);
ImGui::SetNextWindowSize({300*dpi[0], 0});
- auto name = loader.strip_prefix(s.atlas->name());
+ auto name = loader.strip_prefix(e.atlas->name());
if (z == 0)
snformat(buf, "{} ({}x{} -> {}x{})"_cf, name, ch.x, ch.y, (int)pos.x, (int)pos.y);
else
snformat(buf, "{} ({}x{}:{} -> {}x{})"_cf, name, ch.x, ch.y, (int)z, (int)pos.x, (int)pos.y);
bool is_open = true;
- if (s.type() == entity_type::scenery)
+ if (e.type() == entity_type::scenery)
{
- auto& s2 = static_cast<scenery&>(s);
+ auto& s2 = static_cast<scenery&>(e);
if (auto b2 = begin_window(buf, &is_open))
{
bool ret = entities::inspect_type(s2);
diff --git a/editor/imgui.cpp b/editor/imgui.cpp
index 32b85cb8..2396f1bb 100644
--- a/editor/imgui.cpp
+++ b/editor/imgui.cpp
@@ -147,21 +147,25 @@ bool app::check_inspector_exists(const popup_target& p)
void app::do_popup_menu()
{
- const auto [sc, target] = _popup_target;
- if (target == popup_target_type::none || sc == nullptr)
+ const auto [id, target] = _popup_target;
+ auto& w = M->world();
+ auto e_ = w.find_entity(id);
+
+ if (target == popup_target_type::none || !e_)
{
_popup_target = {};
_pending_popup = {};
return;
}
+ auto& e = *e_;
+
auto b0 = push_id(SCENERY_POPUP_NAME);
//if (_popup_target.target != popup_target_type::scenery) {...}
if (_pending_popup)
{
_pending_popup = false;
- fm_assert(target != popup_target_type::none && sc != nullptr);
//if (type != popup_target_type::scenery) {...}
ImGui::OpenPopup(SCENERY_POPUP_NAME.data());
}
@@ -169,18 +173,18 @@ void app::do_popup_menu()
if (auto b1 = begin_popup(SCENERY_POPUP_NAME))
{
ImGui::SeparatorText("Setup");
- const auto i = sc->index();
- if (ImGui::MenuItem("Activate", nullptr, false, sc->can_activate(i)))
- sc->activate(i);
+ const auto i = e.index();
+ if (ImGui::MenuItem("Activate", nullptr, false, e.can_activate(i)))
+ e.activate(i);
if (bool b_ins = !check_inspector_exists(_popup_target);
ImGui::MenuItem("Inspect", nullptr, !b_ins, b_ins))
inspectors.push_back(std::exchange(_popup_target, {}));
ImGui::SeparatorText("Modify");
- if (auto next_rot = sc->atlas->next_rotation_from(sc->r);
- ImGui::MenuItem("Rotate", nullptr, false, next_rot != sc->r && sc->can_rotate(next_rot)))
- sc->rotate(i, next_rot);
+ if (auto next_rot = e.atlas->next_rotation_from(e.r);
+ ImGui::MenuItem("Rotate", nullptr, false, next_rot != e.r && e.can_rotate(next_rot)))
+ e.rotate(i, next_rot);
if (ImGui::MenuItem("Delete", nullptr, false))
- sc->chunk().remove_entity(sc->index());
+ e.chunk().remove_entity(e.index());
}
}
diff --git a/editor/update.cpp b/editor/update.cpp
index 18cab4f7..63cc7a3c 100644
--- a/editor/update.cpp
+++ b/editor/update.cpp
@@ -75,7 +75,7 @@ void app::do_mouse_up_down(uint8_t button, bool is_down, int mods)
if (auto* cl = find_clickable_scenery(*cursor.pixel))
{
_pending_popup = true;
- _popup_target = { .e = cl->e, .target = popup_target_type::scenery, };
+ _popup_target = { .id = cl->e->id, .target = popup_target_type::scenery, };
}
break;
case editor_mode::floor:
diff --git a/src/world.hpp b/src/world.hpp
index e6ec4f5b..8148bfd5 100644
--- a/src/world.hpp
+++ b/src/world.hpp
@@ -82,7 +82,7 @@ public:
return ret;
}
- template<typename T = entity> std::shared_ptr<T> find_entity(object_id id);
+ template<typename T = entity> std::shared_ptr<T> find_entity(object_id id);
bool is_teardown() const { return _teardown; }
object_id entity_counter() const { return _entity_counter; }
@@ -98,7 +98,7 @@ public:
template<typename T>
std::shared_ptr<T> world::find_entity(object_id id)
{
- static_assert(std::is_base_of_v<entity, T>);
+ static_assert(std::is_same_v<entity, T> || std::is_base_of_v<entity, T>);
// make it a dependent name so that including "src/entity.hpp" isn't needed
using U = std::conditional_t<std::is_same_v<T, entity>, T, entity>;
if (std::shared_ptr<U> ptr = find_entity_(id); !ptr)