diff options
| author | Crozet Sébastien <developer@crozet.re> | 2020-09-28 10:19:49 +0200 |
|---|---|---|
| committer | Crozet Sébastien <developer@crozet.re> | 2020-09-28 10:24:42 +0200 |
| commit | e7466e2f6923d24e987a34f8ebaf839346af8d4e (patch) | |
| tree | fa25c9c94bf4cd18a84f1a8c2bea327cd875af5f | |
| parent | 0829ed10ac33bd3697fe2f92dd6b8f55df1094b4 (diff) | |
| download | rapier-e7466e2f6923d24e987a34f8ebaf839346af8d4e.tar.gz rapier-e7466e2f6923d24e987a34f8ebaf839346af8d4e.tar.bz2 rapier-e7466e2f6923d24e987a34f8ebaf839346af8d4e.zip | |
Move 2D benchmarks into their own directory/crate.
| -rw-r--r-- | Cargo.toml | 2 | ||||
| -rw-r--r-- | benchmarks2d/Cargo.toml | 27 | ||||
| -rw-r--r-- | benchmarks2d/all_benchmarks2.rs | 82 | ||||
| -rw-r--r-- | benchmarks2d/balls2.rs (renamed from examples2d/balls2.rs) | 0 | ||||
| -rw-r--r-- | benchmarks2d/boxes2.rs (renamed from examples2d/boxes2.rs) | 0 | ||||
| -rw-r--r-- | benchmarks2d/capsules2.rs (renamed from examples2d/capsules2.rs) | 0 | ||||
| -rw-r--r-- | benchmarks2d/heightfield2.rs | 72 | ||||
| -rw-r--r-- | benchmarks2d/joint_ball2.rs (renamed from examples2d/stress_joint_ball2.rs) | 0 | ||||
| -rw-r--r-- | benchmarks2d/joint_fixed2.rs (renamed from examples2d/stress_joint_fixed2.rs) | 0 | ||||
| -rw-r--r-- | benchmarks2d/joint_prismatic2.rs (renamed from examples2d/stress_joint_prismatic2.rs) | 0 | ||||
| -rw-r--r-- | benchmarks2d/pyramid2.rs | 60 | ||||
| -rw-r--r-- | examples2d/all_examples2.rs | 19 | ||||
| -rw-r--r-- | examples2d/heightfield2.rs | 8 | ||||
| -rw-r--r-- | examples2d/joints2.rs | 8 | ||||
| -rw-r--r-- | examples2d/platform2.rs (renamed from examples2d/kinematic2.rs) | 2 | ||||
| -rw-r--r-- | examples2d/pyramid2.rs | 6 |
16 files changed, 256 insertions, 30 deletions
@@ -1,5 +1,5 @@ [workspace] -members = [ "build/rapier2d", "build/rapier_testbed2d", "examples2d", +members = [ "build/rapier2d", "build/rapier_testbed2d", "examples2d", "benchmarks2d", "build/rapier3d", "build/rapier_testbed3d", "examples3d", "benchmarks3d" ] [patch.crates-io] diff --git a/benchmarks2d/Cargo.toml b/benchmarks2d/Cargo.toml new file mode 100644 index 0000000..b1ee8db --- /dev/null +++ b/benchmarks2d/Cargo.toml @@ -0,0 +1,27 @@ +[package] +name = "rapier-benchmarks-2d" +version = "0.1.0" +authors = [ "Sébastien Crozet <developer@crozet.re>" ] +edition = "2018" + +[features] +parallel = [ "rapier2d/parallel", "rapier_testbed2d/parallel" ] +simd-stable = [ "rapier2d/simd-stable" ] +simd-nightly = [ "rapier2d/simd-nightly" ] +other-backends = [ "rapier_testbed2d/other-backends" ] +enhanced-determinism = [ "rapier2d/enhanced-determinism" ] + +[dependencies] +rand = "0.7" +Inflector = "0.11" +nalgebra = "0.22" + +[dependencies.rapier_testbed2d] +path = "../build/rapier_testbed2d" + +[dependencies.rapier2d] +path = "../build/rapier2d" + +[[bin]] +name = "all_benchmarks2" +path = "./all_benchmarks2.rs"
\ No newline at end of file diff --git a/benchmarks2d/all_benchmarks2.rs b/benchmarks2d/all_benchmarks2.rs new file mode 100644 index 0000000..9a7a607 --- /dev/null +++ b/benchmarks2d/all_benchmarks2.rs @@ -0,0 +1,82 @@ +#![allow(dead_code)] + +extern crate nalgebra as na; + +#[cfg(target_arch = "wasm32")] +use wasm_bindgen::prelude::*; + +use inflector::Inflector; + +use rapier_testbed2d::Testbed; +use std::cmp::Ordering; + +mod balls2; +mod boxes2; +mod capsules2; +mod heightfield2; +mod joint_ball2; +mod joint_fixed2; +mod joint_prismatic2; +mod pyramid2; + +fn demo_name_from_command_line() -> Option<String> { + let mut args = std::env::args(); + + while let Some(arg) = args.next() { + if &arg[..] == "--example" { + return args.next(); + } + } + + None +} + +#[cfg(any(target_arch = "wasm32", target_arch = "asmjs"))] +fn demo_name_from_url() -> Option<String> { + None + // let window = stdweb::web::window(); + // let hash = window.location()?.search().ok()?; + // Some(hash[1..].to_string()) +} + +#[cfg(not(any(target_arch = "wasm32", target_arch = "asmjs")))] +fn demo_name_from_url() -> Option<String> { + None +} + +#[cfg_attr(target_arch = "wasm32", wasm_bindgen(start))] +pub fn main() { + let demo = demo_name_from_command_line() + .or_else(|| demo_name_from_url()) + .unwrap_or(String::new()) + .to_camel_case(); + + let mut builders: Vec<(_, fn(&mut Testbed))> = vec![ + ("Balls", balls2::init_world), + ("Boxes", boxes2::init_world), + ("Capsules", capsules2::init_world), + ("Heightfield", heightfield2::init_world), + ("Pyramid", pyramid2::init_world), + ("(Stress test) joint ball", joint_ball2::init_world), + ("(Stress test) joint fixed", joint_fixed2::init_world), + ( + "(Stress test) joint prismatic", + joint_prismatic2::init_world, + ), + ]; + + // Lexicographic sort, with stress tests moved at the end of the list. + builders.sort_by(|a, b| match (a.0.starts_with("("), b.0.starts_with("(")) { + (true, true) | (false, false) => a.0.cmp(b.0), + (true, false) => Ordering::Greater, + (false, true) => Ordering::Less, + }); + + let i = builders + .iter() + .position(|builder| builder.0.to_camel_case().as_str() == demo.as_str()) + .unwrap_or(0); + let testbed = Testbed::from_builders(i, builders); + + testbed.run() +} diff --git a/examples2d/balls2.rs b/benchmarks2d/balls2.rs index 6791505..6791505 100644 --- a/examples2d/balls2.rs +++ b/benchmarks2d/balls2.rs diff --git a/examples2d/boxes2.rs b/benchmarks2d/boxes2.rs index 4fb9bf3..4fb9bf3 100644 --- a/examples2d/boxes2.rs +++ b/benchmarks2d/boxes2.rs diff --git a/examples2d/capsules2.rs b/benchmarks2d/capsules2.rs index 76633bc..76633bc 100644 --- a/examples2d/capsules2.rs +++ b/benchmarks2d/capsules2.rs diff --git a/benchmarks2d/heightfield2.rs b/benchmarks2d/heightfield2.rs new file mode 100644 index 0000000..95fed6c --- /dev/null +++ b/benchmarks2d/heightfield2.rs @@ -0,0 +1,72 @@ +use na::{DVector, Point2, Vector2}; +use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; +use rapier2d::geometry::{ColliderBuilder, ColliderSet}; +use rapier_testbed2d::Testbed; + +pub fn init_world(testbed: &mut Testbed) { + /* + * World + */ + let mut bodies = RigidBodySet::new(); + let mut colliders = ColliderSet::new(); + let joints = JointSet::new(); + + /* + * Ground + */ + let ground_size = Vector2::new(50.0, 1.0); + let nsubdivs = 2000; + + let heights = DVector::from_fn(nsubdivs + 1, |i, _| { + if i == 0 || i == nsubdivs { + 80.0 + } else { + (i as f32 * ground_size.x / (nsubdivs as f32)).cos() * 2.0 + } + }); + + let rigid_body = RigidBodyBuilder::new_static().build(); + let handle = bodies.insert(rigid_body); + let collider = ColliderBuilder::heightfield(heights, ground_size).build(); + colliders.insert(collider, handle, &mut bodies); + + /* + * Create the cubes + */ + let num = 26; + let rad = 0.5; + + let shift = rad * 2.0; + let centerx = shift * (num / 2) as f32; + let centery = shift / 2.0; + + for i in 0..num { + for j in 0usize..num * 5 { + let x = i as f32 * shift - centerx; + let y = j as f32 * shift + centery + 3.0; + + // Build the rigid body. + let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build(); + let handle = bodies.insert(rigid_body); + + if j % 2 == 0 { + let collider = ColliderBuilder::cuboid(rad, rad).build(); + colliders.insert(collider, handle, &mut bodies); + } else { + let collider = ColliderBuilder::ball(rad).build(); + colliders.insert(collider, handle, &mut bodies); + } + } + } + + /* + * Set up the testbed. + */ + testbed.set_world(bodies, colliders, joints); + testbed.look_at(Point2::new(0.0, 50.0), 10.0); +} + +fn main() { + let testbed = Testbed::from_builders(0, vec![("Heightfield", init_world)]); + testbed.run() +} diff --git a/examples2d/stress_joint_ball2.rs b/benchmarks2d/joint_ball2.rs index ecfdc47..ecfdc47 100644 --- a/examples2d/stress_joint_ball2.rs +++ b/benchmarks2d/joint_ball2.rs diff --git a/examples2d/stress_joint_fixed2.rs b/benchmarks2d/joint_fixed2.rs index 32a219e..32a219e 100644 --- a/examples2d/stress_joint_fixed2.rs +++ b/benchmarks2d/joint_fixed2.rs diff --git a/examples2d/stress_joint_prismatic2.rs b/benchmarks2d/joint_prismatic2.rs index 91ef48e..91ef48e 100644 --- a/examples2d/stress_joint_prismatic2.rs +++ b/benchmarks2d/joint_prismatic2.rs diff --git a/benchmarks2d/pyramid2.rs b/benchmarks2d/pyramid2.rs new file mode 100644 index 0000000..e6a715b --- /dev/null +++ b/benchmarks2d/pyramid2.rs @@ -0,0 +1,60 @@ +use na::Point2; +use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; +use rapier2d::geometry::{ColliderBuilder, ColliderSet}; +use rapier_testbed2d::Testbed; + +pub fn init_world(testbed: &mut Testbed) { + /* + * World + */ + let mut bodies = RigidBodySet::new(); + let mut colliders = ColliderSet::new(); + let joints = JointSet::new(); + + /* + * Ground + */ + let ground_size = 100.0; + let ground_thickness = 1.0; + + let rigid_body = RigidBodyBuilder::new_static().build(); + let ground_handle = bodies.insert(rigid_body); + let collider = ColliderBuilder::cuboid(ground_size, ground_thickness).build(); + colliders.insert(collider, ground_handle, &mut bodies); + + /* + * Create the cubes + */ + let num = 100; + let rad = 0.5; + + let shift = rad * 2.0; + let centerx = shift * (num as f32) / 2.0; + let centery = shift / 2.0 + ground_thickness + rad * 1.5; + + for i in 0usize..num { + for j in i..num { + let fj = j as f32; + let fi = i as f32; + let x = (fi * shift / 2.0) + (fj - fi) * shift - centerx; + let y = fi * shift + centery; + + // Build the rigid body. + let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build(); + let handle = bodies.insert(rigid_body); + let collider = ColliderBuilder::cuboid(rad, rad).build(); + colliders.insert(collider, handle, &mut bodies); + } + } + + /* + * Set up the testbed. + */ + testbed.set_world(bodies, colliders, joints); + testbed.look_at(Point2::new(0.0, 2.5), 5.0); +} + +fn main() { + let testbed = Testbed::from_builders(0, vec![("Balls", init_world)]); + testbed.run() +} diff --git a/examples2d/all_examples2.rs b/examples2d/all_examples2.rs index 836dcbc..0ebef88 100644 --- a/examples2d/all_examples2.rs +++ b/examples2d/all_examples2.rs @@ -11,18 +11,12 @@ use rapier_testbed2d::Testbed; use std::cmp::Ordering; mod add_remove2; -mod balls2; -mod boxes2; -mod capsules2; mod debug_box_ball2; mod heightfield2; mod joints2; -mod kinematic2; +mod platform2; mod pyramid2; mod sensor2; -mod stress_joint_ball2; -mod stress_joint_fixed2; -mod stress_joint_prismatic2; fn demo_name_from_command_line() -> Option<String> { let mut args = std::env::args(); @@ -58,21 +52,12 @@ pub fn main() { let mut builders: Vec<(_, fn(&mut Testbed))> = vec![ ("Add remove", add_remove2::init_world), - ("Balls", balls2::init_world), - ("Boxes", boxes2::init_world), - ("Capsules", capsules2::init_world), ("Heightfield", heightfield2::init_world), ("Joints", joints2::init_world), - ("Kinematic", kinematic2::init_world), + ("Platform", platform2::init_world), ("Pyramid", pyramid2::init_world), ("Sensor", sensor2::init_world), ("(Debug) box ball", debug_box_ball2::init_world), - ("(Stress test) joint ball", stress_joint_ball2::init_world), - ("(Stress test) joint fixed", stress_joint_fixed2::init_world), - ( - "(Stress test) joint prismatic", - stress_joint_prismatic2::init_world, - ), ]; // Lexicographic sort, with stress tests moved at the end of the list. diff --git a/examples2d/heightfield2.rs b/examples2d/heightfield2.rs index 95fed6c..f5ddff9 100644 --- a/examples2d/heightfield2.rs +++ b/examples2d/heightfield2.rs @@ -19,7 +19,7 @@ pub fn init_world(testbed: &mut Testbed) { let heights = DVector::from_fn(nsubdivs + 1, |i, _| { if i == 0 || i == nsubdivs { - 80.0 + 8.0 } else { (i as f32 * ground_size.x / (nsubdivs as f32)).cos() * 2.0 } @@ -33,7 +33,7 @@ pub fn init_world(testbed: &mut Testbed) { /* * Create the cubes */ - let num = 26; + let num = 20; let rad = 0.5; let shift = rad * 2.0; @@ -41,7 +41,7 @@ pub fn init_world(testbed: &mut Testbed) { let centery = shift / 2.0; for i in 0..num { - for j in 0usize..num * 5 { + for j in 0usize..num { let x = i as f32 * shift - centerx; let y = j as f32 * shift + centery + 3.0; @@ -63,7 +63,7 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point2::new(0.0, 50.0), 10.0); + testbed.look_at(Point2::new(0.0, 0.0), 10.0); } fn main() { diff --git a/examples2d/joints2.rs b/examples2d/joints2.rs index 888c48b..d1a1942 100644 --- a/examples2d/joints2.rs +++ b/examples2d/joints2.rs @@ -19,8 +19,8 @@ pub fn init_world(testbed: &mut Testbed) { // in order to be able to compare rapier with Box2D, // we set it to 0.4. let rad = 0.4; - let numi = 100; // Num vertical nodes. - let numk = 100; // Num horizontal nodes. + let numi = 10; // Num vertical nodes. + let numk = 10; // Num horizontal nodes. let shift = 1.0; let mut body_handles = Vec::new(); @@ -30,7 +30,7 @@ pub fn init_world(testbed: &mut Testbed) { let fk = k as f32; let fi = i as f32; - let status = if i == 0 && (k % 4 == 0 || k == numk - 1) { + let status = if i == 0 && k == 0 { BodyStatus::Static } else { BodyStatus::Dynamic @@ -66,7 +66,7 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point2::new(numk as f32 * rad, numi as f32 * -rad), 5.0); + testbed.look_at(Point2::new(numk as f32 * rad, numi as f32 * -rad), 20.0); } fn main() { diff --git a/examples2d/kinematic2.rs b/examples2d/platform2.rs index 9540f17..fd836a3 100644 --- a/examples2d/kinematic2.rs +++ b/examples2d/platform2.rs @@ -35,7 +35,7 @@ pub fn init_world(testbed: &mut Testbed) { let centery = shift / 2.0 + 3.04; for i in 0usize..num { - for j in 0usize..num * 50 { + for j in 0usize..num { let x = i as f32 * shift - centerx; let y = j as f32 * shift + centery; diff --git a/examples2d/pyramid2.rs b/examples2d/pyramid2.rs index e6a715b..689e9c0 100644 --- a/examples2d/pyramid2.rs +++ b/examples2d/pyramid2.rs @@ -14,7 +14,7 @@ pub fn init_world(testbed: &mut Testbed) { /* * Ground */ - let ground_size = 100.0; + let ground_size = 10.0; let ground_thickness = 1.0; let rigid_body = RigidBodyBuilder::new_static().build(); @@ -25,7 +25,7 @@ pub fn init_world(testbed: &mut Testbed) { /* * Create the cubes */ - let num = 100; + let num = 10; let rad = 0.5; let shift = rad * 2.0; @@ -51,7 +51,7 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point2::new(0.0, 2.5), 5.0); + testbed.look_at(Point2::new(0.0, 2.5), 20.0); } fn main() { |
