Use switch consistently in _notification (scene folder)

This commit is contained in:
Rémi Verschelde 2022-02-15 18:06:48 +01:00
parent 171021145d
commit 0f5455230c
No known key found for this signature in database
GPG key ID: C3336907360768E1
127 changed files with 2853 additions and 2601 deletions

View file

@ -239,80 +239,82 @@ float AudioStreamPlayer3D::_get_attenuation_db(float p_distance) const {
}
void AudioStreamPlayer3D::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
velocity_tracker->reset(get_global_transform().origin);
AudioServer::get_singleton()->add_listener_changed_callback(_listener_changed_cb, this);
if (autoplay && !Engine::get_singleton()->is_editor_hint()) {
play();
}
}
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
velocity_tracker->reset(get_global_transform().origin);
AudioServer::get_singleton()->add_listener_changed_callback(_listener_changed_cb, this);
if (autoplay && !Engine::get_singleton()->is_editor_hint()) {
play();
}
} break;
if (p_what == NOTIFICATION_EXIT_TREE) {
stop();
AudioServer::get_singleton()->remove_listener_changed_callback(_listener_changed_cb, this);
}
case NOTIFICATION_EXIT_TREE: {
stop();
AudioServer::get_singleton()->remove_listener_changed_callback(_listener_changed_cb, this);
} break;
if (p_what == NOTIFICATION_PAUSED) {
if (!can_process()) {
// Node can't process so we start fading out to silence
set_stream_paused(true);
}
}
case NOTIFICATION_PAUSED: {
if (!can_process()) {
// Node can't process so we start fading out to silence.
set_stream_paused(true);
}
} break;
if (p_what == NOTIFICATION_UNPAUSED) {
set_stream_paused(false);
}
case NOTIFICATION_UNPAUSED: {
set_stream_paused(false);
} break;
if (p_what == NOTIFICATION_TRANSFORM_CHANGED) {
if (doppler_tracking != DOPPLER_TRACKING_DISABLED) {
velocity_tracker->update_position(get_global_transform().origin);
}
}
case NOTIFICATION_TRANSFORM_CHANGED: {
if (doppler_tracking != DOPPLER_TRACKING_DISABLED) {
velocity_tracker->update_position(get_global_transform().origin);
}
} break;
if (p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS) {
//update anything related to position first, if possible of course
Vector<AudioFrame> volume_vector;
if (setplay.get() > 0 || (active.is_set() && last_mix_count != AudioServer::get_singleton()->get_mix_count())) {
volume_vector = _update_panning();
}
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
// Update anything related to position first, if possible of course.
Vector<AudioFrame> volume_vector;
if (setplay.get() > 0 || (active.is_set() && last_mix_count != AudioServer::get_singleton()->get_mix_count())) {
volume_vector = _update_panning();
}
if (setplay.get() >= 0 && stream.is_valid()) {
active.set();
Ref<AudioStreamPlayback> new_playback = stream->instance_playback();
ERR_FAIL_COND_MSG(new_playback.is_null(), "Failed to instantiate playback.");
Map<StringName, Vector<AudioFrame>> bus_map;
bus_map[_get_actual_bus()] = volume_vector;
AudioServer::get_singleton()->start_playback_stream(new_playback, bus_map, setplay.get(), actual_pitch_scale, linear_attenuation, attenuation_filter_cutoff_hz);
stream_playbacks.push_back(new_playback);
setplay.set(-1);
}
if (setplay.get() >= 0 && stream.is_valid()) {
active.set();
Ref<AudioStreamPlayback> new_playback = stream->instance_playback();
ERR_FAIL_COND_MSG(new_playback.is_null(), "Failed to instantiate playback.");
Map<StringName, Vector<AudioFrame>> bus_map;
bus_map[_get_actual_bus()] = volume_vector;
AudioServer::get_singleton()->start_playback_stream(new_playback, bus_map, setplay.get(), actual_pitch_scale, linear_attenuation, attenuation_filter_cutoff_hz);
stream_playbacks.push_back(new_playback);
setplay.set(-1);
}
if (!stream_playbacks.is_empty() && active.is_set()) {
// Stop playing if no longer active.
Vector<Ref<AudioStreamPlayback>> playbacks_to_remove;
for (Ref<AudioStreamPlayback> &playback : stream_playbacks) {
if (playback.is_valid() && !AudioServer::get_singleton()->is_playback_active(playback) && !AudioServer::get_singleton()->is_playback_paused(playback)) {
playbacks_to_remove.push_back(playback);
if (!stream_playbacks.is_empty() && active.is_set()) {
// Stop playing if no longer active.
Vector<Ref<AudioStreamPlayback>> playbacks_to_remove;
for (Ref<AudioStreamPlayback> &playback : stream_playbacks) {
if (playback.is_valid() && !AudioServer::get_singleton()->is_playback_active(playback) && !AudioServer::get_singleton()->is_playback_paused(playback)) {
playbacks_to_remove.push_back(playback);
}
}
// Now go through and remove playbacks that have finished. Removing elements from a Vector in a range based for is asking for trouble.
for (Ref<AudioStreamPlayback> &playback : playbacks_to_remove) {
stream_playbacks.erase(playback);
}
if (!playbacks_to_remove.is_empty() && stream_playbacks.is_empty()) {
// This node is no longer actively playing audio.
active.clear();
set_physics_process_internal(false);
}
if (!playbacks_to_remove.is_empty()) {
emit_signal(SNAME("finished"));
}
}
// Now go through and remove playbacks that have finished. Removing elements from a Vector in a range based for is asking for trouble.
for (Ref<AudioStreamPlayback> &playback : playbacks_to_remove) {
stream_playbacks.erase(playback);
}
if (!playbacks_to_remove.is_empty() && stream_playbacks.is_empty()) {
// This node is no longer actively playing audio.
active.clear();
set_physics_process_internal(false);
}
if (!playbacks_to_remove.is_empty()) {
emit_signal(SNAME("finished"));
}
}
while (stream_playbacks.size() > max_polyphony) {
AudioServer::get_singleton()->stop_playback_stream(stream_playbacks[0]);
stream_playbacks.remove_at(0);
}
while (stream_playbacks.size() > max_polyphony) {
AudioServer::get_singleton()->stop_playback_stream(stream_playbacks[0]);
stream_playbacks.remove_at(0);
}
} break;
}
}