diff options
Diffstat (limited to 'scene/2d')
37 files changed, 858 insertions, 460 deletions
diff --git a/scene/2d/animated_sprite_2d.cpp b/scene/2d/animated_sprite_2d.cpp index 54477758f4..3268544519 100644 --- a/scene/2d/animated_sprite_2d.cpp +++ b/scene/2d/animated_sprite_2d.cpp @@ -70,8 +70,9 @@ bool AnimatedSprite2D::_edit_use_rect() const { return false; } Ref<Texture2D> t; - if (animation) + if (animation) { t = frames->get_frame(animation, frame); + } return t.is_valid(); } #endif @@ -86,18 +87,22 @@ Rect2 AnimatedSprite2D::_get_rect() const { } Ref<Texture2D> t; - if (animation) + if (animation) { t = frames->get_frame(animation, frame); - if (t.is_null()) + } + if (t.is_null()) { return Rect2(); + } Size2 s = t->get_size(); Point2 ofs = offset; - if (centered) + if (centered) { ofs -= Size2(s) / 2; + } - if (s == Size2(0, 0)) + if (s == Size2(0, 0)) { s = Size2(1, 1); + } return Rect2(ofs, s); } @@ -106,10 +111,11 @@ void SpriteFrames::add_frame(const StringName &p_anim, const Ref<Texture2D> &p_f Map<StringName, Anim>::Element *E = animations.find(p_anim); ERR_FAIL_COND_MSG(!E, "Animation '" + String(p_anim) + "' doesn't exist."); - if (p_at_pos >= 0 && p_at_pos < E->get().frames.size()) + if (p_at_pos >= 0 && p_at_pos < E->get().frames.size()) { E->get().frames.insert(p_at_pos, p_frame); - else + } else { E->get().frames.push_back(p_frame); + } emit_changed(); } @@ -226,8 +232,9 @@ void SpriteFrames::_set_frames(const Array &p_frames) { ERR_FAIL_COND(!E); E->get().frames.resize(p_frames.size()); - for (int i = 0; i < E->get().frames.size(); i++) + for (int i = 0; i < E->get().frames.size(); i++) { E->get().frames.write[i] = p_frames[i]; + } } Array SpriteFrames::_get_frames() const { @@ -313,8 +320,9 @@ SpriteFrames::SpriteFrames() { } void AnimatedSprite2D::_validate_property(PropertyInfo &property) const { - if (!frames.is_valid()) + if (!frames.is_valid()) { return; + } if (property.name == "animation") { property.hint = PROPERTY_HINT_ENUM; List<StringName> names; @@ -355,16 +363,20 @@ void AnimatedSprite2D::_validate_property(PropertyInfo &property) const { void AnimatedSprite2D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_INTERNAL_PROCESS: { - if (frames.is_null()) + if (frames.is_null()) { return; - if (!frames->has_animation(animation)) + } + if (!frames->has_animation(animation)) { return; - if (frame < 0) + } + if (frame < 0) { return; + } float speed = frames->get_animation_speed(animation) * speed_scale; - if (speed == 0) + if (speed == 0) { return; //do nothing + } float remaining = get_process_delta_time(); @@ -375,17 +387,19 @@ void AnimatedSprite2D::_notification(int p_what) { int fc = frames->get_frame_count(animation); if ((!backwards && frame >= fc - 1) || (backwards && frame <= 0)) { if (frames->get_animation_loop(animation)) { - if (backwards) + if (backwards) { frame = fc - 1; - else + } else { frame = 0; + } emit_signal(SceneStringNames::get_singleton()->animation_finished); } else { - if (backwards) + if (backwards) { frame = 0; - else + } else { frame = fc - 1; + } if (!is_over) { is_over = true; @@ -393,10 +407,11 @@ void AnimatedSprite2D::_notification(int p_what) { } } } else { - if (backwards) + if (backwards) { frame--; - else + } else { frame++; + } } update(); @@ -411,16 +426,20 @@ void AnimatedSprite2D::_notification(int p_what) { } break; case NOTIFICATION_DRAW: { - if (frames.is_null()) + if (frames.is_null()) { return; - if (frame < 0) + } + if (frame < 0) { return; - if (!frames->has_animation(animation)) + } + if (!frames->has_animation(animation)) { return; + } Ref<Texture2D> texture = frames->get_frame(animation, frame); - if (texture.is_null()) + if (texture.is_null()) { return; + } Ref<Texture2D> normal = frames->get_normal_frame(animation, frame); Ref<Texture2D> specular = frames->get_specular_frame(animation, frame); @@ -430,18 +449,21 @@ void AnimatedSprite2D::_notification(int p_what) { Size2i s; s = texture->get_size(); Point2 ofs = offset; - if (centered) + if (centered) { ofs -= s / 2; + } if (Engine::get_singleton()->get_use_pixel_snap()) { ofs = ofs.floor(); } Rect2 dst_rect(ofs, s); - if (hflip) + if (hflip) { dst_rect.size.x = -dst_rect.size.x; - if (vflip) + } + if (vflip) { dst_rect.size.y = -dst_rect.size.y; + } texture->draw_rect_region(ci, dst_rect, Rect2(Vector2(), texture->get_size()), Color(1, 1, 1), false, normal, specular, Color(specular_color.r, specular_color.g, specular_color.b, shininess)); @@ -450,11 +472,13 @@ void AnimatedSprite2D::_notification(int p_what) { } void AnimatedSprite2D::set_sprite_frames(const Ref<SpriteFrames> &p_frames) { - if (frames.is_valid()) + if (frames.is_valid()) { frames->disconnect("changed", callable_mp(this, &AnimatedSprite2D::_res_changed)); + } frames = p_frames; - if (frames.is_valid()) + if (frames.is_valid()) { frames->connect("changed", callable_mp(this, &AnimatedSprite2D::_res_changed)); + } if (!frames.is_valid()) { frame = 0; @@ -479,15 +503,18 @@ void AnimatedSprite2D::set_frame(int p_frame) { if (frames->has_animation(animation)) { int limit = frames->get_frame_count(animation); - if (p_frame >= limit) + if (p_frame >= limit) { p_frame = limit - 1; + } } - if (p_frame < 0) + if (p_frame < 0) { p_frame = 0; + } - if (frame == p_frame) + if (frame == p_frame) { return; + } frame = p_frame; _reset_timeout(); @@ -561,8 +588,9 @@ void AnimatedSprite2D::_res_changed() { } void AnimatedSprite2D::_set_playing(bool p_playing) { - if (playing == p_playing) + if (playing == p_playing) { return; + } playing = p_playing; _reset_timeout(); set_process_internal(playing); @@ -577,8 +605,9 @@ void AnimatedSprite2D::play(const StringName &p_animation, const bool p_backward if (p_animation) { set_animation(p_animation); - if (backwards && get_frame() == 0) + if (backwards && get_frame() == 0) { set_frame(frames->get_frame_count(p_animation) - 1); + } } _set_playing(true); @@ -603,8 +632,9 @@ float AnimatedSprite2D::_get_frame_duration() { } void AnimatedSprite2D::_reset_timeout() { - if (!playing) + if (!playing) { return; + } timeout = _get_frame_duration(); is_over = false; @@ -614,8 +644,9 @@ void AnimatedSprite2D::set_animation(const StringName &p_animation) { ERR_FAIL_COND_MSG(frames == nullptr, vformat("There is no animation with name '%s'.", p_animation)); ERR_FAIL_COND_MSG(frames->get_animation_names().find(p_animation) == -1, vformat("There is no animation with name '%s'.", p_animation)); - if (animation == p_animation) + if (animation == p_animation) { return; + } animation = p_animation; _reset_timeout(); diff --git a/scene/2d/animated_sprite_2d.h b/scene/2d/animated_sprite_2d.h index fae334498d..5e8344ec4c 100644 --- a/scene/2d/animated_sprite_2d.h +++ b/scene/2d/animated_sprite_2d.h @@ -88,8 +88,9 @@ public: const Map<StringName, Anim>::Element *E = animations.find(p_anim); ERR_FAIL_COND_V_MSG(!E, Ref<Texture2D>(), "Animation '" + String(p_anim) + "' doesn't exist."); ERR_FAIL_COND_V(p_idx < 0, Ref<Texture2D>()); - if (p_idx >= E->get().frames.size()) + if (p_idx >= E->get().frames.size()) { return Ref<Texture2D>(); + } return E->get().frames[p_idx]; } @@ -101,8 +102,9 @@ public: const Map<StringName, Anim>::Element *EN = animations.find(E->get().normal_name); - if (!EN || p_idx >= EN->get().frames.size()) + if (!EN || p_idx >= EN->get().frames.size()) { return Ref<Texture2D>(); + } return EN->get().frames[p_idx]; } @@ -114,8 +116,9 @@ public: const Map<StringName, Anim>::Element *EN = animations.find(E->get().specular_name); - if (!EN || p_idx >= EN->get().frames.size()) + if (!EN || p_idx >= EN->get().frames.size()) { return Ref<Texture2D>(); + } return EN->get().frames[p_idx]; } @@ -124,8 +127,9 @@ public: Map<StringName, Anim>::Element *E = animations.find(p_anim); ERR_FAIL_COND_MSG(!E, "Animation '" + String(p_anim) + "' doesn't exist."); ERR_FAIL_COND(p_idx < 0); - if (p_idx >= E->get().frames.size()) + if (p_idx >= E->get().frames.size()) { return; + } E->get().frames.write[p_idx] = p_frame; } void remove_frame(const StringName &p_anim, int p_idx); diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp index 9a3b6c2611..ebfcb9cad6 100644 --- a/scene/2d/area_2d.cpp +++ b/scene/2d/area_2d.cpp @@ -165,8 +165,9 @@ void Area2D::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, i } } E->get().rc++; - if (node) + if (node) { E->get().shapes.insert(ShapePair(p_body_shape, p_area_shape)); + } if (!node || E->get().in_tree) { emit_signal(SceneStringNames::get_singleton()->body_shape_entered, objid, node, p_body_shape, p_area_shape); @@ -175,8 +176,9 @@ void Area2D::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, i } else { E->get().rc--; - if (node) + if (node) { E->get().shapes.erase(ShapePair(p_body_shape, p_area_shape)); + } bool eraseit = false; @@ -184,8 +186,9 @@ void Area2D::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, i if (node) { node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &Area2D::_body_enter_tree)); node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Area2D::_body_exit_tree)); - if (E->get().in_tree) + if (E->get().in_tree) { emit_signal(SceneStringNames::get_singleton()->body_exited, obj); + } } eraseit = true; @@ -194,8 +197,9 @@ void Area2D::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, i emit_signal(SceneStringNames::get_singleton()->body_shape_exited, objid, obj, p_body_shape, p_area_shape); } - if (eraseit) + if (eraseit) { body_map.erase(E); + } } locked = false; @@ -259,8 +263,9 @@ void Area2D::_area_inout(int p_status, const RID &p_area, ObjectID p_instance, i } } E->get().rc++; - if (node) + if (node) { E->get().shapes.insert(AreaShapePair(p_area_shape, p_self_shape)); + } if (!node || E->get().in_tree) { emit_signal(SceneStringNames::get_singleton()->area_shape_entered, objid, node, p_area_shape, p_self_shape); @@ -269,8 +274,9 @@ void Area2D::_area_inout(int p_status, const RID &p_area, ObjectID p_instance, i } else { E->get().rc--; - if (node) + if (node) { E->get().shapes.erase(AreaShapePair(p_area_shape, p_self_shape)); + } bool eraseit = false; @@ -278,8 +284,9 @@ void Area2D::_area_inout(int p_status, const RID &p_area, ObjectID p_instance, i if (node) { node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &Area2D::_area_enter_tree)); node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Area2D::_area_exit_tree)); - if (E->get().in_tree) + if (E->get().in_tree) { emit_signal(SceneStringNames::get_singleton()->area_exited, obj); + } } eraseit = true; @@ -288,8 +295,9 @@ void Area2D::_area_inout(int p_status, const RID &p_area, ObjectID p_instance, i emit_signal(SceneStringNames::get_singleton()->area_shape_exited, objid, obj, p_area_shape, p_self_shape); } - if (eraseit) + if (eraseit) { area_map.erase(E); + } } locked = false; @@ -307,14 +315,16 @@ void Area2D::_clear_monitoring() { Object *obj = ObjectDB::get_instance(E->key()); Node *node = Object::cast_to<Node>(obj); - if (!node) //node may have been deleted in previous frame or at other legitimate point + if (!node) { //node may have been deleted in previous frame or at other legitimate point continue; + } node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &Area2D::_body_enter_tree)); node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Area2D::_body_exit_tree)); - if (!E->get().in_tree) + if (!E->get().in_tree) { continue; + } for (int i = 0; i < E->get().shapes.size(); i++) { emit_signal(SceneStringNames::get_singleton()->body_shape_exited, E->key(), node, E->get().shapes[i].body_shape, E->get().shapes[i].area_shape); @@ -333,14 +343,16 @@ void Area2D::_clear_monitoring() { Object *obj = ObjectDB::get_instance(E->key()); Node *node = Object::cast_to<Node>(obj); - if (!node) //node may have been deleted in previous frame or at other legitimate point + if (!node) { //node may have been deleted in previous frame or at other legitimate point continue; + } node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &Area2D::_area_enter_tree)); node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Area2D::_area_exit_tree)); - if (!E->get().in_tree) + if (!E->get().in_tree) { continue; + } for (int i = 0; i < E->get().shapes.size(); i++) { emit_signal(SceneStringNames::get_singleton()->area_shape_exited, E->key(), node, E->get().shapes[i].area_shape, E->get().shapes[i].self_shape); @@ -360,8 +372,9 @@ void Area2D::_notification(int p_what) { } void Area2D::set_monitoring(bool p_enable) { - if (p_enable == monitoring) + if (p_enable == monitoring) { return; + } ERR_FAIL_COND_MSG(locked, "Function blocked during in/out signal. Use set_deferred(\"monitoring\", true/false)."); monitoring = p_enable; @@ -384,8 +397,9 @@ bool Area2D::is_monitoring() const { void Area2D::set_monitorable(bool p_enable) { ERR_FAIL_COND_MSG(locked || (is_inside_tree() && PhysicsServer2D::get_singleton()->is_flushing_queries()), "Function blocked during in/out signal. Use set_deferred(\"monitorable\", true/false)."); - if (p_enable == monitorable) + if (p_enable == monitorable) { return; + } monitorable = p_enable; @@ -433,16 +447,18 @@ TypedArray<Area2D> Area2D::get_overlapping_areas() const { bool Area2D::overlaps_area(Node *p_area) const { ERR_FAIL_NULL_V(p_area, false); const Map<ObjectID, AreaState>::Element *E = area_map.find(p_area->get_instance_id()); - if (!E) + if (!E) { return false; + } return E->get().in_tree; } bool Area2D::overlaps_body(Node *p_body) const { ERR_FAIL_NULL_V(p_body, false); const Map<ObjectID, BodyState>::Element *E = body_map.find(p_body->get_instance_id()); - if (!E) + if (!E) { return false; + } return E->get().in_tree; } @@ -466,10 +482,11 @@ uint32_t Area2D::get_collision_layer() const { void Area2D::set_collision_mask_bit(int p_bit, bool p_value) { uint32_t mask = get_collision_mask(); - if (p_value) + if (p_value) { mask |= 1 << p_bit; - else + } else { mask &= ~(1 << p_bit); + } set_collision_mask(mask); } @@ -479,10 +496,11 @@ bool Area2D::get_collision_mask_bit(int p_bit) const { void Area2D::set_collision_layer_bit(int p_bit, bool p_value) { uint32_t layer = get_collision_layer(); - if (p_value) + if (p_value) { layer |= 1 << p_bit; - else + } else { layer &= ~(1 << p_bit); + } set_collision_layer(layer); } @@ -515,8 +533,9 @@ void Area2D::_validate_property(PropertyInfo &property) const { if (property.name == "audio_bus_name") { String options; for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) { - if (i > 0) + if (i > 0) { options += ","; + } String name = AudioServer::get_singleton()->get_bus_name(i); options += name; } diff --git a/scene/2d/area_2d.h b/scene/2d/area_2d.h index 3b9b57cab4..0d0293dd12 100644 --- a/scene/2d/area_2d.h +++ b/scene/2d/area_2d.h @@ -70,10 +70,11 @@ private: int body_shape; int area_shape; bool operator<(const ShapePair &p_sp) const { - if (body_shape == p_sp.body_shape) + if (body_shape == p_sp.body_shape) { return area_shape < p_sp.area_shape; - else + } else { return body_shape < p_sp.body_shape; + } } ShapePair() {} @@ -100,10 +101,11 @@ private: int area_shape; int self_shape; bool operator<(const AreaShapePair &p_sp) const { - if (area_shape == p_sp.area_shape) + if (area_shape == p_sp.area_shape) { return self_shape < p_sp.self_shape; - else + } else { return area_shape < p_sp.area_shape; + } } AreaShapePair() {} diff --git a/scene/2d/audio_stream_player_2d.cpp b/scene/2d/audio_stream_player_2d.cpp index eca48406ce..5b89ac15b1 100644 --- a/scene/2d/audio_stream_player_2d.cpp +++ b/scene/2d/audio_stream_player_2d.cpp @@ -90,8 +90,9 @@ void AudioStreamPlayer2D::_mix_audio() { int cc = AudioServer::get_singleton()->get_channel_count(); if (cc == 1) { - if (!AudioServer::get_singleton()->thread_has_channel_mix_buffer(current.bus_index, 0)) + if (!AudioServer::get_singleton()->thread_has_channel_mix_buffer(current.bus_index, 0)) { continue; //may have been removed + } AudioFrame *target = AudioServer::get_singleton()->thread_get_channel_mix_buffer(current.bus_index, 0); @@ -113,8 +114,9 @@ void AudioStreamPlayer2D::_mix_audio() { targets[k] = AudioServer::get_singleton()->thread_get_channel_mix_buffer(current.bus_index, k); } - if (!valid) + if (!valid) { continue; + } for (int j = 0; j < buffer_size; j++) { AudioFrame frame = buffer[j] * vol; @@ -187,11 +189,13 @@ void AudioStreamPlayer2D::_notification(int p_what) { for (int i = 0; i < areas; i++) { Area2D *area2d = Object::cast_to<Area2D>(sr[i].collider); - if (!area2d) + if (!area2d) { continue; + } - if (!area2d->is_overriding_audio_bus()) + if (!area2d->is_overriding_audio_bus()) { continue; + } StringName bus_name = area2d->get_audio_bus_name(); bus_index = AudioServer::get_singleton()->thread_find_bus_index(bus_name); @@ -211,8 +215,9 @@ void AudioStreamPlayer2D::_notification(int p_what) { float dist = global_pos.distance_to(screen_in_global); //distance to screen center - if (dist > max_distance) + if (dist > max_distance) { continue; //can't hear this sound in this viewport + } float multiplier = Math::pow(1.0f - dist / max_distance, attenuation); multiplier *= Math::db2linear(volume_db); //also apply player volume! @@ -229,8 +234,9 @@ void AudioStreamPlayer2D::_notification(int p_what) { outputs[new_output_count].bus_index = bus_index; outputs[new_output_count].viewport = vp; //keep pointer only for reference new_output_count++; - if (new_output_count == MAX_OUTPUTS) + if (new_output_count == MAX_OUTPUTS) { break; + } } } @@ -371,10 +377,11 @@ bool AudioStreamPlayer2D::is_autoplay_enabled() { } void AudioStreamPlayer2D::_set_playing(bool p_enable) { - if (p_enable) + if (p_enable) { play(); - else + } else { stop(); + } } bool AudioStreamPlayer2D::_is_active() const { @@ -385,8 +392,9 @@ void AudioStreamPlayer2D::_validate_property(PropertyInfo &property) const { if (property.name == "bus") { String options; for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) { - if (i > 0) + if (i > 0) { options += ","; + } String name = AudioServer::get_singleton()->get_bus_name(i); options += name; } diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp index fc691c9ca6..8f69676da4 100644 --- a/scene/2d/camera_2d.cpp +++ b/scene/2d/camera_2d.cpp @@ -36,16 +36,18 @@ #include "servers/rendering_server.h" void Camera2D::_update_scroll() { - if (!is_inside_tree()) + if (!is_inside_tree()) { return; + } if (Engine::get_singleton()->is_editor_hint()) { update(); //will just be drawn return; } - if (!viewport) + if (!viewport) { return; + } if (current) { ERR_FAIL_COND(custom_viewport && !ObjectDB::get_instance(custom_viewport_id)); @@ -86,8 +88,9 @@ Vector2 Camera2D::get_zoom() const { }; Transform2D Camera2D::get_camera_transform() { - if (!get_tree()) + if (!get_tree()) { return Transform2D(); + } ERR_FAIL_COND_V(custom_viewport && !ObjectDB::get_instance(custom_viewport_id), Transform2D()); @@ -133,17 +136,21 @@ Transform2D Camera2D::get_camera_transform() { Rect2 screen_rect(-screen_offset + camera_pos, screen_size * zoom); if (limit_smoothing_enabled) { - if (screen_rect.position.x < limit[MARGIN_LEFT]) + if (screen_rect.position.x < limit[MARGIN_LEFT]) { camera_pos.x -= screen_rect.position.x - limit[MARGIN_LEFT]; + } - if (screen_rect.position.x + screen_rect.size.x > limit[MARGIN_RIGHT]) + if (screen_rect.position.x + screen_rect.size.x > limit[MARGIN_RIGHT]) { camera_pos.x -= screen_rect.position.x + screen_rect.size.x - limit[MARGIN_RIGHT]; + } - if (screen_rect.position.y + screen_rect.size.y > limit[MARGIN_BOTTOM]) + if (screen_rect.position.y + screen_rect.size.y > limit[MARGIN_BOTTOM]) { camera_pos.y -= screen_rect.position.y + screen_rect.size.y - limit[MARGIN_BOTTOM]; + } - if (screen_rect.position.y < limit[MARGIN_TOP]) + if (screen_rect.position.y < limit[MARGIN_TOP]) { camera_pos.y -= screen_rect.position.y - limit[MARGIN_TOP]; + } } if (smoothing_enabled && !Engine::get_singleton()->is_editor_hint()) { @@ -168,20 +175,25 @@ Transform2D Camera2D::get_camera_transform() { } Rect2 screen_rect(-screen_offset + ret_camera_pos, screen_size * zoom); - if (screen_rect.position.x < limit[MARGIN_LEFT]) + if (screen_rect.position.x < limit[MARGIN_LEFT]) { screen_rect.position.x = limit[MARGIN_LEFT]; + } - if (screen_rect.position.x + screen_rect.size.x > limit[MARGIN_RIGHT]) + if (screen_rect.position.x + screen_rect.size.x > limit[MARGIN_RIGHT]) { screen_rect.position.x = limit[MARGIN_RIGHT] - screen_rect.size.x; + } - if (screen_rect.position.y + screen_rect.size.y > limit[MARGIN_BOTTOM]) + if (screen_rect.position.y + screen_rect.size.y > limit[MARGIN_BOTTOM]) { screen_rect.position.y = limit[MARGIN_BOTTOM] - screen_rect.size.y; + } - if (screen_rect.position.y < limit[MARGIN_TOP]) + if (screen_rect.position.y < limit[MARGIN_TOP]) { screen_rect.position.y = limit[MARGIN_TOP]; + } - if (offset != Vector2()) + if (offset != Vector2()) { screen_rect.position += offset; + } camera_screen_center = screen_rect.position + screen_rect.size * 0.5; @@ -211,8 +223,9 @@ void Camera2D::_notification(int p_what) { } break; case NOTIFICATION_TRANSFORM_CHANGED: { - if (!is_processing_internal() && !is_physics_processing_internal()) + if (!is_processing_internal() && !is_physics_processing_internal()) { _update_scroll(); + } } break; case NOTIFICATION_ENTER_TREE: { @@ -248,8 +261,9 @@ void Camera2D::_notification(int p_what) { } break; case NOTIFICATION_DRAW: { - if (!is_inside_tree() || !Engine::get_singleton()->is_editor_hint()) + if (!is_inside_tree() || !Engine::get_singleton()->is_editor_hint()) { break; + } if (screen_drawing_enabled) { Color area_axis_color(0.5, 0.42, 0.87, 0.63); @@ -355,8 +369,9 @@ bool Camera2D::is_rotating() const { } void Camera2D::set_process_mode(Camera2DProcessMode p_mode) { - if (process_mode == p_mode) + if (process_mode == p_mode) { return; + } process_mode = p_mode; _update_process_mode(); @@ -375,8 +390,9 @@ void Camera2D::_make_current(Object *p_which) { } void Camera2D::_set_current(bool p_current) { - if (p_current) + if (p_current) { make_current(); + } current = p_current; update(); @@ -472,10 +488,11 @@ void Camera2D::align() { void Camera2D::set_follow_smoothing(float p_speed) { smoothing = p_speed; - if (smoothing > 0 && !(is_inside_tree() && Engine::get_singleton()->is_editor_hint())) + if (smoothing > 0 && !(is_inside_tree() && Engine::get_singleton()->is_editor_hint())) { set_process_internal(true); - else + } else { set_process_internal(false); + } } float Camera2D::get_follow_smoothing() const { @@ -554,10 +571,11 @@ void Camera2D::set_custom_viewport(Node *p_viewport) { } if (is_inside_tree()) { - if (custom_viewport) + if (custom_viewport) { viewport = custom_viewport; - else + } else { viewport = get_viewport(); + } RID vp = viewport->get_viewport_rid(); group_name = "__cameras_" + itos(vp.get_id()); diff --git a/scene/2d/canvas_modulate.cpp b/scene/2d/canvas_modulate.cpp index 41db3f771a..56643542a8 100644 --- a/scene/2d/canvas_modulate.cpp +++ b/scene/2d/canvas_modulate.cpp @@ -74,8 +74,9 @@ Color CanvasModulate::get_color() const { } String CanvasModulate::get_configuration_warning() const { - if (!is_visible_in_tree() || !is_inside_tree()) + if (!is_visible_in_tree() || !is_inside_tree()) { return String(); + } List<Node *> nodes; get_tree()->get_nodes_in_group("_canvas_modulate_" + itos(get_canvas().get_id()), &nodes); diff --git a/scene/2d/collision_object_2d.cpp b/scene/2d/collision_object_2d.cpp index aa1c107dea..fe16d4089a 100644 --- a/scene/2d/collision_object_2d.cpp +++ b/scene/2d/collision_object_2d.cpp @@ -38,16 +38,18 @@ void CollisionObject2D::_notification(int p_what) { case NOTIFICATION_ENTER_TREE: { Transform2D global_transform = get_global_transform(); - if (area) + if (area) { PhysicsServer2D::get_singleton()->area_set_transform(rid, global_transform); - else + } else { PhysicsServer2D::get_singleton()->body_set_state(rid, PhysicsServer2D::BODY_STATE_TRANSFORM, global_transform); + } RID space = get_world_2d()->get_space(); if (area) { PhysicsServer2D::get_singleton()->area_set_space(rid, space); - } else + } else { PhysicsServer2D::get_singleton()->body_set_space(rid, space); + } _update_pickable(); @@ -55,10 +57,11 @@ void CollisionObject2D::_notification(int p_what) { } break; case NOTIFICATION_ENTER_CANVAS: { - if (area) + if (area) { PhysicsServer2D::get_singleton()->area_attach_canvas_instance_id(rid, get_canvas_layer_instance_id()); - else + } else { PhysicsServer2D::get_singleton()->body_attach_canvas_instance_id(rid, get_canvas_layer_instance_id()); + } } break; case NOTIFICATION_VISIBILITY_CHANGED: { @@ -71,25 +74,28 @@ void CollisionObject2D::_notification(int p_what) { Transform2D global_transform = get_global_transform(); - if (area) + if (area) { PhysicsServer2D::get_singleton()->area_set_transform(rid, global_transform); - else + } else { PhysicsServer2D::get_singleton()->body_set_state(rid, PhysicsServer2D::BODY_STATE_TRANSFORM, global_transform); + } } break; case NOTIFICATION_EXIT_TREE: { if (area) { PhysicsServer2D::get_singleton()->area_set_space(rid, RID()); - } else + } else { PhysicsServer2D::get_singleton()->body_set_space(rid, RID()); + } } break; case NOTIFICATION_EXIT_CANVAS: { - if (area) + if (area) { PhysicsServer2D::get_singleton()->area_attach_canvas_instance_id(rid, ObjectID()); - else + } else { PhysicsServer2D::get_singleton()->body_attach_canvas_instance_id(rid, ObjectID()); + } } break; } } @@ -140,8 +146,9 @@ bool CollisionObject2D::is_shape_owner_disabled(uint32_t p_owner) const { } void CollisionObject2D::shape_owner_set_one_way_collision(uint32_t p_owner, bool p_enable) { - if (area) + if (area) { return; //not for areas + } ERR_FAIL_COND(!shapes.has(p_owner)); @@ -159,8 +166,9 @@ bool CollisionObject2D::is_shape_owner_one_way_collision_enabled(uint32_t p_owne } void CollisionObject2D::shape_owner_set_one_way_collision_margin(uint32_t p_owner, float p_margin) { - if (area) + if (area) { return; //not for areas + } ERR_FAIL_COND(!shapes.has(p_owner)); @@ -305,8 +313,9 @@ uint32_t CollisionObject2D::shape_find_owner(int p_shape_index) const { } void CollisionObject2D::set_pickable(bool p_enabled) { - if (pickable == p_enabled) + if (pickable == p_enabled) { return; + } pickable = p_enabled; _update_pickable(); @@ -342,14 +351,16 @@ void CollisionObject2D::set_only_update_transform_changes(bool p_enable) { } void CollisionObject2D::_update_pickable() { - if (!is_inside_tree()) + if (!is_inside_tree()) { return; + } bool is_pickable = pickable && is_visible_in_tree(); - if (area) + if (area) { PhysicsServer2D::get_singleton()->area_set_pickable(rid, is_pickable); - else + } else { PhysicsServer2D::get_singleton()->body_set_pickable(rid, is_pickable); + } } String CollisionObject2D::get_configuration_warning() const { diff --git a/scene/2d/collision_polygon_2d.cpp b/scene/2d/collision_polygon_2d.cpp index ebbda63e7b..4919ef8304 100644 --- a/scene/2d/collision_polygon_2d.cpp +++ b/scene/2d/collision_polygon_2d.cpp @@ -40,8 +40,9 @@ void CollisionPolygon2D::_build_polygon() { parent->shape_owner_clear_shapes(owner_id); - if (polygon.size() == 0) + if (polygon.size() == 0) { return; + } bool solids = build_mode == BUILD_SOLIDS; @@ -80,8 +81,9 @@ Vector<Vector<Vector2>> CollisionPolygon2D::_decompose_in_convex() { void CollisionPolygon2D::_update_in_shape_owner(bool p_xform_only) { parent->shape_owner_set_transform(owner_id, get_transform()); - if (p_xform_only) + if (p_xform_only) { return; + } parent->shape_owner_set_disabled(owner_id, disabled); parent->shape_owner_set_one_way_collision(owner_id, one_way_collision); parent->shape_owner_set_one_way_collision_margin(owner_id, one_way_collision_margin); @@ -160,8 +162,9 @@ void CollisionPolygon2D::_notification(int p_what) { pts.push_back(line_to + (Vector2(Math_SQRT12 * tsize, 0))); pts.push_back(line_to + (Vector2(-Math_SQRT12 * tsize, 0))); Vector<Color> cols; - for (int i = 0; i < 3; i++) + for (int i = 0; i < 3; i++) { cols.push_back(dcol); + } draw_primitive(pts, cols, Vector<Vector2>()); //small arrow } @@ -174,10 +177,11 @@ void CollisionPolygon2D::set_polygon(const Vector<Point2> &p_polygon) { { for (int i = 0; i < polygon.size(); i++) { - if (i == 0) + if (i == 0) { aabb = Rect2(polygon[i], Size2()); - else + } else { aabb.expand_to(polygon[i]); + } } if (aabb == Rect2()) { aabb = Rect2(-10, -10, 20, 20); diff --git a/scene/2d/collision_shape_2d.cpp b/scene/2d/collision_shape_2d.cpp index 43c8db18be..88d124536c 100644 --- a/scene/2d/collision_shape_2d.cpp +++ b/scene/2d/collision_shape_2d.cpp @@ -46,8 +46,9 @@ void CollisionShape2D::_shape_changed() { void CollisionShape2D::_update_in_shape_owner(bool p_xform_only) { parent->shape_owner_set_transform(owner_id, get_transform()); - if (p_xform_only) + if (p_xform_only) { return; + } parent->shape_owner_set_disabled(owner_id, disabled); parent->shape_owner_set_one_way_collision(owner_id, one_way_collision); parent->shape_owner_set_one_way_collision_margin(owner_id, one_way_collision_margin); @@ -129,8 +130,9 @@ void CollisionShape2D::_notification(int p_what) { pts.push_back(line_to + (Vector2(Math_SQRT12 * tsize, 0))); pts.push_back(line_to + (Vector2(-Math_SQRT12 * tsize, 0))); Vector<Color> cols; - for (int i = 0; i < 3; i++) + for (int i = 0; i < 3; i++) { cols.push_back(draw_col); + } draw_primitive(pts, cols, Vector<Vector2>()); } @@ -139,8 +141,9 @@ void CollisionShape2D::_notification(int p_what) { } void CollisionShape2D::set_shape(const Ref<Shape2D> &p_shape) { - if (shape.is_valid()) + if (shape.is_valid()) { shape->disconnect("changed", callable_mp(this, &CollisionShape2D::_shape_changed)); + } shape = p_shape; update(); if (parent) { @@ -150,8 +153,9 @@ void CollisionShape2D::set_shape(const Ref<Shape2D> &p_shape) { } } - if (shape.is_valid()) + if (shape.is_valid()) { shape->connect("changed", callable_mp(this, &CollisionShape2D::_shape_changed)); + } update_configuration_warning(); } @@ -161,8 +165,9 @@ Ref<Shape2D> CollisionShape2D::get_shape() const { } bool CollisionShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { - if (!shape.is_valid()) + if (!shape.is_valid()) { return false; + } return shape->_edit_is_selected_on_click(p_point, p_tolerance); } diff --git a/scene/2d/cpu_particles_2d.cpp b/scene/2d/cpu_particles_2d.cpp index e7129f39e7..526951976e 100644 --- a/scene/2d/cpu_particles_2d.cpp +++ b/scene/2d/cpu_particles_2d.cpp @@ -37,12 +37,14 @@ #include "servers/rendering_server.h" void CPUParticles2D::set_emitting(bool p_emitting) { - if (emitting == p_emitting) + if (emitting == p_emitting) { return; + } emitting = p_emitting; - if (emitting) + if (emitting) { set_process_internal(true); + } } void CPUParticles2D::set_amount(int p_amount) { @@ -197,16 +199,19 @@ void CPUParticles2D::_update_mesh_texture() { } void CPUParticles2D::set_texture(const Ref<Texture2D> &p_texture) { - if (p_texture == texture) + if (p_texture == texture) { return; + } - if (texture.is_valid()) + if (texture.is_valid()) { texture->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &CPUParticles2D::_texture_changed)); + } texture = p_texture; - if (texture.is_valid()) + if (texture.is_valid()) { texture->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &CPUParticles2D::_texture_changed)); + } update(); _update_mesh_texture(); @@ -256,8 +261,9 @@ String CPUParticles2D::get_configuration_warning() const { if (get_material().is_null() || (mat && !mat->get_particles_animation())) { if (get_param(PARAM_ANIM_SPEED) != 0.0 || get_param(PARAM_ANIM_OFFSET) != 0.0 || get_param_curve(PARAM_ANIM_SPEED).is_valid() || get_param_curve(PARAM_ANIM_OFFSET).is_valid()) { - if (warnings != String()) + if (warnings != String()) { warnings += "\n"; + } warnings += "- " + TTR("CPUParticles2D animation requires the usage of a CanvasItemMaterial with \"Particles Animation\" enabled."); } } @@ -326,8 +332,9 @@ float CPUParticles2D::get_param_randomness(Parameter p_param) const { static void _adjust_curve_range(const Ref<Curve> &p_curve, float p_min, float p_max) { Ref<Curve> curve = p_curve; - if (!curve.is_valid()) + if (!curve.is_valid()) { return; + } curve->ensure_default_setup(p_min, p_max); } @@ -507,12 +514,14 @@ static uint32_t idhash(uint32_t x) { static float rand_from_seed(uint32_t &seed) { int k; int s = int(seed); - if (s == 0) + if (s == 0) { s = 305420679; + } k = s / 127773; s = 16807 * (s - k * 127773) - 2836 * k; - if (s < 0) + if (s < 0) { s += 2147483647; + } seed = uint32_t(s); return float(seed % uint32_t(65536)) / 65535.0; } @@ -544,10 +553,11 @@ void CPUParticles2D::_update_internal() { if (time == 0 && pre_process_time > 0.0) { float frame_time; - if (fixed_fps > 0) + if (fixed_fps > 0) { frame_time = 1.0 / fixed_fps; - else + } else { frame_time = 1.0 / 30.0; + } float todo = pre_process_time; @@ -615,8 +625,9 @@ void CPUParticles2D::_particles_process(float p_delta) { for (int i = 0; i < pcount; i++) { Particle &p = parray[i]; - if (!emitting && !p.active) + if (!emitting && !p.active) { continue; + } float local_delta = p_delta; @@ -729,8 +740,9 @@ void CPUParticles2D::_particles_process(float p_delta) { case EMISSION_SHAPE_POINTS: case EMISSION_SHAPE_DIRECTED_POINTS: { int pc = emission_points.size(); - if (pc == 0) + if (pc == 0) { break; + } int random_idx = Math::rand() % pc; @@ -911,8 +923,9 @@ void CPUParticles2D::_particles_process(float p_delta) { //scale by scale float base_scale = tex_scale * Math::lerp(parameters[PARAM_SCALE], 1.0f, p.scale_rand * randomness[PARAM_SCALE]); - if (base_scale < 0.000001) + if (base_scale < 0.000001) { base_scale = 0.000001; + } p.transform.elements[0] *= base_scale; p.transform.elements[1] *= base_scale; @@ -987,8 +1000,9 @@ void CPUParticles2D::_update_particle_data_buffer() { } void CPUParticles2D::_set_redraw(bool p_redraw) { - if (redraw == p_redraw) + if (redraw == p_redraw) { return; + } redraw = p_redraw; { @@ -1029,11 +1043,13 @@ void CPUParticles2D::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { // first update before rendering to avoid one frame delay after emitting starts - if (emitting && (time == 0)) + if (emitting && (time == 0)) { _update_internal(); + } - if (!redraw) + if (!redraw) { return; // don't add to render list + } RID texrid; if (texture.is_valid()) { @@ -1109,8 +1125,9 @@ void CPUParticles2D::convert_from_particles(Node *p_particles) { } Ref<ParticlesMaterial> material = particles->get_process_material(); - if (material.is_null()) + if (material.is_null()) { return; + } Vector3 dir = material->get_direction(); set_direction(Vector2(dir.x, dir.y)); diff --git a/scene/2d/gpu_particles_2d.cpp b/scene/2d/gpu_particles_2d.cpp index dc50ea8f19..0814fbb549 100644 --- a/scene/2d/gpu_particles_2d.cpp +++ b/scene/2d/gpu_particles_2d.cpp @@ -66,12 +66,14 @@ void GPUParticles2D::set_one_shot(bool p_enable) { if (is_emitting()) { set_process_internal(true); - if (!one_shot) + if (!one_shot) { RenderingServer::get_singleton()->particles_restart(particles); + } } - if (!one_shot) + if (!one_shot) { set_process_internal(false); + } } void GPUParticles2D::set_pre_process_time(float p_time) { @@ -131,8 +133,9 @@ void GPUParticles2D::set_process_material(const Ref<Material> &p_material) { pm->set_gravity(Vector3(0, 98, 0)); } RID material_rid; - if (process_material.is_valid()) + if (process_material.is_valid()) { material_rid = process_material->get_rid(); + } RS::get_singleton()->particles_set_process_material(particles, material_rid); update_configuration_warning(); @@ -222,8 +225,9 @@ String GPUParticles2D::get_configuration_warning() const { String warnings; if (process_material.is_null()) { - if (warnings != String()) + if (warnings != String()) { warnings += "\n"; + } warnings += "- " + TTR("A material to process the particles is not assigned, so no behavior is imprinted."); } else { CanvasItemMaterial *mat = Object::cast_to<CanvasItemMaterial>(get_material().ptr()); @@ -233,8 +237,9 @@ String GPUParticles2D::get_configuration_warning() const { if (process && (process->get_param(ParticlesMaterial::PARAM_ANIM_SPEED) != 0.0 || process->get_param(ParticlesMaterial::PARAM_ANIM_OFFSET) != 0.0 || process->get_param_texture(ParticlesMaterial::PARAM_ANIM_SPEED).is_valid() || process->get_param_texture(ParticlesMaterial::PARAM_ANIM_OFFSET).is_valid())) { - if (warnings != String()) + if (warnings != String()) { warnings += "\n"; + } warnings += "- " + TTR("Particles2D animation requires the usage of a CanvasItemMaterial with \"Particles Animation\" enabled."); } } @@ -282,11 +287,13 @@ void GPUParticles2D::restart() { void GPUParticles2D::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { RID texture_rid; - if (texture.is_valid()) + if (texture.is_valid()) { texture_rid = texture->get_rid(); + } RID normal_rid; - if (normal_map.is_valid()) + if (normal_map.is_valid()) { normal_rid = normal_map->get_rid(); + } RS::get_singleton()->canvas_item_add_particles(get_canvas_item(), particles, texture_rid, normal_rid); diff --git a/scene/2d/joints_2d.cpp b/scene/2d/joints_2d.cpp index a67b951155..0d126b949d 100644 --- a/scene/2d/joints_2d.cpp +++ b/scene/2d/joints_2d.cpp @@ -36,8 +36,9 @@ void Joint2D::_update_joint(bool p_only_free) { if (joint.is_valid()) { - if (ba.is_valid() && bb.is_valid() && exclude_from_collision) + if (ba.is_valid() && bb.is_valid() && exclude_from_collision) { PhysicsServer2D::get_singleton()->joint_disable_collisions_between_bodies(joint, false); + } PhysicsServer2D::get_singleton()->free(joint); joint = RID(); @@ -45,25 +46,29 @@ void Joint2D::_update_joint(bool p_only_free) { bb = RID(); } - if (p_only_free || !is_inside_tree()) + if (p_only_free || !is_inside_tree()) { return; + } Node *node_a = has_node(get_node_a()) ? get_node(get_node_a()) : (Node *)nullptr; Node *node_b = has_node(get_node_b()) ? get_node(get_node_b()) : (Node *)nullptr; - if (!node_a || !node_b) + if (!node_a || !node_b) { return; + } PhysicsBody2D *body_a = Object::cast_to<PhysicsBody2D>(node_a); PhysicsBody2D *body_b = Object::cast_to<PhysicsBody2D>(node_b); - if (!body_a || !body_b) + if (!body_a || !body_b) { return; + } joint = _configure_joint(body_a, body_b); - if (!joint.is_valid()) + if (!joint.is_valid()) { return; + } PhysicsServer2D::get_singleton()->get_singleton()->joint_set_param(joint, PhysicsServer2D::JOINT_PARAM_BIAS, bias); @@ -74,8 +79,9 @@ void Joint2D::_update_joint(bool p_only_free) { } void Joint2D::set_node_a(const NodePath &p_node_a) { - if (a == p_node_a) + if (a == p_node_a) { return; + } a = p_node_a; _update_joint(); @@ -86,8 +92,9 @@ NodePath Joint2D::get_node_a() const { } void Joint2D::set_node_b(const NodePath &p_node_b) { - if (b == p_node_b) + if (b == p_node_b) { return; + } b = p_node_b; _update_joint(); } @@ -111,8 +118,9 @@ void Joint2D::_notification(int p_what) { void Joint2D::set_bias(real_t p_bias) { bias = p_bias; - if (joint.is_valid()) + if (joint.is_valid()) { PhysicsServer2D::get_singleton()->get_singleton()->joint_set_param(joint, PhysicsServer2D::JOINT_PARAM_BIAS, bias); + } } real_t Joint2D::get_bias() const { @@ -120,8 +128,9 @@ real_t Joint2D::get_bias() const { } void Joint2D::set_exclude_nodes_from_collision(bool p_enable) { - if (exclude_from_collision == p_enable) + if (exclude_from_collision == p_enable) { return; + } _update_joint(true); exclude_from_collision = p_enable; @@ -163,8 +172,9 @@ Joint2D::Joint2D() { void PinJoint2D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_DRAW: { - if (!is_inside_tree()) + if (!is_inside_tree()) { break; + } if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) { break; @@ -185,8 +195,9 @@ RID PinJoint2D::_configure_joint(PhysicsBody2D *body_a, PhysicsBody2D *body_b) { void PinJoint2D::set_softness(real_t p_softness) { softness = p_softness; update(); - if (get_joint().is_valid()) + if (get_joint().is_valid()) { PhysicsServer2D::get_singleton()->pin_joint_set_param(get_joint(), PhysicsServer2D::PIN_JOINT_SOFTNESS, p_softness); + } } real_t PinJoint2D::get_softness() const { @@ -211,8 +222,9 @@ PinJoint2D::PinJoint2D() { void GrooveJoint2D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_DRAW: { - if (!is_inside_tree()) + if (!is_inside_tree()) { break; + } if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) { break; @@ -275,8 +287,9 @@ GrooveJoint2D::GrooveJoint2D() { void DampedSpringJoint2D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_DRAW: { - if (!is_inside_tree()) + if (!is_inside_tree()) { break; + } if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) { break; @@ -295,8 +308,9 @@ RID DampedSpringJoint2D::_configure_joint(PhysicsBody2D *body_a, PhysicsBody2D * Vector2 anchor_B = gt.xform(Vector2(0, length)); RID dsj = PhysicsServer2D::get_singleton()->damped_spring_joint_create(anchor_A, anchor_B, body_a->get_rid(), body_b->get_rid()); - if (rest_length) + if (rest_length) { PhysicsServer2D::get_singleton()->damped_string_joint_set_param(dsj, PhysicsServer2D::DAMPED_STRING_REST_LENGTH, rest_length); + } PhysicsServer2D::get_singleton()->damped_string_joint_set_param(dsj, PhysicsServer2D::DAMPED_STRING_STIFFNESS, stiffness); PhysicsServer2D::get_singleton()->damped_string_joint_set_param(dsj, PhysicsServer2D::DAMPED_STRING_DAMPING, damping); @@ -315,8 +329,9 @@ real_t DampedSpringJoint2D::get_length() const { void DampedSpringJoint2D::set_rest_length(real_t p_rest_length) { rest_length = p_rest_length; update(); - if (get_joint().is_valid()) + if (get_joint().is_valid()) { PhysicsServer2D::get_singleton()->damped_string_joint_set_param(get_joint(), PhysicsServer2D::DAMPED_STRING_REST_LENGTH, p_rest_length ? p_rest_length : length); + } } real_t DampedSpringJoint2D::get_rest_length() const { @@ -326,8 +341,9 @@ real_t DampedSpringJoint2D::get_rest_length() const { void DampedSpringJoint2D::set_stiffness(real_t p_stiffness) { stiffness = p_stiffness; update(); - if (get_joint().is_valid()) + if (get_joint().is_valid()) { PhysicsServer2D::get_singleton()->damped_string_joint_set_param(get_joint(), PhysicsServer2D::DAMPED_STRING_STIFFNESS, p_stiffness); + } } real_t DampedSpringJoint2D::get_stiffness() const { @@ -337,8 +353,9 @@ real_t DampedSpringJoint2D::get_stiffness() const { void DampedSpringJoint2D::set_damping(real_t p_damping) { damping = p_damping; update(); - if (get_joint().is_valid()) + if (get_joint().is_valid()) { PhysicsServer2D::get_singleton()->damped_string_joint_set_param(get_joint(), PhysicsServer2D::DAMPED_STRING_DAMPING, p_damping); + } } real_t DampedSpringJoint2D::get_damping() const { diff --git a/scene/2d/light_2d.cpp b/scene/2d/light_2d.cpp index 2bae6bbd48..1e7e9f6b6a 100644 --- a/scene/2d/light_2d.cpp +++ b/scene/2d/light_2d.cpp @@ -59,8 +59,9 @@ bool Light2D::_edit_use_pivot() const { } Rect2 Light2D::_edit_get_rect() const { - if (texture.is_null()) + if (texture.is_null()) { return Rect2(); + } Size2 s = texture->get_size() * _scale; return Rect2(texture_offset - s / 2.0, s); @@ -72,16 +73,18 @@ bool Light2D::_edit_use_rect() const { #endif Rect2 Light2D::get_anchorable_rect() const { - if (texture.is_null()) + if (texture.is_null()) { return Rect2(); + } Size2 s = texture->get_size() * _scale; return Rect2(texture_offset - s / 2.0, s); } void Light2D::_update_light_visibility() { - if (!is_inside_tree()) + if (!is_inside_tree()) { return; + } bool editor_ok = true; @@ -122,10 +125,11 @@ bool Light2D::is_editor_only() const { void Light2D::set_texture(const Ref<Texture2D> &p_texture) { texture = p_texture; - if (texture.is_valid()) + if (texture.is_valid()) { RS::get_singleton()->canvas_light_set_texture(canvas_light, texture->get_rid()); - else + } else { RS::get_singleton()->canvas_light_set_texture(canvas_light, RID()); + } update_configuration_warning(); } diff --git a/scene/2d/light_occluder_2d.cpp b/scene/2d/light_occluder_2d.cpp index 80a0c0c40a..0f4880f69a 100644 --- a/scene/2d/light_occluder_2d.cpp +++ b/scene/2d/light_occluder_2d.cpp @@ -42,10 +42,11 @@ Rect2 OccluderPolygon2D::_edit_get_rect() const { item_rect = Rect2(); for (int i = 0; i < polygon.size(); i++) { Vector2 pos = r[i]; - if (i == 0) + if (i == 0) { item_rect.position = pos; - else + } else { item_rect.expand_to(pos); + } } rect_cache_dirty = false; } else { @@ -73,8 +74,9 @@ bool OccluderPolygon2D::_edit_is_selected_on_click(const Point2 &p_point, double const Vector2 *points = polygon.ptr(); for (int i = 0; i < polygon.size() - 1; i++) { Vector2 p = Geometry::get_closest_point_to_segment_2d(p_point, &points[i]); - if (p.distance_to(p_point) <= d) + if (p.distance_to(p_point) <= d) { return true; + } } return false; @@ -94,11 +96,13 @@ Vector<Vector2> OccluderPolygon2D::get_polygon() const { } void OccluderPolygon2D::set_closed(bool p_closed) { - if (closed == p_closed) + if (closed == p_closed) { return; + } closed = p_closed; - if (polygon.size()) + if (polygon.size()) { RS::get_singleton()->canvas_occluder_polygon_set_shape(occ_polygon, polygon, closed); + } emit_changed(); } @@ -207,19 +211,22 @@ bool LightOccluder2D::_edit_is_selected_on_click(const Point2 &p_point, double p void LightOccluder2D::set_occluder_polygon(const Ref<OccluderPolygon2D> &p_polygon) { #ifdef DEBUG_ENABLED - if (occluder_polygon.is_valid()) + if (occluder_polygon.is_valid()) { occluder_polygon->disconnect("changed", callable_mp(this, &LightOccluder2D::_poly_changed)); + } #endif occluder_polygon = p_polygon; - if (occluder_polygon.is_valid()) + if (occluder_polygon.is_valid()) { RS::get_singleton()->canvas_light_occluder_set_polygon(occluder, occluder_polygon->get_rid()); - else + } else { RS::get_singleton()->canvas_light_occluder_set_polygon(occluder, RID()); + } #ifdef DEBUG_ENABLED - if (occluder_polygon.is_valid()) + if (occluder_polygon.is_valid()) { occluder_polygon->connect("changed", callable_mp(this, &LightOccluder2D::_poly_changed)); + } update(); #endif } diff --git a/scene/2d/line_2d.cpp b/scene/2d/line_2d.cpp index 0ec58ec176..28183403f2 100644 --- a/scene/2d/line_2d.cpp +++ b/scene/2d/line_2d.cpp @@ -52,8 +52,9 @@ Line2D::Line2D() { #ifdef TOOLS_ENABLED Rect2 Line2D::_edit_get_rect() const { - if (_points.size() == 0) + if (_points.size() == 0) { return Rect2(0, 0, 0, 0); + } Vector2 d = Vector2(_width, _width); Rect2 aabb = Rect2(_points[0] - d, 2 * d); for (int i = 1; i < _points.size(); i++) { @@ -72,8 +73,9 @@ bool Line2D::_edit_is_selected_on_click(const Point2 &p_point, double p_toleranc const Vector2 *points = _points.ptr(); for (int i = 0; i < _points.size() - 1; i++) { Vector2 p = Geometry::get_closest_point_to_segment_2d(p_point, &points[i]); - if (p.distance_to(p_point) <= d) + if (p.distance_to(p_point) <= d) { return true; + } } return false; @@ -86,8 +88,9 @@ void Line2D::set_points(const Vector<Vector2> &p_points) { } void Line2D::set_width(float p_width) { - if (p_width < 0.0) + if (p_width < 0.0) { p_width = 0.0; + } _width = p_width; update(); } @@ -239,8 +242,9 @@ void Line2D::_notification(int p_what) { } void Line2D::set_sharp_limit(float p_limit) { - if (p_limit < 0.f) + if (p_limit < 0.f) { p_limit = 0.f; + } _sharp_limit = p_limit; update(); } @@ -250,8 +254,9 @@ float Line2D::get_sharp_limit() const { } void Line2D::set_round_precision(int p_precision) { - if (p_precision < 1) + if (p_precision < 1) { p_precision = 1; + } _round_precision = p_precision; update(); } @@ -270,8 +275,9 @@ bool Line2D::get_antialiased() const { } void Line2D::_draw() { - if (_points.size() <= 1 || _width == 0.f) + if (_points.size() <= 1 || _width == 0.f) { return; + } // TODO Is this really needed? // Copy points for faster access diff --git a/scene/2d/line_builder.cpp b/scene/2d/line_builder.cpp index 56293a7b8d..f1522dbaeb 100644 --- a/scene/2d/line_builder.cpp +++ b/scene/2d/line_builder.cpp @@ -53,8 +53,9 @@ static SegmentIntersectionResult segment_intersection( float ub = (ab.x * (a.y - c.y) - ab.y * (a.x - c.x)) / div; *out_intersection = a + ua * ab; if (ua >= 0.f && ua <= 1.f && - ub >= 0.f && ub <= 1.f) + ub >= 0.f && ub <= 1.f) { return SEGMENT_INTERSECT; + } return SEGMENT_NO_INTERSECT; } @@ -157,28 +158,32 @@ void LineBuilder::build() { //Adjust totalDistance. // The line's outer length will be a little higher due to begin and end caps if (begin_cap_mode == Line2D::LINE_CAP_BOX || begin_cap_mode == Line2D::LINE_CAP_ROUND) { - if (retrieve_curve) + if (retrieve_curve) { total_distance += width * curve->interpolate_baked(0.f) * 0.5f; - else + } else { total_distance += width * 0.5f; + } } if (end_cap_mode == Line2D::LINE_CAP_BOX || end_cap_mode == Line2D::LINE_CAP_ROUND) { - if (retrieve_curve) + if (retrieve_curve) { total_distance += width * curve->interpolate_baked(1.f) * 0.5f; - else + } else { total_distance += width * 0.5f; + } } } - if (_interpolate_color) + if (_interpolate_color) { color0 = gradient->get_color(0); - else + } else { colors.push_back(default_color); + } float uvx0 = 0.f; float uvx1 = 0.f; - if (retrieve_curve) + if (retrieve_curve) { width_factor = curve->interpolate_baked(0.f); + } pos_up0 += u0 * hw * width_factor; pos_down0 -= u0 * hw * width_factor; @@ -269,10 +274,10 @@ void LineBuilder::build() { pos1 + inner_normal1, pos2 + inner_normal1, &corner_pos_in); - if (intersection_result == SEGMENT_INTERSECT) + if (intersection_result == SEGMENT_INTERSECT) { // Inner parts of the segments intersect corner_pos_out = 2.f * pos1 - corner_pos_in; - else { + } else { // No intersection, segments are either parallel or too sharp corner_pos_in = pos1 + inner_normal0; corner_pos_out = pos1 - inner_normal0; @@ -383,10 +388,11 @@ void LineBuilder::build() { strip_add_arc(pos1, vbegin.angle_to(vend), orientation); } - if (intersection_result != SEGMENT_INTERSECT) + if (intersection_result != SEGMENT_INTERSECT) { // In this case the joint is too corrputed to be re-used, // start again the strip with fallback points strip_begin(pos_up0, pos_down0, color1, uvx1); + } } } // Last (or only) segment @@ -547,8 +553,9 @@ void LineBuilder::strip_add_arc(Vector2 center, float angle_delta, Orientation o float angle_step = Math_PI / static_cast<float>(round_precision); float steps = Math::abs(angle_delta) / angle_step; - if (angle_delta < 0.f) + if (angle_delta < 0.f) { angle_step = -angle_step; + } float t = Vector2(1, 0).angle_to(vbegin); float end_angle = t + angle_delta; @@ -573,8 +580,9 @@ void LineBuilder::new_arc(Vector2 center, Vector2 vbegin, float angle_delta, Col float angle_step = Math_PI / static_cast<float>(round_precision); float steps = Math::abs(angle_delta) / angle_step; - if (angle_delta < 0.f) + if (angle_delta < 0.f) { angle_step = -angle_step; + } float t = Vector2(1, 0).angle_to(vbegin); float end_angle = t + angle_delta; @@ -585,10 +593,12 @@ void LineBuilder::new_arc(Vector2 center, Vector2 vbegin, float angle_delta, Col // Center vertice int vi = vertices.size(); vertices.push_back(center); - if (_interpolate_color) + if (_interpolate_color) { colors.push_back(color); - if (texture_mode != Line2D::LINE_TEXTURE_NONE) + } + if (texture_mode != Line2D::LINE_TEXTURE_NONE) { uvs.push_back(interpolate(uv_rect, Vector2(0.5f, 0.5f))); + } // Arc vertices for (int ti = 0; ti < steps; ++ti, t += angle_step) { @@ -596,8 +606,9 @@ void LineBuilder::new_arc(Vector2 center, Vector2 vbegin, float angle_delta, Col rpos = center + sc * radius; vertices.push_back(rpos); - if (_interpolate_color) + if (_interpolate_color) { colors.push_back(color); + } if (texture_mode != Line2D::LINE_TEXTURE_NONE) { Vector2 tsc = Vector2(Math::cos(tt), Math::sin(tt)); uvs.push_back(interpolate(uv_rect, 0.5f * (tsc + Vector2(1.f, 1.f)))); @@ -609,8 +620,9 @@ void LineBuilder::new_arc(Vector2 center, Vector2 vbegin, float angle_delta, Col Vector2 sc = Vector2(Math::cos(end_angle), Math::sin(end_angle)); rpos = center + sc * radius; vertices.push_back(rpos); - if (_interpolate_color) + if (_interpolate_color) { colors.push_back(color); + } if (texture_mode != Line2D::LINE_TEXTURE_NONE) { tt = tt_begin + angle_delta; Vector2 tsc = Vector2(Math::cos(tt), Math::sin(tt)); diff --git a/scene/2d/mesh_instance_2d.cpp b/scene/2d/mesh_instance_2d.cpp index b4dd09c513..897595ad1f 100644 --- a/scene/2d/mesh_instance_2d.cpp +++ b/scene/2d/mesh_instance_2d.cpp @@ -65,8 +65,9 @@ Ref<Mesh> MeshInstance2D::get_mesh() const { } void MeshInstance2D::set_texture(const Ref<Texture2D> &p_texture) { - if (p_texture == texture) + if (p_texture == texture) { return; + } texture = p_texture; update(); emit_signal("texture_changed"); diff --git a/scene/2d/multimesh_instance_2d.cpp b/scene/2d/multimesh_instance_2d.cpp index d99d5b9b30..b99c0a3fa9 100644 --- a/scene/2d/multimesh_instance_2d.cpp +++ b/scene/2d/multimesh_instance_2d.cpp @@ -65,8 +65,9 @@ Ref<MultiMesh> MultiMeshInstance2D::get_multimesh() const { } void MultiMeshInstance2D::set_texture(const Ref<Texture2D> &p_texture) { - if (p_texture == texture) + if (p_texture == texture) { return; + } texture = p_texture; update(); emit_signal("texture_changed"); diff --git a/scene/2d/navigation_agent_2d.cpp b/scene/2d/navigation_agent_2d.cpp index 42dabeb488..cb2dbba0fe 100644 --- a/scene/2d/navigation_agent_2d.cpp +++ b/scene/2d/navigation_agent_2d.cpp @@ -100,10 +100,11 @@ void NavigationAgent2D::_notification(int p_what) { Node *p = get_parent(); while (p != nullptr) { nav = Object::cast_to<Navigation2D>(p); - if (nav != nullptr) + if (nav != nullptr) { p = nullptr; - else + } else { p = p->get_parent(); + } } set_navigation(nav); @@ -145,8 +146,9 @@ NavigationAgent2D::~NavigationAgent2D() { } void NavigationAgent2D::set_navigation(Navigation2D *p_nav) { - if (navigation == p_nav) + if (navigation == p_nav) { return; // Pointless + } navigation = p_nav; NavigationServer2D::get_singleton()->agent_set_map(agent, navigation == nullptr ? RID() : navigation->get_rid()); @@ -276,12 +278,15 @@ String NavigationAgent2D::get_configuration_warning() const { } void NavigationAgent2D::update_navigation() { - if (agent_parent == nullptr) + if (agent_parent == nullptr) { return; - if (navigation == nullptr) + } + if (navigation == nullptr) { return; - if (update_frame_id == Engine::get_singleton()->get_physics_frames()) + } + if (update_frame_id == Engine::get_singleton()->get_physics_frames()) { return; + } update_frame_id = Engine::get_singleton()->get_physics_frames(); @@ -314,8 +319,9 @@ void NavigationAgent2D::update_navigation() { emit_signal("path_changed"); } - if (navigation_path.size() == 0) + if (navigation_path.size() == 0) { return; + } // Check if we can advance the navigation path if (navigation_finished == false) { diff --git a/scene/2d/navigation_obstacle_2d.cpp b/scene/2d/navigation_obstacle_2d.cpp index 2352064ae6..568023bbe2 100644 --- a/scene/2d/navigation_obstacle_2d.cpp +++ b/scene/2d/navigation_obstacle_2d.cpp @@ -51,10 +51,11 @@ void NavigationObstacle2D::_notification(int p_what) { Node *p = get_parent(); while (p != nullptr) { nav = Object::cast_to<Navigation2D>(p); - if (nav != nullptr) + if (nav != nullptr) { p = nullptr; - else + } else { p = p->get_parent(); + } } set_navigation(nav); @@ -86,8 +87,9 @@ NavigationObstacle2D::~NavigationObstacle2D() { } void NavigationObstacle2D::set_navigation(Navigation2D *p_nav) { - if (navigation == p_nav) + if (navigation == p_nav) { return; // Pointless + } navigation = p_nav; NavigationServer2D::get_singleton()->agent_set_map(agent, navigation == nullptr ? RID() : navigation->get_rid()); @@ -138,8 +140,9 @@ void NavigationObstacle2D::update_agent_shape() { radius *= MAX(s.x, s.y); } - if (radius == 0.0) + if (radius == 0.0) { radius = 1.0; // Never a 0 radius + } // Initialize the Agent as an object NavigationServer2D::get_singleton()->agent_set_neighbor_dist(agent, 0.0); diff --git a/scene/2d/navigation_region_2d.cpp b/scene/2d/navigation_region_2d.cpp index 1ab414c7ea..72bde17428 100644 --- a/scene/2d/navigation_region_2d.cpp +++ b/scene/2d/navigation_region_2d.cpp @@ -47,8 +47,9 @@ Rect2 NavigationPolygon::_edit_get_rect() const { for (int i = 0; i < outlines.size(); i++) { const Vector<Vector2> &outline = outlines[i]; const int outline_size = outline.size(); - if (outline_size < 3) + if (outline_size < 3) { continue; + } const Vector2 *p = outline.ptr(); for (int j = 0; j < outline_size; j++) { if (first) { @@ -69,10 +70,12 @@ bool NavigationPolygon::_edit_is_selected_on_click(const Point2 &p_point, double for (int i = 0; i < outlines.size(); i++) { const Vector<Vector2> &outline = outlines[i]; const int outline_size = outline.size(); - if (outline_size < 3) + if (outline_size < 3) { continue; - if (Geometry::is_point_in_polygon(p_point, Variant(outline))) + } + if (Geometry::is_point_in_polygon(p_point, Variant(outline))) { return true; + } } return false; } @@ -231,8 +234,9 @@ void NavigationPolygon::make_polygons_from_outlines() { for (int i = 0; i < outlines.size(); i++) { Vector<Vector2> ol = outlines[i]; int olsize = ol.size(); - if (olsize < 3) + if (olsize < 3) { continue; + } const Vector2 *r = ol.ptr(); for (int j = 0; j < olsize; j++) { outside_point.x = MAX(r[j].x, outside_point.x); @@ -245,20 +249,23 @@ void NavigationPolygon::make_polygons_from_outlines() { for (int i = 0; i < outlines.size(); i++) { Vector<Vector2> ol = outlines[i]; int olsize = ol.size(); - if (olsize < 3) + if (olsize < 3) { continue; + } const Vector2 *r = ol.ptr(); int interscount = 0; //test if this is an outer outline for (int k = 0; k < outlines.size(); k++) { - if (i == k) + if (i == k) { continue; //no self intersect + } Vector<Vector2> ol2 = outlines[k]; int olsize2 = ol2.size(); - if (olsize2 < 3) + if (olsize2 < 3) { continue; + } const Vector2 *r2 = ol2.ptr(); for (int l = 0; l < olsize2; l++) { @@ -276,9 +283,9 @@ void NavigationPolygon::make_polygons_from_outlines() { tp[j] = r[j]; } - if (outer) + if (outer) { tp.SetOrientation(TRIANGULATOR_CCW); - else { + } else { tp.SetOrientation(TRIANGULATOR_CW); tp.SetHole(true); } @@ -346,12 +353,14 @@ void NavigationPolygon::_bind_methods() { } void NavigationRegion2D::set_enabled(bool p_enabled) { - if (enabled == p_enabled) + if (enabled == p_enabled) { return; + } enabled = p_enabled; - if (!is_inside_tree()) + if (!is_inside_tree()) { return; + } if (!enabled) { NavigationServer2D::get_singleton()->region_set_map(region, RID()); @@ -361,8 +370,9 @@ void NavigationRegion2D::set_enabled(bool p_enabled) { } } - if (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_navigation_hint()) + if (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_navigation_hint()) { update(); + } } bool NavigationRegion2D::is_enabled() const { @@ -411,8 +421,9 @@ void NavigationRegion2D::_notification(int p_what) { if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_navigation_hint()) && navpoly.is_valid()) { Vector<Vector2> verts = navpoly->get_vertices(); int vsize = verts.size(); - if (vsize < 3) + if (vsize < 3) { return; + } Color color; if (enabled) { @@ -478,13 +489,15 @@ Ref<NavigationPolygon> NavigationRegion2D::get_navigation_polygon() const { } void NavigationRegion2D::_navpoly_changed() { - if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_navigation_hint())) + if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_navigation_hint())) { update(); + } } String NavigationRegion2D::get_configuration_warning() const { - if (!is_visible_in_tree() || !is_inside_tree()) + if (!is_visible_in_tree() || !is_inside_tree()) { return String(); + } if (!navpoly.is_valid()) { return TTR("A NavigationPolygon resource must be set or created for this node to work. Please set a property or draw a polygon."); diff --git a/scene/2d/node_2d.cpp b/scene/2d/node_2d.cpp index 388d64334d..72250e96b3 100644 --- a/scene/2d/node_2d.cpp +++ b/scene/2d/node_2d.cpp @@ -98,17 +98,21 @@ void Node2D::_edit_set_rect(const Rect2 &p_edit_rect) { Rect2 r = _edit_get_rect(); Vector2 zero_offset; - if (r.size.x != 0) + if (r.size.x != 0) { zero_offset.x = -r.position.x / r.size.x; - if (r.size.y != 0) + } + if (r.size.y != 0) { zero_offset.y = -r.position.y / r.size.y; + } Size2 new_scale(1, 1); - if (r.size.x != 0) + if (r.size.x != 0) { new_scale.x = p_edit_rect.size.x / r.size.x; - if (r.size.y != 0) + } + if (r.size.y != 0) { new_scale.y = p_edit_rect.size.y / r.size.y; + } Point2 new_pos = p_edit_rect.position + p_edit_rect.size * zero_offset; @@ -139,23 +143,26 @@ void Node2D::_update_transform() { RenderingServer::get_singleton()->canvas_item_set_transform(get_canvas_item(), _mat); - if (!is_inside_tree()) + if (!is_inside_tree()) { return; + } _notify_transform(); } void Node2D::set_position(const Point2 &p_pos) { - if (_xform_dirty) + if (_xform_dirty) { ((Node2D *)this)->_update_xform_values(); + } pos = p_pos; _update_transform(); _change_notify("position"); } void Node2D::set_rotation(float p_radians) { - if (_xform_dirty) + if (_xform_dirty) { ((Node2D *)this)->_update_xform_values(); + } angle = p_radians; _update_transform(); _change_notify("rotation"); @@ -163,8 +170,9 @@ void Node2D::set_rotation(float p_radians) { } void Node2D::set_skew(float p_radians) { - if (_xform_dirty) + if (_xform_dirty) { ((Node2D *)this)->_update_xform_values(); + } skew = p_radians; _update_transform(); _change_notify("skew"); @@ -180,34 +188,40 @@ void Node2D::set_skew_degrees(float p_degrees) { } void Node2D::set_scale(const Size2 &p_scale) { - if (_xform_dirty) + if (_xform_dirty) { ((Node2D *)this)->_update_xform_values(); + } _scale = p_scale; // Avoid having 0 scale values, can lead to errors in physics and rendering. - if (_scale.x == 0) + if (_scale.x == 0) { _scale.x = CMP_EPSILON; - if (_scale.y == 0) + } + if (_scale.y == 0) { _scale.y = CMP_EPSILON; + } _update_transform(); _change_notify("scale"); } Point2 Node2D::get_position() const { - if (_xform_dirty) + if (_xform_dirty) { ((Node2D *)this)->_update_xform_values(); + } return pos; } float Node2D::get_rotation() const { - if (_xform_dirty) + if (_xform_dirty) { ((Node2D *)this)->_update_xform_values(); + } return angle; } float Node2D::get_skew() const { - if (_xform_dirty) + if (_xform_dirty) { ((Node2D *)this)->_update_xform_values(); + } return skew; } @@ -221,8 +235,9 @@ float Node2D::get_skew_degrees() const { } Size2 Node2D::get_scale() const { - if (_xform_dirty) + if (_xform_dirty) { ((Node2D *)this)->_update_xform_values(); + } return _scale; } @@ -250,16 +265,18 @@ void Node2D::apply_scale(const Size2 &p_amount) { void Node2D::move_x(float p_delta, bool p_scaled) { Transform2D t = get_transform(); Vector2 m = t[0]; - if (!p_scaled) + if (!p_scaled) { m.normalize(); + } set_position(t[2] + m * p_delta); } void Node2D::move_y(float p_delta, bool p_scaled) { Transform2D t = get_transform(); Vector2 m = t[1]; - if (!p_scaled) + if (!p_scaled) { m.normalize(); + } set_position(t[2] + m * p_delta); } @@ -320,18 +337,20 @@ void Node2D::set_transform(const Transform2D &p_transform) { RenderingServer::get_singleton()->canvas_item_set_transform(get_canvas_item(), _mat); - if (!is_inside_tree()) + if (!is_inside_tree()) { return; + } _notify_transform(); } void Node2D::set_global_transform(const Transform2D &p_transform) { CanvasItem *pi = get_parent_item(); - if (pi) + if (pi) { set_transform(pi->get_global_transform().affine_inverse() * p_transform); - else + } else { set_transform(p_transform); + } } void Node2D::set_z_index(int p_z) { @@ -343,8 +362,9 @@ void Node2D::set_z_index(int p_z) { } void Node2D::set_z_as_relative(bool p_enabled) { - if (z_relative == p_enabled) + if (z_relative == p_enabled) { return; + } z_relative = p_enabled; RS::get_singleton()->canvas_item_set_z_as_relative_to_parent(get_canvas_item(), p_enabled); } @@ -358,16 +378,18 @@ int Node2D::get_z_index() const { } Transform2D Node2D::get_relative_transform_to_parent(const Node *p_parent) const { - if (p_parent == this) + if (p_parent == this) { return Transform2D(); + } Node2D *parent_2d = Object::cast_to<Node2D>(get_parent()); ERR_FAIL_COND_V(!parent_2d, Transform2D()); - if (p_parent == parent_2d) + if (p_parent == parent_2d) { return get_transform(); - else + } else { return parent_2d->get_relative_transform_to_parent(p_parent) * get_transform(); + } } void Node2D::look_at(const Vector2 &p_pos) { diff --git a/scene/2d/parallax_background.cpp b/scene/2d/parallax_background.cpp index 6930307840..416622e6d5 100644 --- a/scene/2d/parallax_background.cpp +++ b/scene/2d/parallax_background.cpp @@ -66,8 +66,9 @@ void ParallaxBackground::set_scroll_offset(const Point2 &p_ofs) { } void ParallaxBackground::_update_scroll() { - if (!is_inside_tree()) + if (!is_inside_tree()) { return; + } Vector2 ofs = base_offset + offset * base_scale; @@ -75,17 +76,19 @@ void ParallaxBackground::_update_scroll() { ofs = -ofs; if (limit_begin.x < limit_end.x) { - if (ofs.x < limit_begin.x) + if (ofs.x < limit_begin.x) { ofs.x = limit_begin.x; - else if (ofs.x + vps.x > limit_end.x) + } else if (ofs.x + vps.x > limit_end.x) { ofs.x = limit_end.x - vps.x; + } } if (limit_begin.y < limit_end.y) { - if (ofs.y < limit_begin.y) + if (ofs.y < limit_begin.y) { ofs.y = limit_begin.y; - else if (ofs.y + vps.y > limit_end.y) + } else if (ofs.y + vps.y > limit_end.y) { ofs.y = limit_end.y - vps.y; + } } ofs = -ofs; @@ -93,13 +96,15 @@ void ParallaxBackground::_update_scroll() { for (int i = 0; i < get_child_count(); i++) { ParallaxLayer *l = Object::cast_to<ParallaxLayer>(get_child(i)); - if (!l) + if (!l) { continue; + } - if (ignore_camera_zoom) + if (ignore_camera_zoom) { l->set_base_offset_and_scale(ofs, 1.0, screen_offset); - else + } else { l->set_base_offset_and_scale(ofs, scale, screen_offset); + } } } diff --git a/scene/2d/parallax_layer.cpp b/scene/2d/parallax_layer.cpp index ffc6e50da2..4ed335dec8 100644 --- a/scene/2d/parallax_layer.cpp +++ b/scene/2d/parallax_layer.cpp @@ -64,8 +64,9 @@ Size2 ParallaxLayer::get_motion_offset() const { } void ParallaxLayer::_update_mirroring() { - if (!is_inside_tree()) + if (!is_inside_tree()) { return; + } ParallaxBackground *pb = Object::cast_to<ParallaxBackground>(get_parent()); if (pb) { @@ -78,10 +79,12 @@ void ParallaxLayer::_update_mirroring() { void ParallaxLayer::set_mirroring(const Size2 &p_mirroring) { mirroring = p_mirroring; - if (mirroring.x < 0) + if (mirroring.x < 0) { mirroring.x = 0; - if (mirroring.y < 0) + } + if (mirroring.y < 0) { mirroring.y = 0; + } _update_mirroring(); } @@ -107,10 +110,12 @@ void ParallaxLayer::_notification(int p_what) { void ParallaxLayer::set_base_offset_and_scale(const Point2 &p_offset, float p_scale, const Point2 &p_screen_offset) { screen_offset = p_screen_offset; - if (!is_inside_tree()) + if (!is_inside_tree()) { return; - if (Engine::get_singleton()->is_editor_hint()) + } + if (Engine::get_singleton()->is_editor_hint()) { return; + } Point2 new_ofs = (screen_offset + (p_offset - screen_offset) * motion_scale) + motion_offset * p_scale + orig_offset * p_scale; diff --git a/scene/2d/path_2d.cpp b/scene/2d/path_2d.cpp index a914da8fe0..046e4dbd41 100644 --- a/scene/2d/path_2d.cpp +++ b/scene/2d/path_2d.cpp @@ -39,8 +39,9 @@ #ifdef TOOLS_ENABLED Rect2 Path2D::_edit_get_rect() const { - if (!curve.is_valid() || curve->get_point_count() == 0) + if (!curve.is_valid() || curve->get_point_count() == 0) { return Rect2(0, 0, 0, 0); + } Rect2 aabb = Rect2(curve->get_point_position(0), Vector2(0, 0)); @@ -73,8 +74,9 @@ bool Path2D::_edit_is_selected_on_click(const Point2 &p_point, double p_toleranc s[1] = curve->interpolate(i, frac); Vector2 p = Geometry::get_closest_point_to_segment_2d(p_point, s); - if (p.distance_to(p_point) <= p_tolerance) + if (p.distance_to(p_point) <= p_tolerance) { return true; + } s[0] = s[1]; } @@ -156,12 +158,14 @@ Path2D::Path2D() { ///////////////////////////////////////////////////////////////////////////////// void PathFollow2D::_update_transform() { - if (!path) + if (!path) { return; + } Ref<Curve2D> c = path->get_curve(); - if (!c.is_valid()) + if (!c.is_valid()) { return; + } float path_length = c->get_baked_length(); if (path_length == 0) { @@ -240,16 +244,18 @@ bool PathFollow2D::get_cubic_interpolation() const { void PathFollow2D::_validate_property(PropertyInfo &property) const { if (property.name == "offset") { float max = 10000; - if (path && path->get_curve().is_valid()) + if (path && path->get_curve().is_valid()) { max = path->get_curve()->get_baked_length(); + } property.hint_string = "0," + rtos(max) + ",0.01,or_lesser,or_greater"; } } String PathFollow2D::get_configuration_warning() const { - if (!is_visible_in_tree() || !is_inside_tree()) + if (!is_visible_in_tree() || !is_inside_tree()) { return String(); + } if (!Object::cast_to<Path2D>(get_parent())) { return TTR("PathFollow2D only works when set as a child of a Path2D node."); @@ -317,8 +323,9 @@ void PathFollow2D::set_offset(float p_offset) { void PathFollow2D::set_h_offset(float p_h_offset) { h_offset = p_h_offset; - if (path) + if (path) { _update_transform(); + } } float PathFollow2D::get_h_offset() const { @@ -327,8 +334,9 @@ float PathFollow2D::get_h_offset() const { void PathFollow2D::set_v_offset(float p_v_offset) { v_offset = p_v_offset; - if (path) + if (path) { _update_transform(); + } } float PathFollow2D::get_v_offset() const { @@ -340,15 +348,17 @@ float PathFollow2D::get_offset() const { } void PathFollow2D::set_unit_offset(float p_unit_offset) { - if (path && path->get_curve().is_valid() && path->get_curve()->get_baked_length()) + if (path && path->get_curve().is_valid() && path->get_curve()->get_baked_length()) { set_offset(p_unit_offset * path->get_curve()->get_baked_length()); + } } float PathFollow2D::get_unit_offset() const { - if (path && path->get_curve().is_valid() && path->get_curve()->get_baked_length()) + if (path && path->get_curve().is_valid() && path->get_curve()->get_baked_length()) { return get_offset() / path->get_curve()->get_baked_length(); - else + } else { return 0; + } } void PathFollow2D::set_lookahead(float p_lookahead) { diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index 0225fd55c2..ae448129bc 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -96,10 +96,11 @@ uint32_t PhysicsBody2D::get_collision_mask() const { void PhysicsBody2D::set_collision_mask_bit(int p_bit, bool p_value) { uint32_t mask = get_collision_mask(); - if (p_value) + if (p_value) { mask |= 1 << p_bit; - else + } else { mask &= ~(1 << p_bit); + } set_collision_mask(mask); } @@ -109,10 +110,11 @@ bool PhysicsBody2D::get_collision_mask_bit(int p_bit) const { void PhysicsBody2D::set_collision_layer_bit(int p_bit, bool p_value) { uint32_t collision_layer = get_collision_layer(); - if (p_value) + if (p_value) { collision_layer |= 1 << p_bit; - else + } else { collision_layer &= ~(1 << p_bit); + } set_collision_layer(collision_layer); } @@ -296,8 +298,9 @@ void RigidBody2D::_body_inout(int p_status, ObjectID p_instance, int p_body_shap //E->get().rc++; } - if (node) + if (node) { E->get().shapes.insert(ShapePair(p_body_shape, p_local_shape)); + } if (E->get().in_scene) { emit_signal(SceneStringNames::get_singleton()->body_shape_entered, objid, node, p_body_shape, p_local_shape); @@ -306,8 +309,9 @@ void RigidBody2D::_body_inout(int p_status, ObjectID p_instance, int p_body_shap } else { //E->get().rc--; - if (node) + if (node) { E->get().shapes.erase(ShapePair(p_body_shape, p_local_shape)); + } bool in_scene = E->get().in_scene; @@ -315,8 +319,9 @@ void RigidBody2D::_body_inout(int p_status, ObjectID p_instance, int p_body_shap if (node) { node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &RigidBody2D::_body_enter_tree)); node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &RigidBody2D::_body_exit_tree)); - if (in_scene) + if (in_scene) { emit_signal(SceneStringNames::get_singleton()->body_exited, node); + } } contact_monitor->body_map.erase(E); @@ -335,8 +340,9 @@ struct _RigidBody2DInOut { bool RigidBody2D::_test_motion(const Vector2 &p_motion, bool p_infinite_inertia, float p_margin, const Ref<PhysicsTestMotionResult2D> &p_result) { PhysicsServer2D::MotionResult *r = nullptr; - if (p_result.is_valid()) + if (p_result.is_valid()) { r = p_result->get_result_ptr(); + } return PhysicsServer2D::get_singleton()->body_test_motion(get_rid(), get_global_transform(), p_motion, p_infinite_inertia, p_margin, r); } @@ -348,16 +354,18 @@ void RigidBody2D::_direct_state_changed(Object *p_state) { #endif set_block_transform_notify(true); // don't want notify (would feedback loop) - if (mode != MODE_KINEMATIC) + if (mode != MODE_KINEMATIC) { set_global_transform(state->get_transform()); + } linear_velocity = state->get_linear_velocity(); angular_velocity = state->get_angular_velocity(); if (sleeping != state->is_sleeping()) { sleeping = state->is_sleeping(); emit_signal(SceneStringNames::get_singleton()->sleeping_state_changed); } - if (get_script_instance()) + if (get_script_instance()) { get_script_instance()->call("_integrate_forces", state); + } set_block_transform_notify(false); // want it back if (contact_monitor) { @@ -555,9 +563,9 @@ void RigidBody2D::set_axis_velocity(const Vector2 &p_axis) { void RigidBody2D::set_linear_velocity(const Vector2 &p_velocity) { linear_velocity = p_velocity; - if (state) + if (state) { state->set_linear_velocity(linear_velocity); - else { + } else { PhysicsServer2D::get_singleton()->body_set_state(get_rid(), PhysicsServer2D::BODY_STATE_LINEAR_VELOCITY, linear_velocity); } } @@ -568,10 +576,11 @@ Vector2 RigidBody2D::get_linear_velocity() const { void RigidBody2D::set_angular_velocity(real_t p_velocity) { angular_velocity = p_velocity; - if (state) + if (state) { state->set_angular_velocity(angular_velocity); - else + } else { PhysicsServer2D::get_singleton()->body_set_state(get_rid(), PhysicsServer2D::BODY_STATE_ANGULAR_VELOCITY, angular_velocity); + } } real_t RigidBody2D::get_angular_velocity() const { @@ -579,8 +588,9 @@ real_t RigidBody2D::get_angular_velocity() const { } void RigidBody2D::set_use_custom_integrator(bool p_enable) { - if (custom_integrator == p_enable) + if (custom_integrator == p_enable) { return; + } custom_integrator = p_enable; PhysicsServer2D::get_singleton()->body_set_omit_force_integration(get_rid(), p_enable); @@ -685,8 +695,9 @@ TypedArray<Node2D> RigidBody2D::get_colliding_bodies() const { } void RigidBody2D::set_contact_monitor(bool p_enabled) { - if (p_enabled == is_contact_monitor_enabled()) + if (p_enabled == is_contact_monitor_enabled()) { return; + } if (!p_enabled) { ERR_FAIL_COND_MSG(contact_monitor->locked, "Can't disable contact monitoring during in/out callback. Use call_deferred(\"set_contact_monitor\", false) instead."); @@ -881,8 +892,9 @@ RigidBody2D::RigidBody2D() : } RigidBody2D::~RigidBody2D() { - if (contact_monitor) + if (contact_monitor) { memdelete(contact_monitor); + } } void RigidBody2D::_reload_physics_characteristics() { @@ -1062,8 +1074,9 @@ Vector2 KinematicBody2D::move_and_slide(const Vector2 &p_linear_velocity, const } } - if (!found_collision || motion == Vector2()) + if (!found_collision || motion == Vector2()) { break; + } --p_max_slides; } @@ -1174,8 +1187,9 @@ void KinematicBody2D::set_sync_to_physics(bool p_enable) { } sync_to_physics = p_enable; - if (Engine::get_singleton()->is_editor_hint()) + if (Engine::get_singleton()->is_editor_hint()) { return; + } if (p_enable) { PhysicsServer2D::get_singleton()->body_set_force_integration_callback(get_rid(), this, "_direct_state_changed"); @@ -1193,8 +1207,9 @@ bool KinematicBody2D::is_sync_to_physics_enabled() const { } void KinematicBody2D::_direct_state_changed(Object *p_state) { - if (!sync_to_physics) + if (!sync_to_physics) { return; + } PhysicsDirectBodyState2D *state = Object::cast_to<PhysicsDirectBodyState2D>(p_state); @@ -1297,8 +1312,9 @@ Vector2 KinematicCollision2D::get_remainder() const { } Object *KinematicCollision2D::get_local_shape() const { - if (!owner) + if (!owner) { return nullptr; + } uint32_t ownerid = owner->shape_find_owner(collision.local_shape); return owner->shape_owner_get_owner(ownerid); } diff --git a/scene/2d/physics_body_2d.h b/scene/2d/physics_body_2d.h index f3bdeb4528..cde4398ad3 100644 --- a/scene/2d/physics_body_2d.h +++ b/scene/2d/physics_body_2d.h @@ -144,8 +144,9 @@ private: int local_shape; bool tagged; bool operator<(const ShapePair &p_sp) const { - if (body_shape == p_sp.body_shape) + if (body_shape == p_sp.body_shape) { return local_shape < p_sp.local_shape; + } return body_shape < p_sp.body_shape; } diff --git a/scene/2d/polygon_2d.cpp b/scene/2d/polygon_2d.cpp index b4e3b9bc40..62c66dbb29 100644 --- a/scene/2d/polygon_2d.cpp +++ b/scene/2d/polygon_2d.cpp @@ -65,10 +65,11 @@ Rect2 Polygon2D::_edit_get_rect() const { item_rect = Rect2(); for (int i = 0; i < l; i++) { Vector2 pos = r[i] + offset; - if (i == 0) + if (i == 0) { item_rect.position = pos; - else + } else { item_rect.expand_to(pos); + } } rect_cache_dirty = false; } @@ -96,8 +97,9 @@ void Polygon2D::_skeleton_bone_setup_changed() { void Polygon2D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_DRAW: { - if (polygon.size() < 3) + if (polygon.size() < 3) { return; + } Skeleton2D *skeleton_node = nullptr; if (has_node(skeleton)) { @@ -156,10 +158,11 @@ void Polygon2D::_notification(int p_what) { float sum = 0; for (int i = 0; i < len; i++) { - if (i == 0) + if (i == 0) { bounds.position = points[i]; - else + } else { bounds.expand_to(points[i]); + } if (points[i].y > highest_y) { highest_idx = i; highest_y = points[i].y; @@ -249,8 +252,9 @@ void Polygon2D::_notification(int p_what) { int bone_index = bone->get_index_in_skeleton(); const float *r = bone_weights[i].weights.ptr(); for (int j = 0; j < vc; j++) { - if (r[j] == 0.0) + if (r[j] == 0.0) { continue; //weight is unpainted, skip + } //find an index with a weight for (int k = 0; k < 4; k++) { if (weightsw[j * 4 + k] < r[j]) { @@ -273,8 +277,9 @@ void Polygon2D::_notification(int p_what) { for (int j = 0; j < 4; j++) { tw += weightsw[i * 4 + j]; } - if (tw == 0) + if (tw == 0) { continue; //unpainted, do nothing + } //normalize for (int j = 0; j < 4; j++) { @@ -305,8 +310,9 @@ void Polygon2D::_notification(int p_what) { for (int i = 0; i < polygons.size(); i++) { Vector<int> src_indices = polygons[i]; int ic = src_indices.size(); - if (ic < 3) + if (ic < 3) { continue; + } const int *r = src_indices.ptr(); Vector<Vector2> tmp_points; @@ -580,8 +586,9 @@ void Polygon2D::_set_bones(const Array &p_bones) { } void Polygon2D::set_skeleton(const NodePath &p_skeleton) { - if (skeleton == p_skeleton) + if (skeleton == p_skeleton) { return; + } skeleton = p_skeleton; update(); } diff --git a/scene/2d/position_2d.cpp b/scene/2d/position_2d.cpp index 4cd46171c6..a94a9f7085 100644 --- a/scene/2d/position_2d.cpp +++ b/scene/2d/position_2d.cpp @@ -59,10 +59,12 @@ void Position2D::_notification(int p_what) { update(); } break; case NOTIFICATION_DRAW: { - if (!is_inside_tree()) + if (!is_inside_tree()) { break; - if (Engine::get_singleton()->is_editor_hint()) + } + if (Engine::get_singleton()->is_editor_hint()) { _draw_cross(); + } } break; } diff --git a/scene/2d/ray_cast_2d.cpp b/scene/2d/ray_cast_2d.cpp index 50d437f78b..5020940c5c 100644 --- a/scene/2d/ray_cast_2d.cpp +++ b/scene/2d/ray_cast_2d.cpp @@ -37,8 +37,9 @@ void RayCast2D::set_cast_to(const Vector2 &p_point) { cast_to = p_point; - if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_collisions_hint())) + if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_collisions_hint())) { update(); + } } Vector2 RayCast2D::get_cast_to() const { @@ -55,10 +56,11 @@ uint32_t RayCast2D::get_collision_mask() const { void RayCast2D::set_collision_mask_bit(int p_bit, bool p_value) { uint32_t mask = get_collision_mask(); - if (p_value) + if (p_value) { mask |= 1 << p_bit; - else + } else { mask &= ~(1 << p_bit); + } set_collision_mask(mask); } @@ -71,8 +73,9 @@ bool RayCast2D::is_colliding() const { } Object *RayCast2D::get_collider() const { - if (against.is_null()) + if (against.is_null()) { return nullptr; + } return ObjectDB::get_instance(against); } @@ -92,10 +95,12 @@ Vector2 RayCast2D::get_collision_normal() const { void RayCast2D::set_enabled(bool p_enabled) { enabled = p_enabled; update(); - if (is_inside_tree() && !Engine::get_singleton()->is_editor_hint()) + if (is_inside_tree() && !Engine::get_singleton()->is_editor_hint()) { set_physics_process_internal(p_enabled); - if (!p_enabled) + } + if (!p_enabled) { collided = false; + } } bool RayCast2D::is_enabled() const { @@ -103,19 +108,22 @@ bool RayCast2D::is_enabled() const { } void RayCast2D::set_exclude_parent_body(bool p_exclude_parent_body) { - if (exclude_parent_body == p_exclude_parent_body) + if (exclude_parent_body == p_exclude_parent_body) { return; + } exclude_parent_body = p_exclude_parent_body; - if (!is_inside_tree()) + if (!is_inside_tree()) { return; + } if (Object::cast_to<CollisionObject2D>(get_parent())) { - if (exclude_parent_body) + if (exclude_parent_body) { exclude.insert(Object::cast_to<CollisionObject2D>(get_parent())->get_rid()); - else + } else { exclude.erase(Object::cast_to<CollisionObject2D>(get_parent())->get_rid()); + } } } @@ -126,27 +134,31 @@ bool RayCast2D::get_exclude_parent_body() const { void RayCast2D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { - if (enabled && !Engine::get_singleton()->is_editor_hint()) + if (enabled && !Engine::get_singleton()->is_editor_hint()) { set_physics_process_internal(true); - else + } else { set_physics_process_internal(false); + } if (Object::cast_to<CollisionObject2D>(get_parent())) { - if (exclude_parent_body) + if (exclude_parent_body) { exclude.insert(Object::cast_to<CollisionObject2D>(get_parent())->get_rid()); - else + } else { exclude.erase(Object::cast_to<CollisionObject2D>(get_parent())->get_rid()); + } } } break; case NOTIFICATION_EXIT_TREE: { - if (enabled) + if (enabled) { set_physics_process_internal(false); + } } break; case NOTIFICATION_DRAW: { - if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) + if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) { break; + } Transform2D xf; xf.rotate(cast_to.angle()); xf.translate(Vector2(cast_to.length(), 0)); @@ -166,16 +178,18 @@ void RayCast2D::_notification(int p_what) { pts.push_back(xf.xform(Vector2(0, Math_SQRT12 * tsize))); pts.push_back(xf.xform(Vector2(0, -Math_SQRT12 * tsize))); Vector<Color> cols; - for (int i = 0; i < 3; i++) + for (int i = 0; i < 3; i++) { cols.push_back(draw_col); + } draw_primitive(pts, cols, Vector<Vector2>()); } break; case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { - if (!enabled) + if (!enabled) { break; + } _update_raycast_state(); @@ -193,8 +207,9 @@ void RayCast2D::_update_raycast_state() { Transform2D gt = get_global_transform(); Vector2 to = cast_to; - if (to == Vector2()) + if (to == Vector2()) { to = Vector2(0, 0.01); + } PhysicsDirectSpaceState2D::RayResult rr; @@ -222,8 +237,9 @@ void RayCast2D::add_exception_rid(const RID &p_rid) { void RayCast2D::add_exception(const Object *p_object) { ERR_FAIL_NULL(p_object); const CollisionObject2D *co = Object::cast_to<CollisionObject2D>(p_object); - if (!co) + if (!co) { return; + } add_exception_rid(co->get_rid()); } @@ -234,8 +250,9 @@ void RayCast2D::remove_exception_rid(const RID &p_rid) { void RayCast2D::remove_exception(const Object *p_object) { ERR_FAIL_NULL(p_object); const CollisionObject2D *co = Object::cast_to<CollisionObject2D>(p_object); - if (!co) + if (!co) { return; + } remove_exception_rid(co->get_rid()); } diff --git a/scene/2d/remote_transform_2d.cpp b/scene/2d/remote_transform_2d.cpp index d9b73a5e6e..3104436dbe 100644 --- a/scene/2d/remote_transform_2d.cpp +++ b/scene/2d/remote_transform_2d.cpp @@ -44,18 +44,22 @@ void RemoteTransform2D::_update_cache() { } void RemoteTransform2D::_update_remote() { - if (!is_inside_tree()) + if (!is_inside_tree()) { return; + } - if (cache.is_null()) + if (cache.is_null()) { return; + } Node2D *n = Object::cast_to<Node2D>(ObjectDB::get_instance(cache)); - if (!n) + if (!n) { return; + } - if (!n->is_inside_tree()) + if (!n->is_inside_tree()) { return; + } //todo make faster if (use_global_coordinates) { @@ -66,17 +70,20 @@ void RemoteTransform2D::_update_remote() { Transform2D our_trans = get_global_transform(); Vector2 n_scale = n->get_scale(); - if (!update_remote_position) + if (!update_remote_position) { our_trans.set_origin(n_trans.get_origin()); - if (!update_remote_rotation) + } + if (!update_remote_rotation) { our_trans.set_rotation(n_trans.get_rotation()); + } n->set_global_transform(our_trans); - if (update_remote_scale) + if (update_remote_scale) { n->set_scale(get_global_scale()); - else + } else { n->set_scale(n_scale); + } } } else { @@ -87,17 +94,20 @@ void RemoteTransform2D::_update_remote() { Transform2D our_trans = get_transform(); Vector2 n_scale = n->get_scale(); - if (!update_remote_position) + if (!update_remote_position) { our_trans.set_origin(n_trans.get_origin()); - if (!update_remote_rotation) + } + if (!update_remote_rotation) { our_trans.set_rotation(n_trans.get_rotation()); + } n->set_transform(our_trans); - if (update_remote_scale) + if (update_remote_scale) { n->set_scale(get_scale()); - else + } else { n->set_scale(n_scale); + } } } } @@ -109,8 +119,9 @@ void RemoteTransform2D::_notification(int p_what) { } break; case NOTIFICATION_TRANSFORM_CHANGED: { - if (!is_inside_tree()) + if (!is_inside_tree()) { break; + } if (cache.is_valid()) { _update_remote(); diff --git a/scene/2d/skeleton_2d.cpp b/scene/2d/skeleton_2d.cpp index 2c041f7449..ea37c8dfe7 100644 --- a/scene/2d/skeleton_2d.cpp +++ b/scene/2d/skeleton_2d.cpp @@ -37,10 +37,12 @@ void Bone2D::_notification(int p_what) { skeleton = nullptr; while (parent) { skeleton = Object::cast_to<Skeleton2D>(parent); - if (skeleton) + if (skeleton) { break; - if (!Object::cast_to<Bone2D>(parent)) + } + if (!Object::cast_to<Bone2D>(parent)) { break; //skeletons must be chained to Bone2Ds. + } parent = parent->get_parent(); } @@ -94,8 +96,9 @@ void Bone2D::_bind_methods() { void Bone2D::set_rest(const Transform2D &p_rest) { rest = p_rest; - if (skeleton) + if (skeleton) { skeleton->_make_bone_setup_dirty(); + } update_configuration_warning(); } @@ -168,8 +171,9 @@ Bone2D::Bone2D() { ////////////////////////////////////// void Skeleton2D::_make_bone_setup_dirty() { - if (bone_setup_dirty) + if (bone_setup_dirty) { return; + } bone_setup_dirty = true; if (is_inside_tree()) { call_deferred("_update_bone_setup"); @@ -177,8 +181,9 @@ void Skeleton2D::_make_bone_setup_dirty() { } void Skeleton2D::_update_bone_setup() { - if (!bone_setup_dirty) + if (!bone_setup_dirty) { return; + } bone_setup_dirty = false; RS::get_singleton()->skeleton_allocate(skeleton, bones.size(), true); @@ -202,8 +207,9 @@ void Skeleton2D::_update_bone_setup() { } void Skeleton2D::_make_transform_dirty() { - if (transform_dirty) + if (transform_dirty) { return; + } transform_dirty = true; if (is_inside_tree()) { call_deferred("_update_transform"); @@ -215,8 +221,9 @@ void Skeleton2D::_update_transform() { _update_bone_setup(); return; //above will update transform anyway } - if (!transform_dirty) + if (!transform_dirty) { return; + } transform_dirty = false; @@ -254,10 +261,12 @@ Bone2D *Skeleton2D::get_bone(int p_idx) { void Skeleton2D::_notification(int p_what) { if (p_what == NOTIFICATION_READY) { - if (bone_setup_dirty) + if (bone_setup_dirty) { _update_bone_setup(); - if (transform_dirty) + } + if (transform_dirty) { _update_transform(); + } request_ready(); } diff --git a/scene/2d/sprite_2d.cpp b/scene/2d/sprite_2d.cpp index ce350f167e..7e07019578 100644 --- a/scene/2d/sprite_2d.cpp +++ b/scene/2d/sprite_2d.cpp @@ -96,25 +96,29 @@ void Sprite2D::_get_rects(Rect2 &r_src_rect, Rect2 &r_dst_rect, bool &r_filter_c r_src_rect.position = base_rect.position + frame_offset; Point2 dest_offset = offset; - if (centered) + if (centered) { dest_offset -= frame_size / 2; + } if (Engine::get_singleton()->get_use_pixel_snap()) { dest_offset = dest_offset.floor(); } r_dst_rect = Rect2(dest_offset, frame_size); - if (hflip) + if (hflip) { r_dst_rect.size.x = -r_dst_rect.size.x; - if (vflip) + } + if (vflip) { r_dst_rect.size.y = -r_dst_rect.size.y; + } } void Sprite2D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_DRAW: { - if (texture.is_null()) + if (texture.is_null()) { return; + } RID ci = get_canvas_item(); @@ -133,16 +137,19 @@ void Sprite2D::_notification(int p_what) { } void Sprite2D::set_texture(const Ref<Texture2D> &p_texture) { - if (p_texture == texture) + if (p_texture == texture) { return; + } - if (texture.is_valid()) + if (texture.is_valid()) { texture->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Sprite2D::_texture_changed)); + } texture = p_texture; - if (texture.is_valid()) + if (texture.is_valid()) { texture->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Sprite2D::_texture_changed)); + } update(); emit_signal("texture_changed"); @@ -230,8 +237,9 @@ bool Sprite2D::is_flipped_v() const { } void Sprite2D::set_region(bool p_region) { - if (p_region == region) + if (p_region == region) { return; + } region = p_region; update(); @@ -242,13 +250,15 @@ bool Sprite2D::is_region() const { } void Sprite2D::set_region_rect(const Rect2 &p_region_rect) { - if (region_rect == p_region_rect) + if (region_rect == p_region_rect) { return; + } region_rect = p_region_rect; - if (region) + if (region) { item_rect_changed(); + } _change_notify("region_rect"); } @@ -269,8 +279,9 @@ bool Sprite2D::is_region_filter_clip_enabled() const { void Sprite2D::set_frame(int p_frame) { ERR_FAIL_INDEX(p_frame, vframes * hframes); - if (frame != p_frame) + if (frame != p_frame) { item_rect_changed(); + } frame = p_frame; @@ -319,25 +330,30 @@ int Sprite2D::get_hframes() const { } bool Sprite2D::is_pixel_opaque(const Point2 &p_point) const { - if (texture.is_null()) + if (texture.is_null()) { return false; + } - if (texture->get_size().width == 0 || texture->get_size().height == 0) + if (texture->get_size().width == 0 || texture->get_size().height == 0) { return false; + } Rect2 src_rect, dst_rect; bool filter_clip; _get_rects(src_rect, dst_rect, filter_clip); dst_rect.size = dst_rect.size.abs(); - if (!dst_rect.has_point(p_point)) + if (!dst_rect.has_point(p_point)) { return false; + } Vector2 q = (p_point - dst_rect.position) / dst_rect.size; - if (hflip) + if (hflip) { q.x = 1.0f - q.x; - if (vflip) + } + if (vflip) { q.y = 1.0f - q.y; + } q = q * src_rect.size + src_rect.position; #ifndef _MSC_VER #warning this need to be obtained from CanvasItem new repeat mode (but it needs to guess it from hierarchy, need to add a function for that) @@ -368,8 +384,9 @@ bool Sprite2D::is_pixel_opaque(const Point2 &p_point) const { } Rect2 Sprite2D::get_rect() const { - if (texture.is_null()) + if (texture.is_null()) { return Rect2(0, 0, 1, 1); + } Size2i s; @@ -382,11 +399,13 @@ Rect2 Sprite2D::get_rect() const { s = s / Point2(hframes, vframes); Point2 ofs = offset; - if (centered) + if (centered) { ofs -= Size2(s) / 2; + } - if (s == Size2(0, 0)) + if (s == Size2(0, 0)) { s = Size2(1, 1); + } return Rect2(ofs, s); } diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index 7af3acd83e..c7a809f6d8 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -39,10 +39,11 @@ #include "servers/physics_server_2d.h" int TileMap::_get_quadrant_size() const { - if (use_y_sort) + if (use_y_sort) { return 1; - else + } else { return quadrant_size; + } } void TileMap::_notification(int p_what) { @@ -124,18 +125,21 @@ void TileMap::_update_quadrant_space(const RID &p_space) { } void TileMap::_update_quadrant_transform() { - if (!is_inside_tree()) + if (!is_inside_tree()) { return; + } Transform2D global_transform = get_global_transform(); Transform2D local_transform; - if (collision_parent) + if (collision_parent) { local_transform = get_transform(); + } Transform2D nav_rel; - if (navigation) + if (navigation) { nav_rel = get_relative_transform_to_parent(navigation); + } for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) { Quadrant &q = E->get(); @@ -303,8 +307,9 @@ void TileMap::_add_shape(int &shape_idx, const Quadrant &p_q, const Ref<Shape2D> } void TileMap::update_dirty_quadrants() { - if (!pending_update) + if (!pending_update) { return; + } if (!is_inside_tree() || !tile_set.is_valid()) { pending_update = false; return; @@ -314,8 +319,9 @@ void TileMap::update_dirty_quadrants() { PhysicsServer2D *ps = PhysicsServer2D::get_singleton(); Vector2 tofs = get_cell_draw_offset(); Transform2D nav_rel; - if (navigation) + if (navigation) { nav_rel = get_relative_transform_to_parent(navigation); + } Vector2 qofs; @@ -369,16 +375,18 @@ void TileMap::update_dirty_quadrants() { Map<PosKey, Cell>::Element *E = tile_map.find(q.cells[i]); Cell &c = E->get(); //moment of truth - if (!tile_set->has_tile(c.id)) + if (!tile_set->has_tile(c.id)) { continue; + } Ref<Texture2D> tex = tile_set->tile_get_texture(c.id); Vector2 tile_ofs = tile_set->tile_get_texture_offset(c.id); Vector2 wofs = _map_to_world(E->key().x, E->key().y); Vector2 offset = wofs - q.pos + tofs; - if (!tex.is_valid()) + if (!tex.is_valid()) { continue; + } Ref<ShaderMaterial> mat = tile_set->tile_get_material(c.id); int z_index = tile_set->tile_get_z_index(c.id); @@ -393,8 +401,9 @@ void TileMap::update_dirty_quadrants() { if (prev_canvas_item == RID() || prev_material != mat || prev_z_index != z_index) { canvas_item = vs->canvas_item_create(); - if (mat.is_valid()) + if (mat.is_valid()) { vs->canvas_item_set_material(canvas_item, mat->get_rid()); + } vs->canvas_item_set_parent(canvas_item, get_canvas_item()); _update_item_material_state(canvas_item); Transform2D xform; @@ -433,10 +442,11 @@ void TileMap::update_dirty_quadrants() { } Size2 s; - if (r == Rect2()) + if (r == Rect2()) { s = tex->get_size(); - else + } else { s = r.size; + } Rect2 rect; rect.position = offset.floor(); @@ -446,11 +456,13 @@ void TileMap::update_dirty_quadrants() { if (compatibility_mode && !centered_textures) { if (rect.size.y > rect.size.x) { - if ((c.flip_h && (c.flip_v || c.transpose)) || (c.flip_v && !c.transpose)) + if ((c.flip_h && (c.flip_v || c.transpose)) || (c.flip_v && !c.transpose)) { tile_ofs.y += rect.size.y - rect.size.x; + } } else if (rect.size.y < rect.size.x) { - if ((c.flip_v && (c.flip_h || c.transpose)) || (c.flip_h && !c.transpose)) + if ((c.flip_v && (c.flip_h || c.transpose)) || (c.flip_h && !c.transpose)) { tile_ofs.x += rect.size.x - rect.size.y; + } } } @@ -482,29 +494,33 @@ void TileMap::update_dirty_quadrants() { rect.position += tile_ofs; if (c.transpose) { - if (c.flip_h) + if (c.flip_h) { rect.position.x -= cell_size.x; - else + } else { rect.position.x += cell_size.x; + } } else { - if (c.flip_v) + if (c.flip_v) { rect.position.y -= cell_size.y; - else + } else { rect.position.y += cell_size.y; + } } } else if (tile_origin == TILE_ORIGIN_CENTER) { rect.position += tile_ofs; - if (c.flip_h) + if (c.flip_h) { rect.position.x -= cell_size.x / 2; - else + } else { rect.position.x += cell_size.x / 2; + } - if (c.flip_v) + if (c.flip_v) { rect.position.y -= cell_size.y / 2; - else + } else { rect.position.y += cell_size.y / 2; + } } } else { rect.position += tile_ofs; @@ -687,8 +703,9 @@ void TileMap::update_dirty_quadrants() { void TileMap::_recompute_rect_cache() { #ifdef DEBUG_ENABLED - if (!rect_cache_dirty) + if (!rect_cache_dirty) { return; + } Rect2 r_total; for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) { @@ -697,10 +714,11 @@ void TileMap::_recompute_rect_cache() { r.expand_to(_map_to_world(E->key().x * _get_quadrant_size() + _get_quadrant_size(), E->key().y * _get_quadrant_size())); r.expand_to(_map_to_world(E->key().x * _get_quadrant_size() + _get_quadrant_size(), E->key().y * _get_quadrant_size() + _get_quadrant_size())); r.expand_to(_map_to_world(E->key().x * _get_quadrant_size(), E->key().y * _get_quadrant_size() + _get_quadrant_size())); - if (E == quadrant_map.front()) + if (E == quadrant_map.front()) { r_total = r; - else + } else { r_total = r_total.merge(r); + } } rect_cache = r_total; @@ -717,10 +735,11 @@ Map<TileMap::PosKey, TileMap::Quadrant>::Element *TileMap::_create_quadrant(cons Quadrant q; q.pos = _map_to_world(p_qk.x * _get_quadrant_size(), p_qk.y * _get_quadrant_size()); q.pos += get_cell_draw_offset(); - if (tile_origin == TILE_ORIGIN_CENTER) + if (tile_origin == TILE_ORIGIN_CENTER) { q.pos += cell_size / 2; - else if (tile_origin == TILE_ORIGIN_BOTTOM_LEFT) + } else if (tile_origin == TILE_ORIGIN_BOTTOM_LEFT) { q.pos.y += cell_size.y; + } xform.set_origin(q.pos); //q.canvas_item = RenderingServer::get_singleton()->canvas_item_create(); @@ -765,8 +784,9 @@ void TileMap::_erase_quadrant(Map<PosKey, Quadrant>::Element *Q) { RenderingServer::get_singleton()->free(E->get()); } q.canvas_items.clear(); - if (q.dirty_list.in_list()) + if (q.dirty_list.in_list()) { dirty_quadrant_list.remove(&q.dirty_list); + } if (navigation) { for (Map<PosKey, Quadrant::NavPoly>::Element *E = q.navpoly_ids.front(); E; E = E->next()) { @@ -786,14 +806,17 @@ void TileMap::_erase_quadrant(Map<PosKey, Quadrant>::Element *Q) { void TileMap::_make_quadrant_dirty(Map<PosKey, Quadrant>::Element *Q, bool update) { Quadrant &q = Q->get(); - if (!q.dirty_list.in_list()) + if (!q.dirty_list.in_list()) { dirty_quadrant_list.add(&q.dirty_list); + } - if (pending_update) + if (pending_update) { return; + } pending_update = true; - if (!is_inside_tree()) + if (!is_inside_tree()) { return; + } if (update) { call_deferred("update_dirty_quadrants"); @@ -815,8 +838,9 @@ void TileMap::set_cell(int p_x, int p_y, int p_tile, bool p_flip_x, bool p_flip_ PosKey pk(p_x, p_y); Map<PosKey, Cell>::Element *E = tile_map.find(pk); - if (!E && p_tile == INVALID_CELL) + if (!E && p_tile == INVALID_CELL) { return; //nothing to do + } PosKey qk = pk.to_quadrant(_get_quadrant_size()); if (p_tile == INVALID_CELL) { @@ -826,10 +850,11 @@ void TileMap::set_cell(int p_x, int p_y, int p_tile, bool p_flip_x, bool p_flip_ ERR_FAIL_COND(!Q); Quadrant &q = Q->get(); q.cells.erase(pk); - if (q.cells.size() == 0) + if (q.cells.size() == 0) { _erase_quadrant(Q); - else + } else { _make_quadrant_dirty(Q); + } used_size_cache_dirty = true; return; @@ -847,8 +872,9 @@ void TileMap::set_cell(int p_x, int p_y, int p_tile, bool p_flip_x, bool p_flip_ } else { ERR_FAIL_COND(!Q); // quadrant should exist... - if (E->get().id == p_tile && E->get().flip_h == p_flip_x && E->get().flip_v == p_flip_y && E->get().transpose == p_transpose && E->get().autotile_coord_x == (uint16_t)p_autotile_coord.x && E->get().autotile_coord_y == (uint16_t)p_autotile_coord.y) + if (E->get().id == p_tile && E->get().flip_h == p_flip_x && E->get().flip_v == p_flip_y && E->get().transpose == p_transpose && E->get().autotile_coord_x == (uint16_t)p_autotile_coord.x && E->get().autotile_coord_y == (uint16_t)p_autotile_coord.y) { return; //nothing changed + } } Cell &c = E->get(); @@ -1009,8 +1035,9 @@ int TileMap::get_cell(int p_x, int p_y) const { const Map<PosKey, Cell>::Element *E = tile_map.find(pk); - if (!E) + if (!E) { return INVALID_CELL; + } return E->get().id; } @@ -1020,8 +1047,9 @@ bool TileMap::is_cell_x_flipped(int p_x, int p_y) const { const Map<PosKey, Cell>::Element *E = tile_map.find(pk); - if (!E) + if (!E) { return false; + } return E->get().flip_h; } @@ -1031,8 +1059,9 @@ bool TileMap::is_cell_y_flipped(int p_x, int p_y) const { const Map<PosKey, Cell>::Element *E = tile_map.find(pk); - if (!E) + if (!E) { return false; + } return E->get().flip_v; } @@ -1042,8 +1071,9 @@ bool TileMap::is_cell_transposed(int p_x, int p_y) const { const Map<PosKey, Cell>::Element *E = tile_map.find(pk); - if (!E) + if (!E) { return false; + } return E->get().transpose; } @@ -1053,8 +1083,9 @@ void TileMap::set_cell_autotile_coord(int p_x, int p_y, const Vector2 &p_coord) const Map<PosKey, Cell>::Element *E = tile_map.find(pk); - if (!E) + if (!E) { return; + } Cell c = E->get(); c.autotile_coord_x = p_coord.x; @@ -1064,8 +1095,9 @@ void TileMap::set_cell_autotile_coord(int p_x, int p_y, const Vector2 &p_coord) PosKey qk = pk.to_quadrant(_get_quadrant_size()); Map<PosKey, Quadrant>::Element *Q = quadrant_map.find(qk); - if (!Q) + if (!Q) { return; + } _make_quadrant_dirty(Q); } @@ -1075,8 +1107,9 @@ Vector2 TileMap::get_cell_autotile_coord(int p_x, int p_y) const { const Map<PosKey, Cell>::Element *E = tile_map.find(pk); - if (!E) + if (!E) { return Vector2(); + } return Vector2(E->get().autotile_coord_x, E->get().autotile_coord_y); } @@ -1146,8 +1179,9 @@ void TileMap::_set_tile_data(const Vector<int> &p_data) { for (int i = 0; i < c; i += offset) { const uint8_t *ptr = (const uint8_t *)&r[i]; uint8_t local[12]; - for (int j = 0; j < ((format == FORMAT_2) ? 12 : 8); j++) + for (int j = 0; j < ((format == FORMAT_2) ? 12 : 8); j++) { local[j] = ptr[j]; + } #ifdef BIG_ENDIAN_ENABLED @@ -1193,12 +1227,15 @@ Vector<int> TileMap::_get_tile_data() const { encode_uint16(E->key().x, &ptr[0]); encode_uint16(E->key().y, &ptr[2]); uint32_t val = E->get().id; - if (E->get().flip_h) + if (E->get().flip_h) { val |= (1 << 29); - if (E->get().flip_v) + } + if (E->get().flip_v) { val |= (1 << 30); - if (E->get().transpose) + } + if (E->get().transpose) { val |= (1 << 31); + } encode_uint32(val, &ptr[4]); encode_uint16(E->get().autotile_coord_x, &ptr[8]); encode_uint16(E->get().autotile_coord_y, &ptr[10]); @@ -1241,19 +1278,21 @@ void TileMap::set_collision_mask(uint32_t p_mask) { void TileMap::set_collision_layer_bit(int p_bit, bool p_value) { uint32_t layer = get_collision_layer(); - if (p_value) + if (p_value) { layer |= 1 << p_bit; - else + } else { layer &= ~(1 << p_bit); + } set_collision_layer(layer); } void TileMap::set_collision_mask_bit(int p_bit, bool p_value) { uint32_t mask = get_collision_mask(); - if (p_value) + if (p_value) { mask |= 1 << p_bit; - else + } else { mask &= ~(1 << p_bit); + } set_collision_mask(mask); } @@ -1272,8 +1311,9 @@ bool TileMap::get_collision_use_parent() const { } void TileMap::set_collision_use_parent(bool p_use_parent) { - if (use_parent == p_use_parent) + if (use_parent == p_use_parent) { return; + } _clear_quadrants(); @@ -1634,8 +1674,9 @@ void TileMap::set_light_mask(int p_light_mask) { } void TileMap::set_clip_uv(bool p_enable) { - if (clip_uv == p_enable) + if (clip_uv == p_enable) { return; + } _clear_quadrants(); clip_uv = p_enable; @@ -1837,8 +1878,9 @@ TileMap::TileMap() { } TileMap::~TileMap() { - if (tile_set.is_valid()) + if (tile_set.is_valid()) { tile_set->remove_change_receptor(this); + } clear(); } diff --git a/scene/2d/touch_screen_button.cpp b/scene/2d/touch_screen_button.cpp index 2d8a47ee98..4597300db8 100644 --- a/scene/2d/touch_screen_button.cpp +++ b/scene/2d/touch_screen_button.cpp @@ -62,13 +62,15 @@ Ref<BitMap> TouchScreenButton::get_bitmask() const { } void TouchScreenButton::set_shape(const Ref<Shape2D> &p_shape) { - if (shape.is_valid()) + if (shape.is_valid()) { shape->disconnect("changed", callable_mp((CanvasItem *)this, &CanvasItem::update)); + } shape = p_shape; - if (shape.is_valid()) + if (shape.is_valid()) { shape->connect("changed", callable_mp((CanvasItem *)this, &CanvasItem::update)); + } update(); } @@ -98,26 +100,32 @@ bool TouchScreenButton::is_shape_centered() const { void TouchScreenButton::_notification(int p_what) { switch (p_what) { case NOTIFICATION_DRAW: { - if (!is_inside_tree()) + if (!is_inside_tree()) { return; - if (!Engine::get_singleton()->is_editor_hint() && !!DisplayServer::get_singleton()->screen_is_touchscreen(DisplayServer::get_singleton()->window_get_current_screen(get_viewport()->get_window_id())) && visibility == VISIBILITY_TOUCHSCREEN_ONLY) + } + if (!Engine::get_singleton()->is_editor_hint() && !!DisplayServer::get_singleton()->screen_is_touchscreen(DisplayServer::get_singleton()->window_get_current_screen(get_viewport()->get_window_id())) && visibility == VISIBILITY_TOUCHSCREEN_ONLY) { return; + } if (finger_pressed != -1) { - if (texture_pressed.is_valid()) + if (texture_pressed.is_valid()) { draw_texture(texture_pressed, Point2()); - else if (texture.is_valid()) + } else if (texture.is_valid()) { draw_texture(texture, Point2()); + } } else { - if (texture.is_valid()) + if (texture.is_valid()) { draw_texture(texture, Point2()); + } } - if (!shape_visible) + if (!shape_visible) { return; - if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) + } + if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) { return; + } if (shape.is_valid()) { Color draw_col = get_tree()->get_debug_collisions_color(); @@ -129,32 +137,38 @@ void TouchScreenButton::_notification(int p_what) { } break; case NOTIFICATION_ENTER_TREE: { - if (!Engine::get_singleton()->is_editor_hint() && !!DisplayServer::get_singleton()->screen_is_touchscreen(DisplayServer::get_singleton()->window_get_current_screen(get_viewport()->get_window_id())) && visibility == VISIBILITY_TOUCHSCREEN_ONLY) + if (!Engine::get_singleton()->is_editor_hint() && !!DisplayServer::get_singleton()->screen_is_touchscreen(DisplayServer::get_singleton()->window_get_current_screen(get_viewport()->get_window_id())) && visibility == VISIBILITY_TOUCHSCREEN_ONLY) { return; + } update(); - if (!Engine::get_singleton()->is_editor_hint()) + if (!Engine::get_singleton()->is_editor_hint()) { set_process_input(is_visible_in_tree()); + } } break; case NOTIFICATION_EXIT_TREE: { - if (is_pressed()) + if (is_pressed()) { _release(true); + } } break; case NOTIFICATION_VISIBILITY_CHANGED: { - if (Engine::get_singleton()->is_editor_hint()) + if (Engine::get_singleton()->is_editor_hint()) { break; + } if (is_visible_in_tree()) { set_process_input(true); } else { set_process_input(false); - if (is_pressed()) + if (is_pressed()) { _release(); + } } } break; case NOTIFICATION_PAUSED: { - if (is_pressed()) + if (is_pressed()) { _release(); + } } break; } } @@ -172,11 +186,13 @@ String TouchScreenButton::get_action() const { } void TouchScreenButton::_input(const Ref<InputEvent> &p_event) { - if (!get_tree()) + if (!get_tree()) { return; + } - if (p_event->get_device() != 0) + if (p_event->get_device() != 0) { return; + } ERR_FAIL_COND(!is_visible_in_tree()); @@ -210,8 +226,9 @@ void TouchScreenButton::_input(const Ref<InputEvent> &p_event) { if (st) { if (st->is_pressed()) { const bool can_press = finger_pressed == -1; - if (!can_press) + if (!can_press) { return; //already fingering + } if (_is_point_inside(st->get_position())) { _press(st->get_index()); @@ -242,14 +259,16 @@ bool TouchScreenButton::_is_point_inside(const Point2 &p_point) { if (bitmask.is_valid()) { check_rect = false; if (!touched && Rect2(Point2(), bitmask->get_size()).has_point(coord)) { - if (bitmask->get_bit(coord)) + if (bitmask->get_bit(coord)) { touched = true; + } } } if (!touched && check_rect) { - if (texture.is_valid()) + if (texture.is_valid()) { touched = Rect2(Size2(), texture->get_size()).has_point(coord); + } } return touched; @@ -293,8 +312,9 @@ void TouchScreenButton::_release(bool p_exiting_tree) { #ifdef TOOLS_ENABLED Rect2 TouchScreenButton::_edit_get_rect() const { - if (texture.is_null()) + if (texture.is_null()) { return CanvasItem::_edit_get_rect(); + } return Rect2(Size2(), texture->get_size()); } @@ -305,8 +325,9 @@ bool TouchScreenButton::_edit_use_rect() const { #endif Rect2 TouchScreenButton::get_anchorable_rect() const { - if (texture.is_null()) + if (texture.is_null()) { return CanvasItem::get_anchorable_rect(); + } return Rect2(Size2(), texture->get_size()); } diff --git a/scene/2d/visibility_notifier_2d.cpp b/scene/2d/visibility_notifier_2d.cpp index 1f250bbdf6..75154c7acb 100644 --- a/scene/2d/visibility_notifier_2d.cpp +++ b/scene/2d/visibility_notifier_2d.cpp @@ -52,8 +52,9 @@ void VisibilityNotifier2D::_enter_viewport(Viewport *p_viewport) { ERR_FAIL_COND(viewports.has(p_viewport)); viewports.insert(p_viewport); - if (is_inside_tree() && Engine::get_singleton()->is_editor_hint()) + if (is_inside_tree() && Engine::get_singleton()->is_editor_hint()) { return; + } if (viewports.size() == 1) { emit_signal(SceneStringNames::get_singleton()->screen_entered); @@ -67,8 +68,9 @@ void VisibilityNotifier2D::_exit_viewport(Viewport *p_viewport) { ERR_FAIL_COND(!viewports.has(p_viewport)); viewports.erase(p_viewport); - if (is_inside_tree() && Engine::get_singleton()->is_editor_hint()) + if (is_inside_tree() && Engine::get_singleton()->is_editor_hint()) { return; + } emit_signal(SceneStringNames::get_singleton()->viewport_exited, p_viewport); if (viewports.size() == 0) { @@ -145,10 +147,12 @@ void VisibilityEnabler2D::_screen_enter() { _change_node_state(E->key(), true); } - if (enabler[ENABLER_PARENT_PHYSICS_PROCESS] && get_parent()) + if (enabler[ENABLER_PARENT_PHYSICS_PROCESS] && get_parent()) { get_parent()->set_physics_process(true); - if (enabler[ENABLER_PARENT_PROCESS] && get_parent()) + } + if (enabler[ENABLER_PARENT_PROCESS] && get_parent()) { get_parent()->set_process(true); + } visible = true; } @@ -158,10 +162,12 @@ void VisibilityEnabler2D::_screen_exit() { _change_node_state(E->key(), false); } - if (enabler[ENABLER_PARENT_PHYSICS_PROCESS] && get_parent()) + if (enabler[ENABLER_PARENT_PHYSICS_PROCESS] && get_parent()) { get_parent()->set_physics_process(false); - if (enabler[ENABLER_PARENT_PROCESS] && get_parent()) + } + if (enabler[ENABLER_PARENT_PROCESS] && get_parent()) { get_parent()->set_process(false); + } visible = false; } @@ -207,8 +213,9 @@ void VisibilityEnabler2D::_find_nodes(Node *p_node) { for (int i = 0; i < p_node->get_child_count(); i++) { Node *c = p_node->get_child(i); - if (c->get_filename() != String()) + if (c->get_filename() != String()) { continue; //skip, instance + } _find_nodes(c); } @@ -216,13 +223,15 @@ void VisibilityEnabler2D::_find_nodes(Node *p_node) { void VisibilityEnabler2D::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { - if (Engine::get_singleton()->is_editor_hint()) + if (Engine::get_singleton()->is_editor_hint()) { return; + } Node *from = this; //find where current scene starts - while (from->get_parent() && from->get_filename() == String()) + while (from->get_parent() && from->get_filename() == String()) { from = from->get_parent(); + } _find_nodes(from); @@ -242,12 +251,14 @@ void VisibilityEnabler2D::_notification(int p_what) { } if (p_what == NOTIFICATION_EXIT_TREE) { - if (Engine::get_singleton()->is_editor_hint()) + if (Engine::get_singleton()->is_editor_hint()) { return; + } for (Map<Node *, Variant>::Element *E = nodes.front(); E; E = E->next()) { - if (!visible) + if (!visible) { _change_node_state(E->key(), true); + } E->key()->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &VisibilityEnabler2D::_node_removed)); } @@ -277,10 +288,11 @@ void VisibilityEnabler2D::_change_node_state(Node *p_node, bool p_enabled) { AnimatedSprite2D *as = Object::cast_to<AnimatedSprite2D>(p_node); if (as) { - if (p_enabled) + if (p_enabled) { as->play(); - else + } else { as->stop(); + } } } @@ -294,8 +306,9 @@ void VisibilityEnabler2D::_change_node_state(Node *p_node, bool p_enabled) { } void VisibilityEnabler2D::_node_removed(Node *p_node) { - if (!visible) + if (!visible) { _change_node_state(p_node, true); + } nodes.erase(p_node); } @@ -340,8 +353,9 @@ bool VisibilityEnabler2D::is_enabler_enabled(Enabler p_enabler) const { } VisibilityEnabler2D::VisibilityEnabler2D() { - for (int i = 0; i < ENABLER_MAX; i++) + for (int i = 0; i < ENABLER_MAX; i++) { enabler[i] = true; + } enabler[ENABLER_PARENT_PROCESS] = false; enabler[ENABLER_PARENT_PHYSICS_PROCESS] = false; |