I have not found a good solution for ECS data structure in termes of cache coherency. Maybe it does not exist, so I am looking for some algorithms that reorder antities or components in memory using some data (may be also statistic data obtaind from the the game real time) to achieve contiguas memory traversing when the systems will travers on entities to accomplish their mission.
Statistic algorithms for ECS
Moderators - Reputation: 17516
Posted 08 May 2014 - 03:10 PM
Keep in mind that an ECS doesn't have to be implemented in terms of each entity object holding" containers of its components. You can use data-oriented architectures to store the component relationships externally from the actual entity/component objects/classes themselves. It's a little trickier to read, but it works pretty well in my experience.
[Work - ArenaNet] [Epoch Language] [Scribblings] [Journal - peek into my shattered mind]
Senior Moderators - Reputation: 13300
Posted 08 May 2014 - 04:32 PM
Adding to what ApochPiQ said, a lot of ECS systems tend to use the "outboard component" model, where each component is pooled separately, and the entity itself is just a semantic tag (usually an integer handle).
That's kind of the idea case for cache coherency - you can have a system, for example, that just iterates over a flat array of position data, and calculates world transforms for each one.
Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]
Members - Reputation: 1226
Posted 10 May 2014 - 04:54 PM
What ApochPiQ and swiftcoder said is exactly how I implemented my ECS. I don't have any caching stats I can point to that prove its better doing it that way, but I can say that it was relatively straightforward to implement, and gives you quite a few interesting advantages.
The biggest downside is that it becomes a little more difficult to list all components for a single entity, since each component is stored far away from the others.