cargo fmt

This commit is contained in:
rezural
2020-12-24 20:16:11 +11:00
parent baccfff4cd
commit b1d0dc006d
2 changed files with 61 additions and 31 deletions

View File

@@ -20,7 +20,7 @@ impl RunState {
#[cfg(feature = "parallel")] #[cfg(feature = "parallel")]
thread_pool: rapier::rayon::ThreadPool, thread_pool: rapier::rayon::ThreadPool,
timestep_id: 0, timestep_id: 0,
time: 0.0 time: 0.0,
} }
} }
} }
@@ -117,9 +117,7 @@ impl Harness {
self.plugins.push(Box::new(plugin)); self.plugins.push(Box::new(plugin));
} }
pub fn add_callback< pub fn add_callback<F: FnMut(&mut PhysicsState, &PhysicsEvents, &RunState, f32) + 'static>(
F: FnMut(&mut PhysicsState, &PhysicsEvents, &RunState, f32) + 'static,
>(
&mut self, &mut self,
callback: F, callback: F,
) { ) {
@@ -170,11 +168,21 @@ impl Harness {
} }
for f in &mut self.callbacks { 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 { 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(); self.events.poll_all();

View File

@@ -25,15 +25,15 @@ use rapier::geometry::{ColliderHandle, ColliderSet, NarrowPhase};
#[cfg(feature = "dim3")] #[cfg(feature = "dim3")]
use rapier::geometry::{InteractionGroups, Ray}; use rapier::geometry::{InteractionGroups, Ray};
use rapier::math::Vector; use rapier::math::Vector;
use rapier::pipeline::{ChannelEventCollector}; use rapier::pipeline::ChannelEventCollector;
#[cfg(all(feature = "dim2", feature = "other-backends"))] #[cfg(all(feature = "dim2", feature = "other-backends"))]
use crate::box2d_backend::Box2dWorld; use crate::box2d_backend::Box2dWorld;
use crate::harness::{Harness, RunState};
#[cfg(feature = "other-backends")] #[cfg(feature = "other-backends")]
use crate::nphysics_backend::NPhysicsWorld; use crate::nphysics_backend::NPhysicsWorld;
#[cfg(all(feature = "dim3", feature = "other-backends"))] #[cfg(all(feature = "dim3", feature = "other-backends"))]
use crate::physx_backend::PhysxWorld; use crate::physx_backend::PhysxWorld;
use crate::harness::{Harness, RunState};
const RAPIER_BACKEND: usize = 0; const RAPIER_BACKEND: usize = 0;
const NPHYSICS_BACKEND: usize = 1; const NPHYSICS_BACKEND: usize = 1;
@@ -141,8 +141,9 @@ pub struct Testbed {
nphysics: Option<NPhysicsWorld>, nphysics: Option<NPhysicsWorld>,
} }
type Callbacks = type Callbacks = Vec<
Vec<Box<dyn FnMut(&mut Window, &mut PhysicsState, &PhysicsEvents, &mut GraphicsManager, &RunState)>>; Box<dyn FnMut(&mut Window, &mut PhysicsState, &PhysicsEvents, &mut GraphicsManager, &RunState)>,
>;
impl Testbed { impl Testbed {
pub fn new_empty() -> Testbed { pub fn new_empty() -> Testbed {
@@ -271,10 +272,10 @@ impl Testbed {
joints: JointSet, joints: JointSet,
gravity: Vector<f32>, gravity: Vector<f32>,
) { ) {
println!("Num bodies: {}", bodies.len()); println!("Num bodies: {}", bodies.len());
println!("Num joints: {}", joints.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 self.state
.action_flags .action_flags
@@ -416,7 +417,8 @@ impl Testbed {
} }
pub fn add_callback< 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, &mut self,
callback: F, callback: F,
@@ -463,11 +465,23 @@ impl Testbed {
&& (backend_id == PHYSX_BACKEND_PATCH_FRICTION && (backend_id == PHYSX_BACKEND_PATCH_FRICTION
|| backend_id == PHYSX_BACKEND_TWO_FRICTION_DIR) || backend_id == PHYSX_BACKEND_TWO_FRICTION_DIR)
{ {
self.harness.physics.integration_parameters.max_velocity_iterations = 1; self.harness
self.harness.physics.integration_parameters.max_position_iterations = 4; .physics
.integration_parameters
.max_velocity_iterations = 1;
self.harness
.physics
.integration_parameters
.max_position_iterations = 4;
} else { } else {
self.harness.physics.integration_parameters.max_velocity_iterations = 4; self.harness
self.harness.physics.integration_parameters.max_position_iterations = 1; .physics
.integration_parameters
.max_velocity_iterations = 4;
self.harness
.physics
.integration_parameters
.max_position_iterations = 1;
} }
// Init world. // Init world.
(builder.1)(&mut self); (builder.1)(&mut self);
@@ -581,7 +595,9 @@ impl Testbed {
.set(TestbedActionFlags::EXAMPLE_CHANGED, true), .set(TestbedActionFlags::EXAMPLE_CHANGED, true),
WindowEvent::Key(Key::C, Action::Release, _) => { WindowEvent::Key(Key::C, Action::Release, _) => {
// Delete 1 collider of 10% of the remaining dynamic bodies. // 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 .bodies
.iter() .iter()
.filter(|e| e.1.is_dynamic()) .filter(|e| e.1.is_dynamic())
@@ -592,11 +608,11 @@ impl Testbed {
let num_to_delete = (colliders.len() / 10).max(1); let num_to_delete = (colliders.len() / 10).max(1);
for to_delete in &colliders[..num_to_delete] { for to_delete in &colliders[..num_to_delete] {
self self.harness.physics.colliders.remove(
.harness to_delete[0],
.physics &mut self.harness.physics.bodies,
.colliders true,
.remove(to_delete[0], &mut self.harness.physics.bodies, true); );
} }
} }
WindowEvent::Key(Key::D, Action::Release, _) => { 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 joints: Vec<_> = self.harness.physics.joints.iter().map(|e| e.0).collect();
let num_to_delete = (joints.len() / 10).max(1); let num_to_delete = (joints.len() / 10).max(1);
for to_delete in &joints[..num_to_delete] { for to_delete in &joints[..num_to_delete] {
self self.harness.physics.joints.remove(
.harness *to_delete,
.physics &mut self.harness.physics.bodies,
.joints true,
.remove(*to_delete, &mut self.harness.physics.bodies, true); );
} }
} }
WindowEvent::CursorPos(x, y, _) => { WindowEvent::CursorPos(x, y, _) => {
@@ -1103,7 +1119,6 @@ impl State for Testbed {
} }
} }
if self if self
.state .state
.action_flags .action_flags
@@ -1184,7 +1199,10 @@ impl State for Testbed {
.contains(TestbedStateFlags::SUB_STEPPING) .contains(TestbedStateFlags::SUB_STEPPING)
!= self.state.flags.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); self.state.flags.contains(TestbedStateFlags::SUB_STEPPING);
} }
@@ -1289,7 +1307,11 @@ impl State for Testbed {
for plugin in &mut self.plugins { 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,
);
} }
} }