From 0be6d925dc3c6413bce7a3ccb49631b8e4a6e67a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 14 May 2020 13:23:58 +0200 Subject: Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks Which means that reduz' beloved style which we all became used to will now be changed automatically to remove the first empty line. This makes us lean closer to 1TBS (the one true brace style) instead of hybridating it with some Allman-inspired spacing. There's still the case of braces around single-statement blocks that needs to be addressed (but clang-format can't help with that, but clang-tidy may if we agree about it). Part of #33027. --- scene/2d/visibility_notifier_2d.cpp | 34 ---------------------------------- 1 file changed, 34 deletions(-) (limited to 'scene/2d/visibility_notifier_2d.cpp') diff --git a/scene/2d/visibility_notifier_2d.cpp b/scene/2d/visibility_notifier_2d.cpp index 780d08693d..6b03d86e8b 100644 --- a/scene/2d/visibility_notifier_2d.cpp +++ b/scene/2d/visibility_notifier_2d.cpp @@ -49,7 +49,6 @@ bool VisibilityNotifier2D::_edit_use_rect() const { #endif void VisibilityNotifier2D::_enter_viewport(Viewport *p_viewport) { - ERR_FAIL_COND(viewports.has(p_viewport)); viewports.insert(p_viewport); @@ -65,7 +64,6 @@ void VisibilityNotifier2D::_enter_viewport(Viewport *p_viewport) { } void VisibilityNotifier2D::_exit_viewport(Viewport *p_viewport) { - ERR_FAIL_COND(!viewports.has(p_viewport)); viewports.erase(p_viewport); @@ -81,7 +79,6 @@ void VisibilityNotifier2D::_exit_viewport(Viewport *p_viewport) { } void VisibilityNotifier2D::set_rect(const Rect2 &p_rect) { - rect = p_rect; if (is_inside_tree()) { get_world_2d()->_update_notifier(this, get_global_transform().xform(rect)); @@ -95,44 +92,35 @@ void VisibilityNotifier2D::set_rect(const Rect2 &p_rect) { } Rect2 VisibilityNotifier2D::get_rect() const { - return rect; } void VisibilityNotifier2D::_notification(int p_what) { - switch (p_what) { case NOTIFICATION_ENTER_TREE: { - //get_world_2d()-> get_world_2d()->_register_notifier(this, get_global_transform().xform(rect)); } break; case NOTIFICATION_TRANSFORM_CHANGED: { - //get_world_2d()-> get_world_2d()->_update_notifier(this, get_global_transform().xform(rect)); } break; case NOTIFICATION_DRAW: { - if (Engine::get_singleton()->is_editor_hint()) { - draw_rect(rect, Color(1, 0.5, 1, 0.2)); } } break; case NOTIFICATION_EXIT_TREE: { - get_world_2d()->_remove_notifier(this); } break; } } bool VisibilityNotifier2D::is_on_screen() const { - return viewports.size() > 0; } void VisibilityNotifier2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_rect", "rect"), &VisibilityNotifier2D::set_rect); ClassDB::bind_method(D_METHOD("get_rect"), &VisibilityNotifier2D::get_rect); ClassDB::bind_method(D_METHOD("is_on_screen"), &VisibilityNotifier2D::is_on_screen); @@ -146,7 +134,6 @@ void VisibilityNotifier2D::_bind_methods() { } VisibilityNotifier2D::VisibilityNotifier2D() { - rect = Rect2(-10, -10, 20, 20); set_notify_transform(true); } @@ -154,9 +141,7 @@ VisibilityNotifier2D::VisibilityNotifier2D() { ////////////////////////////////////// void VisibilityEnabler2D::_screen_enter() { - for (Map::Element *E = nodes.front(); E; E = E->next()) { - _change_node_state(E->key(), true); } @@ -169,9 +154,7 @@ void VisibilityEnabler2D::_screen_enter() { } void VisibilityEnabler2D::_screen_exit() { - for (Map::Element *E = nodes.front(); E; E = E->next()) { - _change_node_state(E->key(), false); } @@ -184,14 +167,12 @@ void VisibilityEnabler2D::_screen_exit() { } void VisibilityEnabler2D::_find_nodes(Node *p_node) { - bool add = false; Variant meta; { RigidBody2D *rb2d = Object::cast_to(p_node); if (rb2d && ((rb2d->get_mode() == RigidBody2D::MODE_CHARACTER || rb2d->get_mode() == RigidBody2D::MODE_RIGID))) { - add = true; meta = rb2d->get_mode(); } @@ -219,7 +200,6 @@ void VisibilityEnabler2D::_find_nodes(Node *p_node) { } if (add) { - p_node->connect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &VisibilityEnabler2D::_node_removed), varray(p_node), CONNECT_ONESHOT); nodes[p_node] = meta; _change_node_state(p_node, false); @@ -235,9 +215,7 @@ 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()) return; @@ -264,12 +242,10 @@ void VisibilityEnabler2D::_notification(int p_what) { } if (p_what == NOTIFICATION_EXIT_TREE) { - if (Engine::get_singleton()->is_editor_hint()) return; for (Map::Element *E = nodes.front(); E; E = E->next()) { - if (!visible) _change_node_state(E->key(), true); E->key()->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &VisibilityEnabler2D::_node_removed)); @@ -280,13 +256,11 @@ void VisibilityEnabler2D::_notification(int p_what) { } void VisibilityEnabler2D::_change_node_state(Node *p_node, bool p_enabled) { - ERR_FAIL_COND(!nodes.has(p_node)); if (enabler[ENABLER_FREEZE_BODIES]) { RigidBody2D *rb = Object::cast_to(p_node); if (rb) { - rb->set_sleeping(!p_enabled); } } @@ -295,7 +269,6 @@ void VisibilityEnabler2D::_change_node_state(Node *p_node, bool p_enabled) { AnimationPlayer *ap = Object::cast_to(p_node); if (ap) { - ap->set_active(p_enabled); } } @@ -304,7 +277,6 @@ void VisibilityEnabler2D::_change_node_state(Node *p_node, bool p_enabled) { AnimatedSprite2D *as = Object::cast_to(p_node); if (as) { - if (p_enabled) as->play(); else @@ -316,14 +288,12 @@ void VisibilityEnabler2D::_change_node_state(Node *p_node, bool p_enabled) { GPUParticles2D *ps = Object::cast_to(p_node); if (ps) { - ps->set_emitting(p_enabled); } } } void VisibilityEnabler2D::_node_removed(Node *p_node) { - if (!visible) _change_node_state(p_node, true); nodes.erase(p_node); @@ -339,7 +309,6 @@ String VisibilityEnabler2D::get_configuration_warning() const { } void VisibilityEnabler2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_enabler", "enabler", "enabled"), &VisibilityEnabler2D::set_enabler); ClassDB::bind_method(D_METHOD("is_enabler_enabled", "enabler"), &VisibilityEnabler2D::is_enabler_enabled); ClassDB::bind_method(D_METHOD("_node_removed"), &VisibilityEnabler2D::_node_removed); @@ -361,18 +330,15 @@ void VisibilityEnabler2D::_bind_methods() { } void VisibilityEnabler2D::set_enabler(Enabler p_enabler, bool p_enable) { - ERR_FAIL_INDEX(p_enabler, ENABLER_MAX); enabler[p_enabler] = p_enable; } bool VisibilityEnabler2D::is_enabler_enabled(Enabler p_enabler) const { - ERR_FAIL_INDEX_V(p_enabler, ENABLER_MAX, false); return enabler[p_enabler]; } VisibilityEnabler2D::VisibilityEnabler2D() { - for (int i = 0; i < ENABLER_MAX; i++) enabler[i] = true; enabler[ENABLER_PARENT_PROCESS] = false; -- cgit v1.2.3 From 07bc4e2f96f8f47991339654ff4ab16acc19d44f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 14 May 2020 14:29:06 +0200 Subject: Style: Enforce separation line between function definitions I couldn't find a tool that enforces it, so I went the manual route: ``` find -name "thirdparty" -prune \ -o -name "*.cpp" -o -name "*.h" -o -name "*.m" -o -name "*.mm" \ -o -name "*.glsl" > files perl -0777 -pi -e 's/\n}\n([^#])/\n}\n\n\1/g' $(cat files) misc/scripts/fix_style.sh -c ``` This adds a newline after all `}` on the first column, unless they are followed by `#` (typically `#endif`). This leads to having lots of places with two lines between function/class definitions, but clang-format then fixes it as we enforce max one line of separation. This doesn't fix potential occurrences of function definitions which are indented (e.g. for a helper class defined in a .cpp), but it's better than nothing. Also can't be made to run easily on CI/hooks so we'll have to be careful with new code. Part of #33027. --- scene/2d/visibility_notifier_2d.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'scene/2d/visibility_notifier_2d.cpp') diff --git a/scene/2d/visibility_notifier_2d.cpp b/scene/2d/visibility_notifier_2d.cpp index 6b03d86e8b..1f250bbdf6 100644 --- a/scene/2d/visibility_notifier_2d.cpp +++ b/scene/2d/visibility_notifier_2d.cpp @@ -333,6 +333,7 @@ void VisibilityEnabler2D::set_enabler(Enabler p_enabler, bool p_enable) { ERR_FAIL_INDEX(p_enabler, ENABLER_MAX); enabler[p_enabler] = p_enable; } + bool VisibilityEnabler2D::is_enabler_enabled(Enabler p_enabler) const { ERR_FAIL_INDEX_V(p_enabler, ENABLER_MAX, false); return enabler[p_enabler]; -- cgit v1.2.3 From 0ee0fa42e6639b6fa474b7cf6afc6b1a78142185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 14 May 2020 16:41:43 +0200 Subject: Style: Enforce braces around if blocks and loops Using clang-tidy's `readability-braces-around-statements`. https://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html --- scene/2d/visibility_notifier_2d.cpp | 44 ++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 15 deletions(-) (limited to 'scene/2d/visibility_notifier_2d.cpp') 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::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(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; -- cgit v1.2.3