From a5acc700d6a3a9b050864cf78a0f9f2305babdff Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 15 Jan 2024 13:46:16 +0100 Subject: b --- src/chunk.cpp | 17 +++++++++-------- src/chunk.hpp | 5 +++-- src/object.cpp | 3 ++- src/object.hpp | 1 - src/world.cpp | 3 ++- 5 files changed, 16 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/chunk.cpp b/src/chunk.cpp index ad24b92f..a819de6c 100644 --- a/src/chunk.cpp +++ b/src/chunk.cpp @@ -3,6 +3,7 @@ #include "world.hpp" #include "tile-iterator.hpp" #include +#include #include namespace floormat { @@ -27,11 +28,11 @@ bool chunk::empty(bool force) const noexcept if (!force && !_maybe_empty) [[likely]] return false; for (auto i = 0uz; i < TILE_COUNT; i++) - if (!_objects.empty() || + if (!_objects.isEmpty() || _ground && _ground->atlases[i] || _walls && (_walls->atlases[i*2+0] || _walls->atlases[i*2+1])) return _maybe_empty = false; - if (!_objects.empty()) + if (!_objects.isEmpty()) return false; return true; } @@ -126,7 +127,8 @@ chunk::chunk(class world& w, chunk_coords_ ch) noexcept : _world{&w}, _coord{ch} chunk::~chunk() noexcept { _teardown = true; - _objects.clear(); + arrayResize(_objects, 0); + arrayShrink(_objects); _rtree.RemoveAll(); } @@ -142,7 +144,7 @@ void chunk::add_object_unsorted(const std::shared_ptr& e) mark_scenery_modified(); if (bbox bb; _bbox_for_scenery(*e, bb)) _add_bbox(bb); - _objects.push_back(e); + arrayAppend(_objects, e); } void chunk::sort_objects() @@ -166,9 +168,8 @@ void chunk::add_object(const std::shared_ptr& e) if (bbox bb; _bbox_for_scenery(*e, bb)) _add_bbox(bb); auto& es = _objects; - es.reserve(es.size() + 1); auto it = std::lower_bound(es.cbegin(), es.cend(), e, object_id_lessp); - _objects.insert(it, e); + arrayInsert(es, (size_t)std::distance(es.cbegin(), it), e); } void chunk::remove_object(size_t i) @@ -181,10 +182,10 @@ void chunk::remove_object(size_t i) mark_scenery_modified(); if (bbox bb; _bbox_for_scenery(*e, bb)) _remove_bbox(bb); - es.erase(es.cbegin() + ptrdiff_t(i)); + arrayRemove(es, i); } -const std::vector>& chunk::objects() const +ArrayView> chunk::objects() const { fm_assert(_objects_sorted); return _objects; diff --git a/src/chunk.hpp b/src/chunk.hpp index ff0f589e..56afb6a5 100644 --- a/src/chunk.hpp +++ b/src/chunk.hpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -123,7 +124,7 @@ struct chunk final void add_object_unsorted(const std::shared_ptr& e); void sort_objects(); void remove_object(size_t i); - const std::vector>& objects() const; + ArrayView> objects() const; // for drawing only static constexpr size_t max_wall_quad_count = @@ -146,7 +147,7 @@ private: Pointer _ground; Pointer _walls; - std::vector> _objects; + Array> _objects; class world* _world; GL::Mesh ground_mesh{NoCreate}, wall_mesh{NoCreate}, scenery_mesh{NoCreate}; RTree _rtree; diff --git a/src/object.cpp b/src/object.cpp index 9d5aec5a..0139362c 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -7,6 +7,7 @@ #include "shaders/shader.hpp" #include #include +#include #include #include #include @@ -257,7 +258,7 @@ void object::move_to(size_t& i, Vector2i delta, rotation new_r) const_cast(r) = new_r; const_cast(c) = &c2; i = (size_t)std::distance(es.cbegin(), it); - es.insert(it, std::move(e_)); + arrayInsert(es, i, std::move(e_)); } } diff --git a/src/object.hpp b/src/object.hpp index cfa406d6..ca5a425d 100644 --- a/src/object.hpp +++ b/src/object.hpp @@ -7,7 +7,6 @@ #include "src/object-id.hpp" #include "src/point.hpp" #include -#include namespace floormat { diff --git a/src/world.cpp b/src/world.cpp index 7920c205..e057ffe7 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -3,6 +3,7 @@ #include "object.hpp" #include "compat/int-hash.hpp" #include "compat/exception.hpp" +#include using namespace floormat; @@ -65,7 +66,7 @@ world::~world() noexcept v.mark_scenery_modified(); v.mark_passability_modified(); _last_chunk = {}; - v._objects.clear(); + arrayResize(v._objects, 0); } _last_chunk = {}; _chunks.clear(); -- cgit v1.2.3