Rename find_space_opt to try_find_space.

This commit is contained in:
Avi Weinstock 2021-07-24 13:09:10 -04:00
parent ca10d89068
commit 5dd56b724c
2 changed files with 3 additions and 3 deletions

View File

@ -159,10 +159,10 @@ 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> {
self.find_space_opt(pos).unwrap_or(pos) self.try_find_space(pos).unwrap_or(pos)
} }
pub fn find_space_opt(&self, pos: Vec3<i32>) -> Option<Vec3<i32>> { pub fn try_find_space(&self, pos: Vec3<i32>) -> Option<Vec3<i32>> {
const SEARCH_DIST: i32 = 63; const SEARCH_DIST: i32 = 63;
(0..SEARCH_DIST * 2 + 1) (0..SEARCH_DIST * 2 + 1)
.map(|i| if i % 2 == 0 { i } else { -i } / 2) .map(|i| if i % 2 == 0 { i } else { -i } / 2)

View File

@ -336,7 +336,7 @@ impl<'a> System<'a> for Sys {
let chunk_pos = terrain.pos_key(pos.0.map(|e| e as i32)); let chunk_pos = terrain.pos_key(pos.0.map(|e| e as i32));
if let Some(chunk) = terrain.get_key(chunk_pos) { if let Some(chunk) = terrain.get_key(chunk_pos) {
pos.0 = terrain pos.0 = terrain
.find_space_opt(pos.0.as_::<i32>()) .try_find_space(pos.0.as_::<i32>())
.map(|x| x.as_::<f32>()) .map(|x| x.as_::<f32>())
.unwrap_or_else(|| chunk.find_accessible_pos(pos.0.xy().as_::<i32>(), false)); .unwrap_or_else(|| chunk.find_accessible_pos(pos.0.xy().as_::<i32>(), false));
repositioned.push(entity); repositioned.push(entity);