Struct shipyard::View

source ·
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>

source

pub const ASSERT_VIEW_TRACKING_INSERTION: () = _

Check that the view tracks insertion if the component is tracking it.

source

pub const ASSERT_VIEW_TRACKING_MODIFICATION: () = _

Check that the view tracks modification if the component is tracking it.

source

pub const ASSERT_VIEW_TRACKING_DELETION: () = _

Check that the view tracks deletion if the component is tracking it.

source

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,

source

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.

source

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.

source

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>

source

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,

source

pub fn inserted(&self) -> Inserted<&Self>

Wraps this view to be able to iterate inserted components.

source

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,

source

pub fn modified(&self) -> Modified<&Self>

Wraps this view to be able to iterate modified components.

source

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>

source

pub fn inserted_or_modified(&self) -> InsertedOrModified<&Self>

Wraps this view to be able to iterate inserted and modified components.

source

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,

source

pub fn deleted(&self) -> impl Iterator<Item = (EntityId, &T)> + '_

Returns the deleted components of a storage tracking deletion.

source

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,

source

pub fn removed(&self) -> impl Iterator<Item = EntityId> + '_

Returns the ids of removed components of a storage tracking removal.

source

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>

source

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.

source

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>>§

source

pub fn as_slice(&self) -> &[T]

Returns a slice of all the components in this storage.

source

pub fn contains(&self, entity: EntityId) -> bool

Returns true if entity owns a component in this storage.

source

pub fn len(&self) -> usize

Returns the length of the storage.

source

pub fn is_empty(&self) -> bool

Returns true if the storage’s length is 0.

source

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.

source

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.

source

pub fn id_at(&self, index: usize) -> Option<EntityId>

Returns the EntityId at a given index.

source

pub fn is_tracking_insertion(&self) -> bool

Returns true if the storage tracks insertion.

source

pub fn is_tracking_modification(&self) -> bool

Returns true if the storage tracks modification.

source

pub fn is_tracking_deletion(&self) -> bool

Returns true if the storage tracks deletion.

source

pub fn is_tracking_removal(&self) -> bool

Returns true if the storage tracks removal.

source

pub fn is_tracking_any(&self) -> bool

Returns true if the storage tracks insertion, deletion or removal.

Trait Implementations§

source§

impl<'a, T: Component, Track: Tracking> AsRef<SparseSet<T>> for View<'a, T, Track>

source§

fn as_ref(&self) -> &SparseSet<T>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<'a, T: Component, Track: Tracking, U: IntoAbstract> BitOr<U> for &'a View<'a, T, Track>

source§

type Output = Or<(&'a View<'a, T, Track>, U)>

The resulting type after applying the | operator.
source§

fn bitor(self, rhs: U) -> Self::Output

Performs the | operation. Read more
source§

impl<T: Send + Sync + Component, Track> Borrow for View<'_, T, Track>
where Track: Tracking,

source§

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>

This function is where the actual borrowing happens.
source§

impl<'a, T: Send + Sync + Component, Track> BorrowInfo for View<'a, T, Track>
where Track: Tracking,

source§

fn borrow_info(info: &mut Vec<TypeInfo>)

This information is used during workload creation to determine which systems can run in parallel. Read more
source§

fn enable_tracking( enable_tracking_fn: &mut Vec<fn(_: &AllStorages) -> Result<(), GetStorage>>, )

Enable tracking on the World where this storage is borrowed.
source§

impl<'a, T: Component, Track: Tracking> Clone for View<'a, T, Track>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a: 'b, 'b, T: Component, Track: Tracking> Contains for &'b View<'a, T, Track>

source§

fn contains(&self, entity: EntityId) -> bool

Returns true if all storages contains entity.
source§

impl<T: Debug + Component, Track: Tracking> Debug for View<'_, T, Track>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a, T: Component, Track: Tracking> Deref for View<'a, T, Track>

source§

type Target = SparseSet<T>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<'a, 'b, T: Component, Track: Tracking> Get for &'b View<'a, T, Track>

source§

type Out = &'b T

source§

fn get(self, entity: EntityId) -> Result<Self::Out, MissingComponent>

Retrieve components of entity. Read more
source§

impl<T: Component, Track: Tracking> Index<EntityId> for View<'_, T, Track>

source§

type Output = T

The returned type after indexing.
source§

fn index(&self, entity: EntityId) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl<'a: 'b, 'b, T: Component, Track: Tracking> IntoAbstract for &'b View<'a, T, Track>

source§

type AbsView = FullRawWindow<'b, T>

source§

impl<T: Component, Track: Tracking> Not for &View<'_, T, Track>

source§

type Output = Not<&View<'_, T, Track>>

The resulting type after applying the ! operator.
source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
source§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> WorldBorrow for T
where T: Borrow,

source§

type WorldView<'a> = <T as Borrow>::View<'a>

source§

fn world_borrow( world: &World, last_run: Option<TrackingTimestamp>, current: TrackingTimestamp, ) -> Result<<T as WorldBorrow>::WorldView<'_>, GetStorage>

This function is where the actual borrowing happens.