Closed genaray closed 2 years ago
What about using a EntityMultiMap? You create a system to refresh a component to identify which chunk the entity should belong to, and then you can quickly get all the entities for a given chunk id. I do something similar in the Boid sample with the GridId. Is it something you could do or your usage is totally different?
What about using a EntityMultiMap? You create a system to refresh a component to identify which chunk the entity should belong to, and then you can quickly get all the entities for a given chunk id. I do something similar in the Boid sample with the GridId. Is it something you could do or your usage is totally different?
Thanks a lot im gonna look at that ! What exactly is a EntityMultiMap and whats the difference from a EntitySet and a single EntityMap ? I read the docs but i couldnt really find a difference so i would be glad for clarification :)
In general collection term:
EntitySet
is like a List<Entity>
EntitySortedSet<T>
is like a List<Entity>
ordered by their T component (not yet released)EntityMap<T>
is like a Dictionary<T, Entity>
EntityMultiMap<T>
is like a Dictionary<T, List<Entity>>
All of them are updated and maintained as you add/remove/change components on entities so their content always respect the rules you used to create them.
EntitySet, EntitySortedSet and EntityMultiMap all have their corresponding AEntity...System to handle update and multithreading for you, EntityMap is just here to quickly access a specific entity based on a component value.
I have a few systems where i need to query for entities during an iteration.
To understand the use case : I split the game world into chunk - entities and normal entities. Chunk entities basically symbolize a grid region in my game. Theres a chunk calculation system which iterates over all normal entities each frame and calculate the chunk/grid it belongs into. But once that chunk/grid was calculated, i need to query all existing chunk-entities to find the right one based on the calculation. So this query happens pretty often.
Whats the fastest and most efficient way to query for entities ? Is there some sort of raw acess without using .ToEnumerable() ? One raw acess which creates no garbage and is blazing fast ?