Expand description
A Rust implementation of https://github.com/runevision/LayerProcGen
The main entry point to access the data of layers is the Layer type.
To create your own layers, you need to define a data type for the Chunks of that layer, and implement the Chunk trait for it. This trait also allows you to specify other Chunk types whose layers you’ll need information from to generate the data of your own chunks.
All coordinates are integer based (chunk position and borders), but the data within your chunks can be of arbitrary data types, including floats, strings, etc.
As an example, here’s a layer that generates a point at its center:
use layer_proc_gen::{Chunk, GridPoint, Point2d, debug::DynLayer};
#[derive(Clone, Default)]
struct MyChunk {
center: Point2d,
}
impl Chunk for MyChunk {
type LayerStore<T> = std::sync::Arc<T>;
type Dependencies = ();
fn compute(&(): &(), index: GridPoint<Self>) -> Self {
let center = Self::bounds(index).center();
MyChunk { center }
}
}
There are builtin Chunk types for common patterns like generating uniformly distributed points on an infinite grid.
Re-exports§
Modules§
- debug
- Various helpers for viewing layers and their data without knowing the exact structure and contents
- generic_
layers - Various useful layer/chunk type combinations that you can reuse in many kind of games.
- vec2
- Various position related data structures for 2d integer position handling.
Macros§
- deps
- Generate a struct where all fields are wrapped in
Layer
Structs§
- Grid
Index - An x or y index in chunk coordinates, not world coordinates.
- Layer
- The entry point to access the chunks of a layer.
Traits§
- Chunk
- Chunks are rectangular regions of the same size that make up a layer in a grid shape.
- Dependencies
- A struct that defines the dependencies of your Chunk. Usually generated for structs via the deps macro, but you can manually define it in case you have non-Layer dependencies.
Type Aliases§
- Grid
Point - The x and y positions of a chunk in the number of chunks, not in world coordinates.