Skip to content

Commit a68d0c6

Browse files
authored
Expose ColliderSet::{take_modified, take_removed} (dimforge#887)
These are practically necessary when working without a PhysicsPipeline
1 parent 57c4e91 commit a68d0c6

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed

src/data/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
pub use self::arena::{Arena, Index};
44
pub use self::coarena::Coarena;
5-
pub(crate) use self::modified_objects::{HasModifiedFlag, ModifiedObjects};
5+
pub use self::modified_objects::{HasModifiedFlag, ModifiedObjects};
66

77
pub mod arena;
88
mod coarena;

src/data/modified_objects.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,19 @@ use std::ops::Deref;
99
/// be done for internal engine usage (like the physics pipeline).
1010
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
1111
#[derive(Clone, Debug)]
12-
pub(crate) struct ModifiedObjects<Handle, Object>(Vec<Handle>, PhantomData<Object>);
12+
pub struct ModifiedObjects<Handle, Object>(Vec<Handle>, PhantomData<Object>);
1313

1414
impl<Handle, Object> Default for ModifiedObjects<Handle, Object> {
1515
fn default() -> Self {
1616
Self(Vec::new(), PhantomData)
1717
}
1818
}
1919

20-
pub(crate) trait HasModifiedFlag {
20+
/// Objects that internally track a flag indicating whether they've been modified
21+
pub trait HasModifiedFlag {
22+
/// Whether the object has been modified
2123
fn has_modified_flag(&self) -> bool;
24+
/// Mark object as modified
2225
fn set_modified_flag(&mut self);
2326
}
2427

@@ -30,6 +33,7 @@ impl<Handle, Object> Deref for ModifiedObjects<Handle, Object> {
3033
}
3134

3235
impl<Handle, Object: HasModifiedFlag> ModifiedObjects<Handle, Object> {
36+
/// Preallocate memory for `capacity` handles
3337
pub fn with_capacity(capacity: usize) -> Self {
3438
Self(Vec::with_capacity(capacity), PhantomData)
3539
}

src/geometry/collider_set.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use crate::geometry::{Collider, ColliderChanges, ColliderHandle, ColliderParent}
55
use crate::math::Isometry;
66
use std::ops::{Index, IndexMut};
77

8-
pub(crate) type ModifiedColliders = ModifiedObjects<ColliderHandle, Collider>;
8+
/// A set of modified colliders
9+
pub type ModifiedColliders = ModifiedObjects<ColliderHandle, Collider>;
910

1011
impl HasModifiedFlag for Collider {
1112
#[inline]
@@ -71,15 +72,32 @@ impl ColliderSet {
7172
}
7273
}
7374

74-
pub(crate) fn take_modified(&mut self) -> ModifiedColliders {
75+
/// Fetch the set of colliders modified since the last call to
76+
/// `take_modified`
77+
///
78+
/// Provides a value that can be passed to the `modified_colliders` argument
79+
/// of [`BroadPhaseBvh::update`](crate::geometry::BroadPhaseBvh::update).
80+
///
81+
/// Should not be used if this [`ColliderSet`] will be used with a
82+
/// [`PhysicsPipeline`](crate::pipeline::PhysicsPipeline), which handles
83+
/// broadphase updates automatically.
84+
pub fn take_modified(&mut self) -> ModifiedColliders {
7585
std::mem::take(&mut self.modified_colliders)
7686
}
7787

7888
pub(crate) fn set_modified(&mut self, modified: ModifiedColliders) {
7989
self.modified_colliders = modified;
8090
}
8191

82-
pub(crate) fn take_removed(&mut self) -> Vec<ColliderHandle> {
92+
/// Fetch the set of colliders removed since the last call to `take_removed`
93+
///
94+
/// Provides a value that can be passed to the `removed_colliders` argument
95+
/// of [`BroadPhaseBvh::update`](crate::geometry::BroadPhaseBvh::update).
96+
///
97+
/// Should not be used if this [`ColliderSet`] will be used with a
98+
/// [`PhysicsPipeline`](crate::pipeline::PhysicsPipeline), which handles
99+
/// broadphase updates automatically.
100+
pub fn take_removed(&mut self) -> Vec<ColliderHandle> {
83101
std::mem::take(&mut self.removed_colliders)
84102
}
85103

src/geometry/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pub use self::broad_phase_bvh::{BroadPhaseBvh, BvhOptimizationStrategy};
44
pub use self::broad_phase_pair_event::{BroadPhasePairEvent, ColliderPair};
55
pub use self::collider::{Collider, ColliderBuilder};
66
pub use self::collider_components::*;
7-
pub use self::collider_set::ColliderSet;
7+
pub use self::collider_set::{ColliderSet, ModifiedColliders};
88
pub use self::contact_pair::{
99
ContactData, ContactManifoldData, ContactPair, IntersectionPair, SimdSolverContact,
1010
SolverContact, SolverFlags,
@@ -211,7 +211,6 @@ impl ContactForceEvent {
211211
}
212212
}
213213

214-
pub(crate) use self::collider_set::ModifiedColliders;
215214
pub(crate) use self::narrow_phase::ContactManifoldIndex;
216215
pub use parry::shape::*;
217216

0 commit comments

Comments
 (0)