summaryrefslogtreecommitdiffhomepage
path: root/src/chunk.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-01-15 13:46:16 +0100
committerStanislaw Halik <sthalik@misaki.pl>2024-01-15 13:46:16 +0100
commita5acc700d6a3a9b050864cf78a0f9f2305babdff (patch)
treeed3c0a02b51e19b14f92535b9640673cae84f8ac /src/chunk.cpp
parente850be48828ce9cf4767b88707495257c98e88b0 (diff)
b
Diffstat (limited to 'src/chunk.cpp')
-rw-r--r--src/chunk.cpp17
1 files changed, 9 insertions, 8 deletions
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 <algorithm>
+#include <Corrade/Containers/GrowableArray.h>
#include <Magnum/GL/Context.h>
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<object>& 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<object>& 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<std::shared_ptr<object>>& chunk::objects() const
+ArrayView<const std::shared_ptr<object>> chunk::objects() const
{
fm_assert(_objects_sorted);
return _objects;