Partially looping over entities per frame.

Is there a “best practice” way to conduct a EntityBatch job on a fraction of entities per frame? Lets say there are 100k entities, I want to do work on them splitting between 4 frames, so 25k per frame. I have thought about using SCD and just assign them frame that way, but it doesn’t seem right.

To be clear, all entities are same components, I just don’t need to do work every frame so I want to split it.

I would just make 4 different component tags and 4 different jobs in the system.

1 Like

If you’re gonna make different tags, I’d honestly just go with SCD. Different values of SCD will cause different chunk grouping and allow for fast queries just like tags would, but it’s much cleaner. Make like an ‘UpdateGroup’ int SCD or something, then you can easily change how many groups you have.

3 Likes

Perhaps try to make a new fixed step simulation group and add your system to that. so it can take multiple frames to complete?

what does SCD stand for?

1 Like

Shared Component Data

I am interested in this as well in the context of VR where it’s more important that a system completes in a predictable amount of time to hit a specific framerate than necessarily update each entity every frame.

I was thinking something along the lines of using an SCD with a uint “lastFrameProcessed”. In the system, you get the array of chunks, sort them based on lastFrameProcessed, and then operate on a fixed number of the most stale chunks. After you process each chunk, you update lastFrameProcessed with the current frame so it ends up at the back of the line next frame. If you were updating 25K entities per frame, you would automatically get an update every 4th frame with 100K entities, but proportionally more updates at lower entity counts.

Adding new entities would be a bit more difficult. Add them to the stalest chunk with an opening and set the lastFrameProcessed to 0 to make sure it gets updated next frame.

I haven’t implemented this so not sure how well it would work in practice, and I’m still learning the API so perhaps there is a more elegant to do it.

2 Likes