Skip to content

Commit

Permalink
Documentation for querying archetype claims.
Browse files Browse the repository at this point in the history
  • Loading branch information
Anders429 committed Jan 31, 2023
1 parent 96a98e0 commit 1988e77
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Iterator over dynamic claims of a query on its affected archetypes.
use crate::{
archetype,
archetypes,
Expand All @@ -16,7 +18,11 @@ use crate::{
};
use core::marker::PhantomData;

pub struct ArchetypeIdentifiers<'a, R, F, FI, V, VI, P, I, Q>
/// Iterator over dynamic claims of a query on its affected archetypes.
///
/// This iterator returns key-value pairs of archetype identifiers and the list of claimed
/// components for the given query on that archetype.
pub struct ArchetypeClaims<'a, R, F, FI, V, VI, P, I, Q>
where
R: Registry,
{
Expand All @@ -31,11 +37,13 @@ where
reshape_indices: PhantomData<Q>,
}

impl<'a, R, F, FI, V, VI, P, I, Q> ArchetypeIdentifiers<'a, R, F, FI, V, VI, P, I, Q>
impl<'a, R, F, FI, V, VI, P, I, Q> ArchetypeClaims<'a, R, F, FI, V, VI, P, I, Q>
where
R: Registry,
{
/// # SAFETY
/// Returns a new `ArchetypeClaims` iterator.
///
/// # Safety
/// The `archetype::IdentifierRef`s over which this iterator iterates must not outlive the
/// `Archetypes` to which they belong.
pub(crate) unsafe fn new(archetypes_iter: archetypes::IterMut<'a, R>) -> Self {
Expand All @@ -53,7 +61,7 @@ where
}
}

impl<'a, R, F, FI, V, VI, P, I, Q> Iterator for ArchetypeIdentifiers<'a, R, F, FI, V, VI, P, I, Q>
impl<'a, R, F, FI, V, VI, P, I, Q> Iterator for ArchetypeClaims<'a, R, F, FI, V, VI, P, I, Q>
where
F: Filter,
V: Views<'a> + Filter,
Expand Down
4 changes: 2 additions & 2 deletions src/query/result/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
//! [`World`]: crate::world::World
#[cfg(feature = "rayon")]
pub(crate) mod archetype_identifiers;
pub(crate) mod archetype_claims;
pub(crate) mod get;
pub(crate) mod reshape;

Expand All @@ -64,7 +64,7 @@ pub use iter::Iter;
pub use par_iter::ParIter;

#[cfg(feature = "rayon")]
pub(crate) use archetype_identifiers::ArchetypeIdentifiers;
pub(crate) use archetype_claims::ArchetypeClaims;
pub(crate) use get::Get;
pub(crate) use reshape::Reshape;
#[cfg(feature = "rayon")]
Expand Down
4 changes: 2 additions & 2 deletions src/system/schedule/stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ where
// SAFETY: The access to the world's archetype identifiers follows Rust's borrowing
// rules.
unsafe {
(*world.get()).query_archetype_identifiers(Query::<T::Views, T::Filter>::new())
(*world.get()).query_archetype_claims(Query::<T::Views, T::Filter>::new())
}
{
match merged_borrowed_archetypes.entry(identifier) {
Expand Down Expand Up @@ -157,7 +157,7 @@ fn query_archetype_identifiers_unchecked<'a, R, T, FI, VI, P, I, Q>(
// SAFETY: The access to the world's archetype identifiers follows Rust's borrowing
// rules.
unsafe {
(*world.get()).query_archetype_identifiers(Query::<T::Views, T::Filter>::new())
(*world.get()).query_archetype_claims(Query::<T::Views, T::Filter>::new())
}
{
borrowed_archetypes.insert_unique_unchecked(identifier, claims);
Expand Down
8 changes: 5 additions & 3 deletions src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,22 +360,24 @@ where
result::ParIter::new(self.archetypes.par_iter_mut())
}

/// Return the claims on each archetype touched by the given query.
///
/// # Safety
/// The `archetype::IdentifierRef`s over which this iterator iterates must not outlive the
/// `Archetypes` to which they belong.
#[cfg(feature = "rayon")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "rayon")))]
pub(crate) unsafe fn query_archetype_identifiers<'a, V, F, VI, FI, P, I, Q>(
pub(crate) unsafe fn query_archetype_claims<'a, V, F, VI, FI, P, I, Q>(
&'a mut self,
#[allow(unused_variables)] query: Query<V, F>,
) -> result::ArchetypeIdentifiers<'a, R, F, FI, V, VI, P, I, Q>
) -> result::ArchetypeClaims<'a, R, F, FI, V, VI, P, I, Q>
where
V: Views<'a> + Filter,
F: Filter,
R: ContainsFilter<And<F, V>, And<FI, VI>>,
{
// SAFETY: The safety contract here is upheld by the safety contract of this method.
unsafe { result::ArchetypeIdentifiers::new(self.archetypes.iter_mut()) }
unsafe { result::ArchetypeClaims::new(self.archetypes.iter_mut()) }
}

/// Run a [`System`] over the entities in this `World`.
Expand Down

0 comments on commit 1988e77

Please sign in to comment.