Mincong Lu
1d950e6195
Allow AssetServer::load
to acquire a guard item. ( #13051 )
...
# 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.
---------
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: Zachary Harrold <zac@harrold.com.au>
2024-05-23 13:28:29 +00:00
Ricky Taylor
efcb6d6c11
Make LoadContext use the builder pattern for loading dependent assets ( #13465 )
...
# Objective
- Fixes #13445 .
## Solution
- Removes all `load_` methods from `LoadContext`.
- Introduces `fn loader()` which returns a builder.
## Testing
- I've tested with `cargo test --package=bevy_asset` and run the two
relevant examples (`asset_processing` & `asset_decompression`).
---
## Changelog
- Replaced all `load_` methods on `LoadContext` with the new `loader()`
pattern.
## Migration Guide
- Several LoadContext method calls will need to be updated:
- `load_context.load_with_settings(path, settings)` =>
`load_context.loader().with_settings(settings).load(path)`
- `load_context.load_untyped(path)` =>
`load_context.loader().untyped().load(path)`
- `load_context.load_direct(path)` =>
`load_context.loader().direct().load(path)`
- `load_context.load_direct_untyped(path)` =>
`load_context.loader().direct().untyped().load(path)`
- `load_context.load_direct_with_settings(path, settings)` =>
`load_context.loader().with_settings(settings).direct().load(path)`
- `load_context.load_direct_with_reader(reader, path)` =>
`load_context.loader().direct().with_reader(reader).load(path)`
- `load_context.load_direct_with_reader_and_settings(reader, path,
settings)` =>
`load_context.loader().with_settings(settings).direct().with_reader(reader).load(path)`
- `load_context.load_direct_untyped_with_reader(reader, path)` =>
`load_context.loader().direct().with_reader(reader).untyped().load(path)`
---
CC @alice-i-cecile / @bushrat011899
Examples:
```rust
load_context.loader()
.with_asset_type::<A>()
.with_asset_type_id(TypeId::of::<A>())
.with_settings(|mut settings| { settings.key = value; })
// Then, for a Handle<A>:
.load::<A>()
// Or, for a Handle<LoadedUntypedAsset>:
.untyped()
.load()
// Or, to load an `A` directly:
.direct()
.load::<A>()
.await
// Or, to load an `ErasedLoadedAsset` directly:
.direct()
.untyped()
.load()
.await
```
2024-05-22 23:35:41 +00:00