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

Remove FetchState #4802

Closed
wants to merge 14 commits into from
28 changes: 12 additions & 16 deletions crates/bevy_ecs/macros/src/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,19 @@ pub fn derive_world_query_impl(ast: DeriveInput) -> TokenStream {
true #(&& self.#field_idents.archetype_filter_fetch(_archetype_index))*
}

fn init_state(world: &mut #path::world::World) -> Self::State {
#state_struct_name {
#(#field_idents: #path::query::#fetch_type_alias::<'static, #field_types>::init_state(world),)*
#(#ignored_field_idents: Default::default(),)*
}
}

fn update_component_access(state: &Self::State, _access: &mut #path::query::FilteredAccess<#path::component::ComponentId>) {
#( #path::query::#fetch_type_alias::<'static, #field_types> :: update_component_access(&state.#field_idents, _access); )*
#(#path::query::#fetch_type_alias::<'static, #field_types>::update_component_access(&state.#field_idents, _access);)*
}

fn matches_component_set(state: &Self::State, _set_contains_id: &impl Fn(#path::component::ComponentId) -> bool) -> bool {
true #(&& #path::query::#fetch_type_alias::<'static, #field_types>::matches_component_set(&state.#field_idents, _set_contains_id))*
}

fn update_archetype_component_access(state: &Self::State, _archetype: &#path::archetype::Archetype, _access: &mut #path::query::Access<#path::archetype::ArchetypeComponentId>) {
Expand All @@ -274,24 +285,9 @@ pub fn derive_world_query_impl(ast: DeriveInput) -> TokenStream {
let state_impl = quote! {
#[doc(hidden)]
#visibility struct #state_struct_name #user_impl_generics #user_where_clauses {

#(#field_idents: <#field_types as #path::query::WorldQuery>::State,)*
#(#ignored_field_idents: #ignored_field_types,)*
}

impl #user_impl_generics #path::query::FetchState for #state_struct_name #user_ty_generics #user_where_clauses {
fn init(world: &mut #path::world::World) -> Self {
#state_struct_name {
#(#field_idents: <<#field_types as #path::query::WorldQuery>::State as #path::query::FetchState>::init(world),)*
#(#ignored_field_idents: Default::default(),)*
}
}

fn matches_component_set(&self, _set_contains_id: &impl Fn(#path::component::ComponentId) -> bool) -> bool {
true #(&& self.#field_idents.matches_component_set(_set_contains_id))*

}
}
};

let read_only_fetch_impl = if fetch_struct_attributes.is_mutable {
Expand Down
Loading