bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Allow `AssetServer::load` to acquire a guard item.

Open mintlu8 opened this issue 1 year ago • 4 comments

Objective

Supercedes #12881 . Added a simple implementation that allows the user to react to multiple asset loads both synchronously and asynchronously.

Solution

Added load_acquire, that holds an item and drops it when loading is finished or failed.

When used synchronously

Hold an Arc<()>, check for Arc::strong_count() == 1 when all loading completed.

When used asynchronously

Hold a SemaphoreGuard, await on acquire_all for completion.

This implementation has more freedom than the original in my opinion.

mintlu8 avatar Apr 21 '24 13:04 mintlu8

The generated examples/README.md is out of sync with the example metadata in Cargo.toml or the example readme template. Please run cargo run -p build-templated-pages -- update examples to update it, and commit the file change.

github-actions[bot] avatar May 17 '24 01:05 github-actions[bot]

The generated examples/README.md is out of sync with the example metadata in Cargo.toml or the example readme template. Please run cargo run -p build-templated-pages -- update examples to update it, and commit the file change.

github-actions[bot] avatar May 17 '24 01:05 github-actions[bot]

Could you add an example demonstrating how one might use this? This seems like a really neat design, but making the jump from "cool API" to "practical use" has been a perpetual challenge for users of bevy_asset.

Added an example to show how this works.

mintlu8 avatar May 17 '24 02:05 mintlu8

Okay, that example was super useful! I now understand the point of this PR much better, and now it can be more easily taught and tested.

I've left a few comments for suggestions on how to make the example a bit gentler on beginners :) I think that I would also hook into Bevy's states to define whether or not asset loading is done, but I'm happy to get pushback if you feel otherwise.

Thanks! I made a few more updates to the example. I think it is now more useful as a template or as a guide to beginners.

mintlu8 avatar May 18 '24 01:05 mintlu8