fix: Clear generator when source is cleared, and improve handling for changing source types.
This commit is contained in:
parent
2364f638db
commit
4c02a98eb4
37
src/lib.rs
37
src/lib.rs
|
@ -403,6 +403,7 @@ fn update_source_properties(
|
|||
Option<&AngularPan>,
|
||||
Option<&ScalarPan>,
|
||||
Option<&GlobalTransform>,
|
||||
Option<&mut Sound>,
|
||||
)>,
|
||||
) {
|
||||
for (
|
||||
|
@ -416,15 +417,18 @@ fn update_source_properties(
|
|||
angular_pan,
|
||||
scalar_pan,
|
||||
transform,
|
||||
sound,
|
||||
) in &mut query
|
||||
{
|
||||
let Source { gain, .. } = *source;
|
||||
assert!(gain >= 0.);
|
||||
if let Some(handle) = source.handle.as_mut() {
|
||||
let Some(handle) = source.handle.as_mut() else {
|
||||
continue;
|
||||
};
|
||||
handle.gain().set(gain).expect("Failed to set gain");
|
||||
let mut clear_source = false;
|
||||
if let Some(transform) = transform {
|
||||
if let Some(source) = handle.cast_to::<syz::Source3D>().expect("Failed to cast") {
|
||||
if let Some(transform) = transform {
|
||||
let translation = transform.translation();
|
||||
source
|
||||
.position()
|
||||
|
@ -462,6 +466,7 @@ fn update_source_properties(
|
|||
.map(|v| **v)
|
||||
.unwrap_or_else(|| context.default_rolloff().get().unwrap());
|
||||
assert!(rolloff >= 0.);
|
||||
assert!(rolloff >= 0.);
|
||||
source
|
||||
.rolloff()
|
||||
.set(rolloff)
|
||||
|
@ -474,23 +479,23 @@ fn update_source_properties(
|
|||
.closeness_boost()
|
||||
.set(closeness_boost)
|
||||
.expect("Failed to set closeness_boost");
|
||||
let closeness_boost_distance =
|
||||
closeness_boost_distance.map(|v| **v).unwrap_or_else(|| {
|
||||
context.default_closeness_boost_distance().get().unwrap()
|
||||
});
|
||||
let closeness_boost_distance = closeness_boost_distance
|
||||
.map(|v| **v)
|
||||
.unwrap_or_else(|| context.default_closeness_boost_distance().get().unwrap());
|
||||
assert!(closeness_boost_distance >= 0.);
|
||||
source
|
||||
.closeness_boost_distance()
|
||||
.set(closeness_boost_distance)
|
||||
.expect("Failed to set closeness_boost_distance");
|
||||
} else {
|
||||
println!("Clearing 3D source because no transform");
|
||||
clear_source = true;
|
||||
}
|
||||
} else if let Some(angular_pan) = angular_pan {
|
||||
if let Some(source) = handle
|
||||
} else if let Some(source) = handle
|
||||
.cast_to::<syz::AngularPannedSource>()
|
||||
.expect("Failed to cast")
|
||||
{
|
||||
if let Some(angular_pan) = angular_pan {
|
||||
assert!(angular_pan.azimuth >= 0. && angular_pan.azimuth <= 360.);
|
||||
source
|
||||
.azimuth()
|
||||
|
@ -504,11 +509,11 @@ fn update_source_properties(
|
|||
} else {
|
||||
clear_source = true;
|
||||
}
|
||||
} else if let Some(scalar_pan) = scalar_pan {
|
||||
if let Some(source) = handle
|
||||
} else if let Some(source) = handle
|
||||
.cast_to::<syz::ScalarPannedSource>()
|
||||
.expect("Failed to cast")
|
||||
{
|
||||
if let Some(scalar_pan) = scalar_pan {
|
||||
assert!(**scalar_pan >= -1. && **scalar_pan <= 1.);
|
||||
source
|
||||
.panning_scalar()
|
||||
|
@ -517,9 +522,21 @@ fn update_source_properties(
|
|||
} else {
|
||||
clear_source = true;
|
||||
}
|
||||
} else if handle
|
||||
.cast_to::<syz::DirectSource>()
|
||||
.expect("Failed to cast")
|
||||
.is_some()
|
||||
{
|
||||
if transform.is_some() || angular_pan.is_some() || scalar_pan.is_some() {
|
||||
clear_source = true;
|
||||
}
|
||||
} else if source.handle.is_some() {
|
||||
clear_source = true;
|
||||
}
|
||||
if clear_source {
|
||||
source.handle = None;
|
||||
if let Some(mut sound) = sound {
|
||||
sound.generator = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user