Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.
Lusito edited this page Oct 30, 2016 · 3 revisions

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.

Obtaining a Family.

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();

Getting a list of entities which belong to a Family

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.