aboutsummaryrefslogtreecommitdiff
path: root/azalea
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2024-02-25 22:31:56 -0600
committermat <git@matdoes.dev>2024-02-25 22:31:56 -0600
commite47dee388e1e7f051417244ab1c054f8b9acd755 (patch)
tree41c369fdcd967dc795ea66cb3a6c982c3dfd2d2f /azalea
parent018ab55bdb02e7774044198c8a30e0d02a7c6e29 (diff)
downloadazalea-drasl-e47dee388e1e7f051417244ab1c054f8b9acd755.tar.xz
reduce allocations for collision detection
Diffstat (limited to 'azalea')
-rw-r--r--azalea/benches/physics.rs82
1 files changed, 17 insertions, 65 deletions
diff --git a/azalea/benches/physics.rs b/azalea/benches/physics.rs
index 6f8dc7bc..0d4a3f2f 100644
--- a/azalea/benches/physics.rs
+++ b/azalea/benches/physics.rs
@@ -28,29 +28,22 @@ fn generate_world(partial_chunks: &mut PartialChunkStorage, size: u32) -> ChunkS
}
}
- // for chunk_x in -size..size {
- // for chunk_z in -size..size {
- // let chunk_pos = ChunkPos::new(chunk_x, chunk_z);
- // let chunk = chunks.get(&chunk_pos).unwrap();
- // let mut chunk = chunk.write();
- // for x in 0..16_u8 {
- // for z in 0..16_u8 {
- // chunk.set(
- // &ChunkBlockPos::new(x, 1, z),
- // azalea_registry::Block::Bedrock.into(),
- // chunks.min_y,
- // );
- // if rng.gen_bool(0.5) {
- // chunk.set(
- // &ChunkBlockPos::new(x, 2, z),
- // azalea_registry::Block::Bedrock.into(),
- // chunks.min_y,
- // );
- // }
- // }
- // }
- // }
- // }
+ for chunk_x in -size..size {
+ for chunk_z in -size..size {
+ let chunk_pos = ChunkPos::new(chunk_x, chunk_z);
+ let chunk = chunks.get(&chunk_pos).unwrap();
+ let mut chunk = chunk.write();
+ for x in 0..16_u8 {
+ for z in 0..16_u8 {
+ chunk.set(
+ &ChunkBlockPos::new(x, 1, z),
+ azalea_registry::Block::OakFence.into(),
+ chunks.min_y,
+ );
+ }
+ }
+ }
+ }
// let mut start = BlockPos::new(-64, 4, -64);
// // move start down until it's on a solid block
@@ -69,47 +62,6 @@ fn generate_world(partial_chunks: &mut PartialChunkStorage, size: u32) -> ChunkS
chunks
}
-fn generate_mining_world(
- partial_chunks: &mut PartialChunkStorage,
- size: u32,
-) -> (ChunkStorage, BlockPos, BlockPos) {
- let size = size as i32;
-
- let mut chunks = ChunkStorage::default();
- for chunk_x in -size..size {
- for chunk_z in -size..size {
- let chunk_pos = ChunkPos::new(chunk_x, chunk_z);
- partial_chunks.set(&chunk_pos, Some(Chunk::default()), &mut chunks);
- }
- }
-
- // let mut rng = StdRng::seed_from_u64(0);
-
- for chunk_x in -size..size {
- for chunk_z in -size..size {
- let chunk_pos = ChunkPos::new(chunk_x, chunk_z);
- let chunk = chunks.get(&chunk_pos).unwrap();
- let mut chunk = chunk.write();
- for y in chunks.min_y..(chunks.min_y + chunks.height as i32) {
- for x in 0..16_u8 {
- for z in 0..16_u8 {
- chunk.set(
- &ChunkBlockPos::new(x, y, z),
- azalea_registry::Block::Stone.into(),
- chunks.min_y,
- );
- }
- }
- }
- }
- }
-
- let start = BlockPos::new(-64, 4, -64);
- let end = BlockPos::new(0, 4, 0);
-
- (chunks, start, end)
-}
-
fn run_physics_benchmark(b: &mut Bencher<'_>) {
let mut partial_chunks = PartialChunkStorage::new(32);
@@ -126,7 +78,7 @@ fn run_physics_benchmark(b: &mut Bencher<'_>) {
// std::process::exit(0);
b.iter(|| {
- let entity = simulation_set.spawn(SimulatedPlayerBundle::new(Vec3::new(0.0, 4.0, 0.0)));
+ let entity = simulation_set.spawn(SimulatedPlayerBundle::new(Vec3::new(0.5, 2.0, 0.5)));
for _ in 0..20 {
simulation_set.tick();
}