mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'imbris/vg3d-fix' into 'master'
Fix overflow in VolGrid3d See merge request veloren/veloren!747
This commit is contained in:
commit
605eb7c6ec
@ -25,19 +25,12 @@ pub struct VolGrid3d<V: RasterableVol> {
|
|||||||
impl<V: RasterableVol> VolGrid3d<V> {
|
impl<V: RasterableVol> VolGrid3d<V> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn chunk_key(pos: Vec3<i32>) -> Vec3<i32> {
|
pub fn chunk_key(pos: Vec3<i32>) -> Vec3<i32> {
|
||||||
pos.map2(V::SIZE, |e, sz| {
|
pos.map2(V::SIZE, |e, sz: u32| e >> (sz - 1).count_ones())
|
||||||
// Horrid, but it's faster than a cheetah with a red bull blood transfusion
|
|
||||||
let log2 = (sz - 1).count_ones();
|
|
||||||
((((i64::from(e) + (1 << 32)) as u64) >> log2) - (1 << (32 - log2))) as i32
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn chunk_offs(pos: Vec3<i32>) -> Vec3<i32> {
|
pub fn chunk_offs(pos: Vec3<i32>) -> Vec3<i32> {
|
||||||
pos.map2(V::SIZE, |e, sz| {
|
pos.map2(V::SIZE, |e, sz| e & (sz - 1) as i32)
|
||||||
// Horrid, but it's even faster than the aforementioned cheetah
|
|
||||||
(((i64::from(e) + (1 << 32)) as u64) & u64::from(sz - 1)) as i32
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user