diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-03-18 17:09:55 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-03-18 17:09:55 +0100 |
commit | a418f0571231a429b8e0adfea7e09c2f81856a57 (patch) | |
tree | 5625cf5d6c4809ec5e17746068e027a5e5cbe60b | |
parent | 27dd8b268fbe37fa6eed0c0fc0f013134e5e2dc9 (diff) |
finally it works
-rw-r--r-- | editor/app.cpp | 21 | ||||
-rw-r--r-- | editor/imgui-inspect.cpp | 13 | ||||
-rw-r--r-- | src/world.cpp | 8 |
3 files changed, 27 insertions, 15 deletions
diff --git a/editor/app.cpp b/editor/app.cpp index c795d403..63394ded 100644 --- a/editor/app.cpp +++ b/editor/app.cpp @@ -77,15 +77,24 @@ void app::ensure_player_character(world& w) } } -void app::reset_world(struct world&& w) +void app::reset_world(struct world&& w_) { - _popup_target = {}; - _character_id = 0; if (!M) return; - auto& w2 = M->reset_world(std::move(w)); - w2.collect(true); - ensure_player_character(w2); + + _editor.on_release(); + _editor.clear_selection(); + inspectors.clear(); + _pending_popup = false; + _popup_target = {}; + + clear_keys(); + cursor = {}; + _character_id = 0; + + auto& w = M->reset_world(std::move(w_)); + w.collect(true); + ensure_player_character(w); } int app::exec() diff --git a/editor/imgui-inspect.cpp b/editor/imgui-inspect.cpp index 510fcf32..42e7bec5 100644 --- a/editor/imgui-inspect.cpp +++ b/editor/imgui-inspect.cpp @@ -15,7 +15,6 @@ using namespace floormat::imgui; void app::draw_inspector() { auto b = push_id("inspector"); - auto& w = M->world(); constexpr auto max_inspectors = 4; // todo change later to 32 if (auto size = inspectors.size(); size > max_inspectors) @@ -33,7 +32,6 @@ void app::draw_inspector() auto& s = *e; chunk_coords ch = e->coord.chunk(); local_coords pos = e->coord.local(); - auto& c = w[ch]; char buf[32]; snformat(buf, "inspector-{:08x}"_cf, s.id); @@ -42,15 +40,16 @@ void app::draw_inspector() ImGui::SetNextWindowSize({300*dpi[0], 0}); auto name = loader.strip_prefix(s.atlas->name()); snformat(buf, "{} ({}x{} -> {}x{})"_cf, name, ch.x, ch.y, (int)pos.x, (int)pos.y); + bool is_open = true; - if (auto b2 = begin_window(buf, &is_open)) + if (s.type == entity_type::scenery) { - if (s.type == entity_type::scenery) - { - auto& s2 = static_cast<scenery&>(s); + auto& s2 = static_cast<scenery&>(s); + if (auto b2 = begin_window(buf, &is_open)) entities::inspect_type(s2); - } } + else + is_open = false; if (!is_open) inspectors.erase(inspectors.begin() + (int)i); } diff --git a/src/world.cpp b/src/world.cpp index 8743981f..f519a91f 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -9,15 +9,19 @@ world::world(world&& w) noexcept = default; world& world::operator=(world&& w) noexcept { fm_assert(!w._teardown); + fm_assert(!_teardown); if (&w != this) [[likely]] { _last_collection = w._last_collection; _collect_every = w._collect_every; _unique_id = std::move(w._unique_id); - w._unique_id = std::make_shared<char>('D'); + fm_assert(_unique_id); + fm_assert(w._unique_id == nullptr); _last_chunk = {}; _chunks = std::move(w._chunks); _entities = std::move(w._entities); + _entity_counter = w._entity_counter; + w._entity_counter = 0; for (auto& [id, c] : _chunks) c._world = this; @@ -109,7 +113,7 @@ void world::collect(bool force) void world::do_make_entity(const std::shared_ptr<entity>& e, global_coords pos, bool sorted) { fm_assert(e->id > 0); - fm_debug_assert(e->c->world()._unique_id == _unique_id); + fm_debug_assert(_unique_id && e->c->world()._unique_id == _unique_id); fm_assert(!_entities.contains(e->id)); fm_assert(Vector2ui(e->bbox_size).product() > 0); fm_assert(e->type != entity_type::none); |