From fb20d72ee29de9311a81aec6eb9f02fd2aa35fc4 Mon Sep 17 00:00:00 2001 From: Sébastien Crozet Date: Sun, 20 Feb 2022 12:55:00 +0100 Subject: Joint API and joint motors improvements --- src_testbed/harness/mod.rs | 38 ++++++++++++++++++++++++++++++++------ src_testbed/testbed.rs | 2 +- src_testbed/ui.rs | 15 ++++++++------- 3 files changed, 41 insertions(+), 14 deletions(-) (limited to 'src_testbed') diff --git a/src_testbed/harness/mod.rs b/src_testbed/harness/mod.rs index beebe80..59cccc3 100644 --- a/src_testbed/harness/mod.rs +++ b/src_testbed/harness/mod.rs @@ -16,32 +16,58 @@ pub mod plugin; pub struct RunState { #[cfg(feature = "parallel")] pub thread_pool: rapier::rayon::ThreadPool, - pub num_threads: usize, + #[cfg(feature = "parallel")] + num_threads: usize, pub timestep_id: usize, pub time: f32, } impl RunState { + #[cfg(feature = "parallel")] pub fn new() -> Self { - #[cfg(feature = "parallel")] let num_threads = num_cpus::get_physical(); - #[cfg(not(feature = "parallel"))] - let num_threads = 1; - #[cfg(feature = "parallel")] let thread_pool = rapier::rayon::ThreadPoolBuilder::new() .num_threads(num_threads) .build() .unwrap(); Self { - #[cfg(feature = "parallel")] thread_pool: thread_pool, num_threads, timestep_id: 0, time: 0.0, } } + + #[cfg(not(feature = "parallel"))] + pub fn new() -> Self { + Self { + timestep_id: 0, + time: 0.0, + } + } + + #[cfg(feature = "parallel")] + pub fn num_threads(&self) -> usize { + self.num_threads + } + + #[cfg(not(feature = "parallel"))] + pub fn num_threads(&self) -> usize { + 1 + } + + #[cfg(feature = "parallel")] + pub fn set_num_threads(&mut self, num_threads: usize) { + if self.num_threads != num_threads { + self.thread_pool = rapier::rayon::ThreadPoolBuilder::new() + .num_threads(num_threads) + .build() + .unwrap(); + self.num_threads = num_threads; + } + } } pub struct Harness { diff --git a/src_testbed/testbed.rs b/src_testbed/testbed.rs index 1a4181b..87a9ca6 100644 --- a/src_testbed/testbed.rs +++ b/src_testbed/testbed.rs @@ -535,7 +535,7 @@ impl<'a, 'b, 'c, 'd, 'e, 'f> Testbed<'a, 'b, 'c, 'd, 'e, 'f> { &self.harness.physics.impulse_joints, &self.harness.physics.multibody_joints, self.state.selected_backend == PHYSX_BACKEND_TWO_FRICTION_DIR, - self.harness.state.num_threads, + self.harness.state.num_threads(), )); } } diff --git a/src_testbed/ui.rs b/src_testbed/ui.rs index 788cc8f..bed8f85 100644 --- a/src_testbed/ui.rs +++ b/src_testbed/ui.rs @@ -101,32 +101,32 @@ pub fn update_ui(ui_context: &EguiContext, state: &mut TestbedState, harness: &m || state.selected_backend == PHYSX_BACKEND_TWO_FRICTION_DIR { ui.add( - Slider::new(&mut integration_parameters.max_velocity_iterations, 0..=200) + Slider::new(&mut integration_parameters.max_velocity_iterations, 1..=200) .text("pos. iters."), ); ui.add( Slider::new( &mut integration_parameters.max_stabilization_iterations, - 0..=200, + 1..=200, ) .text("vel. iters."), ); } else { ui.add( - Slider::new(&mut integration_parameters.max_velocity_iterations, 0..=200) + Slider::new(&mut integration_parameters.max_velocity_iterations, 1..=200) .text("vel. rest. iters."), ); ui.add( Slider::new( &mut integration_parameters.max_velocity_friction_iterations, - 0..=200, + 1..=200, ) .text("vel. frict. iters."), ); ui.add( Slider::new( &mut integration_parameters.max_stabilization_iterations, - 0..=200, + 1..=200, ) .text("vel. stab. iters."), ); @@ -134,10 +134,11 @@ pub fn update_ui(ui_context: &EguiContext, state: &mut TestbedState, harness: &m #[cfg(feature = "parallel")] { + let mut num_threads = harness.state.num_threads(); ui.add( - Slider::new(&mut harness.state.num_threads, 1..=num_cpus::get_physical()) - .text("num. threads"), + Slider::new(&mut num_threads, 1..=num_cpus::get_physical()).text("num. threads"), ); + harness.state.set_num_threads(num_threads); } ui.add( Slider::new(&mut integration_parameters.max_ccd_substeps, 0..=10).text("CCD substeps"), -- cgit