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

Replace check with mask, deprecate check #326

Merged
merged 1 commit into from
Dec 27, 2017
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
7 changes: 7 additions & 0 deletions src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,16 @@ where
/// This bitset *can* be invalidated here if insertion or removal methods
/// are used after the call to get the `BitSet`, so there is no guarantee
/// that the storage will have a component for a specific entity.
#[deprecated(since = "0.11", note = "Use `Storage::mask` and then clone the bitset it returns instead. This method hides a rather expensive operation which could be handled better in other ways.")]
pub fn check(&self) -> BitSet {
self.data.mask.clone()
}

/// Returns a reference to the bitset of this storage which allows filtering
/// by the component type without actually getting the component.
pub fn mask(&self) -> &BitSet {
&self.data.mask
}
}

/// An entry to a storage which has a component associated to the entity.
Expand Down
14 changes: 7 additions & 7 deletions src/storage/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ mod test {
}

#[test]
fn check_storage() {
fn storage_mask() {
use join::Join;

let mut w = World::new();
Expand All @@ -697,19 +697,19 @@ mod test {
s1.insert(Entity::new(i, Generation::new(1)), CMarker);
}

for (entity, id) in (&*w.entities(), &s1.check()).join() {
for (entity, id) in (&*w.entities(), s1.mask().clone()).join() {
if id % 3 == 0 {
let _ = s1.get_mut(entity);
} else {
let _ = s1.get(entity);
}
}

assert_eq!((&s1.check()).join().count(), 50);
assert_eq!((s1.mask()).join().count(), 50);
}

#[test]
fn par_check_storage() {
fn par_storage_mask() {
use join::ParJoin;
use rayon::iter::ParallelIterator;

Expand All @@ -721,7 +721,7 @@ mod test {
s1.insert(Entity::new(i, Generation::new(1)), CMarker);
}

assert_eq!((&s1.check()).par_join().count(), 50);
assert_eq!((s1.mask()).par_join().count(), 50);
}

#[test]
Expand Down Expand Up @@ -751,7 +751,7 @@ mod test {
(&mut s1).open().1.clear_flags();

// Cleared flags
for (entity, _) in (entities, &s1.check()).join() {
for (entity, _) in (entities, s1.mask()).join() {
assert!(!s1.open().1.flagged(&entity));
}

Expand All @@ -761,7 +761,7 @@ mod test {
c1.0 += c2.0;
}

for (entity, _) in (entities, &s1.check()).join() {
for (entity, _) in (entities, s1.mask()).join() {
// Should only be modified if the entity had both components
// Which means only half of them should have it.
if s1.open().1.flagged(&entity) {
Expand Down