I need to write a function for an ECS that takes in a variable number of template parameters (Components) and no arguments and will return a list of entities with those components attached.
The format would look like this:
auto list = registry.getEntityGroupWithComponents<TransformComponent, RenderComponent>();
Within the function, I need to access a static ID of each Component class to determine which entities to return, something like this:
template <class... T>
std::vector<Entity> getEntityGroupWithComponents()
{
auto componentIDs = { T::s_id };
//return entities with all componentIDs in list
}
I've messed around quite a bit and can't come up with anything that produces this behavior, but I'm fairly sure it's possible since I think I've seen a similar API before. Any help would be appreciated, thanks!
Unsure about what you need, but probably something like
template <class... T>
std::vector<Entity> getEntityGroupWithComponents()
{
return {enitity(T::s_id)...};
}
?
Depending on how an entity is constructed from a component id.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.