Skip to content

Commit

Permalink
Merge pull request #184 from Anders429/0.6.1
Browse files Browse the repository at this point in the history
0.6.1.
  • Loading branch information
Anders429 authored Mar 22, 2023
2 parents c094685 + 6f762d7 commit 6bb5738
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

## 0.6.1 - 2023-03-21
### Fixed
- Querying with empty component views no longer iterates endlessly. It now iterates once for each entity filtered, despite no components being viewed.

## 0.6.0 - 2023-03-20
### Added
- `resource` module containing types related to resources.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "brood"
version = "0.6.0"
version = "0.6.1"
authors = ["Anders Evensen"]
edition = "2021"
rust-version = "1.65.0"
Expand Down
4 changes: 2 additions & 2 deletions src/query/result/reshape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ pub trait Reshape<R, I> {
fn reshape(self) -> R;
}

impl Reshape<iter::Repeat<view::Null>, Null> for iter::Repeat<view::Null> {
fn reshape(self) -> iter::Repeat<view::Null> {
impl Reshape<iter::Take<iter::Repeat<view::Null>>, Null> for iter::Take<iter::Repeat<view::Null>> {
fn reshape(self) -> iter::Take<iter::Repeat<view::Null>> {
self
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/query/result/sealed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub trait Results {
fn into_iterator(self) -> Self::Iterator;
}

impl Results for iter::Repeat<view::Null> {
impl Results for iter::Take<iter::Repeat<view::Null>> {
type View = view::Null;
type Iterator = Self;

Expand Down
2 changes: 1 addition & 1 deletion src/query/view/sealed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub trait ViewsSealed<'a> {
}

impl<'a> ViewsSealed<'a> for Null {
type Results = iter::Repeat<Null>;
type Results = iter::Take<iter::Repeat<Null>>;
}

impl<'a, V, W> ViewsSealed<'a> for (V, W)
Expand Down
4 changes: 2 additions & 2 deletions src/registry/sealed/par_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ where
impl<'a> CanonicalParViews<'a, view::Null, Null> for registry::Null {
unsafe fn par_view<R>(
_columns: &[(*mut u8, usize)],
_length: usize,
length: usize,
_archetype_identifier: archetype::identifier::Iter<R>,
) -> <view::Null as ParViewsSeal<'a>>::ParResults
where
R: Registry,
{
iter::repeatn(view::Null, usize::MAX)
iter::repeatn(view::Null, length)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/registry/sealed/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ where
impl<'a> CanonicalViews<'a, view::Null, Null> for registry::Null {
unsafe fn view<R>(
_columns: &[(*mut u8, usize)],
_length: usize,
length: usize,
_archetype_identifier: archetype::identifier::Iter<R>,
) -> <view::Null as ViewsSealed<'a>>::Results
where
R: Registry,
{
iter::repeat(view::Null)
iter::repeat(view::Null).take(length)
}

unsafe fn view_one<R>(
Expand Down
29 changes: 29 additions & 0 deletions src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1436,6 +1436,20 @@ mod tests {
assert_eq!(b, &mut B('a'));
}

#[test]
fn query_empty() {
let mut world = World::<Registry>::new();

world.insert(entity!(B('a'), A(1)));
world.insert(entity!(A(2)));
world.insert(entity!(B('b')));
world.insert(entity!());

let count = world.query(Query::<Views!()>::new()).iter.count();

assert_eq!(count, 4);
}

#[cfg(feature = "rayon")]
#[test]
fn par_query_refs() {
Expand Down Expand Up @@ -1640,6 +1654,21 @@ mod tests {
assert_eq!(b, &mut B('a'));
}

#[cfg(feature = "rayon")]
#[test]
fn par_query_empty() {
let mut world = World::<Registry>::new();

world.insert(entity!(B('a'), A(1)));
world.insert(entity!(A(2)));
world.insert(entity!(B('b')));
world.insert(entity!());

let count = world.par_query(Query::<Views!()>::new()).iter.count();

assert_eq!(count, 4);
}

#[test]
fn system_refs() {
struct TestSystem;
Expand Down

0 comments on commit 6bb5738

Please sign in to comment.