diff options
| author | mat <git@matdoes.dev> | 2026-01-19 15:05:44 +0600 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2026-01-19 13:28:15 +0400 |
| commit | 6f82263de58c6f33cca8cc36276b5e478801b352 (patch) | |
| tree | 6230d62ce601efa2ae31f9fb363e8d756d787d4d | |
| parent | 70bd9c94dd7ca68777a0ead5f9432812e535bee3 (diff) | |
| download | azalea-drasl-6f82263de58c6f33cca8cc36276b5e478801b352.tar.xz | |
minor physics optimizations
| -rw-r--r-- | azalea-client/src/plugins/movement.rs | 10 | ||||
| -rw-r--r-- | azalea-core/src/bitset.rs | 8 | ||||
| -rw-r--r-- | azalea-physics/src/collision/shape.rs | 17 | ||||
| -rw-r--r-- | azalea-world/src/chunk_storage.rs | 3 | ||||
| -rw-r--r-- | azalea/benches/physics.rs | 4 |
5 files changed, 20 insertions, 22 deletions
diff --git a/azalea-client/src/plugins/movement.rs b/azalea-client/src/plugins/movement.rs index 94b996a0..6e2da752 100644 --- a/azalea-client/src/plugins/movement.rs +++ b/azalea-client/src/plugins/movement.rs @@ -346,10 +346,10 @@ pub fn local_player_ai_step( let new_crouching = !abilities.flying && !is_swimming && !is_passenger - && can_player_fit_within_blocks_and_entities_when(&ctx, Pose::Crouching) && (last_sent_input.is_some_and(|i| i.0.shift) || !is_sleeping - && !can_player_fit_within_blocks_and_entities_when(&ctx, Pose::Standing)); + && !can_player_fit_within_blocks_and_entities_when(&ctx, Pose::Standing)) + && can_player_fit_within_blocks_and_entities_when(&ctx, Pose::Crouching); if **crouching != new_crouching { **crouching = new_crouching; } @@ -650,15 +650,15 @@ struct CanPlayerFitCtx<'world, 'state, 'a, 'b> { physics: &'a Physics, } fn can_player_fit_within_blocks_and_entities_when(ctx: &CanPlayerFitCtx, pose: Pose) -> bool { - // return this.level().noCollision(this, - // this.getDimensions(var1).makeBoundingBox(this.position()).deflate(1.0E-7)); no_collision( ctx.world, Some(ctx.entity), ctx.aabb_query, ctx.collidable_entity_query, ctx.physics, - &calculate_dimensions(EntityKind::Player, pose).make_bounding_box(*ctx.position), + &calculate_dimensions(EntityKind::Player, pose) + .make_bounding_box(*ctx.position) + .deflate_all(1.0e-7), false, ) } diff --git a/azalea-core/src/bitset.rs b/azalea-core/src/bitset.rs index f8c9da28..b50988b1 100644 --- a/azalea-core/src/bitset.rs +++ b/azalea-core/src/bitset.rs @@ -8,7 +8,7 @@ use azalea_buf::{AzBuf, BufReadError}; /// Represents Java's BitSet, a list of bits. #[derive(AzBuf, Clone, Debug, Default, Eq, Hash, PartialEq)] pub struct BitSet { - data: Vec<u64>, + data: Box<[u64]>, } /// `log2(64)`. @@ -19,7 +19,7 @@ impl BitSet { #[inline] pub fn new(num_bits: usize) -> Self { BitSet { - data: vec![0; num_bits.div_ceil(64)], + data: vec![0; num_bits.div_ceil(64)].into(), } } @@ -155,7 +155,7 @@ impl BitSet { impl From<Vec<u64>> for BitSet { fn from(data: Vec<u64>) -> Self { - BitSet { data } + BitSet { data: data.into() } } } @@ -165,7 +165,7 @@ impl From<Vec<u8>> for BitSet { for (i, byte) in data.iter().enumerate() { words[i / 8] |= (*byte as u64) << ((i % 8) * 8); } - BitSet { data: words } + BitSet { data: words.into() } } } diff --git a/azalea-physics/src/collision/shape.rs b/azalea-physics/src/collision/shape.rs index 4726ff85..63dd1b4d 100644 --- a/azalea-physics/src/collision/shape.rs +++ b/azalea-physics/src/collision/shape.rs @@ -607,9 +607,9 @@ pub struct CubeVoxelShape { #[allow(dead_code)] faces: Option<Vec<VoxelShape>>, - x_coords: Vec<f64>, - y_coords: Vec<f64>, - z_coords: Vec<f64>, + x_coords: Box<[f64]>, + y_coords: Box<[f64]>, + z_coords: Box<[f64]>, } impl ArrayVoxelShape { @@ -631,9 +631,7 @@ impl ArrayVoxelShape { zs, } } -} -impl ArrayVoxelShape { fn shape(&self) -> &DiscreteVoxelShape { &self.shape } @@ -665,13 +663,10 @@ impl CubeVoxelShape { &self.shape } - fn calculate_coords(shape: &DiscreteVoxelShape, axis: Axis) -> Vec<f64> { + fn calculate_coords(shape: &DiscreteVoxelShape, axis: Axis) -> Box<[f64]> { let size = shape.size(axis); - let mut parts = Vec::with_capacity(size as usize); - for i in 0..=size { - parts.push(i as f64 / size as f64); - } - parts + + (0..=size).map(|i| i as f64 / size as f64).collect() } #[inline] diff --git a/azalea-world/src/chunk_storage.rs b/azalea-world/src/chunk_storage.rs index 0ad96c81..e170dc83 100644 --- a/azalea-world/src/chunk_storage.rs +++ b/azalea-world/src/chunk_storage.rs @@ -457,6 +457,9 @@ pub fn get_block_state_from_sections( return None; }; let section = §ions[section_index]; + if section.block_count == 0 { + return Some(BlockState::AIR); + } let chunk_section_pos = ChunkSectionBlockPos::from(pos); Some(section.get_block_state(chunk_section_pos)) } diff --git a/azalea/benches/physics.rs b/azalea/benches/physics.rs index d81a0221..8b15cc6c 100644 --- a/azalea/benches/physics.rs +++ b/azalea/benches/physics.rs @@ -32,7 +32,7 @@ fn generate_world(partial_chunks: &mut PartialChunkStorage, size: u32) -> ChunkS for z in 0..16_u8 { chunk.set_block_state( &ChunkBlockPos::new(x, 1, z), - BlockKind::OakFence.into(), + BlockKind::Stone.into(), chunks.min_y, ); } @@ -74,7 +74,7 @@ fn run_physics_benchmark(b: &mut Bencher<'_>) { b.iter(|| { let entity = simulation_set.spawn(SimulatedPlayerBundle::new(Vec3::new(0.5, 2.0, 0.5))); - for _ in 0..20 { + for _ in 0..200 { simulation_set.tick(); } simulation_set.despawn(entity); |
