Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename many types to better reflect their usability (in the context of Components and Resources) #11772

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/bevy_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -49,7 +49,7 @@ impl Plugin for TypeRegistrationPlugin {

fn register_ecs_types(app: &mut App) {
app.register_type::<Entity>()
.register_type::<ComponentId>()
.register_type::<DataId>()
.register_type::<Tick>()
.register_type::<ComponentTicks>();
}
Expand Down
8 changes: 4 additions & 4 deletions crates/bevy_ecs/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)*
}
Expand Down Expand Up @@ -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,)*)>
{
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_ecs/macros/src/world_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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); )*
}

Expand All @@ -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))*
}
}
Expand Down
35 changes: 16 additions & 19 deletions crates/bevy_ecs/src/archetype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

use crate::{
bundle::BundleId,
component::{ComponentId, StorageType},
component::{DataId, StorageType},
entity::{Entity, EntityLocation},
storage::{ImmutableSparseSet, SparseArray, SparseSet, SparseSetIndex, TableId, TableRow},
};
Expand Down Expand Up @@ -309,15 +309,15 @@ pub struct Archetype {
table_id: TableId,
edges: Edges,
entities: Vec<ArchetypeEntity>,
components: ImmutableSparseSet<ComponentId, ArchetypeComponentInfo>,
components: ImmutableSparseSet<DataId, ArchetypeComponentInfo>,
}

impl Archetype {
pub(crate) fn new(
id: ArchetypeId,
table_id: TableId,
table_components: impl Iterator<Item = (ComponentId, ArchetypeComponentId)>,
sparse_set_components: impl Iterator<Item = (ComponentId, ArchetypeComponentId)>,
table_components: impl Iterator<Item = (DataId, ArchetypeComponentId)>,
sparse_set_components: impl Iterator<Item = (DataId, ArchetypeComponentId)>,
) -> Self {
let (min_table, _) = table_components.size_hint();
let (min_sparse, _) = sparse_set_components.size_hint();
Expand Down Expand Up @@ -376,7 +376,7 @@ impl Archetype {
///
/// [`Table`]: crate::storage::Table
#[inline]
pub fn table_components(&self) -> impl Iterator<Item = ComponentId> + '_ {
pub fn table_components(&self) -> impl Iterator<Item = DataId> + '_ {
self.components
.iter()
.filter(|(_, component)| component.storage_type == StorageType::Table)
Expand All @@ -389,7 +389,7 @@ impl Archetype {
///
/// [`ComponentSparseSet`]: crate::storage::ComponentSparseSet
#[inline]
pub fn sparse_set_components(&self) -> impl Iterator<Item = ComponentId> + '_ {
pub fn sparse_set_components(&self) -> impl Iterator<Item = DataId> + '_ {
self.components
.iter()
.filter(|(_, component)| component.storage_type == StorageType::SparseSet)
Expand All @@ -400,7 +400,7 @@ impl Archetype {
///
/// All of the IDs are unique.
#[inline]
pub fn components(&self) -> impl Iterator<Item = ComponentId> + '_ {
pub fn components(&self) -> impl Iterator<Item = DataId> + '_ {
self.components.indices()
}

Expand Down Expand Up @@ -505,15 +505,15 @@ 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)
}

/// Gets the type of storage where a component in the archetype can be found.
/// 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<StorageType> {
pub fn get_storage_type(&self, component_id: DataId) -> Option<StorageType> {
self.components
.get(component_id)
.map(|info| info.storage_type)
Expand All @@ -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<ArchetypeComponentId> {
pub fn get_archetype_component_id(&self, component_id: DataId) -> Option<ArchetypeComponentId> {
self.components
.get(component_id)
.map(|info| info.archetype_component_id)
Expand Down Expand Up @@ -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`].
Expand All @@ -566,10 +563,10 @@ struct ArchetypeComponents {
/// schedulers to opportunistically run multiple systems in parallel that would otherwise
/// conflict. For example, `Query<&mut A, With<B>>` and `Query<&mut A, Without<B>>` 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.
Expand Down Expand Up @@ -714,8 +711,8 @@ impl Archetypes {
pub(crate) fn get_id_or_insert(
&mut self,
table_id: TableId,
table_components: Vec<ComponentId>,
sparse_set_components: Vec<ComponentId>,
table_components: Vec<DataId>,
sparse_set_components: Vec<DataId>,
) -> ArchetypeId {
let archetype_identity = ArchetypeComponents {
sparse_set_components: sparse_set_components.clone().into_boxed_slice(),
Expand Down
60 changes: 30 additions & 30 deletions crates/bevy_ecs/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<C: Component> 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::<C>(storages));
}
Expand Down Expand Up @@ -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);)*
}

Expand Down Expand Up @@ -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<ComponentId>,
component_ids: Vec<DataId>,
}

impl BundleInfo {
Expand All @@ -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<ComponentId>,
components: &WorldData,
component_ids: Vec<DataId>,
id: BundleId,
) -> BundleInfo {
let mut deduped = component_ids.clone();
Expand Down Expand Up @@ -338,17 +338,17 @@ 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
}

pub(crate) fn get_bundle_inserter<'a, 'b>(
&'b self,
entities: &'a mut Entities,
archetypes: &'a mut Archetypes,
components: &Components,
components: &WorldData,
storages: &'a mut Storages,
archetype_id: ArchetypeId,
change_tick: Tick,
Expand Down Expand Up @@ -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> {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -799,9 +799,9 @@ pub struct Bundles {
/// Cache static [`BundleId`]
bundle_ids: TypeIdMap<BundleId>,
/// Cache dynamic [`BundleId`] with multiple components
dynamic_bundle_ids: HashMap<Vec<ComponentId>, (BundleId, Vec<StorageType>)>,
dynamic_bundle_ids: HashMap<Vec<DataId>, (BundleId, Vec<StorageType>)>,
/// Cache optimized dynamic [`BundleId`] with single component
dynamic_component_bundle_ids: HashMap<ComponentId, (BundleId, StorageType)>,
dynamic_component_bundle_ids: HashMap<DataId, (BundleId, StorageType)>,
}

impl Bundles {
Expand All @@ -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;
Expand All @@ -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<StorageType>) {
let bundle_infos = &mut self.bundle_infos;

Expand All @@ -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
Expand All @@ -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<BundleInfo>,
components: &Components,
component_ids: Vec<ComponentId>,
components: &WorldData,
component_ids: Vec<DataId>,
) -> (BundleId, Vec<StorageType>) {
// Assert component existence
let storage_types = component_ids.iter().map(|&id| {
Expand Down
Loading