Skip to content

Commit

Permalink
Update to Bevy 0.14.0-rc.2
Browse files Browse the repository at this point in the history
  • Loading branch information
NiklasEi committed Jun 9, 2024
1 parent 02dc1f4 commit 6d11574
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 133 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ wav = ["kira/wav"]
settings_loader = ["dep:ron", "dep:serde", "kira/serde"]

[dependencies]
bevy = { version = "0.13", default-features = false, features = ["bevy_asset"] }
bevy = { version = "0.14.0-rc.2", 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.13"
version = "0.14.0-rc.2"
default-features = false
features = [
"bevy_asset",
Expand All @@ -49,7 +49,7 @@ features = [
"tonemapping_luts",
"ktx2",
"zstd",
"multi-threaded",
"multi_threaded"
]

[[example]]
Expand Down
6 changes: 2 additions & 4 deletions src/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ use bevy::app::{App, PreUpdate};
use bevy::asset::{AssetId, Handle};
use bevy::ecs::system::Resource;
use bevy::prelude::{default, IntoSystemConfigs, PostUpdate};
use bevy::utils::Uuid;
use kira::sound::static_sound::{StaticSoundData, StaticSoundHandle};
use kira::sound::EndPosition;
use kira::tween::Value;
use kira::Volume;
use std::marker::PhantomData;
use std::time::Duration;
use uuid::Uuid;

pub(crate) enum AudioCommand {
Play(PlayAudioSettings),
Expand Down Expand Up @@ -186,9 +186,7 @@ impl<'a> Drop for PlayAudioCommand<'a> {

impl<'a> PlayAudioCommand<'a> {
pub(crate) fn new(source: Handle<AudioSource>, que: &'a dyn AudioCommandQue) -> Self {
let asset_id = AssetId::Uuid {
uuid: Uuid::new_v4(),
};
let asset_id = AssetId::from(Uuid::new_v4());
Self {
instance_handle: Handle::<AudioInstance>::Weak(asset_id),
source,
Expand Down
36 changes: 19 additions & 17 deletions src/audio_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,18 +464,21 @@ mod test {
use crate::{Audio, AudioPlugin};
use bevy::asset::{AssetId, AssetPlugin};
use bevy::prelude::*;
use bevy::utils::Uuid;
use kira::manager::backend::mock::MockBackend;
use kira::manager::AudioManagerSettings;
use uuid::Uuid;

#[test]
fn keeps_order_of_commands_to_retry() {
// we only need this app to conveniently get a assets collection for `AudioSource`...
let mut app = App::new();
app.add_plugins((MinimalPlugins, AssetPlugin::default(), AudioPlugin));
let audio_source_assets = app.world.remove_resource::<Assets<AudioSource>>().unwrap();
let audio_source_assets = app
.world_mut()
.remove_resource::<Assets<AudioSource>>()
.unwrap();
let mut audio_instance_assets = app
.world
.world_mut()
.remove_resource::<Assets<AudioInstance>>()
.unwrap();

Expand All @@ -484,12 +487,10 @@ mod test {
instances: HashMap::default(),
channels: HashMap::default(),
};
let audio_handle_one: Handle<AudioSource> = Handle::<AudioSource>::Weak(AssetId::Uuid {
uuid: Uuid::from_u128(1758302748397294),
});
let audio_handle_two: Handle<AudioSource> = Handle::<AudioSource>::Weak(AssetId::Uuid {
uuid: Uuid::from_u128(2537024739048739),
});
let audio_handle_one: Handle<AudioSource> =
Handle::<AudioSource>::Weak(AssetId::from(Uuid::from_u128(1758302748397294)));
let audio_handle_two: Handle<AudioSource> =
Handle::<AudioSource>::Weak(AssetId::from(Uuid::from_u128(2537024739048739)));

let channel = AudioChannel::<Audio>::default();
channel.play(audio_handle_one.clone());
Expand Down Expand Up @@ -518,9 +519,12 @@ mod test {
// we only need this app to conveniently get a assets collection for `AudioSource`...
let mut app = App::new();
app.add_plugins((MinimalPlugins, AssetPlugin::default(), AudioPlugin));
let audio_source_assets = app.world.remove_resource::<Assets<AudioSource>>().unwrap();
let audio_source_assets = app
.world_mut()
.remove_resource::<Assets<AudioSource>>()
.unwrap();
let mut audio_instance_assets = app
.world
.world_mut()
.remove_resource::<Assets<AudioInstance>>()
.unwrap();

Expand All @@ -529,12 +533,10 @@ mod test {
instances: HashMap::default(),
channels: HashMap::default(),
};
let audio_handle_one: Handle<AudioSource> = Handle::<AudioSource>::Weak(AssetId::Uuid {
uuid: Uuid::from_u128(13290473942075938),
});
let audio_handle_two: Handle<AudioSource> = Handle::<AudioSource>::Weak(AssetId::Uuid {
uuid: Uuid::from_u128(243290473942075938),
});
let audio_handle_one: Handle<AudioSource> =
Handle::<AudioSource>::Weak(AssetId::from(Uuid::from_u128(13290473942075938)));
let audio_handle_two: Handle<AudioSource> =
Handle::<AudioSource>::Weak(AssetId::from(Uuid::from_u128(243290473942075938)));

let channel = AudioChannel::<Audio>::default();
channel.play(audio_handle_one);
Expand Down
33 changes: 11 additions & 22 deletions src/channel/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,13 @@ mod tests {
use crate::channel::dynamic::DynamicAudioChannels;
use crate::channel::*;
use bevy::asset::AssetId;
use bevy::utils::Uuid;
use uuid::Uuid;

#[test]
fn state_is_queued_if_command_is_queued() {
let mut audio = DynamicAudioChannels::default();
let audio_handle: Handle<AudioSource> = Handle::<AudioSource>::Weak(AssetId::Uuid {
uuid: Uuid::from_u128(43290473942075938),
});
let audio_handle: Handle<AudioSource> =
Handle::<AudioSource>::Weak(AssetId::from(Uuid::from_u128(43290473942075938)));
let instance_handle = audio.create_channel("test").play(audio_handle).handle();

assert_eq!(
Expand All @@ -255,9 +254,8 @@ mod tests {
#[test]
fn state_is_stopped_if_command_is_not_queued_and_id_not_in_state_map() {
let mut audio = DynamicAudioChannels::default();
let instance_handle = Handle::<AudioInstance>::Weak(AssetId::Uuid {
uuid: Uuid::from_u128(43290473942075938),
});
let instance_handle =
Handle::<AudioInstance>::Weak(AssetId::from(Uuid::from_u128(43290473942075938)));

assert_eq!(
audio.create_channel("test").state(&instance_handle),
Expand All @@ -268,9 +266,8 @@ mod tests {
#[test]
fn state_is_fetched_from_state_map() {
let mut audio = DynamicAudioChannels::default();
let instance_handle = Handle::<AudioInstance>::Weak(AssetId::Uuid {
uuid: Uuid::from_u128(43290473942075938),
});
let instance_handle =
Handle::<AudioInstance>::Weak(AssetId::from(Uuid::from_u128(43290473942075938)));
audio.create_channel("test");
audio.channels.get_mut("test").unwrap().states.insert(
instance_handle.id(),
Expand All @@ -288,29 +285,21 @@ mod tests {
let mut audio = DynamicAudioChannels::default();
audio.create_channel("test");
audio.channels.get_mut("test").unwrap().states.insert(
AssetId::Uuid {
uuid: Uuid::from_u128(143290473942075938),
},
AssetId::from(Uuid::from_u128(143290473942075938)),
PlaybackState::Queued,
);
audio.channels.get_mut("test").unwrap().states.insert(
AssetId::Uuid {
uuid: Uuid::from_u128(243290473942075938),
},
AssetId::from(Uuid::from_u128(243290473942075938)),
PlaybackState::Paused { position: 42. },
);
audio.channels.get_mut("test").unwrap().states.insert(
AssetId::Uuid {
uuid: Uuid::from_u128(343290473942075938),
},
AssetId::from(Uuid::from_u128(343290473942075938)),
PlaybackState::Stopped,
);
assert!(!audio.channel("test").is_playing_sound());

audio.channels.get_mut("test").unwrap().states.insert(
AssetId::Uuid {
uuid: Uuid::from_u128(43290473942075938),
},
AssetId::from(Uuid::from_u128(43290473942075938)),
PlaybackState::Playing { position: 42. },
);
assert!(audio.channel("test").is_playing_sound());
Expand Down
18 changes: 5 additions & 13 deletions src/channel/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ mod test {
use crate::channel::*;
use crate::Audio;
use bevy::asset::{AssetId, Handle};
use bevy::utils::Uuid;
use uuid::Uuid;

#[test]
fn state_is_queued_if_command_is_queued() {
Expand Down Expand Up @@ -230,29 +230,21 @@ mod test {
fn finds_playing_sound() {
let mut audio = AudioChannel::<Audio>::default();
audio.states.insert(
AssetId::Uuid {
uuid: Uuid::from_u128(43290473942075938),
},
Uuid::from_u128(43290473942075938).into(),
PlaybackState::Queued,
);
audio.states.insert(
AssetId::Uuid {
uuid: Uuid::from_u128(432952340473942075938),
},
Uuid::from_u128(432952340473942075938).into(),
PlaybackState::Paused { position: 42. },
);
audio.states.insert(
AssetId::Uuid {
uuid: Uuid::from_u128(46254624324354345324),
},
Uuid::from_u128(46254624324354345324).into(),
PlaybackState::Stopped,
);
assert!(!audio.is_playing_sound());

audio.states.insert(
AssetId::Uuid {
uuid: Uuid::from_u128(70973842759324739),
},
Uuid::from_u128(70973842759324739).into(),
PlaybackState::Playing { position: 42. },
);
assert!(audio.is_playing_sound());
Expand Down
23 changes: 9 additions & 14 deletions src/source/flac_loader.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use anyhow::Result;
use bevy::asset::io::Reader;
use bevy::asset::{AssetLoader, AsyncReadExt, LoadContext};
use bevy::utils::BoxedFuture;
use kira::sound::static_sound::{StaticSoundData, StaticSoundSettings};
use kira::sound::FromFileError;
use std::io::Cursor;
Expand Down Expand Up @@ -29,21 +28,17 @@ impl AssetLoader for FlacLoader {
type Settings = ();
type Error = FlacLoaderError;

fn load<'a>(
async fn load<'a>(
&'a self,
reader: &'a mut Reader,
reader: &'a mut Reader<'_>,
_settings: &'a (),
_load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result<Self::Asset, Self::Error>> {
Box::pin(async move {
let mut sound_bytes = vec![];
reader.read_to_end(&mut sound_bytes).await?;
let sound = StaticSoundData::from_cursor(
Cursor::new(sound_bytes),
StaticSoundSettings::default(),
)?;
Ok(AudioSource { sound })
})
_load_context: &'a mut LoadContext<'_>,
) -> Result<Self::Asset, Self::Error> {
let mut sound_bytes = vec![];
reader.read_to_end(&mut sound_bytes).await?;
let sound =
StaticSoundData::from_cursor(Cursor::new(sound_bytes), StaticSoundSettings::default())?;
Ok(AudioSource { sound })
}

fn extensions(&self) -> &[&str] {
Expand Down
23 changes: 9 additions & 14 deletions src/source/mp3_loader.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use anyhow::Result;
use bevy::asset::io::Reader;
use bevy::asset::{AssetLoader, AsyncReadExt, LoadContext};
use bevy::utils::BoxedFuture;
use kira::sound::static_sound::{StaticSoundData, StaticSoundSettings};
use kira::sound::FromFileError;
use std::io::Cursor;
Expand Down Expand Up @@ -29,21 +28,17 @@ impl AssetLoader for Mp3Loader {
type Settings = ();
type Error = Mp3LoaderError;

fn load<'a>(
async fn load<'a>(
&'a self,
reader: &'a mut Reader,
reader: &'a mut Reader<'_>,
_settings: &'a (),
_load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result<Self::Asset, Self::Error>> {
Box::pin(async move {
let mut sound_bytes = vec![];
reader.read_to_end(&mut sound_bytes).await?;
let sound = StaticSoundData::from_cursor(
Cursor::new(sound_bytes),
StaticSoundSettings::default(),
)?;
Ok(AudioSource { sound })
})
_load_context: &'a mut LoadContext<'_>,
) -> Result<Self::Asset, Self::Error> {
let mut sound_bytes = vec![];
reader.read_to_end(&mut sound_bytes).await?;
let sound =
StaticSoundData::from_cursor(Cursor::new(sound_bytes), StaticSoundSettings::default())?;
Ok(AudioSource { sound })
}

fn extensions(&self) -> &[&str] {
Expand Down
23 changes: 9 additions & 14 deletions src/source/ogg_loader.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use anyhow::Result;
use bevy::asset::io::Reader;
use bevy::asset::{AssetLoader, AsyncReadExt, LoadContext};
use bevy::utils::BoxedFuture;
use kira::sound::static_sound::{StaticSoundData, StaticSoundSettings};
use kira::sound::FromFileError;
use std::io::Cursor;
Expand Down Expand Up @@ -29,21 +28,17 @@ impl AssetLoader for OggLoader {
type Settings = ();
type Error = OggLoaderError;

fn load<'a>(
async fn load<'a>(
&'a self,
reader: &'a mut Reader,
reader: &'a mut Reader<'_>,
_settings: &'a (),
_load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result<Self::Asset, Self::Error>> {
Box::pin(async move {
let mut sound_bytes = vec![];
reader.read_to_end(&mut sound_bytes).await?;
let sound = StaticSoundData::from_cursor(
Cursor::new(sound_bytes),
StaticSoundSettings::default(),
)?;
Ok(AudioSource { sound })
})
_load_context: &'a mut LoadContext<'_>,
) -> Result<Self::Asset, Self::Error> {
let mut sound_bytes = vec![];
reader.read_to_end(&mut sound_bytes).await?;
let sound =
StaticSoundData::from_cursor(Cursor::new(sound_bytes), StaticSoundSettings::default())?;
Ok(AudioSource { sound })
}

fn extensions(&self) -> &[&str] {
Expand Down
Loading

0 comments on commit 6d11574

Please sign in to comment.