-
Notifications
You must be signed in to change notification settings - Fork 1
Family
Entities with the same set of components can be grouped in Family
objects.
A Family
is defined by:
- A set of components the entity must have.
- A set of components of which the entity must have at least one.
- A set of components the entity cannot have.
You can obtain a Family
by specifying the list of component classes the entities belonging to said family must (not) possess. This should satisfy most of your entity classification needs.
auto& family = Family::all<PositionComponent, VelocityComponent>().get(); // returns const Family&
Imagine we want to group all entities that should be rendered. It certainly must have a position and either a texture or a particle system. Additionally, we need to make sure it is not invisible. These constraints can easily be represented the following way.
auto& family = Family::all<PositionComponent>()
.one<TextureComponent, ParticleComponent>()
.exclude<InvisibleComponent>()
.get();
The Engine
has the capability of providing the full collection of entities that match a specific family.
const std::vector<Entity*>* entities = engine.getEntitiesFor(family);
Usually you'd store the result in the attribute of an EntitySystem
(the vector will always be up-to-date).
Iterating over them works the same way as with components.