diff --git a/src/bloxel/math/chunk_pos.rs b/src/bloxel/math/chunk_pos.rs index f1cfd45..6aea995 100644 --- a/src/bloxel/math/chunk_pos.rs +++ b/src/bloxel/math/chunk_pos.rs @@ -1,4 +1,7 @@ -use std::ops::{self, Index, IndexMut}; +use std::{ + num::NonZeroU32, + ops::{self, Index, IndexMut}, +}; use bevy::{ ecs::component::Component, @@ -8,11 +11,15 @@ use bevy::{ use overload::overload; use super::{BlockPos, BlockRegion, ChunkRegion}; +use crate::bloxel::math::USize3; pub const CHUNK_SHIFT: i32 = 4; pub const CHUNK_MASK: i32 = !(!0 << CHUNK_SHIFT); // = 0b1111 pub const CHUNK_LENGTH: usize = 1 << CHUNK_SHIFT; // = 16 +pub const CHUNK_SIZE: USize3 = + USize3::splat(unsafe { NonZeroU32::new_unchecked(CHUNK_LENGTH as u32) }); + pub const CHUNK_MAX: IVec3 = IVec3::splat((CHUNK_LENGTH - 1) as i32); #[derive(Component, Clone, Copy, PartialEq, Eq, Hash, Debug)] diff --git a/src/bloxel/math/size.rs b/src/bloxel/math/size.rs index d5cd748..03333b5 100644 --- a/src/bloxel/math/size.rs +++ b/src/bloxel/math/size.rs @@ -10,7 +10,7 @@ pub struct USize3 { } impl USize3 { - pub fn new(width: NonZeroU32, height: NonZeroU32, depth: NonZeroU32) -> Self { + pub const fn new(width: NonZeroU32, height: NonZeroU32, depth: NonZeroU32) -> Self { Self { width, height, @@ -18,7 +18,7 @@ impl USize3 { } } - pub fn splat(length: NonZeroU32) -> Self { + pub const fn splat(length: NonZeroU32) -> Self { Self::new(length, length, length) }