More aggressively clean up sounds when possible.

This commit is contained in:
Nolan Darilek 2021-07-13 10:40:50 -05:00
parent 76c7701e92
commit 0a65d16d44

View File

@ -252,9 +252,11 @@ fn source_update(
max_distance, max_distance,
rolloff_factor, rolloff_factor,
bypass_global_effects, bypass_global_effects,
state,
.. ..
} = *sound; } = *sound;
match &sound.state { let mut clear = false;
match state {
SoundState::Stopped => { SoundState::Stopped => {
if let Some(source) = sound.source.as_mut() { if let Some(source) = sound.source.as_mut() {
let mut source = source.lock().unwrap(); let mut source = source.lock().unwrap();
@ -265,21 +267,25 @@ fn source_update(
SoundState::Playing => { SoundState::Playing => {
if let Some(source) = sound.source.as_mut() { if let Some(source) = sound.source.as_mut() {
let mut source = source.lock().unwrap(); let mut source = source.lock().unwrap();
sync_source_and_components( if !vec![SourceState::Playing, SourceState::Paused].contains(&source.state()) {
&mut source, clear = true;
transform, } else {
global_transform, sync_source_and_components(
gain, &mut source,
pitch, transform,
looping, global_transform,
reference_distance, gain,
max_distance, pitch,
rolloff_factor, looping,
bypass_global_effects, reference_distance,
&mut **global_effects, max_distance,
); rolloff_factor,
if ![SourceState::Playing, SourceState::Stopped].contains(&source.state()) { bypass_global_effects,
source.play(); &mut **global_effects,
);
if source.state() != SourceState::Playing {
source.play();
}
} }
} else { } else {
if let Ok(mut source) = context.new_static_source() { if let Ok(mut source) = context.new_static_source() {
@ -348,6 +354,10 @@ fn source_update(
} }
} }
} }
if clear {
sound.source = None;
sound.state = SoundState::Stopped;
}
if let Some(source) = sound.source.clone() { if let Some(source) = sound.source.clone() {
let source = source.lock().unwrap(); let source = source.lock().unwrap();
sound.state = match &source.state() { sound.state = match &source.state() {