Fix volumetric sound and adapt sound icon code to new bevy_synthizer.
This commit is contained in:
parent
8c930c321d
commit
d268ed2b0c
|
@ -49,7 +49,7 @@ features = [
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bevy_rapier2d = "0.27"
|
bevy_rapier2d = "0.27"
|
||||||
bevy_synthizer = "0.7"
|
bevy_synthizer = "0.8"
|
||||||
bevy_tts = { version = "0.9", default-features = false, features = ["tolk"] }
|
bevy_tts = { version = "0.9", default-features = false, features = ["tolk"] }
|
||||||
coord_2d = "0.3"
|
coord_2d = "0.3"
|
||||||
here_be_dragons = { version = "0.3", features = ["serde"] }
|
here_be_dragons = { version = "0.3", features = ["serde"] }
|
||||||
|
|
|
@ -75,42 +75,43 @@ fn update<S>(
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
if let Some(entity) = entity {
|
let Some(entity) = entity else {
|
||||||
if visible.contains(&entity) {
|
continue;
|
||||||
if let Some(interval) = icon.interval.as_mut() {
|
};
|
||||||
if interval.finished() {
|
if visible.contains(&entity) {
|
||||||
interval.reset();
|
if let Some(interval) = icon.interval.as_mut() {
|
||||||
continue;
|
if interval.finished() {
|
||||||
} else if interval.fraction() == 0. {
|
interval.reset();
|
||||||
sound.generator = None;
|
continue;
|
||||||
}
|
} else if interval.fraction() == 0. {
|
||||||
interval.tick(time.delta());
|
sound.playback_position = 0.;
|
||||||
}
|
|
||||||
if sound.audio != icon.audio {
|
|
||||||
sound.audio = icon.audio.clone();
|
|
||||||
}
|
|
||||||
if sound.gain != icon.gain {
|
|
||||||
sound.gain = icon.gain;
|
|
||||||
}
|
|
||||||
if sound.pitch != icon.pitch {
|
|
||||||
sound.pitch = icon.pitch;
|
|
||||||
}
|
|
||||||
let looping = icon.interval.is_none();
|
|
||||||
if sound.looping != looping {
|
|
||||||
sound.looping = looping;
|
|
||||||
}
|
|
||||||
if sound.paused {
|
|
||||||
sound.paused = false;
|
|
||||||
sound.generator = None;
|
sound.generator = None;
|
||||||
}
|
}
|
||||||
} else if !sound.paused {
|
interval.tick(time.delta());
|
||||||
sound.paused = true;
|
}
|
||||||
if let Some(interval) = icon.interval.as_mut() {
|
if sound.audio != icon.audio {
|
||||||
interval.reset();
|
sound.audio = icon.audio.clone();
|
||||||
}
|
}
|
||||||
|
if sound.gain != icon.gain {
|
||||||
|
sound.gain = icon.gain;
|
||||||
|
}
|
||||||
|
if sound.pitch != icon.pitch {
|
||||||
|
sound.pitch = icon.pitch;
|
||||||
|
}
|
||||||
|
let looping = icon.interval.is_none();
|
||||||
|
if sound.looping != looping {
|
||||||
|
sound.looping = looping;
|
||||||
|
}
|
||||||
|
if sound.paused {
|
||||||
|
sound.paused = false;
|
||||||
|
sound.playback_position = 0.;
|
||||||
|
sound.generator = None;
|
||||||
|
}
|
||||||
|
} else if !sound.paused {
|
||||||
|
sound.paused = true;
|
||||||
|
if let Some(interval) = icon.interval.as_mut() {
|
||||||
|
interval.reset();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
panic!("Should not happen");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,31 +9,46 @@ use crate::core::GlobalTransformExt;
|
||||||
pub struct Volumetric;
|
pub struct Volumetric;
|
||||||
|
|
||||||
fn update(
|
fn update(
|
||||||
|
mut commands: Commands,
|
||||||
listener: Query<(&Collider, &GlobalTransform), With<Listener>>,
|
listener: Query<(&Collider, &GlobalTransform), With<Listener>>,
|
||||||
mut sounds: Query<(&Sound, &Parent, &mut Transform), With<Volumetric>>,
|
mut sounds: Query<(Entity, &Sound, &Parent, Option<&mut Transform>), With<Volumetric>>,
|
||||||
colliders: Query<(&Collider, &GlobalTransform)>,
|
colliders: Query<(&Collider, &GlobalTransform)>,
|
||||||
) {
|
) {
|
||||||
if let Ok((listener_collider, listener_global_transform)) = listener.get_single() {
|
if let Ok((listener_collider, listener_global_transform)) = listener.get_single() {
|
||||||
for (sound, parent, mut sound_transform) in &mut sounds {
|
for (sound_entity, sound, parent, sound_transform) in &mut sounds {
|
||||||
if sound.paused {
|
if sound.paused {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if let Ok((sound_collider, sound_global_transform)) = colliders.get(**parent) {
|
let Ok((sound_collider, sound_global_transform)) = colliders.get(**parent) else {
|
||||||
let closest = listener_global_transform.closest_points(
|
continue;
|
||||||
listener_collider,
|
};
|
||||||
sound_global_transform,
|
let closest = listener_global_transform.closest_points(
|
||||||
sound_collider,
|
listener_collider,
|
||||||
);
|
sound_global_transform,
|
||||||
if let ClosestPoints::WithinMargin(_p1, p2) = closest {
|
sound_collider,
|
||||||
let p2 = Vec3::new(p2.x, p2.y, 0.);
|
);
|
||||||
|
if let ClosestPoints::WithinMargin(_p1, p2) = closest {
|
||||||
|
if let Some(mut sound_transform) = sound_transform {
|
||||||
sound_transform.translation.x = p2.x - sound_global_transform.translation().x;
|
sound_transform.translation.x = p2.x - sound_global_transform.translation().x;
|
||||||
sound_transform.translation.y = p2.y - sound_global_transform.translation().y;
|
sound_transform.translation.y = p2.y - sound_global_transform.translation().y;
|
||||||
} else if closest == ClosestPoints::Intersecting {
|
} else {
|
||||||
sound_transform.translation.x = listener_global_transform.translation().x
|
let sound_translation = Vec3::new(
|
||||||
- sound_global_transform.translation().x;
|
p2.x - sound_global_transform.translation().x,
|
||||||
sound_transform.translation.y = listener_global_transform.translation().y
|
p2.y - sound_global_transform.translation().y,
|
||||||
- sound_global_transform.translation().y;
|
0.,
|
||||||
|
);
|
||||||
|
commands
|
||||||
|
.entity(sound_entity)
|
||||||
|
.insert(TransformBundle::from_transform(
|
||||||
|
Transform::from_translation(sound_translation),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
} else if closest == ClosestPoints::Intersecting && sound_transform.is_some() {
|
||||||
|
println!("Clearing volumetric");
|
||||||
|
commands
|
||||||
|
.entity(sound_entity)
|
||||||
|
.remove::<Transform>()
|
||||||
|
.remove::<GlobalTransform>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user