diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-05-18 15:39:02 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-05-18 15:39:11 +0200 |
commit | 44c8e45d71e5320aedaa5b4b839e636a0d973f7f (patch) | |
tree | 13b9e2896c19cf900202fb376f8b6cd6e3642bba /editor | |
parent | 3eed6f633605c308547c73ddd232c0081842247a (diff) |
editor: fix removing scenery with pixel offset
Diffstat (limited to 'editor')
-rw-r--r-- | editor/scenery-editor.cpp | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/editor/scenery-editor.cpp b/editor/scenery-editor.cpp index 6cfe56bf..b012af8d 100644 --- a/editor/scenery-editor.cpp +++ b/editor/scenery-editor.cpp @@ -3,6 +3,7 @@ #include "loader/loader.hpp" #include "compat/assert.hpp" #include "src/world.hpp" +#include "src/RTree-search.hpp" #include "rotation.inl" namespace floormat { @@ -79,20 +80,33 @@ bool scenery_editor::is_anything_selected() const void scenery_editor::place_tile(world& w, global_coords pos, const scenery_& s) { - auto [c, t] = w[pos]; if (!s) { + auto [c, t] = w[pos]; + // don't regen colliders - const auto px = Vector2(pos.local()) * TILE_SIZE2; 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& e = *es[i]; if (e.type() != entity_type::scenery) continue; - auto center = Vector2(e.coord.local())*TILE_SIZE2 + Vector2(e.offset) + Vector2(e.bbox_offset), - min = center - Vector2(e.bbox_size/2), max = min + Vector2(e.bbox_size); - if (px >= min && px <= max) + using rtree_type = std::decay_t<decltype(*w[chunk_coords_{}].rtree())>; + 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<collision_data>(data); + if (e.id == x.data) + { + do_remove = true; + return false; + } + return true; + }); + if (do_remove) c.remove_entity(i); } } |