From c6020257f1644347614a0e90bbdc984917a07ba6 Mon Sep 17 00:00:00 2001 From: Acrimon Date: Mon, 19 Aug 2019 14:33:31 +0200 Subject: [PATCH] Eliminated unsafe. --- common/src/terrain/chonk.rs | 34 -------------------------------- common/src/vol.rs | 4 ---- common/src/volumes/chunk.rs | 5 ----- common/src/volumes/dyna.rs | 6 ------ common/src/volumes/vol_map_2d.rs | 7 ------- 5 files changed, 56 deletions(-) diff --git a/common/src/terrain/chonk.rs b/common/src/terrain/chonk.rs index 42541166e2..b365ae5357 100644 --- a/common/src/terrain/chonk.rs +++ b/common/src/terrain/chonk.rs @@ -122,40 +122,6 @@ impl ReadVol for Chonk { } } } - - #[inline(always)] - unsafe fn get_unchecked(&self, pos: Vec3) -> &Block { - if pos.z < self.z_offset { - // Below the terrain - &self.below - } else if pos.z >= self.z_offset + SUB_CHUNK_HEIGHT as i32 * self.sub_chunks.len() as i32 { - // Above the terrain - &self.above - } else { - // Within the terrain - - let sub_chunk_idx = self.sub_chunk_idx(pos.z); - - match &self.sub_chunks[sub_chunk_idx] { - // Can't fail - SubChunk::Homogeneous(block) => block, - SubChunk::Hash(cblock, map) => { - let rpos = pos - - Vec3::unit_z() - * (self.z_offset + sub_chunk_idx as i32 * SUB_CHUNK_HEIGHT as i32); - - map.get(&rpos.map(|e| e as u8)).unwrap_or(cblock) - } - SubChunk::Heterogeneous(chunk) => { - let rpos = pos - - Vec3::unit_z() - * (self.z_offset + sub_chunk_idx as i32 * SUB_CHUNK_HEIGHT as i32); - - chunk.get_unchecked(rpos) - } - } - } - } } impl WriteVol for Chonk { diff --git a/common/src/vol.rs b/common/src/vol.rs index 266a3193a9..f77e696bc4 100644 --- a/common/src/vol.rs +++ b/common/src/vol.rs @@ -72,10 +72,6 @@ pub trait ReadVol: BaseVol { /// Get a reference to the voxel at the provided position in the volume. fn get(&self, pos: Vec3) -> Result<&Self::Vox, Self::Err>; - unsafe fn get_unchecked(&self, pos: Vec3) -> &Self::Vox { - self.get(pos).unwrap() - } - fn ray( &self, from: Vec3, diff --git a/common/src/volumes/chunk.rs b/common/src/volumes/chunk.rs index 9386485297..0168686278 100644 --- a/common/src/volumes/chunk.rs +++ b/common/src/volumes/chunk.rs @@ -60,11 +60,6 @@ impl ReadVol for Chunk { .and_then(|idx| self.vox.get(idx)) .ok_or(ChunkErr::OutOfBounds) } - - #[inline(always)] - unsafe fn get_unchecked(&self, pos: Vec3) -> &V { - self.vox.get_unchecked(Self::idx_for_unchecked(pos)) - } } impl WriteVol for Chunk { diff --git a/common/src/volumes/dyna.rs b/common/src/volumes/dyna.rs index e88ccd3de7..4acebe6f1e 100644 --- a/common/src/volumes/dyna.rs +++ b/common/src/volumes/dyna.rs @@ -57,12 +57,6 @@ impl ReadVol for Dyna { .and_then(|idx| self.vox.get(idx)) .ok_or(DynaErr::OutOfBounds) } - - #[inline(always)] - unsafe fn get_unchecked(&self, pos: Vec3) -> &V { - self.vox - .get_unchecked(Self::idx_for_unchecked(self.sz, pos)) - } } impl WriteVol for Dyna { diff --git a/common/src/volumes/vol_map_2d.rs b/common/src/volumes/vol_map_2d.rs index b3ba4d3d9d..86fac2c251 100644 --- a/common/src/volumes/vol_map_2d.rs +++ b/common/src/volumes/vol_map_2d.rs @@ -60,13 +60,6 @@ impl ReadVol for VolMap2d { chunk.get(co).map_err(VolMap2dErr::ChunkErr) }) } - - #[inline(always)] - unsafe fn get_unchecked(&self, pos: Vec3) -> &V::Vox { - let ck = Self::chunk_key(pos); - let co = Self::chunk_offs(pos); - self.chunks.get(&ck).unwrap().get_unchecked(co) - } } // TODO: This actually breaks the API: samples are supposed to have an offset of zero!