From b27370fb4334586cc8b870bc4177c3c5e3f974f6 Mon Sep 17 00:00:00 2001 From: Jondolf Date: Tue, 31 Oct 2023 22:51:02 +0200 Subject: [PATCH] Replace time resources with `Time` and `Time` --- crates/benches_common_3d/src/lib.rs | 6 +- crates/bevy_xpbd_2d/examples/move_marbles.rs | 2 +- src/constraints/mod.rs | 2 +- src/lib.rs | 2 +- src/plugins/collision/broad_phase.rs | 4 +- src/plugins/integrator.rs | 38 +++--- src/plugins/mod.rs | 8 +- src/plugins/{setup.rs => setup/mod.rs} | 130 ++++++++++--------- src/plugins/setup/time.rs | 97 ++++++++++++++ src/plugins/sleeping.rs | 4 +- src/plugins/solver.rs | 53 +++++--- src/resources.rs | 55 +------- 12 files changed, 237 insertions(+), 164 deletions(-) rename src/plugins/{setup.rs => setup/mod.rs} (77%) create mode 100644 src/plugins/setup/time.rs diff --git a/crates/benches_common_3d/src/lib.rs b/crates/benches_common_3d/src/lib.rs index 5875ece5..85397b2d 100644 --- a/crates/benches_common_3d/src/lib.rs +++ b/crates/benches_common_3d/src/lib.rs @@ -1,3 +1,5 @@ +use std::time::Duration; + use bevy::{app::PluginsState, prelude::*}; use bevy_xpbd_3d::prelude::*; use criterion::{measurement::Measurement, BatchSize, Bencher}; @@ -18,7 +20,9 @@ pub fn bench_app( PhysicsPlugins::default(), )); - app.insert_resource(PhysicsTimestep::FixedOnce(1.0 / 60.0)); + app.insert_resource(Time::new_with(Physics::FixedOnce(Duration::from_secs_f64( + 1.0 / 64.0, + )))); setup(&mut app); diff --git a/crates/bevy_xpbd_2d/examples/move_marbles.rs b/crates/bevy_xpbd_2d/examples/move_marbles.rs index 4fadfb0c..0aad215f 100644 --- a/crates/bevy_xpbd_2d/examples/move_marbles.rs +++ b/crates/bevy_xpbd_2d/examples/move_marbles.rs @@ -8,7 +8,7 @@ fn main() { App::new() .add_plugins((DefaultPlugins, XpbdExamplePlugin)) .insert_resource(ClearColor(Color::rgb(0.05, 0.05, 0.1))) - .insert_resource(SubstepCount(6)) + .insert_resource(SubstepCount(5)) .insert_resource(Gravity(Vector::NEG_Y * 1000.0)) .add_systems(Startup, setup) .add_systems(Update, movement) diff --git a/src/constraints/mod.rs b/src/constraints/mod.rs index 3900ab7b..92073295 100644 --- a/src/constraints/mod.rs +++ b/src/constraints/mod.rs @@ -133,7 +133,7 @@ //! ``` //! //! where `w_i` is the inverse mass of particle `i`, `|▽C_i|` is the length of the gradient vector for particle `i`, -//! `α` is the constraint's compliance (inverse of stiffness) and `h` is the [substep size](SubDeltaTime). Using `α = 0` +//! `α` is the constraint's compliance (inverse of stiffness) and `h` is the substep size. Using `α = 0` //! corresponds to infinite stiffness. //! //! The minus sign is there because the gradients point in the direction in which `C` increases the most, diff --git a/src/lib.rs b/src/lib.rs index bffd1d2f..8b54c11b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -393,7 +393,7 @@ //! solve_velocities(particles and bodies) //! ``` //! -//! where `h` is the [substep size](SubDeltaTime), `q` is the [rotation](Rotation) as a quaternion, +//! where `h` is the substep size, `q` is the [rotation](Rotation) as a quaternion, //! `ω` is the [angular velocity](AngularVelocity), `I` is the [angular inertia tensor](`Inertia`) and `τ` is the //! [external torque](ExternalTorque). //! diff --git a/src/plugins/collision/broad_phase.rs b/src/plugins/collision/broad_phase.rs index 15e33239..a7fec4f1 100644 --- a/src/plugins/collision/broad_phase.rs +++ b/src/plugins/collision/broad_phase.rs @@ -68,10 +68,10 @@ fn update_aabb( (&Position, Option<&LinearVelocity>, Option<&AngularVelocity>), With, >, - dt: Res, + dt: Res