Fix AudioStreamPlayer3D still processing when out of range
This commit is contained in:
parent
0a4aedb360
commit
a3158d89bb
2 changed files with 11 additions and 1 deletions
|
@ -401,10 +401,19 @@ Vector<AudioFrame> AudioStreamPlayer3D::_update_panning() {
|
|||
if (area && area->is_using_reverb_bus() && area->get_reverb_uniformity() > 0) {
|
||||
total_max = MAX(total_max, listener_area_pos.length());
|
||||
}
|
||||
if (total_max > max_distance) {
|
||||
if (dist > total_max || total_max > max_distance) {
|
||||
if (!was_further_than_max_distance_last_frame) {
|
||||
HashMap<StringName, Vector<AudioFrame>> bus_volumes;
|
||||
for (Ref<AudioStreamPlayback> &playback : internal->stream_playbacks) {
|
||||
// So the player gets muted and mostly stops mixing when out of range.
|
||||
AudioServer::get_singleton()->set_playback_bus_volumes_linear(playback, bus_volumes);
|
||||
}
|
||||
was_further_than_max_distance_last_frame = true; // Cache so we don't set the volume over and over.
|
||||
}
|
||||
continue; //can't hear this sound in this listener
|
||||
}
|
||||
}
|
||||
was_further_than_max_distance_last_frame = false;
|
||||
|
||||
float multiplier = Math::db_to_linear(_get_attenuation_db(dist));
|
||||
if (max_distance > 0) {
|
||||
|
|
|
@ -105,6 +105,7 @@ private:
|
|||
float linear_attenuation = 0;
|
||||
|
||||
float max_distance = 0.0;
|
||||
bool was_further_than_max_distance_last_frame = false;
|
||||
|
||||
Ref<VelocityTracker3D> velocity_tracker;
|
||||
|
||||
|
|
Loading…
Reference in a new issue