Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Composing Systems #100

Closed
cab opened this issue Feb 10, 2020 · 1 comment
Closed

Composing Systems #100

cab opened this issue Feb 10, 2020 · 1 comment

Comments

@cab
Copy link

cab commented Feb 10, 2020

I was wondering if there were any provided solutions, "tips", or possible contributions I could make for composing systems.

For example, taking the example system:

let update_positions = SystemBuilder::new("update_positions")
        .write_resource::<ExampleResource1>()
        .read_resource::<ExampleResource2>()
        .with_query(<(Write<Pos>, Read<Vel>)>::query())
        .build(|_, mut world, (res1, res2), query| {
            res1.0 = res2.0.clone(); // Write the mutable resource from the immutable resource

            for (mut pos, vel) in query.iter_mut(&mut world) {
                pos.0 += vel.0;
                pos.1 += vel.1;
                pos.2 += vel.2;
            }
        });

It would be nice to be able to compose the function passed to build to e.g. make this system execute every 1000 milliseconds, something like:

 .build(timed_system(1000, |_, mut world, (res1, res2), query| {
            res1.0 = res2.0.clone(); // Write the mutable resource from the immutable resource

            for (mut pos, vel) in query.iter_mut(&mut world) {
                pos.0 += vel.0;
                pos.1 += vel.1;
                pos.2 += vel.2;
            }
        }));

But if you define some function that takes in a FnMut with the same type parameters as build, the query argument type can no longer be inferred, which makes this difficult to work with. Separately, I think there would be no way to specify what resources the "wrapper" system needs without modifying the scheduler.

However, maybe this is just the wrong approach overall, or I'm looking for something different from legion_systems.

This is maybe related to #31.

And thanks for legion, really enjoying using it so far.

@cab
Copy link
Author

cab commented Dec 8, 2020

I think with all the new changes, this issue is no longer relevant. Thanks!

@cab cab closed this as completed Dec 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant