pub fn run_systems(&mut self, ctx: C::View<'_>, world: &mut W) {
        match self.systems.len() {
            1 => {
                // safety: we have exlusive access to all systems, world and resources here
                unsafe {
                    let system = self.systems[0].get_mut();
                    system.prepare(world);
                    system.run(ctx, world);
                };
            }
            _ => {
                let systems = &mut self.systems;
                let static_dependency_counts = &self.static_dependency_counts;
                let awaiting = &mut self.awaiting;

                // prepare all systems - archetype filters are pre-executed here
                systems
                    .par_iter_mut(&self.job_system)
                    .for_each(|sys| unsafe { sys.get_mut() }.prepare(world));

                // self.job_system.for_each(0..systems.len(), |idx| {
                //     let sys = &systems[idx];
                //     let static_dep = &self.static_dependants[idx];
                //     let dyn_dep = &self.dynamic_dependants[idx];

                //     // safety: systems is held exclusively, and we are only reading each system
                //     let archetypes = unsafe { sys.get() }.accesses_archetypes();
                //     for i in (0..dyn_dep.len()).rev() {
                //         let dep = dyn_dep[i];
                //         let other = unsafe { systems[dep].get() };

                //         // if the archetype sets intersect,
                //         // then we can move the dynamic dependant into the static dependants set
                //         if !other.accesses_archetypes().is_disjoint(archetypes) {
                //             static_dep.push(dep);
                //             dyn_dep.swap_remove(i);
                //             static_dependency_counts[dep].fetch_add(1, Ordering::Relaxed);
                //         }
                //     }
                // });

                // determine dynamic dependencies
                let iter = izip!(
                    systems.iter(),
                    self.static_dependants.iter_mut(),
                    self.dynamic_dependants.iter_mut()
                )
                .par_bridge(&self.job_system)
                .for_each(|(sys, static_dep, dyn_dep)| {
                    // safety: systems is held exclusively, and we are only reading each system
                    let archetypes = unsafe { sys.get() }.accesses_archetypes();
                    for i in (0..dyn_dep.len()).rev() {
                        let dep = dyn_dep[i];
                        let other = unsafe { systems[dep].get() };

                        // if the archetype sets intersect,
                        // then we can move the dynamic dependant into the static dependants set
                        if !other.accesses_archetypes().is_disjoint(archetypes) {
                            static_dep.push(dep);
                            dyn_dep.swap_remove(i);
                            static_dependency_counts[dep].fetch_add(1, Ordering::Relaxed);
                        }
                    }
                });

                // initialize dependency tracking
                for (i, count) in static_dependency_counts.iter().enumerate() {
                    awaiting[i].store(count.load(Ordering::Relaxed), Ordering::Relaxed);
                }

                let awaiting = &self.awaiting;

                (0..systems.len())
                    .into_par_iter(&self.job_system)
                    .filter(|i| static_dependency_counts[*i].load(Ordering::SeqCst) == 0)
                    .for_each(|i| {
                        // safety: we are at the root of the execution tree, so we know each
                        // index is exclusive here
                        unsafe { self.run_recursive(i, ctx, world) };
                    });

                debug_assert!(
                    awaiting.iter().all(|x| x.load(Ordering::SeqCst) == 0),
                    "not all systems run: {:?}",
                    awaiting
                );
            }
        }
    }
/// Executes all systems, potentially in parallel.
///
/// Ordering is retained in so far as the order of observed resource and component
/// accesses is maintained.
///
/// Call from within `rayon::ThreadPool::install()` to execute within a specific thread pool.
Executes all systems, potentially in parallel.
Ordering is retained in so far as the order of observed resource and component
accesses is maintained.

Call from within `rayon::ThreadPool::install()` to execute within a specific thread pool.
Executes all systems potentially in parallel . Ordering is retained in so far as the order of observed resource and component accesses is maintained . Call from within ` rayon :: ThreadPool :: install () ` to execute within a specific thread pool .
pub fn run_systems(&mut self, ctx: C::View<'_>, world: &mut W) {
        match self.systems.len() {
            1 => {
                // safety: we have exlusive access to all systems, world and resources here
                unsafe {
                    let system = self.systems[0].get_mut();
                    system.prepare(world);
                    system.run(ctx, world);
                };
            }
            _ => {
                let systems = &mut self.systems;
                let static_dependency_counts = &self.static_dependency_counts;
                let awaiting = &mut self.awaiting;
                // prepare all systems - archetype filters are pre-executed here
                systems
                    .par_iter_mut(&self.job_system)
                    .for_each(|sys| unsafe { sys.get_mut() }.prepare(world));
                // self.job_system.for_each(0..systems.len(), |idx| {
                //     let sys = &systems[idx];
                //     let static_dep = &self.static_dependants[idx];
                //     let dyn_dep = &self.dynamic_dependants[idx];
                //     // safety: systems is held exclusively, and we are only reading each system
                //     let archetypes = unsafe { sys.get() }.accesses_archetypes();
                //     for i in (0..dyn_dep.len()).rev() {
                //         let dep = dyn_dep[i];
                //         let other = unsafe { systems[dep].get() };
                //         // if the archetype sets intersect,
                //         // then we can move the dynamic dependant into the static dependants set
                //         if !other.accesses_archetypes().is_disjoint(archetypes) {
                //             static_dep.push(dep);
                //             dyn_dep.swap_remove(i);
                //             static_dependency_counts[dep].fetch_add(1, Ordering::Relaxed);
                //         }
                //     }
                // });
                // determine dynamic dependencies
                let iter = izip!(
                    systems.iter(),
                    self.static_dependants.iter_mut(),
                    self.dynamic_dependants.iter_mut()
                )
                .par_bridge(&self.job_system)
                .for_each(|(sys, static_dep, dyn_dep)| {
                    // safety: systems is held exclusively, and we are only reading each system
                    let archetypes = unsafe { sys.get() }.accesses_archetypes();
                    for i in (0..dyn_dep.len()).rev() {
                        let dep = dyn_dep[i];
                        let other = unsafe { systems[dep].get() };
                        // if the archetype sets intersect,
                        // then we can move the dynamic dependant into the static dependants set
                        if !other.accesses_archetypes().is_disjoint(archetypes) {
                            static_dep.push(dep);
                            dyn_dep.swap_remove(i);
                            static_dependency_counts[dep].fetch_add(1, Ordering::Relaxed);
                        }
                    }
                });
                // initialize dependency tracking
                for (i, count) in static_dependency_counts.iter().enumerate() {
                    awaiting[i].store(count.load(Ordering::Relaxed), Ordering::Relaxed);
                }
                let awaiting = &self.awaiting;
                (0..systems.len())
                    .into_par_iter(&self.job_system)
                    .filter(|i| static_dependency_counts[*i].load(Ordering::SeqCst) == 0)
                    .for_each(|i| {
                        // safety: we are at the root of the execution tree, so we know each
                        // index is exclusive here
                        unsafe { self.run_recursive(i, ctx, world) };
                    });
                debug_assert!(
                    awaiting.iter().all(|x| x.load(Ordering::SeqCst) == 0),
                    "not all systems run: {:?}",
                    awaiting
                );
            }
        }
    }
pub fn run_systems ( & mut self , ctx : C :: View < ' _ > , world : & mut W ) { match self . systems . len ( ) { 1 => { // safety: we have exlusive access to all systems, world and resources here unsafe { let system = self . systems [ 0 ] . get_mut ( ) ; system . prepare ( world ) ; system . run ( ctx , world ) ; } ; } _ => { let systems = & mut self . systems ; let static_dependency_counts = & self . static_dependency_counts ; let awaiting = & mut self . awaiting ; // prepare all systems - archetype filters are pre-executed here systems . par_iter_mut ( & self . job_system ) . for_each ( | sys | unsafe { sys . get_mut ( ) } . prepare ( world ) ) ; // self.job_system.for_each(0..systems.len(), |idx| { //     let sys = &systems[idx]; //     let static_dep = &self.static_dependants[idx]; //     let dyn_dep = &self.dynamic_dependants[idx]; //     // safety: systems is held exclusively, and we are only reading each system //     let archetypes = unsafe { sys.get() }.accesses_archetypes(); //     for i in (0..dyn_dep.len()).rev() { //         let dep = dyn_dep[i]; //         let other = unsafe { systems[dep].get() }; //         // if the archetype sets intersect, //         // then we can move the dynamic dependant into the static dependants set //         if !other.accesses_archetypes().is_disjoint(archetypes) { //             static_dep.push(dep); //             dyn_dep.swap_remove(i); //             static_dependency_counts[dep].fetch_add(1, Ordering::Relaxed); //         } //     } // }); // determine dynamic dependencies let iter = izip ! ( systems iter ( ) self static_dependants iter_mut ( ) self dynamic_dependants iter_mut ( ) ) . par_bridge ( & self . job_system ) . for_each ( | ( sys , static_dep , dyn_dep ) | { // safety: systems is held exclusively, and we are only reading each system let archetypes = unsafe { sys . get ( ) } . accesses_archetypes ( ) ; for i in ( 0 .. dyn_dep . len ( ) ) . rev ( ) { let dep = dyn_dep [ i ] ; let other = unsafe { systems [ dep ] . get ( ) } ; // if the archetype sets intersect, // then we can move the dynamic dependant into the static dependants set if ! other . accesses_archetypes ( ) . is_disjoint ( archetypes ) { static_dep . push ( dep ) ; dyn_dep . swap_remove ( i ) ; static_dependency_counts [ dep ] . fetch_add ( 1 , Ordering :: Relaxed ) ; } } } ) ; // initialize dependency tracking for ( i , count ) in static_dependency_counts . iter ( ) . enumerate ( ) { awaiting [ i ] . store ( count . load ( Ordering :: Relaxed ) , Ordering :: Relaxed ) ; } let awaiting = & self . awaiting ; ( 0 .. systems . len ( ) ) . into_par_iter ( & self . job_system ) . filter ( | i | static_dependency_counts [ * i ] . load ( Ordering :: SeqCst ) == 0 ) . for_each ( | i | { // safety: we are at the root of the execution tree, so we know each // index is exclusive here unsafe { self . run_recursive ( i , ctx , world ) } ; } ) ; debug_assert ! ( awaiting iter ( ) all ( x x load ( Ordering SeqCst ) 0 ) " " awaiting ) ; } } }
Executes all systems, potentially in parallel.
Executes all systems potentially in parallel .
&mut self
ctx
C::View<'_>
world
&mut W
&mut self
ctx
C::View<'_>
world
&mut W