Better pathfinding iteration cap

This commit is contained in:
Joshua Barretto 2020-01-24 10:40:52 +00:00
parent 7167320c92
commit 353a0f67be
3 changed files with 8 additions and 11 deletions

View File

@ -135,8 +135,8 @@ impl Chaser {
fn find_path<V>(
astar: &mut Option<Astar<Vec3<i32>>>,
vol: &V,
start: Vec3<f32>,
end: Vec3<f32>,
startf: Vec3<f32>,
endf: Vec3<f32>,
) -> Path<Vec3<i32>>
where
V: BaseVol<Vox = Block> + ReadVol,
@ -167,8 +167,8 @@ where
};
let (start, end) = match (
get_walkable_z(start.map(|e| e.floor() as i32)),
get_walkable_z(end.map(|e| e.floor() as i32)),
get_walkable_z(startf.map(|e| e.floor() as i32)),
get_walkable_z(endf.map(|e| e.floor() as i32)),
) {
(Some(start), Some(end)) => (start, end),
_ => return Path::default(),
@ -206,8 +206,8 @@ where
let mut new_astar = match astar.take() {
None => {
let max_iters = ((Vec2::<f32>::from(start).distance(Vec2::from(end)) + 10.0).powf(2.0)
as usize)
let max_iters = ((Vec2::<f32>::from(startf).distance(Vec2::from(endf)) * 2.0 + 25.0)
.powf(2.0) as usize)
.min(25_000);
Astar::new(max_iters, start, heuristic.clone())
}

View File

@ -133,7 +133,7 @@ impl Server {
#[cfg(not(feature = "worldgen"))]
let world = World::generate(settings.world_seed);
let map = Vec::new();
let map = vec![0];
#[cfg(feature = "worldgen")]
let spawn_point = {

View File

@ -7,10 +7,7 @@ use rand::{prelude::*, rngs::SmallRng};
use std::time::Duration;
use vek::*;
pub const WORLD_SIZE: Vec2<usize> = Vec2 {
x: 1024 * 1,
y: 1024 * 1,
};
pub const WORLD_SIZE: Vec2<usize> = Vec2 { x: 1, y: 1 };
pub struct World;