Add empty CollisionGroups ctor, and option to replace masks entirely
This should make it easier to create `CollisionGroups` values from scratch
using bitmasks. This is a further extension of
@@ -59,6 +59,16 @@ impl CollisionGroups {
}
}
+ /// Creates a new `CollisionGroups` that disables interactions with everything.
+ #[inline]
+ pub fn empty() -> CollisionGroups {
+ CollisionGroups {
+ membership: NO_GROUP,
+ whitelist: NO_GROUP,
+ blacklist: NO_GROUP,
+ }
+ }
+
/// Returns a copy of this object, updated with a new set of membership groups.
///
/// # Examples
@@ -172,6 +182,18 @@ impl CollisionGroups {
self
}
+ #[inline]
+ /// Replaces the membership with a mask of bits where each bit index represent a group
+ pub fn with_membership_by_mask(mut self, group_mask: u32) -> CollisionGroups {
+ assert!(
+ group_mask <= ALL_GROUPS,
+ "There are at most 30 groups indexed from 0 to 29 (included)."
+ );
+
+ self.membership = group_mask;
+ self
+ }
+
#[inline]
/// adds this entity to this entity whitelist by a mask of bits where each bit index represent a group
pub fn add_whitelist_by_mask(mut self, group_mask: u32) -> CollisionGroups {
@@ -186,6 +208,18 @@ impl CollisionGroups {
self
}
+ #[inline]
+ /// Replaces the whitelist with a mask of bits where each bit index represent a group
+ pub fn with_whitelist_by_mask(mut self, group_mask: u32) -> CollisionGroups {
+ assert!(
+ group_mask <= ALL_GROUPS,
+ "There are at most 30 groups indexed from 0 to 29 (included)."
+ );
+
+ self.whitelist = group_mask;
+ self
+ }
+
#[inline]
/// adds this entity to this entity blacklist by a mask of bits where each bit index represent a group
pub fn add_blacklist_by_mask(mut self, group_mask: u32) -> CollisionGroups {
@@ -200,6 +234,18 @@ impl CollisionGroups {
self
}
+ #[inline]
+ /// Replaces the blacklist with a mask of bits where each bit index represent a group
+ pub fn with_blacklist_by_mask(mut self, group_mask: u32) -> CollisionGroups {
+ assert!(
+ group_mask <= ALL_GROUPS,
+ "There are at most 30 groups indexed from 0 to 29 (included)."
+ );
+
+ self.blacklist = group_mask;
+ self
+ }
+
/// Adds or removes this entity from the given group.
#[inline]
pub fn modify_membership(&mut self, group_id: usize, add: bool) {
