Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve capacity handling for ColliderSet, RigidBodySet. #726

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
- The region key has been replaced by an i64 in the f64 version of rapier, increasing the range before panics occur.
- Fix `BroadphaseMultiSap` not being able to serialize correctly with serde_json.

### Added

- `RigidBodySet` and `ColliderSet` have a new constructor `with_capacity`.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this point to this PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally yes, but it's rare to have the PR link, I'm adding it arbitrarily on bigger/breaking/difficult PRs


### Modified

- `InteractionGroups` default value for `memberships` is now `GROUP_1` (#706)
Expand Down
8 changes: 8 additions & 0 deletions src/dynamics/rigid_body_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RigidBodyHandle> {
std::mem::take(&mut self.modified_bodies)
}
Expand Down
11 changes: 11 additions & 0 deletions src/geometry/collider_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ColliderHandle> {
std::mem::take(&mut self.modified_colliders)
}
Expand Down