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

Improved Spawn APIs and Bundle Effects #17521

Merged
merged 12 commits into from
Feb 9, 2025
4 changes: 2 additions & 2 deletions benches/benches/bevy_ecs/world/world_get.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use core::hint::black_box;

use bevy_ecs::{
bundle::Bundle,
bundle::{Bundle, NoBundleEffect},
component::Component,
entity::Entity,
system::{Query, SystemState},
Expand Down Expand Up @@ -36,7 +36,7 @@ fn setup<T: Component + Default>(entity_count: u32) -> World {
black_box(world)
}

fn setup_wide<T: Bundle + Default>(entity_count: u32) -> World {
fn setup_wide<T: Bundle<Effect: NoBundleEffect> + Default>(entity_count: u32) -> World {
let mut world = World::default();
world.spawn_batch((0..entity_count).map(|_| T::default()));
black_box(world)
Expand Down
25 changes: 15 additions & 10 deletions crates/bevy_ecs/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub fn derive_bundle(input: TokenStream) -> TokenStream {
self.#field.get_components(&mut *func);
});
field_from_components.push(quote! {
#field: <#field_type as #ecs_path::bundle::Bundle>::from_components(ctx, &mut *func),
#field: <#field_type as #ecs_path::bundle::BundleFromComponents>::from_components(ctx, &mut *func),
});
}
None => {
Expand All @@ -109,7 +109,7 @@ pub fn derive_bundle(input: TokenStream) -> TokenStream {
self.#index.get_components(&mut *func);
});
field_from_components.push(quote! {
#index: <#field_type as #ecs_path::bundle::Bundle>::from_components(ctx, &mut *func),
#index: <#field_type as #ecs_path::bundle::BundleFromComponents>::from_components(ctx, &mut *func),
});
}
}
Expand All @@ -128,7 +128,7 @@ pub fn derive_bundle(input: TokenStream) -> TokenStream {

TokenStream::from(quote! {
// SAFETY:
// - ComponentId is returned in field-definition-order. [from_components] and [get_components] use field-definition-order
// - ComponentId is returned in field-definition-order. [get_components] uses field-definition-order
// - `Bundle::get_components` is exactly once for each member. Rely's on the Component -> Bundle implementation to properly pass
// the correct `StorageType` into the callback.
unsafe impl #impl_generics #ecs_path::bundle::Bundle for #struct_name #ty_generics #where_clause {
Expand All @@ -146,6 +146,17 @@ pub fn derive_bundle(input: TokenStream) -> TokenStream {
#(#field_get_component_ids)*
}

fn register_required_components(
components: &mut #ecs_path::component::Components,
required_components: &mut #ecs_path::component::RequiredComponents
){
#(#field_required_components)*
}
}

// SAFETY:
// - ComponentId is returned in field-definition-order. [from_components] uses field-definition-order
unsafe impl #impl_generics #ecs_path::bundle::BundleFromComponents for #struct_name #ty_generics #where_clause {
#[allow(unused_variables, non_snake_case)]
unsafe fn from_components<__T, __F>(ctx: &mut __T, func: &mut __F) -> Self
where
Expand All @@ -155,16 +166,10 @@ pub fn derive_bundle(input: TokenStream) -> TokenStream {
#(#field_from_components)*
}
}

fn register_required_components(
components: &mut #ecs_path::component::Components,
required_components: &mut #ecs_path::component::RequiredComponents
){
#(#field_required_components)*
}
}

impl #impl_generics #ecs_path::bundle::DynamicBundle for #struct_name #ty_generics #where_clause {
type Effect = ();
#[allow(unused_variables)]
#[inline]
fn get_components(
Expand Down
Loading