registry: remove the visit overload that also takes an entity

This commit is contained in:
Michele Caini
2021-12-14 22:57:10 +01:00
parent 4b3108283f
commit 69ddf4936e
5 changed files with 12 additions and 52 deletions

View File

@@ -1207,9 +1207,11 @@ components with entities without knowing their actual type and even initialize
them by copy if needed:
```cpp
registry.visit(entity, [other](auto &&storage) {
// create a copy of an entity component by component
storage.emplace(other, storage.get(entity));
// create a copy of an entity component by component
registry.visit([entity, other](auto &&storage) {
if(storage.contains(entity)) {
storage.emplace(other, storage.get(entity));
}
});
```

View File

@@ -272,7 +272,11 @@ struct basic_handle {
*/
template<typename Func>
void visit(Func &&func) const {
reg->visit(entt, std::forward<Func>(func));
reg->visit([func = std::forward<Func>(func), this](auto &&storage) {
if(storage.contains(entt)) {
func(storage);
}
});
}
private:

View File

@@ -1295,30 +1295,6 @@ public:
assure<To>().respect(assure<From>());
}
/**
* @brief Visits an entity and returns the pools for its components.
*
* The signature of the function should be equivalent to the following:
*
* @code{.cpp}
* void(const basic_sparse_set<entity_type> &);
* @endcode
*
* Returned pools are those of the components owned by the entity.
*
* @tparam Func Type of the function object to invoke.
* @param entity A valid identifier.
* @param func A valid function object.
*/
template<typename Func>
void visit(entity_type entity, Func func) const {
for(auto &&curr: pools) {
if(curr.second->contains(entity)) {
func(*curr.second);
}
}
}
/**
* @brief Visits a registry and returns the pools for its components.
*

View File

@@ -1872,28 +1872,6 @@ TEST(Registry, Visit) {
});
ASSERT_TRUE(hasType[0] && hasType[1] && hasType[2]);
hasType[0] = hasType[1] = hasType[2] = false;
registry.visit(entity, [&hasType](const auto &pool) {
hasType[0] = hasType[0] || (pool.type() == entt::type_id<int>());
hasType[1] = hasType[1] || (pool.type() == entt::type_id<double>());
hasType[2] = hasType[2] || (pool.type() == entt::type_id<char>());
});
ASSERT_TRUE(hasType[0] && !hasType[1] && hasType[2]);
hasType[0] = hasType[2] = false;
registry.visit(other, [&hasType](const auto &pool) {
hasType[0] = hasType[0] || (pool.type() == entt::type_id<int>());
hasType[1] = hasType[1] || (pool.type() == entt::type_id<double>());
hasType[2] = hasType[2] || (pool.type() == entt::type_id<char>());
});
ASSERT_TRUE(!hasType[0] && hasType[1] && !hasType[2]);
hasType[1] = false;
}
TEST(Registry, ScramblingPoolsIsAllowed) {

View File

@@ -22,9 +22,9 @@ TEST(Example, EntityCopy) {
ASSERT_FALSE((registry.any_of<int, char, double>(dst)));
ASSERT_FALSE(custom.contains(dst));
registry.visit(src, [src, dst](auto &&storage) {
registry.visit([src, dst](auto &&storage) {
// discard chars because why not, this is just an example after all
if(storage.type() != entt::type_id<char>()) {
if(storage.type() != entt::type_id<char>() && storage.contains(src)) {
storage.emplace(dst, storage.get(src));
}
});