Trait voxelize::ChunkStage
source · [−]pub trait ChunkStage {
fn name(&self) -> String;
fn process(
&self,
chunk: Chunk,
resources: ResourceResults<'_>,
space: Option<Space>
) -> Chunk;
fn neighbors(&self, _: &WorldConfig) -> usize { ... }
fn needs_space(&self) -> Option<SpaceData> { ... }
fn needs_resources(&self) -> ResourceRequirements { ... }
}
Expand description
A stage in the pipeline where a chunk gets populated.
Required Methods
The core of this chunk stage, in other words what is done on the chunk. Returns the chunk instance, and additional
block changes to the world would be automatically added into chunk.exceeded_changes
. For instance, if a tree is
placed on the border of a chunk, the leaves would exceed the chunk border, thus appended to exceeded_changes
.
After each stage, the exceeded_changes
list of block changes would be emptied and applied to the world.
Provided Methods
fn neighbors(&self, _: &WorldConfig) -> usize
fn neighbors(&self, _: &WorldConfig) -> usize
The radius neighbor from the center chunk that are required before being processed in this chunk. Defaults to 0 blocks.
fn needs_space(&self) -> Option<SpaceData>
fn needs_space(&self) -> Option<SpaceData>
Whether if this stage needs a data-fetching structure called Space for
each chunk process. In short, space provides additional information such as
voxels/lights/height around the center chunk by cloning the neighboring data
into the same Space, and providing data accessing utility functions. Defaults
to None
.
Example
// If this stage needs the neighboring chunk's voxel data.
impl ChunkStage for TreePlanting {
...
// neighboring 5 blocks.
fn neighbors(&self, _:&WorldConfig) -> usize {
5
}
// get the voxel data around this chunk.
fn needs_space(&self) -> Option<SpaceData> {
Some(SpaceData {
needs_voxels: true,
..Default::default()
})
}
...
}
fn needs_resources(&self) -> ResourceRequirements
fn needs_resources(&self) -> ResourceRequirements
Define what resources of the ECS world is needed for this stage so the pipeline can prepare in advance. Defaults to needing only the registry.