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
24 changes: 13 additions & 11 deletions scene/2d/audio_stream_player_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,32 @@
#include "scene/resources/world_2d.h"

void AudioStreamPlayer2D::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
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) {
case NOTIFICATION_EXIT_TREE: {
stop();
AudioServer::get_singleton()->remove_listener_changed_callback(_listener_changed_cb, this);
}
} break;

if (p_what == NOTIFICATION_PAUSED) {
case NOTIFICATION_PAUSED: {
if (!can_process()) {
// Node can't process so we start fading out to silence
// Node can't process so we start fading out to silence.
set_stream_paused(true);
}
}
} break;

if (p_what == NOTIFICATION_UNPAUSED) {
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
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();
}
Expand Down Expand Up @@ -100,6 +101,7 @@ void AudioStreamPlayer2D::_notification(int p_what) {
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
11 changes: 8 additions & 3 deletions scene/2d/canvas_modulate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,22 @@
#include "canvas_modulate.h"

void CanvasModulate::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_CANVAS) {
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) {
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()));
}
} else if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
} 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()));
Expand All @@ -52,6 +56,7 @@ void CanvasModulate::_notification(int p_what) {
}

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
25 changes: 14 additions & 11 deletions scene/2d/gpu_particles_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,8 @@ void GPUParticles2D::restart() {
}

void GPUParticles2D::_notification(int p_what) {
if (p_what == NOTIFICATION_DRAW) {
switch (p_what) {
case NOTIFICATION_DRAW: {
RID texture_rid;
Size2 size;
if (texture.is_valid()) {
Expand Down Expand Up @@ -496,35 +497,37 @@ void GPUParticles2D::_notification(int p_what) {
draw_rect(visibility_rect, Color(0, 0.7, 0.9, 0.4), false);
}
#endif
}
} break;

if (p_what == NOTIFICATION_ENTER_TREE) {
case NOTIFICATION_ENTER_TREE: {
if (sub_emitter != NodePath()) {
_attach_sub_emitter();
}
}
} break;

if (p_what == NOTIFICATION_EXIT_TREE) {
case NOTIFICATION_EXIT_TREE: {
RS::get_singleton()->particles_set_subemitter(particles, RID());
}
} break;

if (p_what == NOTIFICATION_PAUSED || p_what == NOTIFICATION_UNPAUSED) {
case NOTIFICATION_PAUSED:
case NOTIFICATION_UNPAUSED: {
if (can_process()) {
RS::get_singleton()->particles_set_speed_scale(particles, speed_scale);
} else {
RS::get_singleton()->particles_set_speed_scale(particles, 0);
}
}
} break;

if (p_what == NOTIFICATION_TRANSFORM_CHANGED) {
case NOTIFICATION_TRANSFORM_CHANGED: {
_update_particle_emission_transform();
}
} break;

if (p_what == NOTIFICATION_INTERNAL_PROCESS) {
case NOTIFICATION_INTERNAL_PROCESS: {
if (one_shot && !is_emitting()) {
notify_property_list_changed();
set_process_internal(false);
}
} break;
}
}

Expand Down
1 change: 1 addition & 0 deletions scene/2d/joint_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ void Joint2D::_notification(int p_what) {
case NOTIFICATION_READY: {
_update_joint();
} break;

case NOTIFICATION_EXIT_TREE: {
if (joint.is_valid()) {
_disconnect_signals();
Expand Down
17 changes: 10 additions & 7 deletions scene/2d/light_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,21 +192,24 @@ Light2D::BlendMode Light2D::get_blend_mode() const {
}

void Light2D::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
RS::get_singleton()->canvas_light_attach_to_canvas(canvas_light, get_canvas());
_update_light_visibility();
}
} break;

if (p_what == NOTIFICATION_TRANSFORM_CHANGED) {
case NOTIFICATION_TRANSFORM_CHANGED: {
RS::get_singleton()->canvas_light_set_transform(canvas_light, get_global_transform());
}
if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
} break;

case NOTIFICATION_VISIBILITY_CHANGED: {
_update_light_visibility();
}
} break;

if (p_what == NOTIFICATION_EXIT_TREE) {
case NOTIFICATION_EXIT_TREE: {
RS::get_singleton()->canvas_light_attach_to_canvas(canvas_light, RID());
_update_light_visibility();
} break;
}
}

Expand Down