Skip to content

Commit a5acc70

Browse files
committed
b
1 parent e850be4 commit a5acc70

File tree

5 files changed

+16
-13
lines changed

5 files changed

+16
-13
lines changed

src/chunk.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
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

89
namespace 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}
126127
chunk::~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

148150
void 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

174175
void 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;

src/chunk.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <type_traits>
99
#include <array>
1010
#include <vector>
11+
#include <Corrade/Containers/Array.h>
1112
#include <Corrade/Containers/Pointer.h>
1213
#include <Magnum/GL/Mesh.h>
1314

@@ -123,7 +124,7 @@ struct chunk final
123124
void add_object_unsorted(const std::shared_ptr<object>& e);
124125
void sort_objects();
125126
void remove_object(size_t i);
126-
const std::vector<std::shared_ptr<object>>& objects() const;
127+
ArrayView<const std::shared_ptr<object>> objects() const;
127128

128129
// for drawing only
129130
static constexpr size_t max_wall_quad_count =
@@ -146,7 +147,7 @@ struct chunk final
146147

147148
Pointer<ground_stuff> _ground;
148149
Pointer<wall_stuff> _walls;
149-
std::vector<std::shared_ptr<object>> _objects;
150+
Array<std::shared_ptr<object>> _objects;
150151
class world* _world;
151152
GL::Mesh ground_mesh{NoCreate}, wall_mesh{NoCreate}, scenery_mesh{NoCreate};
152153
RTree _rtree;

src/object.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "shaders/shader.hpp"
88
#include <cmath>
99
#include <algorithm>
10+
#include <Corrade/Containers/GrowableArray.h>
1011
#include <Corrade/Containers/StructuredBindings.h>
1112
#include <Corrade/Containers/Pair.h>
1213
#include <Magnum/Math/Functions.h>
@@ -257,7 +258,7 @@ void object::move_to(size_t& i, Vector2i delta, rotation new_r)
257258
const_cast<rotation&>(r) = new_r;
258259
const_cast<struct chunk*&>(c) = &c2;
259260
i = (size_t)std::distance(es.cbegin(), it);
260-
es.insert(it, std::move(e_));
261+
arrayInsert(es, i, std::move(e_));
261262
}
262263
}
263264

src/object.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "src/object-id.hpp"
88
#include "src/point.hpp"
99
#include <memory>
10-
#include <vector>
1110

1211
namespace floormat {
1312

src/world.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "object.hpp"
44
#include "compat/int-hash.hpp"
55
#include "compat/exception.hpp"
6+
#include <Corrade/Containers/GrowableArray.h>
67

78
using namespace floormat;
89

@@ -65,7 +66,7 @@ world::~world() noexcept
6566
v.mark_scenery_modified();
6667
v.mark_passability_modified();
6768
_last_chunk = {};
68-
v._objects.clear();
69+
arrayResize(v._objects, 0);
6970
}
7071
_last_chunk = {};
7172
_chunks.clear();

0 commit comments

Comments
 (0)