If an Entity has no explicit 'type' (e.g. player) and is simply a collection of components, how do I identify the entities that my systems should and should not be working on? For example, in a game of Pong the paddle and ball both collide with the window boundaries. However, the collision handling systems for each will be different, therefore a system should not handle entities of the wrong type.
void PlayerCollisionSystem::update(std::vector<Entity *> entities) {
typedef std::vector<Entity *>::iterator EIter;
for (EIter i = entities.begin(); i != entities.end(); ++i) {
Entity *player = *i; // How do I verify that the entity is a player?
// Get relevant components.
PositionComponent *position = player->getComponent<PositionComponent>();
VelocityComponent *velocity = player->getComponent<VelocityComponent>();
SpriteComponent *sprite = player->getComponent<SpriteComponent>();
// Detect and handle player collisions using the components.
}
}
Both the player and the ball share the same relevant component types for collision handling yet their system implementations will be different.
If I have a container of all game entities, how do I identify specific types of entity without inheriting Entity
or including a member variable such as std::string type
, in which case an entity is no longer simply a collection of components?