From 0f5455230c8955be0c6533574bd3d5b6f50792b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Tue, 15 Feb 2022 18:06:48 +0100 Subject: Use `switch` consistently in `_notification` (`scene` folder) --- scene/audio/audio_stream_player.cpp | 80 +++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 39 deletions(-) (limited to 'scene/audio') diff --git a/scene/audio/audio_stream_player.cpp b/scene/audio/audio_stream_player.cpp index 5f9d8a0d47..c8e8ff1cd1 100644 --- a/scene/audio/audio_stream_player.cpp +++ b/scene/audio/audio_stream_player.cpp @@ -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> playbacks_to_remove; - for (Ref &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 &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; + + case NOTIFICATION_INTERNAL_PROCESS: { + Vector> playbacks_to_remove; + for (Ref &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 &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 &playback : stream_playbacks) { - AudioServer::get_singleton()->stop_playback_stream(playback); - } - stream_playbacks.clear(); - } + case NOTIFICATION_EXIT_TREE: { + for (Ref &playback : stream_playbacks) { + AudioServer::get_singleton()->stop_playback_stream(playback); + } + stream_playbacks.clear(); + } 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; } } -- cgit v1.2.3