From 7b10e5cd7e80be85f7b0517f941b175e733d3fc4 Mon Sep 17 00:00:00 2001 From: mat Date: Mon, 2 Oct 2023 18:53:27 -0500 Subject: optimize pathfinder more --- azalea/src/pathfinder/moves/mod.rs | 4 ++-- azalea/src/pathfinder/moves/parkour.rs | 27 +++++++++++++++------------ 2 files changed, 17 insertions(+), 14 deletions(-) (limited to 'azalea/src') diff --git a/azalea/src/pathfinder/moves/mod.rs b/azalea/src/pathfinder/moves/mod.rs index caf4bbb4..9eb6462b 100644 --- a/azalea/src/pathfinder/moves/mod.rs +++ b/azalea/src/pathfinder/moves/mod.rs @@ -80,7 +80,7 @@ impl<'a> PathfinderCtx<'a> { // fast path return true; } - if block.shape() != &*collision::EMPTY_SHAPE { + if !block.is_shape_empty() { return false; } if block == azalea_registry::Block::Water.into() { @@ -107,7 +107,7 @@ impl<'a> PathfinderCtx<'a> { // fast path return false; } - block.shape() == &*collision::BLOCK_SHAPE + block.is_shape_full() } /// Whether this block and the block above are passable diff --git a/azalea/src/pathfinder/moves/parkour.rs b/azalea/src/pathfinder/moves/parkour.rs index 53f5a348..27763257 100644 --- a/azalea/src/pathfinder/moves/parkour.rs +++ b/azalea/src/pathfinder/moves/parkour.rs @@ -22,6 +22,10 @@ fn parkour_forward_1_move(ctx: &PathfinderCtx, pos: BlockPos) -> Vec { let gap_offset = BlockPos::new(dir.x(), 0, dir.z()); let offset = BlockPos::new(dir.x() * 2, 0, dir.z() * 2); + // make sure we actually have to jump + if ctx.is_block_solid(&(pos + gap_offset).down(1)) { + continue; + } if !ctx.is_standable(&(pos + offset)) { continue; } @@ -31,10 +35,6 @@ fn parkour_forward_1_move(ctx: &PathfinderCtx, pos: BlockPos) -> Vec { if !ctx.is_block_passable(&(pos + gap_offset).up(2)) { continue; } - // make sure we actually have to jump - if ctx.is_block_solid(&(pos + gap_offset).down(1)) { - continue; - } // make sure it's not a headhitter if !ctx.is_block_passable(&pos.up(2)) { continue; @@ -64,6 +64,13 @@ fn parkour_forward_2_move(ctx: &PathfinderCtx, pos: BlockPos) -> Vec { let gap_2_offset = BlockPos::new(dir.x() * 2, 0, dir.z() * 2); let offset = BlockPos::new(dir.x() * 3, 0, dir.z() * 3); + // make sure we actually have to jump + if ctx.is_block_solid(&(pos + gap_1_offset).down(1)) + || ctx.is_block_solid(&(pos + gap_2_offset).down(1)) + { + continue; + } + if !ctx.is_standable(&(pos + offset)) { continue; } @@ -79,10 +86,6 @@ fn parkour_forward_2_move(ctx: &PathfinderCtx, pos: BlockPos) -> Vec { if !ctx.is_block_passable(&(pos + gap_2_offset).up(2)) { continue; } - // make sure we actually have to jump - if ctx.is_block_solid(&(pos + gap_1_offset).down(1)) { - continue; - } // make sure it's not a headhitter if !ctx.is_block_passable(&pos.up(2)) { continue; @@ -114,6 +117,10 @@ fn parkour_headhitter_forward_1_move(ctx: &PathfinderCtx, pos: BlockPos) -> Vec< let gap_offset = BlockPos::new(dir.x(), 0, dir.z()); let offset = BlockPos::new(dir.x() * 2, 0, dir.z() * 2); + // make sure we actually have to jump + if ctx.is_block_solid(&(pos + gap_offset).down(1)) { + continue; + } if !ctx.is_standable(&(pos + offset)) { continue; } @@ -123,10 +130,6 @@ fn parkour_headhitter_forward_1_move(ctx: &PathfinderCtx, pos: BlockPos) -> Vec< if !ctx.is_block_passable(&(pos + gap_offset).up(2)) { continue; } - // make sure we actually have to jump - if ctx.is_block_solid(&(pos + gap_offset).down(1)) { - continue; - } // make sure it is a headhitter if !ctx.is_block_solid(&pos.up(2)) { continue; -- cgit v1.2.3