diff options
| author | mat <git@matdoes.dev> | 2023-10-01 20:23:26 -0500 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2023-10-01 20:23:26 -0500 |
| commit | 4f6ab28325ce87678a406e07327bd4f051282109 (patch) | |
| tree | 1481029bb8a2a4bde50031c1c50ded3c9c216bf8 /azalea/src | |
| parent | 37146f46f03f2e18becb7b58725a9183bcbcb2e6 (diff) | |
| download | azalea-drasl-4f6ab28325ce87678a406e07327bd4f051282109.tar.xz | |
add pathfinder benchmark
Diffstat (limited to 'azalea/src')
| -rw-r--r-- | azalea/src/pathfinder/mod.rs | 18 | ||||
| -rw-r--r-- | azalea/src/pathfinder/moves/basic.rs | 12 | ||||
| -rw-r--r-- | azalea/src/pathfinder/moves/mod.rs | 22 | ||||
| -rw-r--r-- | azalea/src/pathfinder/moves/parkour.rs | 10 |
4 files changed, 30 insertions, 32 deletions
diff --git a/azalea/src/pathfinder/mod.rs b/azalea/src/pathfinder/mod.rs index 0be063a4..02b7d935 100644 --- a/azalea/src/pathfinder/mod.rs +++ b/azalea/src/pathfinder/mod.rs @@ -1,10 +1,10 @@ //! A pathfinding plugin to make bots navigate the world. A lot of this code is //! based on [Baritone](https://github.com/cabaletta/baritone). -mod astar; +pub mod astar; pub mod costs; pub mod goals; -mod moves; +pub mod moves; pub mod simulation; use crate::bot::{JumpEvent, LookAtEvent}; @@ -177,10 +177,8 @@ fn goto_listener( let task = thread_pool.spawn(async move { debug!("start: {start:?}"); - let successors = |pos: BlockPos| { - let world = world_lock.read(); - successors_fn(&world, pos) - }; + let world = &world_lock.read().chunks; + let successors = |pos: BlockPos| successors_fn(world, pos); let mut attempt_number = 0; @@ -279,8 +277,8 @@ fn path_found_listener( ); let successors_fn: moves::SuccessorsFn = event.successors_fn; let successors = |pos: BlockPos| { - let world = world_lock.read(); - successors_fn(&world, pos) + let world = &world_lock.read().chunks; + successors_fn(world, pos) }; if successors(last_node.target) @@ -442,8 +440,8 @@ fn tick_execute_path( { // obstruction check (the path we're executing isn't possible anymore) let successors = |pos: BlockPos| { - let world = world_lock.read(); - successors_fn(&world, pos) + let world = &world_lock.read().chunks; + successors_fn(world, pos) }; if let Some(last_reached_node) = pathfinder.last_reached_node { diff --git a/azalea/src/pathfinder/moves/basic.rs b/azalea/src/pathfinder/moves/basic.rs index 188eb3a6..1785ec2e 100644 --- a/azalea/src/pathfinder/moves/basic.rs +++ b/azalea/src/pathfinder/moves/basic.rs @@ -5,7 +5,7 @@ use azalea_core::{ direction::CardinalDirection, position::{BlockPos, Vec3}, }; -use azalea_world::Instance; +use azalea_world::ChunkStorage; use crate::{ pathfinder::{astar, costs::*}, @@ -17,7 +17,7 @@ use super::{ ExecuteCtx, IsReachedCtx, MoveData, }; -pub fn basic_move(world: &Instance, node: BlockPos) -> Vec<Edge> { +pub fn basic_move(world: &ChunkStorage, node: BlockPos) -> Vec<Edge> { let mut edges = Vec::new(); edges.extend(forward_move(world, node)); edges.extend(ascend_move(world, node)); @@ -26,7 +26,7 @@ pub fn basic_move(world: &Instance, node: BlockPos) -> Vec<Edge> { edges } -fn forward_move(world: &Instance, pos: BlockPos) -> Vec<Edge> { +fn forward_move(world: &ChunkStorage, pos: BlockPos) -> Vec<Edge> { let mut edges = Vec::new(); for dir in CardinalDirection::iter() { let offset = BlockPos::new(dir.x(), 0, dir.z()); @@ -72,7 +72,7 @@ fn execute_forward_move( }); } -fn ascend_move(world: &Instance, pos: BlockPos) -> Vec<Edge> { +fn ascend_move(world: &ChunkStorage, pos: BlockPos) -> Vec<Edge> { let mut edges = Vec::new(); for dir in CardinalDirection::iter() { let offset = BlockPos::new(dir.x(), 1, dir.z()); @@ -156,7 +156,7 @@ pub fn ascend_is_reached( BlockPos::from(position) == target || BlockPos::from(position) == target.down(1) } -fn descend_move(world: &Instance, pos: BlockPos) -> Vec<Edge> { +fn descend_move(world: &ChunkStorage, pos: BlockPos) -> Vec<Edge> { let mut edges = Vec::new(); for dir in CardinalDirection::iter() { let dir_delta = BlockPos::new(dir.x(), 0, dir.z()); @@ -258,7 +258,7 @@ pub fn descend_is_reached( && (position.y - target.y as f64) < 0.5 } -fn diagonal_move(world: &Instance, pos: BlockPos) -> Vec<Edge> { +fn diagonal_move(world: &ChunkStorage, pos: BlockPos) -> Vec<Edge> { let mut edges = Vec::new(); for dir in CardinalDirection::iter() { let right = dir.right(); diff --git a/azalea/src/pathfinder/moves/mod.rs b/azalea/src/pathfinder/moves/mod.rs index d631ac8a..9bd074c0 100644 --- a/azalea/src/pathfinder/moves/mod.rs +++ b/azalea/src/pathfinder/moves/mod.rs @@ -9,13 +9,13 @@ use super::astar; use azalea_client::{StartSprintEvent, StartWalkEvent}; use azalea_core::position::{BlockPos, Vec3}; use azalea_physics::collision::{self, BlockWithShape}; -use azalea_world::Instance; +use azalea_world::ChunkStorage; use bevy_ecs::{entity::Entity, event::EventWriter}; type Edge = astar::Edge<BlockPos, MoveData>; pub type SuccessorsFn = - fn(&azalea_world::Instance, BlockPos) -> Vec<astar::Edge<BlockPos, MoveData>>; + fn(&azalea_world::ChunkStorage, BlockPos) -> Vec<astar::Edge<BlockPos, MoveData>>; #[derive(Clone)] pub struct MoveData { @@ -34,8 +34,8 @@ impl Debug for MoveData { } /// whether this block is passable -fn is_block_passable(pos: &BlockPos, world: &Instance) -> bool { - if let Some(block) = world.chunks.get_block_state(pos) { +fn is_block_passable(pos: &BlockPos, world: &ChunkStorage) -> bool { + if let Some(block) = world.get_block_state(pos) { if block.shape() != &collision::empty_shape() { return false; } @@ -58,8 +58,8 @@ fn is_block_passable(pos: &BlockPos, world: &Instance) -> bool { } /// whether this block has a solid hitbox (i.e. we can stand on it) -fn is_block_solid(pos: &BlockPos, world: &Instance) -> bool { - if let Some(block) = world.chunks.get_block_state(pos) { +fn is_block_solid(pos: &BlockPos, world: &ChunkStorage) -> bool { + if let Some(block) = world.get_block_state(pos) { block.shape() == &collision::block_shape() } else { false @@ -67,26 +67,26 @@ fn is_block_solid(pos: &BlockPos, world: &Instance) -> bool { } /// Whether this block and the block above are passable -fn is_passable(pos: &BlockPos, world: &Instance) -> bool { +fn is_passable(pos: &BlockPos, world: &ChunkStorage) -> bool { is_block_passable(pos, world) && is_block_passable(&pos.up(1), world) } /// Whether we can stand in this position. Checks if the block below is solid, /// and that the two blocks above that are passable. -fn is_standable(pos: &BlockPos, world: &Instance) -> bool { +fn is_standable(pos: &BlockPos, world: &ChunkStorage) -> bool { is_block_solid(&pos.down(1), world) && is_passable(pos, world) } /// Get the amount of air blocks until the next solid block below this one. -fn fall_distance(pos: &BlockPos, world: &Instance) -> u32 { +fn fall_distance(pos: &BlockPos, world: &ChunkStorage) -> u32 { let mut distance = 0; let mut current_pos = pos.down(1); while is_block_passable(¤t_pos, world) { distance += 1; current_pos = current_pos.down(1); - if current_pos.y < world.chunks.min_y { + if current_pos.y < world.min_y { return u32::MAX; } } @@ -115,7 +115,7 @@ pub struct IsReachedCtx<'a> { pub physics: &'a azalea_entity::Physics, } -pub fn default_move(world: &Instance, node: BlockPos) -> Vec<Edge> { +pub fn default_move(world: &ChunkStorage, node: BlockPos) -> Vec<Edge> { let mut edges = Vec::new(); edges.extend(basic::basic_move(world, node)); edges.extend(parkour::parkour_move(world, node)); diff --git a/azalea/src/pathfinder/moves/parkour.rs b/azalea/src/pathfinder/moves/parkour.rs index ab9c509c..03635faa 100644 --- a/azalea/src/pathfinder/moves/parkour.rs +++ b/azalea/src/pathfinder/moves/parkour.rs @@ -1,6 +1,6 @@ use azalea_client::{SprintDirection, StartSprintEvent, StartWalkEvent, WalkDirection}; use azalea_core::{direction::CardinalDirection, position::BlockPos}; -use azalea_world::Instance; +use azalea_world::ChunkStorage; use crate::{ pathfinder::{astar, costs::*}, @@ -12,7 +12,7 @@ use super::{ ExecuteCtx, IsReachedCtx, MoveData, }; -pub fn parkour_move(world: &Instance, node: BlockPos) -> Vec<Edge> { +pub fn parkour_move(world: &ChunkStorage, node: BlockPos) -> Vec<Edge> { let mut edges = Vec::new(); edges.extend(parkour_forward_1_move(world, node)); edges.extend(parkour_headhitter_forward_1_move(world, node)); @@ -20,7 +20,7 @@ pub fn parkour_move(world: &Instance, node: BlockPos) -> Vec<Edge> { edges } -fn parkour_forward_1_move(world: &Instance, pos: BlockPos) -> Vec<Edge> { +fn parkour_forward_1_move(world: &ChunkStorage, pos: BlockPos) -> Vec<Edge> { let mut edges = Vec::new(); for dir in CardinalDirection::iter() { let gap_offset = BlockPos::new(dir.x(), 0, dir.z()); @@ -61,7 +61,7 @@ fn parkour_forward_1_move(world: &Instance, pos: BlockPos) -> Vec<Edge> { edges } -fn parkour_forward_2_move(world: &Instance, pos: BlockPos) -> Vec<Edge> { +fn parkour_forward_2_move(world: &ChunkStorage, pos: BlockPos) -> Vec<Edge> { let mut edges = Vec::new(); for dir in CardinalDirection::iter() { let gap_1_offset = BlockPos::new(dir.x(), 0, dir.z()); @@ -112,7 +112,7 @@ fn parkour_forward_2_move(world: &Instance, pos: BlockPos) -> Vec<Edge> { edges } -fn parkour_headhitter_forward_1_move(world: &Instance, pos: BlockPos) -> Vec<Edge> { +fn parkour_headhitter_forward_1_move(world: &ChunkStorage, pos: BlockPos) -> Vec<Edge> { let mut edges = Vec::new(); for dir in CardinalDirection::iter() { let gap_offset = BlockPos::new(dir.x(), 0, dir.z()); |
