while (i_ < capacity_ && !predicate()) {
++i_;
}
+
if (i_ < capacity_ && !unpackers_.empty()) {
Entity::Id id = manager_->create_id(i_);
for (auto &unpacker : unpackers_) {
}
Iterator begin() { return Iterator(manager_, predicates_, unpackers_, 0); }
- Iterator end() { return Iterator(manager_, predicates_, unpackers_, manager_->size()); }
+ Iterator end() { return Iterator(manager_, predicates_, unpackers_, manager_->capacity()); }
const Iterator begin() const { return Iterator(manager_, predicates_, unpackers_, 0); }
- const Iterator end() const { return Iterator(manager_, predicates_, unpackers_, manager_->size()); }
+ const Iterator end() const { return Iterator(manager_, predicates_, unpackers_, manager_->capacity()); }
template <typename A>
View &unpack_to(ptr<A> &a) {
* Author: Alec Thomas <alec@swapoff.org>
*/
+#include <algorithm>
#include <iterator>
#include <string>
#include <utility>
ASSERT_FALSE(a.valid());
ASSERT_FALSE(b.valid());
}
+
+
+TEST_F(EntityManagerTest, TestEntityDestroyHole) {
+ std::vector<Entity> entities;
+
+ auto count = [this]() {
+ auto e = em->entities_with_components<Position>();
+ return std::count_if(e.begin(), e.end(), [] (const Entity &) { return true; });
+ };
+
+ for (int i = 0; i < 5000; i++) {
+ auto e = em->create();
+ e.assign<Position>();
+ entities.push_back(e);
+ }
+
+ ASSERT_EQ(count(), 5000);
+
+ entities[2500].destroy();
+
+ ASSERT_EQ(count(), 4999);
+}