pub(crate) unsafe fn par_for_each_unchecked_manual<
        'w,
        's,
        QF: Fetch<'w, 's, State = Q::State>,
        FN: Fn(QF::Item) + Send + Sync + Clone,
    >(
        &'s self,
        world: &'w World,
        task_pool: &TaskPool,
        batch_size: usize,
        func: FN,
        last_change_tick: u32,
        change_tick: u32,
    ) {
        // NOTE: If you are changing query iteration code, remember to update the following places, where relevant:
        // QueryIter, QueryIterationCursor, QueryState::for_each_unchecked_manual, QueryState::par_for_each_unchecked_manual
        task_pool.scope(|scope| {
            if QF::IS_DENSE && F::Fetch::IS_DENSE {
                let tables = &world.storages().tables;
                for table_id in self.matched_table_ids.iter() {
                    let table = &tables[*table_id];
                    let mut offset = 0;
                    while offset < table.len() {
                        let func = func.clone();
                        scope.spawn(async move {
                            let mut fetch =
                                QF::init(world, &self.fetch_state, last_change_tick, change_tick);
                            let mut filter = <F::Fetch as Fetch>::init(
                                world,
                                &self.filter_state,
                                last_change_tick,
                                change_tick,
                            );
                            let tables = &world.storages().tables;
                            let table = &tables[*table_id];
                            fetch.set_table(&self.fetch_state, table);
                            filter.set_table(&self.filter_state, table);
                            let len = batch_size.min(table.len() - offset);
                            for table_index in offset..offset + len {
                                if !filter.table_filter_fetch(table_index) {
                                    continue;
                                }
                                let item = fetch.table_fetch(table_index);
                                func(item);
                            }
                        });
                        offset += batch_size;
                    }
                }
            } else {
                let archetypes = &world.archetypes;
                for archetype_id in self.matched_archetype_ids.iter() {
                    let mut offset = 0;
                    let archetype = &archetypes[*archetype_id];
                    while offset < archetype.len() {
                        let func = func.clone();
                        scope.spawn(async move {
                            let mut fetch =
                                QF::init(world, &self.fetch_state, last_change_tick, change_tick);
                            let mut filter = <F::Fetch as Fetch>::init(
                                world,
                                &self.filter_state,
                                last_change_tick,
                                change_tick,
                            );
                            let tables = &world.storages().tables;
                            let archetype = &world.archetypes[*archetype_id];
                            fetch.set_archetype(&self.fetch_state, archetype, tables);
                            filter.set_archetype(&self.filter_state, archetype, tables);

                            let len = batch_size.min(archetype.len() - offset);
                            for archetype_index in offset..offset + len {
                                if !filter.archetype_filter_fetch(archetype_index) {
                                    continue;
                                }
                                func(fetch.archetype_fetch(archetype_index));
                            }
                        });
                        offset += batch_size;
                    }
                }
            }
        });
    }
/// Runs `func` on each query result in parallel for the given [`World`], where the last change and
/// the current change tick are given. This is faster than the equivalent
/// iter() method, but cannot be chained like a normal [`Iterator`].
///
/// # Safety
///
/// This does not check for mutable query correctness. To be safe, make sure mutable queries
/// have unique access to the components they query.
/// This does not validate that `world.id()` matches `self.world_id`. Calling this on a `world`
/// with a mismatched WorldId is unsound.
Runs `func` on each query result in parallel for the given [`World`], where the last change and
the current change tick are given. This is faster than the equivalent
iter() method, but cannot be chained like a normal [`Iterator`].
Runs ` func ` on each query result in parallel for the given [ ` World ` ] where the last change and the current change tick are given . This is faster than the equivalent iter () method but cannot be chained like a normal [ ` Iterator ` ] .
pub(crate) unsafe fn par_for_each_unchecked_manual<
        'w,
        's,
        QF: Fetch<'w, 's, State = Q::State>,
        FN: Fn(QF::Item) + Send + Sync + Clone,
    >(
        &'s self,
        world: &'w World,
        task_pool: &TaskPool,
        batch_size: usize,
        func: FN,
        last_change_tick: u32,
        change_tick: u32,
    ) {
        // NOTE: If you are changing query iteration code, remember to update the following places, where relevant:
        // QueryIter, QueryIterationCursor, QueryState::for_each_unchecked_manual, QueryState::par_for_each_unchecked_manual
        task_pool.scope(|scope| {
            if QF::IS_DENSE && F::Fetch::IS_DENSE {
                let tables = &world.storages().tables;
                for table_id in self.matched_table_ids.iter() {
                    let table = &tables[*table_id];
                    let mut offset = 0;
                    while offset < table.len() {
                        let func = func.clone();
                        scope.spawn(async move {
                            let mut fetch =
                                QF::init(world, &self.fetch_state, last_change_tick, change_tick);
                            let mut filter = <F::Fetch as Fetch>::init(
                                world,
                                &self.filter_state,
                                last_change_tick,
                                change_tick,
                            );
                            let tables = &world.storages().tables;
                            let table = &tables[*table_id];
                            fetch.set_table(&self.fetch_state, table);
                            filter.set_table(&self.filter_state, table);
                            let len = batch_size.min(table.len() - offset);
                            for table_index in offset..offset + len {
                                if !filter.table_filter_fetch(table_index) {
                                    continue;
                                }
                                let item = fetch.table_fetch(table_index);
                                func(item);
                            }
                        });
                        offset += batch_size;
                    }
                }
            } else {
                let archetypes = &world.archetypes;
                for archetype_id in self.matched_archetype_ids.iter() {
                    let mut offset = 0;
                    let archetype = &archetypes[*archetype_id];
                    while offset < archetype.len() {
                        let func = func.clone();
                        scope.spawn(async move {
                            let mut fetch =
                                QF::init(world, &self.fetch_state, last_change_tick, change_tick);
                            let mut filter = <F::Fetch as Fetch>::init(
                                world,
                                &self.filter_state,
                                last_change_tick,
                                change_tick,
                            );
                            let tables = &world.storages().tables;
                            let archetype = &world.archetypes[*archetype_id];
                            fetch.set_archetype(&self.fetch_state, archetype, tables);
                            filter.set_archetype(&self.filter_state, archetype, tables);
                            let len = batch_size.min(archetype.len() - offset);
                            for archetype_index in offset..offset + len {
                                if !filter.archetype_filter_fetch(archetype_index) {
                                    continue;
                                }
                                func(fetch.archetype_fetch(archetype_index));
                            }
                        });
                        offset += batch_size;
                    }
                }
            }
        });
    }
pub ( crate ) unsafe fn par_for_each_unchecked_manual < ' w , ' s , QF : Fetch < ' w , ' s , State = Q :: State > , FN : Fn ( QF :: Item ) + Send + Sync + Clone , > ( & ' s self , world : & ' w World , task_pool : & TaskPool , batch_size : usize , func : FN , last_change_tick : u32 , change_tick : u32 , ) { // NOTE: If you are changing query iteration code, remember to update the following places, where relevant: // QueryIter, QueryIterationCursor, QueryState::for_each_unchecked_manual, QueryState::par_for_each_unchecked_manual task_pool . scope ( | scope | { if QF :: IS_DENSE && F :: Fetch :: IS_DENSE { let tables = & world . storages ( ) . tables ; for table_id in self . matched_table_ids . iter ( ) { let table = & tables [ * table_id ] ; let mut offset = 0 ; while offset < table . len ( ) { let func = func . clone ( ) ; scope . spawn ( async move { let mut fetch = QF :: init ( world , & self . fetch_state , last_change_tick , change_tick ) ; let mut filter = < F :: Fetch as Fetch > :: init ( world , & self . filter_state , last_change_tick , change_tick , ) ; let tables = & world . storages ( ) . tables ; let table = & tables [ * table_id ] ; fetch . set_table ( & self . fetch_state , table ) ; filter . set_table ( & self . filter_state , table ) ; let len = batch_size . min ( table . len ( ) - offset ) ; for table_index in offset .. offset + len { if ! filter . table_filter_fetch ( table_index ) { continue ; } let item = fetch . table_fetch ( table_index ) ; func ( item ) ; } } ) ; offset += batch_size ; } } } else { let archetypes = & world . archetypes ; for archetype_id in self . matched_archetype_ids . iter ( ) { let mut offset = 0 ; let archetype = & archetypes [ * archetype_id ] ; while offset < archetype . len ( ) { let func = func . clone ( ) ; scope . spawn ( async move { let mut fetch = QF :: init ( world , & self . fetch_state , last_change_tick , change_tick ) ; let mut filter = < F :: Fetch as Fetch > :: init ( world , & self . filter_state , last_change_tick , change_tick , ) ; let tables = & world . storages ( ) . tables ; let archetype = & world . archetypes [ * archetype_id ] ; fetch . set_archetype ( & self . fetch_state , archetype , tables ) ; filter . set_archetype ( & self . filter_state , archetype , tables ) ; let len = batch_size . min ( archetype . len ( ) - offset ) ; for archetype_index in offset .. offset + len { if ! filter . archetype_filter_fetch ( archetype_index ) { continue ; } func ( fetch . archetype_fetch ( archetype_index ) ) ; } } ) ; offset += batch_size ; } } } } ) ; }
Runs `func` on each query result in parallel for the given [`World`], where the last change and
the current change tick are given.
Runs ` func ` on each query result in parallel for the given [ ` World ` ] where the last change and the current change tick are given .
&'s self
world
&'w World
task_pool
&TaskPool
batch_size
usize
func
FN
last_change_tick
u32
change_tick
u32
&'s self
world
&'w World
task_pool
&TaskPool
batch_size
usize
func
FN
last_change_tick
u32
change_tick
u32
safety
This does not check for mutable query correctness. To be safe, make sure mutable queries
have unique access to the components they query.
This does not validate that `world.id()` matches `self.world_id`. Calling this on a `world`
with a mismatched WorldId is unsound.
This does not check for mutable query correctness . To be safe make sure mutable queries have unique access to the components they query . This does not validate that ` world . id () ` matches ` self . world_id ` . Calling this on a ` world ` with a mismatched WorldId is unsound .