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

[Merged by Bors] - Add a method iter_combinations on query to iterate over combinations of query results #1763

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
2d5712b
implement k_iter and k_iter_mut on queries
Frizi Mar 26, 2021
7a9eb9c
prevent overflow in size_hint for large number of permutations in Que…
Frizi Mar 26, 2021
0f0c83e
add n_body example that uses Query::k_iter_mut
Frizi Mar 27, 2021
cf24a73
handle K=0 case in permutation iterator
Frizi Mar 27, 2021
ab324cc
move n_body example to ecs folder
Frizi Mar 27, 2021
1634b62
rename `k_iter` to `iter_permutations`
Frizi Mar 27, 2021
fa1e7bc
rename `iter_permutations` to `iter_combinations`
Frizi Mar 27, 2021
b5ba3ce
disallow creating combinations iterator with mutable access
Frizi Mar 31, 2021
bd38250
avoid ICE when calling `QueryCombinationIter::for_each`
Frizi Apr 2, 2021
b44a987
fix clippy warning
Frizi Apr 2, 2021
41cca88
fix doc test on `iter_combinations_mut`
Frizi Apr 2, 2021
b7e2bd4
remove `QueryCombinationIter::for_each`, as it cannot be implemented …
Frizi Apr 5, 2021
3b23892
handle sparse sets in `QueryIterationCursor::peek_last`
Frizi Apr 5, 2021
7f17fe9
fix typo in comment
Frizi Apr 5, 2021
df0cf84
more stable n-body simulation
Frizi Apr 17, 2021
6cc3ae3
added `QueryIter::new` safety doc comment
Frizi Apr 24, 2021
901c8d0
finish sentence in the `QueryCombinationIter` comment
Frizi Apr 24, 2021
93d7482
label comments about unstable methods as todo
Frizi May 2, 2021
06ba263
manually inline iteratrion cursor into QueryIter to avoid performance…
Frizi May 11, 2021
08c8ebd
Add notes reminding devs to update iter code in both places
cart May 17, 2021
575fe00
add reminder comments to all query iterator impls
cart May 17, 2021
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
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ path = "examples/ecs/fixed_timestep.rs"
name = "hierarchy"
path = "examples/ecs/hierarchy.rs"

[[example]]
name = "iter_combinations"
path = "examples/ecs/iter_combinations.rs"

[[example]]
name = "parallel_query"
path = "examples/ecs/parallel_query.rs"
Expand Down
27 changes: 27 additions & 0 deletions crates/bevy_ecs/src/query/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,18 @@ pub struct ReadFetch<T> {
sparse_set: *const ComponentSparseSet,
}

impl<T> Clone for ReadFetch<T> {
fn clone(&self) -> Self {
Self {
storage_type: self.storage_type,
table_components: self.table_components,
entity_table_rows: self.entity_table_rows,
entities: self.entities,
sparse_set: self.sparse_set,
}
}
}

/// SAFETY: access is read only
unsafe impl<T> ReadOnlyFetch for ReadFetch<T> {}

Expand Down Expand Up @@ -382,6 +394,21 @@ pub struct WriteFetch<T> {
change_tick: u32,
}

impl<T> Clone for WriteFetch<T> {
fn clone(&self) -> Self {
Self {
storage_type: self.storage_type,
table_components: self.table_components,
table_ticks: self.table_ticks,
entities: self.entities,
entity_table_rows: self.entity_table_rows,
sparse_set: self.sparse_set,
last_change_tick: self.last_change_tick,
change_tick: self.change_tick,
}
}
}

/// The [`FetchState`] of `&mut T`.
pub struct WriteState<T> {
component_id: ComponentId,
Expand Down
Loading