@@ -165,13 +165,15 @@ impl AssetSourceBuilder {
165165 }
166166 }
167167
168- /// Builds a new [`AssetSource`] with the given `id`. If `watch` is true, the unprocessed source will watch for changes.
169- /// If `watch_processed` is true, the processed source will watch for changes.
170- pub fn build (
168+ /// Builds a new [`AssetSource`] with the given `id`. If `watch` is true, the unprocessed source
169+ /// will watch for changes. If `watch_processed` is true, the processed source will watch for
170+ /// changes. If `processing_state` is [`Some`], the processed reader will be gated on the state.
171+ pub ( crate ) fn build (
171172 & mut self ,
172173 id : AssetSourceId < ' static > ,
173174 watch : bool ,
174175 watch_processed : bool ,
176+ processing_state : Option < Arc < ProcessingState > > ,
175177 ) -> AssetSource {
176178 let reader = self . reader . as_mut ( ) ( ) ;
177179 let writer = self . writer . as_mut ( ) . and_then ( |w| w ( false ) ) ;
@@ -222,6 +224,13 @@ impl AssetSourceBuilder {
222224 }
223225 }
224226 }
227+
228+ if source. should_process ( )
229+ && let Some ( processing_state) = processing_state
230+ {
231+ source. gate_on_processor ( processing_state) ;
232+ }
233+
225234 source
226235 }
227236
@@ -355,25 +364,41 @@ impl AssetSourceBuilders {
355364 }
356365 }
357366
358- /// Builds a new [`AssetSources`] collection. If `watch` is true, the unprocessed sources will watch for changes.
359- /// If `watch_processed` is true, the processed sources will watch for changes.
360- pub fn build_sources ( & mut self , watch : bool , watch_processed : bool ) -> AssetSources {
367+ /// Builds a new [`AssetSources`] collection. If `watch` is true, the unprocessed sources will
368+ /// watch for changes. If `watch_processed` is true, the processed sources will watch for
369+ /// changes. If `processing_state` is [`Some`], the processed readers will be gated on the
370+ /// processing state.
371+ pub ( crate ) fn build_sources (
372+ & mut self ,
373+ watch : bool ,
374+ watch_processed : bool ,
375+ processing_state : Option < Arc < ProcessingState > > ,
376+ ) -> AssetSources {
361377 let mut sources = <HashMap < _ , _ > >:: default ( ) ;
362378 for ( id, source) in & mut self . sources {
363379 let source = source. build (
364380 AssetSourceId :: Name ( id. clone_owned ( ) ) ,
365381 watch,
366382 watch_processed,
383+ processing_state. clone ( ) ,
367384 ) ;
368- sources. insert ( id. clone_owned ( ) , source) ;
385+ sources. insert ( id. clone_owned ( ) , Arc :: new ( source) ) ;
369386 }
370387
371388 AssetSources {
372389 sources,
373390 default : self
374391 . default
375392 . as_mut ( )
376- . map ( |p| p. build ( AssetSourceId :: Default , watch, watch_processed) )
393+ . map ( |p| {
394+ p. build (
395+ AssetSourceId :: Default ,
396+ watch,
397+ watch_processed,
398+ processing_state. clone ( ) ,
399+ )
400+ } )
401+ . map ( Arc :: new)
377402 . expect ( MISSING_DEFAULT_SOURCE ) ,
378403 }
379404 }
@@ -591,60 +616,43 @@ impl AssetSource {
591616
592617/// A collection of [`AssetSource`]s.
593618pub struct AssetSources {
594- sources : HashMap < CowArc < ' static , str > , AssetSource > ,
595- default : AssetSource ,
619+ sources : HashMap < CowArc < ' static , str > , Arc < AssetSource > > ,
620+ default : Arc < AssetSource > ,
596621}
597622
598623impl AssetSources {
599624 /// Gets the [`AssetSource`] with the given `id`, if it exists.
600- pub fn get < ' a , ' b > (
601- & ' a self ,
602- id : impl Into < AssetSourceId < ' b > > ,
603- ) -> Result < & ' a AssetSource , MissingAssetSourceError > {
625+ pub fn get < ' a > (
626+ & self ,
627+ id : impl Into < AssetSourceId < ' a > > ,
628+ ) -> Result < Arc < AssetSource > , MissingAssetSourceError > {
604629 match id. into ( ) . into_owned ( ) {
605- AssetSourceId :: Default => Ok ( & self . default ) ,
630+ AssetSourceId :: Default => Ok ( self . default . clone ( ) ) ,
606631 AssetSourceId :: Name ( name) => self
607632 . sources
608633 . get ( & name)
634+ . cloned ( )
609635 . ok_or ( MissingAssetSourceError ( AssetSourceId :: Name ( name) ) ) ,
610636 }
611637 }
612638
613639 /// Iterates all asset sources in the collection (including the default source).
614- pub fn iter ( & self ) -> impl Iterator < Item = & AssetSource > {
640+ pub fn iter ( & self ) -> impl Iterator < Item = & Arc < AssetSource > > {
615641 self . sources . values ( ) . chain ( Some ( & self . default ) )
616642 }
617643
618- /// Mutably iterates all asset sources in the collection (including the default source).
619- pub fn iter_mut ( & mut self ) -> impl Iterator < Item = & mut AssetSource > {
620- self . sources . values_mut ( ) . chain ( Some ( & mut self . default ) )
621- }
622-
623644 /// Iterates all processed asset sources in the collection (including the default source).
624- pub fn iter_processed ( & self ) -> impl Iterator < Item = & AssetSource > {
645+ pub fn iter_processed ( & self ) -> impl Iterator < Item = & Arc < AssetSource > > {
625646 self . iter ( ) . filter ( |p| p. should_process ( ) )
626647 }
627648
628- /// Mutably iterates all processed asset sources in the collection (including the default source).
629- pub fn iter_processed_mut ( & mut self ) -> impl Iterator < Item = & mut AssetSource > {
630- self . iter_mut ( ) . filter ( |p| p. should_process ( ) )
631- }
632-
633649 /// Iterates over the [`AssetSourceId`] of every [`AssetSource`] in the collection (including the default source).
634650 pub fn ids ( & self ) -> impl Iterator < Item = AssetSourceId < ' static > > + ' _ {
635651 self . sources
636652 . keys ( )
637653 . map ( |k| AssetSourceId :: Name ( k. clone_owned ( ) ) )
638654 . chain ( Some ( AssetSourceId :: Default ) )
639655 }
640-
641- /// This will cause processed [`AssetReader`](crate::io::AssetReader) futures (such as [`AssetReader::read`](crate::io::AssetReader::read)) to wait until
642- /// the [`AssetProcessor`](crate::AssetProcessor) has finished processing the requested asset.
643- pub ( crate ) fn gate_on_processor ( & mut self , processing_state : Arc < ProcessingState > ) {
644- for source in self . iter_processed_mut ( ) {
645- source. gate_on_processor ( processing_state. clone ( ) ) ;
646- }
647- }
648656}
649657
650658/// An error returned when an [`AssetSource`] does not exist for a given id.
0 commit comments