aboutsummaryrefslogtreecommitdiff
path: root/azalea-core
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2023-10-04 20:24:49 -0500
committermat <git@matdoes.dev>2023-10-04 20:24:49 -0500
commit17734cdcbf8ea30ded09a0b14372d92c11d1cc8c (patch)
treebd3ea629493015f3d1703f50c932da4b96b47b68 /azalea-core
parentc2fb99159556e1d55552aac0a782dbc69be338f3 (diff)
downloadazalea-drasl-17734cdcbf8ea30ded09a0b14372d92c11d1cc8c.tar.xz
add safety comments and simplify some code
Diffstat (limited to 'azalea-core')
-rwxr-xr-xazalea-core/src/bitset.rs2
-rwxr-xr-xazalea-core/src/position.rs11
2 files changed, 3 insertions, 10 deletions
diff --git a/azalea-core/src/bitset.rs b/azalea-core/src/bitset.rs
index b7a426c9..912216a8 100755
--- a/azalea-core/src/bitset.rs
+++ b/azalea-core/src/bitset.rs
@@ -143,10 +143,12 @@ where
}
}
+ #[inline]
pub fn index(&self, index: usize) -> bool {
(self.data[index / 8] & (1u8 << (index % 8))) != 0
}
+ #[inline]
pub fn set(&mut self, bit_index: usize) {
self.data[bit_index / 8] |= 1u8 << (bit_index % 8);
}
diff --git a/azalea-core/src/position.rs b/azalea-core/src/position.rs
index b731384b..e1993b18 100755
--- a/azalea-core/src/position.rs
+++ b/azalea-core/src/position.rs
@@ -261,7 +261,6 @@ impl ChunkSectionPos {
}
/// The coordinates of a block inside a chunk.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
-#[repr(align(8))]
pub struct ChunkBlockPos {
pub x: u8,
pub y: i32,
@@ -300,7 +299,6 @@ impl nohash_hasher::IsEnabled for ChunkBlockPos {}
/// The coordinates of a block inside a chunk section. Each coordinate must be
/// in the range [0, 15].
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
-#[repr(align(4))]
pub struct ChunkSectionBlockPos {
pub x: u8,
pub y: u8,
@@ -330,14 +328,7 @@ impl Hash for ChunkSectionBlockPos {
impl From<ChunkSectionBlockPos> for u16 {
#[inline]
fn from(pos: ChunkSectionBlockPos) -> Self {
- let mut val: u16 = 0;
- // first 4 bits are z
- val |= pos.z as u16;
- // next 4 bits are y
- val |= (pos.y as u16) << 4;
- // last 4 bits are x
- val |= (pos.x as u16) << 8;
- val
+ (pos.z as u16) | ((pos.y as u16) << 4) | ((pos.x as u16) << 8)
}
}
impl nohash_hasher::IsEnabled for ChunkSectionBlockPos {}