Skip to content

Commit

Permalink
Add navigation benchmarks.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGrimsey committed Oct 1, 2023
1 parent 9b0cf38 commit 8704f61
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,8 @@ criterion = { version = "0.5" }

[[bench]]
name = "simple_geometry"
harness = false

[[bench]]
name = "simple_navigation"
harness = false
108 changes: 108 additions & 0 deletions benches/simple_navigation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
use bevy::{prelude::{UVec2, Transform, Vec3}, utils::HashMap};
use criterion::{Criterion, criterion_group, criterion_main, black_box};
use oxidized_navigation::{build_tile_sync, NavMeshSettings, conversion::{GeometryToConvert, GeometryCollection, ColliderType}, tiles::{NavMeshTile, NavMeshTiles}, query::find_path};
use parry3d::shape::Cuboid;


fn generate_single_primitive_geometry(nav_mesh_settings: &NavMeshSettings) -> NavMeshTile {
let tile_coord = UVec2::new(0, 0);
let heightfields = vec![];


let geometry_collections = vec![
GeometryCollection {
transform: Transform::from_xyz(0.0, 0.0, 0.0),
geometry_to_convert: GeometryToConvert::Collider(ColliderType::Cuboid(Cuboid::new(Vec3::new(10.0, 0.2, 10.0).into()))),
area: None
}
];

build_tile_sync(geometry_collections, tile_coord, heightfields, nav_mesh_settings)
}

fn generate_many_primitive_geometry(nav_mesh_settings: &NavMeshSettings) -> NavMeshTile {
let tile_coord = UVec2::new(0, 0);
let heightfields = vec![];

let geometry_collections = vec![
GeometryCollection {
transform: Transform::from_xyz(0.0, 0.0, 0.0),
geometry_to_convert: GeometryToConvert::Collider(ColliderType::Cuboid(Cuboid::new(Vec3::new(10.0, 0.2, 10.0).into()))),
area: None
},
GeometryCollection {
transform: Transform::from_xyz(5.0, 1.0, 0.0),
geometry_to_convert: GeometryToConvert::Collider(ColliderType::Cuboid(Cuboid::new(Vec3::new(1.0, 1.0, 1.0).into()))),
area: None
},
GeometryCollection {
transform: Transform::from_xyz(-5.0, 1.0, 2.0),
geometry_to_convert: GeometryToConvert::Collider(ColliderType::Cuboid(Cuboid::new(Vec3::new(4.0, 1.0, 1.0).into()))),
area: None
},
GeometryCollection {
transform: Transform::from_xyz(-2.5, 2.0, 2.0),
geometry_to_convert: GeometryToConvert::Collider(ColliderType::Cuboid(Cuboid::new(Vec3::new(1.0, 2.0, 1.0).into()))),
area: None
},
GeometryCollection {
transform: Transform::from_xyz(-2.5, 2.0, -2.0),
geometry_to_convert: GeometryToConvert::Collider(ColliderType::Cuboid(Cuboid::new(Vec3::new(1.0, 2.0, 1.0).into()))),
area: None
}
];

build_tile_sync(geometry_collections, tile_coord, heightfields, nav_mesh_settings)
}

fn criterion_benchmark(c: &mut Criterion) {
let nav_mesh_settings = NavMeshSettings {
cell_width: 0.25,
cell_height: 0.1,
tile_width: 100,
world_half_extents: 12.5,
world_bottom_bound: -100.0,
max_traversable_slope_radians: (40.0_f32 - 0.1).to_radians(),
walkable_height: 20,
walkable_radius: 1,
step_height: 3,
min_region_area: 100,
merge_region_area: 500,
max_contour_simplification_error: 1.1,
max_edge_length: 80,
max_tile_generation_tasks: Some(1),
};

let simple_tiles = NavMeshTiles {
tiles: vec![(UVec2::ZERO, generate_single_primitive_geometry(&nav_mesh_settings))].into_iter().collect(),
tile_generations: HashMap::default(),
};
let many_tiles = NavMeshTiles {
tiles: vec![(UVec2::ZERO, generate_many_primitive_geometry(&nav_mesh_settings))].into_iter().collect(),
tile_generations: HashMap::default(),
};

c.bench_function("Simple Navigation", |b| b.iter(||
black_box(find_path(
&simple_tiles,
&nav_mesh_settings,
Vec3::new(5.0, 0.0, 5.0),
Vec3::new(0.0, 0.0, 0.0),
None,
None
))
));
c.bench_function("Many Navigation", |b| b.iter(||
black_box(find_path(
&many_tiles,
&nav_mesh_settings,
Vec3::new(5.0, 0.0, 5.0),
Vec3::new(0.0, 0.0, 0.0),
None,
None
))
));
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
4 changes: 2 additions & 2 deletions src/tiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ impl NavMeshTile {
/// Call [crate::query::find_path] to run pathfinding algorithm.
#[derive(Default)]
pub struct NavMeshTiles {
pub(super) tiles: HashMap<UVec2, NavMeshTile>,
pub(super) tile_generations: HashMap<UVec2, u64>,
pub tiles: HashMap<UVec2, NavMeshTile>,
pub tile_generations: HashMap<UVec2, u64>,
}

impl NavMeshTiles {
Expand Down

0 comments on commit 8704f61

Please sign in to comment.