How would one look for entities with specific components in an entity component system?
In my current implementation I'm storing components in a
std::unordered_map< entity_id, std::unordered_map<type_index, Component *> >
.
So if a system needs access to entities with specific components, what is the most efficient way to access them.
I currently have 2 ideas:
I saw some approaches with bitmasks and such, but that doesn't seem scalable.
Your situation calls for std::unordered_multimap.
"find" method would return an iterator for the first element, which matches the key in multimap. "equal_range" method would return you a pair, containing the iterators for the first and last object, matching your key.
Actually what unordered_multimap allows you to create is an in-memory key-value database that stores a bunch of objects for the same key.
If your "queries" would get more complicated than "give me all objects with component T" and turn into something like "give me all components that have component T and B at the same time", you would be better suited to create a class that has unordered_multimap as a member and has a bunch of utility methods for querying the stuff.
More on the subject: