diff options
| author | rezural <rezural@protonmail.com> | 2020-12-24 20:16:11 +1100 |
|---|---|---|
| committer | rezural <rezural@protonmail.com> | 2020-12-24 20:16:11 +1100 |
| commit | b1d0dc006d39faeb4a3ef85acc62f2981d26a85b (patch) | |
| tree | 593a90452b61564362dacd7bcec4b55c98b5a002 | |
| parent | baccfff4cde4e70f79bef1d061a4bdea9a845546 (diff) | |
| download | rapier-b1d0dc006d39faeb4a3ef85acc62f2981d26a85b.tar.gz rapier-b1d0dc006d39faeb4a3ef85acc62f2981d26a85b.tar.bz2 rapier-b1d0dc006d39faeb4a3ef85acc62f2981d26a85b.zip | |
cargo fmt
| -rw-r--r-- | src_testbed/harness/mod.rs | 20 | ||||
| -rw-r--r-- | src_testbed/testbed.rs | 72 |
2 files changed, 61 insertions, 31 deletions
diff --git a/src_testbed/harness/mod.rs b/src_testbed/harness/mod.rs index dd49fe6..c6f682c 100644 --- a/src_testbed/harness/mod.rs +++ b/src_testbed/harness/mod.rs @@ -20,7 +20,7 @@ impl RunState { #[cfg(feature = "parallel")] thread_pool: rapier::rayon::ThreadPool, timestep_id: 0, - time: 0.0 + time: 0.0, } } } @@ -117,9 +117,7 @@ impl Harness { self.plugins.push(Box::new(plugin)); } - pub fn add_callback< - F: FnMut(&mut PhysicsState, &PhysicsEvents, &RunState, f32) + 'static, - >( + pub fn add_callback<F: FnMut(&mut PhysicsState, &PhysicsEvents, &RunState, f32) + 'static>( &mut self, callback: F, ) { @@ -170,11 +168,21 @@ impl Harness { } for f in &mut self.callbacks { - f(&mut self.physics, &self.events, &self.state, self.state.time) + f( + &mut self.physics, + &self.events, + &self.state, + self.state.time, + ) } for plugin in &mut self.plugins { - plugin.run_callbacks(&mut self.physics, &self.events, &self.state, self.state.time) + plugin.run_callbacks( + &mut self.physics, + &self.events, + &self.state, + self.state.time, + ) } self.events.poll_all(); diff --git a/src_testbed/testbed.rs b/src_testbed/testbed.rs index 46cb64f..b7a6974 100644 --- a/src_testbed/testbed.rs +++ b/src_testbed/testbed.rs @@ -25,15 +25,15 @@ use rapier::geometry::{ColliderHandle, ColliderSet, NarrowPhase}; #[cfg(feature = "dim3")] use rapier::geometry::{InteractionGroups, Ray}; use rapier::math::Vector; -use rapier::pipeline::{ChannelEventCollector}; +use rapier::pipeline::ChannelEventCollector; #[cfg(all(feature = "dim2", feature = "other-backends"))] use crate::box2d_backend::Box2dWorld; +use crate::harness::{Harness, RunState}; #[cfg(feature = "other-backends")] use crate::nphysics_backend::NPhysicsWorld; #[cfg(all(feature = "dim3", feature = "other-backends"))] use crate::physx_backend::PhysxWorld; -use crate::harness::{Harness, RunState}; const RAPIER_BACKEND: usize = 0; const NPHYSICS_BACKEND: usize = 1; @@ -141,8 +141,9 @@ pub struct Testbed { nphysics: Option<NPhysicsWorld>, } -type Callbacks = - Vec<Box<dyn FnMut(&mut Window, &mut PhysicsState, &PhysicsEvents, &mut GraphicsManager, &RunState)>>; +type Callbacks = Vec< + Box<dyn FnMut(&mut Window, &mut PhysicsState, &PhysicsEvents, &mut GraphicsManager, &RunState)>, +>; impl Testbed { pub fn new_empty() -> Testbed { @@ -271,10 +272,10 @@ impl Testbed { joints: JointSet, gravity: Vector<f32>, ) { - println!("Num bodies: {}", bodies.len()); println!("Num joints: {}", joints.len()); - self.harness.set_world_with_gravity(bodies, colliders, joints, gravity); + self.harness + .set_world_with_gravity(bodies, colliders, joints, gravity); self.state .action_flags @@ -416,7 +417,8 @@ impl Testbed { } pub fn add_callback< - F: FnMut(&mut Window, &mut PhysicsState, &PhysicsEvents, &mut GraphicsManager, &RunState) + 'static, + F: FnMut(&mut Window, &mut PhysicsState, &PhysicsEvents, &mut GraphicsManager, &RunState) + + 'static, >( &mut self, callback: F, @@ -463,11 +465,23 @@ impl Testbed { && (backend_id == PHYSX_BACKEND_PATCH_FRICTION || backend_id == PHYSX_BACKEND_TWO_FRICTION_DIR) { - self.harness.physics.integration_parameters.max_velocity_iterations = 1; - self.harness.physics.integration_parameters.max_position_iterations = 4; + self.harness + .physics + .integration_parameters + .max_velocity_iterations = 1; + self.harness + .physics + .integration_parameters + .max_position_iterations = 4; } else { - self.harness.physics.integration_parameters.max_velocity_iterations = 4; - self.harness.physics.integration_parameters.max_position_iterations = 1; + self.harness + .physics + .integration_parameters + .max_velocity_iterations = 4; + self.harness + .physics + .integration_parameters + .max_position_iterations = 1; } // Init world. (builder.1)(&mut self); @@ -581,7 +595,9 @@ impl Testbed { .set(TestbedActionFlags::EXAMPLE_CHANGED, true), WindowEvent::Key(Key::C, Action::Release, _) => { // Delete 1 collider of 10% of the remaining dynamic bodies. - let mut colliders: Vec<_> = self.harness.physics + let mut colliders: Vec<_> = self + .harness + .physics .bodies .iter() .filter(|e| e.1.is_dynamic()) @@ -592,11 +608,11 @@ impl Testbed { let num_to_delete = (colliders.len() / 10).max(1); for to_delete in &colliders[..num_to_delete] { - self - .harness - .physics - .colliders - .remove(to_delete[0], &mut self.harness.physics.bodies, true); + self.harness.physics.colliders.remove( + to_delete[0], + &mut self.harness.physics.bodies, + true, + ); } } WindowEvent::Key(Key::D, Action::Release, _) => { @@ -623,11 +639,11 @@ impl Testbed { let joints: Vec<_> = self.harness.physics.joints.iter().map(|e| e.0).collect(); let num_to_delete = (joints.len() / 10).max(1); for to_delete in &joints[..num_to_delete] { - self - .harness - .physics - .joints - .remove(*to_delete, &mut self.harness.physics.bodies, true); + self.harness.physics.joints.remove( + *to_delete, + &mut self.harness.physics.bodies, + true, + ); } } WindowEvent::CursorPos(x, y, _) => { @@ -1103,7 +1119,6 @@ impl State for Testbed { } } - if self .state .action_flags @@ -1184,7 +1199,10 @@ impl State for Testbed { .contains(TestbedStateFlags::SUB_STEPPING) != self.state.flags.contains(TestbedStateFlags::SUB_STEPPING) { - self.harness.physics.integration_parameters.return_after_ccd_substep = + self.harness + .physics + .integration_parameters + .return_after_ccd_substep = self.state.flags.contains(TestbedStateFlags::SUB_STEPPING); } @@ -1289,7 +1307,11 @@ impl State for Testbed { for plugin in &mut self.plugins { { - plugin.run_callbacks(window, &mut self.harness.physics, self.harness.state.time); + plugin.run_callbacks( + window, + &mut self.harness.physics, + self.harness.state.time, + ); } } |
