From da5f47df47c3eedd05b476856b7aedc3051f6aa9 Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Tue, 10 Nov 2020 17:03:28 +0100 Subject: Move the infinite fall debug example to the 3D examples. All our other debug examples were there. --- examples2d/all_examples2.rs | 2 -- examples2d/debug_infinite_fall.rs | 33 --------------------------------- examples3d/all_examples3.rs | 2 ++ examples3d/debug_infinite_fall3.rs | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 35 deletions(-) delete mode 100644 examples2d/debug_infinite_fall.rs create mode 100644 examples3d/debug_infinite_fall3.rs diff --git a/examples2d/all_examples2.rs b/examples2d/all_examples2.rs index 2fe39e5..92606d8 100644 --- a/examples2d/all_examples2.rs +++ b/examples2d/all_examples2.rs @@ -14,7 +14,6 @@ mod add_remove2; mod collision_groups2; mod damping2; mod debug_box_ball2; -mod debug_infinite_fall; mod heightfield2; mod joints2; mod platform2; @@ -65,7 +64,6 @@ pub fn main() { ("Restitution", restitution2::init_world), ("Sensor", sensor2::init_world), ("(Debug) box ball", debug_box_ball2::init_world), - ("(Debug) infinite fall", debug_infinite_fall::init_world), ]; // Lexicographic sort, with stress tests moved at the end of the list. diff --git a/examples2d/debug_infinite_fall.rs b/examples2d/debug_infinite_fall.rs deleted file mode 100644 index 353e695..0000000 --- a/examples2d/debug_infinite_fall.rs +++ /dev/null @@ -1,33 +0,0 @@ -use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier2d::geometry::{ColliderBuilder, ColliderSet}; -use rapier_testbed2d::Testbed; - -pub fn init_world(testbed: &mut Testbed) { - /* - * World - */ - let mut bodies = RigidBodySet::new(); - let mut colliders = ColliderSet::new(); - let joints = JointSet::new(); - - let rad = 1.0; - // Build the dynamic box rigid body. - let rigid_body = RigidBodyBuilder::new_dynamic() - .translation(0.0, 3.0 * rad) - .can_sleep(false) - .build(); - let handle = bodies.insert(rigid_body); - let collider = ColliderBuilder::ball(rad).build(); - colliders.insert(collider, handle, &mut bodies); - - /* - * Set up the testbed. - */ - testbed.set_world(bodies, colliders, joints); - // testbed.look_at(Point2::new(10.0, 10.0, 10.0), Point2::origin()); -} - -fn main() { - let testbed = Testbed::from_builders(0, vec![("Boxes", init_world)]); - testbed.run() -} diff --git a/examples3d/all_examples3.rs b/examples3d/all_examples3.rs index 9c1dffc..d0efa0e 100644 --- a/examples3d/all_examples3.rs +++ b/examples3d/all_examples3.rs @@ -16,6 +16,7 @@ mod compound3; mod damping3; mod debug_boxes3; mod debug_cylinder3; +mod debug_infinite_fall3; mod debug_triangle3; mod debug_trimesh3; mod domino3; @@ -84,6 +85,7 @@ pub fn main() { ("(Debug) triangle", debug_triangle3::init_world), ("(Debug) trimesh", debug_trimesh3::init_world), ("(Debug) cylinder", debug_cylinder3::init_world), + ("(Debug) infinite fall", debug_infinite_fall3::init_world), ]; // Lexicographic sort, with stress tests moved at the end of the list. diff --git a/examples3d/debug_infinite_fall3.rs b/examples3d/debug_infinite_fall3.rs new file mode 100644 index 0000000..d1bda45 --- /dev/null +++ b/examples3d/debug_infinite_fall3.rs @@ -0,0 +1,32 @@ +use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; +use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier_testbed3d::Testbed; + +pub fn init_world(testbed: &mut Testbed) { + /* + * World + */ + let mut bodies = RigidBodySet::new(); + let mut colliders = ColliderSet::new(); + let joints = JointSet::new(); + + let rad = 1.0; + // Build the dynamic box rigid body. + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(0.0, 3.0 * rad, 0.0) + .can_sleep(false) + .build(); + let handle = bodies.insert(rigid_body); + let collider = ColliderBuilder::ball(rad).build(); + colliders.insert(collider, handle, &mut bodies); + + /* + * Set up the testbed. + */ + testbed.set_world(bodies, colliders, joints); +} + +fn main() { + let testbed = Testbed::from_builders(0, vec![("Boxes", init_world)]); + testbed.run() +} -- cgit From 0a5cd9bc6e578f4a2c9aed54035d4591edaa3ef9 Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Tue, 10 Nov 2020 17:04:12 +0100 Subject: SAP: make the update_count a u8. It can only have three values 0,1,2, so storing a whole usize is useless. --- src/geometry/broad_phase_multi_sap.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/geometry/broad_phase_multi_sap.rs b/src/geometry/broad_phase_multi_sap.rs index e2309cf..1f3bed8 100644 --- a/src/geometry/broad_phase_multi_sap.rs +++ b/src/geometry/broad_phase_multi_sap.rs @@ -340,7 +340,7 @@ struct SAPRegion { existing_proxies: BitVec, #[cfg_attr(feature = "serde-serialize", serde(skip))] to_insert: Vec, // Workspace - update_count: usize, + update_count: u8, proxy_count: usize, } -- cgit From 17cfa1edd2556d5e14c3368c9ba8f4e52395a57d Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Tue, 10 Nov 2020 17:04:31 +0100 Subject: SAP: don't serialize workspaces and caches. --- src/geometry/broad_phase_multi_sap.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/geometry/broad_phase_multi_sap.rs b/src/geometry/broad_phase_multi_sap.rs index 1f3bed8..4cea113 100644 --- a/src/geometry/broad_phase_multi_sap.rs +++ b/src/geometry/broad_phase_multi_sap.rs @@ -376,9 +376,7 @@ impl SAPRegion { assert_eq!(old.proxy_count, 0); assert!(old.to_insert.is_empty()); debug_assert!(!old.existing_proxies.any()); - for axis in old.axes.iter() { - assert!(axis.endpoints.len() == 2); // Account for sentinels - } + assert!(old.axes.iter().all(|ax| ax.endpoints.len() == 2)); old } @@ -422,6 +420,7 @@ impl SAPRegion { if self.update_count > 0 { // Update endpoints. let mut deleted = 0; + for dim in 0..DIM { self.axes[dim].update_endpoints(dim, proxies, reporting); deleted += self.axes[dim].delete_out_of_bounds_proxies(&mut self.existing_proxies); @@ -460,8 +459,10 @@ pub struct BroadPhase { regions: HashMap, SAPRegion>, removed_colliders: Option>, deleted_any: bool, - region_pool: Vec, - points_to_remove: Vec>, // Workspace + #[cfg_attr(feature = "serde-serialize", serde(skip))] + region_pool: Vec, // To avoid repeated allocations. + #[cfg_attr(feature = "serde-serialize", serde(skip))] + regions_to_remove: Vec>, // Workspace // We could think serializing this workspace is useless. // It turns out is is important to serialize at least its capacity // and restore this capacity when deserializing the hashmap. @@ -555,7 +556,7 @@ impl BroadPhase { proxies: Proxies::new(), regions: HashMap::default(), region_pool: Vec::new(), - points_to_remove: Vec::new(), + regions_to_remove: Vec::new(), reporting: HashMap::default(), deleted_any: false, } @@ -658,6 +659,7 @@ impl BroadPhase { let regions = &mut self.regions; let pool = &mut self.region_pool; + #[cfg(feature = "dim2")] for i in start.x..=end.x { for j in start.y..=end.y { @@ -691,14 +693,14 @@ impl BroadPhase { for (point, region) in &mut self.regions { region.update(&self.proxies, &mut self.reporting); if region.proxy_count == 0 { - self.points_to_remove.push(*point); + self.regions_to_remove.push(*point); } } // Remove all the empty regions and store them in the region pool let regions = &mut self.regions; self.region_pool.extend( - self.points_to_remove + self.regions_to_remove .drain(..) .map(|p| regions.remove(&p).unwrap()), ); -- cgit