Statistic algorithms for ECS

Started by
3 comments, last by Postie 10 years ago

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.

Advertisement

You could use a pool allocator for each type of component in order to guarantee (mostly) contiguous memory for components of the same type.

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.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

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. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

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.

[size="2"]Currently working on an open world survival RPG - For info check out my Development blog:[size="2"] ByteWrangler

This topic is closed to new replies.

Advertisement