Skip to content

Commit

Permalink
Merge pull request #117 from NiklasEi/bevy_main
Browse files Browse the repository at this point in the history
Update to Bevy 0.13
  • Loading branch information
NiklasEi authored Feb 17, 2024
2 parents ca55350 + 7d84938 commit 763cd92
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 46 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## v0.19.0 - 17.02.2024
- Update to Bevy `0.13`

## v0.18.0 - 04.11.2023
- Update to Bevy `0.12`

Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_kira_audio"
version = "0.18.0"
version = "0.19.0"
authors = ["Niklas Eicker <[email protected]>"]
edition = "2021"
license = "MIT OR Apache-2.0"
Expand All @@ -22,7 +22,7 @@ wav = ["kira/wav"]
settings_loader = ["dep:ron", "dep:serde", "kira/serde"]

[dependencies]
bevy = { version = "0.12", default-features = false, features = ["bevy_asset"] }
bevy = { version = "0.13", default-features = false, features = ["bevy_asset"] }
anyhow = "1.0"
uuid = { version = "1", features = ["fast-rng"] }
kira = { version = "0.8", default-features = false, features = ["cpal"] }
Expand All @@ -32,7 +32,7 @@ parking_lot = "0.12"
thiserror = "1.0"

[dev-dependencies.bevy]
version = "0.12"
version = "0.13"
default-features = false
features = [
"bevy_asset",
Expand Down
31 changes: 17 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Sound can be played in channels. Each channel has controls to pause or stop play

## Usage

*Note: the Bevy feature `bevy_audio` is enabled by default and not compatible with this plugin. Make sure to not have the `bevy_audio` feature enabled if you want to use `bevy_kira_audio`. The same goes for Bevy's `vorbis` feature. See [Bevys' Cargo file](https://github.com/bevyengine/bevy/blob/v0.12.0/Cargo.toml#L33-L57) for a list of all default features of version `0.12` and list them manually in your Cargo file excluding the ones you do not want. Make sure to set `default-features` to `false` for the Bevy dependency. You can take a look at [bevy_game_template's cargo file as an example](https://github.com/NiklasEi/bevy_game_template/blob/main/Cargo.toml).*
*Note: the Bevy feature `bevy_audio` is enabled by default and not compatible with this plugin. Make sure to not have the `bevy_audio` feature enabled if you want to use `bevy_kira_audio`. The same goes for Bevy's `vorbis` feature. See [Bevys' Cargo file][bevy_default_features] for a list of all default features of version `0.12` and list them manually in your Cargo file excluding the ones you do not want. Make sure to set `default-features` to `false` for the Bevy dependency. You can take a look at [bevy_game_template's cargo file as an example](https://github.com/NiklasEi/bevy_game_template/blob/main/Cargo.toml).*


To play audio, you usually want to load audio files as assets. This requires `AssetLoaders`. `bevy_kira_audio` comes with loaders for most common audio formats. You can enable them with the features `ogg` (enabled by default), `mp3`, `wav`, or `flac`. The following example assumes that the feature `ogg` is enabled.
Expand Down Expand Up @@ -88,19 +88,21 @@ There is limited spacial audio support. Currently, only the volume of audio and
The main branch is compatible with the latest Bevy release.

Compatibility of `bevy_kira_audio` versions:
| `bevy_kira_audio` | `bevy` |
| :-- | :-- |
| `0.18` | `0.12` |
| `0.16` - `0.17` | `0.11` |
| `0.15` | `0.10` |
| `0.13` - `0.14` | `0.9` |
| `0.11` - `0.12` | `0.8` |
| `0.9` - `0.10` | `0.7` |
| `0.8` | `0.6` |
| `0.4` - `0.7` | `0.5` |
| `0.3` | `0.4` |
| `main` | `0.12` |
| `bevy_main` | `main` |

| Bevy version | `bevy_kira_audio` version |
|:-------------|:--------------------------|
| `0.13` | `0.19` |
| `0.12` | `0.18` |
| `0.11` | `0.16` - `0.17` |
| `0.10` | `0.15` |
| `0.9` | `0.13` - `0.14` |
| `0.8` | `0.11` - `0.12` |
| `0.7` | `0.9` - `0.10` |
| `0.6` | `0.8` |
| `0.5` | `0.4` - `0.7` |
| `0.4` | `0.3` |
| `0.13` | `main` |
| `main` | `bevy_main` |

## License

Expand All @@ -122,3 +124,4 @@ additional terms or conditions.


[kira]: https://github.com/tesselode/kira
[bevy_default_features]: https://github.com/bevyengine/bevy/blob/v0.13.0/Cargo.toml#L55-L80
2 changes: 1 addition & 1 deletion examples/channel_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn main() {
.run()
}

fn channel_control(input: Res<Input<MouseButton>>, audio: Res<Audio>) {
fn channel_control(input: Res<ButtonInput<MouseButton>>, audio: Res<Audio>) {
if input.just_pressed(MouseButton::Left) {
audio
.pause()
Expand Down
2 changes: 1 addition & 1 deletion examples/dynamic_channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn start_background_audio(
fn plop(
handle: Res<AudioHandle>,
audio: Res<DynamicAudioChannels>,
input: Res<Input<MouseButton>>,
input: Res<ButtonInput<MouseButton>>,
) {
if input.just_pressed(MouseButton::Left) {
audio.channel("example").play(handle.0.clone());
Expand Down
2 changes: 1 addition & 1 deletion examples/instance_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn main() {
fn instance_control(
handle: Res<InstanceHandle>,
mut audio_instances: ResMut<Assets<AudioInstance>>,
input: Res<Input<MouseButton>>,
input: Res<ButtonInput<MouseButton>>,
) {
if let Some(instance) = audio_instances.get_mut(&handle.0) {
if input.just_pressed(MouseButton::Left) {
Expand Down
2 changes: 1 addition & 1 deletion examples/multiple_channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ fn spawn_button<T: Component + Clone>(
font: font.clone(),
},
}],
alignment: TextAlignment::Center,
justify: JustifyText::Center,
..Default::default()
},
..Default::default()
Expand Down
24 changes: 10 additions & 14 deletions examples/spacial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,10 @@ fn setup(
..default()
});
commands.spawn(PbrBundle {
mesh: meshes.add(
shape::Plane {
size: 50.,
subdivisions: 0,
}
.into(),
),
material: materials.add(Color::DARK_GREEN.into()),
mesh: meshes.add(Cuboid {
half_size: Vec3::new(25., 0., 25.),
}),
material: materials.add(Color::DARK_GREEN),
..default()
});
}
Expand Down Expand Up @@ -131,7 +127,7 @@ fn initial_grab_cursor(mut primary_window: Query<&mut Window, With<PrimaryWindow
}

fn cursor_grab(
keys: Res<Input<KeyCode>>,
keys: Res<ButtonInput<KeyCode>>,
mut primary_window: Query<&mut Window, With<PrimaryWindow>>,
) {
if let Ok(mut window) = primary_window.get_single_mut() {
Expand Down Expand Up @@ -159,7 +155,7 @@ fn toggle_grab_cursor(window: &mut Window) {

/// Handles keyboard input and movement
fn player_move(
keys: Res<Input<KeyCode>>,
keys: Res<ButtonInput<KeyCode>>,
time: Res<Time>,
primary_window: Query<&Window, With<PrimaryWindow>>,
mut query: Query<&mut Transform, With<FlyCam>>,
Expand All @@ -175,10 +171,10 @@ fn player_move(
match window.cursor.grab_mode {
CursorGrabMode::None => (),
_ => match key {
KeyCode::W => velocity += forward,
KeyCode::S => velocity -= forward,
KeyCode::A => velocity -= right,
KeyCode::D => velocity += right,
KeyCode::KeyW => velocity += forward,
KeyCode::KeyS => velocity -= forward,
KeyCode::KeyA => velocity -= right,
KeyCode::KeyD => velocity += right,
KeyCode::Space => velocity += Vec3::Y,
KeyCode::ShiftLeft => velocity -= Vec3::Y,
_ => (),
Expand Down
10 changes: 5 additions & 5 deletions examples/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ fn start_audio(mut commands: Commands, asset_server: Res<AssetServer>, audio: Re
commands.insert_resource(LoopAudioInstanceHandle(instance_handle));
}

fn process_keyboard_input(audio: Res<Audio>, kb: Res<Input<KeyCode>>) {
if kb.just_pressed(KeyCode::P) {
fn process_keyboard_input(audio: Res<Audio>, kb: Res<ButtonInput<KeyCode>>) {
if kb.just_pressed(KeyCode::KeyP) {
audio.pause().linear_fade_out(Duration::from_millis(500));
println!("Audio pausing...");
} else if kb.just_pressed(KeyCode::S) {
} else if kb.just_pressed(KeyCode::KeyS) {
audio.stop().fade_out(AudioTween::new(
Duration::from_secs(1),
AudioEasing::InOutPowi(2),
));
println!("Audio stopping...");
} else if kb.just_pressed(KeyCode::R) {
} else if kb.just_pressed(KeyCode::KeyR) {
audio.resume().fade_in(AudioTween::new(
Duration::from_millis(500),
AudioEasing::InOutPowi(4),
Expand Down Expand Up @@ -99,7 +99,7 @@ fn display_help_text(mut commands: Commands, asset_server: Res<AssetServer>) {
},
},
],
alignment: TextAlignment::Center,
justify: JustifyText::Center,
..Default::default()
},
..Default::default()
Expand Down
4 changes: 2 additions & 2 deletions examples/stress_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct AudioHandle(Handle<AudioSource>);

fn prepare(asset_server: Res<AssetServer>, mut commands: Commands, audio: Res<Audio>) {
// Stop our ears from exploding...
// Playing multiple sounds in the same frame gets
// Playing multiple sounds in the same frame can get quite loud
audio.set_volume(0.001);
commands.insert_resource(LoadingAudioHandle(asset_server.load("sounds/plop.ogg")))
}
Expand All @@ -55,7 +55,7 @@ fn play(handle: Option<Res<AudioHandle>>, audio: Res<Audio>) {
// The max number here depends on your hardware.
// If you get warnings and/or stuttered sounds try reducing the amount and/or changing the
// capacities of the `AudioSettings` in the `main` method.
for _ in 0..75 {
for _ in 0..100 {
audio.play(handle.0.clone());
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
//! }
//!
//! # fn stop(mut events: EventWriter<AppExit>) {
//! # events.send(AppExit)
//! # events.send(AppExit);
//! # }
//! ```
Expand Down Expand Up @@ -131,7 +131,7 @@ pub use instance::AudioInstanceAssetsExt;
/// }
///
/// # fn stop(mut events: EventWriter<AppExit>) {
/// # events.send(AppExit)
/// # events.send(AppExit);
/// # }
/// ```
#[derive(Default)]
Expand Down Expand Up @@ -169,11 +169,11 @@ impl Plugin for AudioPlugin {
PreUpdate,
cleanup_stopped_spacial_instances
.in_set(AudioSystemSet::InstanceCleanup)
.run_if(resource_exists::<SpacialAudio>()),
.run_if(resource_exists::<SpacialAudio>),
)
.add_systems(
PostUpdate,
run_spacial_audio.run_if(resource_exists::<SpacialAudio>()),
run_spacial_audio.run_if(resource_exists::<SpacialAudio>),
);
}
}
Expand Down

0 comments on commit 763cd92

Please sign in to comment.