Make Archetypes.archetype_component_count private (#10774)
Make more clear where it is used and how.
This commit is contained in:
parent
c99ca79825
commit
c55a5ba40b
@ -588,13 +588,6 @@ struct ArchetypeComponents {
|
|||||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
||||||
pub struct ArchetypeComponentId(usize);
|
pub struct ArchetypeComponentId(usize);
|
||||||
|
|
||||||
impl ArchetypeComponentId {
|
|
||||||
#[inline]
|
|
||||||
pub(crate) const fn new(index: usize) -> Self {
|
|
||||||
Self(index)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SparseSetIndex for ArchetypeComponentId {
|
impl SparseSetIndex for ArchetypeComponentId {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sparse_set_index(&self) -> usize {
|
fn sparse_set_index(&self) -> usize {
|
||||||
@ -614,7 +607,7 @@ impl SparseSetIndex for ArchetypeComponentId {
|
|||||||
/// [module level documentation]: crate::archetype
|
/// [module level documentation]: crate::archetype
|
||||||
pub struct Archetypes {
|
pub struct Archetypes {
|
||||||
pub(crate) archetypes: Vec<Archetype>,
|
pub(crate) archetypes: Vec<Archetype>,
|
||||||
pub(crate) archetype_component_count: usize,
|
archetype_component_count: usize,
|
||||||
by_components: bevy_utils::HashMap<ArchetypeComponents, ArchetypeId>,
|
by_components: bevy_utils::HashMap<ArchetypeComponents, ArchetypeId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -666,6 +659,22 @@ impl Archetypes {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Generate and store a new [`ArchetypeComponentId`].
|
||||||
|
///
|
||||||
|
/// This simply increment the counter and return the new value.
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// On archetype component id overflow.
|
||||||
|
pub(crate) fn new_archetype_component_id(&mut self) -> ArchetypeComponentId {
|
||||||
|
let id = ArchetypeComponentId(self.archetype_component_count);
|
||||||
|
self.archetype_component_count = self
|
||||||
|
.archetype_component_count
|
||||||
|
.checked_add(1)
|
||||||
|
.expect("archetype_component_count overflow");
|
||||||
|
id
|
||||||
|
}
|
||||||
|
|
||||||
/// Fetches an immutable reference to an [`Archetype`] using its
|
/// Fetches an immutable reference to an [`Archetype`] using its
|
||||||
/// ID. Returns `None` if no corresponding archetype exists.
|
/// ID. Returns `None` if no corresponding archetype exists.
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|||||||
@ -1780,13 +1780,11 @@ impl World {
|
|||||||
&mut self,
|
&mut self,
|
||||||
component_id: ComponentId,
|
component_id: ComponentId,
|
||||||
) -> &mut ResourceData<true> {
|
) -> &mut ResourceData<true> {
|
||||||
let archetype_component_count = &mut self.archetypes.archetype_component_count;
|
let archetypes = &mut self.archetypes;
|
||||||
self.storages
|
self.storages
|
||||||
.resources
|
.resources
|
||||||
.initialize_with(component_id, &self.components, || {
|
.initialize_with(component_id, &self.components, || {
|
||||||
let id = ArchetypeComponentId::new(*archetype_component_count);
|
archetypes.new_archetype_component_id()
|
||||||
*archetype_component_count += 1;
|
|
||||||
id
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1797,13 +1795,11 @@ impl World {
|
|||||||
&mut self,
|
&mut self,
|
||||||
component_id: ComponentId,
|
component_id: ComponentId,
|
||||||
) -> &mut ResourceData<false> {
|
) -> &mut ResourceData<false> {
|
||||||
let archetype_component_count = &mut self.archetypes.archetype_component_count;
|
let archetypes = &mut self.archetypes;
|
||||||
self.storages
|
self.storages
|
||||||
.non_send_resources
|
.non_send_resources
|
||||||
.initialize_with(component_id, &self.components, || {
|
.initialize_with(component_id, &self.components, || {
|
||||||
let id = ArchetypeComponentId::new(*archetype_component_count);
|
archetypes.new_archetype_component_id()
|
||||||
*archetype_component_count += 1;
|
|
||||||
id
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user