mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Switched to pure iterator space search
This commit is contained in:
parent
4bb0da24b6
commit
54989cf4a6
@ -113,24 +113,19 @@ impl TerrainGrid {
|
|||||||
/// Find a location suitable for spawning an entity near the given
|
/// Find a location suitable for spawning an entity near the given
|
||||||
/// position (but in the same chunk).
|
/// position (but in the same chunk).
|
||||||
pub fn find_space(&self, pos: Vec3<i32>) -> Vec3<i32> {
|
pub fn find_space(&self, pos: Vec3<i32>) -> Vec3<i32> {
|
||||||
let mut z_diff = 0;
|
const SEARCH_DIST: i32 = 63;
|
||||||
for _ in 0..128 {
|
(0..SEARCH_DIST * 2 + 1)
|
||||||
let test_pos = pos + Vec3::unit_z() * z_diff;
|
.map(|i| if i % 2 == 0 { i } else { -i } / 2)
|
||||||
if self
|
.map(|z_diff| pos + Vec3::unit_z() * z_diff)
|
||||||
.get(test_pos - Vec3::unit_z())
|
.find(|test_pos| {
|
||||||
.map(|b| b.is_filled())
|
self.get(test_pos - Vec3::unit_z())
|
||||||
.unwrap_or(false)
|
.map_or(false, |b| b.is_filled())
|
||||||
&& (0..2)
|
&& (0..2).all(|z| {
|
||||||
.all(|z| self
|
self.get(test_pos + Vec3::unit_z() * z)
|
||||||
.get(test_pos + Vec3::unit_z() * z)
|
.map_or(true, |b| !b.is_solid())
|
||||||
.map(|b| !b.is_solid())
|
})
|
||||||
.unwrap_or(true))
|
})
|
||||||
{
|
.unwrap_or(pos)
|
||||||
return test_pos;
|
|
||||||
}
|
|
||||||
z_diff = -z_diff + if z_diff <= 0 { 1 } else { 0 };
|
|
||||||
}
|
|
||||||
pos
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user