Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
995307c
added id generator.
ElliottjPierce Mar 5, 2025
63b0931
separated id generation form registration
ElliottjPierce Mar 5, 2025
3efef9c
handled the major errors
ElliottjPierce Mar 5, 2025
35d9493
fixed all remaining errors and warning
ElliottjPierce Mar 5, 2025
f786616
small improvements
ElliottjPierce Mar 5, 2025
a49dade
outlined queuing
ElliottjPierce Mar 5, 2025
95ec1d5
rearanged data
ElliottjPierce Mar 5, 2025
825d573
small move
ElliottjPierce Mar 5, 2025
53f9d96
respect the queued registrations
ElliottjPierce Mar 5, 2025
3aab1a4
apply registrations
ElliottjPierce Mar 5, 2025
6a976ef
fully implemented queueing
ElliottjPierce Mar 5, 2025
1b98032
fixed docs
ElliottjPierce Mar 5, 2025
2741c77
final touches
ElliottjPierce Mar 6, 2025
e84684d
simplified as_queued
ElliottjPierce Mar 6, 2025
cbea213
Merge branch 'main' into queued-component-registration
ElliottjPierce Mar 6, 2025
afdd3c1
fixed ci hopefully
ElliottjPierce Mar 6, 2025
83513b7
Merge branch 'queued-component-registration' of https://github.com/El…
ElliottjPierce Mar 6, 2025
d2672b5
Minor docs changes.
ElliottjPierce Mar 6, 2025
a329e2d
Redid queued registration without trait indirection
ElliottjPierce Mar 6, 2025
ed4dc99
comments and reduced allocations
ElliottjPierce Mar 6, 2025
a7523be
clarified access to queued
ElliottjPierce Mar 6, 2025
3c9943f
added ways to check registration easily
ElliottjPierce Mar 6, 2025
dddd24c
fixed docs
ElliottjPierce Mar 6, 2025
2d5baaa
change component storage back to vec
ElliottjPierce Mar 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/bevy_ecs/macros/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ pub fn derive_component(input: TokenStream) -> TokenStream {
type Mutability = #mutable_type;
fn register_required_components(
requiree: #bevy_ecs_path::component::ComponentId,
components: &mut #bevy_ecs_path::component::Components,
components: &mut #bevy_ecs_path::component::ComponentsRegistrator,
required_components: &mut #bevy_ecs_path::component::RequiredComponents,
inheritance_depth: u16,
recursion_check_stack: &mut #bevy_ecs_path::__macro_exports::Vec<#bevy_ecs_path::component::ComponentId>
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_ecs/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub fn derive_bundle(input: TokenStream) -> TokenStream {
#[allow(deprecated)]
unsafe impl #impl_generics #ecs_path::bundle::Bundle for #struct_name #ty_generics #where_clause {
fn component_ids(
components: &mut #ecs_path::component::Components,
components: &mut #ecs_path::component::ComponentsRegistrator,
ids: &mut impl FnMut(#ecs_path::component::ComponentId)
){
#(#field_component_ids)*
Expand All @@ -148,7 +148,7 @@ pub fn derive_bundle(input: TokenStream) -> TokenStream {
}

fn register_required_components(
components: &mut #ecs_path::component::Components,
components: &mut #ecs_path::component::ComponentsRegistrator,
required_components: &mut #ecs_path::component::RequiredComponents
){
#(#field_required_components)*
Expand Down
34 changes: 20 additions & 14 deletions crates/bevy_ecs/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use crate::{
},
change_detection::MaybeLocation,
component::{
Component, ComponentId, Components, RequiredComponentConstructor, RequiredComponents,
StorageType, Tick,
Component, ComponentId, Components, ComponentsRegistrator, RequiredComponentConstructor,
RequiredComponents, StorageType, Tick,
},
entity::{Entities, Entity, EntityLocation},
observer::Observers,
Expand All @@ -31,7 +31,7 @@ use variadics_please::all_tuples;

/// The `Bundle` trait enables insertion and removal of [`Component`]s from an entity.
///
/// Implementors of the `Bundle` trait are called 'bundles'.
/// Implementers of the `Bundle` trait are called 'bundles'.
///
/// Each bundle represents a static set of [`Component`] types.
/// Currently, bundles can only contain one of each [`Component`], and will
Expand Down Expand Up @@ -72,7 +72,7 @@ use variadics_please::all_tuples;
/// That is, if the entity does not have all the components of the bundle, those
/// which are present will be removed.
///
/// # Implementors
/// # Implementers
///
/// Every type which implements [`Component`] also implements `Bundle`, since
/// [`Component`] types can be added to or removed from an entity.
Expand Down Expand Up @@ -151,14 +151,14 @@ use variadics_please::all_tuples;
pub unsafe trait Bundle: DynamicBundle + Send + Sync + 'static {
/// Gets this [`Bundle`]'s component ids, in the order of this bundle's [`Component`]s
#[doc(hidden)]
fn component_ids(components: &mut Components, ids: &mut impl FnMut(ComponentId));
fn component_ids(components: &mut ComponentsRegistrator, ids: &mut impl FnMut(ComponentId));

/// Gets this [`Bundle`]'s component ids. This will be [`None`] if the component has not been registered.
fn get_component_ids(components: &Components, ids: &mut impl FnMut(Option<ComponentId>));

/// Registers components that are required by the components in this [`Bundle`].
fn register_required_components(
_components: &mut Components,
_components: &mut ComponentsRegistrator,
_required_components: &mut RequiredComponents,
);
}
Expand Down Expand Up @@ -223,12 +223,12 @@ pub trait BundleEffect {
// - `Bundle::component_ids` calls `ids` for C's component id (and nothing else)
// - `Bundle::get_components` is called exactly once for C and passes the component's storage type based on its associated constant.
unsafe impl<C: Component> Bundle for C {
fn component_ids(components: &mut Components, ids: &mut impl FnMut(ComponentId)) {
fn component_ids(components: &mut ComponentsRegistrator, ids: &mut impl FnMut(ComponentId)) {
ids(components.register_component::<C>());
}

fn register_required_components(
components: &mut Components,
components: &mut ComponentsRegistrator,
required_components: &mut RequiredComponents,
) {
let component_id = components.register_component::<C>();
Expand Down Expand Up @@ -288,7 +288,7 @@ macro_rules! tuple_impl {
// - `Bundle::get_components` is called exactly once for each member. Relies on the above implementation to pass the correct
// `StorageType` into the callback.
unsafe impl<$($name: Bundle),*> Bundle for ($($name,)*) {
fn component_ids(components: &mut Components, ids: &mut impl FnMut(ComponentId)){
fn component_ids(components: &mut ComponentsRegistrator, ids: &mut impl FnMut(ComponentId)){
$(<$name as Bundle>::component_ids(components, ids);)*
}

Expand All @@ -297,7 +297,7 @@ macro_rules! tuple_impl {
}

fn register_required_components(
components: &mut Components,
components: &mut ComponentsRegistrator,
required_components: &mut RequiredComponents,
) {
$(<$name as Bundle>::register_required_components(components, required_components);)*
Expand Down Expand Up @@ -999,9 +999,12 @@ impl<'w> BundleInserter<'w> {
archetype_id: ArchetypeId,
change_tick: Tick,
) -> Self {
// SAFETY: These come from the same world. `world.components_registrator` can't be used since we borrow other fields too.
let mut registrator =
unsafe { ComponentsRegistrator::new(&mut world.components, &mut world.component_ids) };
let bundle_id = world
.bundles
.register_info::<T>(&mut world.components, &mut world.storages);
.register_info::<T>(&mut registrator, &mut world.storages);
// SAFETY: We just ensured this bundle exists
unsafe { Self::new_with_id(world, archetype_id, bundle_id, change_tick) }
}
Expand Down Expand Up @@ -1369,9 +1372,12 @@ pub(crate) struct BundleSpawner<'w> {
impl<'w> BundleSpawner<'w> {
#[inline]
pub fn new<T: Bundle>(world: &'w mut World, change_tick: Tick) -> Self {
// SAFETY: These come from the same world. `world.components_registrator` can't be used since we borrow other fields too.
let mut registrator =
unsafe { ComponentsRegistrator::new(&mut world.components, &mut world.component_ids) };
let bundle_id = world
.bundles
.register_info::<T>(&mut world.components, &mut world.storages);
.register_info::<T>(&mut registrator, &mut world.storages);
// SAFETY: we initialized this bundle_id in `init_info`
unsafe { Self::new_with_id(world, bundle_id, change_tick) }
}
Expand Down Expand Up @@ -1574,7 +1580,7 @@ impl Bundles {
/// Also registers all the components in the bundle.
pub(crate) fn register_info<T: Bundle>(
&mut self,
components: &mut Components,
components: &mut ComponentsRegistrator,
storages: &mut Storages,
) -> BundleId {
let bundle_infos = &mut self.bundle_infos;
Expand All @@ -1599,7 +1605,7 @@ impl Bundles {
/// Also registers all the components in the bundle.
pub(crate) fn register_contributed_bundle_info<T: Bundle>(
&mut self,
components: &mut Components,
components: &mut ComponentsRegistrator,
storages: &mut Storages,
) -> BundleId {
if let Some(id) = self.contributed_bundle_ids.get(&TypeId::of::<T>()).cloned() {
Expand Down
Loading