aboutsummaryrefslogtreecommitdiff
path: root/azalea/src/pathfinder/mod.rs
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2023-10-02 17:51:38 -0500
committermat <git@matdoes.dev>2023-10-02 17:51:38 -0500
commitd0505f7de30e4a9a330ef99d0082849ee44723e0 (patch)
treef91879b0423eb0329efd2cb12a10a4e98b3b366d /azalea/src/pathfinder/mod.rs
parentc3d27487cae6af5d593193b922d1e81e93a1c45d (diff)
downloadazalea-drasl-d0505f7de30e4a9a330ef99d0082849ee44723e0.tar.xz
optimize pathfinder more
Diffstat (limited to 'azalea/src/pathfinder/mod.rs')
-rw-r--r--azalea/src/pathfinder/mod.rs31
1 files changed, 18 insertions, 13 deletions
diff --git a/azalea/src/pathfinder/mod.rs b/azalea/src/pathfinder/mod.rs
index 02b7d935..831a5524 100644
--- a/azalea/src/pathfinder/mod.rs
+++ b/azalea/src/pathfinder/mod.rs
@@ -19,6 +19,7 @@ use crate::ecs::{
query::{With, Without},
system::{Commands, Query, Res},
};
+use crate::pathfinder::moves::PathfinderCtx;
use azalea_client::movement::walk_listener;
use azalea_client::{StartSprintEvent, StartWalkEvent};
use azalea_core::position::BlockPos;
@@ -178,7 +179,8 @@ fn goto_listener(
debug!("start: {start:?}");
let world = &world_lock.read().chunks;
- let successors = |pos: BlockPos| successors_fn(world, pos);
+ let ctx = PathfinderCtx::new(world);
+ let successors = |pos: BlockPos| successors_fn(&ctx, pos);
let mut attempt_number = 0;
@@ -192,15 +194,20 @@ fn goto_listener(
|n| goal.heuristic(n),
successors,
|n| goal.success(n),
- Duration::from_secs(if attempt_number == 0 { 1 } else { 5 }),
+ Duration::from_secs(if attempt_number == 0 { 10 } else { 10 }),
);
let end_time = std::time::Instant::now();
debug!("partial: {partial:?}");
- debug!("time: {:?}", end_time - start_time);
+ let duration = end_time - start_time;
+ if partial {
+ info!("Pathfinder took {duration:?} (timed out)");
+ } else {
+ info!("Pathfinder took {duration:?}");
+ }
- info!("Path:");
+ debug!("Path:");
for movement in &movements {
- info!(" {:?}", movement.target);
+ debug!(" {:?}", movement.target);
}
path = movements.into_iter().collect::<VecDeque<_>>();
@@ -275,11 +282,10 @@ fn path_found_listener(
let world_lock = instance_container.get(instance_name).expect(
"Entity tried to pathfind but the entity isn't in a valid world",
);
+ let world = &world_lock.read().chunks;
+ let ctx = PathfinderCtx::new(&world);
let successors_fn: moves::SuccessorsFn = event.successors_fn;
- let successors = |pos: BlockPos| {
- let world = &world_lock.read().chunks;
- successors_fn(world, pos)
- };
+ let successors = |pos: BlockPos| successors_fn(&ctx, pos);
if successors(last_node.target)
.iter()
@@ -439,10 +445,9 @@ fn tick_execute_path(
{
// obstruction check (the path we're executing isn't possible anymore)
- let successors = |pos: BlockPos| {
- let world = &world_lock.read().chunks;
- successors_fn(world, pos)
- };
+ let world = &world_lock.read().chunks;
+ let ctx = PathfinderCtx::new(&world);
+ let successors = |pos: BlockPos| successors_fn(&ctx, pos);
if let Some(last_reached_node) = pathfinder.last_reached_node {
if let Some(obstructed_index) =