@@ -5,6 +5,8 @@ use crate::{
5
5
use alloc:: { boxed:: Box , sync:: Arc , vec:: Vec } ;
6
6
use async_broadcast:: RecvError ;
7
7
use bevy_platform:: collections:: HashMap ;
8
+ #[ cfg( feature = "trace" ) ]
9
+ use bevy_reflect:: TypePath ;
8
10
use bevy_tasks:: IoTaskPool ;
9
11
use bevy_utils:: TypeIdMap ;
10
12
use core:: any:: TypeId ;
@@ -23,8 +25,8 @@ pub(crate) struct AssetLoaders {
23
25
loaders : Vec < MaybeAssetLoader > ,
24
26
type_id_to_loaders : TypeIdMap < Vec < usize > > ,
25
27
extension_to_loaders : HashMap < Box < str > , Vec < usize > > ,
26
- type_name_to_loader : HashMap < & ' static str , usize > ,
27
- preregistered_loaders : HashMap < & ' static str , usize > ,
28
+ type_path_to_loader : HashMap < & ' static str , usize > ,
29
+ type_path_to_preregistered_loader : HashMap < & ' static str , usize > ,
28
30
}
29
31
30
32
impl AssetLoaders {
@@ -35,7 +37,7 @@ impl AssetLoaders {
35
37
36
38
/// Registers a new [`AssetLoader`]. [`AssetLoader`]s must be registered before they can be used.
37
39
pub ( crate ) fn push < L : AssetLoader > ( & mut self , loader : L ) {
38
- let type_name = core :: any :: type_name :: < L > ( ) ;
40
+ let type_path = L :: type_path ( ) ;
39
41
let loader_asset_type = TypeId :: of :: < L :: Asset > ( ) ;
40
42
let loader_asset_type_name = core:: any:: type_name :: < L :: Asset > ( ) ;
41
43
@@ -44,7 +46,7 @@ impl AssetLoaders {
44
46
let loader = Arc :: new ( loader) ;
45
47
46
48
let ( loader_index, is_new) =
47
- if let Some ( index) = self . preregistered_loaders . remove ( type_name ) {
49
+ if let Some ( index) = self . type_path_to_preregistered_loader . remove ( type_path ) {
48
50
( index, false )
49
51
} else {
50
52
( self . loaders . len ( ) , true )
@@ -75,7 +77,7 @@ impl AssetLoaders {
75
77
Loader must be specified in a .meta file in order to load assets of this type with these extensions.") ;
76
78
}
77
79
78
- self . type_name_to_loader . insert ( type_name , loader_index) ;
80
+ self . type_path_to_loader . insert ( type_path , loader_index) ;
79
81
80
82
self . type_id_to_loaders
81
83
. entry ( loader_asset_type)
@@ -108,12 +110,13 @@ impl AssetLoaders {
108
110
pub ( crate ) fn reserve < L : AssetLoader > ( & mut self , extensions : & [ & str ] ) {
109
111
let loader_asset_type = TypeId :: of :: < L :: Asset > ( ) ;
110
112
let loader_asset_type_name = core:: any:: type_name :: < L :: Asset > ( ) ;
111
- let type_name = core :: any :: type_name :: < L > ( ) ;
113
+ let type_path = L :: type_path ( ) ;
112
114
113
115
let loader_index = self . loaders . len ( ) ;
114
116
115
- self . preregistered_loaders . insert ( type_name, loader_index) ;
116
- self . type_name_to_loader . insert ( type_name, loader_index) ;
117
+ self . type_path_to_preregistered_loader
118
+ . insert ( type_path, loader_index) ;
119
+ self . type_path_to_loader . insert ( type_path, loader_index) ;
117
120
118
121
let existing_loaders_for_type_id = self . type_id_to_loaders . get ( & loader_asset_type) ;
119
122
let mut duplicate_extensions = Vec :: new ( ) ;
@@ -152,7 +155,7 @@ impl AssetLoaders {
152
155
153
156
/// Get the [`AssetLoader`] by name
154
157
pub ( crate ) fn get_by_name ( & self , name : & str ) -> Option < MaybeAssetLoader > {
155
- let index = self . type_name_to_loader . get ( name) . copied ( ) ?;
158
+ let index = self . type_path_to_loader . get ( name) . copied ( ) ?;
156
159
157
160
self . get_by_index ( index)
158
161
}
@@ -309,6 +312,7 @@ impl MaybeAssetLoader {
309
312
}
310
313
311
314
#[ cfg( feature = "trace" ) ]
315
+ #[ derive( TypePath ) ]
312
316
struct InstrumentedAssetLoader < T > ( T ) ;
313
317
314
318
#[ cfg( feature = "trace" ) ]
@@ -361,6 +365,7 @@ mod tests {
361
365
#[ derive( Asset , TypePath , Debug ) ]
362
366
struct C ;
363
367
368
+ #[ derive( TypePath ) ]
364
369
struct Loader < A : Asset , const N : usize , const E : usize > {
365
370
sender : Sender < ( ) > ,
366
371
_phantom : PhantomData < A > ,
@@ -430,7 +435,7 @@ mod tests {
430
435
431
436
let loader = block_on (
432
437
loaders
433
- . get_by_name ( core :: any :: type_name :: < Loader < A , 1 , 0 > > ( ) )
438
+ . get_by_name ( Loader :: < A , 1 , 0 > :: type_path ( ) )
434
439
. unwrap ( )
435
440
. get ( ) ,
436
441
)
0 commit comments