Skip to content

Commit

Permalink
Unpartial the Commit- Made QueryRelationFilter a proper type
Browse files Browse the repository at this point in the history
  • Loading branch information
BoxyUwU committed Apr 4, 2021
1 parent acf2be6 commit d41a88f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
4 changes: 2 additions & 2 deletions crates/bevy_ecs/src/query/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub trait WorldQuery {

pub trait Fetch<'w>: Sized {
type Item;
type State: FetchState;
type State: FetchState<RelationFilter = Self::RelationFilter>;
type RelationFilter: Clone + std::hash::Hash + PartialEq + Eq + Default + Send + Sync + 'static;

/// Creates a new instance of this fetch.
Expand Down Expand Up @@ -1010,4 +1010,4 @@ macro_rules! impl_tuple_fetch {
};
}

all_tuples!(impl_tuple_fetch, 0, 15, F, S, R);
all_tuples!(impl_tuple_fetch, 0, 11, F, S, R);
15 changes: 9 additions & 6 deletions crates/bevy_ecs/src/query/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,11 @@ macro_rules! impl_query_filter_tuple {
unsafe fn set_archetype(&mut self, state: &Self::State, relation_filter: &Self::RelationFilter, archetype: &Archetype, tables: &Tables) {
let ($($filter,)*) = &mut self.0;
let ($($state,)*) = &state.0;
let ($($relation_filter,)*) = relation_filter;
$(
$filter.matches = $state.matches_archetype(archetype, relation_filter);
$filter.matches = $state.matches_archetype(archetype, $relation_filter);
if $filter.matches {
$filter.fetch.set_archetype($state, relation_filter, archetype, tables);
$filter.fetch.set_archetype($state, $relation_filter, archetype, tables);
}
)*
}
Expand All @@ -462,7 +463,7 @@ macro_rules! impl_query_filter_tuple {
#[allow(unused_variables)]
#[allow(non_snake_case)]
unsafe impl<$($filter: FetchState),*> FetchState for Or<($($filter,)*)> {
type RelationFilter = ();
type RelationFilter = ($($filter::RelationFilter,)*);

fn init(world: &mut World) -> Self {
Or(($($filter::init(world),)*))
Expand All @@ -480,18 +481,20 @@ macro_rules! impl_query_filter_tuple {

fn matches_archetype(&self, archetype: &Archetype, relation_filter: &Self::RelationFilter) -> bool {
let ($($filter,)*) = &self.0;
false $(|| $filter.matches_archetype(archetype, relation_filter))*
let ($($relation_filter,)*) = relation_filter;
false $(|| $filter.matches_archetype(archetype, $relation_filter))*
}

fn matches_table(&self, table: &Table, relation_filter: &Self::RelationFilter,) -> bool {
let ($($filter,)*) = &self.0;
false $(|| $filter.matches_table(table, relation_filter))*
let ($($relation_filter,)*) = relation_filter;
false $(|| $filter.matches_table(table, $relation_filter))*
}
}
};
}

all_tuples!(impl_query_filter_tuple, 0, 15, F, S, R);
all_tuples!(impl_query_filter_tuple, 0, 11, F, S, R);

// FIXME(Relationships) AAAAAAAAAAAAAAAA
macro_rules! impl_flag_filter {
Expand Down
6 changes: 2 additions & 4 deletions crates/bevy_ecs/src/query/relation_filter.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use crate::prelude::Entity;

use super::{FetchState, WorldQuery};
use std::{
hash::{Hash, Hasher},
Expand All @@ -8,8 +6,8 @@ use std::{

// FIXME(Relationships) this is not remotely correct, we want an assoc type on `Fetch`
pub struct QueryRelationFilter<Q: WorldQuery, F: WorldQuery>(
<Q::State as FetchState>::RelationFilter,
<F::State as FetchState>::RelationFilter,
pub <Q::State as FetchState>::RelationFilter,
pub <F::State as FetchState>::RelationFilter,
PhantomData<fn() -> (Q, F)>,
);

Expand Down
24 changes: 12 additions & 12 deletions crates/bevy_ecs/src/query/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ where
archetype: &Archetype,
) {
let table_index = archetype.table_id().index();
if fetch_state.matches_archetype(archetype, relation_filter)
&& filter_state.matches_archetype(archetype, relation_filter)
if fetch_state.matches_archetype(archetype, &relation_filter.0)
&& filter_state.matches_archetype(archetype, &relation_filter.1)
{
// FIXME(Relationships) Use a new ArchetypeRelationKindId here instead
fetch_state.update_archetype_component_access(archetype, access);
Expand Down Expand Up @@ -217,13 +217,13 @@ where

fetch.set_archetype(
&self.fetch_state,
&self.current_relation_filter,
&self.current_relation_filter.0,
archetype,
&world.storages().tables,
);
filter.set_archetype(
&self.filter_state,
&self.current_relation_filter,
&self.current_relation_filter.1,
archetype,
&world.storages().tables,
);
Expand Down Expand Up @@ -374,8 +374,8 @@ where
let tables = &world.storages().tables;
for table_id in self.current_query_access_cache().matched_table_ids.iter() {
let table = tables.get_unchecked(*table_id);
fetch.set_table(&self.fetch_state, &self.current_relation_filter, table);
filter.set_table(&self.filter_state, &self.current_relation_filter, table);
fetch.set_table(&self.fetch_state, &self.current_relation_filter.0, table);
filter.set_table(&self.filter_state, &self.current_relation_filter.1, table);

for table_index in 0..table.len() {
if !filter.table_filter_fetch(table_index) {
Expand All @@ -396,13 +396,13 @@ where
let archetype = archetypes.get_unchecked(*archetype_id);
fetch.set_archetype(
&self.fetch_state,
&self.current_relation_filter,
&self.current_relation_filter.0,
archetype,
tables,
);
filter.set_archetype(
&self.filter_state,
&self.current_relation_filter,
&self.current_relation_filter.1,
archetype,
tables,
);
Expand Down Expand Up @@ -447,12 +447,12 @@ where
let table = tables.get_unchecked(*table_id);
fetch.set_table(
&self.fetch_state,
&self.current_relation_filter,
&self.current_relation_filter.0,
table,
);
filter.set_table(
&self.filter_state,
&self.current_relation_filter,
&self.current_relation_filter.1,
table,
);
let len = batch_size.min(table.len() - offset);
Expand Down Expand Up @@ -485,13 +485,13 @@ where
let archetype = world.archetypes.get_unchecked(*archetype_id);
fetch.set_archetype(
&self.fetch_state,
&self.current_relation_filter,
&self.current_relation_filter.0,
archetype,
tables,
);
filter.set_archetype(
&self.filter_state,
&self.current_relation_filter,
&self.current_relation_filter.1,
archetype,
tables,
);
Expand Down

0 comments on commit d41a88f

Please sign in to comment.