Struct Layer

Source
pub struct Layer<C: Chunk> { /* private fields */ }
Expand description

The entry point to access the chunks of a layer.

It exposes various convenience accessors, like iterating over areas in chunk or world coordinates.

Implementations§

Source§

impl<C: Chunk> Layer<C>

Source

pub fn new(value: C::Dependencies) -> Self

Create a new layer, manually specifying the dependencies. This is useful if you want to share dependencies with another layer.

Source§

impl<C: Chunk> Layer<C>

Source

pub fn ensure_loaded_in_bounds(&self, chunk_bounds: Bounds)

Eagerly compute all chunks in the given bounds (in world coordinates). Load all dependencies’ chunks and then compute our chunks. May recursively cause the dependencies to load their deps and so on.

Source

pub fn clear(&self, chunk_bounds: Bounds)

Eagerly unload all chunks in the given bounds (in world coordinates).

Source

pub fn incoherent_override_cache(&self, index: GridPoint<C>, val: C)

Manually (without calling compute) set a chunk in the cache.

This violates all the nice properties like the fact that layers depending on this one will not even load this chunk if they have computed all their chunks that depend on this one. They may later have to recompute, and then see the new value, which may lead to recomputed chunks being different from non-recomputed chunks.

TLDR: only call this if you have called clear on everything that depended on this one.

Source

pub fn get_or_compute(&self, index: GridPoint<C>) -> C

Get a chunk or generate it if it wasn’t already cached.

Source

pub fn get_range(&self, range: Bounds) -> impl Iterator<Item = C> + '_

Get an iterator over all chunks that touch the given bounds (in world coordinates)

Source

pub fn get_grid_range( &self, range: Bounds<GridIndex<C>>, ) -> impl Iterator<Item = C> + '_

Get an iterator over chunks as given by the bounds (in chunk grid indices). Chunks will be generated on the fly.

Source

pub fn get_moore_neighborhood(&self, index: GridPoint<C>) -> [[C; 3]; 3]

Get a 3x3 array of chunks around a specific chunk

Trait Implementations§

Source§

impl<C: Chunk> Clone for Layer<C>
where C::LayerStore<(RollingGrid<C>, C::Dependencies)>: Clone,

Source§

fn clone(&self) -> Self

Shallowly clone the layer. The clones will share the caches with this copy of the layer.

1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<C: Chunk> Default for Layer<C>

Source§

fn default() -> Self

Create an entirely new layer and its dependencies. The dependencies will not be connected to any other dependencies of the same type.

Source§

impl<C: Chunk + Debug> Dependencies for Layer<C>

Source§

fn debug(&self) -> Vec<&dyn DynLayer>

For runtime debugging of your layers, you should return references to each of the layer types within your dependencies.
Source§

impl<C: Chunk> Deref for Layer<C>

Source§

type Target = <C as Chunk>::Dependencies

The resulting type after dereferencing.
Source§

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

Dereferences the value.
Source§

impl<C: Chunk + Debug> DynLayer for Layer<C>

Source§

fn iter_all_loaded( &self, ) -> Box<dyn Iterator<Item = (Bounds, Box<dyn Debug + 'static>)> + '_>

Iterate only over the chunks that have been generated already and not unloaded yet to make space for new ones.
Source§

fn deps(&self) -> Vec<&dyn DynLayer>

Iterate over the dependency layers of this layer.
Source§

fn ident(&self) -> (usize, TypeId)

A unique identifier for this layer, useful for the use as map keys.
Source§

fn name(&self) -> String

A shortened version of the type name of the layer and its generic parameters.

Auto Trait Implementations§

§

impl<C> Freeze for Layer<C>
where <C as Chunk>::LayerStore<(RollingGrid<C>, <C as Chunk>::Dependencies)>: Freeze,

§

impl<C> RefUnwindSafe for Layer<C>
where <C as Chunk>::LayerStore<(RollingGrid<C>, <C as Chunk>::Dependencies)>: RefUnwindSafe,

§

impl<C> Send for Layer<C>
where <C as Chunk>::LayerStore<(RollingGrid<C>, <C as Chunk>::Dependencies)>: Send,

§

impl<C> Sync for Layer<C>
where <C as Chunk>::LayerStore<(RollingGrid<C>, <C as Chunk>::Dependencies)>: Sync,

§

impl<C> Unpin for Layer<C>
where <C as Chunk>::LayerStore<(RollingGrid<C>, <C as Chunk>::Dependencies)>: Unpin,

§

impl<C> UnwindSafe for Layer<C>
where <C as Chunk>::LayerStore<(RollingGrid<C>, <C as Chunk>::Dependencies)>: UnwindSafe,

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, dest: *mut u8)

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.