storage/registry: batch add no longer returns an iterator
This commit is contained in:
@@ -74,11 +74,13 @@ class basic_registry {
|
||||
}
|
||||
|
||||
template<typename It>
|
||||
std::enable_if_t<std::is_same_v<typename std::iterator_traits<It>::value_type, Entity>, typename storage<Entity, Component>::reverse_iterator_type>
|
||||
std::enable_if_t<std::is_same_v<typename std::iterator_traits<It>::value_type, Entity>, void>
|
||||
assign(basic_registry &owner, It first, It last) {
|
||||
auto it = this->construct(first, last);
|
||||
std::for_each(first, last, [this, &owner](const auto entt) { construction.publish(entt, owner); });
|
||||
return it;
|
||||
this->construct(first, last);
|
||||
|
||||
if(!construction.empty()) {
|
||||
std::for_each(first, last, [this, &owner](const auto entt) { construction.publish(entt, owner); });
|
||||
}
|
||||
}
|
||||
|
||||
void remove(basic_registry &owner, const Entity entt) {
|
||||
@@ -641,13 +643,12 @@ public:
|
||||
* @tparam It Type of input iterator.
|
||||
* @param first An iterator to the first element of the range of entities.
|
||||
* @param last An iterator past the last element of the range of entities.
|
||||
* @return An iterator to the list of components just created.
|
||||
*/
|
||||
template<typename Component, typename It>
|
||||
std::enable_if_t<std::is_same_v<typename std::iterator_traits<It>::value_type, entity_type>, typename pool_handler<Component>::reverse_iterator_type>
|
||||
std::enable_if_t<std::is_same_v<typename std::iterator_traits<It>::value_type, entity_type>, void>
|
||||
assign(It first, It last) {
|
||||
ENTT_ASSERT(std::all_of(first, last, [this](const auto entity) { return valid(entity); }));
|
||||
return assure<Component>().assign(*this, first, last);
|
||||
assure<Component>().assign(*this, first, last);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -164,8 +164,6 @@ public:
|
||||
using iterator_type = iterator<false>;
|
||||
/*! @brief Constant random access iterator type. */
|
||||
using const_iterator_type = iterator<true>;
|
||||
/*! @brief Reverse iterator type. */
|
||||
using reverse_iterator_type = std::reverse_iterator<iterator<false>>;
|
||||
|
||||
/**
|
||||
* @brief Increases the capacity of a storage.
|
||||
@@ -345,16 +343,13 @@ public:
|
||||
* @tparam It Type of forward iterator.
|
||||
* @param first An iterator to the first element of the range of entities.
|
||||
* @param last An iterator past the last element of the range of entities.
|
||||
* @return An iterator to the list of instances just created and sorted the
|
||||
* same of the entities.
|
||||
*/
|
||||
template<typename It>
|
||||
std::enable_if_t<std::is_same_v<typename std::iterator_traits<It>::value_type, entity_type>, reverse_iterator_type>
|
||||
std::enable_if_t<std::is_same_v<typename std::iterator_traits<It>::value_type, entity_type>, void>
|
||||
construct(It first, It last) {
|
||||
instances.insert(instances.end(), std::distance(first, last), object_type{});
|
||||
instances.resize(instances.size() + std::distance(first, last), object_type{});
|
||||
// entity goes after component in case constructor throws
|
||||
underlying_type::construct(first, last);
|
||||
return std::make_reverse_iterator(begin() + std::distance(first, last));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -581,8 +576,6 @@ public:
|
||||
using size_type = std::size_t;
|
||||
/*! @brief Random access iterator type. */
|
||||
using iterator_type = iterator;
|
||||
/*! @brief Reverse iterator type. */
|
||||
using reverse_iterator_type = std::reverse_iterator<iterator>;
|
||||
|
||||
/**
|
||||
* @brief Returns an iterator to the beginning.
|
||||
@@ -679,14 +672,11 @@ public:
|
||||
* @tparam It Type of forward iterator.
|
||||
* @param first An iterator to the first element of the range of entities.
|
||||
* @param last An iterator past the last element of the range of entities.
|
||||
* @return An iterator to the list of instances just created and sorted the
|
||||
* same of the entities.
|
||||
*/
|
||||
template<typename It>
|
||||
std::enable_if_t<std::is_same_v<typename std::iterator_traits<It>::value_type, entity_type>, reverse_iterator_type>
|
||||
std::enable_if_t<std::is_same_v<typename std::iterator_traits<It>::value_type, entity_type>, void>
|
||||
construct(It first, It last) {
|
||||
underlying_type::construct(first, last);
|
||||
return std::make_reverse_iterator(begin() + std::distance(first, last));
|
||||
}
|
||||
|
||||
/*! @copydoc storage::sort */
|
||||
|
||||
@@ -1191,17 +1191,11 @@ TEST(Registry, RangeAssign) {
|
||||
ASSERT_FALSE(registry.has<float>(e2));
|
||||
|
||||
const auto view = registry.view<int, char>();
|
||||
auto it = registry.assign<float>(view.begin(), view.end());
|
||||
registry.assign<float>(view.begin(), view.end());
|
||||
|
||||
ASSERT_TRUE(registry.has<float>(e0));
|
||||
ASSERT_TRUE(registry.has<float>(e1));
|
||||
ASSERT_FALSE(registry.has<float>(e2));
|
||||
|
||||
*it = 0.f;
|
||||
*(it+1) = 1.f;
|
||||
|
||||
ASSERT_EQ(registry.get<float>(*view.begin()), 0.f);
|
||||
ASSERT_EQ(registry.get<float>(*(++view.begin())), 1.f);
|
||||
}
|
||||
|
||||
TEST(Registry, RangeRemove) {
|
||||
|
||||
@@ -100,7 +100,7 @@ TEST(Storage, BatchAdd) {
|
||||
|
||||
entities[0] = entt::entity{3};
|
||||
entities[1] = entt::entity{42};
|
||||
auto it = pool.construct(std::begin(entities), std::end(entities));
|
||||
pool.construct(std::begin(entities), std::end(entities));
|
||||
|
||||
ASSERT_TRUE(pool.has(entities[0]));
|
||||
ASSERT_TRUE(pool.has(entities[1]));
|
||||
@@ -109,12 +109,6 @@ TEST(Storage, BatchAdd) {
|
||||
ASSERT_EQ(pool.size(), 2u);
|
||||
ASSERT_EQ(pool.get(entities[0]), 0);
|
||||
ASSERT_EQ(pool.get(entities[1]), 0);
|
||||
|
||||
it[0] = 1;
|
||||
it[1] = 2;
|
||||
|
||||
ASSERT_EQ(pool.get(entities[0]), 1);
|
||||
ASSERT_EQ(pool.get(entities[1]), 2);
|
||||
}
|
||||
|
||||
TEST(Storage, BatchAddEmptyType) {
|
||||
|
||||
Reference in New Issue
Block a user