11use crate :: {
2- meta:: MetaTransform , Asset , AssetId , AssetIndexAllocator , AssetPath , InternalAssetId ,
3- UntypedAssetId ,
2+ meta:: MetaTransform , Asset , AssetId , AssetIndex , AssetIndexAllocator , AssetPath ,
3+ ErasedAssetIndex , UntypedAssetId ,
44} ;
55use alloc:: sync:: Arc ;
66use bevy_reflect:: { std_traits:: ReflectDefault , Reflect , TypePath } ;
@@ -26,7 +26,7 @@ pub struct AssetHandleProvider {
2626
2727#[ derive( Debug ) ]
2828pub ( crate ) struct DropEvent {
29- pub ( crate ) id : InternalAssetId ,
29+ pub ( crate ) index : ErasedAssetIndex ,
3030 pub ( crate ) asset_server_managed : bool ,
3131}
3232
@@ -45,18 +45,19 @@ impl AssetHandleProvider {
4545 /// [`UntypedHandle`] will match the [`Asset`] [`TypeId`] assigned to this [`AssetHandleProvider`].
4646 pub fn reserve_handle ( & self ) -> UntypedHandle {
4747 let index = self . allocator . reserve ( ) ;
48- UntypedHandle :: Strong ( self . get_handle ( InternalAssetId :: Index ( index) , false , None , None ) )
48+ UntypedHandle :: Strong ( self . get_handle ( index, false , None , None ) )
4949 }
5050
5151 pub ( crate ) fn get_handle (
5252 & self ,
53- id : InternalAssetId ,
53+ index : AssetIndex ,
5454 asset_server_managed : bool ,
5555 path : Option < AssetPath < ' static > > ,
5656 meta_transform : Option < MetaTransform > ,
5757 ) -> Arc < StrongHandle > {
5858 Arc :: new ( StrongHandle {
59- id : id. untyped ( self . type_id ) ,
59+ index,
60+ type_id : self . type_id ,
6061 drop_sender : self . drop_sender . clone ( ) ,
6162 meta_transform,
6263 path,
@@ -71,20 +72,16 @@ impl AssetHandleProvider {
7172 meta_transform : Option < MetaTransform > ,
7273 ) -> Arc < StrongHandle > {
7374 let index = self . allocator . reserve ( ) ;
74- self . get_handle (
75- InternalAssetId :: Index ( index) ,
76- asset_server_managed,
77- path,
78- meta_transform,
79- )
75+ self . get_handle ( index, asset_server_managed, path, meta_transform)
8076 }
8177}
8278
8379/// The internal "strong" [`Asset`] handle storage for [`Handle::Strong`] and [`UntypedHandle::Strong`]. When this is dropped,
8480/// the [`Asset`] will be freed. It also stores some asset metadata for easy access from handles.
8581#[ derive( TypePath ) ]
8682pub struct StrongHandle {
87- pub ( crate ) id : UntypedAssetId ,
83+ pub ( crate ) index : AssetIndex ,
84+ pub ( crate ) type_id : TypeId ,
8885 pub ( crate ) asset_server_managed : bool ,
8986 pub ( crate ) path : Option < AssetPath < ' static > > ,
9087 /// Modifies asset meta. This is stored on the handle because it is:
@@ -97,7 +94,7 @@ pub struct StrongHandle {
9794impl Drop for StrongHandle {
9895 fn drop ( & mut self ) {
9996 let _ = self . drop_sender . send ( DropEvent {
100- id : self . id . internal ( ) ,
97+ index : ErasedAssetIndex :: new ( self . index , self . type_id ) ,
10198 asset_server_managed : self . asset_server_managed ,
10299 } ) ;
103100 }
@@ -106,7 +103,8 @@ impl Drop for StrongHandle {
106103impl core:: fmt:: Debug for StrongHandle {
107104 fn fmt ( & self , f : & mut core:: fmt:: Formatter < ' _ > ) -> core:: fmt:: Result {
108105 f. debug_struct ( "StrongHandle" )
109- . field ( "id" , & self . id )
106+ . field ( "index" , & self . index )
107+ . field ( "type_id" , & self . type_id )
110108 . field ( "asset_server_managed" , & self . asset_server_managed )
111109 . field ( "path" , & self . path )
112110 . field ( "drop_sender" , & self . drop_sender )
@@ -154,7 +152,10 @@ impl<A: Asset> Handle<A> {
154152 #[ inline]
155153 pub fn id ( & self ) -> AssetId < A > {
156154 match self {
157- Handle :: Strong ( handle) => handle. id . typed_unchecked ( ) ,
155+ Handle :: Strong ( handle) => AssetId :: Index {
156+ index : handle. index ,
157+ marker : PhantomData ,
158+ } ,
158159 Handle :: Uuid ( uuid, ..) => AssetId :: Uuid { uuid : * uuid } ,
159160 }
160161 }
@@ -202,9 +203,8 @@ impl<A: Asset> core::fmt::Debug for Handle<A> {
202203 Handle :: Strong ( handle) => {
203204 write ! (
204205 f,
205- "StrongHandle<{name}>{{ id: {:?}, path: {:?} }}" ,
206- handle. id. internal( ) ,
207- handle. path
206+ "StrongHandle<{name}>{{ index: {:?}, type_id: {:?}, path: {:?} }}" ,
207+ handle. index, handle. type_id, handle. path
208208 )
209209 }
210210 Handle :: Uuid ( uuid, ..) => write ! ( f, "UuidHandle<{name}>({uuid:?})" ) ,
@@ -298,7 +298,10 @@ impl UntypedHandle {
298298 #[ inline]
299299 pub fn id ( & self ) -> UntypedAssetId {
300300 match self {
301- UntypedHandle :: Strong ( handle) => handle. id ,
301+ UntypedHandle :: Strong ( handle) => UntypedAssetId :: Index {
302+ type_id : handle. type_id ,
303+ index : handle. index ,
304+ } ,
302305 UntypedHandle :: Uuid { type_id, uuid } => UntypedAssetId :: Uuid {
303306 uuid : * uuid,
304307 type_id : * type_id,
@@ -319,7 +322,7 @@ impl UntypedHandle {
319322 #[ inline]
320323 pub fn type_id ( & self ) -> TypeId {
321324 match self {
322- UntypedHandle :: Strong ( handle) => handle. id . type_id ( ) ,
325+ UntypedHandle :: Strong ( handle) => handle. type_id ,
323326 UntypedHandle :: Uuid { type_id, .. } => * type_id,
324327 }
325328 }
@@ -400,9 +403,7 @@ impl core::fmt::Debug for UntypedHandle {
400403 write ! (
401404 f,
402405 "StrongHandle{{ type_id: {:?}, id: {:?}, path: {:?} }}" ,
403- handle. id. type_id( ) ,
404- handle. id. internal( ) ,
405- handle. path
406+ handle. type_id, handle. index, handle. path
406407 )
407408 }
408409 UntypedHandle :: Uuid { type_id, uuid } => {
0 commit comments