mirror of
https://github.com/bevyengine/bevy
synced 2024-11-26 06:30:19 +00:00
d4ec80d5d2
# Objective Support more kinds of system params in buildable systems, such as a `ParamSet` or `Vec` containing buildable params or tuples of buildable params. ## Solution Replace the `BuildableSystemParam` trait with `SystemParamBuilder` to make it easier to compose builders. Provide implementations for existing buildable params, plus tuples, `ParamSet`, and `Vec`. ## Examples ```rust // ParamSet of tuple: let system = (ParamSetBuilder(( QueryParamBuilder::new(|builder| { builder.with::<B>(); }), QueryParamBuilder::new(|builder| { builder.with::<C>(); }), )),) .build_state(&mut world) .build_system(|mut params: ParamSet<(Query<&mut A>, Query<&mut A>)>| { params.p0().iter().count() + params.p1().iter().count() }); // ParamSet of Vec: let system = (ParamSetBuilder(vec![ QueryParamBuilder::new_box(|builder| { builder.with::<B>(); }), QueryParamBuilder::new_box(|builder| { builder.with::<C>(); }), ]),) .build_state(&mut world) .build_system(|mut params: ParamSet<Vec<Query<&mut A>>>| { let mut count = 0; params.for_each(|mut query| count += query.iter_mut().count()); count }); ``` ## Migration Guide The API for `SystemBuilder` has changed. Instead of constructing a builder with a world and then adding params, you first create a tuple of param builders and then supply the world. ```rust // Before let system = SystemBuilder::<()>::new(&mut world) .local::<u64>() .builder::<Local<u64>>(|x| *x = 10) .builder::<Query<&A>>(|builder| { builder.with::<B>(); }) .build(system); // After let system = ( ParamBuilder, LocalBuilder(10), QueryParamBuilder::new(|builder| { builder.with::<B>(); }), ) .build_state(&mut world) .build_system(system); ``` ## Possible Future Work Here are a few possible follow-up changes. I coded them up to prove that this API can support them, but they aren't necessary for this PR. * chescock/bevy#1 * chescock/bevy#2 * chescock/bevy#3 |
||
---|---|---|
.. | ||
bevy_a11y | ||
bevy_animation | ||
bevy_app | ||
bevy_asset | ||
bevy_audio | ||
bevy_color | ||
bevy_core | ||
bevy_core_pipeline | ||
bevy_derive | ||
bevy_dev_tools | ||
bevy_diagnostic | ||
bevy_dylib | ||
bevy_ecs | ||
bevy_encase_derive | ||
bevy_gilrs | ||
bevy_gizmos | ||
bevy_gltf | ||
bevy_hierarchy | ||
bevy_input | ||
bevy_internal | ||
bevy_log | ||
bevy_macro_utils | ||
bevy_math | ||
bevy_mikktspace | ||
bevy_pbr | ||
bevy_picking | ||
bevy_ptr | ||
bevy_reflect | ||
bevy_render | ||
bevy_scene | ||
bevy_sprite | ||
bevy_state | ||
bevy_tasks | ||
bevy_text | ||
bevy_time | ||
bevy_transform | ||
bevy_ui | ||
bevy_utils | ||
bevy_window | ||
bevy_winit |