pub struct ChunkManager {
pub noise: NoiseSource,
pub chunk_size: f32,
pub chunk_resolution: usize,
pub view_radius: i32,
pub lod_thresholds: LodThresholds,
pub chunks: HashMap<ChunkCoord, HeightFieldChunk>,
pub last_camera_pos: Vec2,
pub animations: Vec<HeightFieldAnimation>,
}Expand description
Manages a dynamic set of terrain chunks around a camera position.
Fields§
§noise: NoiseSourceThe noise source shared by all chunks.
chunk_size: f32Size of each chunk in world units.
chunk_resolution: usizeResolution of each chunk (vertices per side).
view_radius: i32How many chunks to keep around the camera in each direction.
lod_thresholds: LodThresholdsLOD distance thresholds.
chunks: HashMap<ChunkCoord, HeightFieldChunk>Currently loaded chunks.
last_camera_pos: Vec2Last known camera position (for determining which chunks to load/unload).
animations: Vec<HeightFieldAnimation>Animations applied to all chunks.
Implementations§
Source§impl ChunkManager
impl ChunkManager
Sourcepub fn new(
noise: NoiseSource,
chunk_size: f32,
chunk_resolution: usize,
view_radius: i32,
) -> Self
pub fn new( noise: NoiseSource, chunk_size: f32, chunk_resolution: usize, view_radius: i32, ) -> Self
Create a new chunk manager.
Sourcepub fn update(&mut self, camera_x: f32, camera_z: f32)
pub fn update(&mut self, camera_x: f32, camera_z: f32)
Update the chunk manager with a new camera position. Loads new chunks that are now in range, unloads chunks that are too far.
Sourcepub fn sample_height(&self, x: f32, z: f32) -> f32
pub fn sample_height(&self, x: f32, z: f32) -> f32
Sample height at an arbitrary world-space position.
Sourcepub fn sample_normal(&self, x: f32, z: f32) -> Vec3
pub fn sample_normal(&self, x: f32, z: f32) -> Vec3
Sample normal at an arbitrary world-space position.
Sourcepub fn loaded_chunk_count(&self) -> usize
pub fn loaded_chunk_count(&self) -> usize
Get the number of currently loaded chunks.
Sourcepub fn iter_chunks(&self) -> impl Iterator<Item = &HeightFieldChunk>
pub fn iter_chunks(&self) -> impl Iterator<Item = &HeightFieldChunk>
Get an iterator over all loaded chunks.
Sourcepub fn iter_chunks_mut(&mut self) -> impl Iterator<Item = &mut HeightFieldChunk>
pub fn iter_chunks_mut(&mut self) -> impl Iterator<Item = &mut HeightFieldChunk>
Get a mutable iterator over all loaded chunks.