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.
Auto Trait Implementations§
impl Freeze for ChunkManager
impl RefUnwindSafe for ChunkManager
impl Send for ChunkManager
impl Sync for ChunkManager
impl Unpin for ChunkManager
impl UnsafeUnpin for ChunkManager
impl UnwindSafe for ChunkManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.