bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
36.25k stars 3.57k forks source link

Example of parallel processing of a SystemSet #1989

Open CGMossa opened 3 years ago

CGMossa commented 3 years ago

I'm working on using Bevy to facilitate an ecological (scientific) simulation model. To that end, I need to repeat/replicate the positted scenario a number of times, while using already available resources, and also having some things that pertain to the particular iteration. Also, I need to reset some resources/etc. after each run.

There is a discussion on this here #1678, where @alice-i-cecile called this

easy parallel process replication

and also there is this RFC for SubWorlds bevyengine/rfcs#16 that could help with this.

If someone could pinpoint some way to accomplish today, that would be great so as to be able to get going for now.

ghost commented 3 years ago

I have a PR up for an example of system sets. If I understood your requirements correctly perhaps this part is of interest to you:

https://github.com/bevyengine/bevy/pull/1909/files#diff-608eb7fd189284d2c34d7192c97d3400c16781e1d031437da19b0714a790486eR77-R93

I haven't gotten a lot feedback on the PR yet though so I'm not sure if it's idiomatic/correct/clear at this point, but it might at least point you in the right direction.

CGMossa commented 3 years ago

Thanks for the reply. I like reading this example. I am not sure it is doing what I wish for it todo. But it is such a nicely written example. My problem is that the repetition has to run "separately". Imagine like if I basically was simulating an NPC separately, or separate games.

CGMossa commented 3 years ago

I'm still unable to do this, and it is beginning to become important for my project. Currently, there is no way for me to even Clone the World and then use that as a way to parallel run the App.

I'd appreciate it if anyone had some ideas on how to do it.

Ixentus commented 3 years ago

Have you seen the new Render Rework? It includes a SubApps experiment. The second iteration (first link) also has SubGraphs. Not sure if either solves your problem right now, but they are worth checking out.

mockersf commented 3 years ago

Would it work in your case to tag entities specific to a scenario with a unit struct Scenario1, and have everything in one app, with your systems only making interactions between entities with the same tag?

CGMossa commented 3 years ago

It wouldn't necessarily not work. But it is less than ideal. I don't want to figure out how many repetitions to schedule simultaneously. Nor do I want to pollute all the systems with having repetitions as a marker, etc.

I also don't see that Bevy supports "taggy" behaviour. I'm not sure it would translate to good performance in the long run.

Also, I have some other things, that I'm unsure about. Like, are resources then going to have a repetition id attached to them. What if I wanted a resource shared across repetitions? Is ResMut a sort of Mutex or is it not?

I'll investigate the other hints, but right now, I'm really unsure about things.

Thanks for the advice folks.

On Wed, 23 Jun 2021 at 01:26, François @.***> wrote:

Would it work in your case to tag entities specific to a scenario with a unit struct Scenario1, and have everything in one app, with your systems only making interactions between entities with the same tag?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/bevyengine/bevy/issues/1989#issuecomment-866402285, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIDVSA5O22SH6LY4O5BHJTTUELZVANCNFSM43OIH7RQ .