Struct Chunks

Source
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

Source

pub fn new(config: &WorldConfig) -> Self

Create a new instance of a chunk manager.

Source

pub fn try_load(&mut self, coords: &Vec2<i32>) -> Option<Chunk>

Source

pub fn save(&self, coords: &Vec2<i32>) -> bool

Source

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.

Source

pub fn add(&mut self, chunk: Chunk)

Add a new chunk, synonym for chunks.renew

Source

pub fn raw(&self, coords: &Vec2<i32>) -> Option<&Chunk>

Get raw chunk data.

Source

pub fn raw_mut(&mut self, coords: &Vec2<i32>) -> Option<&mut Chunk>

Get raw mutable chunk data.

Source

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.

Source

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.

Source

pub fn raw_chunk_by_voxel(&self, vx: i32, vy: i32, vz: i32) -> Option<&Chunk>

Source

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.

Source

pub fn voxel_affected_chunks(&self, vx: i32, vy: i32, vz: i32) -> Vec<Vec2<i32>>

Get neighboring coords of a voxel coordinate.

Source

pub fn light_traversed_chunks(&self, coords: &Vec2<i32>) -> Vec<Vec2<i32>>

Get a list of chunks that light could traverse within.

Source

pub fn make_space<'a>( &'a self, coords: &Vec2<i32>, margin: usize, ) -> SpaceBuilder<'a>

Create a voxel querying space around a chunk coordinate.

Source

pub fn is_within_world(&self, coords: &Vec2<i32>) -> bool

Check to see if chunk is within the world’s min/max chunk.

Source

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.

Source

pub fn clear_cache(&mut self)

Clear the mutable chunk borrowing list.

Source

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.

Source

pub fn update_voxels(&mut self, voxels: &[(Vec3<i32>, u32)])

Source

pub fn mark_voxel_active(&mut self, voxel: &Vec3<i32>, active_at: u64)

Source

pub fn add_chunk_to_save(&mut self, coords: &Vec2<i32>, prioritized: bool)

Add a chunk to be saved.

Source

pub fn add_chunk_to_send( &mut self, coords: &Vec2<i32>, type: &MessageType, prioritized: bool, )

Add a chunk to be sent.

Source

pub fn add_listener(&mut self, coords: &Vec2<i32>, listener: &Vec2<i32>)

Add a listener to a chunk.

Trait Implementations§

Source§

impl Default for Chunks

Source§

fn default() -> Chunks

Returns the “default value” for a type. Read more
Source§

impl VoxelAccess for Chunks

Source§

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

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

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

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

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

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

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

Checks to see if the voxel is contained within the voxel acces.
Source§

fn get_voxel(&self, vx: i32, vy: i32, vz: i32) -> u32

Get the voxel ID at a voxel coordinate. If chunk not found, 0 is returned.
Source§

fn set_voxel(&mut self, vx: i32, vy: i32, vz: i32, id: u32) -> bool

Set the voxel type at a voxel coordinate. Returns false couldn’t set.
Source§

fn get_voxel_rotation(&self, vx: i32, vy: i32, vz: i32) -> BlockRotation

Get the voxel rotation at a voxel coordinate. Panics if chunk isn’t found.
Source§

fn set_voxel_rotation( &mut self, vx: i32, vy: i32, vz: i32, rotation: &BlockRotation, ) -> bool

Set the voxel rotation at a voxel coordinate. Does nothing if chunk isn’t found.
Source§

fn get_voxel_stage(&self, vx: i32, vy: i32, vz: i32) -> u32

Get the voxel stage at a voxel coordinate. Panics if chunk isn’t found.
Source§

fn set_voxel_stage(&mut self, vx: i32, vy: i32, vz: i32, stage: u32) -> bool

Set the voxel stage at a voxel coordinate. Does nothing if chunk isn’t found.
Source§

fn set_sunlight(&mut self, vx: i32, vy: i32, vz: i32, level: u32) -> bool

Set the sunlight level at a voxel coordinate. Returns false if could not set.
Source§

fn get_red_light(&self, vx: i32, vy: i32, vz: i32) -> u32

Get the red light level at the voxel position. Zero is returned if chunk doesn’t exist.
Source§

fn set_red_light(&mut self, vx: i32, vy: i32, vz: i32, level: u32) -> bool

Set the red light level at the voxel position. Returns false if could not set.
Source§

fn get_green_light(&self, vx: i32, vy: i32, vz: i32) -> u32

Get the green light level at the voxel position. Zero is returned if chunk doesn’t exist.
Source§

fn set_green_light(&mut self, vx: i32, vy: i32, vz: i32, level: u32) -> bool

Set the green light level at the voxel position. Returns false if could not set.
Source§

fn get_blue_light(&self, vx: i32, vy: i32, vz: i32) -> u32

Get the blue light level at the voxel position. Zero is returned if chunk doesn’t exist.
Source§

fn set_blue_light(&mut self, vx: i32, vy: i32, vz: i32, level: u32) -> bool

Set the blue light level at the voxel position. Returns false if could not set.
Source§

fn get_torch_light(&self, vx: i32, vy: i32, vz: i32, color: &LightColor) -> u32

Get the torch light level by color at a voxel coordinate. Returns 0 if chunk does not exist.
Source§

fn set_torch_light( &mut self, vx: i32, vy: i32, vz: i32, level: u32, color: &LightColor, ) -> bool

Set the torch light level by color at a voxel coordinate. Returns false if could not set.
Source§

fn get_voxels(&self, cx: i32, cz: i32) -> Option<&Ndarray<u32>>

Get a reference of voxel n-dimensional array.
Source§

fn get_lights(&self, cx: i32, cz: i32) -> Option<&Ndarray<u32>>

Get a reference of lighting n-dimensional array.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> TryDefault for T
where T: Default,

Source§

fn try_default() -> Result<T, String>

Tries to create the default.
Source§

fn unwrap_default() -> Self

Calls try_default and panics on an error case.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> Event for T
where T: Send + Sync + 'static,

Source§

impl<T> Resource for T
where T: Any + Send + Sync,