diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2023-03-20 06:29:31 +0100 |
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-03-20 07:54:17 +0100 |
| commit | 1c13313ec845d43077bd7e78538358ca4e007f8a (patch) | |
| tree | 95923091df12f95bae5049d88037c9c8ff39f07f /src/chunk.cpp | |
| parent | 38a87664deaedacf0aa8e97d9b0aa46dfb6c8ae6 (diff) | |
sort entities by id rather than draw order
Diffstat (limited to 'src/chunk.cpp')
| -rw-r--r-- | src/chunk.cpp | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/chunk.cpp b/src/chunk.cpp index d660d2c8..2c65ccae 100644 --- a/src/chunk.cpp +++ b/src/chunk.cpp @@ -8,7 +8,9 @@ namespace floormat { namespace { -size_t _reload_no_ = 0; +constexpr auto entity_id_lessp = [](const auto& a, const auto& b) { return a->id < b->id; }; + +size_t _reload_no_ = 0; // NOLINT bool is_log_quiet() { @@ -123,7 +125,7 @@ void chunk::sort_entities() mark_scenery_modified(); std::sort(_entities.begin(), _entities.end(), [](const auto& a, const auto& b) { - return a->ordinal() < b->ordinal(); + return a->id < b->id; }); } @@ -134,25 +136,23 @@ void chunk::add_entity(const std::shared_ptr<entity>& e) mark_scenery_modified(); if (bbox bb; _bbox_for_scenery(*e, bb)) _add_bbox(bb); - - _entities.reserve(_entities.size() + 1); - auto it = std::lower_bound(_entities.cbegin(), _entities.cend(), e, [ord = e->ordinal()](const auto& a, const auto&) { - return a->ordinal() < ord; - }); + auto& es = _entities; + es.reserve(es.size() + 1); + auto it = std::lower_bound(es.cbegin(), es.cend(), e, entity_id_lessp); _entities.insert(it, e); } void chunk::remove_entity(size_t i) { fm_assert(_entities_sorted); - fm_debug_assert(i < _entities.size()); - const auto& e = _entities[i]; + auto& es = _entities; + fm_debug_assert(i < es.size()); + const auto& e = es[i]; if (!e->is_dynamic()) mark_scenery_modified(); if (bbox bb; _bbox_for_scenery(*e, bb)) _remove_bbox(bb); - - _entities.erase(_entities.cbegin() + ptrdiff_t(i)); + es.erase(es.cbegin() + ptrdiff_t(i)); } const std::vector<std::shared_ptr<entity>>& chunk::entities() const |
