pub fn process_custom_drop<F, D>(
        &mut self,
        mut f: F,
        mut drop_fn: D,
        frame_number: u64,
        pool: &ThreadPool,
        strategy: Option<&HotReloadStrategy>,
    ) where
        D: FnMut(A),
        F: FnMut(A::Data) -> Result<ProcessingState<A>>,
    {
        {
            let requeue = self.requeue.get_mut().unwrap();
            while let Some(processed) = self.processed.try_pop() {
                let assets = &mut self.assets;
                let bitset = &mut self.bitset;
                let handles = &mut self.handles;
                let reloads = &mut self.reloads;

                let f = &mut f;
                let (reload_obj, handle) = match processed {
                    Processed::NewAsset {
                        data,
                        handle,
                        name,
                        tracker,
                    } => {
                        let (asset, reload_obj) = match data.map(|FormatValue { data, reload }| {
                            (data, reload)
                        }).and_then(|(d, rel)| f(d).map(|a| (a, rel)))
                            .chain_err(|| ErrorKind::Asset(name.clone()))
                        {
                            Ok((ProcessingState::Loaded(x), r)) => {
                                debug!(
                                        "{:?}: Asset {:?} (handle id: {:?}) has been loaded successfully",
                                        A::NAME,
                                        name,
                                        handle,
                                    );
                                // Add a warning if a handle is unique (i.e. asset does not
                                // need to be loaded as it is not used by anything)
                                // https://github.com/amethyst/amethyst/issues/628
                                if handle.is_unique() {
                                    warn!(
                                        "Loading unnecessary asset. Handle {} is unique ",
                                        handle.id()
                                    );
                                    tracker.fail(
                                        handle.id(),
                                        A::NAME,
                                        name,
                                        Error::from_kind(ErrorKind::UnusedHandle),
                                    );
                                } else {
                                    tracker.success();
                                }

                                (x, r)
                            }
                            Ok((ProcessingState::Loading(x), r)) => {
                                debug!(
                                        "{:?}: Asset {:?} (handle id: {:?}) is not complete, readding to queue",
                                        A::NAME,
                                        name,
                                        handle,
                                    );
                                requeue.push(Processed::NewAsset {
                                    data: Ok(FormatValue { data: x, reload: r }),
                                    handle,
                                    name,
                                    tracker,
                                });
                                continue;
                            }
                            Err(e) => {
                                error!(
                                    "{:?}: Asset {:?} (handle id: {:?}) could not be loaded: {}",
                                    A::NAME,
                                    name,
                                    handle,
                                    e,
                                );
                                tracker.fail(handle.id(), A::NAME, name, e);

                                continue;
                            }
                        };

                        let id = handle.id();
                        bitset.add(id);
                        handles.push(handle.clone());

                        // NOTE: the loader has to ensure that a handle will be used
                        // together with a `Data` only once.
                        unsafe {
                            assets.insert(id, asset);
                        }

                        (reload_obj, handle)
                    }
                    Processed::HotReload {
                        data,
                        handle,
                        name,
                        old_reload,
                    } => {
                        let (asset, reload_obj) = match data.map(|FormatValue { data, reload }| {
                            (data, reload)
                        }).and_then(|(d, rel)| f(d).map(|a| (a, rel)))
                            .chain_err(|| ErrorKind::Asset(name.clone()))
                        {
                            Ok((ProcessingState::Loaded(x), r)) => (x, r),
                            Ok((ProcessingState::Loading(x), r)) => {
                                debug!(
                                    "{:?}: Asset {:?} (handle id: {:?}) is not complete, readding to queue",
                                    A::NAME,
                                    name,
                                    handle,
                                );
                                requeue.push(Processed::HotReload {
                                    data: Ok(FormatValue { data: x, reload: r }),
                                    handle,
                                    name,
                                    old_reload,
                                });
                                continue;
                            }
                            Err(e) => {
                                error!(
                                    "{:?}: Failed to hot-reload asset {:?} (handle id: {:?}): {}\n\
                                     Falling back to old reload object.",
                                    A::NAME,
                                    name,
                                    handle,
                                    e,
                                );

                                reloads.push((handle.downgrade(), old_reload));

                                continue;
                            }
                        };

                        let id = handle.id();
                        assert!(
                            bitset.contains(id),
                            "Expected handle {:?} to be valid, but the asset storage says otherwise",
                            handle,
                        );
                        unsafe {
                            let old = assets.get_mut(id);
                            *old = asset;
                        }

                        (reload_obj, handle)
                    }
                };

                // Add the reload obj if it is `Some`.
                if let Some(reload_obj) = reload_obj {
                    reloads.push((handle.downgrade(), reload_obj));
                }
            }

            for p in requeue.drain(..) {
                self.processed.push(p);
            }
        }

        let mut count = 0;
        let mut skip = 0;
        while let Some(i) = self.handles.iter().skip(skip).position(Handle::is_unique) {
            count += 1;
            // Re-normalize index
            let i = skip + i;
            skip = i;
            let handle = self.handles.swap_remove(i);
            let id = handle.id();
            unsafe {
                drop_fn(self.assets.remove(id));
            }
            self.bitset.remove(id);

            // Can't reuse old handle here, because otherwise weak handles would still be valid.
            // TODO: maybe just store u32?
            self.unused_handles.push(Handle {
                id: Arc::new(id),
                marker: PhantomData,
            });
        }
        if count != 0 {
            debug!("{:?}: Freed {} handle ids", A::NAME, count,);
        }

        if strategy
            .map(|s| s.needs_reload(frame_number))
            .unwrap_or(false)
        {
            trace!("{:?}: Testing for asset reloads..", A::NAME);
            self.hot_reload(pool);
        }
    }
/// Process finished asset data and maintain the storage.
/// This calls the `drop_fn` closure for assets that were removed from the storage.
Process finished asset data and maintain the storage.
This calls the `drop_fn` closure for assets that were removed from the storage.
Process finished asset data and maintain the storage . This calls the ` drop_fn ` closure for assets that were removed from the storage .
pub fn process_custom_drop<F, D>(
        &mut self,
        mut f: F,
        mut drop_fn: D,
        frame_number: u64,
        pool: &ThreadPool,
        strategy: Option<&HotReloadStrategy>,
    ) where
        D: FnMut(A),
        F: FnMut(A::Data) -> Result<ProcessingState<A>>,
    {
        {
            let requeue = self.requeue.get_mut().unwrap();
            while let Some(processed) = self.processed.try_pop() {
                let assets = &mut self.assets;
                let bitset = &mut self.bitset;
                let handles = &mut self.handles;
                let reloads = &mut self.reloads;
                let f = &mut f;
                let (reload_obj, handle) = match processed {
                    Processed::NewAsset {
                        data,
                        handle,
                        name,
                        tracker,
                    } => {
                        let (asset, reload_obj) = match data.map(|FormatValue { data, reload }| {
                            (data, reload)
                        }).and_then(|(d, rel)| f(d).map(|a| (a, rel)))
                            .chain_err(|| ErrorKind::Asset(name.clone()))
                        {
                            Ok((ProcessingState::Loaded(x), r)) => {
                                debug!(
                                        "{:?}: Asset {:?} (handle id: {:?}) has been loaded successfully",
                                        A::NAME,
                                        name,
                                        handle,
                                    );
                                // Add a warning if a handle is unique (i.e. asset does not
                                // need to be loaded as it is not used by anything)
                                // https://github.com/amethyst/amethyst/issues/628
                                if handle.is_unique() {
                                    warn!(
                                        "Loading unnecessary asset. Handle {} is unique ",
                                        handle.id()
                                    );
                                    tracker.fail(
                                        handle.id(),
                                        A::NAME,
                                        name,
                                        Error::from_kind(ErrorKind::UnusedHandle),
                                    );
                                } else {
                                    tracker.success();
                                }
                                (x, r)
                            }
                            Ok((ProcessingState::Loading(x), r)) => {
                                debug!(
                                        "{:?}: Asset {:?} (handle id: {:?}) is not complete, readding to queue",
                                        A::NAME,
                                        name,
                                        handle,
                                    );
                                requeue.push(Processed::NewAsset {
                                    data: Ok(FormatValue { data: x, reload: r }),
                                    handle,
                                    name,
                                    tracker,
                                });
                                continue;
                            }
                            Err(e) => {
                                error!(
                                    "{:?}: Asset {:?} (handle id: {:?}) could not be loaded: {}",
                                    A::NAME,
                                    name,
                                    handle,
                                    e,
                                );
                                tracker.fail(handle.id(), A::NAME, name, e);
                                continue;
                            }
                        };
                        let id = handle.id();
                        bitset.add(id);
                        handles.push(handle.clone());
                        // NOTE: the loader has to ensure that a handle will be used
                        // together with a `Data` only once.
                        unsafe {
                            assets.insert(id, asset);
                        }
                        (reload_obj, handle)
                    }
                    Processed::HotReload {
                        data,
                        handle,
                        name,
                        old_reload,
                    } => {
                        let (asset, reload_obj) = match data.map(|FormatValue { data, reload }| {
                            (data, reload)
                        }).and_then(|(d, rel)| f(d).map(|a| (a, rel)))
                            .chain_err(|| ErrorKind::Asset(name.clone()))
                        {
                            Ok((ProcessingState::Loaded(x), r)) => (x, r),
                            Ok((ProcessingState::Loading(x), r)) => {
                                debug!(
                                    "{:?}: Asset {:?} (handle id: {:?}) is not complete, readding to queue",
                                    A::NAME,
                                    name,
                                    handle,
                                );
                                requeue.push(Processed::HotReload {
                                    data: Ok(FormatValue { data: x, reload: r }),
                                    handle,
                                    name,
                                    old_reload,
                                });
                                continue;
                            }
                            Err(e) => {
                                error!(
                                    "{:?}: Failed to hot-reload asset {:?} (handle id: {:?}): {}\n\
                                     Falling back to old reload object.",
                                    A::NAME,
                                    name,
                                    handle,
                                    e,
                                );
                                reloads.push((handle.downgrade(), old_reload));
                                continue;
                            }
                        };
                        let id = handle.id();
                        assert!(
                            bitset.contains(id),
                            "Expected handle {:?} to be valid, but the asset storage says otherwise",
                            handle,
                        );
                        unsafe {
                            let old = assets.get_mut(id);
                            *old = asset;
                        }
                        (reload_obj, handle)
                    }
                };
                // Add the reload obj if it is `Some`.
                if let Some(reload_obj) = reload_obj {
                    reloads.push((handle.downgrade(), reload_obj));
                }
            }
            for p in requeue.drain(..) {
                self.processed.push(p);
            }
        }
        let mut count = 0;
        let mut skip = 0;
        while let Some(i) = self.handles.iter().skip(skip).position(Handle::is_unique) {
            count += 1;
            // Re-normalize index
            let i = skip + i;
            skip = i;
            let handle = self.handles.swap_remove(i);
            let id = handle.id();
            unsafe {
                drop_fn(self.assets.remove(id));
            }
            self.bitset.remove(id);
            // Can't reuse old handle here, because otherwise weak handles would still be valid.
            // TODO: maybe just store u32?
            self.unused_handles.push(Handle {
                id: Arc::new(id),
                marker: PhantomData,
            });
        }
        if count != 0 {
            debug!("{:?}: Freed {} handle ids", A::NAME, count,);
        }
        if strategy
            .map(|s| s.needs_reload(frame_number))
            .unwrap_or(false)
        {
            trace!("{:?}: Testing for asset reloads..", A::NAME);
            self.hot_reload(pool);
        }
    }
pub fn process_custom_drop < F , D > ( & mut self , mut f : F , mut drop_fn : D , frame_number : u64 , pool : & ThreadPool , strategy : Option < & HotReloadStrategy > , ) where D : FnMut ( A ) , F : FnMut ( A :: Data ) -> Result < ProcessingState < A > > , { { let requeue = self . requeue . get_mut ( ) . unwrap ( ) ; while let Some ( processed ) = self . processed . try_pop ( ) { let assets = & mut self . assets ; let bitset = & mut self . bitset ; let handles = & mut self . handles ; let reloads = & mut self . reloads ; let f = & mut f ; let ( reload_obj , handle ) = match processed { Processed :: NewAsset { data , handle , name , tracker , } => { let ( asset , reload_obj ) = match data . map ( | FormatValue { data , reload } | { ( data , reload ) } ) . and_then ( | ( d , rel ) | f ( d ) . map ( | a | ( a , rel ) ) ) . chain_err ( | | ErrorKind :: Asset ( name . clone ( ) ) ) { Ok ( ( ProcessingState :: Loaded ( x ) , r ) ) => { debug ! ( " " A NAME name handle ) ; // Add a warning if a handle is unique (i.e. asset does not // need to be loaded as it is not used by anything) // https://github.com/amethyst/amethyst/issues/628 if handle . is_unique ( ) { warn ! ( " " handle id ( ) ) ; tracker . fail ( handle . id ( ) , A :: NAME , name , Error :: from_kind ( ErrorKind :: UnusedHandle ) , ) ; } else { tracker . success ( ) ; } ( x , r ) } Ok ( ( ProcessingState :: Loading ( x ) , r ) ) => { debug ! ( " " A NAME name handle ) ; requeue . push ( Processed :: NewAsset { data : Ok ( FormatValue { data : x , reload : r } ) , handle , name , tracker , } ) ; continue ; } Err ( e ) => { error ! ( " " A NAME name handle e ) ; tracker . fail ( handle . id ( ) , A :: NAME , name , e ) ; continue ; } } ; let id = handle . id ( ) ; bitset . add ( id ) ; handles . push ( handle . clone ( ) ) ; // NOTE: the loader has to ensure that a handle will be used // together with a `Data` only once. unsafe { assets . insert ( id , asset ) ; } ( reload_obj , handle ) } Processed :: HotReload { data , handle , name , old_reload , } => { let ( asset , reload_obj ) = match data . map ( | FormatValue { data , reload } | { ( data , reload ) } ) . and_then ( | ( d , rel ) | f ( d ) . map ( | a | ( a , rel ) ) ) . chain_err ( | | ErrorKind :: Asset ( name . clone ( ) ) ) { Ok ( ( ProcessingState :: Loaded ( x ) , r ) ) => ( x , r ) , Ok ( ( ProcessingState :: Loading ( x ) , r ) ) => { debug ! ( " " A NAME name handle ) ; requeue . push ( Processed :: HotReload { data : Ok ( FormatValue { data : x , reload : r } ) , handle , name , old_reload , } ) ; continue ; } Err ( e ) => { error ! ( " \n \
 " A NAME name handle e ) ; reloads . push ( ( handle . downgrade ( ) , old_reload ) ) ; continue ; } } ; let id = handle . id ( ) ; assert ! ( bitset contains ( id ) " " handle ) ; unsafe { let old = assets . get_mut ( id ) ; * old = asset ; } ( reload_obj , handle ) } } ; // Add the reload obj if it is `Some`. if let Some ( reload_obj ) = reload_obj { reloads . push ( ( handle . downgrade ( ) , reload_obj ) ) ; } } for p in requeue . drain ( .. ) { self . processed . push ( p ) ; } } let mut count = 0 ; let mut skip = 0 ; while let Some ( i ) = self . handles . iter ( ) . skip ( skip ) . position ( Handle :: is_unique ) { count += 1 ; // Re-normalize index let i = skip + i ; skip = i ; let handle = self . handles . swap_remove ( i ) ; let id = handle . id ( ) ; unsafe { drop_fn ( self . assets . remove ( id ) ) ; } self . bitset . remove ( id ) ; // Can't reuse old handle here, because otherwise weak handles would still be valid. // TODO: maybe just store u32? self . unused_handles . push ( Handle { id : Arc :: new ( id ) , marker : PhantomData , } ) ; } if count != 0 { debug ! ( " " A NAME count ) ; } if strategy . map ( | s | s . needs_reload ( frame_number ) ) . unwrap_or ( false ) { trace ! ( " " A NAME ) ; self . hot_reload ( pool ) ; } }
Process finished asset data and maintain the storage.
Process finished asset data and maintain the storage .
&mut self
f
F
drop_fn
D
frame_number
u64
pool
&ThreadPool
strategy
Option<&HotReloadStrategy>
&mut self
f
F
drop_fn
D
frame_number
u64
pool
&ThreadPool
strategy
Option<&HotReloadStrategy>