Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 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/time/fixed_timestep.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::Time;
use bevy_ecs::{
archetype::{Archetype, ArchetypeComponentId},
component::ComponentId,
component::DataId,
query::Access,
schedule::ShouldRun,
system::{ConfigurableSystem, IntoSystem, Local, Res, ResMut, System},
Expand Down Expand Up @@ -156,7 +156,7 @@ impl System for FixedTimestep {
self.internal_system.archetype_component_access()
}

fn component_access(&self) -> &Access<ComponentId> {
fn component_access(&self) -> &Access<DataId> {
self.internal_system.component_access()
}

Expand Down
10 changes: 5 additions & 5 deletions crates/bevy_ecs/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@ pub fn derive_bundle(input: TokenStream) -> TokenStream {
let struct_name = &ast.ident;

TokenStream::from(quote! {
/// SAFE: ComponentId is returned in field-definition-order. [from_components] and [get_components] use field-definition-order
/// SAFE: DataId is returned in field-definition-order. [from_components] and [get_components] use field-definition-order
unsafe impl #impl_generics #ecs_path::bundle::Bundle for #struct_name#ty_generics #where_clause {
fn component_ids(
components: &mut #ecs_path::component::Components,
components: &mut #ecs_path::component::WorldData,
storages: &mut #ecs_path::storage::Storages,
) -> Vec<#ecs_path::component::ComponentId> {
) -> Vec<#ecs_path::component::DataId> {
let mut component_ids = Vec::with_capacity(#field_len);
#(#field_component_ids)*
component_ids
Expand Down Expand Up @@ -195,7 +195,7 @@ pub fn impl_query_set(_input: TokenStream) -> TokenStream {
pub fn #fn_name(&mut self) -> Query<'_, '_, #query, #filter> {
// SAFE: systems run without conflicts with other systems.
// Conflicting queries in QuerySet are not accessible at the same time
// QuerySets are guaranteed to not conflict with other SystemParams
// QuerySets are guaranteed to not onflict with other SystemParams
unsafe {
Query::new(self.world, &self.query_states.#index, self.last_change_tick, self.change_tick)
}
Expand All @@ -219,7 +219,7 @@ pub fn impl_query_set(_input: TokenStream) -> TokenStream {
where #(#query::Fetch: ReadOnlyFetch,)* #(#filter::Fetch: FilterFetch,)*
{ }

// SAFE: Relevant query ComponentId and ArchetypeComponentId access is applied to SystemMeta. If any QueryState conflicts
// SAFE: Relevant query DataId and ArchetypeComponentId access is applied to SystemMeta. If any QueryState conflicts
// with any prior access, a panic will occur.
unsafe impl<#(#query: WorldQuery + 'static,)* #(#filter: WorldQuery + 'static,)*> SystemParamState for QuerySetState<(#(QueryState<#query, #filter>,)*)>
where #(#filter::Fetch: FilterFetch,)*
Expand Down
41 changes: 19 additions & 22 deletions crates/bevy_ecs/src/archetype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use crate::{
bundle::BundleId,
component::{ComponentId, StorageType},
component::{DataId, StorageType},
entity::{Entity, EntityLocation},
storage::{Column, SparseArray, SparseSet, SparseSetIndex, TableId},
};
Expand Down Expand Up @@ -121,18 +121,18 @@ pub struct Archetype {
entities: Vec<Entity>,
edges: Edges,
table_info: TableInfo,
table_components: Cow<'static, [ComponentId]>,
sparse_set_components: Cow<'static, [ComponentId]>,
pub(crate) unique_components: SparseSet<ComponentId, Column>,
pub(crate) components: SparseSet<ComponentId, ArchetypeComponentInfo>,
table_components: Cow<'static, [DataId]>,
sparse_set_components: Cow<'static, [DataId]>,
pub(crate) unique_components: SparseSet<DataId, Column>,
pub(crate) components: SparseSet<DataId, ArchetypeComponentInfo>,
}

impl Archetype {
pub fn new(
id: ArchetypeId,
table_id: TableId,
table_components: Cow<'static, [ComponentId]>,
sparse_set_components: Cow<'static, [ComponentId]>,
table_components: Cow<'static, [DataId]>,
sparse_set_components: Cow<'static, [DataId]>,
table_archetype_components: Vec<ArchetypeComponentId>,
sparse_set_archetype_components: Vec<ArchetypeComponentId>,
) -> Self {
Expand Down Expand Up @@ -198,27 +198,27 @@ impl Archetype {
}

#[inline]
pub fn table_components(&self) -> &[ComponentId] {
pub fn table_components(&self) -> &[DataId] {
&self.table_components
}

#[inline]
pub fn sparse_set_components(&self) -> &[ComponentId] {
pub fn sparse_set_components(&self) -> &[DataId] {
&self.sparse_set_components
}

#[inline]
pub fn unique_components(&self) -> &SparseSet<ComponentId, Column> {
pub fn unique_components(&self) -> &SparseSet<DataId, Column> {
&self.unique_components
}

#[inline]
pub fn unique_components_mut(&mut self) -> &mut SparseSet<ComponentId, Column> {
pub fn unique_components_mut(&mut self) -> &mut SparseSet<DataId, Column> {
&mut self.unique_components
}

#[inline]
pub fn components(&self) -> impl Iterator<Item = ComponentId> + '_ {
pub fn components(&self) -> impl Iterator<Item = DataId> + '_ {
self.components.indices()
}

Expand Down Expand Up @@ -286,22 +286,19 @@ impl Archetype {
}

#[inline]
pub fn contains(&self, component_id: ComponentId) -> bool {
pub fn contains(&self, component_id: DataId) -> bool {
self.components.contains(component_id)
}

#[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)
}

#[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 @@ -331,8 +328,8 @@ impl ArchetypeGeneration {

#[derive(Hash, PartialEq, Eq)]
pub struct ArchetypeIdentity {
table_components: Cow<'static, [ComponentId]>,
sparse_set_components: Cow<'static, [ComponentId]>,
table_components: Cow<'static, [DataId]>,
sparse_set_components: Cow<'static, [DataId]>,
}

#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
Expand Down Expand Up @@ -474,8 +471,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 table_components = Cow::from(table_components);
let sparse_set_components = Cow::from(sparse_set_components);
Expand Down
36 changes: 18 additions & 18 deletions crates/bevy_ecs/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub use bevy_ecs_macros::Bundle;

use crate::{
archetype::{AddBundle, Archetype, ArchetypeId, Archetypes, ComponentStatus},
component::{Component, ComponentId, ComponentTicks, Components, StorageType},
component::{Component, ComponentTicks, DataId, StorageType, WorldData},
entity::{Entities, Entity, EntityLocation},
storage::{SparseSetIndex, SparseSets, Storages, Table},
};
Expand Down Expand Up @@ -71,25 +71,25 @@ use std::{any::TypeId, collections::HashMap};
///
/// # Safety
///
/// - [Bundle::component_ids] must return the ComponentId for each component type in the bundle, in the
/// - [Bundle::component_ids] must return the DataId for each component type in the bundle, in the
/// _exact_ order that [Bundle::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: Send + Sync + 'static {
/// Gets this [Bundle]'s component ids, in the order of this bundle's Components
fn component_ids(components: &mut Components, storages: &mut Storages) -> Vec<ComponentId>;
/// Gets this [Bundle]'s component ids, in the order of this bundle's WorldData
fn component_ids(components: &mut WorldData, storages: &mut Storages) -> Vec<DataId>;

/// Calls `func`, which should return data for each component in the bundle, in the order of
/// this bundle's Components
/// this bundle's WorldData
///
/// # Safety
/// Caller must return data for each component in the bundle, in the order of this bundle's
/// Components
/// WorldData
unsafe fn from_components(func: impl FnMut() -> *mut u8) -> Self
where
Self: Sized;

/// Calls `func` on each value, in the order of this bundle's Components. This will
/// Calls `func` on each value, in the order of this bundle's WorldData. This will
/// "mem::forget" the bundle fields, so callers are responsible for dropping the fields if
/// that is desirable.
fn get_components(self, func: impl FnMut(*mut u8));
Expand All @@ -100,7 +100,7 @@ macro_rules! tuple_impl {
/// SAFE: Component is returned in tuple-order. [Bundle::from_components] and [Bundle::get_components] use tuple-order
unsafe impl<$($name: Component),*> Bundle for ($($name,)*) {
#[allow(unused_variables)]
fn component_ids(components: &mut Components, storages: &mut Storages) -> Vec<ComponentId> {
fn component_ids(components: &mut WorldData, storages: &mut Storages) -> Vec<DataId> {
vec![$(components.init_component::<$name>(storages)),*]
}

Expand Down Expand Up @@ -152,7 +152,7 @@ impl SparseSetIndex for BundleId {

pub struct BundleInfo {
pub(crate) id: BundleId,
pub(crate) component_ids: Vec<ComponentId>,
pub(crate) component_ids: Vec<DataId>,
pub(crate) storage_types: Vec<StorageType>,
}

Expand All @@ -163,7 +163,7 @@ impl BundleInfo {
}

#[inline]
pub fn components(&self) -> &[ComponentId] {
pub fn components(&self) -> &[DataId] {
&self.component_ids
}

Expand All @@ -176,7 +176,7 @@ impl BundleInfo {
&'b self,
entities: &'a mut Entities,
archetypes: &'a mut Archetypes,
components: &mut Components,
components: &mut WorldData,
storages: &'a mut Storages,
archetype_id: ArchetypeId,
change_tick: u32,
Expand Down Expand Up @@ -236,7 +236,7 @@ impl BundleInfo {
&'b self,
entities: &'a mut Entities,
archetypes: &'a mut Archetypes,
components: &mut Components,
components: &mut WorldData,
storages: &'a mut Storages,
change_tick: u32,
) -> BundleSpawner<'a, 'b> {
Expand Down Expand Up @@ -308,7 +308,7 @@ impl BundleInfo {
&self,
archetypes: &mut Archetypes,
storages: &mut Storages,
components: &mut Components,
components: &mut WorldData,
archetype_id: ArchetypeId,
) -> ArchetypeId {
if let Some(add_bundle) = archetypes[archetype_id].edges().get_add_bundle(self.id) {
Expand Down Expand Up @@ -591,7 +591,7 @@ impl Bundles {

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 @@ -612,12 +612,12 @@ impl Bundles {

/// # Safety
///
/// `component_id` must be valid [ComponentId]'s
/// `component_id` must be valid [DataId]'s
unsafe fn initialize_bundle(
bundle_type_name: &'static str,
component_ids: Vec<ComponentId>,
component_ids: Vec<DataId>,
id: BundleId,
components: &mut Components,
components: &mut WorldData,
) -> BundleInfo {
let mut storage_types = Vec::new();

Expand Down
Loading