33#include " world.hpp"
44#include " tile-iterator.hpp"
55#include < algorithm>
6+ #include < Corrade/Containers/GrowableArray.h>
67#include < Magnum/GL/Context.h>
78
89namespace floormat {
@@ -27,11 +28,11 @@ bool chunk::empty(bool force) const noexcept
2728 if (!force && !_maybe_empty) [[likely]]
2829 return false ;
2930 for (auto i = 0uz; i < TILE_COUNT; i++)
30- if (!_objects.empty () ||
31+ if (!_objects.isEmpty () ||
3132 _ground && _ground->atlases [i] ||
3233 _walls && (_walls->atlases [i*2 +0 ] || _walls->atlases [i*2 +1 ]))
3334 return _maybe_empty = false ;
34- if (!_objects.empty ())
35+ if (!_objects.isEmpty ())
3536 return false ;
3637 return true ;
3738}
@@ -126,7 +127,8 @@ chunk::chunk(class world& w, chunk_coords_ ch) noexcept : _world{&w}, _coord{ch}
126127chunk::~chunk () noexcept
127128{
128129 _teardown = true ;
129- _objects.clear ();
130+ arrayResize (_objects, 0 );
131+ arrayShrink (_objects);
130132 _rtree.RemoveAll ();
131133}
132134
@@ -142,7 +144,7 @@ void chunk::add_object_unsorted(const std::shared_ptr<object>& e)
142144 mark_scenery_modified ();
143145 if (bbox bb; _bbox_for_scenery (*e, bb))
144146 _add_bbox (bb);
145- _objects. push_back ( e);
147+ arrayAppend (_objects, e);
146148}
147149
148150void chunk::sort_objects ()
@@ -166,9 +168,8 @@ void chunk::add_object(const std::shared_ptr<object>& e)
166168 if (bbox bb; _bbox_for_scenery (*e, bb))
167169 _add_bbox (bb);
168170 auto & es = _objects;
169- es.reserve (es.size () + 1 );
170171 auto it = std::lower_bound (es.cbegin (), es.cend (), e, object_id_lessp);
171- _objects. insert (it , e);
172+ arrayInsert (es, ( size_t ) std::distance (es. cbegin (), it) , e);
172173}
173174
174175void chunk::remove_object (size_t i)
@@ -181,10 +182,10 @@ void chunk::remove_object(size_t i)
181182 mark_scenery_modified ();
182183 if (bbox bb; _bbox_for_scenery (*e, bb))
183184 _remove_bbox (bb);
184- es. erase (es. cbegin () + ptrdiff_t (i) );
185+ arrayRemove (es, i );
185186}
186187
187- const std::vector<std:: shared_ptr<object>>& chunk::objects () const
188+ ArrayView< const std::shared_ptr<object>> chunk::objects () const
188189{
189190 fm_assert (_objects_sorted);
190191 return _objects;
0 commit comments