-
-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewrite AssetStorage to the new ktx-async API #182
Comments
I'm making changes to a project I created two years ago in which I used the previous version of I see that Would you say the wise move right now is to switch to using |
@amitkot For now, yes. There were some issues with thread safety and unstable coroutines API usage, and I'm afraid |
@Quillraven @cypherdare @Jkly @maltaisn @jcornaz @amitkot I finally decided to rewrite the good old To be honest, this is probably among top 5 most fun, challenging and complex pieces of code I've written. The initial implementation would definitely not pass the extensive tests I've written this time, including concurrent assets loading and unloading on multiple threads and coroutines. I think the current implementation is fully thread-safe and non-blocking. Unless the user of the API blocks the rendering or loading threads manually with Anyway, I would appreciate it very much if you took the time to try
I'll leave the pull request open awaiting suggestions while I focus on the documentation and Thanks. |
|
Ironically, after implementing this I found this obscure feature called
Edit: other than having to make the parameters nullable and create them dynamically for supported asset types, this would be as easy as: import com.badlogic.gdx.assets.AssetLoaderParameters
import com.badlogic.gdx.assets.AssetLoaderParameters.LoadedCallback
import com.badlogic.gdx.assets.AssetManager
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.Deferred
inline fun <reified T> AssetManager.loadAsync(
path: String, parameters: AssetLoaderParameters<T>
): Deferred<T> {
val result = CompletableDeferred<T>()
parameters.loadedCallback = LoadedCallback { assetManager, fileName, type ->
@Suppress("UNCHECKED_CAST") val assetClass = type as Class<T>
try {
result.complete(assetManager.get(fileName, assetClass) as T)
} catch (exception: Throwable) {
result.completeExceptionally(exception)
}
}
load(path, T::class.java, parameters)
return result
} Oh well. |
Asynchronous coroutines-based asset manager: AssetLoader #182
I believe the current I want to thank @Quillraven again for testing and review of the new asset manager. I'd ship a lot less features and a clunky API if not for the input and feature requests. Since there were no further comments, I'm closing this issue for now. If you'd like you make a feature request or comment regarding the |
@czyzby I have been on a bit of LibGDX hiatus for the past three months. I looked this over briefly and it looks slick. I don't currently have a project in need of this feature to try it out in currently, though. |
ktx-assets-async
module.AssetStorage
rewrite.ktx-freetype-async
, update to new API.TextAssetLoader
, move toktx-assets
.AssetStorage
was removed during thektx-async
overhaul in1.9.9-b1
due to reliance on old coroutines API and threading issues. The goal of this task is to rewriteAssetStorage
in a fully thread-safe way, without reliance on specific coroutines dispatchers for asynchronous tasks.The text was updated successfully, but these errors were encountered: