pub trait Chunk:
Sized
+ Default
+ Clone
+ 'static {
type LayerStore<T>: Borrow<T> + From<T>;
type Dependencies: Dependencies;
const GRID_SIZE: Point2d<u8> = _;
const GRID_OVERLAP: u8 = 3u8;
const SIZE: Point2d<u8> = _;
// Required methods
fn compute(layer: &Self::Dependencies, index: GridPoint<Self>) -> Self;
fn clear(layer: &Self::Dependencies, index: GridPoint<Self>);
// Provided methods
fn bounds(index: GridPoint<Self>) -> Bounds { ... }
fn bounds_to_grid(bounds: Bounds) -> Bounds<GridIndex<Self>> { ... }
fn pos_to_grid(point: Point2d) -> GridPoint<Self> { ... }
fn vision_range(bounds: Bounds) -> Bounds { ... }
fn moore_neighborhood(index: GridPoint<Self>) -> [[GridPoint<Self>; 3]; 3] { ... }
}
Expand description
Chunks are rectangular regions of the same size that make up a layer in a grid shape.
Provided Associated Constants§
Sourceconst GRID_SIZE: Point2d<u8> = _
const GRID_SIZE: Point2d<u8> = _
Exponent of 2
of the cached area (in grid chunk numbers, not world coordinates).
This is the area that should stay in memory at all times as it will get requested a lot.
Sourceconst GRID_OVERLAP: u8 = 3u8
const GRID_OVERLAP: u8 = 3u8
Internal RollingGrid
overlap before the system drops old chunks. Basically scales the grid width/height by
this number to allow moving across the grid width/height boundaries completely transparently.
Increasing this number makes indexing the RollingGrid
more expensive if there is a lot of overlap.
Required Associated Types§
Sourcetype LayerStore<T>: Borrow<T> + From<T>
type LayerStore<T>: Borrow<T> + From<T>
Data structure that stores the layer. Usually Arc<Self>
,
but some layers are only used to simplify another layer, so
they can get stored directly without the Arc
indirection.
Sourcetype Dependencies: Dependencies
type Dependencies: Dependencies
The actual dependencies. Usually a struct with fields of Layer<T>
type, but
can be of any type to specify non-layer dependencies, too.
It is the type of the first argument of Chunk::compute.
Required Methods§
Sourcefn compute(layer: &Self::Dependencies, index: GridPoint<Self>) -> Self
fn compute(layer: &Self::Dependencies, index: GridPoint<Self>) -> Self
Compute a chunk from its dependencies
Sourcefn clear(layer: &Self::Dependencies, index: GridPoint<Self>)
fn clear(layer: &Self::Dependencies, index: GridPoint<Self>)
Clear all information that [compute] would have computed
Provided Methods§
Sourcefn bounds_to_grid(bounds: Bounds) -> Bounds<GridIndex<Self>>
fn bounds_to_grid(bounds: Bounds) -> Bounds<GridIndex<Self>>
Get the grids that are touched by the given bounds.
Sourcefn pos_to_grid(point: Point2d) -> GridPoint<Self>
fn pos_to_grid(point: Point2d) -> GridPoint<Self>
Get the grid the position is in
Sourcefn vision_range(bounds: Bounds) -> Bounds
fn vision_range(bounds: Bounds) -> Bounds
Pad by a chunk size to make sure we see effects from the neighboring chunks
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.