fix batch creation (close #305)
This commit is contained in:
@@ -606,7 +606,8 @@ public:
|
||||
});
|
||||
|
||||
if constexpr(sizeof...(Component) > 0) {
|
||||
return std::make_tuple(assure<Component>()->batch(*this, first, last)...);
|
||||
// the reverse iterators guarantee the ordering between entities and components (hint: the pools return begin())
|
||||
return std::make_tuple(assure<Component>()->batch(*this, std::make_reverse_iterator(last), std::make_reverse_iterator(first))...);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -419,7 +419,7 @@ public:
|
||||
*/
|
||||
template<typename It>
|
||||
void batch(It first, It last) {
|
||||
std::for_each(std::make_reverse_iterator(last), std::make_reverse_iterator(first), [this, next = direct.size()](const auto entt) mutable {
|
||||
std::for_each(first, last, [this, next = direct.size()](const auto entt) mutable {
|
||||
ENTT_ASSERT(!has(entt));
|
||||
auto [page, offset] = map(entt);
|
||||
assure(page);
|
||||
|
||||
@@ -135,9 +135,13 @@ TEST(SparseSet, BatchAdd) {
|
||||
ASSERT_FALSE(set.empty());
|
||||
ASSERT_EQ(set.size(), 4u);
|
||||
ASSERT_EQ(set.index(entt::entity{12}), 0u);
|
||||
ASSERT_EQ(set.index(entities[0]), 2u);
|
||||
ASSERT_EQ(set.index(entities[1]), 1u);
|
||||
ASSERT_EQ(set.index(entities[0]), 1u);
|
||||
ASSERT_EQ(set.index(entities[1]), 2u);
|
||||
ASSERT_EQ(set.index(entt::entity{24}), 3u);
|
||||
ASSERT_EQ(set.data()[set.index(entt::entity{12})], entt::entity{12});
|
||||
ASSERT_EQ(set.data()[set.index(entities[0])], entities[0]);
|
||||
ASSERT_EQ(set.data()[set.index(entities[1])], entities[1]);
|
||||
ASSERT_EQ(set.data()[set.index(entt::entity{24})], entt::entity{24});
|
||||
}
|
||||
|
||||
TEST(SparseSet, Iterator) {
|
||||
|
||||
@@ -113,8 +113,8 @@ TEST(Storage, BatchAdd) {
|
||||
it[0] = 1;
|
||||
it[1] = 2;
|
||||
|
||||
ASSERT_EQ(pool.get(entities[0]), 1);
|
||||
ASSERT_EQ(pool.get(entities[1]), 2);
|
||||
ASSERT_EQ(pool.get(entities[0]), 2);
|
||||
ASSERT_EQ(pool.get(entities[1]), 1);
|
||||
}
|
||||
|
||||
TEST(Storage, BatchAddByCopy) {
|
||||
@@ -136,8 +136,8 @@ TEST(Storage, BatchAddByCopy) {
|
||||
it[0] = 1;
|
||||
it[1] = 2;
|
||||
|
||||
ASSERT_EQ(pool.get(entities[0]), 1);
|
||||
ASSERT_EQ(pool.get(entities[1]), 2);
|
||||
ASSERT_EQ(pool.get(entities[0]), 2);
|
||||
ASSERT_EQ(pool.get(entities[1]), 1);
|
||||
}
|
||||
|
||||
TEST(Storage, BatchAddEmptyType) {
|
||||
|
||||
Reference in New Issue
Block a user