Skip to content

Commit

Permalink
Merge pull request #132 from josekoalas/bevy_main
Browse files Browse the repository at this point in the history
Update development branch to Bevy 0.11-dev
  • Loading branch information
NiklasEi authored May 28, 2023
2 parents c22b98b + 16922f8 commit f8b37ff
Show file tree
Hide file tree
Showing 29 changed files with 470 additions and 229 deletions.
21 changes: 9 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ jobs:
os: [windows-latest, ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
Expand All @@ -21,10 +21,9 @@ jobs:
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-build-stable-${{ hashFiles('**/Cargo.toml') }}
- uses: actions-rs/toolchain@v1
- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
override: true
- uses: taiki-e/install-action@v1
with:
tool: cargo-hack
Expand All @@ -41,8 +40,8 @@ jobs:
os: [ windows-latest, ubuntu-latest, macos-latest ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
Expand All @@ -51,10 +50,9 @@ jobs:
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-build-stable-${{ hashFiles('**/Cargo.toml') }}
- uses: actions-rs/toolchain@v1
- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
override: true
- uses: taiki-e/install-action@v1
with:
tool: cargo-hack
Expand All @@ -66,8 +64,8 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
Expand All @@ -76,11 +74,10 @@ jobs:
~/.cargo/git/db/
target/
key: ubuntu-latest-cargo-build-stable-${{ hashFiles('**/Cargo.toml') }}
- uses: actions-rs/toolchain@v1
- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
components: rustfmt, clippy
override: true
- name: Install alsa and udev
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev
- name: Run clippy
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

- Fix running loading states in parallel states, meaning using multiple state types (resolves [#125](https://github.com/NiklasEi/bevy_asset_loader/issues/125))
- Dynamic asset files can be loaded multiple times now
- This allows re-entering a loading state containing dynamic assets (see [#126](https://github.com/NiklasEi/bevy_asset_loader/issues/126))
- and loading dynamic assets in multiple states (see [#123](https://github.com/NiklasEi/bevy_asset_loader/issues/123))
- Fix crash with non default exit criteria (see [#121](https://github.com/NiklasEi/bevy_asset_loader/issues/121))

## v0.16.0
- Remove features coming from optional dependencies

## v0.15.0
- Option to load folders as maps of path to handle (resolves [#32](https://github.com/NiklasEi/bevy_asset_loader/issues/32))
- Changed the default file ending for standard dynamic asset files from `.assets` to `.assets.ron`
Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ use bevy_asset_loader::prelude::*;
fn main() {
App::new()
.add_state::<GameState>()
.add_plugins(DefaultPlugins)
.add_loading_state(
LoadingState::new(GameState::AssetLoading)
.continue_to_state(GameState::Next)
)
.add_collection_to_loading_state::<_, MyAssets>(GameState::AssetLoading)
.add_plugins(DefaultPlugins)
.add_system(use_my_assets.in_schedule(OnEnter(GameState::Next)))
.add_systems(OnEnter(GameState::Next), use_my_assets)
.run();
}

Expand Down Expand Up @@ -111,6 +111,8 @@ Dynamic assets can be optional. This requires the derive attribute `optional` on

The example [full_dynamic_collection](/bevy_asset_loader/examples/full_dynamic_collection.rs) shows all supported field types for dynamic assets.

Note that adding a dynamic asset file to a loading state requires the `AssetServer` resource to be available. In most cases that means that you should add the `DefaultPlugins` before configuring your loading state.

### Custom dynamic assets

You can define your own types to load as dynamic assets. Take a look at the [custom_dynamic_assets.rs](/bevy_asset_loader/examples/custom_dynamic_assets.rs) example for some code.
Expand Down Expand Up @@ -402,14 +404,18 @@ struct MyAssets {
}
```

## Unloading assets

Bevy unloads an asset when there are no strong asset handles left pointing to the asset. An `AssetCollection` stores strong handles and ensures that assets contained in it are not removed from memory. If you want to unload assets, you need to remove any `AssetCollection` resource that holds handles pointing to those assets. You, for example, could do this when leaving the state that needed the collection.

## Compatible Bevy versions

The main branch is compatible with the latest Bevy release, while the branch `bevy_main` tries to track the `main` branch of Bevy (PRs updating the tracked commit are welcome).

Compatibility of `bevy_asset_loader` versions:
| `bevy_asset_loader` | `bevy` |
| :-- | :-- |
| `0.15` | `0.10` |
| `0.15` - `0.16` | `0.10` |
| `0.14` | `0.9` |
| `0.12` - `0.13` | `0.8` |
| `0.10` - `0.11` | `0.7` |
Expand Down
20 changes: 10 additions & 10 deletions bevy_asset_loader/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_asset_loader"
version = "0.15.0"
version = "0.17.0-dev"
authors = ["Niklas Eicker <[email protected]>"]
edition = "2021"
license = "MIT OR Apache-2.0"
Expand All @@ -16,23 +16,23 @@ readme = "README.md"
2d = ["bevy/bevy_sprite", "bevy_asset_loader_derive/2d"]
# This feature adds support for bevy's StandardMaterial assets
3d = ["bevy/bevy_pbr", "bevy/bevy_render", "bevy_asset_loader_derive/3d"]
standard_dynamic_assets = ["bevy_common_assets", "serde"]
progress_tracking = ["iyes_progress"]
standard_dynamic_assets = ["dep:bevy_common_assets", "dep:serde"]
progress_tracking = ["dep:iyes_progress"]

[dependencies]
bevy = { version = "0.10", default-features = false, features = ["bevy_asset"] }
bevy_asset_loader_derive = { version = "=0.15.0", path = "../bevy_asset_loader_derive" }
bevy = { git = "https://github.com/bevyengine/bevy", default-features = false, features = ["bevy_asset"] }
bevy_asset_loader_derive = { version = "=0.17.0-dev", path = "../bevy_asset_loader_derive" }
anyhow = "1"

bevy_common_assets = { version = "0.5.0", features = ["ron"], optional = true }
bevy_common_assets = { git = "https://github.com/NiklasEi/bevy_common_assets", branch = "bevy_main", features = ["ron"], optional = true }
serde = { version = "1", optional = true }
iyes_progress = { version = "0.8", optional = true }
iyes_progress = { git = "https://github.com/josekoalas/iyes_progress", branch = "bevy_main", optional = true }

[dev-dependencies]
bevy = { version = "0.10", features = ["vorbis"] }
bevy = { git = "https://github.com/bevyengine/bevy", features = ["vorbis"] }
anyhow = "1"
iyes_progress = { version = "0.8" }
bevy_common_assets = { version = "0.5.0", features = ["ron"] }
iyes_progress = { git = "https://github.com/josekoalas/iyes_progress", branch = "bevy_main" }
bevy_common_assets = { git = "https://github.com/NiklasEi/bevy_common_assets", branch = "bevy_main", features = ["ron"] }
serde = { version = "1" }
trybuild = { version = "1.0" }

Expand Down
9 changes: 6 additions & 3 deletions bevy_asset_loader/examples/atlas_from_grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ use bevy_asset_loader::prelude::*;
fn main() {
App::new()
.add_state::<MyStates>()
.add_plugins(DefaultPlugins)
.add_loading_state(
LoadingState::new(MyStates::AssetLoading).continue_to_state(MyStates::Next),
)
.add_collection_to_loading_state::<_, MyAssets>(MyStates::AssetLoading)
.insert_resource(Msaa::Off)
.add_plugins(DefaultPlugins)
.add_system(draw_atlas.in_schedule(OnEnter(MyStates::Next)))
.add_system(animate_sprite_system.run_if(in_state(MyStates::Next)))
.add_systems(OnEnter(MyStates::Next), draw_atlas)
.add_systems(
Update,
animate_sprite_system.run_if(in_state(MyStates::Next)),
)
.run();
}

Expand Down
2 changes: 1 addition & 1 deletion bevy_asset_loader/examples/custom_dynamic_assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn main() {
"custom.my-assets.ron",
)
.add_collection_to_loading_state::<_, MyAssets>(MyStates::AssetLoading)
.add_system(render_stuff.in_schedule(OnEnter(MyStates::Next)))
.add_systems(OnEnter(MyStates::Next), render_stuff)
.run();
}

Expand Down
8 changes: 6 additions & 2 deletions bevy_asset_loader/examples/dynamic_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ fn main() {
.add_collection_to_loading_state::<_, AudioAssets>(MyStates::AssetLoading)
.insert_resource(Msaa::Off)
.add_systems(
(spawn_player_and_tree, play_background_audio).in_schedule(OnEnter(MyStates::Next)),
OnEnter(MyStates::Next),
(spawn_player_and_tree, play_background_audio),
)
.add_systems(
Update,
animate_sprite_system.run_if(in_state(MyStates::Next)),
)
.add_system(animate_sprite_system.run_if(in_state(MyStates::Next)))
.run();
}

Expand Down
6 changes: 3 additions & 3 deletions bevy_asset_loader/examples/failure_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ fn main() {
.on_failure_continue_to_state(MyStates::ErrorScreen),
)
.add_collection_to_loading_state::<_, MyAssets>(MyStates::AssetLoading)
.add_system(timeout.run_if(in_state(MyStates::AssetLoading)))
.add_system(fail.in_schedule(OnEnter(MyStates::Next)))
.add_system(ok.in_schedule(OnEnter(MyStates::ErrorScreen)))
.add_systems(Update, timeout.run_if(in_state(MyStates::AssetLoading)))
.add_systems(OnEnter(MyStates::Next), fail)
.add_systems(OnEnter(MyStates::ErrorScreen), ok)
.run();
}

Expand Down
21 changes: 6 additions & 15 deletions bevy_asset_loader/examples/full_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use bevy::asset::LoadState;
use bevy::prelude::*;
use bevy::utils::HashMap;
use bevy_asset_loader::prelude::*;
use std::path::Path;

fn main() {
App::new()
Expand All @@ -12,7 +13,7 @@ fn main() {
LoadingState::new(MyStates::AssetLoading).continue_to_state(MyStates::Next),
)
.add_collection_to_loading_state::<_, MyAssets>(MyStates::AssetLoading)
.add_system(expectations.in_schedule(OnEnter(MyStates::Next)))
.add_systems(OnEnter(MyStates::Next), expectations)
.run();
}

Expand Down Expand Up @@ -166,13 +167,8 @@ fn expectations(
LoadState::Loaded
);
assert_eq!(
name,
asset_server
.get_handle_path(handle.clone())
.unwrap()
.path()
.to_str()
.unwrap()
Path::new(name),
asset_server.get_handle_path(handle.clone()).unwrap().path()
);
}
assert_eq!(assets.mapped_files_typed.len(), 2);
Expand All @@ -182,13 +178,8 @@ fn expectations(
LoadState::Loaded
);
assert_eq!(
name,
asset_server
.get_handle_path(handle.clone())
.unwrap()
.path()
.to_str()
.unwrap()
Path::new(name),
asset_server.get_handle_path(handle.clone()).unwrap().path()
);
}

Expand Down
2 changes: 1 addition & 1 deletion bevy_asset_loader/examples/full_dynamic_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn main() {
"full_dynamic_collection.assets.ron",
)
.add_collection_to_loading_state::<_, MyAssets>(MyStates::AssetLoading)
.add_system(expectations.run_if(in_state(MyStates::Next)))
.add_systems(Update, expectations.run_if(in_state(MyStates::Next)))
.run();
}

Expand Down
4 changes: 2 additions & 2 deletions bevy_asset_loader/examples/init_resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ use bevy_asset_loader::prelude::*;
/// them by adding up their pixel data.
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_state::<MyStates>()
.add_loading_state(
LoadingState::new(MyStates::AssetLoading).continue_to_state(MyStates::Next),
)
.add_collection_to_loading_state::<_, ImageAssets>(MyStates::AssetLoading)
.init_resource_after_loading_state::<_, CombinedImage>(MyStates::AssetLoading)
.insert_resource(Msaa::Off)
.add_plugins(DefaultPlugins)
.add_system(draw.in_schedule(OnEnter(MyStates::Next)))
.add_systems(OnEnter(MyStates::Next), draw)
.run();
}

Expand Down
23 changes: 16 additions & 7 deletions bevy_asset_loader/examples/manual_dynamic_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,23 @@ fn main() {
.insert_resource(Msaa::Off)
.insert_resource(ShowBackground(false))
.add_systems(
(spawn_player_and_tree, play_background_audio).in_schedule(OnEnter(MyStates::Next)),
OnEnter(MyStates::Next),
(
spawn_player_and_tree,
play_background_audio,
render_optional_background,
),
)
.add_systems(OnEnter(MyStates::Menu), menu)
.add_systems(OnExit(MyStates::Menu), exit_menu)
.add_systems(
Update,
(
character_setup.run_if(in_state(MyStates::Menu)),
update_menu.run_if(in_state(MyStates::Menu)),
move_player.run_if(in_state(MyStates::Next)),
),
)
.add_system(menu.in_schedule(OnEnter(MyStates::Menu)))
.add_system(character_setup.run_if(in_state(MyStates::Menu)))
.add_system(update_menu.run_if(in_state(MyStates::Menu)))
.add_system(exit_menu.in_schedule(OnExit(MyStates::Menu)))
.add_system(render_optional_background.in_schedule(OnEnter(MyStates::Next)))
.add_system(move_player.run_if(in_state(MyStates::Next)))
.run();
}

Expand Down
4 changes: 2 additions & 2 deletions bevy_asset_loader/examples/no_loading_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ fn main() {
// This requires the extension trait `AssetCollectionApp` to be in scope.
.init_collection::<ImageAssets>()
// This system listens for mouse clicks and then loads + inserts the AudioAssets collection
.add_system(load_and_play_audio)
.add_system(draw.on_startup())
.add_systems(Startup, draw)
.add_systems(Update, load_and_play_audio)
.run();
}

Expand Down
Loading

0 comments on commit f8b37ff

Please sign in to comment.