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

SystemParamBuilder - Support buildable Vec parameters #14821

Merged
merged 2 commits into from
Aug 27, 2024

Conversation

chescock
Copy link
Contributor

Objective

Allow dynamic systems to take lists of system parameters whose length is not known at compile time.

This can be used for building a system that runs a script defined at runtime, where the script needs a variable number of query parameters. It can also be used for building a system that collects a list of plugins at runtime, and provides a parameter to each one.

This is most useful today with Vec<Query<FilteredEntityMut>>. It will be even more useful with Vec<DynSystemParam> if #14817 is merged, since the parameters in the list can then be of different types.

Solution

Implement SystemParam and SystemParamBuilder for Vec and ParamSet<Vec>.

Example

let system = (vec![
    QueryParamBuilder::new_box(|builder| {
        builder.with::<B>().without::<C>();
    }),
    QueryParamBuilder::new_box(|builder| {
        builder.with::<C>().without::<B>();
    }),
],)
    .build_state(&mut world)
    .build_system(|params: Vec<Query<&mut A>>| {
        let mut count: usize = 0;
        params
            .into_iter()
            .for_each(|mut query| count += query.iter_mut().count());
        count
    });

@TrialDragon TrialDragon added C-Feature A new feature, making something new possible A-ECS Entities, components, systems, and events D-Unsafe Touches with unsafe code in some way S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Aug 19, 2024
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm glad this is split out! The motivation in the PR description was very helpful, thanks :)

@cBournhonesque cBournhonesque added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Aug 24, 2024
@alice-i-cecile
Copy link
Member

@chescock let me know when merge conflicts are resolved and I'll get this in.

@alice-i-cecile alice-i-cecile added this pull request to the merge queue Aug 27, 2024
Merged via the queue into bevyengine:main with commit 6ddbf97 Aug 27, 2024
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Feature A new feature, making something new possible D-Unsafe Touches with unsafe code in some way S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants