Skip to content

Commit

Permalink
Update to Bevy 0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
NiklasEi committed Jul 13, 2023
1 parent 9e71b55 commit 1314f23
Show file tree
Hide file tree
Showing 19 changed files with 97 additions and 110 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.16.0
- Update to Bevy `0.11`

## v0.15.0
- Update to Bevy `0.10`
- Fix: stop spacial audio from getting louder again at large distances ([#88](https://github.com/NiklasEi/bevy_kira_audio/issues/88))
Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_kira_audio"
version = "0.16.0-dev"
version = "0.16.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.10", default-features = false, features = ["bevy_asset"] }
bevy = { version = "0.11", default-features = false, features = ["bevy_asset"] }
anyhow = "1.0"
kira = { version = "0.8", default-features = false, features = ["cpal"] }
ron = { version = "0.8", optional = true }
Expand All @@ -31,7 +31,7 @@ parking_lot = "0.12"
thiserror = "1.0"

[dev-dependencies.bevy]
version = "0.10"
version = "0.11"
default-features = false
features = [
"bevy_asset",
Expand All @@ -44,7 +44,7 @@ features = [
"bevy_sprite",
"bevy_gltf",
"bevy_scene",
"bevy_pbr"
"bevy_pbr","tonemapping_luts", "ktx2" , "zstd"
]

[[example]]
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ use bevy::prelude::*;

fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(AudioPlugin)
.add_system(start_background_audio.on_startup())
.add_plugins((DefaultPlugins, AudioPlugin))
.add_systems(Startup, start_background_audio)
.run();
}

Expand Down Expand Up @@ -91,6 +90,7 @@ The main branch is compatible with the latest Bevy release.
Compatibility of `bevy_kira_audio` versions:
| `bevy_kira_audio` | `bevy` |
| :-- | :-- |
| `0.16` | `0.11` |
| `0.15` | `0.10` |
| `0.13` - `0.14` | `0.9` |
| `0.11` - `0.12` | `0.8` |
Expand Down
5 changes: 2 additions & 3 deletions examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ use bevy_kira_audio::prelude::*;

fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(AudioPlugin)
.add_system(play_loop.on_startup())
.add_plugins((DefaultPlugins, AudioPlugin))
.add_systems(Startup, play_loop)
.run()
}

Expand Down
17 changes: 11 additions & 6 deletions examples/channel_control.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
use bevy::prelude::*;
use bevy_kira_audio::prelude::*;
use kira::tween::Easing;
use std::time::Duration;

// This example demonstrates how to control an audio channel
// This kind of control is deferred to the end of the current frame update
// Left-click to pause the audio
// Right-click to resume the audio
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(AudioPlugin)
.add_system(play_loop.on_startup())
.add_system(channel_control)
.add_plugins((DefaultPlugins, AudioPlugin))
.add_systems(Startup, play_loop)
.add_systems(Update, channel_control)
.run()
}

fn channel_control(input: Res<Input<MouseButton>>, audio: Res<Audio>) {
if input.just_pressed(MouseButton::Left) {
audio.pause().fade_out(AudioTween::default());
audio
.pause()
.fade_out(AudioTween::new(Duration::from_secs(2), Easing::Linear));
} else if input.just_pressed(MouseButton::Right) {
audio.resume().fade_in(AudioTween::default());
audio
.resume()
.fade_in(AudioTween::new(Duration::from_secs(2), Easing::Linear));
}
}

Expand Down
5 changes: 2 additions & 3 deletions examples/custom_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ use bevy_kira_audio::prelude::*;

fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(AudioPlugin)
.add_plugins((DefaultPlugins, AudioPlugin))
// add our custom audio channel
.add_audio_channel::<Background>()
.add_system(play.on_startup())
.add_systems(Startup, play)
.run();
}

Expand Down
7 changes: 3 additions & 4 deletions examples/dynamic_channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ use bevy_kira_audio::prelude::*;
/// that is not known at compile time, you can create and use dynamic channels based on string keys.
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(AudioPlugin)
.add_system(start_background_audio.on_startup())
.add_system(plop)
.add_plugins((DefaultPlugins, AudioPlugin))
.add_systems(Startup, start_background_audio)
.add_systems(Update, plop)
.run()
}

Expand Down
7 changes: 3 additions & 4 deletions examples/instance_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ use bevy_kira_audio::prelude::*;
// sent to the audio thread immediately.
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(AudioPlugin)
.add_system(play_loop.on_startup())
.add_system(instance_control)
.add_plugins((DefaultPlugins, AudioPlugin))
.add_systems(Startup, play_loop)
.add_systems(Update, instance_control)
.run()
}

Expand Down
33 changes: 18 additions & 15 deletions examples/multiple_channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ use std::marker::PhantomData;
// This is a bigger example with a GUI for full control over three audio channels
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(AudioPlugin)
.add_plugins((DefaultPlugins, AudioPlugin))
.init_resource::<LastAction>()
.add_system(prepare_audio_and_ui.on_startup())
.add_systems(create_row_systems::<FirstChannel>())
.add_systems(create_row_systems::<SecondChannel>())
.add_systems(create_row_systems::<ThirdChannel>())
.add_systems(Startup, prepare_audio_and_ui)
.add_systems(Update, create_row_systems::<FirstChannel>())
.add_systems(Update, create_row_systems::<SecondChannel>())
.add_systems(Update, create_row_systems::<ThirdChannel>())
.add_audio_channel::<FirstChannel>()
.add_audio_channel::<SecondChannel>()
.add_audio_channel::<ThirdChannel>()
Expand Down Expand Up @@ -57,7 +56,7 @@ fn play_pause_button<T: Component + Default>(
if channel_state.stopped {
return;
}
if interaction == &Interaction::Clicked {
if interaction == &Interaction::Pressed {
if !last_action.action(&time) {
return;
}
Expand Down Expand Up @@ -88,7 +87,7 @@ fn stop_button<T: Component + Default>(
if channel_state.stopped {
return;
}
if interaction == &Interaction::Clicked {
if interaction == &Interaction::Pressed {
if !last_action.action(&time) {
return;
}
Expand Down Expand Up @@ -118,7 +117,7 @@ fn loop_button<T: Component + Default>(
if channel_state.loop_started {
return;
}
if interaction == &Interaction::Clicked {
if interaction == &Interaction::Pressed {
if !last_action.action(&time) {
return;
}
Expand All @@ -142,7 +141,7 @@ fn play_sound_button<T: Component + Default>(
} else {
NORMAL_BUTTON.into()
};
if interaction == &Interaction::Clicked {
if interaction == &Interaction::Pressed {
if !last_action.action(&time) {
return;
}
Expand All @@ -165,7 +164,7 @@ fn volume_buttons<T: Component + Default>(
} else {
NORMAL_BUTTON.into()
};
if interaction == &Interaction::Clicked {
if interaction == &Interaction::Pressed {
if !last_action.action(&time) {
return;
}
Expand Down Expand Up @@ -280,7 +279,8 @@ fn set_up_ui(commands: &mut Commands, asset_server: ResMut<AssetServer>) {
style: Style {
display: Display::Flex,
flex_direction: FlexDirection::Column,
size: Size::new(Val::Percent(100.), Val::Percent(100.)),
width: Val::Percent(100.),
height: Val::Percent(100.),
..Default::default()
},
..Default::default()
Expand All @@ -302,7 +302,8 @@ fn build_button_row<T: Component + Default + Clone>(
style: Style {
display: Display::Flex,
flex_direction: FlexDirection::Row,
size: Size::new(Val::Percent(100.), Val::Percent(33.3)),
width: Val::Percent(100.),
height: Val::Percent(33.3),
..Default::default()
},
..Default::default()
Expand All @@ -311,7 +312,8 @@ fn build_button_row<T: Component + Default + Clone>(
parent
.spawn(NodeBundle {
style: Style {
size: Size::new(Val::Px(120.0), Val::Percent(100.)),
width: Val::Px(120.0),
height: Val::Percent(100.),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..Default::default()
Expand Down Expand Up @@ -395,7 +397,8 @@ fn spawn_button<T: Component + Clone>(
parent
.spawn(ButtonBundle {
style: Style {
size: Size::new(Val::Px(100.0), Val::Px(65.0)),
width: Val::Px(100.0),
height: Val::Px(65.0),
margin: UiRect::all(Val::Auto),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
Expand Down
5 changes: 2 additions & 3 deletions examples/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ use std::time::Duration;
/// This example shows the different settings that can be applied when playing a sound.
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(AudioPlugin)
.add_system(play_audio.on_startup())
.add_plugins((DefaultPlugins, AudioPlugin))
.add_systems(Startup, play_audio)
.run();
}

Expand Down
5 changes: 2 additions & 3 deletions examples/settings_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ use bevy_kira_audio::prelude::*;
/// You can also easily apply settings when playing a sound (see the `settings` example).
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(AudioPlugin)
.add_system(play_audio.on_startup())
.add_plugins((DefaultPlugins, AudioPlugin))
.add_systems(Startup, play_audio)
.run();
}

Expand Down
15 changes: 5 additions & 10 deletions examples/spacial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ use bevy_kira_audio::prelude::*;

fn main() {
App::new()
.insert_resource(Msaa::Off)
.insert_resource(SpacialAudio { max_distance: 25. })
.add_plugins(DefaultPlugins)
.add_plugin(AudioPlugin)
.add_plugin(CameraPlugin)
.add_system(setup.on_startup())
.add_plugins((DefaultPlugins, AudioPlugin, CameraPlugin))
.add_systems(Startup, setup)
.run()
}

Expand Down Expand Up @@ -120,10 +117,8 @@ pub struct FlyCam;
impl Plugin for CameraPlugin {
fn build(&self, app: &mut App) {
app.init_resource::<InputState>()
.add_system(initial_grab_cursor.on_startup())
.add_system(player_move)
.add_system(player_look)
.add_system(cursor_grab);
.add_systems(Startup, initial_grab_cursor)
.add_systems(Update, (player_move, player_look, cursor_grab));
}
}

Expand Down Expand Up @@ -185,7 +180,7 @@ fn player_move(
KeyCode::A => velocity -= right,
KeyCode::D => velocity += right,
KeyCode::Space => velocity += Vec3::Y,
KeyCode::LShift => velocity -= Vec3::Y,
KeyCode::ShiftLeft => velocity -= Vec3::Y,
_ => (),
},
}
Expand Down
15 changes: 5 additions & 10 deletions examples/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ struct LoopAudioInstanceHandle(Handle<AudioInstance>);

fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(AudioPlugin)
.add_system(start_audio.on_startup())
.add_system(display_help_text.on_startup())
.add_system(print_status)
.add_system(process_keyboard_input)
.add_plugins((DefaultPlugins, AudioPlugin))
.add_systems(Startup, (start_audio, display_help_text))
.add_systems(Update, (print_status, process_keyboard_input))
.run();
}

Expand Down Expand Up @@ -56,10 +53,8 @@ fn display_help_text(mut commands: Commands, asset_server: Res<AssetServer>) {
commands
.spawn(NodeBundle {
style: Style {
size: Size {
width: Val::Percent(100.),
height: Val::Percent(100.),
},
width: Val::Percent(100.),
height: Val::Percent(100.),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..Default::default()
Expand Down
10 changes: 5 additions & 5 deletions examples/stress_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,16 @@ use bevy_kira_audio::prelude::*;
/// Depending on your machine, the number of sounds you can play before audio issues appear may differ.
fn main() {
App::new()
.add_plugins(DefaultPlugins)
// We need to increase the queue sizes of the audio backend.
// The default is 128 per queue, which is way too low for playing as many sounds
// as this example does.
.insert_resource(AudioSettings {
sound_capacity: 8192,
command_capacity: 4096,
})
.add_plugin(AudioPlugin)
.add_system(prepare.on_startup())
.add_system(check)
.add_system(play)
.add_plugins((DefaultPlugins, AudioPlugin))
.add_systems(Startup, prepare)
.add_systems(Update, (check, play))
.run()
}

Expand Down Expand Up @@ -54,6 +52,8 @@ fn check(

fn play(handle: Option<Res<AudioHandle>>, audio: Res<Audio>) {
if let Some(handle) = handle {
// the max number here depends on your hardware.
// If you get warnings and/or stuttered sounds try reducing the amount.
for _ in 0..75 {
audio.play(handle.0.clone());
}
Expand Down
Loading

0 comments on commit 1314f23

Please sign in to comment.