Add printlns around source creation, handle-setting and event dispatch.

This commit is contained in:
Nolan Darilek 2022-09-06 09:00:47 -05:00
parent 07d6d99ba7
commit d69ef38486

View File

@ -194,6 +194,7 @@ 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>,
@ -201,7 +202,7 @@ fn add_source_handle(
Option<&ScalarPan>, Option<&ScalarPan>,
)>, )>,
) { ) {
for (mut source, panner_strategy, transform, angular_pan, scalar_pan) in &mut query { for (entity, 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 {
@ -235,6 +236,7 @@ fn add_source_handle(
.expect("Failed to create source") .expect("Failed to create source")
.into() .into()
}; };
println!("{:?}: Instantiated source", entity);
source.handle = Some(handle); source.handle = Some(handle);
} }
} }
@ -295,20 +297,21 @@ fn add_generator(
fn add_sound_without_source( fn add_sound_without_source(
mut commands: Commands, mut commands: Commands,
query: Query<Entity, (Added<Sound>, Without<Source>)>, query: Query<Entity, (Added<Sound>, Without<Source>)>,
parents: Query<&Parent>, parents: Query<(&Parent, Option<&Source>)>,
sources: Query<&Source>,
) { ) {
for entity in &query { for entity in &query {
println!("{:?}: Maybe add source", entity);
let mut has_source = false; let mut has_source = false;
let mut target = entity; let mut target = entity;
while let Ok(parent) = parents.get(target) { while let Ok((parent, source)) = parents.get(target) {
if sources.get(**parent).is_ok() { if source.is_some() {
has_source = true; has_source = true;
break; break;
} }
target = **parent; target = **parent;
} }
if !has_source { if !has_source {
println!("Adding default source");
commands.entity(entity).insert(Source::default()); commands.entity(entity).insert(Source::default());
} }
} }
@ -348,6 +351,7 @@ fn change_panner_strategy(
for entity in check.iter() { for entity in check.iter() {
if let Ok(mut source) = sources.get_mut(*entity) { if let Ok(mut source) = sources.get_mut(*entity) {
if source.handle.is_some() { if source.handle.is_some() {
println!("{:?}: Clearing handle for panner strategy", entity);
source.handle = None; source.handle = None;
} }
} }
@ -357,6 +361,7 @@ 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>,
@ -370,6 +375,7 @@ fn update_source_properties(
)>, )>,
) { ) {
for ( for (
entity,
mut source, mut source,
distance_model, distance_model,
distance_ref, distance_ref,
@ -483,6 +489,7 @@ fn update_source_properties(
} }
} }
if clear_source { if clear_source {
println!("{:?}: Clearing source", entity);
source.handle = None; source.handle = None;
} }
} }
@ -636,14 +643,18 @@ fn events(
) { ) {
context.get_events().for_each(|event| { context.get_events().for_each(|event| {
if let Ok(event) = event { if let Ok(event) = event {
let mut matched = false;
for (entity, sound) in &sounds { for (entity, sound) in &sounds {
if let Some(generator) = &sound.generator { if let Some(generator) = &sound.generator {
if *generator.handle() == event.source { if *generator.handle() == event.source {
matched = true;
match event.r#type { match event.r#type {
syz::EventType::Finished => { syz::EventType::Finished => {
println!("{:?} finished", entity);
output.send(SynthizerEvent::Finished(entity)); output.send(SynthizerEvent::Finished(entity));
} }
syz::EventType::Looped => { syz::EventType::Looped => {
println!("{:?} looped", entity);
output.send(SynthizerEvent::Looped(entity)); output.send(SynthizerEvent::Looped(entity));
} }
_ => {} _ => {}
@ -652,6 +663,9 @@ fn events(
} }
} }
} }
if !matched {
println!("No match");
}
} }
}); });
} }