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>
impl<C: Chunk> Layer<C>
Sourcepub fn new(value: C::Dependencies) -> Self
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>
impl<C: Chunk> Layer<C>
Sourcepub fn ensure_loaded_in_bounds(&self, chunk_bounds: Bounds)
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.
Sourcepub fn clear(&self, chunk_bounds: Bounds)
pub fn clear(&self, chunk_bounds: Bounds)
Eagerly unload all chunks in the given bounds (in world coordinates).
Sourcepub fn incoherent_override_cache(&self, index: GridPoint<C>, val: C)
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.
Sourcepub fn get_or_compute(&self, index: GridPoint<C>) -> C
pub fn get_or_compute(&self, index: GridPoint<C>) -> C
Get a chunk or generate it if it wasn’t already cached.
Sourcepub fn get_range(&self, range: Bounds) -> impl Iterator<Item = C> + '_
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)
Sourcepub fn get_grid_range(
&self,
range: Bounds<GridIndex<C>>,
) -> impl Iterator<Item = C> + '_
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.
Sourcepub fn get_moore_neighborhood(&self, index: GridPoint<C>) -> [[C; 3]; 3]
pub fn get_moore_neighborhood(&self, index: GridPoint<C>) -> [[C; 3]; 3]
Get a 3x3 array of chunks around a specific chunk