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/resources/shape_2d.cpp | 8 -------- 1 file changed, 8 deletions(-) (limited to 'scene/resources/shape_2d.cpp') diff --git a/scene/resources/shape_2d.cpp b/scene/resources/shape_2d.cpp index 4fe585053a..b48de1aeb3 100644 --- a/scene/resources/shape_2d.cpp +++ b/scene/resources/shape_2d.cpp @@ -31,23 +31,19 @@ #include "shape_2d.h" #include "servers/physics_server_2d.h" RID Shape2D::get_rid() const { - return shape; } void Shape2D::set_custom_solver_bias(real_t p_bias) { - custom_bias = p_bias; PhysicsServer2D::get_singleton()->shape_set_custom_solver_bias(shape, custom_bias); } real_t Shape2D::get_custom_solver_bias() const { - return custom_bias; } bool Shape2D::collide_with_motion(const Transform2D &p_local_xform, const Vector2 &p_local_motion, const Ref &p_shape, const Transform2D &p_shape_xform, const Vector2 &p_shape_motion) { - ERR_FAIL_COND_V(p_shape.is_null(), false); int r; return PhysicsServer2D::get_singleton()->shape_collide(get_rid(), p_local_xform, p_local_motion, p_shape->get_rid(), p_shape_xform, p_shape_motion, nullptr, 0, r); @@ -60,7 +56,6 @@ bool Shape2D::collide(const Transform2D &p_local_xform, const Ref &p_sh } Array Shape2D::collide_with_motion_and_get_contacts(const Transform2D &p_local_xform, const Vector2 &p_local_motion, const Ref &p_shape, const Transform2D &p_shape_xform, const Vector2 &p_shape_motion) { - ERR_FAIL_COND_V(p_shape.is_null(), Array()); const int max_contacts = 16; Vector2 result[max_contacts * 2]; @@ -78,7 +73,6 @@ Array Shape2D::collide_with_motion_and_get_contacts(const Transform2D &p_local_x return results; } Array Shape2D::collide_and_get_contacts(const Transform2D &p_local_xform, const Ref &p_shape, const Transform2D &p_shape_xform) { - ERR_FAIL_COND_V(p_shape.is_null(), Array()); const int max_contacts = 16; Vector2 result[max_contacts * 2]; @@ -97,7 +91,6 @@ Array Shape2D::collide_and_get_contacts(const Transform2D &p_local_xform, const } void Shape2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_custom_solver_bias", "bias"), &Shape2D::set_custom_solver_bias); ClassDB::bind_method(D_METHOD("get_custom_solver_bias"), &Shape2D::get_custom_solver_bias); ClassDB::bind_method(D_METHOD("collide", "local_xform", "with_shape", "shape_xform"), &Shape2D::collide); @@ -114,6 +107,5 @@ Shape2D::Shape2D(const RID &p_rid) { } Shape2D::~Shape2D() { - PhysicsServer2D::get_singleton()->free(shape); } -- 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/resources/shape_2d.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'scene/resources/shape_2d.cpp') diff --git a/scene/resources/shape_2d.cpp b/scene/resources/shape_2d.cpp index b48de1aeb3..60c796f9f9 100644 --- a/scene/resources/shape_2d.cpp +++ b/scene/resources/shape_2d.cpp @@ -72,6 +72,7 @@ Array Shape2D::collide_with_motion_and_get_contacts(const Transform2D &p_local_x return results; } + Array Shape2D::collide_and_get_contacts(const Transform2D &p_local_xform, const Ref &p_shape, const Transform2D &p_shape_xform) { ERR_FAIL_COND_V(p_shape.is_null(), Array()); const int max_contacts = 16; -- 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/resources/shape_2d.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'scene/resources/shape_2d.cpp') diff --git a/scene/resources/shape_2d.cpp b/scene/resources/shape_2d.cpp index 60c796f9f9..99e8020e34 100644 --- a/scene/resources/shape_2d.cpp +++ b/scene/resources/shape_2d.cpp @@ -61,8 +61,9 @@ Array Shape2D::collide_with_motion_and_get_contacts(const Transform2D &p_local_x Vector2 result[max_contacts * 2]; int contacts = 0; - if (!PhysicsServer2D::get_singleton()->shape_collide(get_rid(), p_local_xform, p_local_motion, p_shape->get_rid(), p_shape_xform, p_shape_motion, result, max_contacts, contacts)) + if (!PhysicsServer2D::get_singleton()->shape_collide(get_rid(), p_local_xform, p_local_motion, p_shape->get_rid(), p_shape_xform, p_shape_motion, result, max_contacts, contacts)) { return Array(); + } Array results; results.resize(contacts * 2); @@ -79,8 +80,9 @@ Array Shape2D::collide_and_get_contacts(const Transform2D &p_local_xform, const Vector2 result[max_contacts * 2]; int contacts = 0; - if (!PhysicsServer2D::get_singleton()->shape_collide(get_rid(), p_local_xform, Vector2(), p_shape->get_rid(), p_shape_xform, Vector2(), result, max_contacts, contacts)) + if (!PhysicsServer2D::get_singleton()->shape_collide(get_rid(), p_local_xform, Vector2(), p_shape->get_rid(), p_shape_xform, Vector2(), result, max_contacts, contacts)) { return Array(); + } Array results; results.resize(contacts * 2); -- cgit v1.2.3