Skip to content

Commit

Permalink
Merge pull request #1 from skalldri/destroy_all_with
Browse files Browse the repository at this point in the history
Add DestroyAllWith function to EntityManager
  • Loading branch information
xthexder authored Nov 27, 2020
2 parents 9816e53 + 2868a9e commit 38e550c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions include/ecs/EntityManager.hh
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ namespace ecs
*/
void DestroyAll();

/**
* Calls Destroy() on all Entities that match a specific KeyType value.
*
* This function will only find components added with the AssignKey() function.
*/
template <typename KeyType, typename... CompTypes>
void DestroyAllWith(const KeyType &key);

/**
* Check if the entity is still valid in the system.
* An entity is invalid if it is not currently present in the system.
Expand Down
11 changes: 11 additions & 0 deletions include/ecs/EntityManagerImpl.hh
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,17 @@ namespace ecs
}
}

template<typename KeyType, typename... CompTypes>
inline void EntityManager::DestroyAllWith(const KeyType &key)
{
auto entityCollection = EntitiesWith<KeyType, CompTypes...>(key);

for (auto ent : entityCollection)
{
ent.Destroy();
}
}

inline bool EntityManager::Valid(Entity::Id e) const
{
return e && e.Generation() == entIndexToGen.at(e.Index());
Expand Down

0 comments on commit 38e550c

Please sign in to comment.