2024-03-04 23:12:35 +00:00
|
|
|
use common::{spiral::Spiral2d, terrain::CoordinateConversions};
|
2024-03-11 15:36:56 +00:00
|
|
|
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
2024-03-02 22:31:42 +00:00
|
|
|
use rayon::ThreadPoolBuilder;
|
|
|
|
use veloren_world::{
|
|
|
|
layer,
|
2024-03-28 09:32:59 +00:00
|
|
|
sim::{FileOpts, WorldOpts, DEFAULT_WORLD_MAP, DEFAULT_WORLD_SEED},
|
2024-03-04 23:12:35 +00:00
|
|
|
CanvasInfo, Land, World,
|
2024-03-02 22:31:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
fn cave(c: &mut Criterion) {
|
|
|
|
let pool = ThreadPoolBuilder::new().build().unwrap();
|
|
|
|
let (world, index) = World::generate(
|
2024-03-28 09:32:59 +00:00
|
|
|
DEFAULT_WORLD_SEED,
|
2024-03-02 22:31:42 +00:00
|
|
|
WorldOpts {
|
|
|
|
seed_elements: true,
|
|
|
|
world_file: FileOpts::LoadAsset(DEFAULT_WORLD_MAP.into()),
|
|
|
|
..WorldOpts::default()
|
|
|
|
},
|
|
|
|
&pool,
|
|
|
|
&|_| {},
|
|
|
|
);
|
|
|
|
let land = Land::from_sim(world.sim());
|
2024-03-04 23:12:35 +00:00
|
|
|
let mut group = c.benchmark_group("cave");
|
2024-03-11 15:36:56 +00:00
|
|
|
group.sample_size(10);
|
2024-03-04 23:12:35 +00:00
|
|
|
group.bench_function("generate_entrances", |b| {
|
2024-03-02 22:31:42 +00:00
|
|
|
b.iter(|| {
|
2024-03-11 15:36:56 +00:00
|
|
|
let entrances =
|
|
|
|
black_box(layer::cave::surface_entrances(&land)).map(|e| e.wpos_to_cpos());
|
2024-03-02 22:31:42 +00:00
|
|
|
for entrance in entrances {
|
|
|
|
_ = black_box(world.generate_chunk(
|
|
|
|
index.as_index_ref(),
|
|
|
|
entrance,
|
|
|
|
None,
|
|
|
|
|| false,
|
|
|
|
None,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2024-03-04 23:12:35 +00:00
|
|
|
|
2024-03-11 15:36:56 +00:00
|
|
|
group.bench_function("generate_multiple_tunnels", |b| {
|
|
|
|
b.iter(|| {
|
|
|
|
let entrances = layer::cave::surface_entrances(&land)
|
|
|
|
.map(|e| e.wpos_to_cpos())
|
|
|
|
.step_by(6);
|
|
|
|
for entrance in entrances {
|
|
|
|
let chunk = Spiral2d::new()
|
|
|
|
.step_by(16)
|
2024-03-04 23:12:35 +00:00
|
|
|
.find(|p| {
|
|
|
|
CanvasInfo::with_mock_canvas_info(
|
|
|
|
index.as_index_ref(),
|
|
|
|
world.sim(),
|
|
|
|
|&info| {
|
|
|
|
let land = &info.land();
|
|
|
|
let tunnels =
|
|
|
|
layer::cave::tunnel_bounds_at(entrance + p, &info, land);
|
2024-03-11 15:36:56 +00:00
|
|
|
tunnels.count() > 1
|
2024-03-04 23:12:35 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
})
|
2024-03-11 15:36:56 +00:00
|
|
|
.map_or(entrance, |p| entrance + p);
|
|
|
|
|
2024-03-04 23:12:35 +00:00
|
|
|
_ = black_box(world.generate_chunk(
|
|
|
|
index.as_index_ref(),
|
|
|
|
chunk,
|
|
|
|
None,
|
|
|
|
|| false,
|
|
|
|
None,
|
|
|
|
));
|
2024-03-11 15:36:56 +00:00
|
|
|
}
|
|
|
|
});
|
2024-03-04 23:12:35 +00:00
|
|
|
});
|
2024-03-02 22:31:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
criterion_group!(benches, cave);
|
|
|
|
criterion_main!(benches);
|