Skip to content

Commit

Permalink
Style: Enforce separation line between function definitions
Browse files Browse the repository at this point in the history
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 godotengine#33027.
  • Loading branch information
akien-mga committed May 14, 2020
1 parent 0be6d92 commit 07bc4e2
Show file tree
Hide file tree
Showing 409 changed files with 2,286 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,11 @@ const Variant &Array::operator[](int p_idx) const {
int Array::size() const {
return _p->array.size();
}

bool Array::empty() const {
return _p->array.empty();
}

void Array::clear() {
_p->array.clear();
}
Expand Down Expand Up @@ -151,6 +153,7 @@ void Array::_assign(const Array &p_array) {
void Array::operator=(const Array &p_array) {
_assign(p_array);
}

void Array::push_back(const Variant &p_value) {
ERR_FAIL_COND(!_p->typed.validate(p_value, "push_back"));
_p->array.push_back(p_value);
Expand Down Expand Up @@ -509,6 +512,7 @@ Array::Array() {
_p = memnew(ArrayPrivate);
_p->refcount.init();
}

Array::~Array() {
_unref();
}
48 changes: 48 additions & 0 deletions core/bind/core_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ _ResourceLoader *_ResourceLoader::singleton = nullptr;
Error _ResourceLoader::load_threaded_request(const String &p_path, const String &p_type_hint, bool p_use_sub_threads) {
return ResourceLoader::load_threaded_request(p_path, p_type_hint, p_use_sub_threads);
}

_ResourceLoader::ThreadLoadStatus _ResourceLoader::load_threaded_get_status(const String &p_path, Array r_progress) {
float progress = 0;
ResourceLoader::ThreadLoadStatus tls = ResourceLoader::load_threaded_get_status(p_path, &progress);
r_progress.resize(1);
r_progress[0] = progress;
return (ThreadLoadStatus)tls;
}

RES _ResourceLoader::load_threaded_get(const String &p_path) {
Error error;
RES res = ResourceLoader::load_threaded_get(p_path, &error);
Expand Down Expand Up @@ -198,6 +200,7 @@ void _OS::set_use_file_access_save_and_swap(bool p_enable) {
void _OS::set_low_processor_usage_mode(bool p_enabled) {
OS::get_singleton()->set_low_processor_usage_mode(p_enabled);
}

bool _OS::is_in_low_processor_usage_mode() const {
return OS::get_singleton()->is_in_low_processor_usage_mode();
}
Expand Down Expand Up @@ -252,13 +255,15 @@ int _OS::get_process_id() const {
bool _OS::has_environment(const String &p_var) const {
return OS::get_singleton()->has_environment(p_var);
}

String _OS::get_environment(const String &p_var) const {
return OS::get_singleton()->get_environment(p_var);
}

String _OS::get_name() const {
return OS::get_singleton()->get_name();
}

Vector<String> _OS::get_cmdline_args() {
List<String> cmdline = OS::get_singleton()->get_cmdline_args();
Vector<String> cmdlinev;
Expand Down Expand Up @@ -811,6 +816,7 @@ Vector<Plane> _Geometry::build_box_planes(const Vector3 &p_extents) {
Vector<Plane> _Geometry::build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis) {
return Geometry::build_cylinder_planes(p_radius, p_height, p_sides, p_axis);
}

Vector<Plane> _Geometry::build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis) {
return Geometry::build_capsule_planes(p_radius, p_height, p_sides, p_lats, p_axis);
}
Expand Down Expand Up @@ -860,29 +866,35 @@ Vector<Vector3> _Geometry::get_closest_points_between_segments(const Vector3 &p1
r.set(1, r2);
return r;
}

Vector2 _Geometry::get_closest_point_to_segment_2d(const Vector2 &p_point, const Vector2 &p_a, const Vector2 &p_b) {
Vector2 s[2] = { p_a, p_b };
return Geometry::get_closest_point_to_segment_2d(p_point, s);
}

Vector3 _Geometry::get_closest_point_to_segment(const Vector3 &p_point, const Vector3 &p_a, const Vector3 &p_b) {
Vector3 s[2] = { p_a, p_b };
return Geometry::get_closest_point_to_segment(p_point, s);
}

Vector2 _Geometry::get_closest_point_to_segment_uncapped_2d(const Vector2 &p_point, const Vector2 &p_a, const Vector2 &p_b) {
Vector2 s[2] = { p_a, p_b };
return Geometry::get_closest_point_to_segment_uncapped_2d(p_point, s);
}

Vector3 _Geometry::get_closest_point_to_segment_uncapped(const Vector3 &p_point, const Vector3 &p_a, const Vector3 &p_b) {
Vector3 s[2] = { p_a, p_b };
return Geometry::get_closest_point_to_segment_uncapped(p_point, s);
}

Variant _Geometry::ray_intersects_triangle(const Vector3 &p_from, const Vector3 &p_dir, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2) {
Vector3 res;
if (Geometry::ray_intersects_triangle(p_from, p_dir, p_v0, p_v1, p_v2, &res))
return res;
else
return Variant();
}

Variant _Geometry::segment_intersects_triangle(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2) {
Vector3 res;
if (Geometry::segment_intersects_triangle(p_from, p_to, p_v0, p_v1, p_v2, &res))
Expand All @@ -906,6 +918,7 @@ Vector<Vector3> _Geometry::segment_intersects_sphere(const Vector3 &p_from, cons
r.set(1, norm);
return r;
}

Vector<Vector3> _Geometry::segment_intersects_cylinder(const Vector3 &p_from, const Vector3 &p_to, float p_height, float p_radius) {
Vector<Vector3> r;
Vector3 res, norm;
Expand All @@ -917,6 +930,7 @@ Vector<Vector3> _Geometry::segment_intersects_cylinder(const Vector3 &p_from, co
r.set(1, norm);
return r;
}

Vector<Vector3> _Geometry::segment_intersects_convex(const Vector3 &p_from, const Vector3 &p_to, const Vector<Plane> &p_planes) {
Vector<Vector3> r;
Vector3 res, norm;
Expand Down Expand Up @@ -1198,9 +1212,11 @@ void _File::close() {
memdelete(f);
f = nullptr;
}

bool _File::is_open() const {
return f != nullptr;
}

String _File::get_path() const {
ERR_FAIL_COND_V_MSG(!f, "", "File must be opened before use.");
return f->get_path();
Expand All @@ -1215,10 +1231,12 @@ void _File::seek(int64_t p_position) {
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
f->seek(p_position);
}

void _File::seek_end(int64_t p_position) {
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
f->seek_end(p_position);
}

int64_t _File::get_position() const {
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
return f->get_position();
Expand All @@ -1238,14 +1256,17 @@ uint8_t _File::get_8() const {
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
return f->get_8();
}

uint16_t _File::get_16() const {
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
return f->get_16();
}

uint32_t _File::get_32() const {
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
return f->get_32();
}

uint64_t _File::get_64() const {
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
return f->get_64();
Expand All @@ -1255,10 +1276,12 @@ float _File::get_float() const {
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
return f->get_float();
}

double _File::get_double() const {
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
return f->get_double();
}

real_t _File::get_real() const {
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
return f->get_real();
Expand Down Expand Up @@ -1332,6 +1355,7 @@ void _File::set_endian_swap(bool p_swap) {
if (f)
f->set_endian_swap(p_swap);
}

bool _File::get_endian_swap() {
return eswap;
}
Expand All @@ -1347,16 +1371,19 @@ void _File::store_8(uint8_t p_dest) {

f->store_8(p_dest);
}

void _File::store_16(uint16_t p_dest) {
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");

f->store_16(p_dest);
}

void _File::store_32(uint32_t p_dest) {
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");

f->store_32(p_dest);
}

void _File::store_64(uint64_t p_dest) {
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");

Expand All @@ -1368,11 +1395,13 @@ void _File::store_float(float p_dest) {

f->store_float(p_dest);
}

void _File::store_double(double p_dest) {
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");

f->store_double(p_dest);
}

void _File::store_real(real_t p_real) {
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");

Expand Down Expand Up @@ -1562,6 +1591,7 @@ String _Directory::get_next() {
}
return next;
}

bool _Directory::current_is_dir() const {
ERR_FAIL_COND_V_MSG(!d, false, "Directory must be opened before use.");
return d->current_is_dir();
Expand All @@ -1576,10 +1606,12 @@ int _Directory::get_drive_count() {
ERR_FAIL_COND_V_MSG(!d, 0, "Directory must be opened before use.");
return d->get_drive_count();
}

String _Directory::get_drive(int p_drive) {
ERR_FAIL_COND_V_MSG(!d, "", "Directory must be opened before use.");
return d->get_drive(p_drive);
}

int _Directory::get_current_drive() {
ERR_FAIL_COND_V_MSG(!d, 0, "Directory must be opened before use.");
return d->get_current_drive();
Expand All @@ -1589,10 +1621,12 @@ Error _Directory::change_dir(String p_dir) {
ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use.");
return d->change_dir(p_dir);
}

String _Directory::get_current_dir() {
ERR_FAIL_COND_V_MSG(!d, "", "Directory must be opened before use.");
return d->get_current_dir();
}

Error _Directory::make_dir(String p_dir) {
ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use.");
if (!p_dir.is_rel_path()) {
Expand All @@ -1603,6 +1637,7 @@ Error _Directory::make_dir(String p_dir) {
}
return d->make_dir(p_dir);
}

Error _Directory::make_dir_recursive(String p_dir) {
ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use.");
if (!p_dir.is_rel_path()) {
Expand Down Expand Up @@ -1646,6 +1681,7 @@ Error _Directory::copy(String p_from, String p_to) {
ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use.");
return d->copy(p_from, p_to);
}

Error _Directory::rename(String p_from, String p_to) {
ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use.");
if (!p_from.is_rel_path()) {
Expand All @@ -1657,6 +1693,7 @@ Error _Directory::rename(String p_from, String p_to) {

return d->rename(p_from, p_to);
}

Error _Directory::remove(String p_name) {
ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use.");
if (!p_name.is_rel_path()) {
Expand Down Expand Up @@ -1915,6 +1952,7 @@ String _Thread::get_id() const {
bool _Thread::is_active() const {
return active;
}

Variant _Thread::wait_to_finish() {
ERR_FAIL_COND_V_MSG(!thread, Variant(), "Thread must exist to wait for its completion.");
ERR_FAIL_COND_V_MSG(!active, Variant(), "Thread must be active to wait for its completion.");
Expand Down Expand Up @@ -1961,6 +1999,7 @@ PackedStringArray _ClassDB::get_class_list() const {

return ret;
}

PackedStringArray _ClassDB::get_inheriters_from_class(const StringName &p_class) const {
List<StringName> classes;
ClassDB::get_inheriters_from_class(p_class, &classes);
Expand All @@ -1974,18 +2013,23 @@ PackedStringArray _ClassDB::get_inheriters_from_class(const StringName &p_class)

return ret;
}

StringName _ClassDB::get_parent_class(const StringName &p_class) const {
return ClassDB::get_parent_class(p_class);
}

bool _ClassDB::class_exists(const StringName &p_class) const {
return ClassDB::class_exists(p_class);
}

bool _ClassDB::is_parent_class(const StringName &p_class, const StringName &p_inherits) const {
return ClassDB::is_parent_class(p_class, p_inherits);
}

bool _ClassDB::can_instance(const StringName &p_class) const {
return ClassDB::can_instance(p_class);
}

Variant _ClassDB::instance(const StringName &p_class) const {
Object *obj = ClassDB::instance(p_class);
if (!obj)
Expand All @@ -2002,6 +2046,7 @@ Variant _ClassDB::instance(const StringName &p_class) const {
bool _ClassDB::has_signal(StringName p_class, StringName p_signal) const {
return ClassDB::has_signal(p_class, p_signal);
}

Dictionary _ClassDB::get_signal(StringName p_class, StringName p_signal) const {
MethodInfo signal;
if (ClassDB::get_signal(p_class, p_signal, &signal)) {
Expand All @@ -2010,6 +2055,7 @@ Dictionary _ClassDB::get_signal(StringName p_class, StringName p_signal) const {
return Dictionary();
}
}

Array _ClassDB::get_signal_list(StringName p_class, bool p_no_inheritance) const {
List<MethodInfo> signals;
ClassDB::get_signal_list(p_class, &signals, p_no_inheritance);
Expand Down Expand Up @@ -2098,6 +2144,7 @@ int _ClassDB::get_integer_constant(const StringName &p_class, const StringName &
ERR_FAIL_COND_V(!found, 0);
return c;
}

StringName _ClassDB::get_category(const StringName &p_node) const {
return ClassDB::get_category(p_node);
}
Expand Down Expand Up @@ -2141,6 +2188,7 @@ void _ClassDB::_bind_methods() {
void _Engine::set_iterations_per_second(int p_ips) {
Engine::get_singleton()->set_iterations_per_second(p_ips);
}

int _Engine::get_iterations_per_second() const {
return Engine::get_singleton()->get_iterations_per_second();
}
Expand Down
Loading

0 comments on commit 07bc4e2

Please sign in to comment.