Skip to content

Commit

Permalink
Merge pull request #48475 from akien-mga/3.x-style-changes
Browse files Browse the repository at this point in the history
  • Loading branch information
akien-mga authored May 5, 2021
2 parents b8d198e + 140350d commit 410b8e8
Show file tree
Hide file tree
Showing 694 changed files with 23,271 additions and 12,487 deletions.
2 changes: 1 addition & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
Checks: 'clang-diagnostic-*,clang-analyzer-*,-*,modernize-redundant-void-arg,modernize-use-bool-literals,modernize-use-nullptr'
Checks: 'clang-diagnostic-*,clang-analyzer-*,-*,modernize-redundant-void-arg,modernize-use-bool-literals,modernize-use-nullptr,readability-braces-around-statements'
WarningsAsErrors: ''
HeaderFilterRegex: '.*'
AnalyzeTemporaryDtors: false
Expand Down
30 changes: 20 additions & 10 deletions core/array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ void Array::_ref(const Array &p_from) const {

ERR_FAIL_COND(!_fp); // should NOT happen.

if (_fp == _p)
if (_fp == _p) {
return; // whatever it is, nothing to do here move along
}

bool success = _fp->refcount.ref();

Expand All @@ -59,8 +60,9 @@ void Array::_ref(const Array &p_from) const {
}

void Array::_unref() const {
if (!_p)
if (!_p) {
return;
}

if (_p->refcount.unref()) {
memdelete(_p);
Expand Down Expand Up @@ -136,8 +138,9 @@ int Array::find(const Variant &p_value, int p_from) const {
}

int Array::rfind(const Variant &p_value, int p_from) const {
if (_p->array.size() == 0)
if (_p->array.size() == 0) {
return -1;
}

if (p_from < 0) {
// Relative offset from the end
Expand All @@ -162,8 +165,9 @@ int Array::find_last(const Variant &p_value) const {
}

int Array::count(const Variant &p_value) const {
if (_p->array.size() == 0)
if (_p->array.size() == 0) {
return 0;
}

int amount = 0;
for (int i = 0; i < _p->array.size(); i++) {
Expand Down Expand Up @@ -217,14 +221,17 @@ Array Array::slice(int p_begin, int p_end, int p_step, bool p_deep) const { // l

ERR_FAIL_COND_V_MSG(p_step == 0, new_arr, "Array slice step size cannot be zero.");

if (empty()) // Don't try to slice empty arrays.
if (empty()) { // Don't try to slice empty arrays.
return new_arr;
}
if (p_step > 0) {
if (p_begin >= size() || p_end < -size())
if (p_begin >= size() || p_end < -size()) {
return new_arr;
}
} else { // p_step < 0
if (p_begin < -size() || p_end >= size())
if (p_begin < -size() || p_end >= size()) {
return new_arr;
}
}

int begin = _clamp_slice_index(p_begin);
Expand Down Expand Up @@ -255,8 +262,9 @@ struct _ArrayVariantSort {
bool valid = false;
Variant res;
Variant::evaluate(Variant::OP_LESS, p_l, p_r, res, valid);
if (!valid)
if (!valid) {
res = false;
}
return res;
}
};
Expand All @@ -274,8 +282,9 @@ struct _ArrayVariantSortCustom {
const Variant *args[2] = { &p_l, &p_r };
Variant::CallError err;
bool res = obj->call(func, args, 2, err);
if (err.error != Variant::CallError::CALL_OK)
if (err.error != Variant::CallError::CALL_OK) {
res = false;
}
return res;
}
};
Expand All @@ -291,8 +300,9 @@ Array &Array::sort_custom(Object *p_obj, const StringName &p_function) {

void Array::shuffle() {
const int n = _p->array.size();
if (n < 2)
if (n < 2) {
return;
}
Variant *data = _p->array.ptrw();
for (int i = n - 1; i >= 1; i--) {
const int j = Math::rand() % (i + 1);
Expand Down
80 changes: 52 additions & 28 deletions core/bind/core_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,18 +475,20 @@ int _OS::execute(const String &p_path, const Vector<String> &p_arguments, bool p
OS::ProcessID pid = -2;
int exitcode = 0;
List<String> args;
for (int i = 0; i < p_arguments.size(); i++)
for (int i = 0; i < p_arguments.size(); i++) {
args.push_back(p_arguments[i]);
}
String pipe;
Error err = OS::get_singleton()->execute(p_path, args, p_blocking, &pid, &pipe, &exitcode, p_read_stderr);
p_output.clear();
p_output.push_back(pipe);
if (err != OK)
if (err != OK) {
return -1;
else if (p_blocking)
} else if (p_blocking) {
return exitcode;
else
} else {
return pid;
}
}

Error _OS::kill(int p_pid) {
Expand Down Expand Up @@ -959,8 +961,9 @@ void _OS::print_all_textures_by_size() {
ResourceCache::get_cached_resources(&rsrc);

for (List<Ref<Resource>>::Element *E = rsrc.front(); E; E = E->next()) {
if (!E->get()->is_class("ImageTexture"))
if (!E->get()->is_class("ImageTexture")) {
continue;
}

Size2 size = E->get()->call("get_size");
int fmt = E->get()->call("get_format");
Expand Down Expand Up @@ -995,11 +998,13 @@ void _OS::print_resources_by_type(const Vector<String> &p_types) {
bool found = false;

for (int i = 0; i < p_types.size(); i++) {
if (r->is_class(p_types[i]))
if (r->is_class(p_types[i])) {
found = true;
}
}
if (!found)
if (!found) {
continue;
}

if (!type_count.has(r->get_class())) {
type_count[r->get_class()] = 0;
Expand Down Expand Up @@ -1542,17 +1547,19 @@ Vector3 _Geometry::get_closest_point_to_segment_uncapped(const Vector3 &p_point,
}
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))
if (Geometry::ray_intersects_triangle(p_from, p_dir, p_v0, p_v1, p_v2, &res)) {
return res;
else
} 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))
if (Geometry::segment_intersects_triangle(p_from, p_to, p_v0, p_v1, p_v2, &res)) {
return res;
else
} else {
return Variant();
}
}

bool _Geometry::point_is_inside_triangle(const Vector2 &s, const Vector2 &a, const Vector2 &b, const Vector2 &c) const {
Expand All @@ -1562,8 +1569,9 @@ bool _Geometry::point_is_inside_triangle(const Vector2 &s, const Vector2 &a, con
PoolVector<Vector3> _Geometry::segment_intersects_sphere(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_sphere_pos, real_t p_sphere_radius) {
PoolVector<Vector3> r;
Vector3 res, norm;
if (!Geometry::segment_intersects_sphere(p_from, p_to, p_sphere_pos, p_sphere_radius, &res, &norm))
if (!Geometry::segment_intersects_sphere(p_from, p_to, p_sphere_pos, p_sphere_radius, &res, &norm)) {
return r;
}

r.resize(2);
r.set(0, res);
Expand All @@ -1573,8 +1581,9 @@ PoolVector<Vector3> _Geometry::segment_intersects_sphere(const Vector3 &p_from,
PoolVector<Vector3> _Geometry::segment_intersects_cylinder(const Vector3 &p_from, const Vector3 &p_to, float p_height, float p_radius) {
PoolVector<Vector3> r;
Vector3 res, norm;
if (!Geometry::segment_intersects_cylinder(p_from, p_to, p_height, p_radius, &res, &norm))
if (!Geometry::segment_intersects_cylinder(p_from, p_to, p_height, p_radius, &res, &norm)) {
return r;
}

r.resize(2);
r.set(0, res);
Expand All @@ -1584,8 +1593,9 @@ PoolVector<Vector3> _Geometry::segment_intersects_cylinder(const Vector3 &p_from
PoolVector<Vector3> _Geometry::segment_intersects_convex(const Vector3 &p_from, const Vector3 &p_to, const Vector<Plane> &p_planes) {
PoolVector<Vector3> r;
Vector3 res, norm;
if (!Geometry::segment_intersects_convex(p_from, p_to, p_planes.ptr(), p_planes.size(), &res, &norm))
if (!Geometry::segment_intersects_convex(p_from, p_to, p_planes.ptr(), p_planes.size(), &res, &norm)) {
return r;
}

r.resize(2);
r.set(0, res);
Expand Down Expand Up @@ -1805,8 +1815,9 @@ _Geometry::_Geometry() {

Error _File::open_encrypted(const String &p_path, ModeFlags p_mode_flags, const Vector<uint8_t> &p_key) {
Error err = open(p_path, p_mode_flags);
if (err)
if (err) {
return err;
}

FileAccessEncrypted *fae = memnew(FileAccessEncrypted);
err = fae->open_and_parse(f, p_key, (p_mode_flags == WRITE) ? FileAccessEncrypted::MODE_WRITE_AES256 : FileAccessEncrypted::MODE_READ);
Expand All @@ -1821,8 +1832,9 @@ Error _File::open_encrypted(const String &p_path, ModeFlags p_mode_flags, const

Error _File::open_encrypted_pass(const String &p_path, ModeFlags p_mode_flags, const String &p_pass) {
Error err = open(p_path, p_mode_flags);
if (err)
if (err) {
return err;
}

FileAccessEncrypted *fae = memnew(FileAccessEncrypted);
err = fae->open_and_parse_password(f, p_pass, (p_mode_flags == WRITE) ? FileAccessEncrypted::MODE_WRITE_AES256 : FileAccessEncrypted::MODE_READ);
Expand Down Expand Up @@ -1856,8 +1868,9 @@ Error _File::open(const String &p_path, ModeFlags p_mode_flags) {
close();
Error err;
f = FileAccess::open(p_path, p_mode_flags, &err);
if (f)
if (f) {
f->set_endian_swap(eswap);
}
return err;
}

Expand All @@ -1867,8 +1880,9 @@ void _File::flush() {
}

void _File::close() {
if (f)
if (f) {
memdelete(f);
}
f = nullptr;
}
bool _File::is_open() const {
Expand Down Expand Up @@ -1942,8 +1956,9 @@ PoolVector<uint8_t> _File::get_buffer(int p_length) const {
ERR_FAIL_COND_V_MSG(!f, data, "File must be opened before use.");

ERR_FAIL_COND_V_MSG(p_length < 0, data, "Length of buffer cannot be smaller than 0.");
if (p_length == 0)
if (p_length == 0) {
return data;
}

Error err = data.resize(p_length);
ERR_FAIL_COND_V_MSG(err != OK, data, "Can't resize data to " + itos(p_length) + " elements.");
Expand All @@ -1954,8 +1969,9 @@ PoolVector<uint8_t> _File::get_buffer(int p_length) const {

w.release();

if (len < p_length)
if (len < p_length) {
data.resize(p_length);
}

return data;
}
Expand Down Expand Up @@ -2004,16 +2020,18 @@ Vector<String> _File::get_csv_line(const String &p_delim) const {

void _File::set_endian_swap(bool p_swap) {
eswap = p_swap;
if (f)
if (f) {
f->set_endian_swap(p_swap);
}
}
bool _File::get_endian_swap() {
return eswap;
}

Error _File::get_error() const {
if (!f)
if (!f) {
return ERR_UNCONFIGURED;
}
return f->get_error();
}

Expand Down Expand Up @@ -2086,8 +2104,9 @@ void _File::store_buffer(const PoolVector<uint8_t> &p_buffer) {
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");

int len = p_buffer.size();
if (len == 0)
if (len == 0) {
return;
}

PoolVector<uint8_t>::Read r = p_buffer.read();

Expand Down Expand Up @@ -2207,8 +2226,9 @@ _File::_File() {
}

_File::~_File() {
if (f)
if (f) {
memdelete(f);
}
}

///////////////////////////////////////////////////////
Expand All @@ -2217,10 +2237,12 @@ Error _Directory::open(const String &p_path) {
Error err;
DirAccess *alt = DirAccess::open(p_path, &err);

if (!alt)
if (!alt) {
return err;
if (d)
}
if (d) {
memdelete(d);
}
d = alt;

return OK;
Expand Down Expand Up @@ -2380,8 +2402,9 @@ _Directory::_Directory() {
}

_Directory::~_Directory() {
if (d)
if (d) {
memdelete(d);
}
}

_Marshalls *_Marshalls::singleton = nullptr;
Expand Down Expand Up @@ -2656,8 +2679,9 @@ bool _ClassDB::can_instance(const StringName &p_class) const {
}
Variant _ClassDB::instance(const StringName &p_class) const {
Object *obj = ClassDB::instance(p_class);
if (!obj)
if (!obj) {
return Variant();
}

Reference *r = Object::cast_to<Reference>(obj);
if (r) {
Expand Down
Loading

0 comments on commit 410b8e8

Please sign in to comment.