Files
rapier/examples2d/all_examples2.rs
Robert Hrusecky bcec54ef31 Merge branch 'master' into infinite_fall_memory
Fix merge conflict resulting from "axii" spelling correction
2020-10-29 18:09:41 -05:00

82 lines
2.2 KiB
Rust

#![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 add_remove2;
mod collision_groups2;
mod debug_box_ball2;
mod debug_infinite_fall;
mod heightfield2;
mod joints2;
mod platform2;
mod pyramid2;
mod sensor2;
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![
("Add remove", add_remove2::init_world),
("Collision groups", collision_groups2::init_world),
("Heightfield", heightfield2::init_world),
("Joints", joints2::init_world),
("Platform", platform2::init_world),
("Pyramid", pyramid2::init_world),
("Sensor", sensor2::init_world),
("(Debug) box ball", debug_box_ball2::init_world),
("(Debug) infinite fall", debug_infinite_fall::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()
}