Fix regressions introduced by the merge with master.

This commit is contained in:
Crozet Sébastien
2021-01-22 16:33:31 +01:00
parent aa838279a6
commit 99c2184e13
3 changed files with 50 additions and 28 deletions

View File

@@ -14,7 +14,6 @@ pub mod plugin;
pub struct RunState { pub struct RunState {
#[cfg(feature = "parallel")] #[cfg(feature = "parallel")]
pub thread_pool: rapier::rayon::ThreadPool, pub thread_pool: rapier::rayon::ThreadPool,
#[cfg(feature = "parallel")]
pub num_threads: usize, pub num_threads: usize,
pub timestep_id: usize, pub timestep_id: usize,
pub time: f32, pub time: f32,
@@ -24,6 +23,8 @@ impl RunState {
pub fn new() -> Self { pub fn new() -> Self {
#[cfg(feature = "parallel")] #[cfg(feature = "parallel")]
let num_threads = num_cpus::get_physical(); let num_threads = num_cpus::get_physical();
#[cfg(not(feature = "parallel"))]
let num_threads = 1;
#[cfg(feature = "parallel")] #[cfg(feature = "parallel")]
let thread_pool = rapier::rayon::ThreadPoolBuilder::new() let thread_pool = rapier::rayon::ThreadPoolBuilder::new()
@@ -34,7 +35,6 @@ impl RunState {
Self { Self {
#[cfg(feature = "parallel")] #[cfg(feature = "parallel")]
thread_pool: thread_pool, thread_pool: thread_pool,
#[cfg(feature = "parallel")]
num_threads, num_threads,
timestep_id: 0, timestep_id: 0,
time: 0.0, time: 0.0,
@@ -111,6 +111,10 @@ impl Harness {
&mut self.physics.integration_parameters &mut self.physics.integration_parameters
} }
pub fn clear_callbacks(&mut self) {
self.callbacks.clear();
}
pub fn physics_state_mut(&mut self) -> &mut PhysicsState { pub fn physics_state_mut(&mut self) -> &mut PhysicsState {
&mut self.physics &mut self.physics
} }

View File

@@ -25,7 +25,6 @@ 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::{Isometry, Vector}; use rapier::math::{Isometry, Vector};
use rapier::pipeline::{ChannelEventCollector, PhysicsPipeline, QueryPipeline};
#[cfg(all(feature = "dim2", feature = "other-backends"))] #[cfg(all(feature = "dim2", feature = "other-backends"))]
use crate::box2d_backend::Box2dWorld; use crate::box2d_backend::Box2dWorld;
@@ -284,11 +283,11 @@ impl Testbed {
|| self.state.selected_backend == PHYSX_BACKEND_TWO_FRICTION_DIR || self.state.selected_backend == PHYSX_BACKEND_TWO_FRICTION_DIR
{ {
self.physx = Some(PhysxWorld::from_rapier( self.physx = Some(PhysxWorld::from_rapier(
physics.gravity, self.harness.physics.gravity,
&physics.integration_parameters, &self.harness.physics.integration_parameters,
&physics.bodies, &self.harness.physics.bodies,
&physics.colliders, &self.harness.physics.colliders,
&physics.joints, &self.harness.physics.joints,
self.state.selected_backend == PHYSX_BACKEND_TWO_FRICTION_DIR, self.state.selected_backend == PHYSX_BACKEND_TWO_FRICTION_DIR,
self.harness.state.num_threads, self.harness.state.num_threads,
)); ));
@@ -299,10 +298,10 @@ impl Testbed {
{ {
if self.state.selected_backend == NPHYSICS_BACKEND { if self.state.selected_backend == NPHYSICS_BACKEND {
self.nphysics = Some(NPhysicsWorld::from_rapier( self.nphysics = Some(NPhysicsWorld::from_rapier(
physics.gravity, self.harness.physics.gravity,
&physics.bodies, &self.harness.physics.bodies,
&physics.colliders, &self.harness.physics.colliders,
&physics.joints, &self.harness.physics.joints,
)); ));
} }
} }
@@ -501,7 +500,7 @@ impl Testbed {
// println!("Step"); // println!("Step");
self.physx.as_mut().unwrap().step( self.physx.as_mut().unwrap().step(
&mut self.harness.physics.pipeline.counters, &mut self.harness.physics.pipeline.counters,
&physics.integration_parameters, &self.harness.physics.integration_parameters,
); );
self.physx.as_mut().unwrap().sync( self.physx.as_mut().unwrap().sync(
&mut self.harness.physics.bodies, &mut self.harness.physics.bodies,
@@ -515,7 +514,7 @@ impl Testbed {
if self.state.selected_backend == NPHYSICS_BACKEND { if self.state.selected_backend == NPHYSICS_BACKEND {
self.nphysics.as_mut().unwrap().step( self.nphysics.as_mut().unwrap().step(
&mut self.harness.physics.pipeline.counters, &mut self.harness.physics.pipeline.counters,
&physics.integration_parameters, &self.harness.physics.integration_parameters,
); );
self.nphysics.as_mut().unwrap().sync( self.nphysics.as_mut().unwrap().sync(
&mut self.harness.physics.bodies, &mut self.harness.physics.bodies,
@@ -986,7 +985,7 @@ impl Testbed {
); );
if let Some((handle, _)) = hit { if let Some((handle, _)) = hit {
let collider = &self.physics.colliders[handle]; let collider = &physics.colliders[handle];
if physics.bodies[collider.parent()].is_dynamic() { if physics.bodies[collider.parent()].is_dynamic() {
self.state.highlighted_body = Some(collider.parent()); self.state.highlighted_body = Some(collider.parent());
for node in self.graphics.body_nodes_mut(collider.parent()).unwrap() { for node in self.graphics.body_nodes_mut(collider.parent()).unwrap() {
@@ -1073,9 +1072,28 @@ impl State for Testbed {
.action_flags .action_flags
.set(TestbedActionFlags::EXAMPLE_CHANGED, false); .set(TestbedActionFlags::EXAMPLE_CHANGED, false);
self.clear(window); self.clear(window);
self.harness.clear_callbacks();
if self.state.selected_example != prev_example { if self.state.selected_example != prev_example {
self.harness.physics.integration_parameters = IntegrationParameters::default(); self.harness.physics.integration_parameters = IntegrationParameters::default();
if cfg!(feature = "dim3")
&& (self.state.selected_backend == PHYSX_BACKEND_PATCH_FRICTION
|| self.state.selected_backend == PHYSX_BACKEND_TWO_FRICTION_DIR)
{
std::mem::swap(
&mut self
.harness
.physics
.integration_parameters
.max_velocity_iterations,
&mut self
.harness
.physics
.integration_parameters
.max_position_iterations,
)
}
} }
self.builders[self.state.selected_example].1(self); self.builders[self.state.selected_example].1(self);
@@ -1269,13 +1287,13 @@ impl State for Testbed {
{ {
// println!("Step"); // println!("Step");
self.physx.as_mut().unwrap().step( self.physx.as_mut().unwrap().step(
&mut physics.pipeline.counters, &mut self.harness.physics.pipeline.counters,
&physics.integration_parameters, &self.harness.physics.integration_parameters,
);
self.physx.as_mut().unwrap().sync(
&mut self.harness.physics.bodies,
&mut self.harness.physics.colliders,
); );
self.physx
.as_mut()
.unwrap()
.sync(&mut physics.bodies, &mut physics.colliders);
} }
} }
@@ -1283,13 +1301,13 @@ impl State for Testbed {
{ {
if self.state.selected_backend == NPHYSICS_BACKEND { if self.state.selected_backend == NPHYSICS_BACKEND {
self.nphysics.as_mut().unwrap().step( self.nphysics.as_mut().unwrap().step(
&mut physics.pipeline.counters, &mut self.harness.physics.pipeline.counters,
&physics.integration_parameters, &self.harness.physics.integration_parameters,
);
self.nphysics.as_mut().unwrap().sync(
&mut self.harness.physics.bodies,
&mut self.harness.physics.colliders,
); );
self.nphysics
.as_mut()
.unwrap()
.sync(&mut physics.bodies, &mut physics.colliders);
} }
} }

View File

@@ -99,7 +99,7 @@ impl TestbedUi {
window: &mut Window, window: &mut Window,
integration_parameters: &mut IntegrationParameters, integration_parameters: &mut IntegrationParameters,
state: &mut TestbedState, state: &mut TestbedState,
run_state: &mut RunState, _run_state: &mut RunState,
) { ) {
let ui_root = window.conrod_ui().window; let ui_root = window.conrod_ui().window;
let mut ui = window.conrod_ui_mut().set_widgets(); let mut ui = window.conrod_ui_mut().set_widgets();