Skip to content

Commit

Permalink
Fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 committed Jul 28, 2021
1 parent 21d9170 commit c3a386f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
10 changes: 5 additions & 5 deletions crates/bevy_ecs/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub fn derive_bundle(input: TokenStream) -> TokenStream {
{
if *is_bundle {
field_component_ids.push(quote! {
component_id.extend(<#field_type as #ecs_path::bundle::Bundle>::component_id(components));
component_ids.extend(<#field_type as #ecs_path::bundle::Bundle>::component_ids(components));
});
field_get_components.push(quote! {
self.#field.get_components(&mut func);
Expand All @@ -128,7 +128,7 @@ pub fn derive_bundle(input: TokenStream) -> TokenStream {
});
} else {
field_component_ids.push(quote! {
component_id.push(components.get_or_insert_id::<#field_type>());
component_ids.push(components.get_or_insert_id::<#field_type>());
});
field_get_components.push(quote! {
func((&mut self.#field as *mut #field_type).cast::<u8>());
Expand All @@ -147,12 +147,12 @@ pub fn derive_bundle(input: TokenStream) -> TokenStream {
TokenStream::from(quote! {
/// SAFE: TypeInfo is returned in field-definition-order. [from_components] and [get_components] use field-definition-order
unsafe impl #impl_generics #ecs_path::bundle::Bundle for #struct_name#ty_generics #where_clause {
fn component_id(
fn component_ids(
components: &mut #ecs_path::component::Components,
) -> Vec<#ecs_path::component::ComponentId> {
let mut component_id = Vec::with_capacity(#field_len);
let mut component_ids = Vec::with_capacity(#field_len);
#(#field_component_ids)*
component_id
component_ids
}

#[allow(unused_variables, unused_mut, non_snake_case)]
Expand Down
14 changes: 6 additions & 8 deletions crates/bevy_ecs/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use std::{any::TypeId, collections::HashMap};
/// [Bundle::component_id]
pub unsafe trait Bundle: Send + Sync + 'static {
/// Gets this [Bundle]'s component ids, in the order of this bundle's Components
fn component_id(components: &mut Components) -> Vec<ComponentId>;
fn component_ids(components: &mut Components) -> Vec<ComponentId>;

/// Calls `func`, which should return data for each component in the bundle, in the order of
/// this bundle's Components
Expand All @@ -67,7 +67,7 @@ macro_rules! tuple_impl {
/// SAFE: TypeInfo is returned in tuple-order. [Bundle::from_components] and [Bundle::get_components] use tuple-order
unsafe impl<$($name: Component),*> Bundle for ($($name,)*) {
#[allow(unused_variables)]
fn component_id(components: &mut Components) -> Vec<ComponentId> {
fn component_ids(components: &mut Components) -> Vec<ComponentId> {
vec![$(components.get_or_insert_id::<$name>()),*]
}

Expand Down Expand Up @@ -206,11 +206,11 @@ impl Bundles {
) -> &'a BundleInfo {
let bundle_infos = &mut self.bundle_infos;
let id = self.bundle_ids.entry(TypeId::of::<T>()).or_insert_with(|| {
let component_id = T::component_id(components);
let component_ids = T::component_ids(components);
let id = BundleId(bundle_infos.len());
// SAFE: T::component_id ensures info was created
let bundle_info = unsafe {
initialize_bundle(std::any::type_name::<T>(), &component_id, id, components)
initialize_bundle(std::any::type_name::<T>(), component_ids, id, components)
};
bundle_infos.push(bundle_info);
id
Expand All @@ -225,17 +225,15 @@ impl Bundles {
/// `component_id` must be valid [ComponentId]'s
unsafe fn initialize_bundle(
bundle_type_name: &'static str,
component_id: &[ComponentId],
component_ids: Vec<ComponentId>,
id: BundleId,
components: &mut Components,
) -> BundleInfo {
let mut component_ids = Vec::new();
let mut storage_types = Vec::new();

for &component_id in component_id {
for &component_id in &component_ids {
// SAFE: component_id exists and is therefore valid
let component_info = components.get_info_unchecked(component_id);
component_ids.push(component_id);
storage_types.push(component_info.storage_type());
}

Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_ecs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ mod tests {
.unwrap();

assert_eq!(
<Foo as Bundle>::component_id(world.components_mut()),
<Foo as Bundle>::component_ids(world.components_mut()),
vec![
world.components_mut().get_or_insert_id::<&'static str>(),
world.components_mut().get_or_insert_id::<i32>(),
Expand Down Expand Up @@ -151,7 +151,7 @@ mod tests {
}

assert_eq!(
<Nested as Bundle>::component_id(world.components_mut()),
<Nested as Bundle>::component_ids(world.components_mut()),
vec![
world.components_mut().get_or_insert_id::<usize>(),
world.components_mut().get_or_insert_id::<&'static str>(),
Expand Down

0 comments on commit c3a386f

Please sign in to comment.