From e7e196d9f949a03ef997f0adc629344c3696b1ff Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Mon, 16 Sep 2024 21:45:14 +0700 Subject: Improve capacity handling for `ColliderSet`, `RigidBodySet`. (#726) These allow an application to reduce the cost of reallocation when they know that a large number of colliders or rigid bodies will be created. --- src/dynamics/rigid_body_set.rs | 8 ++++++++ src/geometry/collider_set.rs | 11 +++++++++++ 2 files changed, 19 insertions(+) (limited to 'src') diff --git a/src/dynamics/rigid_body_set.rs b/src/dynamics/rigid_body_set.rs index 2ef91be..3145300 100644 --- a/src/dynamics/rigid_body_set.rs +++ b/src/dynamics/rigid_body_set.rs @@ -43,6 +43,14 @@ impl RigidBodySet { } } + /// Create a new set of rigid bodies, with an initial capacity. + pub fn with_capacity(capacity: usize) -> Self { + RigidBodySet { + bodies: Arena::with_capacity(capacity), + modified_bodies: Vec::with_capacity(capacity), + } + } + pub(crate) fn take_modified(&mut self) -> Vec { std::mem::take(&mut self.modified_bodies) } diff --git a/src/geometry/collider_set.rs b/src/geometry/collider_set.rs index 3934472..7a2b6aa 100644 --- a/src/geometry/collider_set.rs +++ b/src/geometry/collider_set.rs @@ -23,6 +23,17 @@ impl ColliderSet { } } + /// Create a new set of colliders, with an initial capacity + /// for the set of colliders as well as the tracking of + /// modified colliders. + pub fn with_capacity(capacity: usize) -> Self { + ColliderSet { + colliders: Arena::with_capacity(capacity), + modified_colliders: Vec::with_capacity(capacity), + removed_colliders: Vec::new(), + } + } + pub(crate) fn take_modified(&mut self) -> Vec { std::mem::take(&mut self.modified_colliders) } -- cgit