summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/chunk.cpp17
-rw-r--r--src/chunk.hpp5
-rw-r--r--src/object.cpp3
-rw-r--r--src/object.hpp1
-rw-r--r--src/world.cpp3
5 files changed, 16 insertions, 13 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;
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 <type_traits>
#include <array>
#include <vector>
+#include <Corrade/Containers/Array.h>
#include <Corrade/Containers/Pointer.h>
#include <Magnum/GL/Mesh.h>
@@ -123,7 +124,7 @@ struct chunk final
void add_object_unsorted(const std::shared_ptr<object>& e);
void sort_objects();
void remove_object(size_t i);
- const std::vector<std::shared_ptr<object>>& objects() const;
+ ArrayView<const std::shared_ptr<object>> objects() const;
// for drawing only
static constexpr size_t max_wall_quad_count =
@@ -146,7 +147,7 @@ private:
Pointer<ground_stuff> _ground;
Pointer<wall_stuff> _walls;
- std::vector<std::shared_ptr<object>> _objects;
+ Array<std::shared_ptr<object>> _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 <cmath>
#include <algorithm>
+#include <Corrade/Containers/GrowableArray.h>
#include <Corrade/Containers/StructuredBindings.h>
#include <Corrade/Containers/Pair.h>
#include <Magnum/Math/Functions.h>
@@ -257,7 +258,7 @@ void object::move_to(size_t& i, Vector2i delta, rotation new_r)
const_cast<rotation&>(r) = new_r;
const_cast<struct chunk*&>(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 <memory>
-#include <vector>
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 <Corrade/Containers/GrowableArray.h>
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();