Doraku / DefaultEcs

Entity Component System framework aiming for syntax and usage simplicity with maximum performance for game development.
MIT No Attribution
658 stars 62 forks source link

Fastest way to query entities ? #131

Closed genaray closed 2 years ago

genaray commented 3 years ago

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 ?

Doraku commented 3 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?

genaray commented 3 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?

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 :)

Doraku commented 2 years ago

In general collection term:

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.