added registry::reset<Comp>(entity)

This commit is contained in:
Michele Caini
2017-04-27 13:58:40 +02:00
parent 40368941d6
commit ad8bed937e
3 changed files with 14 additions and 0 deletions

View File

@@ -179,6 +179,7 @@ Once you have created a registry, the followings are the exposed member function
* `clone(entity)`: clones an entity and all its components, then returns the new entity identifier.
* `copy<Component>(from, to)`: copies a component from an entity to another one (both the entities must already have been assigned the component, undefined behaviour otherwise).
* `copy(from, to)`: copies all the components and their contents from an entity to another one (comoonents are created or destroyed if needed).
* `reset<Component>(entity)`: removes the given component from the entity if assigned.
* `reset<Component>()`: destroys all the instances of `Component`.
* `reset()`: resets the pool and destroys all the entities and their components.
* `view<Components...>()`: gets a view of the entities that have the given components (see below for further details).

View File

@@ -353,6 +353,13 @@ public:
(void)accumulator;
}
template<typename Comp>
void reset(entity_type entity) {
if(pool.template has<Comp>(entity)) {
pool.template destroy<Comp>(entity);
}
}
template<typename Comp>
void reset() {
pool.template reset<Comp>();

View File

@@ -103,6 +103,12 @@ TEST(DefaultRegistry, Functionalities) {
ASSERT_TRUE(registry.empty<int>());
ASSERT_TRUE(registry.empty<char>());
e1 = registry.create<int>();
ASSERT_NO_THROW(registry.reset<int>(e1));
ASSERT_NO_THROW(registry.reset<int>(e2));
ASSERT_TRUE(registry.empty<int>());
}
TEST(DefaultRegistry, ViewSingleComponent) {