Entt: What is the best way to feed data to the drawing thread?

Created on 19 Jul 2020  路  2Comments  路  Source: skypjack/entt

Thanks for this wonderful library and all the work you put into it. Sorry if this is a dumb question: I am trying to figure out the best design to communicate between the game-thread and the drawing thread, which are running on separate threads. At first I tried accessing the registry in the drawing thread directly, but since entities are added and removed at any time by the game-thread it often crashed. I tried pausing the drawing thread when something is added or removed, but since it can happen at any time it was difficult to get stable. Am I supposed to loop through the entities and copy them to a vector for the drawing thread to access? I tested this but it doesnt seem very performant, at least compared to letting the drawing thread do the job.

Again, thanks for your work!

question

Most helpful comment

Hi, sorry if I'm a little late, I've been busy this week.
If you want to render concurrently, you need to keep your data _stable_. This doesn't mean that you've to _copy_ everything somewhere else. You can use double buffering, a second component on which you put relevant data and a model with delayed deletions, and so on. Also, for copying everything, you don't have to do it an element at a time since you've range functionalities in EnTT.
What the best approach is for your case depends on the actual design. You haven't provided us with many details, so it's a bit difficult to say. For example, what data is your rendering thread accessing? What granularity you went on components with your design? And so on.
Out of my mind, resources shouldn't be a problem in any case since they are usually managed by an external tool and referenced by components in a flyweight model (at least, this is quite common). So, probably what is causing problems is the transform that you read and update concurrently? Or the entities that you delete from a thread and try to read from another one?

Let me know. In the meantime, I'm closing the issue since it's just a question but feel free to continue here the discussion. Thanks.

All 2 comments

Welp, there are some GDC talks worth watching
https://www.youtube.com/watch?v=0nTDFLMLX9k
https://www.youtube.com/watch?v=v2Q_zHG3vqg
https://www.youtube.com/watch?v=X1T3IQ4N-3g
TL;DW: You can copy required data to render thread

Hi, sorry if I'm a little late, I've been busy this week.
If you want to render concurrently, you need to keep your data _stable_. This doesn't mean that you've to _copy_ everything somewhere else. You can use double buffering, a second component on which you put relevant data and a model with delayed deletions, and so on. Also, for copying everything, you don't have to do it an element at a time since you've range functionalities in EnTT.
What the best approach is for your case depends on the actual design. You haven't provided us with many details, so it's a bit difficult to say. For example, what data is your rendering thread accessing? What granularity you went on components with your design? And so on.
Out of my mind, resources shouldn't be a problem in any case since they are usually managed by an external tool and referenced by components in a flyweight model (at least, this is quite common). So, probably what is causing problems is the transform that you read and update concurrently? Or the entities that you delete from a thread and try to read from another one?

Let me know. In the meantime, I'm closing the issue since it's just a question but feel free to continue here the discussion. Thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alanjfs picture alanjfs  路  5Comments

markand picture markand  路  5Comments

bilek993 picture bilek993  路  3Comments

skypjack picture skypjack  路  4Comments

netpoetica picture netpoetica  路  6Comments