Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use switch consistently in _notification (scene folder) #58151

Merged
merged 1 commit into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion scene/2d/animated_sprite_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ void AnimatedSprite2D::_notification(int p_what) {
}

texture->draw_rect_region(ci, dst_rect, Rect2(Vector2(), texture->get_size()), Color(1, 1, 1), false);

} break;
}
}
Expand Down
1 change: 1 addition & 0 deletions scene/2d/audio_listener_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ void AudioListener2D::_notification(int p_what) {
make_current();
}
} break;

case NOTIFICATION_EXIT_TREE: {
if (!get_tree()->is_node_being_edited(this)) {
if (is_current()) {
Expand Down
112 changes: 57 additions & 55 deletions scene/2d/audio_stream_player_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,70 +36,72 @@
#include "scene/resources/world_2d.h"

void AudioStreamPlayer2D::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
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: {
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_INTERNAL_PHYSICS_PROCESS) {
//update anything related to position first, if possible of course
if (setplay.get() > 0 || (active.is_set() && last_mix_count != AudioServer::get_singleton()->get_mix_count())) {
_update_panning();
}
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
// Update anything related to position first, if possible of course.
if (setplay.get() > 0 || (active.is_set() && last_mix_count != AudioServer::get_singleton()->get_mix_count())) {
_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.");
AudioServer::get_singleton()->start_playback_stream(new_playback, _get_actual_bus(), volume_vector, setplay.get(), pitch_scale);
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.");
AudioServer::get_singleton()->start_playback_stream(new_playback, _get_actual_bus(), volume_vector, setplay.get(), pitch_scale);
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;
}
}

Expand Down
18 changes: 5 additions & 13 deletions scene/2d/camera_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,7 @@ Transform2D Camera2D::get_camera_transform() {
if (rotating) {
xform.set_rotation(angle);
}
xform.set_origin(screen_rect.position /*.floor()*/);

/*
if (0) {
xform = get_global_transform() * xform;
} else {
xform.elements[2]+=get_global_transform().get_origin();
}
*/
xform.set_origin(screen_rect.position);

return (xform).affine_inverse();
}
Expand All @@ -224,14 +216,14 @@ void Camera2D::_notification(int p_what) {
case NOTIFICATION_INTERNAL_PROCESS:
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
_update_scroll();

} break;

case NOTIFICATION_TRANSFORM_CHANGED: {
if (!is_processing_internal() && !is_physics_processing_internal()) {
_update_scroll();
}

} break;

case NOTIFICATION_ENTER_TREE: {
ERR_FAIL_COND(!is_inside_tree());
if (custom_viewport && ObjectDB::get_instance(custom_viewport_id)) {
Expand All @@ -256,8 +248,8 @@ void Camera2D::_notification(int p_what) {
_update_process_callback();
_update_scroll();
first = true;

} break;

case NOTIFICATION_EXIT_TREE: {
if (is_current()) {
if (viewport && !(custom_viewport && !ObjectDB::get_instance(custom_viewport_id))) {
Expand All @@ -269,8 +261,8 @@ void Camera2D::_notification(int p_what) {
remove_from_group(group_name);
remove_from_group(canvas_group_name);
viewport = nullptr;

} break;

#ifdef TOOLS_ENABLED
case NOTIFICATION_DRAW: {
if (!is_inside_tree() || !Engine::get_singleton()->is_editor_hint()) {
Expand Down
43 changes: 24 additions & 19 deletions scene/2d/canvas_modulate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,32 @@
#include "canvas_modulate.h"

void CanvasModulate::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_CANVAS) {
if (is_visible_in_tree()) {
RS::get_singleton()->canvas_set_modulate(get_canvas(), color);
add_to_group("_canvas_modulate_" + itos(get_canvas().get_id()));
}
switch (p_what) {
case NOTIFICATION_ENTER_CANVAS: {
if (is_visible_in_tree()) {
RS::get_singleton()->canvas_set_modulate(get_canvas(), color);
add_to_group("_canvas_modulate_" + itos(get_canvas().get_id()));
}
} break;

} else if (p_what == NOTIFICATION_EXIT_CANVAS) {
if (is_visible_in_tree()) {
RS::get_singleton()->canvas_set_modulate(get_canvas(), Color(1, 1, 1, 1));
remove_from_group("_canvas_modulate_" + itos(get_canvas().get_id()));
}
} else if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
if (is_visible_in_tree()) {
RS::get_singleton()->canvas_set_modulate(get_canvas(), color);
add_to_group("_canvas_modulate_" + itos(get_canvas().get_id()));
} else {
RS::get_singleton()->canvas_set_modulate(get_canvas(), Color(1, 1, 1, 1));
remove_from_group("_canvas_modulate_" + itos(get_canvas().get_id()));
}
case NOTIFICATION_EXIT_CANVAS: {
if (is_visible_in_tree()) {
RS::get_singleton()->canvas_set_modulate(get_canvas(), Color(1, 1, 1, 1));
remove_from_group("_canvas_modulate_" + itos(get_canvas().get_id()));
}
} break;

case NOTIFICATION_VISIBILITY_CHANGED: {
if (is_visible_in_tree()) {
RS::get_singleton()->canvas_set_modulate(get_canvas(), color);
add_to_group("_canvas_modulate_" + itos(get_canvas().get_id()));
} else {
RS::get_singleton()->canvas_set_modulate(get_canvas(), Color(1, 1, 1, 1));
remove_from_group("_canvas_modulate_" + itos(get_canvas().get_id()));
}

update_configuration_warnings();
update_configuration_warnings();
} break;
}
}

Expand Down
12 changes: 3 additions & 9 deletions scene/2d/collision_polygon_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,26 +102,20 @@ void CollisionPolygon2D::_notification(int p_what) {
_build_polygon();
_update_in_shape_owner();
}

/*if (Engine::get_singleton()->is_editor_hint()) {
//display above all else
set_z_as_relative(false);
set_z_index(RS::CANVAS_ITEM_Z_MAX - 1);
}*/

} break;

case NOTIFICATION_ENTER_TREE: {
if (parent) {
_update_in_shape_owner();
}

} break;

case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
if (parent) {
_update_in_shape_owner(true);
}

} break;

case NOTIFICATION_UNPARENTED: {
if (parent) {
parent->remove_shape_owner(owner_id);
Expand Down
14 changes: 4 additions & 10 deletions scene/2d/collision_shape_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,34 +59,28 @@ void CollisionShape2D::_notification(int p_what) {
}
_update_in_shape_owner();
}

/*if (Engine::get_singleton()->is_editor_hint()) {
//display above all else
set_z_as_relative(false);
set_z_index(RS::CANVAS_ITEM_Z_MAX - 1);
}*/

} break;

case NOTIFICATION_ENTER_TREE: {
if (parent) {
_update_in_shape_owner();
}

} break;

case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
if (parent) {
_update_in_shape_owner(true);
}

} break;

case NOTIFICATION_UNPARENTED: {
if (parent) {
parent->remove_shape_owner(owner_id);
}
owner_id = 0;
parent = nullptr;

} break;

case NOTIFICATION_DRAW: {
ERR_FAIL_COND(!is_inside_tree());

Expand Down
4 changes: 4 additions & 0 deletions scene/2d/cpu_particles_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1091,9 +1091,11 @@ void CPUParticles2D::_notification(int p_what) {
case NOTIFICATION_ENTER_TREE: {
set_process_internal(emitting);
} break;

case NOTIFICATION_EXIT_TREE: {
_set_redraw(false);
} break;

case NOTIFICATION_DRAW: {
// first update before rendering to avoid one frame delay after emitting starts
if (emitting && (time == 0)) {
Expand All @@ -1111,9 +1113,11 @@ void CPUParticles2D::_notification(int p_what) {

RS::get_singleton()->canvas_item_add_multimesh(get_canvas_item(), multimesh, texrid);
} break;

case NOTIFICATION_INTERNAL_PROCESS: {
_update_internal();
} break;

case NOTIFICATION_TRANSFORM_CHANGED: {
inv_emission_transform = get_global_transform().affine_inverse();

Expand Down