mirror of
https://github.com/lightsoutgames/bevy_openal.git
synced 2024-11-13 21:25:56 +00:00
More aggressively clean up sounds when possible.
This commit is contained in:
parent
76c7701e92
commit
0a65d16d44
42
src/lib.rs
42
src/lib.rs
|
@ -252,9 +252,11 @@ fn source_update(
|
|||
max_distance,
|
||||
rolloff_factor,
|
||||
bypass_global_effects,
|
||||
state,
|
||||
..
|
||||
} = *sound;
|
||||
match &sound.state {
|
||||
let mut clear = false;
|
||||
match state {
|
||||
SoundState::Stopped => {
|
||||
if let Some(source) = sound.source.as_mut() {
|
||||
let mut source = source.lock().unwrap();
|
||||
|
@ -265,21 +267,25 @@ fn source_update(
|
|||
SoundState::Playing => {
|
||||
if let Some(source) = sound.source.as_mut() {
|
||||
let mut source = source.lock().unwrap();
|
||||
sync_source_and_components(
|
||||
&mut source,
|
||||
transform,
|
||||
global_transform,
|
||||
gain,
|
||||
pitch,
|
||||
looping,
|
||||
reference_distance,
|
||||
max_distance,
|
||||
rolloff_factor,
|
||||
bypass_global_effects,
|
||||
&mut **global_effects,
|
||||
);
|
||||
if ![SourceState::Playing, SourceState::Stopped].contains(&source.state()) {
|
||||
source.play();
|
||||
if !vec![SourceState::Playing, SourceState::Paused].contains(&source.state()) {
|
||||
clear = true;
|
||||
} else {
|
||||
sync_source_and_components(
|
||||
&mut source,
|
||||
transform,
|
||||
global_transform,
|
||||
gain,
|
||||
pitch,
|
||||
looping,
|
||||
reference_distance,
|
||||
max_distance,
|
||||
rolloff_factor,
|
||||
bypass_global_effects,
|
||||
&mut **global_effects,
|
||||
);
|
||||
if source.state() != SourceState::Playing {
|
||||
source.play();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
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() {
|
||||
let source = source.lock().unwrap();
|
||||
sound.state = match &source.state() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user