pub struct Loader { /* private fields */ }Expand description
Loads and tracks lifetimes of asset data.
Implementations§
Source§impl Loader
impl Loader
pub fn new(io: Box<dyn LoaderIO>) -> Loader
pub fn new_with_handle_allocator( io: Box<dyn LoaderIO>, handle_allocator: Arc<dyn HandleAllocator>, ) -> Loader
pub fn with_serde_context<R>( &self, tx: &Sender<RefOp>, f: impl FnMut() -> R, ) -> R
Sourcepub fn get_load(&self, id: AssetUuid) -> Option<LoadHandle>
pub fn get_load(&self, id: AssetUuid) -> Option<LoadHandle>
Returns the load handle for the asset with the given UUID, if present.
This will only return Some(..) if there has been a previous call to Loader::add_ref.
§Parameters
id: UUID of the asset.
Sourcepub fn get_load_info(&self, load: LoadHandle) -> Option<LoadInfo>
pub fn get_load_info(&self, load: LoadHandle) -> Option<LoadInfo>
Returns information about the load of an asset.
Note: The information is true at the time the LoadInfo is retrieved. The actual number
of references may change.
§Parameters
load_handle: ID allocated byLoaderto track loading of the asset.
Sourcepub fn get_active_loads(&self) -> Vec<LoadHandle>
pub fn get_active_loads(&self) -> Vec<LoadHandle>
Returns handles to all active asset loads.
Sourcepub fn get_load_status(&self, load: LoadHandle) -> LoadStatus
pub fn get_load_status(&self, load: LoadHandle) -> LoadStatus
Returns the asset load status.
§Parameters
load: ID allocated byLoaderto track loading of the asset.
pub fn add_ref_handle(&self, handle: LoadHandle)
Sourcepub fn add_ref<U: Into<AssetUuid>>(&self, id: U) -> LoadHandle
pub fn add_ref<U: Into<AssetUuid>>(&self, id: U) -> LoadHandle
Adds a reference to an asset and returns its LoadHandle.
If the asset is already loaded, this returns the existing LoadHandle. If it is not
loaded, this allocates a new LoadHandle and returns that.
§Parameters
id: UUID of the asset.
Sourcepub fn add_ref_indirect(&self, id: IndirectIdentifier) -> LoadHandle
pub fn add_ref_indirect(&self, id: IndirectIdentifier) -> LoadHandle
Adds a reference to an indirect id and returns its LoadHandle with LoadHandle::is_indirect set to true.
§Parameters
id: IndirectIdentifier for the load.
Sourcepub fn get_asset_type(&self, load: LoadHandle) -> Option<AssetTypeId>
pub fn get_asset_type(&self, load: LoadHandle) -> Option<AssetTypeId>
Returns the AssetTypeId for the currently loaded asset of the provided load handle.
§Parameters
load: ID allocated byLoaderto track loading of the asset.
Sourcepub fn remove_ref(&self, load: LoadHandle)
pub fn remove_ref(&self, load: LoadHandle)
Removes a reference to an asset.
§Parameters
load_handle: ID allocated byLoaderto track loading of the asset.
Sourcepub fn process(
&mut self,
asset_storage: &dyn AssetStorage,
resolver: &dyn IndirectionResolver,
) -> Result<()>
pub fn process( &mut self, asset_storage: &dyn AssetStorage, resolver: &dyn IndirectionResolver, ) -> Result<()>
Processes pending load operations.
Load operations include:
- Requesting asset metadata.
- Requesting asset data.
- Committing completed
AssetLoadOps. - Updating the
LoadStatuses of assets. - Resolving active
IndirectIdentifiers.
§Parameters
asset_storage: Storage for all assets of all asset types.
Sourcepub fn indirection_table(&self) -> IndirectionTable
pub fn indirection_table(&self) -> IndirectionTable
Returns a reference to the loader’s IndirectionTable.
When a user fetches an asset by LoadHandle, implementors of AssetStorage
should resolve LoadHandles where LoadHandle::is_indirect returns true by using IndirectionTable::resolve.
IndirectionTable is Send + Sync + Clone so that it can be retrieved once at startup,
then stored in implementors of AssetStorage.
Sourcepub fn invalidate_assets(&self, assets: &[AssetUuid])
pub fn invalidate_assets(&self, assets: &[AssetUuid])
Invalidates the data & metadata of the provided asset IDs.
This causes the asset data to be reloaded.
Sourcepub fn invalidate_paths(&self, paths: &[PathBuf])
pub fn invalidate_paths(&self, paths: &[PathBuf])
Invalidates indirect identifiers that may match the provided paths.
This may cause indirect handles to resolve to new assets.