diff --git a/bevy_rapier_benches3d/Cargo.toml b/bevy_rapier_benches3d/Cargo.toml index f0e54c6b3..90d066cb9 100644 --- a/bevy_rapier_benches3d/Cargo.toml +++ b/bevy_rapier_benches3d/Cargo.toml @@ -8,9 +8,23 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[features] +visual = [ + "bevy/x11", + "bevy/tonemapping_luts", + "bevy/bevy_core_pipeline", + "bevy/bevy_pbr", + "bevy/bevy_gizmos", + "rapier3d/debug-render", + "bevy_rapier3d/debug-render-3d", +] + [dependencies] rapier3d = { features = ["profiler"], version = "0.25" } -bevy_rapier3d = { version = "0.30", path = "../bevy_rapier3d" } +bevy_rapier3d = { version = "0.30", path = "../bevy_rapier3d", default-features = false, features = [ + "dim3", + "headless", +] } bevy = { version = "0.16.0", default-features = false } [dev-dependencies] diff --git a/bevy_rapier_benches3d/README.md b/bevy_rapier_benches3d/README.md index 170918ce4..0765c0ba5 100644 --- a/bevy_rapier_benches3d/README.md +++ b/bevy_rapier_benches3d/README.md @@ -10,6 +10,13 @@ and outputs them at the end. cargo run --release --bin bench ``` +To visually make sure your benchmarks setup is correct, you can use the feature `visual`, +and edit `bench.rs` to test only the scene you want. + +```sh +cargo run --release --bin bench --features visual +``` + ## cargo bench For short-lived benchmarks based on statistical analysis, diff --git a/bevy_rapier_benches3d/src/bin/bench.rs b/bevy_rapier_benches3d/src/bin/bench.rs index e864541b7..018358f19 100644 --- a/bevy_rapier_benches3d/src/bin/bench.rs +++ b/bevy_rapier_benches3d/src/bin/bench.rs @@ -5,7 +5,7 @@ fn pyramid_1_with_height_2() { } fn pyramid_2_with_height_20() { - custom_bencher(100, |app| setup_pyramids(app, 3, 20)); + custom_bencher(100, |app| setup_pyramids(app, 40, 20)); } fn main() { diff --git a/bevy_rapier_benches3d/src/common.rs b/bevy_rapier_benches3d/src/common.rs index e4775a4cd..99b9120ed 100644 --- a/bevy_rapier_benches3d/src/common.rs +++ b/bevy_rapier_benches3d/src/common.rs @@ -1,7 +1,9 @@ -use bevy::{app::PluginsState, prelude::*, time::TimeUpdateStrategy}; +use bevy::{app::PluginsState, prelude::*}; use bevy_rapier3d::prelude::*; +#[cfg(not(feature = "visual"))] pub fn default_app() -> App { + use bevy::time::TimeUpdateStrategy; let mut app = App::new(); app.add_plugins(( @@ -17,6 +19,33 @@ pub fn default_app() -> App { app } +#[cfg(feature = "visual")] +pub fn default_app() -> App { + use bevy::diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}; + + let mut app = App::new(); + println!("visual mode!"); + app.insert_resource(ClearColor(Color::srgb( + 0xF9 as f32 / 255.0, + 0xF9 as f32 / 255.0, + 0xFF as f32 / 255.0, + ))); + app.add_plugins(( + DefaultPlugins, + RapierPhysicsPlugin::<()>::default(), + RapierDebugRenderPlugin::default(), + FrameTimeDiagnosticsPlugin::default(), + LogDiagnosticsPlugin::default(), + )); + app.add_systems(Startup, |mut commands: Commands| { + commands.spawn(( + Camera3d::default(), + Transform::from_xyz(-30.0, 30.0, 100.0).looking_at(Vec3::new(0.0, 0.0, 0.0), Vec3::Y), + )); + }); + app +} + pub fn wait_app_start(app: &mut App) { while app.plugins_state() != PluginsState::Ready { bevy::tasks::tick_global_task_pools_on_main_thread(); diff --git a/bevy_rapier_benches3d/src/lib.rs b/bevy_rapier_benches3d/src/lib.rs index f12479604..e69f4d150 100644 --- a/bevy_rapier_benches3d/src/lib.rs +++ b/bevy_rapier_benches3d/src/lib.rs @@ -11,9 +11,14 @@ use common::wait_app_start; use bevy::prelude::*; use bevy_rapier3d::plugin::context::RapierContextSimulation; -pub fn custom_bencher(steps: usize, setup: impl Fn(&mut App)) { +pub fn custom_bencher(_steps: usize, setup: impl Fn(&mut App)) { let mut app = default_app(); setup(&mut app); + #[cfg(feature = "visual")] + { + app.run(); + return; + } wait_app_start(&mut app); let mut timer_total = rapier3d::counters::Timer::new(); @@ -21,7 +26,7 @@ pub fn custom_bencher(steps: usize, setup: impl Fn(&mut App)) { let mut rapier_step_times = vec![]; let mut total_update_times = vec![]; timer_total.start(); - for _ in 0..steps { + for _ in 0.._steps { timer_full_update.start(); app.update(); timer_full_update.pause(); diff --git a/bevy_rapier_benches3d/src/pyramids.rs b/bevy_rapier_benches3d/src/pyramids.rs index 363538a9e..63fe648a0 100644 --- a/bevy_rapier_benches3d/src/pyramids.rs +++ b/bevy_rapier_benches3d/src/pyramids.rs @@ -17,7 +17,7 @@ pub fn create_pyramid(commands: &mut Commands, offset: Vect, stack_height: usize commands.spawn(( RigidBody::Dynamic, Transform::from_translation(Vec3::new(x, y, 0.0) + offset), - Collider::cuboid(1.0, 1.0, 1.0), + Collider::cuboid(rad, rad, rad), )); } } @@ -47,6 +47,7 @@ pub fn setup_pyramids(app: &mut App, pyramid_count: usize, stack_height: usize) /* * Create the pyramids */ + for pyramid_index in 0..pyramid_count { let bottomy = rad; create_pyramid(