aboutsummaryrefslogtreecommitdiff
path: root/benchmarks3d/all_benchmarks3.rs
blob: f35cb8edf608cce4011d16a6919cb21c70c18756 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#![allow(dead_code)]

extern crate nalgebra as na;

#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;

use inflector::Inflector;

use rapier_testbed3d::Testbed;
use std::cmp::Ordering;

mod balls3;
mod boxes3;
mod capsules3;
mod compound3;
mod convex_polyhedron3;
mod heightfield3;
mod joint_ball3;
mod joint_fixed3;
mod joint_prismatic3;
mod joint_revolute3;
mod keva3;
mod pyramid3;
mod stacks3;
mod trimesh3;

enum Command {
    Run(String),
    List,
    RunAll,
}

fn parse_command_line() -> Command {
    let mut args = std::env::args();

    while let Some(arg) = args.next() {
        if &arg[..] == "--example" {
            return Command::Run(args.next().unwrap_or(String::new()));
        } else if &arg[..] == "--list" {
            return Command::List;
        }
    }

    Command::RunAll
}

pub fn main() {
    let command = parse_command_line();

    let mut builders: Vec<(_, fn(&mut Testbed))> = vec![
        ("Balls", balls3::init_world),
        ("Boxes", boxes3::init_world),
        ("Capsules", capsules3::init_world),
        ("Compound", compound3::init_world),
        ("Convex polyhedron", convex_polyhedron3::init_world),
        ("Heightfield", heightfield3::init_world),
        ("Stacks", stacks3::init_world),
        ("Pyramid", pyramid3::init_world),
        ("Trimesh", trimesh3::init_world),
        ("Joint ball", joint_ball3::init_world),
        ("Joint fixed", joint_fixed3::init_world),
        ("Joint revolute", joint_revolute3::init_world),
        ("Joint prismatic", joint_prismatic3::init_world),
        ("Keva tower", keva3::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,
    });

    match command {
        Command::Run(demo) => {
            if let Some(i) = builders
                .iter()
                .position(|builder| builder.0.to_camel_case().as_str() == demo.as_str())
            {
                Testbed::from_builders(0, vec![builders[i]]).run()
            } else {
                eprintln!("Invalid example to run provided: '{}'", demo);
            }
        }
        Command::RunAll => Testbed::from_builders(0, builders).run(),
        Command::List => {
            for builder in &builders {
                println!("{}", builder.0.to_camel_case())
            }
        }
    }
}