bevy_trait_query/one/core/fetch.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
use std::cell::UnsafeCell;
use bevy_ecs::{
component::Tick,
ptr::{Ptr, ThinSlicePtr},
storage::{ComponentSparseSet, SparseSets},
};
use crate::TraitImplMeta;
pub struct OneTraitFetch<'w, Trait: ?Sized> {
// While we have shared access to all sparse set components,
// in practice we will only access the components specified in the `FetchState`.
// These accesses have been registered, which prevents runtime conflicts.
pub(crate) sparse_sets: &'w SparseSets,
// After `Fetch::set_archetype` or `set_table` has been called,
// this will carry the component data and metadata for the first trait impl found in the archetype.
pub(crate) storage: FetchStorage<'w, Trait>,
pub(crate) last_run: Tick,
pub(crate) this_run: Tick,
}
impl<Trait: ?Sized> Clone for OneTraitFetch<'_, Trait> {
fn clone(&self) -> Self {
*self
}
}
impl<Trait: ?Sized> Copy for OneTraitFetch<'_, Trait> {}
pub(crate) enum FetchStorage<'w, Trait: ?Sized> {
Uninit,
Table {
/// This points to one of the component table columns,
/// corresponding to one of the `ComponentId`s in the fetch state.
/// The fetch impl registers access for all of these components,
/// so there will be no runtime conflicts.
column: Ptr<'w>,
added_ticks: ThinSlicePtr<'w, UnsafeCell<Tick>>,
changed_ticks: ThinSlicePtr<'w, UnsafeCell<Tick>>,
meta: TraitImplMeta<Trait>,
},
SparseSet {
/// This gives us access to one of the components implementing the trait.
/// The fetch impl registers access for all components implementing the trait,
/// so there will not be any runtime conflicts.
components: &'w ComponentSparseSet,
meta: TraitImplMeta<Trait>,
},
}
impl<Trait: ?Sized> Clone for FetchStorage<'_, Trait> {
fn clone(&self) -> Self {
*self
}
}
impl<Trait: ?Sized> Copy for FetchStorage<'_, Trait> {}