Skip to content

Commit

Permalink
fix: missing RandomFetch impl for Union<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
ten3roberts committed Jan 2, 2025
1 parent c07e645 commit ad6ebf0
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
15 changes: 14 additions & 1 deletion src/filter/set.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
archetype::{Archetype, Slice},
fetch::{FetchAccessData, FetchPrepareData, FmtQuery, PreparedFetch, UnionFilter},
fetch::{FetchAccessData, FetchPrepareData, FmtQuery, PreparedFetch, RandomFetch, UnionFilter},
filter::StaticFilter,
system::Access,
Fetch, FetchItem,
Expand Down Expand Up @@ -264,6 +264,19 @@ where
}
}

impl<'q, T> RandomFetch<'q> for Union<T>
where
T: RandomFetch<'q> + UnionFilter,
{
unsafe fn fetch_shared(&'q self, slot: crate::archetype::Slot) -> Self::Item {
self.0.fetch_shared(slot)
}

unsafe fn fetch_shared_chunk(chunk: &Self::Chunk, slot: crate::archetype::Slot) -> Self::Item {
T::fetch_shared_chunk(chunk, slot)
}
}

macro_rules! tuple_impl {
($($idx: tt => $ty: ident),*) => {
// Or
Expand Down
7 changes: 4 additions & 3 deletions src/query/dfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ where
fn borrow(&'w mut self, query_state: QueryBorrowState<'w, Q, F>, dirty: bool) -> Self::Borrow {
if dirty {
self.state
.update(query_state.world, self.relation, query_state.fetch)
.find_archetypes(query_state.world, self.relation, query_state.fetch)
}

DfsBorrow::new(query_state, self)
}

fn access(&self, world: &'w World, fetch: &'w Filtered<Q, F>, dst: &mut Vec<Access>) {
let mut state = State::default();
state.update(world, self.relation, fetch);
state.find_archetypes(world, self.relation, fetch);

state.archetypes.iter().for_each(|&arch_id| {
let arch = world.archetypes.get(arch_id);
Expand Down Expand Up @@ -87,10 +87,11 @@ struct State {
}

impl State {
pub(crate) fn update<'w, Q>(&mut self, world: &'w World, relation: Entity, fetch: &Q)
pub(crate) fn find_archetypes<'w, Q>(&mut self, world: &'w World, relation: Entity, fetch: &Q)
where
Q: Fetch<'w>,
{
profile_function!();
self.edges.clear();
self.archetypes.clear();
self.archetypes_index.clear();
Expand Down
5 changes: 3 additions & 2 deletions src/query/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ type State<'w, Q, F> = (
PreparedArchetype<'w, <Q as Fetch<'w>>::Prepared, <F as Fetch<'w>>::Prepared>,
);

fn state<'w, 'a, Q: Fetch<'w>, F: Fetch<'w>>(
fn find_archetypes<'w, 'a, Q: Fetch<'w>, F: Fetch<'w>>(
id: Entity,
state: &'a QueryBorrowState<'w, Q, F>,
) -> Result<State<'w, Q, F>> {
profile_function!();
let loc = match state.world.location(id) {
Ok(v) => v,
Err(_) => return Err(Error::NoSuchEntity(id)),
Expand Down Expand Up @@ -58,7 +59,7 @@ where

fn borrow(&'w mut self, query_state: QueryBorrowState<'w, Q, F>, _dirty: bool) -> Self::Borrow {
EntityBorrow {
prepared: state(*self, &query_state),
prepared: find_archetypes(*self, &query_state),
}
}

Expand Down
1 change: 1 addition & 0 deletions src/query/planar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ impl Planar {
fetch: &Filtered<Q, F>,
result: &mut Vec<ArchetypeId>,
) {
profile_function!();
let mut searcher = ArchetypeSearcher::default();
fetch.searcher(&mut searcher);

Expand Down
9 changes: 5 additions & 4 deletions src/query/topo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ struct State {
}

impl State {
fn update<'w, Q: Fetch<'w>>(&mut self, relation: Entity, world: &World, fetch: &'w Q) {
fn find_archetypes<'w, Q: Fetch<'w>>(&mut self, relation: Entity, world: &World, fetch: &'w Q) {
profile_function!();
self.clear();
let mut searcher = ArchetypeSearcher::default();
fetch.searcher(&mut searcher);
Expand Down Expand Up @@ -142,7 +143,7 @@ where
) -> Self::Borrow {
if dirty {
self.state
.update(self.relation, query_state.world, query_state.fetch);
.find_archetypes(self.relation, query_state.world, query_state.fetch);
}

TopoBorrow {
Expand All @@ -154,7 +155,7 @@ where

fn access(&self, world: &'w World, fetch: &'w Filtered<Q, F>, dst: &mut Vec<Access>) {
let mut state = State::default();
state.update(self.relation, world, fetch);
state.find_archetypes(self.relation, world, fetch);

state.archetypes.iter().for_each(|&arch_id| {
let arch = world.archetypes.get(arch_id);
Expand Down Expand Up @@ -318,7 +319,7 @@ mod test {

let fetch = name().with() & !component_info().with();

state.update(connected_to.id(), &world, &fetch);
state.find_archetypes(connected_to.id(), &world, &fetch);

let visited = state
.order
Expand Down

0 comments on commit ad6ebf0

Please sign in to comment.