pub struct View<'a, T: Component, Track: Tracking = <T as Component>::Tracking> { /* private fields */ }
Expand description
Shared view over a component storage.
Implementations§
source§impl<'a, T: Component, Track: Tracking> View<'a, T, Track>
impl<'a, T: Component, Track: Tracking> View<'a, T, Track>
sourcepub const ASSERT_VIEW_TRACKING_INSERTION: () = _
pub const ASSERT_VIEW_TRACKING_INSERTION: () = _
Check that the view tracks insertion if the component is tracking it.
sourcepub const ASSERT_VIEW_TRACKING_MODIFICATION: () = _
pub const ASSERT_VIEW_TRACKING_MODIFICATION: () = _
Check that the view tracks modification if the component is tracking it.
sourcepub const ASSERT_VIEW_TRACKING_DELETION: () = _
pub const ASSERT_VIEW_TRACKING_DELETION: () = _
Check that the view tracks deletion if the component is tracking it.
sourcepub const ASSERT_VIEW_TRACKING_REMOVAL: () = _
pub const ASSERT_VIEW_TRACKING_REMOVAL: () = _
Check that the view tracks removal if the component is tracking it.
source§impl<'a, T: Component, Track> View<'a, T, Track>where
Track: Tracking,
impl<'a, T: Component, Track> View<'a, T, Track>where
Track: Tracking,
sourcepub fn override_last_insertion(
&mut self,
new_timestamp: TrackingTimestamp,
) -> TrackingTimestamp
pub fn override_last_insertion( &mut self, new_timestamp: TrackingTimestamp, ) -> TrackingTimestamp
Replaces the timestamp starting the tracking time window for insertions.
Tracking works based on a time window. From the last time the system ran (in workloads) or since the last clear.
Sometimes this automatic time window isn’t what you need. This can happen when you want to keep the same tracking information for multiple runs of the same system.
For example if you interpolate movement between frames, you might run an interpolation workload
multiple times but not change the World
during its execution.
In this case you want the same tracking information for all runs of this workload
which would have disappeared using the automatic window.
sourcepub fn override_last_modification(
&mut self,
new_timestamp: TrackingTimestamp,
) -> TrackingTimestamp
pub fn override_last_modification( &mut self, new_timestamp: TrackingTimestamp, ) -> TrackingTimestamp
Replaces the timestamp starting the tracking time window for modifications.
Tracking works based on a time window. From the last time the system ran (in workloads) or since the last clear.
Sometimes this automatic time window isn’t what you need. This can happen when you want to keep the same tracking information for multiple runs of the same system.
For example if you interpolate movement between frames, you might run an interpolation workload
multiple times but not change the World
during its execution.
In this case you want the same tracking information for all runs of this workload
which would have disappeared using the automatic window.
sourcepub fn override_last_removal_or_deletion(
&mut self,
new_timestamp: TrackingTimestamp,
) -> TrackingTimestamp
pub fn override_last_removal_or_deletion( &mut self, new_timestamp: TrackingTimestamp, ) -> TrackingTimestamp
Replaces the timestamp starting the tracking time window for removals and deletions.
Tracking works based on a time window. From the last time the system ran (in workloads) or since the last clear.
Sometimes this automatic time window isn’t what you need. This can happen when you want to keep the same tracking information for multiple runs of the same system.
For example if you interpolate movement between frames, you might run an interpolation workload
multiple times but not change the World
during its execution.
In this case you want the same tracking information for all runs of this workload
which would have disappeared using the automatic window.
source§impl<'a, T: Component> View<'a, T, Untracked>
impl<'a, T: Component> View<'a, T, Untracked>
sourcepub fn new_for_custom_storage(
storage_id: StorageId,
all_storages: ARef<'a, &'a AllStorages>,
) -> Result<Self, CustomStorageView>
pub fn new_for_custom_storage( storage_id: StorageId, all_storages: ARef<'a, &'a AllStorages>, ) -> Result<Self, CustomStorageView>
Creates a new View
for custom SparseSet
storage.
use shipyard::{track, Component, SparseSet, StorageId, View, World};
struct ScriptingComponent(Vec<u8>);
impl Component for ScriptingComponent {
type Tracking = track::Untracked;
}
let world = World::new();
world.add_custom_storage(
StorageId::Custom(0),
SparseSet::<ScriptingComponent>::new_custom_storage(),
).unwrap();
let all_storages = world.all_storages().unwrap();
let scripting_storage =
View::<ScriptingComponent>::new_for_custom_storage(StorageId::Custom(0), all_storages)
.unwrap();
source§impl<Track, T: Component> View<'_, T, Track>where
Track: InsertionTracking,
impl<Track, T: Component> View<'_, T, Track>where
Track: InsertionTracking,
sourcepub fn inserted(&self) -> Inserted<&Self>
pub fn inserted(&self) -> Inserted<&Self>
Wraps this view to be able to iterate inserted components.
sourcepub fn is_inserted(&self, entity: EntityId) -> bool
pub fn is_inserted(&self, entity: EntityId) -> bool
Inside a workload returns true
if entity
’s component was inserted since the last run of this system.
Outside workloads returns true
if entity
’s component was inserted since the last call to clear_all_inserted
.
Returns false
if entity
does not have a component in this storage.
source§impl<Track, T: Component> View<'_, T, Track>where
Track: ModificationTracking,
impl<Track, T: Component> View<'_, T, Track>where
Track: ModificationTracking,
sourcepub fn modified(&self) -> Modified<&Self>
pub fn modified(&self) -> Modified<&Self>
Wraps this view to be able to iterate modified components.
sourcepub fn is_modified(&self, entity: EntityId) -> bool
pub fn is_modified(&self, entity: EntityId) -> bool
Inside a workload returns true
if entity
’s component was modified since the last run of this system.
Outside workloads returns true
if entity
’s component was modified since the last call to clear_all_modified
.
Returns false
if entity
does not have a component in this storage.
source§impl<Track, T: Component> View<'_, T, Track>where
Track: InsertionTracking + ModificationTracking,
impl<Track, T: Component> View<'_, T, Track>where
Track: InsertionTracking + ModificationTracking,
sourcepub fn inserted_or_modified(&self) -> InsertedOrModified<&Self>
pub fn inserted_or_modified(&self) -> InsertedOrModified<&Self>
Wraps this view to be able to iterate inserted and modified components.
sourcepub fn is_inserted_or_modified(&self, entity: EntityId) -> bool
pub fn is_inserted_or_modified(&self, entity: EntityId) -> bool
Inside a workload returns true
if entity
’s component was inserted or modified since the last run of this system.
Outside workloads returns true
if entity
’s component was inserted or modified since the last call to clear_all_inserted
.
Returns false
if entity
does not have a component in this storage.
source§impl<Track, T: Component> View<'_, T, Track>where
Track: DeletionTracking,
impl<Track, T: Component> View<'_, T, Track>where
Track: DeletionTracking,
sourcepub fn deleted(&self) -> impl Iterator<Item = (EntityId, &T)> + '_
pub fn deleted(&self) -> impl Iterator<Item = (EntityId, &T)> + '_
Returns the deleted components of a storage tracking deletion.
sourcepub fn is_deleted(&self, entity: EntityId) -> bool
pub fn is_deleted(&self, entity: EntityId) -> bool
Inside a workload returns true
if entity
’s component was deleted since the last run of this system.
Outside workloads returns true
if entity
’s component was deleted since the last call to clear_all_deleted
.
Returns false
if entity
does not have a component in this storage.
source§impl<Track, T: Component> View<'_, T, Track>where
Track: RemovalTracking,
impl<Track, T: Component> View<'_, T, Track>where
Track: RemovalTracking,
sourcepub fn removed(&self) -> impl Iterator<Item = EntityId> + '_
pub fn removed(&self) -> impl Iterator<Item = EntityId> + '_
Returns the ids of removed components of a storage tracking removal.
sourcepub fn is_removed(&self, entity: EntityId) -> bool
pub fn is_removed(&self, entity: EntityId) -> bool
Inside a workload returns true
if entity
’s component was removed since the last run of this system.
Outside workloads returns true
if entity
’s component was removed since the last call to clear_all_removed
.
Returns false
if entity
does not have a component in this storage.
source§impl<Track, T: Component> View<'_, T, Track>where
Track: RemovalTracking + DeletionTracking,
impl<Track, T: Component> View<'_, T, Track>where
Track: RemovalTracking + DeletionTracking,
sourcepub fn removed_or_deleted(&self) -> impl Iterator<Item = EntityId> + '_
pub fn removed_or_deleted(&self) -> impl Iterator<Item = EntityId> + '_
Returns the ids of removed or deleted components of a storage tracking removal and/or deletion.
sourcepub fn is_removed_or_deleted(&self, entity: EntityId) -> bool
pub fn is_removed_or_deleted(&self, entity: EntityId) -> bool
Inside a workload returns true
if entity
’s component was deleted or removed since the last run of this system.
Outside workloads returns true
if entity
’s component was deleted or removed since the last clear call.
Returns false
if entity
does not have a component in this storage.
Methods from Deref<Target = SparseSet<T>>§
sourcepub fn contains(&self, entity: EntityId) -> bool
pub fn contains(&self, entity: EntityId) -> bool
Returns true
if entity
owns a component in this storage.
sourcepub fn index_of(&self, entity: EntityId) -> Option<usize>
pub fn index_of(&self, entity: EntityId) -> Option<usize>
Returns the index of entity
’s component in the dense
and data
vectors.
This index is only valid for this storage and until a modification happens.
sourcepub unsafe fn index_of_unchecked(&self, entity: EntityId) -> usize
pub unsafe fn index_of_unchecked(&self, entity: EntityId) -> usize
Returns the index of entity
’s component in the dense
and data
vectors.
This index is only valid for this storage and until a modification happens.
§Safety
entity
has to own a component of this type.
The index is only valid until a modification occurs in the storage.
sourcepub fn is_tracking_insertion(&self) -> bool
pub fn is_tracking_insertion(&self) -> bool
Returns true
if the storage tracks insertion.
sourcepub fn is_tracking_modification(&self) -> bool
pub fn is_tracking_modification(&self) -> bool
Returns true
if the storage tracks modification.
sourcepub fn is_tracking_deletion(&self) -> bool
pub fn is_tracking_deletion(&self) -> bool
Returns true
if the storage tracks deletion.
sourcepub fn is_tracking_removal(&self) -> bool
pub fn is_tracking_removal(&self) -> bool
Returns true
if the storage tracks removal.
sourcepub fn is_tracking_any(&self) -> bool
pub fn is_tracking_any(&self) -> bool
Returns true
if the storage tracks insertion, deletion or removal.
Trait Implementations§
source§impl<T: Send + Sync + Component, Track> Borrow for View<'_, T, Track>where
Track: Tracking,
impl<T: Send + Sync + Component, Track> Borrow for View<'_, T, Track>where
Track: Tracking,
type View<'a> = View<'a, T, Track>
source§fn borrow<'a>(
all_storages: &'a AllStorages,
all_borrow: Option<SharedBorrow<'a>>,
last_run: Option<TrackingTimestamp>,
current: TrackingTimestamp,
) -> Result<Self::View<'a>, GetStorage>
fn borrow<'a>( all_storages: &'a AllStorages, all_borrow: Option<SharedBorrow<'a>>, last_run: Option<TrackingTimestamp>, current: TrackingTimestamp, ) -> Result<Self::View<'a>, GetStorage>
source§impl<'a, T: Send + Sync + Component, Track> BorrowInfo for View<'a, T, Track>where
Track: Tracking,
impl<'a, T: Send + Sync + Component, Track> BorrowInfo for View<'a, T, Track>where
Track: Tracking,
source§fn borrow_info(info: &mut Vec<TypeInfo>)
fn borrow_info(info: &mut Vec<TypeInfo>)
source§fn enable_tracking(
enable_tracking_fn: &mut Vec<fn(_: &AllStorages) -> Result<(), GetStorage>>,
)
fn enable_tracking( enable_tracking_fn: &mut Vec<fn(_: &AllStorages) -> Result<(), GetStorage>>, )
World
where this storage is borrowed.Auto Trait Implementations§
impl<'a, T, Track> Freeze for View<'a, T, Track>
impl<'a, T, Track = <T as Component>::Tracking> !RefUnwindSafe for View<'a, T, Track>
impl<'a, T, Track> Send for View<'a, T, Track>where
T: Sync,
impl<'a, T, Track> Sync for View<'a, T, Track>where
T: Sync,
impl<'a, T, Track> Unpin for View<'a, T, Track>where
Track: Unpin,
impl<'a, T, Track = <T as Component>::Tracking> !UnwindSafe for View<'a, T, Track>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more