Trait Chunk

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

Source

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.

Source

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.

Source

const SIZE: Point2d<u8> = _

Width and height of the chunk (in powers of two);

Required Associated Types§

Source

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.

Source

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§

Source

fn compute(layer: &Self::Dependencies, index: GridPoint<Self>) -> Self

Compute a chunk from its dependencies

Source

fn clear(layer: &Self::Dependencies, index: GridPoint<Self>)

Clear all information that [compute] would have computed

Provided Methods§

Source

fn bounds(index: GridPoint<Self>) -> Bounds

Get the bounds for the chunk at the given index

Source

fn bounds_to_grid(bounds: Bounds) -> Bounds<GridIndex<Self>>

Get the grids that are touched by the given bounds.

Source

fn pos_to_grid(point: Point2d) -> GridPoint<Self>

Get the grid the position is in

Source

fn vision_range(bounds: Bounds) -> Bounds

Pad by a chunk size to make sure we see effects from the neighboring chunks

Source

fn moore_neighborhood(index: GridPoint<Self>) -> [[GridPoint<Self>; 3]; 3]

Get 3x3 grid points around a central one

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.

Implementors§

Source§

impl<P: Reducible, const SIZE: u8, const SALT: u64> Chunk for ReducedUniformPoint<P, SIZE, SALT>

Source§

impl<P: Reducible, const SIZE: u8, const SALT: u64> Chunk for UniformPoint<P, SIZE, SALT>