vendredi 3 juillet 2015

c++ entity component system and accessing components using a template

I've been working on creating my own entity component system, and I'm set on being able to get a component by doing the following:

const auto& component = entity->GetComponent<ComponentType>();

the above function would then look something like this:

template <typename TyComponent>
TyComponent* Entity<T>::GetComponent() const
{
  return &(GetComponent(TyComponent::Id());
}

Which then returns a component based on the associated id if found, else nullptr.

  1. Is what I'm doing viable?
  2. Is there a way to ensure only types derived from Component can be used as a parameter for GetComponent?

Aucun commentaire:

Enregistrer un commentaire