feat: add ColliderSet::get_pair_mut and RigidBodySet::get_pair_mut

This commit is contained in:
Sébastien Crozet
2025-05-23 18:12:23 +02:00
committed by Sébastien Crozet
parent ef3662b3b1
commit a3d983fbe9
2 changed files with 46 additions and 0 deletions

View File

@@ -186,6 +186,29 @@ impl RigidBodySet {
Some(result)
}
/// Gets a mutable reference to the two rigid-bodies with the given handles.
///
/// If `handle1 == handle2`, only the first returned value will be `Some`.
#[cfg(not(feature = "dev-remove-slow-accessors"))]
pub fn get_pair_mut(
&mut self,
handle1: RigidBodyHandle,
handle2: RigidBodyHandle,
) -> (Option<&mut RigidBody>, Option<&mut RigidBody>) {
if handle1 == handle2 {
(self.get_mut(handle1), None)
} else {
let (mut rb1, mut rb2) = self.bodies.get2_mut(handle1.0, handle2.0);
if let Some(rb1) = rb1.as_deref_mut() {
self.modified_bodies.push_once(handle1, rb1);
}
if let Some(rb2) = rb2.as_deref_mut() {
self.modified_bodies.push_once(handle2, rb2);
}
(rb1, rb2)
}
}
pub(crate) fn get_mut_internal(&mut self, handle: RigidBodyHandle) -> Option<&mut RigidBody> {
self.bodies.get_mut(handle.0)
}

View File

@@ -299,6 +299,29 @@ impl ColliderSet {
Some(result)
}
/// Gets a mutable reference to the two colliders with the given handles.
///
/// If `handle1 == handle2`, only the first returned value will be `Some`.
#[cfg(not(feature = "dev-remove-slow-accessors"))]
pub fn get_pair_mut(
&mut self,
handle1: ColliderHandle,
handle2: ColliderHandle,
) -> (Option<&mut Collider>, Option<&mut Collider>) {
if handle1 == handle2 {
(self.get_mut(handle1), None)
} else {
let (mut co1, mut co2) = self.colliders.get2_mut(handle1.0, handle2.0);
if let Some(co1) = co1.as_deref_mut() {
self.modified_colliders.push_once(handle1, co1);
}
if let Some(co2) = co2.as_deref_mut() {
self.modified_colliders.push_once(handle2, co2);
}
(co1, co2)
}
}
pub(crate) fn index_mut_internal(&mut self, handle: ColliderHandle) -> &mut Collider {
&mut self.colliders[handle.0]
}