Compare commits

...

2 Commits

Author SHA1 Message Date
298012455a Store a plain Generator in Sound component. 2022-09-09 08:23:54 -05:00
b60183c448 Remove unused variables. 2022-09-09 08:14:15 -05:00

View File

@ -130,7 +130,7 @@ pub struct Sound {
pub paused: bool, pub paused: bool,
pub restart: bool, pub restart: bool,
#[reflect(ignore)] #[reflect(ignore)]
pub generator: Option<syz::BufferGenerator>, pub generator: Option<syz::Generator>,
} }
impl Default for Sound { impl Default for Sound {
@ -194,7 +194,6 @@ fn update_listener(
fn add_source_handle( fn add_source_handle(
context: Res<syz::Context>, context: Res<syz::Context>,
mut query: Query<( mut query: Query<(
Entity,
&mut Source, &mut Source,
Option<&PannerStrategy>, Option<&PannerStrategy>,
Option<&GlobalTransform>, Option<&GlobalTransform>,
@ -202,7 +201,7 @@ fn add_source_handle(
Option<&ScalarPan>, Option<&ScalarPan>,
)>, )>,
) { ) {
for (entity, mut source, panner_strategy, transform, angular_pan, scalar_pan) in &mut query { for (mut source, panner_strategy, transform, angular_pan, scalar_pan) in &mut query {
if source.handle.is_none() { if source.handle.is_none() {
let panner_strategy = panner_strategy.cloned().unwrap_or_default(); let panner_strategy = panner_strategy.cloned().unwrap_or_default();
let handle: syz::Source = if let Some(transform) = transform { let handle: syz::Source = if let Some(transform) = transform {
@ -285,7 +284,7 @@ fn add_generator(
handle handle
.add_generator(&generator) .add_generator(&generator)
.expect("Unable to add generator"); .expect("Unable to add generator");
sound.generator = Some(generator); sound.generator = Some(generator.into());
} }
} }
} }
@ -357,7 +356,6 @@ fn change_panner_strategy(
fn update_source_properties( fn update_source_properties(
context: Res<syz::Context>, context: Res<syz::Context>,
mut query: Query<( mut query: Query<(
Entity,
&mut Source, &mut Source,
Option<&DistanceModel>, Option<&DistanceModel>,
Option<&DistanceRef>, Option<&DistanceRef>,
@ -371,7 +369,6 @@ fn update_source_properties(
)>, )>,
) { ) {
for ( for (
entity,
mut source, mut source,
distance_model, distance_model,
distance_ref, distance_ref,
@ -503,10 +500,15 @@ fn update_sound_properties(mut query: Query<&mut Sound>) {
assert!(pitch > 0. && pitch <= 2.); assert!(pitch > 0. && pitch <= 2.);
if sound.restart { if sound.restart {
if let Some(generator) = sound.generator.as_mut() { if let Some(generator) = sound.generator.as_mut() {
generator if let Some(generator) = generator
.playback_position() .cast_to::<syz::BufferGenerator>()
.set(0.) .expect("Failed to cast")
.expect("Failed to restart"); {
generator
.playback_position()
.set(0.)
.expect("Failed to restart");
}
} }
sound.restart = false; sound.restart = false;
} }
@ -516,10 +518,15 @@ fn update_sound_properties(mut query: Query<&mut Sound>) {
.pitch_bend() .pitch_bend()
.set(pitch) .set(pitch)
.expect("Failed to set pitch"); .expect("Failed to set pitch");
generator if let Some(generator) = generator
.looping() .cast_to::<syz::BufferGenerator>()
.set(looping) .expect("Failed to cast")
.expect("Failed to set looping"); {
generator
.looping()
.set(looping)
.expect("Failed to set looping");
}
} }
} }
} }