Use switch consistently in _notification (scene folder)
This commit is contained in:
parent
171021145d
commit
0f5455230c
127 changed files with 2853 additions and 2601 deletions
|
|
@ -35,49 +35,51 @@
|
|||
#include "servers/audio_server.h"
|
||||
|
||||
void AudioStreamPlayer::_notification(int p_what) {
|
||||
if (p_what == NOTIFICATION_ENTER_TREE) {
|
||||
if (autoplay && !Engine::get_singleton()->is_editor_hint()) {
|
||||
play();
|
||||
}
|
||||
}
|
||||
|
||||
if (p_what == NOTIFICATION_INTERNAL_PROCESS) {
|
||||
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);
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_ENTER_TREE: {
|
||||
if (autoplay && !Engine::get_singleton()->is_editor_hint()) {
|
||||
play();
|
||||
}
|
||||
}
|
||||
// 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_process_internal(false);
|
||||
}
|
||||
if (!playbacks_to_remove.is_empty()) {
|
||||
emit_signal(SNAME("finished"));
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
||||
if (p_what == NOTIFICATION_EXIT_TREE) {
|
||||
for (Ref<AudioStreamPlayback> &playback : stream_playbacks) {
|
||||
AudioServer::get_singleton()->stop_playback_stream(playback);
|
||||
}
|
||||
stream_playbacks.clear();
|
||||
}
|
||||
case NOTIFICATION_INTERNAL_PROCESS: {
|
||||
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_process_internal(false);
|
||||
}
|
||||
if (!playbacks_to_remove.is_empty()) {
|
||||
emit_signal(SNAME("finished"));
|
||||
}
|
||||
} 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_EXIT_TREE: {
|
||||
for (Ref<AudioStreamPlayback> &playback : stream_playbacks) {
|
||||
AudioServer::get_singleton()->stop_playback_stream(playback);
|
||||
}
|
||||
stream_playbacks.clear();
|
||||
} break;
|
||||
|
||||
if (p_what == NOTIFICATION_UNPAUSED) {
|
||||
set_stream_paused(false);
|
||||
case NOTIFICATION_PAUSED: {
|
||||
if (!can_process()) {
|
||||
// Node can't process so we start fading out to silence
|
||||
set_stream_paused(true);
|
||||
}
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_UNPAUSED: {
|
||||
set_stream_paused(false);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue