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 restart: bool,
#[reflect(ignore)]
pub generator: Option<syz::BufferGenerator>,
pub generator: Option<syz::Generator>,
}
impl Default for Sound {
@ -194,7 +194,6 @@ fn update_listener(
fn add_source_handle(
context: Res<syz::Context>,
mut query: Query<(
Entity,
&mut Source,
Option<&PannerStrategy>,
Option<&GlobalTransform>,
@ -202,7 +201,7 @@ fn add_source_handle(
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() {
let panner_strategy = panner_strategy.cloned().unwrap_or_default();
let handle: syz::Source = if let Some(transform) = transform {
@ -285,7 +284,7 @@ fn add_generator(
handle
.add_generator(&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(
context: Res<syz::Context>,
mut query: Query<(
Entity,
&mut Source,
Option<&DistanceModel>,
Option<&DistanceRef>,
@ -371,7 +369,6 @@ fn update_source_properties(
)>,
) {
for (
entity,
mut source,
distance_model,
distance_ref,
@ -503,11 +500,16 @@ fn update_sound_properties(mut query: Query<&mut Sound>) {
assert!(pitch > 0. && pitch <= 2.);
if sound.restart {
if let Some(generator) = sound.generator.as_mut() {
if let Some(generator) = generator
.cast_to::<syz::BufferGenerator>()
.expect("Failed to cast")
{
generator
.playback_position()
.set(0.)
.expect("Failed to restart");
}
}
sound.restart = false;
}
if let Some(generator) = sound.generator.as_mut() {
@ -516,12 +518,17 @@ fn update_sound_properties(mut query: Query<&mut Sound>) {
.pitch_bend()
.set(pitch)
.expect("Failed to set pitch");
if let Some(generator) = generator
.cast_to::<syz::BufferGenerator>()
.expect("Failed to cast")
{
generator
.looping()
.set(looping)
.expect("Failed to set looping");
}
}
}
}
fn update_source_playback_state(query: Query<&Source>) {