pub struct Chunks {
pub map: HashMap<Vec2<i32>, Chunk>,
/* private fields */
}
Expand description
A manager for all chunks in the Voxelize world.
Fields§
§map: HashMap<Vec2<i32>, Chunk>
A map of all the chunks, coords -> Chunk.
Implementations§
Source§impl Chunks
impl Chunks
Sourcepub fn new(config: &WorldConfig) -> Self
pub fn new(config: &WorldConfig) -> Self
Create a new instance of a chunk manager.
pub fn try_load(&mut self, coords: &Vec2<i32>) -> Option<Chunk>
pub fn save(&self, coords: &Vec2<i32>) -> bool
Sourcepub fn renew(&mut self, chunk: Chunk, renew_mesh_only: bool)
pub fn renew(&mut self, chunk: Chunk, renew_mesh_only: bool)
Update a chunk, removing the old chunk instance and updating with a new one.
Sourcepub fn raw_mut(&mut self, coords: &Vec2<i32>) -> Option<&mut Chunk>
pub fn raw_mut(&mut self, coords: &Vec2<i32>) -> Option<&mut Chunk>
Get raw mutable chunk data.
Sourcepub fn get(&self, coords: &Vec2<i32>) -> Option<&Chunk>
pub fn get(&self, coords: &Vec2<i32>) -> Option<&Chunk>
Get a chunk at a chunk coordinate. Keep in mind that this function only returns a chunk if the chunk has been fully instantiated and meshed. None is returned if not.
Sourcepub fn get_mut(&mut self, coords: &Vec2<i32>) -> Option<&mut Chunk>
pub fn get_mut(&mut self, coords: &Vec2<i32>) -> Option<&mut Chunk>
Get a mutable chunk reference at a chunk coordinate. Keep in mind that this function only returns a chunk if the chunk has been fully instantiated and meshed. None is returned if not.
pub fn raw_chunk_by_voxel(&self, vx: i32, vy: i32, vz: i32) -> Option<&Chunk>
Sourcepub fn raw_chunk_by_voxel_mut(
&mut self,
vx: i32,
vy: i32,
vz: i32,
) -> Option<&mut Chunk>
pub fn raw_chunk_by_voxel_mut( &mut self, vx: i32, vy: i32, vz: i32, ) -> Option<&mut Chunk>
Get a mutable chunk by voxel coordinates. Returns a chunk even if chunk isn’t fully instantiated.
Sourcepub fn voxel_affected_chunks(&self, vx: i32, vy: i32, vz: i32) -> Vec<Vec2<i32>>
pub fn voxel_affected_chunks(&self, vx: i32, vy: i32, vz: i32) -> Vec<Vec2<i32>>
Get neighboring coords of a voxel coordinate.
Sourcepub fn light_traversed_chunks(&self, coords: &Vec2<i32>) -> Vec<Vec2<i32>>
pub fn light_traversed_chunks(&self, coords: &Vec2<i32>) -> Vec<Vec2<i32>>
Get a list of chunks that light could traverse within.
Sourcepub fn make_space<'a>(
&'a self,
coords: &Vec2<i32>,
margin: usize,
) -> SpaceBuilder<'a>
pub fn make_space<'a>( &'a self, coords: &Vec2<i32>, margin: usize, ) -> SpaceBuilder<'a>
Create a voxel querying space around a chunk coordinate.
Sourcepub fn is_within_world(&self, coords: &Vec2<i32>) -> bool
pub fn is_within_world(&self, coords: &Vec2<i32>) -> bool
Check to see if chunk is within the world’s min/max chunk.
Sourcepub fn is_chunk_ready(&self, coords: &Vec2<i32>) -> bool
pub fn is_chunk_ready(&self, coords: &Vec2<i32>) -> bool
Guard to getting a chunk, only allowing chunks to be accessed when they’re ready.
Sourcepub fn clear_cache(&mut self)
pub fn clear_cache(&mut self)
Clear the mutable chunk borrowing list.
Sourcepub fn update_voxel(&mut self, voxel: &Vec3<i32>, val: u32)
pub fn update_voxel(&mut self, voxel: &Vec3<i32>, val: u32)
Update a voxel in the chunk map. This includes recalculating the light and height maps and sending the chunk to the interested clients. This process is not instant, and will be done in the background.
pub fn update_voxels(&mut self, voxels: &[(Vec3<i32>, u32)])
pub fn mark_voxel_active(&mut self, voxel: &Vec3<i32>, active_at: u64)
Sourcepub fn add_chunk_to_save(&mut self, coords: &Vec2<i32>, prioritized: bool)
pub fn add_chunk_to_save(&mut self, coords: &Vec2<i32>, prioritized: bool)
Add a chunk to be saved.
Sourcepub fn add_chunk_to_send(
&mut self,
coords: &Vec2<i32>,
type: &MessageType,
prioritized: bool,
)
pub fn add_chunk_to_send( &mut self, coords: &Vec2<i32>, type: &MessageType, prioritized: bool, )
Add a chunk to be sent.
Trait Implementations§
Source§impl VoxelAccess for Chunks
impl VoxelAccess for Chunks
Source§fn get_raw_voxel(&self, vx: i32, vy: i32, vz: i32) -> u32
fn get_raw_voxel(&self, vx: i32, vy: i32, vz: i32) -> u32
Get the raw voxel value at a voxel coordinate. If chunk not found, 0 is returned.
Source§fn set_raw_voxel(&mut self, vx: i32, vy: i32, vz: i32, id: u32) -> bool
fn set_raw_voxel(&mut self, vx: i32, vy: i32, vz: i32, id: u32) -> bool
Set the raw voxel value at a voxel coordinate. Returns false couldn’t set.
Source§fn get_raw_light(&self, vx: i32, vy: i32, vz: i32) -> u32
fn get_raw_light(&self, vx: i32, vy: i32, vz: i32) -> u32
Get the raw light value at a voxel coordinate. If chunk not found, 0 is returned.
Source§fn set_raw_light(&mut self, vx: i32, vy: i32, vz: i32, level: u32) -> bool
fn set_raw_light(&mut self, vx: i32, vy: i32, vz: i32, level: u32) -> bool
Set the raw light level at a voxel coordinate. Returns false couldn’t set.
Source§fn get_sunlight(&self, vx: i32, vy: i32, vz: i32) -> u32
fn get_sunlight(&self, vx: i32, vy: i32, vz: i32) -> u32
Get the sunlight level at a voxel position. Returns 0 if chunk does not exist.
Source§fn get_max_height(&self, vx: i32, vz: i32) -> u32
fn get_max_height(&self, vx: i32, vz: i32) -> u32
Get the max height at a voxel column. Returns 0 if column does not exist.
Source§fn set_max_height(&mut self, vx: i32, vz: i32, height: u32) -> bool
fn set_max_height(&mut self, vx: i32, vz: i32, height: u32) -> bool
Set the max height at a voxel column. Does nothing if column does not exist.
Source§fn contains(&self, vx: i32, vy: i32, vz: i32) -> bool
fn contains(&self, vx: i32, vy: i32, vz: i32) -> bool
Source§fn get_voxel(&self, vx: i32, vy: i32, vz: i32) -> u32
fn get_voxel(&self, vx: i32, vy: i32, vz: i32) -> u32
Source§fn set_voxel(&mut self, vx: i32, vy: i32, vz: i32, id: u32) -> bool
fn set_voxel(&mut self, vx: i32, vy: i32, vz: i32, id: u32) -> bool
Source§fn get_voxel_rotation(&self, vx: i32, vy: i32, vz: i32) -> BlockRotation
fn get_voxel_rotation(&self, vx: i32, vy: i32, vz: i32) -> BlockRotation
Source§fn set_voxel_rotation(
&mut self,
vx: i32,
vy: i32,
vz: i32,
rotation: &BlockRotation,
) -> bool
fn set_voxel_rotation( &mut self, vx: i32, vy: i32, vz: i32, rotation: &BlockRotation, ) -> bool
Source§fn get_voxel_stage(&self, vx: i32, vy: i32, vz: i32) -> u32
fn get_voxel_stage(&self, vx: i32, vy: i32, vz: i32) -> u32
Source§fn set_voxel_stage(&mut self, vx: i32, vy: i32, vz: i32, stage: u32) -> bool
fn set_voxel_stage(&mut self, vx: i32, vy: i32, vz: i32, stage: u32) -> bool
Source§fn set_sunlight(&mut self, vx: i32, vy: i32, vz: i32, level: u32) -> bool
fn set_sunlight(&mut self, vx: i32, vy: i32, vz: i32, level: u32) -> bool
Source§fn get_red_light(&self, vx: i32, vy: i32, vz: i32) -> u32
fn get_red_light(&self, vx: i32, vy: i32, vz: i32) -> u32
Source§fn set_red_light(&mut self, vx: i32, vy: i32, vz: i32, level: u32) -> bool
fn set_red_light(&mut self, vx: i32, vy: i32, vz: i32, level: u32) -> bool
Source§fn get_green_light(&self, vx: i32, vy: i32, vz: i32) -> u32
fn get_green_light(&self, vx: i32, vy: i32, vz: i32) -> u32
Source§fn set_green_light(&mut self, vx: i32, vy: i32, vz: i32, level: u32) -> bool
fn set_green_light(&mut self, vx: i32, vy: i32, vz: i32, level: u32) -> bool
Source§fn get_blue_light(&self, vx: i32, vy: i32, vz: i32) -> u32
fn get_blue_light(&self, vx: i32, vy: i32, vz: i32) -> u32
Source§fn set_blue_light(&mut self, vx: i32, vy: i32, vz: i32, level: u32) -> bool
fn set_blue_light(&mut self, vx: i32, vy: i32, vz: i32, level: u32) -> bool
Source§fn get_torch_light(&self, vx: i32, vy: i32, vz: i32, color: &LightColor) -> u32
fn get_torch_light(&self, vx: i32, vy: i32, vz: i32, color: &LightColor) -> u32
Source§fn set_torch_light(
&mut self,
vx: i32,
vy: i32,
vz: i32,
level: u32,
color: &LightColor,
) -> bool
fn set_torch_light( &mut self, vx: i32, vy: i32, vz: i32, level: u32, color: &LightColor, ) -> bool
Auto Trait Implementations§
impl Freeze for Chunks
impl RefUnwindSafe for Chunks
impl Send for Chunks
impl Sync for Chunks
impl Unpin for Chunks
impl UnwindSafe for Chunks
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.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.Source§impl<T> TryDefault for Twhere
T: Default,
impl<T> TryDefault for Twhere
T: Default,
Source§fn try_default() -> Result<T, String>
fn try_default() -> Result<T, String>
Source§fn unwrap_default() -> Self
fn unwrap_default() -> Self
try_default
and panics on an error case.