mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Eliminated unsafe.
This commit is contained in:
parent
9c3bc88598
commit
d0f10115f4
@ -122,40 +122,6 @@ impl ReadVol for Chonk {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
unsafe fn get_unchecked(&self, pos: Vec3<i32>) -> &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 {
|
||||
|
@ -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<i32>) -> Result<&Self::Vox, Self::Err>;
|
||||
|
||||
unsafe fn get_unchecked(&self, pos: Vec3<i32>) -> &Self::Vox {
|
||||
self.get(pos).unwrap()
|
||||
}
|
||||
|
||||
fn ray(
|
||||
&self,
|
||||
from: Vec3<f32>,
|
||||
|
@ -60,11 +60,6 @@ impl<V: Vox, S: VolSize, M> ReadVol for Chunk<V, S, M> {
|
||||
.and_then(|idx| self.vox.get(idx))
|
||||
.ok_or(ChunkErr::OutOfBounds)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
unsafe fn get_unchecked(&self, pos: Vec3<i32>) -> &V {
|
||||
self.vox.get_unchecked(Self::idx_for_unchecked(pos))
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: Vox, S: VolSize, M> WriteVol for Chunk<V, S, M> {
|
||||
|
@ -57,12 +57,6 @@ impl<V: Vox, M> ReadVol for Dyna<V, M> {
|
||||
.and_then(|idx| self.vox.get(idx))
|
||||
.ok_or(DynaErr::OutOfBounds)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
unsafe fn get_unchecked(&self, pos: Vec3<i32>) -> &V {
|
||||
self.vox
|
||||
.get_unchecked(Self::idx_for_unchecked(self.sz, pos))
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: Vox, M> WriteVol for Dyna<V, M> {
|
||||
|
@ -60,13 +60,6 @@ impl<V: BaseVol + ReadVol + Debug, S: VolSize> ReadVol for VolMap2d<V, S> {
|
||||
chunk.get(co).map_err(VolMap2dErr::ChunkErr)
|
||||
})
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
unsafe fn get_unchecked(&self, pos: Vec3<i32>) -> &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!
|
||||
|
Loading…
Reference in New Issue
Block a user