From f5a7dc9d264c4231d9f688704ceef6971bddf272 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 18 May 2023 18:32:39 +0200 Subject: editor: fix removing scenery --- editor/scenery-editor.cpp | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) (limited to 'editor/scenery-editor.cpp') diff --git a/editor/scenery-editor.cpp b/editor/scenery-editor.cpp index b012af8d..66ff94bb 100644 --- a/editor/scenery-editor.cpp +++ b/editor/scenery-editor.cpp @@ -5,6 +5,8 @@ #include "src/world.hpp" #include "src/RTree-search.hpp" #include "rotation.inl" +#include "app.hpp" +#include namespace floormat { @@ -78,36 +80,23 @@ bool scenery_editor::is_anything_selected() const return _selected.proto.atlas != nullptr; } -void scenery_editor::place_tile(world& w, global_coords pos, const scenery_& s) +void scenery_editor::place_tile(world& w, global_coords pos, const scenery_& s, app& a) { if (!s) { auto [c, t] = w[pos]; - - // don't regen colliders - const auto es = c.entities(); - constexpr auto half_tile = TILE_SIZE2/2; - auto center = Vector2(pos.local())*TILE_SIZE2, - min = center - half_tile, max = min + half_tile; - for (auto i = es.size()-1; i != (size_t)-1; i--) + const auto& es = c.entities(); +start: while (auto id = a.object_at_cursor()) { - const auto& e = *es[i]; - if (e.type() != entity_type::scenery) - continue; - using rtree_type = std::decay_t; - using rect_type = typename rtree_type::Rect; - bool do_remove = false; - c.rtree()->Search(min.data(), max.data(), [&](uint64_t data, const rect_type&) { - [[maybe_unused]] auto x = std::bit_cast(data); - if (e.id == x.data) + for (auto i = es.size()-1; i != (size_t)-1; i--) + { + if (es[i]->id == id) { - do_remove = true; - return false; + c.remove_entity(i); + goto start; } - return true; - }); - if (do_remove) - c.remove_entity(i); + } + break; } } else -- cgit v1.2.3