From 5a74ce3ec7b85e288baf5cdc1ceae2247cdaedb7 Mon Sep 17 00:00:00 2001 From: Adam <46227443+Adamkob12@users.noreply.github.com> Date: Wed, 7 Feb 2024 23:52:46 +0200 Subject: [PATCH] renamed ComponentId, Components, ComponentDescriptor and ComponentInfo --- crates/bevy_core/src/lib.rs | 4 +- crates/bevy_ecs/macros/src/lib.rs | 8 +- crates/bevy_ecs/macros/src/world_query.rs | 4 +- crates/bevy_ecs/src/archetype.rs | 35 ++- crates/bevy_ecs/src/bundle.rs | 60 ++--- crates/bevy_ecs/src/component.rs | 204 ++++++++-------- crates/bevy_ecs/src/lib.rs | 16 +- crates/bevy_ecs/src/query/access.rs | 2 +- crates/bevy_ecs/src/query/builder.rs | 20 +- crates/bevy_ecs/src/query/fetch.rs | 128 ++++------ crates/bevy_ecs/src/query/filter.rs | 84 +++---- crates/bevy_ecs/src/query/state.rs | 12 +- crates/bevy_ecs/src/query/world_query.rs | 12 +- crates/bevy_ecs/src/removal_detection.rs | 11 +- crates/bevy_ecs/src/schedule/schedule.rs | 46 ++-- crates/bevy_ecs/src/storage/resource.rs | 16 +- crates/bevy_ecs/src/storage/sparse_set.rs | 35 ++- crates/bevy_ecs/src/storage/table.rs | 30 +-- crates/bevy_ecs/src/system/adapter_system.rs | 2 +- crates/bevy_ecs/src/system/combinator.rs | 6 +- .../src/system/exclusive_function_system.rs | 4 +- crates/bevy_ecs/src/system/function_system.rs | 6 +- crates/bevy_ecs/src/system/mod.rs | 8 +- crates/bevy_ecs/src/system/system.rs | 6 +- crates/bevy_ecs/src/system/system_param.rs | 40 ++-- crates/bevy_ecs/src/world/entity_ref.rs | 146 ++++++------ crates/bevy_ecs/src/world/mod.rs | 219 ++++++++---------- crates/bevy_ecs/src/world/spawn_batch.rs | 4 +- .../bevy_ecs/src/world/unsafe_world_cell.rs | 96 ++++---- crates/bevy_ecs/src/world/world_cell.rs | 2 +- .../bevy_scene/src/dynamic_scene_builder.rs | 4 +- examples/ecs/dynamic.rs | 12 +- 32 files changed, 596 insertions(+), 686 deletions(-) diff --git a/crates/bevy_core/src/lib.rs b/crates/bevy_core/src/lib.rs index eff6851e30457..d8c0467cf8626 100644 --- a/crates/bevy_core/src/lib.rs +++ b/crates/bevy_core/src/lib.rs @@ -19,7 +19,7 @@ pub mod prelude { } use bevy_app::prelude::*; -use bevy_ecs::component::{ComponentId, ComponentTicks, Tick}; +use bevy_ecs::component::{ComponentTicks, DataId, Tick}; use bevy_ecs::prelude::*; use bevy_reflect::{ReflectDeserialize, ReflectSerialize}; use bevy_utils::{Duration, HashSet, Instant, Uuid}; @@ -49,7 +49,7 @@ impl Plugin for TypeRegistrationPlugin { fn register_ecs_types(app: &mut App) { app.register_type::() - .register_type::() + .register_type::() .register_type::() .register_type::(); } diff --git a/crates/bevy_ecs/macros/src/lib.rs b/crates/bevy_ecs/macros/src/lib.rs index 43b1fe6591324..f67e95c1e49e9 100644 --- a/crates/bevy_ecs/macros/src/lib.rs +++ b/crates/bevy_ecs/macros/src/lib.rs @@ -120,14 +120,14 @@ 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 + // - DataId is returned in field-definition-order. [from_components] and [get_components] use 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 { fn component_ids( - components: &mut #ecs_path::component::Components, + components: &mut #ecs_path::component::WorldData, storages: &mut #ecs_path::storage::Storages, - ids: &mut impl FnMut(#ecs_path::component::ComponentId) + ids: &mut impl FnMut(#ecs_path::component::DataId) ){ #(#field_component_ids)* } @@ -204,7 +204,7 @@ pub fn impl_param_set(_input: TokenStream) -> TokenStream { where #(#param: ReadOnlySystemParam,)* { } - // SAFETY: Relevant parameter ComponentId and ArchetypeComponentId access is applied to SystemMeta. If any ParamState conflicts + // SAFETY: Relevant parameter DataId and ArchetypeComponentId access is applied to SystemMeta. If any ParamState conflicts // with any prior access, a panic will occur. unsafe impl<'_w, '_s, #(#param: SystemParam,)*> SystemParam for ParamSet<'_w, '_s, (#(#param,)*)> { diff --git a/crates/bevy_ecs/macros/src/world_query.rs b/crates/bevy_ecs/macros/src/world_query.rs index 0206b10d8c669..c6b3fed569fbf 100644 --- a/crates/bevy_ecs/macros/src/world_query.rs +++ b/crates/bevy_ecs/macros/src/world_query.rs @@ -160,7 +160,7 @@ pub(crate) fn world_query_impl( } } - fn update_component_access(state: &Self::State, _access: &mut #path::query::FilteredAccess<#path::component::ComponentId>) { + fn update_component_access(state: &Self::State, _access: &mut #path::query::FilteredAccess<#path::component::DataId>) { #( <#field_types>::update_component_access(&state.#named_field_idents, _access); )* } @@ -176,7 +176,7 @@ pub(crate) fn world_query_impl( }) } - fn matches_component_set(state: &Self::State, _set_contains_id: &impl Fn(#path::component::ComponentId) -> bool) -> bool { + fn matches_component_set(state: &Self::State, _set_contains_id: &impl Fn(#path::component::DataId) -> bool) -> bool { true #(&& <#field_types>::matches_component_set(&state.#named_field_idents, _set_contains_id))* } } diff --git a/crates/bevy_ecs/src/archetype.rs b/crates/bevy_ecs/src/archetype.rs index d6a67d8fffd4b..5a32b477605d8 100644 --- a/crates/bevy_ecs/src/archetype.rs +++ b/crates/bevy_ecs/src/archetype.rs @@ -21,7 +21,7 @@ use crate::{ bundle::BundleId, - component::{ComponentId, StorageType}, + component::{DataId, StorageType}, entity::{Entity, EntityLocation}, storage::{ImmutableSparseSet, SparseArray, SparseSet, SparseSetIndex, TableId, TableRow}, }; @@ -309,15 +309,15 @@ pub struct Archetype { table_id: TableId, edges: Edges, entities: Vec, - components: ImmutableSparseSet, + components: ImmutableSparseSet, } impl Archetype { pub(crate) fn new( id: ArchetypeId, table_id: TableId, - table_components: impl Iterator, - sparse_set_components: impl Iterator, + table_components: impl Iterator, + sparse_set_components: impl Iterator, ) -> Self { let (min_table, _) = table_components.size_hint(); let (min_sparse, _) = sparse_set_components.size_hint(); @@ -376,7 +376,7 @@ impl Archetype { /// /// [`Table`]: crate::storage::Table #[inline] - pub fn table_components(&self) -> impl Iterator + '_ { + pub fn table_components(&self) -> impl Iterator + '_ { self.components .iter() .filter(|(_, component)| component.storage_type == StorageType::Table) @@ -389,7 +389,7 @@ impl Archetype { /// /// [`ComponentSparseSet`]: crate::storage::ComponentSparseSet #[inline] - pub fn sparse_set_components(&self) -> impl Iterator + '_ { + pub fn sparse_set_components(&self) -> impl Iterator + '_ { self.components .iter() .filter(|(_, component)| component.storage_type == StorageType::SparseSet) @@ -400,7 +400,7 @@ impl Archetype { /// /// All of the IDs are unique. #[inline] - pub fn components(&self) -> impl Iterator + '_ { + pub fn components(&self) -> impl Iterator + '_ { self.components.indices() } @@ -505,7 +505,7 @@ impl Archetype { /// Checks if the archetype contains a specific component. This runs in `O(1)` time. #[inline] - pub fn contains(&self, component_id: ComponentId) -> bool { + pub fn contains(&self, component_id: DataId) -> bool { self.components.contains(component_id) } @@ -513,7 +513,7 @@ impl Archetype { /// Returns `None` if the component is not part of the archetype. /// This runs in `O(1)` time. #[inline] - pub fn get_storage_type(&self, component_id: ComponentId) -> Option { + pub fn get_storage_type(&self, component_id: DataId) -> Option { self.components .get(component_id) .map(|info| info.storage_type) @@ -523,10 +523,7 @@ impl Archetype { /// Returns `None` if the component is not part of the archetype. /// This runs in `O(1)` time. #[inline] - pub fn get_archetype_component_id( - &self, - component_id: ComponentId, - ) -> Option { + pub fn get_archetype_component_id(&self, component_id: DataId) -> Option { self.components .get(component_id) .map(|info| info.archetype_component_id) @@ -555,8 +552,8 @@ impl ArchetypeGeneration { #[derive(Hash, PartialEq, Eq)] struct ArchetypeComponents { - table_components: Box<[ComponentId]>, - sparse_set_components: Box<[ComponentId]>, + table_components: Box<[DataId]>, + sparse_set_components: Box<[DataId]>, } /// An opaque unique joint ID for a [`Component`] in an [`Archetype`] within a [`World`]. @@ -566,10 +563,10 @@ struct ArchetypeComponents { /// schedulers to opportunistically run multiple systems in parallel that would otherwise /// conflict. For example, `Query<&mut A, With>` and `Query<&mut A, Without>` can run in /// parallel as the matched `ArchetypeComponentId` sets for both queries are disjoint, even -/// though `&mut A` on both queries point to the same [`ComponentId`]. +/// though `&mut A` on both queries point to the same [`DataId`]. /// /// In SQL terms, these IDs are composite keys on a [many-to-many relationship] between archetypes -/// and components. Each component type will have only one [`ComponentId`], but may have many +/// and components. Each component type will have only one [`DataId`], but may have many /// [`ArchetypeComponentId`]s, one for every archetype the component is present in. Likewise, each /// archetype will have only one [`ArchetypeId`] but may have many [`ArchetypeComponentId`]s, one /// for each component that belongs to the archetype. @@ -714,8 +711,8 @@ impl Archetypes { pub(crate) fn get_id_or_insert( &mut self, table_id: TableId, - table_components: Vec, - sparse_set_components: Vec, + table_components: Vec, + sparse_set_components: Vec, ) -> ArchetypeId { let archetype_identity = ArchetypeComponents { sparse_set_components: sparse_set_components.clone().into_boxed_slice(), diff --git a/crates/bevy_ecs/src/bundle.rs b/crates/bevy_ecs/src/bundle.rs index 35ba1ca9ddbb2..4147feb4b10c5 100644 --- a/crates/bevy_ecs/src/bundle.rs +++ b/crates/bevy_ecs/src/bundle.rs @@ -10,7 +10,7 @@ use crate::{ Archetype, ArchetypeId, Archetypes, BundleComponentStatus, ComponentStatus, SpawnBundleStatus, }, - component::{Component, ComponentId, ComponentStorage, Components, StorageType, Tick}, + component::{Component, ComponentStorage, DataId, StorageType, Tick, WorldData}, entity::{Entities, Entity, EntityLocation}, query::DebugCheckedUnwrap, storage::{SparseSetIndex, SparseSets, Storages, Table, TableRow}, @@ -134,17 +134,17 @@ use std::any::TypeId; /// /// [`Query`]: crate::system::Query // Some safety points: -// - [`Bundle::component_ids`] must return the [`ComponentId`] for each component type in the +// - [`Bundle::component_ids`] must return the [`DataId`] for each component type in the // bundle, in the _exact_ order that [`DynamicBundle::get_components`] is called. -// - [`Bundle::from_components`] must call `func` exactly once for each [`ComponentId`] returned by +// - [`Bundle::from_components`] must call `func` exactly once for each [`DataId`] returned by // [`Bundle::component_ids`]. 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, + components: &mut WorldData, storages: &mut Storages, - ids: &mut impl FnMut(ComponentId), + ids: &mut impl FnMut(DataId), ); /// Calls `func`, which should return data for each component in the bundle, in the order of @@ -179,9 +179,9 @@ pub trait DynamicBundle { // - `Bundle::from_components` calls `func` exactly once for C, which is the exact value returned by `Bundle::component_ids`. unsafe impl Bundle for C { fn component_ids( - components: &mut Components, + components: &mut WorldData, storages: &mut Storages, - ids: &mut impl FnMut(ComponentId), + ids: &mut impl FnMut(DataId), ) { ids(components.init_component::(storages)); } @@ -209,12 +209,12 @@ macro_rules! tuple_impl { // SAFETY: // - `Bundle::component_ids` calls `ids` for each component type in the // bundle, in the exact order that `DynamicBundle::get_components` is called. - // - `Bundle::from_components` calls `func` exactly once for each `ComponentId` returned by `Bundle::component_ids`. + // - `Bundle::from_components` calls `func` exactly once for each `DataId` returned by `Bundle::component_ids`. // - `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,)*) { #[allow(unused_variables)] - fn component_ids(components: &mut Components, storages: &mut Storages, ids: &mut impl FnMut(ComponentId)){ + fn component_ids(components: &mut WorldData, storages: &mut Storages, ids: &mut impl FnMut(DataId)){ $(<$name as Bundle>::component_ids(components, storages, ids);)* } @@ -282,7 +282,7 @@ pub struct BundleInfo { // SAFETY: Every ID in this list must be valid within the World that owns the BundleInfo, // must have its storage initialized (i.e. columns created in tables, sparse set created), // and must be in the same order as the source bundle type writes its components in. - component_ids: Vec, + component_ids: Vec, } impl BundleInfo { @@ -295,8 +295,8 @@ impl BundleInfo { // and must be in the same order as the source bundle type writes its components in. unsafe fn new( bundle_type_name: &'static str, - components: &Components, - component_ids: Vec, + components: &WorldData, + component_ids: Vec, id: BundleId, ) -> BundleInfo { let mut deduped = component_ids.clone(); @@ -338,9 +338,9 @@ impl BundleInfo { self.id } - /// Returns the [ID](ComponentId) of each component stored in this bundle. + /// Returns the [`ID`](DataId) of each component stored in this bundle. #[inline] - pub fn components(&self) -> &[ComponentId] { + pub fn components(&self) -> &[DataId] { &self.component_ids } @@ -348,7 +348,7 @@ impl BundleInfo { &'b self, entities: &'a mut Entities, archetypes: &'a mut Archetypes, - components: &Components, + components: &WorldData, storages: &'a mut Storages, archetype_id: ArchetypeId, change_tick: Tick, @@ -408,7 +408,7 @@ impl BundleInfo { &'b self, entities: &'a mut Entities, archetypes: &'a mut Archetypes, - components: &Components, + components: &WorldData, storages: &'a mut Storages, change_tick: Tick, ) -> BundleSpawner<'a, 'b> { @@ -494,7 +494,7 @@ impl BundleInfo { &self, archetypes: &mut Archetypes, storages: &mut Storages, - components: &Components, + components: &WorldData, archetype_id: ArchetypeId, ) -> ArchetypeId { if let Some(add_bundle_id) = archetypes[archetype_id].edges().get_add_bundle(self.id) { @@ -799,9 +799,9 @@ pub struct Bundles { /// Cache static [`BundleId`] bundle_ids: TypeIdMap, /// Cache dynamic [`BundleId`] with multiple components - dynamic_bundle_ids: HashMap, (BundleId, Vec)>, + dynamic_bundle_ids: HashMap, (BundleId, Vec)>, /// Cache optimized dynamic [`BundleId`] with single component - dynamic_component_bundle_ids: HashMap, + dynamic_component_bundle_ids: HashMap, } impl Bundles { @@ -823,7 +823,7 @@ impl Bundles { /// Initializes a new [`BundleInfo`] for a statically known type. pub(crate) fn init_info<'a, T: Bundle>( &'a mut self, - components: &mut Components, + components: &mut WorldData, storages: &mut Storages, ) -> &'a BundleInfo { let bundle_infos = &mut self.bundle_infos; @@ -848,12 +848,12 @@ impl Bundles { /// /// # Panics /// - /// Panics if any of the provided [`ComponentId`]s do not exist in the - /// provided [`Components`]. + /// Panics if any of the provided [`DataId`]s do not exist in the + /// provided [`WorldData`]. pub(crate) fn init_dynamic_info( &mut self, - components: &Components, - component_ids: &[ComponentId], + components: &WorldData, + component_ids: &[DataId], ) -> (&BundleInfo, &Vec) { let bundle_infos = &mut self.bundle_infos; @@ -879,11 +879,11 @@ impl Bundles { /// /// # Panics /// - /// Panics if the provided [`ComponentId`] does not exist in the provided [`Components`]. + /// Panics if the provided [`DataId`] does not exist in the provided [`WorldData`]. pub(crate) fn init_component_info( &mut self, - components: &Components, - component_id: ComponentId, + components: &WorldData, + component_id: DataId, ) -> (&BundleInfo, StorageType) { let bundle_infos = &mut self.bundle_infos; let (bundle_id, storage_types) = self @@ -903,12 +903,12 @@ impl Bundles { } } -/// Asserts that all components are part of [`Components`] +/// Asserts that all components are part of [`WorldData`] /// and initializes a [`BundleInfo`]. fn initialize_dynamic_bundle( bundle_infos: &mut Vec, - components: &Components, - component_ids: Vec, + components: &WorldData, + component_ids: Vec, ) -> (BundleId, Vec) { // Assert component existence let storage_types = component_ids.iter().map(|&id| { diff --git a/crates/bevy_ecs/src/component.rs b/crates/bevy_ecs/src/component.rs index dcf76efd24fe3..63400797c40d7 100644 --- a/crates/bevy_ecs/src/component.rs +++ b/crates/bevy_ecs/src/component.rs @@ -205,15 +205,15 @@ pub enum StorageType { /// Stores metadata for a type of component or resource stored in a specific [`World`]. #[derive(Debug, Clone)] -pub struct ComponentInfo { - id: ComponentId, - descriptor: ComponentDescriptor, +pub struct DataInfo { + id: DataId, + descriptor: DataDescriptor, } -impl ComponentInfo { +impl DataInfo { /// Returns a value uniquely identifying the current component. #[inline] - pub fn id(&self) -> ComponentId { + pub fn id(&self) -> DataId { self.id } @@ -262,8 +262,8 @@ impl ComponentInfo { } /// Create a new [`ComponentInfo`]. - pub(crate) fn new(id: ComponentId, descriptor: ComponentDescriptor) -> Self { - ComponentInfo { id, descriptor } + pub(crate) fn new(id: DataId, descriptor: DataDescriptor) -> Self { + DataInfo { id, descriptor } } } @@ -273,37 +273,37 @@ impl ComponentInfo { /// Each time a new `Component` type is registered within a `World` using /// [`World::init_component`](World::init_component) or /// [`World::init_component_with_descriptor`](World::init_component_with_descriptor), -/// a corresponding `ComponentId` is created to track it. +/// a corresponding `DataId` is created to track it. /// -/// While the distinction between `ComponentId` and [`TypeId`] may seem superficial, breaking them +/// While the distinction between `DataId` and [`TypeId`] may seem superficial, breaking them /// into two separate but related concepts allows components to exist outside of Rust's type system. -/// Each Rust type registered as a `Component` will have a corresponding `ComponentId`, but additional -/// `ComponentId`s may exist in a `World` to track components which cannot be +/// Each Rust type registered as a `Component` will have a corresponding `DataId`, but additional +/// `DataId`s may exist in a `World` to track components which cannot be /// represented as Rust types for scripting or other advanced use-cases. /// -/// A `ComponentId` is tightly coupled to its parent `World`. Attempting to use a `ComponentId` from +/// A `DataId` is tightly coupled to its parent `World`. Attempting to use a `DataId` from /// one `World` to access the metadata of a `Component` in a different `World` is undefined behavior /// and must not be attempted. /// -/// Given a type `T` which implements [`Component`], the `ComponentId` for `T` can be retrieved -/// from a `World` using [`World::component_id()`] or via [`Components::component_id()`]. Access -/// to the `ComponentId` for a [`Resource`] is available via [`Components::resource_id()`]. +/// Given a type `T` which implements [`Component`], the `DataId` for `T` can be retrieved +/// from a `World` using [`World::component_id()`] or via [`WorldData::component_id()`]. Access +/// to the `DataId` for a [`Resource`] is available via [`WorldData::resource_id()`]. #[derive(Debug, Copy, Clone, Hash, Ord, PartialOrd, Eq, PartialEq)] #[cfg_attr( feature = "bevy_reflect", derive(Reflect), reflect(Debug, Hash, PartialEq) )] -pub struct ComponentId(usize); +pub struct DataId(usize); -impl ComponentId { - /// Creates a new [`ComponentId`]. +impl DataId { + /// Creates a new [`DataId`]. /// /// The `index` is a unique value associated with each type of component in a given world. /// Usually, this value is taken from a counter incremented for each type of component registered with the world. #[inline] - pub const fn new(index: usize) -> ComponentId { - ComponentId(index) + pub const fn new(index: usize) -> DataId { + DataId(index) } /// Returns the index of the current component. @@ -313,7 +313,7 @@ impl ComponentId { } } -impl SparseSetIndex for ComponentId { +impl SparseSetIndex for DataId { #[inline] fn sparse_set_index(&self) -> usize { self.index() @@ -327,7 +327,7 @@ impl SparseSetIndex for ComponentId { /// A value describing a component or resource, which may or may not correspond to a Rust type. #[derive(Clone)] -pub struct ComponentDescriptor { +pub struct DataDescriptor { name: Cow<'static, str>, // SAFETY: This must remain private. It must match the statically known StorageType of the // associated rust component type if one exists. @@ -344,7 +344,7 @@ pub struct ComponentDescriptor { } // We need to ignore the `drop` field in our `Debug` impl -impl std::fmt::Debug for ComponentDescriptor { +impl std::fmt::Debug for DataDescriptor { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("ComponentDescriptor") .field("name", &self.name) @@ -356,7 +356,7 @@ impl std::fmt::Debug for ComponentDescriptor { } } -impl ComponentDescriptor { +impl DataDescriptor { // SAFETY: The pointer points to a valid value of type `T` and it is safe to drop this value. unsafe fn drop_ptr(x: OwningPtr<'_>) { x.drop_as::(); @@ -444,32 +444,32 @@ impl ComponentDescriptor { /// Stores metadata associated with each kind of [`Component`] in a given [`World`]. #[derive(Debug, Default)] -pub struct Components { - components: Vec, - indices: TypeIdMap, - resource_indices: TypeIdMap, +pub struct WorldData { + data_info: Vec, + indices: TypeIdMap, + resource_indices: TypeIdMap, } -impl Components { +impl WorldData { /// Initializes a component of type `T` with this instance. /// If a component of this type has already been initialized, this will return /// the ID of the pre-existing component. /// /// # See also /// - /// * [`Components::component_id()`] - /// * [`Components::init_component_with_descriptor()`] + /// * [`WorldData::component_id()`] + /// * [`WorldData::init_component_with_descriptor()`] #[inline] - pub fn init_component(&mut self, storages: &mut Storages) -> ComponentId { + pub fn init_component(&mut self, storages: &mut Storages) -> DataId { let type_id = TypeId::of::(); - let Components { + let WorldData { indices, - components, + data_info: components, .. } = self; *indices.entry(type_id).or_insert_with(|| { - Components::init_component_inner(components, storages, ComponentDescriptor::new::()) + WorldData::init_component_inner(components, storages, DataDescriptor::new::()) }) } @@ -477,88 +477,88 @@ impl Components { /// /// ## Note /// - /// If this method is called multiple times with identical descriptors, a distinct `ComponentId` + /// If this method is called multiple times with identical descriptors, a distinct `DataId` /// will be created for each one. /// /// # See also /// - /// * [`Components::component_id()`] - /// * [`Components::init_component()`] + /// * [`WorldData::component_id()`] + /// * [`WorldData::init_component()`] pub fn init_component_with_descriptor( &mut self, storages: &mut Storages, - descriptor: ComponentDescriptor, - ) -> ComponentId { - Components::init_component_inner(&mut self.components, storages, descriptor) + descriptor: DataDescriptor, + ) -> DataId { + WorldData::init_component_inner(&mut self.data_info, storages, descriptor) } #[inline] fn init_component_inner( - components: &mut Vec, + data_info: &mut Vec, storages: &mut Storages, - descriptor: ComponentDescriptor, - ) -> ComponentId { - let component_id = ComponentId(components.len()); - let info = ComponentInfo::new(component_id, descriptor); + descriptor: DataDescriptor, + ) -> DataId { + let data_id = DataId(data_info.len()); + let info = DataInfo::new(data_id, descriptor); if info.descriptor.storage_type == StorageType::SparseSet { storages.sparse_sets.get_or_insert(&info); } - components.push(info); - component_id + data_info.push(info); + data_id } /// Returns the number of components registered with this instance. #[inline] pub fn len(&self) -> usize { - self.components.len() + self.data_info.len() } /// Returns `true` if there are no components registered with this instance. Otherwise, this returns `false`. #[inline] pub fn is_empty(&self) -> bool { - self.components.len() == 0 + self.data_info.len() == 0 } /// Gets the metadata associated with the given component. /// /// This will return an incorrect result if `id` did not come from the same world as `self`. It may return `None` or a garbage value. #[inline] - pub fn get_info(&self, id: ComponentId) -> Option<&ComponentInfo> { - self.components.get(id.0) + pub fn get_info(&self, id: DataId) -> Option<&DataInfo> { + self.data_info.get(id.0) } /// Returns the name associated with the given component. /// /// This will return an incorrect result if `id` did not come from the same world as `self`. It may return `None` or a garbage value. #[inline] - pub fn get_name(&self, id: ComponentId) -> Option<&str> { + pub fn get_name(&self, id: DataId) -> Option<&str> { self.get_info(id).map(|descriptor| descriptor.name()) } /// Gets the metadata associated with the given component. /// # Safety /// - /// `id` must be a valid [`ComponentId`] + /// `id` must be a valid [`DataId`] #[inline] - pub unsafe fn get_info_unchecked(&self, id: ComponentId) -> &ComponentInfo { - debug_assert!(id.index() < self.components.len()); - self.components.get_unchecked(id.0) + pub unsafe fn get_info_unchecked(&self, id: DataId) -> &DataInfo { + debug_assert!(id.index() < self.data_info.len()); + self.data_info.get_unchecked(id.0) } - /// Type-erased equivalent of [`Components::component_id()`]. + /// Type-erased equivalent of [`WorldData::component_id()`]. #[inline] - pub fn get_id(&self, type_id: TypeId) -> Option { + pub fn get_id(&self, type_id: TypeId) -> Option { self.indices.get(&type_id).copied() } - /// Returns the [`ComponentId`] of the given [`Component`] type `T`. + /// Returns the [`DataId`] of the given [`Component`] type `T`. /// - /// The returned `ComponentId` is specific to the `Components` instance - /// it was retrieved from and should not be used with another `Components` + /// The returned `DataId` is specific to the `WorldData` instance + /// it was retrieved from and should not be used with another `WorldData` /// instance. /// /// Returns [`None`] if the `Component` type has not - /// yet been initialized using [`Components::init_component()`]. + /// yet been initialized using [`WorldData::init_component()`]. /// /// ``` /// use bevy_ecs::prelude::*; @@ -575,28 +575,28 @@ impl Components { /// /// # See also /// - /// * [`Components::get_id()`] - /// * [`Components::resource_id()`] + /// * [`WorldData::get_id()`] + /// * [`WorldData::resource_id()`] /// * [`World::component_id()`] #[inline] - pub fn component_id(&self) -> Option { + pub fn component_id(&self) -> Option { self.get_id(TypeId::of::()) } - /// Type-erased equivalent of [`Components::resource_id()`]. + /// Type-erased equivalent of [`WorldData::resource_id()`]. #[inline] - pub fn get_resource_id(&self, type_id: TypeId) -> Option { + pub fn get_resource_id(&self, type_id: TypeId) -> Option { self.resource_indices.get(&type_id).copied() } - /// Returns the [`ComponentId`] of the given [`Resource`] type `T`. + /// Returns the [`DataId`] of the given [`Resource`] type `T`. /// - /// The returned `ComponentId` is specific to the `Components` instance - /// it was retrieved from and should not be used with another `Components` + /// The returned `DataId` is specific to the `WorldData` instance + /// it was retrieved from and should not be used with another `WorldData` /// instance. /// /// Returns [`None`] if the `Resource` type has not - /// yet been initialized using [`Components::init_resource()`]. + /// yet been initialized using [`WorldData::init_resource()`]. /// /// ``` /// use bevy_ecs::prelude::*; @@ -613,10 +613,10 @@ impl Components { /// /// # See also /// - /// * [`Components::component_id()`] - /// * [`Components::get_resource_id()`] + /// * [`WorldData::component_id()`] + /// * [`WorldData::get_resource_id()`] #[inline] - pub fn resource_id(&self) -> Option { + pub fn resource_id(&self) -> Option { self.get_resource_id(TypeId::of::()) } @@ -626,13 +626,13 @@ impl Components { /// /// # See also /// - /// * [`Components::resource_id()`] + /// * [`WorldData::resource_id()`] #[inline] - pub fn init_resource(&mut self) -> ComponentId { + pub fn init_resource(&mut self) -> DataId { // SAFETY: The [`ComponentDescriptor`] matches the [`TypeId`] unsafe { self.get_or_insert_resource_with(TypeId::of::(), || { - ComponentDescriptor::new_resource::() + DataDescriptor::new_resource::() }) } } @@ -641,11 +641,11 @@ impl Components { /// If a resource of this type has already been initialized, this will return /// the ID of the pre-existing resource. #[inline] - pub fn init_non_send(&mut self) -> ComponentId { + pub fn init_non_send(&mut self) -> DataId { // SAFETY: The [`ComponentDescriptor`] matches the [`TypeId`] unsafe { self.get_or_insert_resource_with(TypeId::of::(), || { - ComponentDescriptor::new_non_send::(StorageType::default()) + DataDescriptor::new_non_send::(StorageType::default()) }) } } @@ -657,20 +657,20 @@ impl Components { unsafe fn get_or_insert_resource_with( &mut self, type_id: TypeId, - func: impl FnOnce() -> ComponentDescriptor, - ) -> ComponentId { - let components = &mut self.components; + func: impl FnOnce() -> DataDescriptor, + ) -> DataId { + let components = &mut self.data_info; *self.resource_indices.entry(type_id).or_insert_with(|| { let descriptor = func(); - let component_id = ComponentId(components.len()); - components.push(ComponentInfo::new(component_id, descriptor)); + let component_id = DataId(components.len()); + components.push(DataInfo::new(component_id, descriptor)); component_id }) } /// Gets an iterator over all components registered with this instance. - pub fn iter(&self) -> impl Iterator + '_ { - self.components.iter() + pub fn iter(&self) -> impl Iterator + '_ { + self.data_info.iter() } } @@ -829,53 +829,53 @@ impl ComponentTicks { } } -/// A [`SystemParam`] that provides access to the [`ComponentId`] for a specific type. +/// A [`SystemParam`] that provides access to the [`DataId`] for a specific type. /// /// # Example /// ``` -/// # use bevy_ecs::{system::Local, component::{Component, ComponentId, ComponentIdFor}}; +/// # use bevy_ecs::{system::Local, component::{Component, DataId, ComponentIdFor}}; /// #[derive(Component)] /// struct Player; /// fn my_system(component_id: ComponentIdFor) { -/// let component_id: ComponentId = component_id.get(); +/// let component_id: DataId = component_id.get(); /// // ... /// } /// ``` #[derive(SystemParam)] -pub struct ComponentIdFor<'s, T: Component>(Local<'s, InitComponentId>); +pub struct ComponentIdFor<'s, T: Component>(Local<'s, InitDataId>); impl ComponentIdFor<'_, T> { - /// Gets the [`ComponentId`] for the type `T`. + /// Gets the [`DataId`] for the type `T`. #[inline] - pub fn get(&self) -> ComponentId { + pub fn get(&self) -> DataId { **self } } impl std::ops::Deref for ComponentIdFor<'_, T> { - type Target = ComponentId; + type Target = DataId; fn deref(&self) -> &Self::Target { - &self.0.component_id + &self.0.data_id } } -impl From> for ComponentId { +impl From> for DataId { #[inline] - fn from(to_component_id: ComponentIdFor) -> ComponentId { + fn from(to_component_id: ComponentIdFor) -> DataId { *to_component_id } } -/// Initializes the [`ComponentId`] for a specific type when used with [`FromWorld`]. -struct InitComponentId { - component_id: ComponentId, +/// Initializes the [`DataId`] for a specific type when used with [`FromWorld`]. +struct InitDataId { + data_id: DataId, marker: PhantomData, } -impl FromWorld for InitComponentId { +impl FromWorld for InitDataId { fn from_world(world: &mut World) -> Self { Self { - component_id: world.init_component::(), + data_id: world.init_component::(), marker: PhantomData, } } diff --git a/crates/bevy_ecs/src/lib.rs b/crates/bevy_ecs/src/lib.rs index 3cd89b77e2b93..5933542567ab3 100644 --- a/crates/bevy_ecs/src/lib.rs +++ b/crates/bevy_ecs/src/lib.rs @@ -61,7 +61,7 @@ mod tests { use crate::{ bundle::Bundle, change_detection::Ref, - component::{Component, ComponentId}, + component::{Component, DataId}, entity::Entity, query::{Added, Changed, FilteredAccess, QueryFilter, With, Without}, system::Resource, @@ -147,7 +147,7 @@ mod tests { } let mut ids = Vec::new(); ::component_ids( - &mut world.components, + &mut world.world_data, &mut world.storages, &mut |id| { ids.push(id); @@ -201,7 +201,7 @@ mod tests { let mut ids = Vec::new(); ::component_ids( - &mut world.components, + &mut world.world_data, &mut world.storages, &mut |id| { ids.push(id); @@ -257,7 +257,7 @@ mod tests { let mut ids = Vec::new(); ::component_ids( - &mut world.components, + &mut world.world_data, &mut world.storages, &mut |id| { ids.push(id); @@ -1372,14 +1372,14 @@ mod tests { let mut world = World::new(); let query = world.query_filtered::<&mut A, Changed>(); - let mut expected = FilteredAccess::::default(); - let a_id = world.components.get_id(TypeId::of::()).unwrap(); - let b_id = world.components.get_id(TypeId::of::()).unwrap(); + let mut expected = FilteredAccess::::default(); + let a_id = world.world_data.get_id(TypeId::of::()).unwrap(); + let b_id = world.world_data.get_id(TypeId::of::()).unwrap(); expected.add_write(a_id); expected.add_read(b_id); assert!( query.component_access.eq(&expected), - "ComponentId access from query fetch and query filter should be combined" + "DataId access from query fetch and query filter should be combined" ); } diff --git a/crates/bevy_ecs/src/query/access.rs b/crates/bevy_ecs/src/query/access.rs index d7253f073ed7f..69831cdacd604 100644 --- a/crates/bevy_ecs/src/query/access.rs +++ b/crates/bevy_ecs/src/query/access.rs @@ -19,7 +19,7 @@ use std::marker::PhantomData; /// the set. With `FormattedBitSet`, we convert the present set entries into /// what they stand for, it is much clearer what is going on: /// ```text -/// read_and_writes: [ ComponentId(5), ComponentId(7) ] +/// read_and_writes: [ DataId(5), DataId(7) ] /// ``` struct FormattedBitSet<'a, T: SparseSetIndex> { bit_set: &'a FixedBitSet, diff --git a/crates/bevy_ecs/src/query/builder.rs b/crates/bevy_ecs/src/query/builder.rs index 67db644a4fcb4..32ace4eabca83 100644 --- a/crates/bevy_ecs/src/query/builder.rs +++ b/crates/bevy_ecs/src/query/builder.rs @@ -1,6 +1,6 @@ use std::marker::PhantomData; -use crate::{component::ComponentId, prelude::*}; +use crate::{component::DataId, prelude::*}; use super::{FilteredAccess, QueryData, QueryFilter}; @@ -33,7 +33,7 @@ use super::{FilteredAccess, QueryData, QueryFilter}; /// let (entity, b) = query.single(&world); ///``` pub struct QueryBuilder<'w, D: QueryData = (), F: QueryFilter = ()> { - access: FilteredAccess, + access: FilteredAccess, world: &'w mut World, or: bool, first: bool, @@ -79,7 +79,7 @@ impl<'w, D: QueryData, F: QueryFilter> QueryBuilder<'w, D, F> { } /// Adds access to self's underlying [`FilteredAccess`] respecting [`Self::or`] and [`Self::and`] - pub fn extend_access(&mut self, mut access: FilteredAccess) { + pub fn extend_access(&mut self, mut access: FilteredAccess) { if self.or { if self.first { access.required.clear(); @@ -117,8 +117,8 @@ impl<'w, D: QueryData, F: QueryFilter> QueryBuilder<'w, D, F> { self } - /// Adds [`With`] to the [`FilteredAccess`] of self from a runtime [`ComponentId`]. - pub fn with_id(&mut self, id: ComponentId) -> &mut Self { + /// Adds [`With`] to the [`FilteredAccess`] of self from a runtime [`DataId`]. + pub fn with_id(&mut self, id: DataId) -> &mut Self { let mut access = FilteredAccess::default(); access.and_with(id); self.extend_access(access); @@ -131,8 +131,8 @@ impl<'w, D: QueryData, F: QueryFilter> QueryBuilder<'w, D, F> { self } - /// Adds [`Without`] to the [`FilteredAccess`] of self from a runtime [`ComponentId`]. - pub fn without_id(&mut self, id: ComponentId) -> &mut Self { + /// Adds [`Without`] to the [`FilteredAccess`] of self from a runtime [`DataId`]. + pub fn without_id(&mut self, id: DataId) -> &mut Self { let mut access = FilteredAccess::default(); access.and_without(id); self.extend_access(access); @@ -140,14 +140,14 @@ impl<'w, D: QueryData, F: QueryFilter> QueryBuilder<'w, D, F> { } /// Adds `&T` to the [`FilteredAccess`] of self. - pub fn ref_id(&mut self, id: ComponentId) -> &mut Self { + pub fn ref_id(&mut self, id: DataId) -> &mut Self { self.with_id(id); self.access.add_read(id); self } /// Adds `&mut T` to the [`FilteredAccess`] of self. - pub fn mut_id(&mut self, id: ComponentId) -> &mut Self { + pub fn mut_id(&mut self, id: DataId) -> &mut Self { self.with_id(id); self.access.add_write(id); self @@ -205,7 +205,7 @@ impl<'w, D: QueryData, F: QueryFilter> QueryBuilder<'w, D, F> { } /// Returns a reference to the the [`FilteredAccess`] that will be provided to the built [`Query`]. - pub fn access(&self) -> &FilteredAccess { + pub fn access(&self) -> &FilteredAccess { &self.access } diff --git a/crates/bevy_ecs/src/query/fetch.rs b/crates/bevy_ecs/src/query/fetch.rs index 5e83637d33019..fbe7a0851575c 100644 --- a/crates/bevy_ecs/src/query/fetch.rs +++ b/crates/bevy_ecs/src/query/fetch.rs @@ -1,7 +1,7 @@ use crate::{ archetype::Archetype, change_detection::{Ticks, TicksMut}, - component::{Component, ComponentId, ComponentStorage, StorageType, Tick}, + component::{Component, ComponentStorage, DataId, StorageType, Tick}, entity::Entity, query::{Access, DebugCheckedUnwrap, FilteredAccess, WorldQuery}, storage::{ComponentSparseSet, Table, TableRow}, @@ -321,7 +321,7 @@ unsafe impl WorldQuery for Entity { entity } - fn update_component_access(_state: &Self::State, _access: &mut FilteredAccess) {} + fn update_component_access(_state: &Self::State, _access: &mut FilteredAccess) {} fn init_state(_world: &mut World) {} @@ -331,7 +331,7 @@ unsafe impl WorldQuery for Entity { fn matches_component_set( _state: &Self::State, - _set_contains_id: &impl Fn(ComponentId) -> bool, + _set_contains_id: &impl Fn(DataId) -> bool, ) -> bool { true } @@ -394,7 +394,7 @@ unsafe impl<'a> WorldQuery for EntityRef<'a> { EntityRef::new(cell) } - fn update_component_access(_state: &Self::State, access: &mut FilteredAccess) { + fn update_component_access(_state: &Self::State, access: &mut FilteredAccess) { assert!( !access.access().has_any_write(), "EntityRef conflicts with a previous access in this query. Shared access cannot coincide with exclusive access.", @@ -410,7 +410,7 @@ unsafe impl<'a> WorldQuery for EntityRef<'a> { fn matches_component_set( _state: &Self::State, - _set_contains_id: &impl Fn(ComponentId) -> bool, + _set_contains_id: &impl Fn(DataId) -> bool, ) -> bool { true } @@ -470,7 +470,7 @@ unsafe impl<'a> WorldQuery for EntityMut<'a> { EntityMut::new(cell) } - fn update_component_access(_state: &Self::State, access: &mut FilteredAccess) { + fn update_component_access(_state: &Self::State, access: &mut FilteredAccess) { assert!( !access.access().has_any_read(), "EntityMut conflicts with a previous access in this query. Exclusive access cannot coincide with any other accesses.", @@ -486,7 +486,7 @@ unsafe impl<'a> WorldQuery for EntityMut<'a> { fn matches_component_set( _state: &Self::State, - _set_contains_id: &impl Fn(ComponentId) -> bool, + _set_contains_id: &impl Fn(DataId) -> bool, ) -> bool { true } @@ -499,9 +499,9 @@ unsafe impl<'a> QueryData for EntityMut<'a> { /// SAFETY: The accesses of `Self::ReadOnly` are a subset of the accesses of `Self` unsafe impl<'a> WorldQuery for FilteredEntityRef<'a> { - type Fetch<'w> = (UnsafeWorldCell<'w>, Access); + type Fetch<'w> = (UnsafeWorldCell<'w>, Access); type Item<'w> = FilteredEntityRef<'w>; - type State = FilteredAccess; + type State = FilteredAccess; fn shrink<'wlong: 'wshort, 'wshort>(item: Self::Item<'wlong>) -> Self::Item<'wshort> { item @@ -548,7 +548,7 @@ unsafe impl<'a> WorldQuery for FilteredEntityRef<'a> { } #[inline] - fn set_access<'w>(state: &mut Self::State, access: &FilteredAccess) { + fn set_access<'w>(state: &mut Self::State, access: &FilteredAccess) { *state = access.clone(); state.access_mut().clear_writes(); } @@ -565,10 +565,7 @@ unsafe impl<'a> WorldQuery for FilteredEntityRef<'a> { FilteredEntityRef::new(cell, access.clone()) } - fn update_component_access( - state: &Self::State, - filtered_access: &mut FilteredAccess, - ) { + fn update_component_access(state: &Self::State, filtered_access: &mut FilteredAccess) { assert!( filtered_access.access().is_compatible(&state.access), "FilteredEntityRef conflicts with a previous access in this query. Exclusive access cannot coincide with any other accesses.", @@ -586,7 +583,7 @@ unsafe impl<'a> WorldQuery for FilteredEntityRef<'a> { fn matches_component_set( _state: &Self::State, - _set_contains_id: &impl Fn(ComponentId) -> bool, + _set_contains_id: &impl Fn(DataId) -> bool, ) -> bool { true } @@ -602,9 +599,9 @@ unsafe impl ReadOnlyQueryData for FilteredEntityRef<'_> {} /// SAFETY: The accesses of `Self::ReadOnly` are a subset of the accesses of `Self` unsafe impl<'a> WorldQuery for FilteredEntityMut<'a> { - type Fetch<'w> = (UnsafeWorldCell<'w>, Access); + type Fetch<'w> = (UnsafeWorldCell<'w>, Access); type Item<'w> = FilteredEntityMut<'w>; - type State = FilteredAccess; + type State = FilteredAccess; fn shrink<'wlong: 'wshort, 'wshort>(item: Self::Item<'wlong>) -> Self::Item<'wshort> { item @@ -661,7 +658,7 @@ unsafe impl<'a> WorldQuery for FilteredEntityMut<'a> { } #[inline] - fn set_access<'w>(state: &mut Self::State, access: &FilteredAccess) { + fn set_access<'w>(state: &mut Self::State, access: &FilteredAccess) { *state = access.clone(); } @@ -677,10 +674,7 @@ unsafe impl<'a> WorldQuery for FilteredEntityMut<'a> { FilteredEntityMut::new(cell, access.clone()) } - fn update_component_access( - state: &Self::State, - filtered_access: &mut FilteredAccess, - ) { + fn update_component_access(state: &Self::State, filtered_access: &mut FilteredAccess) { assert!( filtered_access.access().is_compatible(&state.access), "FilteredEntityMut conflicts with a previous access in this query. Exclusive access cannot coincide with any other accesses.", @@ -698,7 +692,7 @@ unsafe impl<'a> WorldQuery for FilteredEntityMut<'a> { fn matches_component_set( _state: &Self::State, - _set_contains_id: &impl Fn(ComponentId) -> bool, + _set_contains_id: &impl Fn(DataId) -> bool, ) -> bool { true } @@ -732,7 +726,7 @@ impl Copy for ReadFetch<'_, T> {} unsafe impl WorldQuery for &T { type Item<'w> = &'w T; type Fetch<'w> = ReadFetch<'w, T>; - type State = ComponentId; + type State = DataId; fn shrink<'wlong: 'wshort, 'wshort>(item: &'wlong T) -> &'wshort T { item @@ -741,7 +735,7 @@ unsafe impl WorldQuery for &T { #[inline] unsafe fn init_fetch<'w>( world: UnsafeWorldCell<'w>, - &component_id: &ComponentId, + &component_id: &DataId, _last_run: Tick, _this_run: Tick, ) -> ReadFetch<'w, T> { @@ -771,7 +765,7 @@ unsafe impl WorldQuery for &T { #[inline] unsafe fn set_archetype<'w>( fetch: &mut ReadFetch<'w, T>, - component_id: &ComponentId, + component_id: &DataId, _archetype: &'w Archetype, table: &'w Table, ) { @@ -783,7 +777,7 @@ unsafe impl WorldQuery for &T { #[inline] unsafe fn set_table<'w>( fetch: &mut ReadFetch<'w, T>, - &component_id: &ComponentId, + &component_id: &DataId, table: &'w Table, ) { fetch.table_components = Some( @@ -816,10 +810,7 @@ unsafe impl WorldQuery for &T { } } - fn update_component_access( - &component_id: &ComponentId, - access: &mut FilteredAccess, - ) { + fn update_component_access(&component_id: &DataId, access: &mut FilteredAccess) { assert!( !access.access().has_write(component_id), "&{} conflicts with a previous access in this query. Shared access cannot coincide with exclusive access.", @@ -828,7 +819,7 @@ unsafe impl WorldQuery for &T { access.add_read(component_id); } - fn init_state(world: &mut World) -> ComponentId { + fn init_state(world: &mut World) -> DataId { world.init_component::() } @@ -836,10 +827,7 @@ unsafe impl WorldQuery for &T { world.component_id::() } - fn matches_component_set( - &state: &ComponentId, - set_contains_id: &impl Fn(ComponentId) -> bool, - ) -> bool { + fn matches_component_set(&state: &DataId, set_contains_id: &impl Fn(DataId) -> bool) -> bool { set_contains_id(state) } } @@ -882,7 +870,7 @@ impl Copy for RefFetch<'_, T> {} unsafe impl<'__w, T: Component> WorldQuery for Ref<'__w, T> { type Item<'w> = Ref<'w, T>; type Fetch<'w> = RefFetch<'w, T>; - type State = ComponentId; + type State = DataId; fn shrink<'wlong: 'wshort, 'wshort>(item: Ref<'wlong, T>) -> Ref<'wshort, T> { item @@ -891,7 +879,7 @@ unsafe impl<'__w, T: Component> WorldQuery for Ref<'__w, T> { #[inline] unsafe fn init_fetch<'w>( world: UnsafeWorldCell<'w>, - &component_id: &ComponentId, + &component_id: &DataId, last_run: Tick, this_run: Tick, ) -> RefFetch<'w, T> { @@ -920,7 +908,7 @@ unsafe impl<'__w, T: Component> WorldQuery for Ref<'__w, T> { #[inline] unsafe fn set_archetype<'w>( fetch: &mut RefFetch<'w, T>, - component_id: &ComponentId, + component_id: &DataId, _archetype: &'w Archetype, table: &'w Table, ) { @@ -930,11 +918,7 @@ unsafe impl<'__w, T: Component> WorldQuery for Ref<'__w, T> { } #[inline] - unsafe fn set_table<'w>( - fetch: &mut RefFetch<'w, T>, - &component_id: &ComponentId, - table: &'w Table, - ) { + unsafe fn set_table<'w>(fetch: &mut RefFetch<'w, T>, &component_id: &DataId, table: &'w Table) { let column = table.get_column(component_id).debug_checked_unwrap(); fetch.table_data = Some(( column.get_data_slice().into(), @@ -977,10 +961,7 @@ unsafe impl<'__w, T: Component> WorldQuery for Ref<'__w, T> { } } - fn update_component_access( - &component_id: &ComponentId, - access: &mut FilteredAccess, - ) { + fn update_component_access(&component_id: &DataId, access: &mut FilteredAccess) { assert!( !access.access().has_write(component_id), "&{} conflicts with a previous access in this query. Shared access cannot coincide with exclusive access.", @@ -989,7 +970,7 @@ unsafe impl<'__w, T: Component> WorldQuery for Ref<'__w, T> { access.add_read(component_id); } - fn init_state(world: &mut World) -> ComponentId { + fn init_state(world: &mut World) -> DataId { world.init_component::() } @@ -997,10 +978,7 @@ unsafe impl<'__w, T: Component> WorldQuery for Ref<'__w, T> { world.component_id::() } - fn matches_component_set( - &state: &ComponentId, - set_contains_id: &impl Fn(ComponentId) -> bool, - ) -> bool { + fn matches_component_set(&state: &DataId, set_contains_id: &impl Fn(DataId) -> bool) -> bool { set_contains_id(state) } } @@ -1043,7 +1021,7 @@ impl Copy for WriteFetch<'_, T> {} unsafe impl<'__w, T: Component> WorldQuery for &'__w mut T { type Item<'w> = Mut<'w, T>; type Fetch<'w> = WriteFetch<'w, T>; - type State = ComponentId; + type State = DataId; fn shrink<'wlong: 'wshort, 'wshort>(item: Mut<'wlong, T>) -> Mut<'wshort, T> { item @@ -1052,7 +1030,7 @@ unsafe impl<'__w, T: Component> WorldQuery for &'__w mut T { #[inline] unsafe fn init_fetch<'w>( world: UnsafeWorldCell<'w>, - &component_id: &ComponentId, + &component_id: &DataId, last_run: Tick, this_run: Tick, ) -> WriteFetch<'w, T> { @@ -1081,7 +1059,7 @@ unsafe impl<'__w, T: Component> WorldQuery for &'__w mut T { #[inline] unsafe fn set_archetype<'w>( fetch: &mut WriteFetch<'w, T>, - component_id: &ComponentId, + component_id: &DataId, _archetype: &'w Archetype, table: &'w Table, ) { @@ -1093,7 +1071,7 @@ unsafe impl<'__w, T: Component> WorldQuery for &'__w mut T { #[inline] unsafe fn set_table<'w>( fetch: &mut WriteFetch<'w, T>, - &component_id: &ComponentId, + &component_id: &DataId, table: &'w Table, ) { let column = table.get_column(component_id).debug_checked_unwrap(); @@ -1138,10 +1116,7 @@ unsafe impl<'__w, T: Component> WorldQuery for &'__w mut T { } } - fn update_component_access( - &component_id: &ComponentId, - access: &mut FilteredAccess, - ) { + fn update_component_access(&component_id: &DataId, access: &mut FilteredAccess) { assert!( !access.access().has_read(component_id), "&mut {} conflicts with a previous access in this query. Mutable component access must be unique.", @@ -1150,7 +1125,7 @@ unsafe impl<'__w, T: Component> WorldQuery for &'__w mut T { access.add_write(component_id); } - fn init_state(world: &mut World) -> ComponentId { + fn init_state(world: &mut World) -> DataId { world.init_component::() } @@ -1158,10 +1133,7 @@ unsafe impl<'__w, T: Component> WorldQuery for &'__w mut T { world.component_id::() } - fn matches_component_set( - &state: &ComponentId, - set_contains_id: &impl Fn(ComponentId) -> bool, - ) -> bool { + fn matches_component_set(&state: &DataId, set_contains_id: &impl Fn(DataId) -> bool) -> bool { set_contains_id(state) } } @@ -1246,7 +1218,7 @@ unsafe impl WorldQuery for Option { .then(|| T::fetch(&mut fetch.fetch, entity, table_row)) } - fn update_component_access(state: &T::State, access: &mut FilteredAccess) { + fn update_component_access(state: &T::State, access: &mut FilteredAccess) { // FilteredAccess::add_[write,read] adds the component to the `with` filter. // Those methods are called on `access` in `T::update_component_access`. // But in `Option`, we specifically don't filter on `T`, @@ -1271,7 +1243,7 @@ unsafe impl WorldQuery for Option { fn matches_component_set( _state: &T::State, - _set_contains_id: &impl Fn(ComponentId) -> bool, + _set_contains_id: &impl Fn(DataId) -> bool, ) -> bool { true } @@ -1356,7 +1328,7 @@ pub struct Has(PhantomData); unsafe impl WorldQuery for Has { type Item<'w> = bool; type Fetch<'w> = bool; - type State = ComponentId; + type State = DataId; fn shrink<'wlong: 'wshort, 'wshort>(item: Self::Item<'wlong>) -> Self::Item<'wshort> { item @@ -1403,11 +1375,11 @@ unsafe impl WorldQuery for Has { *fetch } - fn update_component_access(_state: &Self::State, _access: &mut FilteredAccess) { + fn update_component_access(_state: &Self::State, _access: &mut FilteredAccess) { // Do nothing as presence of `Has` never affects whether two queries are disjoint } - fn init_state(world: &mut World) -> ComponentId { + fn init_state(world: &mut World) -> DataId { world.init_component::() } @@ -1417,7 +1389,7 @@ unsafe impl WorldQuery for Has { fn matches_component_set( _state: &Self::State, - _set_contains_id: &impl Fn(ComponentId) -> bool, + _set_contains_id: &impl Fn(DataId) -> bool, ) -> bool { // `Has` always matches true @@ -1528,7 +1500,7 @@ macro_rules! impl_anytuple_fetch { )*) } - fn update_component_access(state: &Self::State, _access: &mut FilteredAccess) { + fn update_component_access(state: &Self::State, _access: &mut FilteredAccess) { let ($($name,)*) = state; let mut _new_access = _access.clone(); @@ -1557,7 +1529,7 @@ macro_rules! impl_anytuple_fetch { Some(($($name::get_state(_world)?,)*)) } - fn matches_component_set(_state: &Self::State, _set_contains_id: &impl Fn(ComponentId) -> bool) -> bool { + fn matches_component_set(_state: &Self::State, _set_contains_id: &impl Fn(DataId) -> bool) -> bool { let ($($name,)*) = _state; false $(|| $name::matches_component_set($name, _set_contains_id))* } @@ -1624,7 +1596,7 @@ unsafe impl WorldQuery for NopWorldQuery { ) -> Self::Item<'w> { } - fn update_component_access(_state: &D::State, _access: &mut FilteredAccess) {} + fn update_component_access(_state: &D::State, _access: &mut FilteredAccess) {} fn init_state(world: &mut World) -> Self::State { D::init_state(world) @@ -1636,7 +1608,7 @@ unsafe impl WorldQuery for NopWorldQuery { fn matches_component_set( state: &Self::State, - set_contains_id: &impl Fn(ComponentId) -> bool, + set_contains_id: &impl Fn(DataId) -> bool, ) -> bool { D::matches_component_set(state, set_contains_id) } @@ -1691,7 +1663,7 @@ unsafe impl WorldQuery for PhantomData { ) -> Self::Item<'w> { } - fn update_component_access(_state: &Self::State, _access: &mut FilteredAccess) {} + fn update_component_access(_state: &Self::State, _access: &mut FilteredAccess) {} fn init_state(_world: &mut World) -> Self::State {} @@ -1701,7 +1673,7 @@ unsafe impl WorldQuery for PhantomData { fn matches_component_set( _state: &Self::State, - _set_contains_id: &impl Fn(ComponentId) -> bool, + _set_contains_id: &impl Fn(DataId) -> bool, ) -> bool { true } diff --git a/crates/bevy_ecs/src/query/filter.rs b/crates/bevy_ecs/src/query/filter.rs index a8d225ab81173..e678cf47358e2 100644 --- a/crates/bevy_ecs/src/query/filter.rs +++ b/crates/bevy_ecs/src/query/filter.rs @@ -1,6 +1,6 @@ use crate::{ archetype::Archetype, - component::{Component, ComponentId, ComponentStorage, StorageType, Tick}, + component::{Component, ComponentStorage, DataId, StorageType, Tick}, entity::Entity, query::{DebugCheckedUnwrap, FilteredAccess, WorldQuery}, storage::{Column, ComponentSparseSet, Table, TableRow}, @@ -130,14 +130,14 @@ pub struct With(PhantomData); unsafe impl WorldQuery for With { type Item<'w> = (); type Fetch<'w> = (); - type State = ComponentId; + type State = DataId; fn shrink<'wlong: 'wshort, 'wshort>(_: Self::Item<'wlong>) -> Self::Item<'wshort> {} #[inline] unsafe fn init_fetch( _world: UnsafeWorldCell, - _state: &ComponentId, + _state: &DataId, _last_run: Tick, _this_run: Tick, ) { @@ -153,14 +153,14 @@ unsafe impl WorldQuery for With { #[inline] unsafe fn set_archetype( _fetch: &mut (), - _state: &ComponentId, + _state: &DataId, _archetype: &Archetype, _table: &Table, ) { } #[inline] - unsafe fn set_table(_fetch: &mut (), _state: &ComponentId, _table: &Table) {} + unsafe fn set_table(_fetch: &mut (), _state: &DataId, _table: &Table) {} #[inline(always)] unsafe fn fetch<'w>( @@ -171,11 +171,11 @@ unsafe impl WorldQuery for With { } #[inline] - fn update_component_access(&id: &ComponentId, access: &mut FilteredAccess) { + fn update_component_access(&id: &DataId, access: &mut FilteredAccess) { access.and_with(id); } - fn init_state(world: &mut World) -> ComponentId { + fn init_state(world: &mut World) -> DataId { world.init_component::() } @@ -183,10 +183,7 @@ unsafe impl WorldQuery for With { world.component_id::() } - fn matches_component_set( - &id: &ComponentId, - set_contains_id: &impl Fn(ComponentId) -> bool, - ) -> bool { + fn matches_component_set(&id: &DataId, set_contains_id: &impl Fn(DataId) -> bool) -> bool { set_contains_id(id) } } @@ -238,14 +235,14 @@ pub struct Without(PhantomData); unsafe impl WorldQuery for Without { type Item<'w> = (); type Fetch<'w> = (); - type State = ComponentId; + type State = DataId; fn shrink<'wlong: 'wshort, 'wshort>(_: Self::Item<'wlong>) -> Self::Item<'wshort> {} #[inline] unsafe fn init_fetch( _world: UnsafeWorldCell, - _state: &ComponentId, + _state: &DataId, _last_run: Tick, _this_run: Tick, ) { @@ -261,7 +258,7 @@ unsafe impl WorldQuery for Without { #[inline] unsafe fn set_archetype( _fetch: &mut (), - _state: &ComponentId, + _state: &DataId, _archetype: &Archetype, _table: &Table, ) { @@ -279,11 +276,11 @@ unsafe impl WorldQuery for Without { } #[inline] - fn update_component_access(&id: &ComponentId, access: &mut FilteredAccess) { + fn update_component_access(&id: &DataId, access: &mut FilteredAccess) { access.and_without(id); } - fn init_state(world: &mut World) -> ComponentId { + fn init_state(world: &mut World) -> DataId { world.init_component::() } @@ -291,10 +288,7 @@ unsafe impl WorldQuery for Without { world.component_id::() } - fn matches_component_set( - &id: &ComponentId, - set_contains_id: &impl Fn(ComponentId) -> bool, - ) -> bool { + fn matches_component_set(&id: &DataId, set_contains_id: &impl Fn(DataId) -> bool) -> bool { !set_contains_id(id) } } @@ -428,7 +422,7 @@ macro_rules! impl_query_filter_tuple { false $(|| ($filter.matches && $filter::filter_fetch(&mut $filter.fetch, _entity, _table_row)))* } - fn update_component_access(state: &Self::State, access: &mut FilteredAccess) { + fn update_component_access(state: &Self::State, access: &mut FilteredAccess) { let ($($filter,)*) = state; let mut _new_access = access.clone(); @@ -457,7 +451,7 @@ macro_rules! impl_query_filter_tuple { Some(($($filter::get_state(world)?,)*)) } - fn matches_component_set(_state: &Self::State, _set_contains_id: &impl Fn(ComponentId) -> bool) -> bool { + fn matches_component_set(_state: &Self::State, _set_contains_id: &impl Fn(DataId) -> bool) -> bool { let ($($filter,)*) = _state; false $(|| $filter::matches_component_set($filter, _set_contains_id))* } @@ -585,7 +579,7 @@ pub struct AddedFetch<'w> { unsafe impl WorldQuery for Added { type Item<'w> = bool; type Fetch<'w> = AddedFetch<'w>; - type State = ComponentId; + type State = DataId; fn shrink<'wlong: 'wshort, 'wshort>(item: Self::Item<'wlong>) -> Self::Item<'wshort> { item @@ -594,7 +588,7 @@ unsafe impl WorldQuery for Added { #[inline] unsafe fn init_fetch<'w>( world: UnsafeWorldCell<'w>, - &id: &ComponentId, + &id: &DataId, last_run: Tick, this_run: Tick, ) -> Self::Fetch<'w> { @@ -617,7 +611,7 @@ unsafe impl WorldQuery for Added { #[inline] unsafe fn set_archetype<'w>( fetch: &mut Self::Fetch<'w>, - component_id: &ComponentId, + component_id: &DataId, _archetype: &'w Archetype, table: &'w Table, ) { @@ -627,11 +621,7 @@ unsafe impl WorldQuery for Added { } #[inline] - unsafe fn set_table<'w>( - fetch: &mut Self::Fetch<'w>, - &component_id: &ComponentId, - table: &'w Table, - ) { + unsafe fn set_table<'w>(fetch: &mut Self::Fetch<'w>, &component_id: &DataId, table: &'w Table) { fetch.table_ticks = Some( Column::get_added_ticks_slice(table.get_column(component_id).debug_checked_unwrap()) .into(), @@ -662,25 +652,22 @@ unsafe impl WorldQuery for Added { } #[inline] - fn update_component_access(&id: &ComponentId, access: &mut FilteredAccess) { + fn update_component_access(&id: &DataId, access: &mut FilteredAccess) { if access.access().has_write(id) { panic!("$state_name<{}> conflicts with a previous access in this query. Shared access cannot coincide with exclusive access.",std::any::type_name::()); } access.add_read(id); } - fn init_state(world: &mut World) -> ComponentId { + fn init_state(world: &mut World) -> DataId { world.init_component::() } - fn get_state(world: &World) -> Option { + fn get_state(world: &World) -> Option { world.component_id::() } - fn matches_component_set( - &id: &ComponentId, - set_contains_id: &impl Fn(ComponentId) -> bool, - ) -> bool { + fn matches_component_set(&id: &DataId, set_contains_id: &impl Fn(DataId) -> bool) -> bool { set_contains_id(id) } } @@ -785,7 +772,7 @@ pub struct ChangedFetch<'w> { unsafe impl WorldQuery for Changed { type Item<'w> = bool; type Fetch<'w> = ChangedFetch<'w>; - type State = ComponentId; + type State = DataId; fn shrink<'wlong: 'wshort, 'wshort>(item: Self::Item<'wlong>) -> Self::Item<'wshort> { item @@ -794,7 +781,7 @@ unsafe impl WorldQuery for Changed { #[inline] unsafe fn init_fetch<'w>( world: UnsafeWorldCell<'w>, - &id: &ComponentId, + &id: &DataId, last_run: Tick, this_run: Tick, ) -> Self::Fetch<'w> { @@ -817,7 +804,7 @@ unsafe impl WorldQuery for Changed { #[inline] unsafe fn set_archetype<'w>( fetch: &mut Self::Fetch<'w>, - component_id: &ComponentId, + component_id: &DataId, _archetype: &'w Archetype, table: &'w Table, ) { @@ -827,11 +814,7 @@ unsafe impl WorldQuery for Changed { } #[inline] - unsafe fn set_table<'w>( - fetch: &mut Self::Fetch<'w>, - &component_id: &ComponentId, - table: &'w Table, - ) { + unsafe fn set_table<'w>(fetch: &mut Self::Fetch<'w>, &component_id: &DataId, table: &'w Table) { fetch.table_ticks = Some( Column::get_changed_ticks_slice(table.get_column(component_id).debug_checked_unwrap()) .into(), @@ -862,25 +845,22 @@ unsafe impl WorldQuery for Changed { } #[inline] - fn update_component_access(&id: &ComponentId, access: &mut FilteredAccess) { + fn update_component_access(&id: &DataId, access: &mut FilteredAccess) { if access.access().has_write(id) { panic!("$state_name<{}> conflicts with a previous access in this query. Shared access cannot coincide with exclusive access.",std::any::type_name::()); } access.add_read(id); } - fn init_state(world: &mut World) -> ComponentId { + fn init_state(world: &mut World) -> DataId { world.init_component::() } - fn get_state(world: &World) -> Option { + fn get_state(world: &World) -> Option { world.component_id::() } - fn matches_component_set( - &id: &ComponentId, - set_contains_id: &impl Fn(ComponentId) -> bool, - ) -> bool { + fn matches_component_set(&id: &DataId, set_contains_id: &impl Fn(DataId) -> bool) -> bool { set_contains_id(id) } } diff --git a/crates/bevy_ecs/src/query/state.rs b/crates/bevy_ecs/src/query/state.rs index 03de79f3d4f9b..90a60996e2ec1 100644 --- a/crates/bevy_ecs/src/query/state.rs +++ b/crates/bevy_ecs/src/query/state.rs @@ -1,7 +1,7 @@ use crate::{ archetype::{Archetype, ArchetypeComponentId, ArchetypeGeneration, ArchetypeId}, change_detection::Mut, - component::{ComponentId, Tick}, + component::{DataId, Tick}, entity::Entity, prelude::{Component, FromWorld}, query::{ @@ -32,7 +32,7 @@ pub struct QueryState { pub(crate) matched_tables: FixedBitSet, pub(crate) matched_archetypes: FixedBitSet, pub(crate) archetype_component_access: Access, - pub(crate) component_access: FilteredAccess, + pub(crate) component_access: FilteredAccess, // NOTE: we maintain both a TableId bitset and a vec because iterating the vec is faster pub(crate) matched_table_ids: Vec, // NOTE: we maintain both a ArchetypeId bitset and a vec because iterating the vec is faster @@ -274,7 +274,7 @@ impl QueryState { } /// Update the current [`QueryState`] with information from the provided [`Archetype`] - /// (if applicable, i.e. if the archetype has any intersecting [`ComponentId`] with the current [`QueryState`]). + /// (if applicable, i.e. if the archetype has any intersecting [`DataId`] with the current [`QueryState`]). pub fn new_archetype(&mut self, archetype: &Archetype) { if D::matches_component_set(&self.fetch_state, &|id| archetype.contains(id)) && F::matches_component_set(&self.filter_state, &|id| archetype.contains(id)) @@ -298,15 +298,15 @@ impl QueryState { } /// Returns `true` if this query matches a set of components. Otherwise, returns `false`. - pub fn matches_component_set(&self, set_contains_id: &impl Fn(ComponentId) -> bool) -> bool { + pub fn matches_component_set(&self, set_contains_id: &impl Fn(DataId) -> bool) -> bool { self.component_access.filter_sets.iter().any(|set| { set.with .ones() - .all(|index| set_contains_id(ComponentId::get_sparse_set_index(index))) + .all(|index| set_contains_id(DataId::get_sparse_set_index(index))) && set .without .ones() - .all(|index| !set_contains_id(ComponentId::get_sparse_set_index(index))) + .all(|index| !set_contains_id(DataId::get_sparse_set_index(index))) }) } diff --git a/crates/bevy_ecs/src/query/world_query.rs b/crates/bevy_ecs/src/query/world_query.rs index ad09c5fe447bf..7114ca3f73eb2 100644 --- a/crates/bevy_ecs/src/query/world_query.rs +++ b/crates/bevy_ecs/src/query/world_query.rs @@ -1,6 +1,6 @@ use crate::{ archetype::Archetype, - component::{ComponentId, Tick}, + component::{DataId, Tick}, entity::Entity, query::FilteredAccess, storage::{Table, TableRow}, @@ -103,7 +103,7 @@ pub unsafe trait WorldQuery { /// or [`FilteredEntityMut`](crate::world::FilteredEntityMut). /// /// Called when constructing a [`QueryLens`](crate::system::QueryLens) or calling [`QueryState::from_builder`](super::QueryState::from_builder) - fn set_access(_state: &mut Self::State, _access: &FilteredAccess) {} + fn set_access(_state: &mut Self::State, _access: &FilteredAccess) {} /// Fetch [`Self::Item`](`WorldQuery::Item`) for either the given `entity` in the current [`Table`], /// or for the given `entity` in the current [`Archetype`]. This must always be called after @@ -123,7 +123,7 @@ pub unsafe trait WorldQuery { /// Adds any component accesses used by this [`WorldQuery`] to `access`. // This does not have a default body of `{}` because 99% of cases need to add accesses // and forgetting to do so would be unsound. - fn update_component_access(state: &Self::State, access: &mut FilteredAccess); + fn update_component_access(state: &Self::State, access: &mut FilteredAccess); /// Creates and initializes a [`State`](WorldQuery::State) for this [`WorldQuery`] type. fn init_state(world: &mut World) -> Self::State; @@ -134,7 +134,7 @@ pub unsafe trait WorldQuery { /// Returns `true` if this query matches a set of components. Otherwise, returns `false`. fn matches_component_set( state: &Self::State, - set_contains_id: &impl Fn(ComponentId) -> bool, + set_contains_id: &impl Fn(DataId) -> bool, ) -> bool; } @@ -199,7 +199,7 @@ macro_rules! impl_tuple_world_query { ($($name::fetch($name, _entity, _table_row),)*) } - fn update_component_access(state: &Self::State, _access: &mut FilteredAccess) { + fn update_component_access(state: &Self::State, _access: &mut FilteredAccess) { let ($($name,)*) = state; $($name::update_component_access($name, _access);)* } @@ -212,7 +212,7 @@ macro_rules! impl_tuple_world_query { Some(($($name::get_state(_world)?,)*)) } - fn matches_component_set(state: &Self::State, _set_contains_id: &impl Fn(ComponentId) -> bool) -> bool { + fn matches_component_set(state: &Self::State, _set_contains_id: &impl Fn(DataId) -> bool) -> bool { let ($($name,)*) = state; true $(&& $name::matches_component_set($name, _set_contains_id))* } diff --git a/crates/bevy_ecs/src/removal_detection.rs b/crates/bevy_ecs/src/removal_detection.rs index aa1bb8fb7d137..76a1ce96e866b 100644 --- a/crates/bevy_ecs/src/removal_detection.rs +++ b/crates/bevy_ecs/src/removal_detection.rs @@ -2,7 +2,7 @@ use crate::{ self as bevy_ecs, - component::{Component, ComponentId, ComponentIdFor, Tick}, + component::{Component, ComponentIdFor, DataId, Tick}, entity::Entity, event::{Event, EventId, EventIterator, EventIteratorWithId, Events, ManualEventReader}, prelude::Local, @@ -66,7 +66,7 @@ impl DerefMut for RemovedComponentReader { /// Stores the [`RemovedComponents`] event buffers for all types of component in a given [`World`]. #[derive(Default, Debug)] pub struct RemovedComponentEvents { - event_sets: SparseSet>, + event_sets: SparseSet>, } impl RemovedComponentEvents { @@ -84,15 +84,12 @@ impl RemovedComponentEvents { } /// Gets the event storage for a given component. - pub fn get( - &self, - component_id: impl Into, - ) -> Option<&Events> { + pub fn get(&self, component_id: impl Into) -> Option<&Events> { self.event_sets.get(component_id.into()) } /// Sends a removal event for the specified component. - pub fn send(&mut self, component_id: impl Into, entity: Entity) { + pub fn send(&mut self, component_id: impl Into, entity: Entity) { self.event_sets .get_or_insert_with(component_id.into(), Default::default) .send(RemovedComponentEntity(entity)); diff --git a/crates/bevy_ecs/src/schedule/schedule.rs b/crates/bevy_ecs/src/schedule/schedule.rs index 512d1490693da..defba6b49d2b1 100644 --- a/crates/bevy_ecs/src/schedule/schedule.rs +++ b/crates/bevy_ecs/src/schedule/schedule.rs @@ -18,7 +18,7 @@ use fixedbitset::FixedBitSet; use crate::{ self as bevy_ecs, - component::{ComponentId, Components, Tick}, + component::{DataId, Tick, WorldData}, prelude::Component, schedule::*, system::{BoxedSystem, IntoSystem, Resource, System}, @@ -31,8 +31,8 @@ pub use stepping::Stepping; #[derive(Default, Resource)] pub struct Schedules { inner: HashMap, - /// List of [`ComponentId`]s to ignore when reporting system order ambiguity conflicts - pub ignored_scheduling_ambiguities: BTreeSet, + /// List of [`DataId`]s to ignore when reporting system order ambiguity conflicts + pub ignored_scheduling_ambiguities: BTreeSet, } impl Schedules { @@ -126,19 +126,19 @@ impl Schedules { /// Ignore system order ambiguities caused by conflicts on [`Resource`]s of type `T`. pub fn allow_ambiguous_resource(&mut self, world: &mut World) { self.ignored_scheduling_ambiguities - .insert(world.components.init_resource::()); + .insert(world.world_data.init_resource::()); } - /// Iterate through the [`ComponentId`]'s that will be ignored. - pub fn iter_ignored_ambiguities(&self) -> impl Iterator + '_ { + /// Iterate through the [`DataId`]'s that will be ignored. + pub fn iter_ignored_ambiguities(&self) -> impl Iterator + '_ { self.ignored_scheduling_ambiguities.iter() } /// Prints the names of the components and resources with [`info`] /// - /// May panic or retrieve incorrect names if [`Components`] is not from the same + /// May panic or retrieve incorrect names if [`WorldData`] is not from the same /// world - pub fn print_ignored_ambiguities(&self, components: &Components) { + pub fn print_ignored_ambiguities(&self, components: &WorldData) { let mut message = "System order ambiguities caused by conflicts on the following types are ignored:\n" .to_string(); @@ -543,7 +543,7 @@ pub struct ScheduleGraph { dependency: Dag, ambiguous_with: UnGraphMap, ambiguous_with_all: HashSet, - conflicting_systems: Vec<(NodeId, NodeId, Vec)>, + conflicting_systems: Vec<(NodeId, NodeId, Vec)>, anonymous_sets: usize, changed: bool, settings: ScheduleBuildSettings, @@ -654,9 +654,9 @@ impl ScheduleGraph { /// Returns the list of systems that conflict with each other, i.e. have ambiguities in their access. /// - /// If the `Vec` is empty, the systems conflict on [`World`] access. + /// If the `Vec` is empty, the systems conflict on [`World`] access. /// Must be called after [`ScheduleGraph::build_schedule`] to be non-empty. - pub fn conflicting_systems(&self) -> &[(NodeId, NodeId, Vec)] { + pub fn conflicting_systems(&self) -> &[(NodeId, NodeId, Vec)] { &self.conflicting_systems } @@ -1036,9 +1036,9 @@ impl ScheduleGraph { /// - checks for system access conflicts and reports ambiguities pub fn build_schedule( &mut self, - components: &Components, + components: &WorldData, schedule_label: InternedScheduleLabel, - ignored_ambiguities: &BTreeSet, + ignored_ambiguities: &BTreeSet, ) -> Result { // check hierarchy for cycles self.hierarchy.topsort = @@ -1307,8 +1307,8 @@ impl ScheduleGraph { &self, flat_results_disconnected: &Vec<(NodeId, NodeId)>, ambiguous_with_flattened: &GraphMap, - ignored_ambiguities: &BTreeSet, - ) -> Vec<(NodeId, NodeId, Vec)> { + ignored_ambiguities: &BTreeSet, + ) -> Vec<(NodeId, NodeId, Vec)> { let mut conflicting_systems = Vec::new(); for &(a, b) in flat_results_disconnected { if ambiguous_with_flattened.contains_edge(a, b) @@ -1445,8 +1445,8 @@ impl ScheduleGraph { fn update_schedule( &mut self, schedule: &mut SystemSchedule, - components: &Components, - ignored_ambiguities: &BTreeSet, + components: &WorldData, + ignored_ambiguities: &BTreeSet, schedule_label: InternedScheduleLabel, ) -> Result<(), ScheduleBuildError> { if !self.uninit.is_empty() { @@ -1794,8 +1794,8 @@ impl ScheduleGraph { /// if [`ScheduleBuildSettings::ambiguity_detection`] is [`LogLevel::Ignore`], this check is skipped fn optionally_check_conflicts( &self, - conflicts: &[(NodeId, NodeId, Vec)], - components: &Components, + conflicts: &[(NodeId, NodeId, Vec)], + components: &WorldData, schedule_label: InternedScheduleLabel, ) -> Result<(), ScheduleBuildError> { if self.settings.ambiguity_detection == LogLevel::Ignore || conflicts.is_empty() { @@ -1815,8 +1815,8 @@ impl ScheduleGraph { fn get_conflicts_error_message( &self, - ambiguities: &[(NodeId, NodeId, Vec)], - components: &Components, + ambiguities: &[(NodeId, NodeId, Vec)], + components: &WorldData, ) -> String { let n_ambiguities = ambiguities.len(); @@ -1843,8 +1843,8 @@ impl ScheduleGraph { /// convert conflicts to human readable format pub fn conflicts_to_string<'a>( &'a self, - ambiguities: &'a [(NodeId, NodeId, Vec)], - components: &'a Components, + ambiguities: &'a [(NodeId, NodeId, Vec)], + components: &'a WorldData, ) -> impl Iterator)> + 'a { ambiguities .iter() diff --git a/crates/bevy_ecs/src/storage/resource.rs b/crates/bevy_ecs/src/storage/resource.rs index 5eeebb1f1d04c..5e0f275e24b39 100644 --- a/crates/bevy_ecs/src/storage/resource.rs +++ b/crates/bevy_ecs/src/storage/resource.rs @@ -1,6 +1,6 @@ use crate::archetype::ArchetypeComponentId; use crate::change_detection::{MutUntyped, TicksMut}; -use crate::component::{ComponentId, ComponentTicks, Components, Tick, TickCells}; +use crate::component::{ComponentTicks, DataId, Tick, TickCells, WorldData}; use crate::storage::{blob_vec::BlobVec, SparseSet}; use bevy_ptr::{OwningPtr, Ptr, UnsafeCellDeref}; use std::{cell::UnsafeCell, mem::ManuallyDrop, thread::ThreadId}; @@ -250,7 +250,7 @@ impl ResourceData { /// [`World`]: crate::world::World #[derive(Default)] pub struct Resources { - resources: SparseSet>, + resources: SparseSet>, } impl Resources { @@ -262,8 +262,8 @@ impl Resources { self.resources.len() } - /// Iterate over all resources that have been initialized, i.e. given a [`ComponentId`] - pub fn iter(&self) -> impl Iterator)> { + /// Iterate over all resources that have been initialized, i.e. given a [`DataId`] + pub fn iter(&self) -> impl Iterator)> { self.resources.iter().map(|(id, data)| (*id, data)) } @@ -278,7 +278,7 @@ impl Resources { /// Gets read-only access to a resource, if it exists. #[inline] - pub fn get(&self, component_id: ComponentId) -> Option<&ResourceData> { + pub fn get(&self, component_id: DataId) -> Option<&ResourceData> { self.resources.get(component_id) } @@ -290,7 +290,7 @@ impl Resources { /// Gets mutable access to a resource, if it exists. #[inline] - pub(crate) fn get_mut(&mut self, component_id: ComponentId) -> Option<&mut ResourceData> { + pub(crate) fn get_mut(&mut self, component_id: DataId) -> Option<&mut ResourceData> { self.resources.get_mut(component_id) } @@ -301,8 +301,8 @@ impl Resources { /// If `SEND` is true, this will panic if `component_id`'s `ComponentInfo` is not registered as being `Send` + `Sync`. pub(crate) fn initialize_with( &mut self, - component_id: ComponentId, - components: &Components, + component_id: DataId, + components: &WorldData, f: impl FnOnce() -> ArchetypeComponentId, ) -> &mut ResourceData { self.resources.get_or_insert_with(component_id, || { diff --git a/crates/bevy_ecs/src/storage/sparse_set.rs b/crates/bevy_ecs/src/storage/sparse_set.rs index dfb03f88681d2..2d6b3aa4512b1 100644 --- a/crates/bevy_ecs/src/storage/sparse_set.rs +++ b/crates/bevy_ecs/src/storage/sparse_set.rs @@ -1,5 +1,5 @@ use crate::{ - component::{ComponentId, ComponentInfo, ComponentTicks, Tick, TickCells}, + component::{ComponentTicks, DataId, DataInfo, Tick, TickCells}, entity::Entity, storage::{Column, TableRow}, }; @@ -130,7 +130,7 @@ pub struct ComponentSparseSet { impl ComponentSparseSet { /// Creates a new [`ComponentSparseSet`] with a given component type layout and /// initial `capacity`. - pub(crate) fn new(component_info: &ComponentInfo, capacity: usize) -> Self { + pub(crate) fn new(component_info: &DataInfo, capacity: usize) -> Self { Self { dense: Column::with_capacity(component_info, capacity), entities: Vec::with_capacity(capacity), @@ -549,12 +549,12 @@ macro_rules! impl_sparse_set_index { impl_sparse_set_index!(u8, u16, u32, u64, usize); -/// A collection of [`ComponentSparseSet`] storages, indexed by [`ComponentId`] +/// A collection of [`ComponentSparseSet`] storages, indexed by [`DataId`] /// /// Can be accessed via [`Storages`](crate::storage::Storages) #[derive(Default)] pub struct SparseSets { - sets: SparseSet, + sets: SparseSet, } impl SparseSets { @@ -570,24 +570,21 @@ impl SparseSets { self.sets.is_empty() } - /// An Iterator visiting all ([`ComponentId`], [`ComponentSparseSet`]) pairs. + /// An Iterator visiting all ([`DataId`], [`ComponentSparseSet`]) pairs. /// NOTE: Order is not guaranteed. - pub fn iter(&self) -> impl Iterator { + pub fn iter(&self) -> impl Iterator { self.sets.iter().map(|(id, data)| (*id, data)) } - /// Gets a reference to the [`ComponentSparseSet`] of a [`ComponentId`]. + /// Gets a reference to the [`ComponentSparseSet`] of a [`DataId`]. #[inline] - pub fn get(&self, component_id: ComponentId) -> Option<&ComponentSparseSet> { + pub fn get(&self, component_id: DataId) -> Option<&ComponentSparseSet> { self.sets.get(component_id) } /// Gets a mutable reference of [`ComponentSparseSet`] of a [`ComponentInfo`]. /// Create a new [`ComponentSparseSet`] if not exists. - pub(crate) fn get_or_insert( - &mut self, - component_info: &ComponentInfo, - ) -> &mut ComponentSparseSet { + pub(crate) fn get_or_insert(&mut self, component_info: &DataInfo) -> &mut ComponentSparseSet { if !self.sets.contains(component_info.id()) { self.sets.insert( component_info.id(), @@ -598,8 +595,8 @@ impl SparseSets { self.sets.get_mut(component_info.id()).unwrap() } - /// Gets a mutable reference to the [`ComponentSparseSet`] of a [`ComponentId`]. - pub(crate) fn get_mut(&mut self, component_id: ComponentId) -> Option<&mut ComponentSparseSet> { + /// Gets a mutable reference to the [`ComponentSparseSet`] of a [`DataId`]. + pub(crate) fn get_mut(&mut self, component_id: DataId) -> Option<&mut ComponentSparseSet> { self.sets.get_mut(component_id) } @@ -622,7 +619,7 @@ mod tests { use super::SparseSets; use crate::{ self as bevy_ecs, - component::{Component, ComponentDescriptor, ComponentId, ComponentInfo}, + component::{Component, DataDescriptor, DataId, DataInfo}, entity::Entity, storage::SparseSet, }; @@ -706,13 +703,13 @@ mod tests { collected_sets.sort(); assert_eq!( collected_sets, - vec![(ComponentId::new(1), 0), (ComponentId::new(2), 0),] + vec![(DataId::new(1), 0), (DataId::new(2), 0),] ); fn init_component(sets: &mut SparseSets, id: usize) { - let descriptor = ComponentDescriptor::new::(); - let id = ComponentId::new(id); - let info = ComponentInfo::new(id, descriptor); + let descriptor = DataDescriptor::new::(); + let id = DataId::new(id); + let info = DataInfo::new(id, descriptor); sets.get_or_insert(&info); } } diff --git a/crates/bevy_ecs/src/storage/table.rs b/crates/bevy_ecs/src/storage/table.rs index 5b05e43c29d2b..9e918708ff508 100644 --- a/crates/bevy_ecs/src/storage/table.rs +++ b/crates/bevy_ecs/src/storage/table.rs @@ -1,5 +1,5 @@ use crate::{ - component::{ComponentId, ComponentInfo, ComponentTicks, Components, Tick, TickCells}, + component::{ComponentTicks, DataId, DataInfo, Tick, TickCells, WorldData}, entity::Entity, query::DebugCheckedUnwrap, storage::{blob_vec::BlobVec, ImmutableSparseSet, SparseSet}, @@ -157,7 +157,7 @@ pub struct Column { impl Column { /// Constructs a new [`Column`], configured with a component's layout and an initial `capacity`. #[inline] - pub(crate) fn with_capacity(component_info: &ComponentInfo, capacity: usize) -> Self { + pub(crate) fn with_capacity(component_info: &DataInfo, capacity: usize) -> Self { Column { // SAFETY: component_info.drop() is valid for the types that will be inserted. data: unsafe { BlobVec::new(component_info.layout(), component_info.drop(), capacity) }, @@ -513,7 +513,7 @@ impl Column { /// [`add_column`]: Self::add_column /// [`build`]: Self::build pub(crate) struct TableBuilder { - columns: SparseSet, + columns: SparseSet, capacity: usize, } @@ -528,7 +528,7 @@ impl TableBuilder { } #[must_use] - pub fn add_column(mut self, component_info: &ComponentInfo) -> Self { + pub fn add_column(mut self, component_info: &DataInfo) -> Self { self.columns.insert( component_info.id(), Column::with_capacity(component_info, self.capacity), @@ -548,17 +548,17 @@ impl TableBuilder { /// A column-oriented [structure-of-arrays] based storage for [`Component`]s of entities /// in a [`World`]. /// -/// Conceptually, a `Table` can be thought of as an `HashMap`, where +/// Conceptually, a `Table` can be thought of as an `HashMap`, where /// each [`Column`] is a type-erased `Vec`. Each row corresponds to a single entity /// (i.e. index 3 in Column A and index 3 in Column B point to different components on the same /// entity). Fetching components from a table involves fetching the associated column for a -/// component type (via its [`ComponentId`]), then fetching the entity's row within that column. +/// component type (via its [`DataId`]), then fetching the entity's row within that column. /// /// [structure-of-arrays]: https://en.wikipedia.org/wiki/AoS_and_SoA#Structure_of_arrays /// [`Component`]: crate::component::Component /// [`World`]: crate::world::World pub struct Table { - columns: ImmutableSparseSet, + columns: ImmutableSparseSet, entities: Vec, } @@ -689,7 +689,7 @@ impl Table { /// /// [`Component`]: crate::component::Component #[inline] - pub fn get_column(&self, component_id: ComponentId) -> Option<&Column> { + pub fn get_column(&self, component_id: DataId) -> Option<&Column> { self.columns.get(component_id) } @@ -700,7 +700,7 @@ impl Table { /// /// [`Component`]: crate::component::Component #[inline] - pub(crate) fn get_column_mut(&mut self, component_id: ComponentId) -> Option<&mut Column> { + pub(crate) fn get_column_mut(&mut self, component_id: DataId) -> Option<&mut Column> { self.columns.get_mut(component_id) } @@ -710,7 +710,7 @@ impl Table { /// /// [`Component`]: crate::component::Component #[inline] - pub fn has_column(&self, component_id: ComponentId) -> bool { + pub fn has_column(&self, component_id: DataId) -> bool { self.columns.contains(component_id) } @@ -796,7 +796,7 @@ impl Table { /// Can be accessed via [`Storages`](crate::storage::Storages) pub struct Tables { tables: Vec, - table_ids: HashMap, TableId>, + table_ids: HashMap, TableId>, } impl Default for Tables { @@ -858,8 +858,8 @@ impl Tables { /// `component_ids` must contain components that exist in `components` pub(crate) unsafe fn get_id_or_insert( &mut self, - component_ids: &[ComponentId], - components: &Components, + component_ids: &[DataId], + components: &WorldData, ) -> TableId { let tables = &mut self.tables; let (_key, value) = self @@ -923,7 +923,7 @@ mod tests { use crate::ptr::OwningPtr; use crate::storage::Storages; use crate::{ - component::{Components, Tick}, + component::{Tick, WorldData}, entity::Entity, storage::{TableBuilder, TableRow}, }; @@ -932,7 +932,7 @@ mod tests { #[test] fn table() { - let mut components = Components::default(); + let mut components = WorldData::default(); let mut storages = Storages::default(); let component_id = components.init_component::>(&mut storages); let columns = &[component_id]; diff --git a/crates/bevy_ecs/src/system/adapter_system.rs b/crates/bevy_ecs/src/system/adapter_system.rs index 0ccd2cf0991bd..ad75533dd12df 100644 --- a/crates/bevy_ecs/src/system/adapter_system.rs +++ b/crates/bevy_ecs/src/system/adapter_system.rs @@ -85,7 +85,7 @@ where std::any::TypeId::of::() } - fn component_access(&self) -> &crate::query::Access { + fn component_access(&self) -> &crate::query::Access { self.system.component_access() } diff --git a/crates/bevy_ecs/src/system/combinator.rs b/crates/bevy_ecs/src/system/combinator.rs index 5a7a403c47169..af57dffac13af 100644 --- a/crates/bevy_ecs/src/system/combinator.rs +++ b/crates/bevy_ecs/src/system/combinator.rs @@ -4,7 +4,7 @@ use bevy_ptr::UnsafeCellDeref; use crate::{ archetype::ArchetypeComponentId, - component::{ComponentId, Tick}, + component::{DataId, Tick}, prelude::World, query::Access, schedule::InternedSystemSet, @@ -109,7 +109,7 @@ pub struct CombinatorSystem { a: A, b: B, name: Cow<'static, str>, - component_access: Access, + component_access: Access, archetype_component_access: Access, } @@ -146,7 +146,7 @@ where std::any::TypeId::of::() } - fn component_access(&self) -> &Access { + fn component_access(&self) -> &Access { &self.component_access } diff --git a/crates/bevy_ecs/src/system/exclusive_function_system.rs b/crates/bevy_ecs/src/system/exclusive_function_system.rs index 1d9e1241d2232..9e5eb42382d34 100644 --- a/crates/bevy_ecs/src/system/exclusive_function_system.rs +++ b/crates/bevy_ecs/src/system/exclusive_function_system.rs @@ -1,6 +1,6 @@ use crate::{ archetype::ArchetypeComponentId, - component::{ComponentId, Tick}, + component::{DataId, Tick}, query::Access, schedule::{InternedSystemSet, SystemSet}, system::{ @@ -71,7 +71,7 @@ where } #[inline] - fn component_access(&self) -> &Access { + fn component_access(&self) -> &Access { self.system_meta.component_access_set.combined_access() } diff --git a/crates/bevy_ecs/src/system/function_system.rs b/crates/bevy_ecs/src/system/function_system.rs index 98f58b69242b5..4f2e825dc4d04 100644 --- a/crates/bevy_ecs/src/system/function_system.rs +++ b/crates/bevy_ecs/src/system/function_system.rs @@ -1,6 +1,6 @@ use crate::{ archetype::{ArchetypeComponentId, ArchetypeGeneration}, - component::{ComponentId, Tick}, + component::{DataId, Tick}, prelude::FromWorld, query::{Access, FilteredAccessSet}, schedule::{InternedSystemSet, SystemSet}, @@ -20,7 +20,7 @@ use super::{In, IntoSystem, ReadOnlySystem}; #[derive(Clone)] pub struct SystemMeta { pub(crate) name: Cow<'static, str>, - pub(crate) component_access_set: FilteredAccessSet, + pub(crate) component_access_set: FilteredAccessSet, pub(crate) archetype_component_access: Access, // NOTE: this must be kept private. making a SystemMeta non-send is irreversible to prevent // SystemParams from overriding each other @@ -459,7 +459,7 @@ where } #[inline] - fn component_access(&self) -> &Access { + fn component_access(&self) -> &Access { self.system_meta.component_access_set.combined_access() } diff --git a/crates/bevy_ecs/src/system/mod.rs b/crates/bevy_ecs/src/system/mod.rs index c5d1dfb5c535e..8eafde3fa2d05 100644 --- a/crates/bevy_ecs/src/system/mod.rs +++ b/crates/bevy_ecs/src/system/mod.rs @@ -96,7 +96,7 @@ //! - [`SystemChangeTick`] //! - [`Archetypes`](crate::archetype::Archetypes) (Provides Archetype metadata) //! - [`Bundles`](crate::bundle::Bundles) (Provides Bundles metadata) -//! - [`Components`](crate::component::Components) (Provides Components metadata) +//! - [`WorldData`](crate::component::WorldData) (Provides Components & Resources metadata) //! - [`Entities`](crate::entity::Entities) (Provides Entities metadata) //! - All tuples between 1 to 16 elements where each element implements [`SystemParam`] //! - [`()` (unit primitive type)](https://doc.rust-lang.org/stable/std/primitive.unit.html) @@ -335,7 +335,7 @@ mod tests { archetype::{ArchetypeComponentId, Archetypes}, bundle::Bundles, change_detection::DetectChanges, - component::{Component, Components, Tick}, + component::{Component, Tick, WorldData}, entity::{Entities, Entity}, prelude::AnyOf, query::{Added, Changed, Or, With, Without}, @@ -1019,7 +1019,7 @@ mod tests { world.spawn((W(42), W(true))); fn sys( archetypes: &Archetypes, - components: &Components, + components: &WorldData, entities: &Entities, bundles: &Bundles, query: Query>>, @@ -1039,7 +1039,7 @@ mod tests { for component_id in &bundle_components { assert!( components.get_info(*component_id).is_some(), - "every bundle component exists in Components" + "every bundle component exists in WorldData" ); } assert_eq!( diff --git a/crates/bevy_ecs/src/system/system.rs b/crates/bevy_ecs/src/system/system.rs index 073c93085937c..b88854f11d789 100644 --- a/crates/bevy_ecs/src/system/system.rs +++ b/crates/bevy_ecs/src/system/system.rs @@ -4,7 +4,7 @@ use core::fmt::Debug; use crate::component::Tick; use crate::schedule::InternedSystemSet; use crate::world::unsafe_world_cell::UnsafeWorldCell; -use crate::{archetype::ArchetypeComponentId, component::ComponentId, query::Access, world::World}; +use crate::{archetype::ArchetypeComponentId, component::DataId, query::Access, world::World}; use std::any::TypeId; use std::borrow::Cow; @@ -33,10 +33,10 @@ pub trait System: Send + Sync + 'static { /// Returns the [`TypeId`] of the underlying system type. fn type_id(&self) -> TypeId; /// Returns the system's component [`Access`]. - fn component_access(&self) -> &Access; + fn component_access(&self) -> &Access; /// Returns the system's archetype component [`Access`]. fn archetype_component_access(&self) -> &Access; - /// Returns true if the system is [`Send`]. + /// Returns true if the system is [`Send`] fn is_send(&self) -> bool; /// Returns true if the system must be run exclusively. diff --git a/crates/bevy_ecs/src/system/system_param.rs b/crates/bevy_ecs/src/system/system_param.rs index 8168654e18749..6dfaba666ff95 100644 --- a/crates/bevy_ecs/src/system/system_param.rs +++ b/crates/bevy_ecs/src/system/system_param.rs @@ -3,7 +3,7 @@ use crate::{ archetype::{Archetype, Archetypes}, bundle::Bundles, change_detection::{Ticks, TicksMut}, - component::{ComponentId, ComponentTicks, Components, Tick}, + component::{ComponentTicks, DataId, Tick, WorldData}, entity::Entities, query::{ Access, FilteredAccess, FilteredAccessSet, QueryData, QueryFilter, QueryState, @@ -186,7 +186,7 @@ unsafe impl<'w, 's, D: ReadOnlyQueryData + 'static, F: QueryFilter + 'static> Re { } -// SAFETY: Relevant query ComponentId and ArchetypeComponentId access is applied to SystemMeta. If +// SAFETY: Relevant query DataId and ArchetypeComponentId access is applied to SystemMeta. If // this Query conflicts with any prior access, a panic will occur. unsafe impl SystemParam for Query<'_, '_, D, F> { type State = QueryState; @@ -236,8 +236,8 @@ fn assert_component_access_compatibility( system_name: &str, query_type: &'static str, filter_type: &'static str, - system_access: &FilteredAccessSet, - current: &FilteredAccess, + system_access: &FilteredAccessSet, + current: &FilteredAccess, world: &World, ) { let conflicts = system_access.get_conflicts_single(current); @@ -246,7 +246,7 @@ fn assert_component_access_compatibility( } let conflicting_components = conflicts .into_iter() - .map(|component_id| world.components.get_info(component_id).unwrap().name()) + .map(|component_id| world.world_data.get_info(component_id).unwrap().name()) .collect::>(); let accesses = conflicting_components.join(", "); panic!("error[B0001]: Query<{query_type}, {filter_type}> in system {system_name} accesses component(s) {accesses} in a way that conflicts with a previous system parameter. Consider using `Without` to create disjoint Queries or merging conflicting Queries into a `ParamSet`."); @@ -435,10 +435,10 @@ pub trait Resource: Send + Sync + 'static {} // SAFETY: Res only reads a single World resource unsafe impl<'a, T: Resource> ReadOnlySystemParam for Res<'a, T> {} -// SAFETY: Res ComponentId and ArchetypeComponentId access is applied to SystemMeta. If this Res +// SAFETY: Res DataId and ArchetypeComponentId access is applied to SystemMeta. If this Res // conflicts with any prior access, a panic will occur. unsafe impl<'a, T: Resource> SystemParam for Res<'a, T> { - type State = ComponentId; + type State = DataId; type Item<'w, 's> = Res<'w, T>; fn init_state(world: &mut World, system_meta: &mut SystemMeta) -> Self::State { @@ -497,7 +497,7 @@ unsafe impl<'a, T: Resource> ReadOnlySystemParam for Option> {} // SAFETY: this impl defers to `Res`, which initializes and validates the correct world access. unsafe impl<'a, T: Resource> SystemParam for Option> { - type State = ComponentId; + type State = DataId; type Item<'w, 's> = Option>; fn init_state(world: &mut World, system_meta: &mut SystemMeta) -> Self::State { @@ -525,10 +525,10 @@ unsafe impl<'a, T: Resource> SystemParam for Option> { } } -// SAFETY: Res ComponentId and ArchetypeComponentId access is applied to SystemMeta. If this Res +// SAFETY: Res DataId and ArchetypeComponentId access is applied to SystemMeta. If this Res // conflicts with any prior access, a panic will occur. unsafe impl<'a, T: Resource> SystemParam for ResMut<'a, T> { - type State = ComponentId; + type State = DataId; type Item<'w, 's> = ResMut<'w, T>; fn init_state(world: &mut World, system_meta: &mut SystemMeta) -> Self::State { @@ -587,7 +587,7 @@ unsafe impl<'a, T: Resource> SystemParam for ResMut<'a, T> { // SAFETY: this impl defers to `ResMut`, which initializes and validates the correct world access. unsafe impl<'a, T: Resource> SystemParam for Option> { - type State = ComponentId; + type State = DataId; type Item<'w, 's> = Option>; fn init_state(world: &mut World, system_meta: &mut SystemMeta) -> Self::State { @@ -1018,10 +1018,10 @@ impl<'a, T> From> for NonSend<'a, T> { } } -// SAFETY: NonSendComponentId and ArchetypeComponentId access is applied to SystemMeta. If this +// SAFETY: NonSend DataId and ArchetypeComponentId access is applied to SystemMeta. If this // NonSend conflicts with any prior access, a panic will occur. unsafe impl<'a, T: 'static> SystemParam for NonSend<'a, T> { - type State = ComponentId; + type State = DataId; type Item<'w, 's> = NonSend<'w, T>; fn init_state(world: &mut World, system_meta: &mut SystemMeta) -> Self::State { @@ -1080,7 +1080,7 @@ unsafe impl ReadOnlySystemParam for Option> {} // SAFETY: this impl defers to `NonSend`, which initializes and validates the correct world access. unsafe impl SystemParam for Option> { - type State = ComponentId; + type State = DataId; type Item<'w, 's> = Option>; fn init_state(world: &mut World, system_meta: &mut SystemMeta) -> Self::State { @@ -1105,10 +1105,10 @@ unsafe impl SystemParam for Option> { } } -// SAFETY: NonSendMut ComponentId and ArchetypeComponentId access is applied to SystemMeta. If this +// SAFETY: NonSendMut DataId and ArchetypeComponentId access is applied to SystemMeta. If this // NonSendMut conflicts with any prior access, a panic will occur. unsafe impl<'a, T: 'static> SystemParam for NonSendMut<'a, T> { - type State = ComponentId; + type State = DataId; type Item<'w, 's> = NonSendMut<'w, T>; fn init_state(world: &mut World, system_meta: &mut SystemMeta) -> Self::State { @@ -1164,7 +1164,7 @@ unsafe impl<'a, T: 'static> SystemParam for NonSendMut<'a, T> { // SAFETY: this impl defers to `NonSendMut`, which initializes and validates the correct world access. unsafe impl<'a, T: 'static> SystemParam for Option> { - type State = ComponentId; + type State = DataId; type Item<'w, 's> = Option>; fn init_state(world: &mut World, system_meta: &mut SystemMeta) -> Self::State { @@ -1209,12 +1209,12 @@ unsafe impl<'a> SystemParam for &'a Archetypes { } // SAFETY: Only reads World components -unsafe impl<'a> ReadOnlySystemParam for &'a Components {} +unsafe impl<'a> ReadOnlySystemParam for &'a WorldData {} // SAFETY: no component value access -unsafe impl<'a> SystemParam for &'a Components { +unsafe impl<'a> SystemParam for &'a WorldData { type State = (); - type Item<'w, 's> = &'w Components; + type Item<'w, 's> = &'w WorldData; fn init_state(_world: &mut World, _system_meta: &mut SystemMeta) -> Self::State {} diff --git a/crates/bevy_ecs/src/world/entity_ref.rs b/crates/bevy_ecs/src/world/entity_ref.rs index 9558ff5c4e73e..bff5a444b364e 100644 --- a/crates/bevy_ecs/src/world/entity_ref.rs +++ b/crates/bevy_ecs/src/world/entity_ref.rs @@ -2,7 +2,7 @@ use crate::{ archetype::{Archetype, ArchetypeId, Archetypes}, bundle::{Bundle, BundleInfo, BundleInserter, DynamicBundle}, change_detection::MutUntyped, - component::{Component, ComponentId, ComponentTicks, Components, StorageType}, + component::{Component, ComponentTicks, DataId, StorageType, WorldData}, entity::{Entities, Entity, EntityLocation}, query::{Access, DebugCheckedUnwrap}, removal_detection::RemovedComponentEvents, @@ -83,10 +83,10 @@ impl<'w> EntityRef<'w> { /// ## Notes /// /// - If you know the concrete type of the component, you should prefer [`Self::contains`]. - /// - If you know the component's [`TypeId`] but not its [`ComponentId`], consider using + /// - If you know the component's [`TypeId`] but not its [`DataId`], consider using /// [`Self::contains_type_id`]. #[inline] - pub fn contains_id(&self, component_id: ComponentId) -> bool { + pub fn contains_id(&self, component_id: DataId) -> bool { self.0.contains_id(component_id) } @@ -96,7 +96,7 @@ impl<'w> EntityRef<'w> { /// ## Notes /// /// - If you know the concrete type of the component, you should prefer [`Self::contains`]. - /// - If you have a [`ComponentId`] instead of a [`TypeId`], consider using [`Self::contains_id`]. + /// - If you have a [`DataId`] instead of a [`TypeId`], consider using [`Self::contains_id`]. #[inline] pub fn contains_type_id(&self, type_id: TypeId) -> bool { self.0.contains_type_id(type_id) @@ -128,19 +128,19 @@ impl<'w> EntityRef<'w> { unsafe { self.0.get_change_ticks::() } } - /// Retrieves the change ticks for the given [`ComponentId`]. This can be useful for implementing change + /// Retrieves the change ticks for the given [`DataId`]. This can be useful for implementing change /// detection in custom runtimes. /// /// **You should prefer to use the typed API [`EntityRef::get_change_ticks`] where possible and only /// use this in cases where the actual component types are not known at /// compile time.** #[inline] - pub fn get_change_ticks_by_id(&self, component_id: ComponentId) -> Option { + pub fn get_change_ticks_by_id(&self, component_id: DataId) -> Option { // SAFETY: We have read-only access to all components of this entity. unsafe { self.0.get_change_ticks_by_id(component_id) } } - /// Gets the component of the given [`ComponentId`] from the entity. + /// Gets the component of the given [`DataId`] from the entity. /// /// **You should prefer to use the typed API where possible and only /// use this in cases where the actual component types are not known at @@ -149,7 +149,7 @@ impl<'w> EntityRef<'w> { /// Unlike [`EntityRef::get`], this returns a raw pointer to the component, /// which is only valid while the `'w` borrow of the lifetime is active. #[inline] - pub fn get_by_id(&self, component_id: ComponentId) -> Option> { + pub fn get_by_id(&self, component_id: DataId) -> Option> { // SAFETY: We have read-only access to all components of this entity. unsafe { self.0.get_by_id(component_id) } } @@ -270,10 +270,10 @@ impl<'w> EntityMut<'w> { /// ## Notes /// /// - If you know the concrete type of the component, you should prefer [`Self::contains`]. - /// - If you know the component's [`TypeId`] but not its [`ComponentId`], consider using + /// - If you know the component's [`TypeId`] but not its [`DataId`], consider using /// [`Self::contains_type_id`]. #[inline] - pub fn contains_id(&self, component_id: ComponentId) -> bool { + pub fn contains_id(&self, component_id: DataId) -> bool { self.0.contains_id(component_id) } @@ -283,7 +283,7 @@ impl<'w> EntityMut<'w> { /// ## Notes /// /// - If you know the concrete type of the component, you should prefer [`Self::contains`]. - /// - If you have a [`ComponentId`] instead of a [`TypeId`], consider using [`Self::contains_id`]. + /// - If you have a [`DataId`] instead of a [`TypeId`], consider using [`Self::contains_id`]. #[inline] pub fn contains_type_id(&self, type_id: TypeId) -> bool { self.0.contains_type_id(type_id) @@ -320,18 +320,18 @@ impl<'w> EntityMut<'w> { self.as_readonly().get_change_ticks::() } - /// Retrieves the change ticks for the given [`ComponentId`]. This can be useful for implementing change + /// Retrieves the change ticks for the given [`DataId`]. This can be useful for implementing change /// detection in custom runtimes. /// /// **You should prefer to use the typed API [`EntityWorldMut::get_change_ticks`] where possible and only /// use this in cases where the actual component types are not known at /// compile time.** #[inline] - pub fn get_change_ticks_by_id(&self, component_id: ComponentId) -> Option { + pub fn get_change_ticks_by_id(&self, component_id: DataId) -> Option { self.as_readonly().get_change_ticks_by_id(component_id) } - /// Gets the component of the given [`ComponentId`] from the entity. + /// Gets the component of the given [`DataId`] from the entity. /// /// **You should prefer to use the typed API [`EntityWorldMut::get`] where possible and only /// use this in cases where the actual component types are not known at @@ -340,11 +340,11 @@ impl<'w> EntityMut<'w> { /// Unlike [`EntityMut::get`], this returns a raw pointer to the component, /// which is only valid while the [`EntityMut`] is alive. #[inline] - pub fn get_by_id(&self, component_id: ComponentId) -> Option> { + pub fn get_by_id(&self, component_id: DataId) -> Option> { self.as_readonly().get_by_id(component_id) } - /// Gets a [`MutUntyped`] of the component of the given [`ComponentId`] from the entity. + /// Gets a [`MutUntyped`] of the component of the given [`DataId`] from the entity. /// /// **You should prefer to use the typed API [`EntityMut::get_mut`] where possible and only /// use this in cases where the actual component types are not known at @@ -353,7 +353,7 @@ impl<'w> EntityMut<'w> { /// Unlike [`EntityMut::get_mut`], this returns a raw pointer to the component, /// which is only valid while the [`EntityMut`] is alive. #[inline] - pub fn get_mut_by_id(&mut self, component_id: ComponentId) -> Option> { + pub fn get_mut_by_id(&mut self, component_id: DataId) -> Option> { // SAFETY: // - `&mut self` ensures that no references exist to this entity's components. // - `as_unsafe_world_cell` gives mutable permission for all components on this entity @@ -473,10 +473,10 @@ impl<'w> EntityWorldMut<'w> { /// ## Notes /// /// - If you know the concrete type of the component, you should prefer [`Self::contains`]. - /// - If you know the component's [`TypeId`] but not its [`ComponentId`], consider using + /// - If you know the component's [`TypeId`] but not its [`DataId`], consider using /// [`Self::contains_type_id`]. #[inline] - pub fn contains_id(&self, component_id: ComponentId) -> bool { + pub fn contains_id(&self, component_id: DataId) -> bool { self.as_unsafe_entity_cell_readonly() .contains_id(component_id) } @@ -487,7 +487,7 @@ impl<'w> EntityWorldMut<'w> { /// ## Notes /// /// - If you know the concrete type of the component, you should prefer [`Self::contains`]. - /// - If you have a [`ComponentId`] instead of a [`TypeId`], consider using [`Self::contains_id`]. + /// - If you have a [`DataId`] instead of a [`TypeId`], consider using [`Self::contains_id`]. #[inline] pub fn contains_type_id(&self, type_id: TypeId) -> bool { self.as_unsafe_entity_cell_readonly() @@ -525,18 +525,18 @@ impl<'w> EntityWorldMut<'w> { EntityRef::from(self).get_change_ticks::() } - /// Retrieves the change ticks for the given [`ComponentId`]. This can be useful for implementing change + /// Retrieves the change ticks for the given [`DataId`]. This can be useful for implementing change /// detection in custom runtimes. /// /// **You should prefer to use the typed API [`EntityWorldMut::get_change_ticks`] where possible and only /// use this in cases where the actual component types are not known at /// compile time.** #[inline] - pub fn get_change_ticks_by_id(&self, component_id: ComponentId) -> Option { + pub fn get_change_ticks_by_id(&self, component_id: DataId) -> Option { EntityRef::from(self).get_change_ticks_by_id(component_id) } - /// Gets the component of the given [`ComponentId`] from the entity. + /// Gets the component of the given [`DataId`] from the entity. /// /// **You should prefer to use the typed API [`EntityWorldMut::get`] where possible and only /// use this in cases where the actual component types are not known at @@ -545,11 +545,11 @@ impl<'w> EntityWorldMut<'w> { /// Unlike [`EntityWorldMut::get`], this returns a raw pointer to the component, /// which is only valid while the [`EntityWorldMut`] is alive. #[inline] - pub fn get_by_id(&self, component_id: ComponentId) -> Option> { + pub fn get_by_id(&self, component_id: DataId) -> Option> { EntityRef::from(self).get_by_id(component_id) } - /// Gets a [`MutUntyped`] of the component of the given [`ComponentId`] from the entity. + /// Gets a [`MutUntyped`] of the component of the given [`DataId`] from the entity. /// /// **You should prefer to use the typed API [`EntityWorldMut::get_mut`] where possible and only /// use this in cases where the actual component types are not known at @@ -558,7 +558,7 @@ impl<'w> EntityWorldMut<'w> { /// Unlike [`EntityWorldMut::get_mut`], this returns a raw pointer to the component, /// which is only valid while the [`EntityWorldMut`] is alive. #[inline] - pub fn get_mut_by_id(&mut self, component_id: ComponentId) -> Option> { + pub fn get_mut_by_id(&mut self, component_id: DataId) -> Option> { // SAFETY: // - `&mut self` ensures that no references exist to this entity's components. // - `as_unsafe_world_cell` gives mutable permission for all components on this entity @@ -573,11 +573,11 @@ impl<'w> EntityWorldMut<'w> { let bundle_info = self .world .bundles - .init_info::(&mut self.world.components, &mut self.world.storages); + .init_info::(&mut self.world.world_data, &mut self.world.storages); let mut bundle_inserter = bundle_info.get_bundle_inserter( &mut self.world.entities, &mut self.world.archetypes, - &self.world.components, + &self.world.world_data, &mut self.world.storages, self.location.archetype_id, change_tick, @@ -598,23 +598,23 @@ impl<'w> EntityWorldMut<'w> { /// /// # Safety /// - /// - [`ComponentId`] must be from the same world as [`EntityWorldMut`] - /// - [`OwningPtr`] must be a valid reference to the type represented by [`ComponentId`] + /// - [`DataId`] must be from the same world as [`EntityWorldMut`] + /// - [`OwningPtr`] must be a valid reference to the type represented by [`DataId`] pub unsafe fn insert_by_id( &mut self, - component_id: ComponentId, + component_id: DataId, component: OwningPtr<'_>, ) -> &mut Self { let change_tick = self.world.change_tick(); let bundles = &mut self.world.bundles; - let components = &mut self.world.components; + let components = &mut self.world.world_data; let (bundle_info, storage_type) = bundles.init_component_info(components, component_id); let bundle_inserter = bundle_info.get_bundle_inserter( &mut self.world.entities, &mut self.world.archetypes, - &self.world.components, + &self.world.world_data, &mut self.world.storages, self.location.archetype_id, change_tick, @@ -638,26 +638,26 @@ impl<'w> EntityWorldMut<'w> { /// You should prefer to use the typed API [`EntityWorldMut::insert`] where possible. /// If your [`Bundle`] only has one component, use the cached API [`EntityWorldMut::insert_by_id`]. /// - /// If possible, pass a sorted slice of `ComponentId` to maximize caching potential. + /// If possible, pass a sorted slice of `DataId` to maximize caching potential. /// /// # Safety - /// - Each [`ComponentId`] must be from the same world as [`EntityWorldMut`] - /// - Each [`OwningPtr`] must be a valid reference to the type represented by [`ComponentId`] + /// - Each [`DataId`] must be from the same world as [`EntityWorldMut`] + /// - Each [`OwningPtr`] must be a valid reference to the type represented by [`DataId`] pub unsafe fn insert_by_ids<'a, I: Iterator>>( &mut self, - component_ids: &[ComponentId], + component_ids: &[DataId], iter_components: I, ) -> &mut Self { let change_tick = self.world.change_tick(); let bundles = &mut self.world.bundles; - let components = &mut self.world.components; + let components = &mut self.world.world_data; let (bundle_info, storage_types) = bundles.init_dynamic_info(components, component_ids); let bundle_inserter = bundle_info.get_bundle_inserter( &mut self.world.entities, &mut self.world.archetypes, - &self.world.components, + &self.world.world_data, &mut self.world.storages, self.location.archetype_id, change_tick, @@ -683,7 +683,7 @@ impl<'w> EntityWorldMut<'w> { pub fn take(&mut self) -> Option { let archetypes = &mut self.world.archetypes; let storages = &mut self.world.storages; - let components = &mut self.world.components; + let components = &mut self.world.world_data; let entities = &mut self.world.entities; let removed_components = &mut self.world.removed_components; @@ -838,7 +838,7 @@ impl<'w> EntityWorldMut<'w> { bundle_info: &BundleInfo, archetypes: &mut Archetypes, storages: &mut Storages, - components: &Components, + components: &WorldData, entities: &mut Entities, removed_components: &mut RemovedComponentEvents, ) { @@ -896,7 +896,7 @@ impl<'w> EntityWorldMut<'w> { pub fn remove(&mut self) -> &mut Self { let archetypes = &mut self.world.archetypes; let storages = &mut self.world.storages; - let components = &mut self.world.components; + let components = &mut self.world.world_data; let entities = &mut self.world.entities; let removed_components = &mut self.world.removed_components; @@ -928,7 +928,7 @@ impl<'w> EntityWorldMut<'w> { pub fn retain(&mut self) -> &mut Self { let archetypes = &mut self.world.archetypes; let storages = &mut self.world.storages; - let components = &mut self.world.components; + let components = &mut self.world.world_data; let entities = &mut self.world.entities; let removed_components = &mut self.world.removed_components; @@ -1500,7 +1500,7 @@ impl<'w, 'a, T: Component> VacantEntry<'w, 'a, T> { #[derive(Clone)] pub struct FilteredEntityRef<'w> { entity: UnsafeEntityCell<'w>, - access: Access, + access: Access, } impl<'w> FilteredEntityRef<'w> { @@ -1509,7 +1509,7 @@ impl<'w> FilteredEntityRef<'w> { /// - If `access` takes read access to a component no mutable reference to that /// component can exist at the same time as the returned [`FilteredEntityMut`] /// - If `access` takes any access for a component `entity` must have that component. - pub(crate) unsafe fn new(entity: UnsafeEntityCell<'w>, access: Access) -> Self { + pub(crate) unsafe fn new(entity: UnsafeEntityCell<'w>, access: Access) -> Self { Self { entity, access } } @@ -1534,13 +1534,13 @@ impl<'w> FilteredEntityRef<'w> { /// Returns an iterator over the component ids that are accessed by self. #[inline] - pub fn components(&self) -> impl Iterator + '_ { + pub fn components(&self) -> impl Iterator + '_ { self.access.reads_and_writes() } /// Returns a reference to the underlying [`Access`]. #[inline] - pub fn access(&self) -> &Access { + pub fn access(&self) -> &Access { &self.access } @@ -1562,10 +1562,10 @@ impl<'w> FilteredEntityRef<'w> { /// ## Notes /// /// - If you know the concrete type of the component, you should prefer [`Self::contains`]. - /// - If you know the component's [`TypeId`] but not its [`ComponentId`], consider using + /// - If you know the component's [`TypeId`] but not its [`DataId`], consider using /// [`Self::contains_type_id`]. #[inline] - pub fn contains_id(&self, component_id: ComponentId) -> bool { + pub fn contains_id(&self, component_id: DataId) -> bool { self.entity.contains_id(component_id) } @@ -1575,7 +1575,7 @@ impl<'w> FilteredEntityRef<'w> { /// ## Notes /// /// - If you know the concrete type of the component, you should prefer [`Self::contains`]. - /// - If you have a [`ComponentId`] instead of a [`TypeId`], consider using [`Self::contains_id`]. + /// - If you have a [`DataId`] instead of a [`TypeId`], consider using [`Self::contains_id`]. #[inline] pub fn contains_type_id(&self, type_id: TypeId) -> bool { self.entity.contains_type_id(type_id) @@ -1622,14 +1622,14 @@ impl<'w> FilteredEntityRef<'w> { .then(|| unsafe { self.entity.get_change_ticks::().debug_checked_unwrap() }) } - /// Retrieves the change ticks for the given [`ComponentId`]. This can be useful for implementing change + /// Retrieves the change ticks for the given [`DataId`]. This can be useful for implementing change /// detection in custom runtimes. /// /// **You should prefer to use the typed API [`Self::get_change_ticks`] where possible and only /// use this in cases where the actual component types are not known at /// compile time.** #[inline] - pub fn get_change_ticks_by_id(&self, component_id: ComponentId) -> Option { + pub fn get_change_ticks_by_id(&self, component_id: DataId) -> Option { // SAFETY: We have read access so we must have the component self.access.has_read(component_id).then(|| unsafe { self.entity @@ -1638,7 +1638,7 @@ impl<'w> FilteredEntityRef<'w> { }) } - /// Gets the component of the given [`ComponentId`] from the entity. + /// Gets the component of the given [`DataId`] from the entity. /// /// **You should prefer to use the typed API [`Self::get`] where possible and only /// use this in cases where the actual component types are not known at @@ -1647,7 +1647,7 @@ impl<'w> FilteredEntityRef<'w> { /// Unlike [`FilteredEntityRef::get`], this returns a raw pointer to the component, /// which is only valid while the [`FilteredEntityRef`] is alive. #[inline] - pub fn get_by_id(&self, component_id: ComponentId) -> Option> { + pub fn get_by_id(&self, component_id: DataId) -> Option> { self.access .has_read(component_id) // SAFETY: We have read access so we must have the component @@ -1674,7 +1674,7 @@ impl<'a> From<&'a FilteredEntityMut<'_>> for FilteredEntityRef<'a> { /// Provides mutable access to a single entity and some of its components defined by the contained [`Access`]. pub struct FilteredEntityMut<'w> { entity: UnsafeEntityCell<'w>, - access: Access, + access: Access, } impl<'w> FilteredEntityMut<'w> { @@ -1685,7 +1685,7 @@ impl<'w> FilteredEntityMut<'w> { /// - If `access` takes write access to a component, no reference to that component /// may exist at the same time as the returned [`FilteredEntityMut`] /// - If `access` takes any access for a component `entity` must have that component. - pub(crate) unsafe fn new(entity: UnsafeEntityCell<'w>, access: Access) -> Self { + pub(crate) unsafe fn new(entity: UnsafeEntityCell<'w>, access: Access) -> Self { Self { entity, access } } @@ -1722,13 +1722,13 @@ impl<'w> FilteredEntityMut<'w> { /// Returns an iterator over the component ids that are accessed by self. #[inline] - pub fn components(&self) -> impl Iterator + '_ { + pub fn components(&self) -> impl Iterator + '_ { self.access.reads_and_writes() } /// Returns a reference to the underlying [`Access`]. #[inline] - pub fn access(&self) -> &Access { + pub fn access(&self) -> &Access { &self.access } @@ -1750,10 +1750,10 @@ impl<'w> FilteredEntityMut<'w> { /// ## Notes /// /// - If you know the concrete type of the component, you should prefer [`Self::contains`]. - /// - If you know the component's [`TypeId`] but not its [`ComponentId`], consider using + /// - If you know the component's [`TypeId`] but not its [`DataId`], consider using /// [`Self::contains_type_id`]. #[inline] - pub fn contains_id(&self, component_id: ComponentId) -> bool { + pub fn contains_id(&self, component_id: DataId) -> bool { self.entity.contains_id(component_id) } @@ -1763,7 +1763,7 @@ impl<'w> FilteredEntityMut<'w> { /// ## Notes /// /// - If you know the concrete type of the component, you should prefer [`Self::contains`]. - /// - If you have a [`ComponentId`] instead of a [`TypeId`], consider using [`Self::contains_id`]. + /// - If you have a [`DataId`] instead of a [`TypeId`], consider using [`Self::contains_id`]. #[inline] pub fn contains_type_id(&self, type_id: TypeId) -> bool { self.entity.contains_type_id(type_id) @@ -1805,18 +1805,18 @@ impl<'w> FilteredEntityMut<'w> { self.as_readonly().get_change_ticks::() } - /// Retrieves the change ticks for the given [`ComponentId`]. This can be useful for implementing change + /// Retrieves the change ticks for the given [`DataId`]. This can be useful for implementing change /// detection in custom runtimes. /// /// **You should prefer to use the typed API [`Self::get_change_ticks`] where possible and only /// use this in cases where the actual component types are not known at /// compile time.** #[inline] - pub fn get_change_ticks_by_id(&self, component_id: ComponentId) -> Option { + pub fn get_change_ticks_by_id(&self, component_id: DataId) -> Option { self.as_readonly().get_change_ticks_by_id(component_id) } - /// Gets the component of the given [`ComponentId`] from the entity. + /// Gets the component of the given [`DataId`] from the entity. /// /// **You should prefer to use the typed API [`Self::get`] where possible and only /// use this in cases where the actual component types are not known at @@ -1825,11 +1825,11 @@ impl<'w> FilteredEntityMut<'w> { /// Unlike [`FilteredEntityMut::get`], this returns a raw pointer to the component, /// which is only valid while the [`FilteredEntityMut`] is alive. #[inline] - pub fn get_by_id(&self, component_id: ComponentId) -> Option> { + pub fn get_by_id(&self, component_id: DataId) -> Option> { self.as_readonly().get_by_id(component_id) } - /// Gets a [`MutUntyped`] of the component of the given [`ComponentId`] from the entity. + /// Gets a [`MutUntyped`] of the component of the given [`DataId`] from the entity. /// /// **You should prefer to use the typed API [`Self::get_mut`] where possible and only /// use this in cases where the actual component types are not known at @@ -1838,7 +1838,7 @@ impl<'w> FilteredEntityMut<'w> { /// Unlike [`FilteredEntityMut::get_mut`], this returns a raw pointer to the component, /// which is only valid while the [`FilteredEntityMut`] is alive. #[inline] - pub fn get_mut_by_id(&mut self, component_id: ComponentId) -> Option> { + pub fn get_mut_by_id(&mut self, component_id: DataId) -> Option> { // SAFETY: We have write access so we must have the component self.access.has_write(component_id).then(|| unsafe { self.entity @@ -1898,7 +1898,7 @@ unsafe fn insert_dynamic_bundle< unsafe fn remove_bundle_from_archetype( archetypes: &mut Archetypes, storages: &mut Storages, - components: &Components, + components: &WorldData, archetype_id: ArchetypeId, bundle_info: &BundleInfo, intersection: bool, @@ -2015,9 +2015,9 @@ fn sorted_remove(source: &mut Vec, remove: &[T]) { #[inline] pub(crate) unsafe fn take_component<'a>( storages: &'a mut Storages, - components: &Components, + components: &WorldData, removed_components: &mut RemovedComponentEvents, - component_id: ComponentId, + component_id: DataId, entity: Entity, location: EntityLocation, ) -> OwningPtr<'a> { @@ -2050,7 +2050,7 @@ mod tests { use bevy_ptr::OwningPtr; use std::panic::AssertUnwindSafe; - use crate::{self as bevy_ecs, component::ComponentId, prelude::*, system::assert_is_system}; + use crate::{self as bevy_ecs, component::DataId, prelude::*, system::assert_is_system}; #[test] fn sorted_remove() { @@ -2126,7 +2126,7 @@ mod tests { #[test] fn entity_ref_get_by_id_invalid_component_id() { - let invalid_component_id = ComponentId::new(usize::MAX); + let invalid_component_id = DataId::new(usize::MAX); let mut world = World::new(); let entity = world.spawn_empty().id(); @@ -2136,7 +2136,7 @@ mod tests { #[test] fn entity_mut_get_by_id_invalid_component_id() { - let invalid_component_id = ComponentId::new(usize::MAX); + let invalid_component_id = DataId::new(usize::MAX); let mut world = World::new(); let mut entity = world.spawn_empty(); diff --git a/crates/bevy_ecs/src/world/mod.rs b/crates/bevy_ecs/src/world/mod.rs index f79d6abdeb121..6f016d6970d88 100644 --- a/crates/bevy_ecs/src/world/mod.rs +++ b/crates/bevy_ecs/src/world/mod.rs @@ -18,10 +18,7 @@ use crate::{ archetype::{ArchetypeComponentId, ArchetypeId, ArchetypeRow, Archetypes}, bundle::{Bundle, BundleInserter, BundleSpawner, Bundles}, change_detection::{MutUntyped, TicksMut}, - component::{ - Component, ComponentDescriptor, ComponentId, ComponentInfo, ComponentTicks, Components, - Tick, - }, + component::{Component, ComponentTicks, DataDescriptor, DataId, DataInfo, Tick, WorldData}, entity::{AllocAtWithoutReplacement, Entities, Entity, EntityLocation}, event::{Event, EventId, Events, SendBatchIds}, query::{DebugCheckedUnwrap, QueryData, QueryEntityError, QueryFilter, QueryState}, @@ -67,7 +64,7 @@ use self::unsafe_world_cell::{UnsafeEntityCell, UnsafeWorldCell}; pub struct World { id: WorldId, pub(crate) entities: Entities, - pub(crate) components: Components, + pub(crate) world_data: WorldData, pub(crate) archetypes: Archetypes, pub(crate) storages: Storages, pub(crate) bundles: Bundles, @@ -84,7 +81,7 @@ impl Default for World { Self { id: WorldId::new().expect("More `bevy` `World`s have been created than is supported"), entities: Entities::new(), - components: Default::default(), + world_data: Default::default(), archetypes: Archetypes::new(), storages: Default::default(), bundles: Default::default(), @@ -152,10 +149,10 @@ impl World { &self.archetypes } - /// Retrieves this world's [`Components`] collection. + /// Retrieves this world's [`WorldData`] collection. #[inline] - pub fn components(&self) -> &Components { - &self.components + pub fn components(&self) -> &WorldData { + &self.world_data } /// Retrieves this world's [`Storages`] collection. @@ -183,12 +180,12 @@ impl World { WorldCell::new(self) } - /// Initializes a new [`Component`] type and returns the [`ComponentId`] created for it. - pub fn init_component(&mut self) -> ComponentId { - self.components.init_component::(&mut self.storages) + /// Initializes a new [`Component`] type and returns the [`DataId`] created for it. + pub fn init_component(&mut self) -> DataId { + self.world_data.init_component::(&mut self.storages) } - /// Initializes a new [`Component`] type and returns the [`ComponentId`] created for it. + /// Initializes a new [`Component`] type and returns the [`DataId`] created for it. /// /// This method differs from [`World::init_component`] in that it uses a [`ComponentDescriptor`] /// to initialize the new component type instead of statically available type information. This @@ -197,17 +194,14 @@ impl World { /// While the option to initialize a component from a descriptor is useful in type-erased /// contexts, the standard `World::init_component` function should always be used instead /// when type information is available at compile time. - pub fn init_component_with_descriptor( - &mut self, - descriptor: ComponentDescriptor, - ) -> ComponentId { - self.components + pub fn init_component_with_descriptor(&mut self, descriptor: DataDescriptor) -> DataId { + self.world_data .init_component_with_descriptor(&mut self.storages, descriptor) } - /// Returns the [`ComponentId`] of the given [`Component`] type `T`. + /// Returns the [`DataId`] of the given [`Component`] type `T`. /// - /// The returned `ComponentId` is specific to the `World` instance + /// The returned `DataId` is specific to the `World` instance /// it was retrieved from and should not be used with another `World` instance. /// /// Returns [`None`] if the `Component` type has not yet been initialized within @@ -228,11 +222,11 @@ impl World { /// /// # See also /// - /// * [`Components::component_id()`] - /// * [`Components::get_id()`] + /// * [`WorldData::component_id()`] + /// * [`WorldData::get_id()`] #[inline] - pub fn component_id(&self) -> Option { - self.components.component_id::() + pub fn component_id(&self) -> Option { + self.world_data.component_id::() } /// Retrieves an [`EntityRef`] that exposes read-only operations for the given `entity`. @@ -391,7 +385,7 @@ impl World { /// Returns the components of an [`Entity`] through [`ComponentInfo`]. #[inline] - pub fn inspect_entity(&self, entity: Entity) -> Vec<&ComponentInfo> { + pub fn inspect_entity(&self, entity: Entity) -> Vec<&DataInfo> { let entity_location = self .entities() .get(entity) @@ -748,11 +742,11 @@ impl World { let entity_location = { let bundle_info = self .bundles - .init_info::(&mut self.components, &mut self.storages); + .init_info::(&mut self.world_data, &mut self.storages); let mut spawner = bundle_info.get_bundle_spawner( &mut self.entities, &mut self.archetypes, - &self.components, + &self.world_data, &mut self.storages, change_tick, ); @@ -1028,7 +1022,7 @@ impl World { /// Returns an iterator of entities that had components of type `T` removed /// since the last call to [`World::clear_trackers`]. pub fn removed(&self) -> impl Iterator + '_ { - self.components + self.world_data .get_id(TypeId::of::()) .map(|component_id| self.removed_with_id(component_id)) .into_iter() @@ -1037,7 +1031,7 @@ impl World { /// Returns an iterator of entities that had components with the given `component_id` removed /// since the last call to [`World::clear_trackers`]. - pub fn removed_with_id(&self, component_id: ComponentId) -> impl Iterator + '_ { + pub fn removed_with_id(&self, component_id: DataId) -> impl Iterator + '_ { self.removed_components .get(component_id) .map(|removed| removed.iter_current_update_events().cloned()) @@ -1046,7 +1040,7 @@ impl World { .map(|e| e.into()) } - /// Initializes a new resource and returns the [`ComponentId`] created for it. + /// Initializes a new resource and returns the [`DataId`] created for it. /// /// If the resource already exists, nothing happens. /// @@ -1054,8 +1048,8 @@ impl World { /// Note that any resource with the [`Default`] trait automatically implements [`FromWorld`], /// and those default values will be here instead. #[inline] - pub fn init_resource(&mut self) -> ComponentId { - let component_id = self.components.init_resource::(); + pub fn init_resource(&mut self) -> DataId { + let component_id = self.world_data.init_resource::(); if self .storages .resources @@ -1080,7 +1074,7 @@ impl World { /// you will overwrite any existing data. #[inline] pub fn insert_resource(&mut self, value: R) { - let component_id = self.components.init_resource::(); + let component_id = self.world_data.init_resource::(); OwningPtr::make(value, |ptr| { // SAFETY: component_id was just initialized and corresponds to resource of type R. unsafe { @@ -1089,7 +1083,7 @@ impl World { }); } - /// Initializes a new non-send resource and returns the [`ComponentId`] created for it. + /// Initializes a new non-send resource and returns the [`DataId`] created for it. /// /// If the resource already exists, nothing happens. /// @@ -1101,8 +1095,8 @@ impl World { /// /// Panics if called from a thread other than the main thread. #[inline] - pub fn init_non_send_resource(&mut self) -> ComponentId { - let component_id = self.components.init_non_send::(); + pub fn init_non_send_resource(&mut self) -> DataId { + let component_id = self.world_data.init_non_send::(); if self .storages .non_send_resources @@ -1131,7 +1125,7 @@ impl World { /// from a different thread than where the original value was inserted from. #[inline] pub fn insert_non_send_resource(&mut self, value: R) { - let component_id = self.components.init_non_send::(); + let component_id = self.world_data.init_non_send::(); OwningPtr::make(value, |ptr| { // SAFETY: component_id was just initialized and corresponds to resource of type R. unsafe { @@ -1143,7 +1137,7 @@ impl World { /// Removes the resource of a given type and returns it, if it exists. Otherwise returns `None`. #[inline] pub fn remove_resource(&mut self) -> Option { - let component_id = self.components.get_resource_id(TypeId::of::())?; + let component_id = self.world_data.get_resource_id(TypeId::of::())?; let (ptr, _) = self.storages.resources.get_mut(component_id)?.remove()?; // SAFETY: `component_id` was gotten via looking up the `R` type unsafe { Some(ptr.read::()) } @@ -1162,7 +1156,7 @@ impl World { /// thread than where the value was inserted from. #[inline] pub fn remove_non_send_resource(&mut self) -> Option { - let component_id = self.components.get_resource_id(TypeId::of::())?; + let component_id = self.world_data.get_resource_id(TypeId::of::())?; let (ptr, _) = self .storages .non_send_resources @@ -1175,7 +1169,7 @@ impl World { /// Returns `true` if a resource of type `R` exists. Otherwise returns `false`. #[inline] pub fn contains_resource(&self) -> bool { - self.components + self.world_data .get_resource_id(TypeId::of::()) .and_then(|component_id| self.storages.resources.get(component_id)) .map(|info| info.is_present()) @@ -1185,7 +1179,7 @@ impl World { /// Returns `true` if a resource of type `R` exists. Otherwise returns `false`. #[inline] pub fn contains_non_send(&self) -> bool { - self.components + self.world_data .get_resource_id(TypeId::of::()) .and_then(|component_id| self.storages.non_send_resources.get(component_id)) .map(|info| info.is_present()) @@ -1200,7 +1194,7 @@ impl World { /// - When called elsewhere, this will check for additions since the last time that [`World::clear_trackers`] /// was called. pub fn is_resource_added(&self) -> bool { - self.components + self.world_data .get_resource_id(TypeId::of::()) .map(|component_id| self.is_resource_added_by_id(component_id)) .unwrap_or(false) @@ -1213,7 +1207,7 @@ impl World { /// - When called from an exclusive system, this will check for additions since the system last ran. /// - When called elsewhere, this will check for additions since the last time that [`World::clear_trackers`] /// was called. - pub fn is_resource_added_by_id(&self, component_id: ComponentId) -> bool { + pub fn is_resource_added_by_id(&self, component_id: DataId) -> bool { self.storages .resources .get(component_id) @@ -1233,7 +1227,7 @@ impl World { /// - When called elsewhere, this will check for changes since the last time that [`World::clear_trackers`] /// was called. pub fn is_resource_changed(&self) -> bool { - self.components + self.world_data .get_resource_id(TypeId::of::()) .map(|component_id| self.is_resource_changed_by_id(component_id)) .unwrap_or(false) @@ -1246,10 +1240,10 @@ impl World { /// - When called from an exclusive system, this will check for changes since the system last ran. /// - When called elsewhere, this will check for changes since the last time that [`World::clear_trackers`] /// was called. - pub fn is_resource_changed_by_id(&self, component_id: ComponentId) -> bool { + pub fn is_resource_changed_by_id(&self, resource_id: DataId) -> bool { self.storages .resources - .get(component_id) + .get(resource_id) .and_then(|resource| { resource .get_ticks() @@ -1260,21 +1254,18 @@ impl World { /// Retrieves the change ticks for the given resource. pub fn get_resource_change_ticks(&self) -> Option { - self.components + self.world_data .get_resource_id(TypeId::of::()) - .and_then(|component_id| self.get_resource_change_ticks_by_id(component_id)) + .and_then(|resource_id| self.get_resource_change_ticks_by_id(resource_id)) } - /// Retrieves the change ticks for the given [`ComponentId`]. + /// Retrieves the change ticks for the given [`DataId`]. /// /// **You should prefer to use the typed API [`World::get_resource_change_ticks`] where possible.** - pub fn get_resource_change_ticks_by_id( - &self, - component_id: ComponentId, - ) -> Option { + pub fn get_resource_change_ticks_by_id(&self, resource_id: DataId) -> Option { self.storages .resources - .get(component_id) + .get(resource_id) .and_then(|resource| resource.get_ticks()) } @@ -1387,7 +1378,7 @@ impl World { let change_tick = self.change_tick(); let last_change_tick = self.last_change_tick(); - let component_id = self.components.init_resource::(); + let component_id = self.world_data.init_resource::(); let data = self.initialize_resource_internal(component_id); if !data.is_present() { OwningPtr::make(func(), |ptr| { @@ -1481,9 +1472,9 @@ impl World { #[inline] pub(crate) fn get_resource_archetype_component_id( &self, - component_id: ComponentId, + resource_id: DataId, ) -> Option { - let resource = self.storages.resources.get(component_id)?; + let resource = self.storages.resources.get(resource_id)?; Some(resource.id()) } @@ -1491,9 +1482,9 @@ impl World { #[inline] pub(crate) fn get_non_send_archetype_component_id( &self, - component_id: ComponentId, + resource_id: DataId, ) -> Option { - let resource = self.storages.non_send_resources.get(component_id)?; + let resource = self.storages.non_send_resources.get(resource_id)?; Some(resource.id()) } @@ -1538,7 +1529,7 @@ impl World { let bundle_info = self .bundles - .init_info::(&mut self.components, &mut self.storages); + .init_info::(&mut self.world_data, &mut self.storages); enum SpawnOrInsert<'a, 'b> { Spawn(BundleSpawner<'a, 'b>), Insert(BundleInserter<'a, 'b>, ArchetypeId), @@ -1555,7 +1546,7 @@ impl World { let mut spawn_or_insert = SpawnOrInsert::Spawn(bundle_info.get_bundle_spawner( &mut self.entities, &mut self.archetypes, - &self.components, + &self.world_data, &mut self.storages, change_tick, )); @@ -1578,7 +1569,7 @@ impl World { let mut inserter = bundle_info.get_bundle_inserter( &mut self.entities, &mut self.archetypes, - &self.components, + &self.world_data, &mut self.storages, location.archetype_id, change_tick, @@ -1598,7 +1589,7 @@ impl World { let mut spawner = bundle_info.get_bundle_spawner( &mut self.entities, &mut self.archetypes, - &self.components, + &self.world_data, &mut self.storages, change_tick, ); @@ -1648,7 +1639,7 @@ impl World { let change_tick = self.change_tick(); let component_id = self - .components + .world_data .get_resource_id(TypeId::of::()) .unwrap_or_else(|| panic!("resource does not exist: {}", std::any::type_name::())); let (ptr, mut ticks) = self @@ -1734,17 +1725,13 @@ impl World { /// use this in cases where the actual types are not known at compile time.** /// /// # Safety - /// The value referenced by `value` must be valid for the given [`ComponentId`] of this world. + /// The value referenced by `value` must be valid for the given [`DataId`] of this world. #[inline] - pub unsafe fn insert_resource_by_id( - &mut self, - component_id: ComponentId, - value: OwningPtr<'_>, - ) { + pub unsafe fn insert_resource_by_id(&mut self, resource_id: DataId, value: OwningPtr<'_>) { let change_tick = self.change_tick(); // SAFETY: value is valid for component_id, ensured by caller - self.initialize_resource_internal(component_id) + self.initialize_resource_internal(resource_id) .insert(value, change_tick); } @@ -1759,31 +1746,24 @@ impl World { /// thread that the original value was inserted from. /// /// # Safety - /// The value referenced by `value` must be valid for the given [`ComponentId`] of this world. + /// The value referenced by `value` must be valid for the given [`DataId`] of this world. #[inline] - pub unsafe fn insert_non_send_by_id( - &mut self, - component_id: ComponentId, - value: OwningPtr<'_>, - ) { + pub unsafe fn insert_non_send_by_id(&mut self, resource_id: DataId, value: OwningPtr<'_>) { let change_tick = self.change_tick(); // SAFETY: value is valid for component_id, ensured by caller - self.initialize_non_send_internal(component_id) + self.initialize_non_send_internal(resource_id) .insert(value, change_tick); } /// # Panics /// Panics if `component_id` is not registered as a `Send` component type in this `World` #[inline] - fn initialize_resource_internal( - &mut self, - component_id: ComponentId, - ) -> &mut ResourceData { + fn initialize_resource_internal(&mut self, resource_id: DataId) -> &mut ResourceData { let archetypes = &mut self.archetypes; self.storages .resources - .initialize_with(component_id, &self.components, || { + .initialize_with(resource_id, &self.world_data, || { archetypes.new_archetype_component_id() }) } @@ -1791,28 +1771,25 @@ impl World { /// # Panics /// panics if `component_id` is not registered in this world #[inline] - fn initialize_non_send_internal( - &mut self, - component_id: ComponentId, - ) -> &mut ResourceData { + fn initialize_non_send_internal(&mut self, resource_id: DataId) -> &mut ResourceData { let archetypes = &mut self.archetypes; self.storages .non_send_resources - .initialize_with(component_id, &self.components, || { + .initialize_with(resource_id, &self.world_data, || { archetypes.new_archetype_component_id() }) } - pub(crate) fn initialize_resource(&mut self) -> ComponentId { - let component_id = self.components.init_resource::(); - self.initialize_resource_internal(component_id); - component_id + pub(crate) fn initialize_resource(&mut self) -> DataId { + let resource_id = self.world_data.init_resource::(); + self.initialize_resource_internal(resource_id); + resource_id } - pub(crate) fn initialize_non_send_resource(&mut self) -> ComponentId { - let component_id = self.components.init_non_send::(); - self.initialize_non_send_internal(component_id); - component_id + pub(crate) fn initialize_non_send_resource(&mut self) -> DataId { + let resource_id = self.world_data.init_non_send::(); + self.initialize_non_send_internal(resource_id); + resource_id } /// Empties queued entities and adds them to the empty [`Archetype`](crate::archetype::Archetype). @@ -1932,41 +1909,41 @@ impl World { } impl World { - /// Gets a pointer to the resource with the id [`ComponentId`] if it exists. + /// Gets a pointer to the resource with the id [`DataId`] if it exists. /// The returned pointer must not be used to modify the resource, and must not be /// dereferenced after the immutable borrow of the [`World`] ends. /// /// **You should prefer to use the typed API [`World::get_resource`] where possible and only /// use this in cases where the actual types are not known at compile time.** #[inline] - pub fn get_resource_by_id(&self, component_id: ComponentId) -> Option> { + pub fn get_resource_by_id(&self, resource_id: DataId) -> Option> { // SAFETY: // - `as_unsafe_world_cell_readonly` gives permission to access the whole world immutably // - `&self` ensures there are no mutable borrows on world data unsafe { self.as_unsafe_world_cell_readonly() - .get_resource_by_id(component_id) + .get_resource_by_id(resource_id) } } - /// Gets a pointer to the resource with the id [`ComponentId`] if it exists. + /// Gets a pointer to the resource with the id [`DataId`] if it exists. /// The returned pointer may be used to modify the resource, as long as the mutable borrow /// of the [`World`] is still valid. /// /// **You should prefer to use the typed API [`World::get_resource_mut`] where possible and only /// use this in cases where the actual types are not known at compile time.** #[inline] - pub fn get_resource_mut_by_id(&mut self, component_id: ComponentId) -> Option> { + pub fn get_resource_mut_by_id(&mut self, resource_id: DataId) -> Option> { // SAFETY: // - `&mut self` ensures that all accessed data is unaliased // - `as_unsafe_world_cell` provides mutable permission to the whole world unsafe { self.as_unsafe_world_cell() - .get_resource_mut_by_id(component_id) + .get_resource_mut_by_id(resource_id) } } - /// Gets a `!Send` resource to the resource with the id [`ComponentId`] if it exists. + /// Gets a `!Send` resource to the resource with the id [`DataId`] if it exists. /// The returned pointer must not be used to modify the resource, and must not be /// dereferenced after the immutable borrow of the [`World`] ends. /// @@ -1976,17 +1953,17 @@ impl World { /// # Panics /// This function will panic if it isn't called from the same thread that the resource was inserted from. #[inline] - pub fn get_non_send_by_id(&self, component_id: ComponentId) -> Option> { + pub fn get_non_send_by_id(&self, resource_id: DataId) -> Option> { // SAFETY: // - `as_unsafe_world_cell_readonly` gives permission to access the whole world immutably // - `&self` ensures there are no mutable borrows on world data unsafe { self.as_unsafe_world_cell_readonly() - .get_non_send_resource_by_id(component_id) + .get_non_send_resource_by_id(resource_id) } } - /// Gets a `!Send` resource to the resource with the id [`ComponentId`] if it exists. + /// Gets a `!Send` resource to the resource with the id [`DataId`] if it exists. /// The returned pointer may be used to modify the resource, as long as the mutable borrow /// of the [`World`] is still valid. /// @@ -1996,13 +1973,13 @@ impl World { /// # Panics /// This function will panic if it isn't called from the same thread that the resource was inserted from. #[inline] - pub fn get_non_send_mut_by_id(&mut self, component_id: ComponentId) -> Option> { + pub fn get_non_send_mut_by_id(&mut self, resource_id: DataId) -> Option> { // SAFETY: // - `&mut self` ensures that all accessed data is unaliased // - `as_unsafe_world_cell` provides mutable permission to the whole world unsafe { self.as_unsafe_world_cell() - .get_non_send_resource_mut_by_id(component_id) + .get_non_send_resource_mut_by_id(resource_id) } } @@ -2010,10 +1987,10 @@ impl World { /// /// **You should prefer to use the typed API [`World::remove_resource`] where possible and only /// use this in cases where the actual types are not known at compile time.** - pub fn remove_resource_by_id(&mut self, component_id: ComponentId) -> Option<()> { + pub fn remove_resource_by_id(&mut self, resource_id: DataId) -> Option<()> { self.storages .resources - .get_mut(component_id)? + .get_mut(resource_id)? .remove_and_drop(); Some(()) } @@ -2025,15 +2002,15 @@ impl World { /// /// # Panics /// This function will panic if it isn't called from the same thread that the resource was inserted from. - pub fn remove_non_send_by_id(&mut self, component_id: ComponentId) -> Option<()> { + pub fn remove_non_send_by_id(&mut self, resource_id: DataId) -> Option<()> { self.storages .non_send_resources - .get_mut(component_id)? + .get_mut(resource_id)? .remove_and_drop(); Some(()) } - /// Retrieves an immutable untyped reference to the given `entity`'s [`Component`] of the given [`ComponentId`]. + /// Retrieves an immutable untyped reference to the given `entity`'s [`Component`] of the given [`DataId`]. /// Returns `None` if the `entity` does not have a [`Component`] of the given type. /// /// **You should prefer to use the typed API [`World::get_mut`] where possible and only @@ -2042,7 +2019,7 @@ impl World { /// # Panics /// This function will panic if it isn't called from the same thread that the resource was inserted from. #[inline] - pub fn get_by_id(&self, entity: Entity, component_id: ComponentId) -> Option> { + pub fn get_by_id(&self, entity: Entity, component_id: DataId) -> Option> { // SAFETY: // - `&self` ensures that all accessed data is not mutably aliased // - `as_unsafe_world_cell_readonly` provides shared/readonly permission to the whole world @@ -2053,7 +2030,7 @@ impl World { } } - /// Retrieves a mutable untyped reference to the given `entity`'s [`Component`] of the given [`ComponentId`]. + /// Retrieves a mutable untyped reference to the given `entity`'s [`Component`] of the given [`DataId`]. /// Returns `None` if the `entity` does not have a [`Component`] of the given type. /// /// **You should prefer to use the typed API [`World::get_mut`] where possible and only @@ -2062,7 +2039,7 @@ impl World { pub fn get_mut_by_id( &mut self, entity: Entity, - component_id: ComponentId, + component_id: DataId, ) -> Option> { // SAFETY: // - `&mut self` ensures that all accessed data is unaliased @@ -2092,7 +2069,7 @@ impl World { /// This returns a [`TryRunScheduleError`] if there is no schedule /// associated with `label`. /// - /// The [`Schedule`] is fetched from the [`Schedules`] resource of the world by its label, + /// The [`Schedule`] is fetched from the [`ScheduleLabel`] of the world by its label, /// and system state is cached. /// /// For simple cases where you just need to call the schedule once, @@ -2218,7 +2195,7 @@ impl fmt::Debug for World { .field("id", &self.id) .field("entity_count", &self.entities.len()) .field("archetype_count", &self.archetypes.len()) - .field("component_count", &self.components.len()) + .field("component_count", &self.world_data.len()) .field("resource_count", &self.storages.resources.len()) .finish() } @@ -2249,7 +2226,7 @@ mod tests { use super::{FromWorld, World}; use crate::{ change_detection::DetectChangesMut, - component::{ComponentDescriptor, ComponentInfo, StorageType}, + component::{DataDescriptor, DataInfo, StorageType}, ptr::OwningPtr, system::Resource, }; @@ -2432,7 +2409,7 @@ mod tests { // SAFETY: the drop function is valid for the layout and the data will be safe to access from any thread let descriptor = unsafe { - ComponentDescriptor::new_with_layout( + DataDescriptor::new_with_layout( "Custom Test Component".to_string(), StorageType::Table, std::alloc::Layout::new::<[u8; 8]>(), @@ -2523,7 +2500,7 @@ mod tests { let ent5 = world.spawn(Bar).id(); let ent6 = world.spawn(Baz).id(); - fn to_type_ids(component_infos: Vec<&ComponentInfo>) -> HashSet> { + fn to_type_ids(component_infos: Vec<&DataInfo>) -> HashSet> { component_infos .into_iter() .map(|component_info| component_info.type_id()) diff --git a/crates/bevy_ecs/src/world/spawn_batch.rs b/crates/bevy_ecs/src/world/spawn_batch.rs index e21199f56444c..fb605e9403a2f 100644 --- a/crates/bevy_ecs/src/world/spawn_batch.rs +++ b/crates/bevy_ecs/src/world/spawn_batch.rs @@ -36,12 +36,12 @@ where let bundle_info = world .bundles - .init_info::(&mut world.components, &mut world.storages); + .init_info::(&mut world.world_data, &mut world.storages); world.entities.reserve(length as u32); let mut spawner = bundle_info.get_bundle_spawner( &mut world.entities, &mut world.archetypes, - &world.components, + &world.world_data, &mut world.storages, change_tick, ); diff --git a/crates/bevy_ecs/src/world/unsafe_world_cell.rs b/crates/bevy_ecs/src/world/unsafe_world_cell.rs index a851024a701e4..3f92fca18ddf7 100644 --- a/crates/bevy_ecs/src/world/unsafe_world_cell.rs +++ b/crates/bevy_ecs/src/world/unsafe_world_cell.rs @@ -8,7 +8,7 @@ use crate::{ bundle::Bundles, change_detection::{MutUntyped, Ticks, TicksMut}, component::{ - ComponentId, ComponentStorage, ComponentTicks, Components, StorageType, Tick, TickCells, + ComponentStorage, ComponentTicks, DataId, StorageType, Tick, TickCells, WorldData, }, entity::{Entities, Entity, EntityLocation}, prelude::Component, @@ -217,12 +217,12 @@ impl<'w> UnsafeWorldCell<'w> { &unsafe { self.world_metadata() }.archetypes } - /// Retrieves this world's [`Components`] collection. + /// Retrieves this world's [`WorldData`] collection. #[inline] - pub fn components(self) -> &'w Components { + pub fn components(self) -> &'w WorldData { // SAFETY: // - we only access world metadata - &unsafe { self.world_metadata() }.components + &unsafe { self.world_metadata() }.world_data } /// Retrieves this world's collection of [removed components](RemovedComponentEvents). @@ -290,7 +290,7 @@ impl<'w> UnsafeWorldCell<'w> { #[inline] pub(crate) fn get_resource_archetype_component_id( self, - component_id: ComponentId, + component_id: DataId, ) -> Option { // SAFETY: // - we only access world metadata @@ -305,7 +305,7 @@ impl<'w> UnsafeWorldCell<'w> { #[inline] pub(crate) fn get_non_send_archetype_component_id( self, - component_id: ComponentId, + component_id: DataId, ) -> Option { // SAFETY: // - we only access world metadata @@ -366,7 +366,7 @@ impl<'w> UnsafeWorldCell<'w> { Some(Res { value, ticks }) } - /// Gets a pointer to the resource with the id [`ComponentId`] if it exists. + /// Gets a pointer to the resource with the id [`DataId`] if it exists. /// The returned pointer must not be used to modify the resource, and must not be /// dereferenced after the borrow of the [`World`] ends. /// @@ -378,7 +378,7 @@ impl<'w> UnsafeWorldCell<'w> { /// - the [`UnsafeWorldCell`] has permission to access the resource /// - no mutable reference to the resource exists at the same time #[inline] - pub unsafe fn get_resource_by_id(self, component_id: ComponentId) -> Option> { + pub unsafe fn get_resource_by_id(self, component_id: DataId) -> Option> { // SAFETY: caller ensures that `self` has permission to access `R` // caller ensures that no mutable reference exists to `R` unsafe { self.storages() } @@ -405,7 +405,7 @@ impl<'w> UnsafeWorldCell<'w> { } } - /// Gets a `!Send` resource to the resource with the id [`ComponentId`] if it exists. + /// Gets a `!Send` resource to the resource with the id [`DataId`] if it exists. /// The returned pointer must not be used to modify the resource, and must not be /// dereferenced after the immutable borrow of the [`World`] ends. /// @@ -420,12 +420,12 @@ impl<'w> UnsafeWorldCell<'w> { /// - the [`UnsafeWorldCell`] has permission to access the resource /// - no mutable reference to the resource exists at the same time #[inline] - pub unsafe fn get_non_send_resource_by_id(self, component_id: ComponentId) -> Option> { + pub unsafe fn get_non_send_resource_by_id(self, resource_id: DataId) -> Option> { // SAFETY: we only access data on world that the caller has ensured is unaliased and we have // permission to access. unsafe { self.storages() } .non_send_resources - .get(component_id)? + .get(resource_id)? .get_data() } @@ -437,18 +437,18 @@ impl<'w> UnsafeWorldCell<'w> { /// - no other references to the resource exist at the same time #[inline] pub unsafe fn get_resource_mut(self) -> Option> { - let component_id = self.components().get_resource_id(TypeId::of::())?; + let resource_id = self.components().get_resource_id(TypeId::of::())?; // SAFETY: // - caller ensures `self` has permission to access the resource mutably // - caller ensures no other references to the resource exist unsafe { - self.get_resource_mut_by_id(component_id) - // `component_id` was gotten from `TypeId::of::()` + self.get_resource_mut_by_id(resource_id) + // `resource_id` was gotten from `TypeId::of::()` .map(|ptr| ptr.with_type::()) } } - /// Gets a pointer to the resource with the id [`ComponentId`] if it exists. + /// Gets a pointer to the resource with the id [`DataId`] if it exists. /// The returned pointer may be used to modify the resource, as long as the mutable borrow /// of the [`UnsafeWorldCell`] is still valid. /// @@ -460,15 +460,12 @@ impl<'w> UnsafeWorldCell<'w> { /// - the [`UnsafeWorldCell`] has permission to access the resource mutably /// - no other references to the resource exist at the same time #[inline] - pub unsafe fn get_resource_mut_by_id( - self, - component_id: ComponentId, - ) -> Option> { + pub unsafe fn get_resource_mut_by_id(self, resource_id: DataId) -> Option> { // SAFETY: we only access data that the caller has ensured is unaliased and `self` // has permission to access. let (ptr, ticks) = unsafe { self.storages() } .resources - .get(component_id)? + .get(resource_id)? .get_with_ticks()?; // SAFETY: @@ -495,18 +492,18 @@ impl<'w> UnsafeWorldCell<'w> { /// - no other references to the resource exist at the same time #[inline] pub unsafe fn get_non_send_resource_mut(self) -> Option> { - let component_id = self.components().get_resource_id(TypeId::of::())?; + let resource_id = self.components().get_resource_id(TypeId::of::())?; // SAFETY: // - caller ensures that `self` has permission to access the resource // - caller ensures that the resource is unaliased unsafe { - self.get_non_send_resource_mut_by_id(component_id) - // SAFETY: `component_id` was gotten by `TypeId::of::()` + self.get_non_send_resource_mut_by_id(resource_id) + // SAFETY: `resource_id` was gotten by `TypeId::of::()` .map(|ptr| ptr.with_type::()) } } - /// Gets a `!Send` resource to the resource with the id [`ComponentId`] if it exists. + /// Gets a `!Send` resource to the resource with the id [`DataId`] if it exists. /// The returned pointer may be used to modify the resource, as long as the mutable borrow /// of the [`World`] is still valid. /// @@ -523,14 +520,14 @@ impl<'w> UnsafeWorldCell<'w> { #[inline] pub unsafe fn get_non_send_resource_mut_by_id( self, - component_id: ComponentId, + resource_id: DataId, ) -> Option> { let change_tick = self.change_tick(); // SAFETY: we only access data that the caller has ensured is unaliased and `self` // has permission to access. let (ptr, ticks) = unsafe { self.storages() } .non_send_resources - .get(component_id)? + .get(resource_id)? .get_with_ticks()?; let ticks = @@ -555,7 +552,7 @@ impl<'w> UnsafeWorldCell<'w> { #[inline] pub(crate) unsafe fn get_resource_with_ticks( self, - component_id: ComponentId, + resource_id: DataId, ) -> Option<(Ptr<'w>, TickCells<'w>)> { // SAFETY: // - caller ensures there is no `&mut World` @@ -563,7 +560,7 @@ impl<'w> UnsafeWorldCell<'w> { // - caller ensures that we have permission to access this resource unsafe { self.storages() } .resources - .get(component_id)? + .get(resource_id)? .get_with_ticks() } @@ -579,7 +576,7 @@ impl<'w> UnsafeWorldCell<'w> { #[inline] pub(crate) unsafe fn get_non_send_with_ticks( self, - component_id: ComponentId, + resource_id: DataId, ) -> Option<(Ptr<'w>, TickCells<'w>)> { // SAFETY: // - caller ensures there is no `&mut World` @@ -587,7 +584,7 @@ impl<'w> UnsafeWorldCell<'w> { // - caller ensures that we have permission to access this resource unsafe { self.storages() } .non_send_resources - .get(component_id)? + .get(resource_id)? .get_with_ticks() } } @@ -664,10 +661,10 @@ impl<'w> UnsafeEntityCell<'w> { /// ## Notes /// /// - If you know the concrete type of the component, you should prefer [`Self::contains`]. - /// - If you know the component's [`TypeId`] but not its [`ComponentId`], consider using + /// - If you know the component's [`TypeId`] but not its [`DataId`], consider using /// [`Self::contains_type_id`]. #[inline] - pub fn contains_id(self, component_id: ComponentId) -> bool { + pub fn contains_id(self, component_id: DataId) -> bool { self.archetype().contains(component_id) } @@ -677,7 +674,7 @@ impl<'w> UnsafeEntityCell<'w> { /// ## Notes /// /// - If you know the concrete type of the component, you should prefer [`Self::contains`]. - /// - If you have a [`ComponentId`] instead of a [`TypeId`], consider using [`Self::contains_id`]. + /// - If you have a [`DataId`] instead of a [`TypeId`], consider using [`Self::contains_id`]. #[inline] pub fn contains_type_id(self, type_id: TypeId) -> bool { let Some(id) = self.world.components().get_id(type_id) else { @@ -765,7 +762,7 @@ impl<'w> UnsafeEntityCell<'w> { } } - /// Retrieves the change ticks for the given [`ComponentId`]. This can be useful for implementing change + /// Retrieves the change ticks for the given [`DataId`]. This can be useful for implementing change /// detection in custom runtimes. /// /// **You should prefer to use the typed API [`UnsafeEntityCell::get_change_ticks`] where possible and only @@ -777,10 +774,7 @@ impl<'w> UnsafeEntityCell<'w> { /// - the [`UnsafeEntityCell`] has permission to access the component /// - no other mutable references to the component exist at the same time #[inline] - pub unsafe fn get_change_ticks_by_id( - &self, - component_id: ComponentId, - ) -> Option { + pub unsafe fn get_change_ticks_by_id(&self, component_id: DataId) -> Option { let info = self.world.components().get_info(component_id)?; // SAFETY: // - entity location and entity is valid @@ -841,7 +835,7 @@ impl<'w> UnsafeEntityCell<'w> { } impl<'w> UnsafeEntityCell<'w> { - /// Gets the component of the given [`ComponentId`] from the entity. + /// Gets the component of the given [`DataId`] from the entity. /// /// **You should prefer to use the typed API where possible and only /// use this in cases where the actual component types are not known at @@ -855,7 +849,7 @@ impl<'w> UnsafeEntityCell<'w> { /// - the [`UnsafeEntityCell`] has permission to access the component /// - no other mutable references to the component exist at the same time #[inline] - pub unsafe fn get_by_id(self, component_id: ComponentId) -> Option> { + pub unsafe fn get_by_id(self, component_id: DataId) -> Option> { let info = self.world.components().get_info(component_id)?; // SAFETY: entity_location is valid, component_id is valid as checked by the line above unsafe { @@ -869,7 +863,7 @@ impl<'w> UnsafeEntityCell<'w> { } } - /// Retrieves a mutable untyped reference to the given `entity`'s [`Component`] of the given [`ComponentId`]. + /// Retrieves a mutable untyped reference to the given `entity`'s [`Component`] of the given [`DataId`]. /// Returns `None` if the `entity` does not have a [`Component`] of the given type. /// /// **You should prefer to use the typed API [`UnsafeEntityCell::get_mut`] where possible and only @@ -880,7 +874,7 @@ impl<'w> UnsafeEntityCell<'w> { /// - the [`UnsafeEntityCell`] has permission to access the component mutably /// - no other references to the component exist at the same time #[inline] - pub unsafe fn get_mut_by_id(self, component_id: ComponentId) -> Option> { + pub unsafe fn get_mut_by_id(self, component_id: DataId) -> Option> { let info = self.world.components().get_info(component_id)?; // SAFETY: entity_location is valid, component_id is valid as checked by the line above unsafe { @@ -910,14 +904,10 @@ impl<'w> UnsafeWorldCell<'w> { /// - the returned `Column` is only used in ways that this [`UnsafeWorldCell`] has permission for. /// - the returned `Column` is only used in ways that would not conflict with any existing /// borrows of world data. - unsafe fn fetch_table( - self, - location: EntityLocation, - component_id: ComponentId, - ) -> Option<&'w Column> { + unsafe fn fetch_table(self, location: EntityLocation, data_id: DataId) -> Option<&'w Column> { // SAFETY: caller ensures returned data is not misused and we have not created any borrows // of component/resource data - unsafe { self.storages() }.tables[location.table_id].get_column(component_id) + unsafe { self.storages() }.tables[location.table_id].get_column(data_id) } #[inline] @@ -925,10 +915,10 @@ impl<'w> UnsafeWorldCell<'w> { /// - the returned `ComponentSparseSet` is only used in ways that this [`UnsafeWorldCell`] has permission for. /// - the returned `ComponentSparseSet` is only used in ways that would not conflict with any existing /// borrows of world data. - unsafe fn fetch_sparse_set(self, component_id: ComponentId) -> Option<&'w ComponentSparseSet> { + unsafe fn fetch_sparse_set(self, data_id: DataId) -> Option<&'w ComponentSparseSet> { // SAFETY: caller ensures returned data is not misused and we have not created any borrows // of component/resource data - unsafe { self.storages() }.sparse_sets.get(component_id) + unsafe { self.storages() }.sparse_sets.get(data_id) } } @@ -944,7 +934,7 @@ impl<'w> UnsafeWorldCell<'w> { #[allow(unsafe_op_in_unsafe_fn)] unsafe fn get_component( world: UnsafeWorldCell<'_>, - component_id: ComponentId, + component_id: DataId, storage_type: StorageType, entity: Entity, location: EntityLocation, @@ -971,7 +961,7 @@ unsafe fn get_component( #[allow(unsafe_op_in_unsafe_fn)] unsafe fn get_component_and_ticks( world: UnsafeWorldCell<'_>, - component_id: ComponentId, + component_id: DataId, storage_type: StorageType, entity: Entity, location: EntityLocation, @@ -1005,7 +995,7 @@ unsafe fn get_component_and_ticks( #[allow(unsafe_op_in_unsafe_fn)] unsafe fn get_ticks( world: UnsafeWorldCell<'_>, - component_id: ComponentId, + component_id: DataId, storage_type: StorageType, entity: Entity, location: EntityLocation, diff --git a/crates/bevy_ecs/src/world/world_cell.rs b/crates/bevy_ecs/src/world/world_cell.rs index 852858ba607b3..5e0335c3a0435 100644 --- a/crates/bevy_ecs/src/world/world_cell.rs +++ b/crates/bevy_ecs/src/world/world_cell.rs @@ -423,7 +423,7 @@ mod tests { } } - let u32_component_id = world.components.get_resource_id(TypeId::of::()).unwrap(); + let u32_component_id = world.world_data.get_resource_id(TypeId::of::()).unwrap(); let u32_archetype_component_id = world .get_resource_archetype_component_id(u32_component_id) .unwrap(); diff --git a/crates/bevy_scene/src/dynamic_scene_builder.rs b/crates/bevy_scene/src/dynamic_scene_builder.rs index ea14930466cf1..879e6f01b76dd 100644 --- a/crates/bevy_scene/src/dynamic_scene_builder.rs +++ b/crates/bevy_scene/src/dynamic_scene_builder.rs @@ -1,5 +1,5 @@ use crate::{DynamicEntity, DynamicScene, SceneFilter}; -use bevy_ecs::component::{Component, ComponentId}; +use bevy_ecs::component::{Component, DataId}; use bevy_ecs::system::Resource; use bevy_ecs::{ prelude::Entity, @@ -53,7 +53,7 @@ use std::collections::BTreeMap; /// let dynamic_scene = DynamicSceneBuilder::from_world(&world).extract_entity(entity).build(); /// ``` pub struct DynamicSceneBuilder<'w> { - extracted_resources: BTreeMap>, + extracted_resources: BTreeMap>, extracted_scene: BTreeMap, component_filter: SceneFilter, resource_filter: SceneFilter, diff --git a/examples/ecs/dynamic.rs b/examples/ecs/dynamic.rs index 3537f335fca90..cd84ee330bf3f 100644 --- a/examples/ecs/dynamic.rs +++ b/examples/ecs/dynamic.rs @@ -6,7 +6,7 @@ use std::{alloc::Layout, io::Write, ptr::NonNull}; use bevy::prelude::*; use bevy::{ ecs::{ - component::{ComponentDescriptor, ComponentId, ComponentInfo, StorageType}, + component::{DataDescriptor, DataId, DataInfo, StorageType}, query::{QueryBuilder, QueryData}, world::FilteredEntityMut, }, @@ -45,8 +45,8 @@ query, q Query for entities fn main() { let mut world = World::new(); let mut lines = std::io::stdin().lines(); - let mut component_names = HashMap::::new(); - let mut component_info = HashMap::::new(); + let mut component_names = HashMap::::new(); + let mut component_info = HashMap::::new(); println!("{}", PROMPT); loop { @@ -84,7 +84,7 @@ fn main() { // Register our new component to the world with a layout specified by it's size // SAFETY: [u64] is Send + Sync let id = world.init_component_with_descriptor(unsafe { - ComponentDescriptor::new_with_layout( + DataDescriptor::new_with_layout( name.to_string(), StorageType::Table, Layout::array::(size).unwrap(), @@ -206,7 +206,7 @@ fn to_owning_ptrs(components: &mut [Vec]) -> Vec> { fn parse_term( str: &str, builder: &mut QueryBuilder, - components: &HashMap, + components: &HashMap, ) { let mut matched = false; let str = str.trim(); @@ -250,7 +250,7 @@ fn parse_term( fn parse_query( str: &str, builder: &mut QueryBuilder, - components: &HashMap, + components: &HashMap, ) { let str = str.split(','); str.for_each(|term| {