AsyncAssetManager

class AsyncAssetManager(fileResolver: FileHandleResolver = InternalFileHandleResolver(), useDefaultLoaders: Boolean = true) : AssetManager

An extension of the AssetManager providing asynchronous file loading methods compatible with the coroutine concurrency model.

In addition to the standard asset loading methods, AsyncAssetManager allows scheduling asset loading with loadAsync which returns a Deferred reference to the asset. The reference can be awaited to obtain a fully loaded asset instance. Any errors that occur during loading can be handled with standard Kotlin try-catch clause by using the Deferred API.

To complete the Deferred references with loaded assets, AsyncAssetManager uses LoadedCallback from the AssetLoaderParameters class. If no parameters are passed to loadAsync, they will be created with getDefaultParameters. If the manager is unable to create a default instance of the parameters, an exception will be thrown. To prevent that, register a parameter supplier for any custom loader with setLoaderParameterSupplier, or always pass non-null AssetLoaderParameters to loadAsync.

AssetErrorListener set with setErrorListener will only be invoked if an error is not associated with any asset scheduled with loadAsync. Otherwise, the error will be used to exceptionally complete the Deferred instance referencing a specific asset, and all Deferred instances of assets that depend on it.

Note that unlike AssetStorage, AsyncAssetManager still has to be updated with update until the assets are loaded.

Other than the additions and listed changes necessary to implement the Deferred support, AsyncAssetManager works like a regular AssetManager, and it can be used as a drop-in replacement. They both share the same concurrency model, which relies on thread blocking with synchronized methods. Because of that, AsyncAssetManager is not expected to be faster; in fact, the extra features add some overhead, decreasing the overall performance.

The AssetStorage is advised over an AsyncAssetManager, as it was designed to be entirely non-blocking, and fully compatible with coroutines. It offers superior performance and better coroutines support. AsyncAssetManager should be used instead only as an intermediate step during migration from an AssetManager to the AssetStorage, or if an AssetManager is strictly required by an otherwise incompatible third-party API.

Constructors

Link copied to clipboard
constructor(fileResolver: FileHandleResolver = InternalFileHandleResolver(), useDefaultLoaders: Boolean = true)

Functions

Link copied to clipboard

Attempts to cancel loading of asset identified by fileName. For internal use.

Attempts to cancel loading of assets identified by fileNames. For internal use.

Link copied to clipboard
open fun clear()
Link copied to clipboard
open operator fun contains(p0: String): Boolean
open fun contains(p0: String, p1: Class<Any>): Boolean
Link copied to clipboard
open fun <T : Any> containsAsset(p0: T): Boolean
Link copied to clipboard
open override fun dispose()
Link copied to clipboard
open fun finishLoading()
Link copied to clipboard
open fun <T : Any> finishLoadingAsset(p0: String): T
Link copied to clipboard
open operator fun <T : Any> get(p0: AssetDescriptor<T>): T
open operator fun <T : Any> get(p0: String): T
open operator fun <T : Any> get(p0: String, p1: Class<T>): T
@Null
open operator fun <T : Any> get(p0: String, p1: Boolean): T
@Null
open operator fun <T : Any> get(p0: String, p1: Class<T>, p2: Boolean): T
Link copied to clipboard
open fun <T : Any> getAll(p0: Class<T>, p1: Array<T>): Array<T>
Link copied to clipboard
open fun <T : Any> getAssetFileName(p0: T): String
Link copied to clipboard
open fun getAssetNames(): Array<String>
Link copied to clipboard
open fun getAssetType(p0: String): Class<Any>
Link copied to clipboard

Attempts to create AssetLoaderParameters instance for the asset defined by assetDescriptor. The parameters will use default loading settings whenever possible, unless modified with setLoaderParameterSupplier.

Link copied to clipboard
open fun getDependencies(p0: String): Array<String>
Link copied to clipboard
Link copied to clipboard
open fun getFileHandleResolver(): FileHandleResolver
Link copied to clipboard
open fun getLoadedAssets(): Int
Link copied to clipboard
open fun <T : Any> getLoader(p0: Class<T>): AssetLoader<Any, AssetLoaderParameters<Any>>
open fun <T : Any> getLoader(p0: Class<T>, p1: String): AssetLoader<Any, AssetLoaderParameters<Any>>
Link copied to clipboard
open fun getLogger(): Logger
Link copied to clipboard
open fun getProgress(): Float
Link copied to clipboard
open fun getQueuedAssets(): Int
Link copied to clipboard
Link copied to clipboard
open fun isFinished(): Boolean
Link copied to clipboard
open fun isLoaded(p0: String): Boolean
open fun isLoaded(p0: String, p1: Class<Any>): Boolean
Link copied to clipboard
open fun load(p0: AssetDescriptor<Any>)
open fun <T : Any> load(p0: String, p1: Class<T>)
open fun <T : Any> load(p0: String, p1: Class<T>, p2: AssetLoaderParameters<T>)
Link copied to clipboard
fun <T> loadAsync(assetDescriptor: AssetDescriptor<T>): Deferred<T>

Schedules asynchronous loading of a selected asset with T class specified by the assetDescriptor. If AssetDescriptor.params are not defined, they will be obtained with getDefaultParameters.

inline fun <T> loadAsync(path: String, parameters: AssetLoaderParameters<T>? = null): Deferred<T>

Schedules asynchronous loading of a selected asset with T class. path must point to an existing file representing the asset, as it will be passed to the FileHandleResolver to obtain a file reference. Loader parameters are optional, and can be used to customize loading of the asset. If no parameters are given, they will be obtained with getDefaultParameters.

Link copied to clipboard
Link copied to clipboard
open fun <T : Any, P : AssetLoaderParameters<T>> setLoader(p0: Class<T>, p1: AssetLoader<T, P>)
open fun <T : Any, P : AssetLoaderParameters<T>> setLoader(p0: Class<T>, p1: String, p2: AssetLoader<T, P>)
Link copied to clipboard
inline fun <L : Loader<*>> setLoaderParameterSupplier(noinline supplier: ParameterSupplier<*>)

Adds a custom ParameterSupplier that creates default instances of AssetLoaderParameters for the asset loader with L class. The supplier will be invoked with an AssetDescriptor each time default loader parameters are requested via getDefaultParameters.

fun <T> setLoaderParameterSupplier(loaderClass: Class<Loader<T>>, supplier: ParameterSupplier<T>)

Adds a custom ParameterSupplier that creates default instances of AssetLoaderParameters for the T asset loader with loaderClass. The supplier will be invoked with an AssetDescriptor each time default loader parameters are requested via getDefaultParameters.

Link copied to clipboard
open fun setLogger(p0: Logger)
Link copied to clipboard
open fun setReferenceCount(p0: String, p1: Int)
Link copied to clipboard
open fun unload(p0: String)
Link copied to clipboard
open fun update(): Boolean
open fun update(p0: Int): Boolean