diff options
Diffstat (limited to 'core')
149 files changed, 4433 insertions, 2396 deletions
diff --git a/core/array.cpp b/core/array.cpp index 1a8a833404..d1c0688e63 100644 --- a/core/array.cpp +++ b/core/array.cpp @@ -50,8 +50,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(); @@ -63,8 +64,9 @@ void Array::_ref(const Array &p_from) const { } void Array::_unref() const { - if (!_p) + if (!_p) { return; + } if (_p->refcount.unref()) { memdelete(_p); @@ -189,8 +191,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; + } ERR_FAIL_COND_V(!_p->typed.validate(p_value, "rfind"), -1); if (p_from < 0) { @@ -218,8 +221,9 @@ int Array::find_last(const Variant &p_value) const { int Array::count(const Variant &p_value) const { ERR_FAIL_COND_V(!_p->typed.validate(p_value, "count"), 0); - if (_p->array.size() == 0) + if (_p->array.size() == 0) { return 0; + } int amount = 0; for (int i = 0; i < _p->array.size(); i++) { @@ -278,14 +282,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); @@ -316,8 +323,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; } }; @@ -335,8 +343,9 @@ struct _ArrayVariantSortCustom { const Variant *args[2] = { &p_l, &p_r }; Callable::CallError err; bool res = obj->call(func, args, 2, err); - if (err.error != Callable::CallError::CALL_OK) + if (err.error != Callable::CallError::CALL_OK) { res = false; + } return res; } }; @@ -352,8 +361,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); diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 7c7ef4e03c..607e17eae4 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -230,18 +230,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) { @@ -564,8 +566,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"); @@ -603,11 +606,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; @@ -889,18 +894,20 @@ 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 { @@ -910,8 +917,9 @@ bool _Geometry::point_is_inside_triangle(const Vector2 &s, const Vector2 &a, con Vector<Vector3> _Geometry::segment_intersects_sphere(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_sphere_pos, real_t p_sphere_radius) { Vector<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); @@ -922,8 +930,9 @@ Vector<Vector3> _Geometry::segment_intersects_sphere(const Vector3 &p_from, cons 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; - 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); @@ -934,8 +943,9 @@ Vector<Vector3> _Geometry::segment_intersects_cylinder(const Vector3 &p_from, co 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; - 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); @@ -1151,8 +1161,9 @@ void _Geometry::_bind_methods() { 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); @@ -1167,8 +1178,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); @@ -1202,14 +1214,16 @@ 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; } void _File::close() { - if (f) + if (f) { memdelete(f); + } f = nullptr; } @@ -1292,8 +1306,9 @@ Vector<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."); @@ -1302,8 +1317,9 @@ Vector<uint8_t> _File::get_buffer(int p_length) const { int len = f->get_buffer(&w[0], p_length); ERR_FAIL_COND_V(len < 0, Vector<uint8_t>()); - if (len < p_length) + if (len < p_length) { data.resize(p_length); + } return data; } @@ -1352,8 +1368,9 @@ 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() { @@ -1361,8 +1378,9 @@ bool _File::get_endian_swap() { } Error _File::get_error() const { - if (!f) + if (!f) { return ERR_UNCONFIGURED; + } return f->get_error(); } @@ -1440,8 +1458,9 @@ void _File::store_buffer(const Vector<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; + } const uint8_t *r = p_buffer.ptr(); @@ -1554,8 +1573,9 @@ void _File::_bind_methods() { } _File::~_File() { - if (f) + if (f) { memdelete(f); + } } ////// _Directory ////// @@ -1564,10 +1584,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; @@ -1733,8 +1755,9 @@ _Directory::_Directory() { } _Directory::~_Directory() { - if (d) + if (d) { memdelete(d); + } } ////// _Marshalls ////// @@ -1943,8 +1966,9 @@ Error _Thread::start(Object *p_instance, const StringName &p_method, const Varia } String _Thread::get_id() const { - if (!thread) + if (!thread) { return String(); + } return itos(thread->get_id()); } @@ -1962,8 +1986,9 @@ Variant _Thread::wait_to_finish() { target_method = StringName(); target_instance = nullptr; userdata = Variant(); - if (thread) + if (thread) { memdelete(thread); + } thread = nullptr; return r; @@ -2032,8 +2057,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) { diff --git a/core/class_db.cpp b/core/class_db.cpp index 0a187416f4..eed9ec17cb 100644 --- a/core/class_db.cpp +++ b/core/class_db.cpp @@ -248,8 +248,9 @@ bool ClassDB::is_parent_class(const StringName &p_class, const StringName &p_inh StringName inherits = p_class; while (inherits.operator String().length()) { - if (inherits == p_inherits) + if (inherits == p_inherits) { return true; + } inherits = get_parent_class(inherits); } @@ -274,8 +275,9 @@ void ClassDB::get_inheriters_from_class(const StringName &p_class, List<StringNa const StringName *k = nullptr; while ((k = classes.next(k))) { - if (*k != p_class && is_parent_class(*k, p_class)) + if (*k != p_class && is_parent_class(*k, p_class)) { p_classes->push_back(*k); + } } } @@ -285,8 +287,9 @@ void ClassDB::get_direct_inheriters_from_class(const StringName &p_class, List<S const StringName *k = nullptr; while ((k = classes.next(k))) { - if (*k != p_class && get_parent_class(*k) == p_class) + if (*k != p_class && get_parent_class(*k) == p_class) { p_classes->push_back(*k); + } } } @@ -294,8 +297,9 @@ StringName ClassDB::get_parent_class_nocheck(const StringName &p_class) { OBJTYPE_RLOCK; ClassInfo *ti = classes.getptr(p_class); - if (!ti) + if (!ti) { return StringName(); + } return ti->inherits; } @@ -347,8 +351,9 @@ uint64_t ClassDB::get_api_hash(APIType p_api) { for (List<StringName>::Element *E = names.front(); E; E = E->next()) { ClassInfo *t = classes.getptr(E->get()); ERR_FAIL_COND_V_MSG(!t, 0, "Cannot get class '" + String(E->get()) + "'."); - if (t->api != p_api || !t->exposed) + if (t->api != p_api || !t->exposed) { continue; + } hash = hash_djb2_one_64(t->name.hash(), hash); hash = hash_djb2_one_64(t->inherits.hash(), hash); @@ -363,8 +368,9 @@ uint64_t ClassDB::get_api_hash(APIType p_api) { ERR_CONTINUE(name.empty()); - if (name[0] == '_') + if (name[0] == '_') { continue; // Ignore non-virtual methods that start with an underscore + } snames.push_back(*k); } @@ -549,8 +555,9 @@ void ClassDB::get_method_list(StringName p_class, List<MethodInfo> *p_methods, b while (type) { if (type->disabled) { - if (p_no_inheritance) + if (p_no_inheritance) { break; + } type = type->inherits_ptr; continue; @@ -568,8 +575,9 @@ void ClassDB::get_method_list(StringName p_class, List<MethodInfo> *p_methods, b minfo.name = E->get(); minfo.id = method->get_method_id(); - if (p_exclude_from_properties && type->methods_in_properties.has(minfo.name)) + if (p_exclude_from_properties && type->methods_in_properties.has(minfo.name)) { continue; + } for (int i = 0; i < method->get_argument_count(); i++) { //Variant::Type t=method->get_argument_type(i); @@ -581,8 +589,9 @@ void ClassDB::get_method_list(StringName p_class, List<MethodInfo> *p_methods, b minfo.flags = method->get_hint_flags(); for (int i = 0; i < method->get_argument_count(); i++) { - if (method->has_default_argument(i)) + if (method->has_default_argument(i)) { minfo.default_arguments.push_back(method->get_default_argument(i)); + } } p_methods->push_back(minfo); @@ -601,8 +610,9 @@ void ClassDB::get_method_list(StringName p_class, List<MethodInfo> *p_methods, b #endif - if (p_no_inheritance) + if (p_no_inheritance) { break; + } type = type->inherits_ptr; } @@ -615,8 +625,9 @@ MethodBind *ClassDB::get_method(StringName p_class, StringName p_name) { while (type) { MethodBind **method = type->method_map.getptr(p_name); - if (method && *method) + if (method && *method) { return *method; + } type = type->inherits_ptr; } return nullptr; @@ -664,8 +675,9 @@ void ClassDB::get_integer_constant_list(const StringName &p_class, List<String> while (type) { #ifdef DEBUG_METHODS_ENABLED - for (List<StringName>::Element *E = type->constant_order.front(); E; E = E->next()) + for (List<StringName>::Element *E = type->constant_order.front(); E; E = E->next()) { p_constants->push_back(E->get()); + } #else const StringName *K = nullptr; @@ -674,8 +686,9 @@ void ClassDB::get_integer_constant_list(const StringName &p_class, List<String> } #endif - if (p_no_inheritance) + if (p_no_inheritance) { break; + } type = type->inherits_ptr; } @@ -689,16 +702,18 @@ int ClassDB::get_integer_constant(const StringName &p_class, const StringName &p while (type) { int *constant = type->constant_map.getptr(p_name); if (constant) { - if (p_success) + if (p_success) { *p_success = true; + } return *constant; } type = type->inherits_ptr; } - if (p_success) + if (p_success) { *p_success = false; + } return 0; } @@ -713,12 +728,14 @@ StringName ClassDB::get_integer_constant_enum(const StringName &p_class, const S while ((k = type->enum_map.next(k))) { List<StringName> &constants_list = type->enum_map.get(*k); const List<StringName>::Element *found = constants_list.find(p_name); - if (found) + if (found) { return *k; + } } - if (p_no_inheritance) + if (p_no_inheritance) { break; + } type = type->inherits_ptr; } @@ -737,8 +754,9 @@ void ClassDB::get_enum_list(const StringName &p_class, List<StringName> *p_enums p_enums->push_back(*k); } - if (p_no_inheritance) + if (p_no_inheritance) { break; + } type = type->inherits_ptr; } @@ -758,8 +776,9 @@ void ClassDB::get_enum_constants(const StringName &p_class, const StringName &p_ } } - if (p_no_inheritance) + if (p_no_inheritance) { break; + } type = type->inherits_ptr; } @@ -798,8 +817,9 @@ void ClassDB::get_signal_list(StringName p_class, List<MethodInfo> *p_signals, b p_signals->push_back(check->signal_map[*S]); } - if (p_no_inheritance) + if (p_no_inheritance) { return; + } check = check->inherits_ptr; } @@ -810,8 +830,9 @@ bool ClassDB::has_signal(StringName p_class, StringName p_signal) { ClassInfo *type = classes.getptr(p_class); ClassInfo *check = type; while (check) { - if (check->signal_map.has(p_signal)) + if (check->signal_map.has(p_signal)) { return true; + } check = check->inherits_ptr; } @@ -931,8 +952,9 @@ void ClassDB::get_property_list(StringName p_class, List<PropertyInfo> *p_list, } } - if (p_no_inheritance) + if (p_no_inheritance) { return; + } check = check->inherits_ptr; } } @@ -944,8 +966,9 @@ bool ClassDB::set_property(Object *p_object, const StringName &p_property, const const PropertySetGet *psg = check->property_setget.getptr(p_property); if (psg) { if (!psg->setter) { - if (r_valid) + if (r_valid) { *r_valid = false; + } return true; //return true but do nothing } @@ -970,8 +993,9 @@ bool ClassDB::set_property(Object *p_object, const StringName &p_property, const } } - if (r_valid) + if (r_valid) { *r_valid = ce.error == Callable::CallError::CALL_OK; + } return true; } @@ -988,8 +1012,9 @@ bool ClassDB::get_property(Object *p_object, const StringName &p_property, Varia while (check) { const PropertySetGet *psg = check->property_setget.getptr(p_property); if (psg) { - if (!psg->getter) + if (!psg->getter) { return true; //return true but do nothing + } if (psg->index >= 0) { Variant index = psg->index; @@ -1036,16 +1061,18 @@ int ClassDB::get_property_index(const StringName &p_class, const StringName &p_p while (check) { const PropertySetGet *psg = check->property_setget.getptr(p_property); if (psg) { - if (r_is_valid) + if (r_is_valid) { *r_is_valid = true; + } return psg->index; } check = check->inherits_ptr; } - if (r_is_valid) + if (r_is_valid) { *r_is_valid = false; + } return -1; } @@ -1056,16 +1083,18 @@ Variant::Type ClassDB::get_property_type(const StringName &p_class, const String while (check) { const PropertySetGet *psg = check->property_setget.getptr(p_property); if (psg) { - if (r_is_valid) + if (r_is_valid) { *r_is_valid = true; + } return psg->type; } check = check->inherits_ptr; } - if (r_is_valid) + if (r_is_valid) { *r_is_valid = false; + } return Variant::NIL; } @@ -1104,11 +1133,13 @@ bool ClassDB::has_property(const StringName &p_class, const StringName &p_proper ClassInfo *type = classes.getptr(p_class); ClassInfo *check = type; while (check) { - if (check->property_setget.has(p_property)) + if (check->property_setget.has(p_property)) { return true; + } - if (p_no_inheritance) + if (p_no_inheritance) { break; + } check = check->inherits_ptr; } @@ -1128,10 +1159,12 @@ bool ClassDB::has_method(StringName p_class, StringName p_method, bool p_no_inhe ClassInfo *type = classes.getptr(p_class); ClassInfo *check = type; while (check) { - if (check->method_map.has(p_method)) + if (check->method_map.has(p_method)) { return true; - if (p_no_inheritance) + } + if (p_no_inheritance) { return false; + } check = check->inherits_ptr; } @@ -1202,8 +1235,9 @@ void ClassDB::add_virtual_method(const StringName &p_class, const MethodInfo &p_ #ifdef DEBUG_METHODS_ENABLED MethodInfo mi = p_method; - if (p_virtual) + if (p_virtual) { mi.flags |= METHOD_FLAG_VIRTUAL; + } classes[p_class].virtual_methods.push_back(mi); #endif @@ -1221,8 +1255,9 @@ void ClassDB::get_virtual_methods(const StringName &p_class, List<MethodInfo> *p p_methods->push_back(E->get()); } - if (p_no_inheritance) + if (p_no_inheritance) { return; + } check = check->inherits_ptr; } @@ -1268,8 +1303,9 @@ StringName ClassDB::get_category(const StringName &p_node) { } void ClassDB::add_resource_base_extension(const StringName &p_extension, const StringName &p_class) { - if (resource_base_extensions.has(p_extension)) + if (resource_base_extensions.has(p_extension)) { return; + } resource_base_extensions[p_extension] = p_class; } @@ -1287,8 +1323,9 @@ void ClassDB::get_extensions_for_type(const StringName &p_class, List<String> *p while ((K = resource_base_extensions.next(K))) { StringName cmp = resource_base_extensions[*K]; - if (is_parent_class(p_class, cmp) || is_parent_class(cmp, p_class)) + if (is_parent_class(p_class, cmp) || is_parent_class(cmp, p_class)) { p_extensions->push_back(*K); + } } } @@ -1333,19 +1370,22 @@ Variant ClassDB::class_get_default_property_value(const StringName &p_class, con } if (!default_values.has(p_class)) { - if (r_valid != nullptr) + if (r_valid != nullptr) { *r_valid = false; + } return Variant(); } if (!default_values[p_class].has(p_property)) { - if (r_valid != nullptr) + if (r_valid != nullptr) { *r_valid = false; + } return Variant(); } - if (r_valid != nullptr) + if (r_valid != nullptr) { *r_valid = true; + } return default_values[p_class][p_property]; } diff --git a/core/color.cpp b/core/color.cpp index 4bee14f3ba..fa3f6475d4 100644 --- a/core/color.cpp +++ b/core/color.cpp @@ -115,20 +115,23 @@ float Color::get_h() const { float delta = max - min; - if (delta == 0) + if (delta == 0) { return 0; + } float h; - if (r == max) + if (r == max) { h = (g - b) / delta; // between yellow & magenta - else if (g == max) + } else if (g == max) { h = 2 + (b - r) / delta; // between cyan & yellow - else + } else { h = 4 + (r - g) / delta; // between magenta & cyan + } h /= 6.0; - if (h < 0) + if (h < 0) { h += 1.0; + } return h; } @@ -277,10 +280,11 @@ static float _parse_col(const String &p_str, int p_ofs) { return -1; } - if (i == 0) + if (i == 0) { ig += v * 16; - else + } else { ig += v; + } } return ig; @@ -300,10 +304,12 @@ Color Color::contrasted() const { Color Color::html(const String &p_color) { String color = p_color; - if (color.length() == 0) + if (color.length() == 0) { return Color(); - if (color[0] == '#') + } + if (color[0] == '#') { color = color.substr(1, color.length() - 1); + } if (color.length() == 3 || color.length() == 4) { String exp_color; for (int i = 0; i < color.length(); i++) { @@ -344,10 +350,12 @@ Color Color::html(const String &p_color) { bool Color::html_is_valid(const String &p_color) { String color = p_color; - if (color.length() == 0) + if (color.length() == 0) { return false; - if (color[0] == '#') + } + if (color[0] == '#') { color = color.substr(1, color.length() - 1); + } bool alpha = false; @@ -385,8 +393,9 @@ bool Color::html_is_valid(const String &p_color) { } Color Color::named(const String &p_name) { - if (_named_colors.empty()) + if (_named_colors.empty()) { _populate_named_colors(); // from color_names.inc + } String name = p_name; // Normalize name name = name.replace(" ", ""); @@ -409,10 +418,11 @@ String _to_hex(float p_val) { for (int i = 0; i < 2; i++) { CharType c[2] = { 0, 0 }; int lv = v & 0xF; - if (lv < 10) + if (lv < 10) { c[0] = '0' + lv; - else + } else { c[0] = 'a' + lv - 10; + } v >>= 4; String cs = (const CharType *)c; @@ -427,15 +437,17 @@ String Color::to_html(bool p_alpha) const { txt += _to_hex(r); txt += _to_hex(g); txt += _to_hex(b); - if (p_alpha) + if (p_alpha) { txt = _to_hex(a) + txt; + } return txt; } Color Color::from_hsv(float p_h, float p_s, float p_v, float p_a) const { p_h = Math::fmod(p_h * 360.0f, 360.0f); - if (p_h < 0.0) + if (p_h < 0.0) { p_h += 360.0f; + } const float h_ = p_h / 60.0f; const float c = p_v * p_s; diff --git a/core/color.h b/core/color.h index 10d49f3cad..258965fd16 100644 --- a/core/color.h +++ b/core/color.h @@ -223,12 +223,15 @@ bool Color::operator<(const Color &p_color) const { if (g == p_color.g) { if (b == p_color.b) { return (a < p_color.a); - } else + } else { return (b < p_color.b); - } else + } + } else { return g < p_color.g; - } else + } + } else { return r < p_color.r; + } } #endif // COLOR_H diff --git a/core/color_names.inc b/core/color_names.inc index f249ee9868..2b50d88b02 100644 --- a/core/color_names.inc +++ b/core/color_names.inc @@ -3,8 +3,9 @@ static Map<String, Color> _named_colors; static void _populate_named_colors() { - if (!_named_colors.empty()) + if (!_named_colors.empty()) { return; + } _named_colors.insert("aliceblue", Color(0.94, 0.97, 1.00)); _named_colors.insert("antiquewhite", Color(0.98, 0.92, 0.84)); _named_colors.insert("aqua", Color(0.00, 1.00, 1.00)); diff --git a/core/command_queue_mt.cpp b/core/command_queue_mt.cpp index d23a6425e3..ace210ca2c 100644 --- a/core/command_queue_mt.cpp +++ b/core/command_queue_mt.cpp @@ -94,12 +94,14 @@ tryagain: } CommandQueueMT::CommandQueueMT(bool p_sync) { - if (p_sync) + if (p_sync) { sync = memnew(Semaphore); + } } CommandQueueMT::~CommandQueueMT() { - if (sync) + if (sync) { memdelete(sync); + } memfree(command_mem); } diff --git a/core/command_queue_mt.h b/core/command_queue_mt.h index d40005fb12..d7a6a5bc43 100644 --- a/core/command_queue_mt.h +++ b/core/command_queue_mt.h @@ -413,14 +413,16 @@ class CommandQueueMT { } bool flush_one(bool p_lock = true) { - if (p_lock) + if (p_lock) { lock(); + } tryagain: // tried to read an empty queue if (read_ptr == write_ptr) { - if (p_lock) + if (p_lock) { unlock(); + } return false; } @@ -439,18 +441,21 @@ class CommandQueueMT { read_ptr += size; - if (p_lock) + if (p_lock) { unlock(); + } cmd->call(); - if (p_lock) + if (p_lock) { lock(); + } cmd->post(); cmd->~CommandBase(); *(uint32_t *)&command_mem[size_ptr] &= ~1; - if (p_lock) + if (p_lock) { unlock(); + } return true; } @@ -482,8 +487,8 @@ public: void flush_all() { //ERR_FAIL_COND(sync); lock(); - while (flush_one(false)) - ; + while (flush_one(false)) { + } unlock(); } diff --git a/core/compressed_translation.cpp b/core/compressed_translation.cpp index dd46e23505..a66997aa52 100644 --- a/core/compressed_translation.cpp +++ b/core/compressed_translation.cpp @@ -109,8 +109,9 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) { const Vector<Pair<int, CharString>> &b = buckets[i]; Map<uint32_t, int> &t = table.write[i]; - if (b.size() == 0) + if (b.size() == 0) { continue; + } int d = 1; int item = 0; @@ -189,22 +190,24 @@ bool PHashTranslation::_set(const StringName &p_name, const Variant &p_value) { strings = p_value; } else if (name == "load_from") { generate(p_value); - } else + } else { return false; + } return true; } bool PHashTranslation::_get(const StringName &p_name, Variant &r_ret) const { String name = p_name.operator String(); - if (name == "hash_table") + if (name == "hash_table") { r_ret = hash_table; - else if (name == "bucket_table") + } else if (name == "bucket_table") { r_ret = bucket_table; - else if (name == "strings") + } else if (name == "strings") { r_ret = strings; - else + } else { return false; + } return true; } @@ -212,8 +215,9 @@ bool PHashTranslation::_get(const StringName &p_name, Variant &r_ret) const { StringName PHashTranslation::get_message(const StringName &p_src_text) const { int htsize = hash_table.size(); - if (htsize == 0) + if (htsize == 0) { return StringName(); + } CharString str = p_src_text.operator String().utf8(); uint32_t h = hash(0, str.get_data()); diff --git a/core/compressed_translation.h b/core/compressed_translation.h index 032e391729..3c029bdf58 100644 --- a/core/compressed_translation.h +++ b/core/compressed_translation.h @@ -61,8 +61,9 @@ class PHashTranslation : public Translation { }; _FORCE_INLINE_ uint32_t hash(uint32_t d, const char *p_str) const { - if (d == 0) + if (d == 0) { d = 0x1000193; + } while (*p_str) { d = (d * 0x1000193) ^ uint32_t(*p_str); p_str++; diff --git a/core/cowdata.h b/core/cowdata.h index 72a76d735d..3f72362e29 100644 --- a/core/cowdata.h +++ b/core/cowdata.h @@ -59,22 +59,25 @@ private: // internal helpers _FORCE_INLINE_ uint32_t *_get_refcount() const { - if (!_ptr) + if (!_ptr) { return nullptr; + } return reinterpret_cast<uint32_t *>(_ptr) - 2; } _FORCE_INLINE_ uint32_t *_get_size() const { - if (!_ptr) + if (!_ptr) { return nullptr; + } return reinterpret_cast<uint32_t *>(_ptr) - 1; } _FORCE_INLINE_ T *_get_data() const { - if (!_ptr) + if (!_ptr) { return nullptr; + } return reinterpret_cast<T *>(_ptr); } @@ -122,10 +125,11 @@ public: _FORCE_INLINE_ int size() const { uint32_t *size = (uint32_t *)_get_size(); - if (size) + if (size) { return *size; - else + } else { return 0; + } } _FORCE_INLINE_ void clear() { resize(0); } @@ -165,8 +169,9 @@ public: Error insert(int p_pos, const T &p_val) { ERR_FAIL_INDEX_V(p_pos, size() + 1, ERR_INVALID_PARAMETER); resize(size() + 1); - for (int i = (size() - 1); i > p_pos; i--) + for (int i = (size() - 1); i > p_pos; i--) { set(i, get(i - 1)); + } set(p_pos, p_val); return OK; @@ -181,13 +186,15 @@ public: template <class T> void CowData<T>::_unref(void *p_data) { - if (!p_data) + if (!p_data) { return; + } uint32_t *refc = _get_refcount(); - if (atomic_decrement(refc) > 0) + if (atomic_decrement(refc) > 0) { return; // still in use + } // clean up if (!__has_trivial_destructor(T)) { @@ -206,8 +213,9 @@ void CowData<T>::_unref(void *p_data) { template <class T> void CowData<T>::_copy_on_write() { - if (!_ptr) + if (!_ptr) { return; + } uint32_t *refc = _get_refcount(); @@ -243,8 +251,9 @@ Error CowData<T>::resize(int p_size) { int current_size = size(); - if (p_size == current_size) + if (p_size == current_size) { return OK; + } if (p_size == 0) { // wants to clean up @@ -337,14 +346,16 @@ void CowData<T>::_ref(const CowData *p_from) { template <class T> void CowData<T>::_ref(const CowData &p_from) { - if (_ptr == p_from._ptr) + if (_ptr == p_from._ptr) { return; // self assign, do nothing. + } _unref(_ptr); _ptr = nullptr; - if (!p_from._ptr) + if (!p_from._ptr) { return; //nothing to do + } if (atomic_conditional_increment(p_from._get_refcount()) > 0) { // could reference _ptr = p_from._ptr; diff --git a/core/crypto/crypto.cpp b/core/crypto/crypto.cpp index ed27d2ebc3..eb942c60c9 100644 --- a/core/crypto/crypto.cpp +++ b/core/crypto/crypto.cpp @@ -38,8 +38,9 @@ CryptoKey *(*CryptoKey::_create)() = nullptr; CryptoKey *CryptoKey::create() { - if (_create) + if (_create) { return _create(); + } return nullptr; } @@ -50,8 +51,9 @@ void CryptoKey::_bind_methods() { X509Certificate *(*X509Certificate::_create)() = nullptr; X509Certificate *X509Certificate::create() { - if (_create) + if (_create) { return _create(); + } return nullptr; } @@ -65,14 +67,16 @@ void X509Certificate::_bind_methods() { void (*Crypto::_load_default_certificates)(String p_path) = nullptr; Crypto *(*Crypto::_create)() = nullptr; Crypto *Crypto::create() { - if (_create) + if (_create) { return _create(); + } return memnew(Crypto); } void Crypto::load_default_certificates(String p_path) { - if (_load_default_certificates) + if (_load_default_certificates) { _load_default_certificates(p_path); + } } void Crypto::_bind_methods() { @@ -99,13 +103,15 @@ RES ResourceFormatLoaderCrypto::load(const String &p_path, const String &p_origi String el = p_path.get_extension().to_lower(); if (el == "crt") { X509Certificate *cert = X509Certificate::create(); - if (cert) + if (cert) { cert->load(p_path); + } return cert; } else if (el == "key") { CryptoKey *key = CryptoKey::create(); - if (key) + if (key) { key->load(p_path); + } return key; } return nullptr; @@ -122,10 +128,11 @@ bool ResourceFormatLoaderCrypto::handles_type(const String &p_type) const { String ResourceFormatLoaderCrypto::get_resource_type(const String &p_path) const { String el = p_path.get_extension().to_lower(); - if (el == "crt") + if (el == "crt") { return "X509Certificate"; - else if (el == "key") + } else if (el == "key") { return "CryptoKey"; + } return ""; } diff --git a/core/crypto/hashing_context.cpp b/core/crypto/hashing_context.cpp index 726dc615df..fb0dadfbab 100644 --- a/core/crypto/hashing_context.cpp +++ b/core/crypto/hashing_context.cpp @@ -128,6 +128,7 @@ void HashingContext::_bind_methods() { } HashingContext::~HashingContext() { - if (ctx != nullptr) + if (ctx != nullptr) { _delete_ctx(); + } } diff --git a/core/debugger/debugger_marshalls.cpp b/core/debugger/debugger_marshalls.cpp index 410c55129d..3f949b0ae1 100644 --- a/core/debugger/debugger_marshalls.cpp +++ b/core/debugger/debugger_marshalls.cpp @@ -228,8 +228,9 @@ Array DebuggerMarshalls::ScriptStackVariable::serialize(int max_size) { int len = 0; Error err = encode_variant(var, nullptr, len, true); - if (err != OK) + if (err != OK) { ERR_PRINT("Failed to encode variant."); + } if (len > max_size) { arr.push_back(Variant()); diff --git a/core/debugger/engine_debugger.cpp b/core/debugger/engine_debugger.cpp index 19ac87ad8b..5c9fb67de4 100644 --- a/core/debugger/engine_debugger.cpp +++ b/core/debugger/engine_debugger.cpp @@ -111,8 +111,9 @@ Error EngineDebugger::capture_parse(const StringName &p_name, const String &p_ms void EngineDebugger::line_poll() { // The purpose of this is just processing events every now and then when the script might get too busy otherwise bugs like infinite loops can't be caught - if (poll_every % 2048 == 0) + if (poll_every % 2048 == 0) { poll_events(false); + } poll_every++; } @@ -124,8 +125,9 @@ void EngineDebugger::iteration(uint64_t p_frame_ticks, uint64_t p_idle_ticks, ui // Notify tick to running profilers for (Map<StringName, Profiler>::Element *E = profilers.front(); E; E = E->next()) { Profiler &p = E->get(); - if (!p.active || !p.tick) + if (!p.active || !p.tick) { continue; + } p.tick(p.data, frame_time, idle_time, physics_time, physics_frame_time); } singleton->poll_events(true); @@ -133,8 +135,9 @@ void EngineDebugger::iteration(uint64_t p_frame_ticks, uint64_t p_idle_ticks, ui void EngineDebugger::initialize(const String &p_uri, bool p_skip_breakpoints, Vector<String> p_breakpoints) { register_uri_handler("tcp://", RemoteDebuggerPeerTCP::create); // TCP is the default protocol. Platforms/modules can add more. - if (p_uri.empty()) + if (p_uri.empty()) { return; + } if (p_uri == "local://") { singleton = memnew(LocalDebugger); script_debugger = memnew(ScriptDebugger); @@ -142,11 +145,13 @@ void EngineDebugger::initialize(const String &p_uri, bool p_skip_breakpoints, Ve OS::get_singleton()->initialize_debugging(); } else if (p_uri.find("://") >= 0) { const String proto = p_uri.substr(0, p_uri.find("://") + 3); - if (!protocols.has(proto)) + if (!protocols.has(proto)) { return; + } RemoteDebuggerPeer *peer = protocols[proto](p_uri); - if (!peer) + if (!peer) { return; + } singleton = memnew(RemoteDebugger(Ref<RemoteDebuggerPeer>(peer))); script_debugger = memnew(ScriptDebugger); // Notify editor of our pid (to allow focus stealing). @@ -154,8 +159,9 @@ void EngineDebugger::initialize(const String &p_uri, bool p_skip_breakpoints, Ve msg.push_back(OS::get_singleton()->get_process_id()); singleton->send_message("set_pid", msg); } - if (!singleton) + if (!singleton) { return; + } // There is a debugger, parse breakpoints. ScriptDebugger *singleton_script_debugger = singleton->get_script_debugger(); @@ -174,8 +180,9 @@ void EngineDebugger::deinitialize() { if (singleton) { // Stop all profilers for (Map<StringName, Profiler>::Element *E = profilers.front(); E; E = E->next()) { - if (E->get().active) + if (E->get().active) { singleton->profiler_enable(E->key(), false); + } } // Flush any remaining message @@ -192,8 +199,9 @@ void EngineDebugger::deinitialize() { } EngineDebugger::~EngineDebugger() { - if (script_debugger) + if (script_debugger) { memdelete(script_debugger); + } script_debugger = nullptr; singleton = nullptr; } diff --git a/core/debugger/local_debugger.cpp b/core/debugger/local_debugger.cpp index 9251b77f96..876be79418 100644 --- a/core/debugger/local_debugger.cpp +++ b/core/debugger/local_debugger.cpp @@ -69,17 +69,19 @@ struct LocalDebugger::ScriptsProfiler { void _print_frame_data(bool p_accumulated) { uint64_t diff = OS::get_singleton()->get_ticks_usec() - idle_accum; - if (!p_accumulated && diff < 1000000) //show every one second + if (!p_accumulated && diff < 1000000) { //show every one second return; + } idle_accum = OS::get_singleton()->get_ticks_usec(); int ofs = 0; for (int i = 0; i < ScriptServer::get_language_count(); i++) { - if (p_accumulated) + if (p_accumulated) { ofs += ScriptServer::get_language(i)->profiling_get_accumulated_data(&pinfo.write[ofs], pinfo.size() - ofs); - else + } else { ofs += ScriptServer::get_language(i)->profiling_get_frame_data(&pinfo.write[ofs], pinfo.size() - ofs); + } } SortArray<ScriptLanguage::ProfilingInfo, ProfileInfoSort> sort; @@ -141,9 +143,9 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { print_line("\nDebugger Break, Reason: '" + script_lang->debug_get_error() + "'"); print_line("*Frame " + itos(current_frame) + " - " + script_lang->debug_get_stack_level_source(current_frame) + ":" + itos(script_lang->debug_get_stack_level_line(current_frame)) + " in function '" + script_lang->debug_get_stack_level_function(current_frame) + "'"); print_line("Enter \"help\" for assistance."); - } else if (line == "c" || line == "continue") + } else if (line == "c" || line == "continue") { break; - else if (line == "bt" || line == "breakpoint") { + } else if (line == "bt" || line == "breakpoint") { for (int i = 0; i < total_frames; i++) { String cfi = (current_frame == i) ? "*" : " "; //current frame indicator print_line(cfi + "Frame " + itos(i) + " - " + script_lang->debug_get_stack_level_source(i) + ":" + itos(script_lang->debug_get_stack_level_line(i)) + " in function '" + script_lang->debug_get_stack_level_function(i) + "'"); @@ -257,8 +259,9 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { String source = breakpoint.first; int linenr = breakpoint.second; - if (source.empty()) + if (source.empty()) { continue; + } script_debugger->insert_breakpoint(linenr, source); @@ -282,8 +285,9 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { String source = breakpoint.first; int linenr = breakpoint.second; - if (source.empty()) + if (source.empty()) { continue; + } script_debugger->remove_breakpoint(linenr, source); @@ -377,6 +381,7 @@ LocalDebugger::LocalDebugger() { LocalDebugger::~LocalDebugger() { unregister_profiler("scripts"); - if (scripts_profiler) + if (scripts_profiler) { memdelete(scripts_profiler); + } } diff --git a/core/debugger/remote_debugger.cpp b/core/debugger/remote_debugger.cpp index ba195f2ab5..62f600c5e5 100644 --- a/core/debugger/remote_debugger.cpp +++ b/core/debugger/remote_debugger.cpp @@ -96,8 +96,9 @@ public: } void init_node(const ObjectID p_node) { - if (multiplayer_node_data.has(p_node)) + if (multiplayer_node_data.has(p_node)) { return; + } multiplayer_node_data.insert(p_node, DebuggerMarshalls::MultiplayerNodeInfo()); multiplayer_node_data[p_node].node = p_node; multiplayer_node_data[p_node].node_path = Object::cast_to<Node>(ObjectDB::get_instance(p_node))->get_path(); @@ -218,10 +219,11 @@ struct RemoteDebugger::ScriptsProfiler { void write_frame_data(Vector<FunctionInfo> &r_funcs, uint64_t &r_total, bool p_accumulated) { int ofs = 0; for (int i = 0; i < ScriptServer::get_language_count(); i++) { - if (p_accumulated) + if (p_accumulated) { ofs += ScriptServer::get_language(i)->profiling_get_accumulated_data(&info.write[ofs], info.size() - ofs); - else + } else { ofs += ScriptServer::get_language(i)->profiling_get_frame_data(&info.write[ofs], info.size() - ofs); + } } for (int i = 0; i < ofs; i++) { @@ -358,8 +360,9 @@ struct RemoteDebugger::VisualProfiler { void tick(float p_frame_time, float p_idle_time, float p_physics_time, float p_physics_frame_time) { Vector<RS::FrameProfileArea> profile_areas = RS::get_singleton()->get_frame_profile(); DebuggerMarshalls::VisualProfilerFrame frame; - if (!profile_areas.size()) + if (!profile_areas.size()) { return; + } frame.frame_number = RS::get_singleton()->get_frame_profile_frame(); frame.areas.append_array(profile_areas); @@ -374,12 +377,14 @@ struct RemoteDebugger::PerformanceProfiler { void toggle(bool p_enable, const Array &p_opts) {} void add(const Array &p_data) {} void tick(float p_frame_time, float p_idle_time, float p_physics_time, float p_physics_frame_time) { - if (!performance) + if (!performance) { return; + } uint64_t pt = OS::get_singleton()->get_ticks_msec(); - if (pt - last_perf_time < 1000) + if (pt - last_perf_time < 1000) { return; + } last_perf_time = pt; int max = performance->get("MONITOR_MAX"); Array arr; @@ -423,25 +428,29 @@ Error RemoteDebugger::_put_msg(String p_message, Array p_data) { msg.push_back(p_message); msg.push_back(p_data); Error err = peer->put_message(msg); - if (err != OK) + if (err != OK) { n_messages_dropped++; + } return err; } void RemoteDebugger::_err_handler(void *p_this, const char *p_func, const char *p_file, int p_line, const char *p_err, const char *p_descr, ErrorHandlerType p_type) { - if (p_type == ERR_HANDLER_SCRIPT) + if (p_type == ERR_HANDLER_SCRIPT) { return; //ignore script errors, those go through debugger + } RemoteDebugger *rd = (RemoteDebugger *)p_this; - if (rd->flushing && Thread::get_caller_id() == rd->flush_thread) // Can't handle recursive errors during flush. + if (rd->flushing && Thread::get_caller_id() == rd->flush_thread) { // Can't handle recursive errors during flush. return; + } Vector<ScriptLanguage::StackInfo> si; for (int i = 0; i < ScriptServer::get_language_count(); i++) { si = ScriptServer::get_language(i)->debug_get_current_stack_info(); - if (si.size()) + if (si.size()) { break; + } } // send_error will lock internally. @@ -451,14 +460,16 @@ void RemoteDebugger::_err_handler(void *p_this, const char *p_func, const char * void RemoteDebugger::_print_handler(void *p_this, const String &p_string, bool p_error) { RemoteDebugger *rd = (RemoteDebugger *)p_this; - if (rd->flushing && Thread::get_caller_id() == rd->flush_thread) // Can't handle recursive prints during flush. + if (rd->flushing && Thread::get_caller_id() == rd->flush_thread) { // Can't handle recursive prints during flush. return; + } String s = p_string; int allowed_chars = MIN(MAX(rd->max_chars_per_second - rd->char_count, 0), s.length()); - if (allowed_chars == 0 && s.length() > 0) + if (allowed_chars == 0 && s.length() > 0) { return; + } if (allowed_chars < s.length()) { s = s.substr(0, allowed_chars); @@ -469,8 +480,9 @@ void RemoteDebugger::_print_handler(void *p_this, const String &p_string, bool p rd->char_count += allowed_chars; bool overflowed = rd->char_count >= rd->max_chars_per_second; if (rd->is_peer_connected()) { - if (overflowed) + if (overflowed) { s += "[...]"; + } OutputString output_string; output_string.message = s; @@ -502,13 +514,15 @@ void RemoteDebugger::flush_output() { flush_thread = Thread::get_caller_id(); flushing = true; MutexLock lock(mutex); - if (!is_peer_connected()) + if (!is_peer_connected()) { return; + } if (n_messages_dropped > 0) { ErrorMessage err_msg = _create_overflow_error("TOO_MANY_MESSAGES", "Too many messages! " + String::num_int64(n_messages_dropped) + " messages were dropped. Profiling might misbheave, try raising 'network/limits/debugger/max_queued_messages' in project setting."); - if (_put_msg("error", err_msg.serialize()) == OK) + if (_put_msg("error", err_msg.serialize()) == OK) { n_messages_dropped = 0; + } } if (output_strings.size()) { @@ -585,8 +599,9 @@ void RemoteDebugger::send_error(const String &p_func, const String &p_file, int oe.msec = time % 1000; oe.callstack.append_array(script_debugger->get_error_stack_info()); - if (flushing && Thread::get_caller_id() == flush_thread) // Can't handle recursive errors during flush. + if (flushing && Thread::get_caller_id() == flush_thread) { // Can't handle recursive errors during flush. return; + } MutexLock lock(mutex); @@ -644,8 +659,9 @@ Error RemoteDebugger::_try_capture(const String &p_msg, const Array &p_data, boo return OK; } const String cap = p_msg.substr(0, idx); - if (!has_capture(cap)) + if (!has_capture(cap)) { return ERR_UNAVAILABLE; // Unknown message... + } const String msg = p_msg.substr(idx + 1); return capture_parse(cap, msg, p_data, r_captured); } @@ -654,13 +670,15 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { //this function is called when there is a debugger break (bug on script) //or when execution is paused from editor - if (script_debugger->is_skipping_breakpoints() && !p_is_error_breakpoint) + if (script_debugger->is_skipping_breakpoints() && !p_is_error_breakpoint) { return; + } ERR_FAIL_COND_MSG(!is_peer_connected(), "Script Debugger failed to connect, but being used anyway."); - if (!peer->can_block()) + if (!peer->can_block()) { return; // Peer does not support blocking IO. We could at least send the error though. + } ScriptLanguage *script_lang = script_debugger->get_break_language(); const String error_str = script_lang ? script_lang->debug_get_error() : ""; @@ -672,8 +690,9 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { servers_profiler->skip_profile_frame = true; // Avoid frame time spike in debug. Input::MouseMode mouse_mode = Input::get_singleton()->get_mouse_mode(); - if (mouse_mode != Input::MOUSE_MODE_VISIBLE) + if (mouse_mode != Input::MOUSE_MODE_VISIBLE) { Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE); + } uint64_t loop_begin_usec = 0; uint64_t loop_time_sec = 0; @@ -761,10 +780,11 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { } else if (command == "breakpoint") { ERR_FAIL_COND(data.size() < 3); bool set = data[2]; - if (set) + if (set) { script_debugger->insert_breakpoint(data[1], data[0]); - else + } else { script_debugger->remove_breakpoint(data[1], data[0]); + } } else if (command == "set_skip_breakpoints") { ERR_FAIL_COND(data.size() < 1); @@ -772,8 +792,9 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { } else { bool captured = false; ERR_CONTINUE(_try_capture(command, data, captured) != OK); - if (!captured) + if (!captured) { WARN_PRINT("Unknown message received from debugger: " + command); + } } } else { OS::get_singleton()->delay_usec(10000); @@ -790,13 +811,15 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { send_message("debug_exit", Array()); - if (mouse_mode != Input::MOUSE_MODE_VISIBLE) + if (mouse_mode != Input::MOUSE_MODE_VISIBLE) { Input::get_singleton()->set_mouse_mode(mouse_mode); + } } void RemoteDebugger::poll_events(bool p_is_idle) { - if (peer.is_null()) + if (peer.is_null()) { return; + } flush_output(); peer->poll(); @@ -816,8 +839,9 @@ void RemoteDebugger::poll_events(bool p_is_idle) { } const String cap = cmd.substr(0, idx); - if (!has_capture(cap)) + if (!has_capture(cap)) { continue; // Unknown message... + } const String msg = cmd.substr(idx + 1); capture_parse(cap, msg, arr[1], parsed); @@ -840,10 +864,11 @@ Error RemoteDebugger::_core_capture(const String &p_cmd, const Array &p_data, bo } else if (p_cmd == "breakpoint") { ERR_FAIL_COND_V(p_data.size() < 3, ERR_INVALID_DATA); bool set = p_data[2]; - if (set) + if (set) { script_debugger->insert_breakpoint(p_data[1], p_data[0]); - else + } else { script_debugger->remove_breakpoint(p_data[1], p_data[0]); + } } else if (p_cmd == "set_skip_breakpoints") { ERR_FAIL_COND_V(p_data.size() < 1, ERR_INVALID_DATA); @@ -934,6 +959,7 @@ RemoteDebugger::~RemoteDebugger() { memdelete(servers_profiler); memdelete(network_profiler); memdelete(visual_profiler); - if (performance_profiler) + if (performance_profiler) { memdelete(performance_profiler); + } } diff --git a/core/debugger/remote_debugger_peer.cpp b/core/debugger/remote_debugger_peer.cpp index 1218bc5060..fd1eee0654 100644 --- a/core/debugger/remote_debugger_peer.cpp +++ b/core/debugger/remote_debugger_peer.cpp @@ -52,8 +52,9 @@ Array RemoteDebuggerPeerTCP::get_message() { Error RemoteDebuggerPeerTCP::put_message(const Array &p_arr) { MutexLock lock(mutex); - if (out_queue.size() >= max_queued_messages) + if (out_queue.size() >= max_queued_messages) { return ERR_OUT_OF_MEMORY; + } out_queue.push_back(p_arr); return OK; @@ -99,8 +100,9 @@ void RemoteDebuggerPeerTCP::_write_out() { while (tcp_client->poll(NetSocket::POLL_TYPE_OUT) == OK) { uint8_t *buf = out_buf.ptrw(); if (out_left <= 0) { - if (out_queue.size() == 0) + if (out_queue.size() == 0) { break; // Nothing left to send + } mutex.lock(); Variant var = out_queue[0]; out_queue.pop_front(); @@ -155,10 +157,11 @@ void RemoteDebuggerPeerTCP::_read_in() { Error RemoteDebuggerPeerTCP::connect_to_host(const String &p_host, uint16_t p_port) { IP_Address ip; - if (p_host.is_valid_ip_address()) + if (p_host.is_valid_ip_address()) { ip = p_host; - else + } else { ip = IP::get_singleton()->resolve_hostname(p_host); + } int port = p_port; @@ -194,8 +197,9 @@ void RemoteDebuggerPeerTCP::_thread_func(void *p_ud) { RemoteDebuggerPeerTCP *peer = (RemoteDebuggerPeerTCP *)p_ud; while (peer->running && peer->is_peer_connected()) { peer->_poll(); - if (!peer->is_peer_connected()) + if (!peer->is_peer_connected()) { break; + } peer->tcp_client->poll(NetSocket::POLL_TYPE_IN_OUT, 1); } } diff --git a/core/debugger/script_debugger.cpp b/core/debugger/script_debugger.cpp index 179745b11e..0cd3238efb 100644 --- a/core/debugger/script_debugger.cpp +++ b/core/debugger/script_debugger.cpp @@ -49,23 +49,27 @@ int ScriptDebugger::get_depth() const { } void ScriptDebugger::insert_breakpoint(int p_line, const StringName &p_source) { - if (!breakpoints.has(p_line)) + if (!breakpoints.has(p_line)) { breakpoints[p_line] = Set<StringName>(); + } breakpoints[p_line].insert(p_source); } void ScriptDebugger::remove_breakpoint(int p_line, const StringName &p_source) { - if (!breakpoints.has(p_line)) + if (!breakpoints.has(p_line)) { return; + } breakpoints[p_line].erase(p_source); - if (breakpoints[p_line].size() == 0) + if (breakpoints[p_line].size() == 0) { breakpoints.erase(p_line); + } } bool ScriptDebugger::is_breakpoint(int p_line, const StringName &p_source) const { - if (!breakpoints.has(p_line)) + if (!breakpoints.has(p_line)) { return false; + } return breakpoints[p_line].has(p_source); } diff --git a/core/dictionary.cpp b/core/dictionary.cpp index 0ef26cfc62..052e1bdae1 100644 --- a/core/dictionary.cpp +++ b/core/dictionary.cpp @@ -40,8 +40,9 @@ struct DictionaryPrivate { }; void Dictionary::get_key_list(List<Variant> *p_keys) const { - if (_p->variant_map.empty()) + if (_p->variant_map.empty()) { return; + } for (OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.front(); E; E = E.next()) { p_keys->push_back(E.key()); @@ -83,24 +84,27 @@ const Variant &Dictionary::operator[](const Variant &p_key) const { const Variant *Dictionary::getptr(const Variant &p_key) const { OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::ConstElement E = ((const OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator> *)&_p->variant_map)->find(p_key); - if (!E) + if (!E) { return nullptr; + } return &E.get(); } Variant *Dictionary::getptr(const Variant &p_key) { OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.find(p_key); - if (!E) + if (!E) { return nullptr; + } return &E.get(); } Variant Dictionary::get_valid(const Variant &p_key) const { OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::ConstElement E = ((const OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator> *)&_p->variant_map)->find(p_key); - if (!E) + if (!E) { return Variant(); + } return E.get(); } @@ -148,16 +152,18 @@ bool Dictionary::operator!=(const Dictionary &p_dictionary) const { void Dictionary::_ref(const Dictionary &p_from) const { //make a copy first (thread safe) - if (!p_from._p->refcount.ref()) + if (!p_from._p->refcount.ref()) { return; // couldn't copy + } //if this is the same, unreference the other one if (p_from._p == _p) { _p->refcount.unref(); return; } - if (_p) + if (_p) { _unref(); + } _p = p_from._p; } @@ -186,8 +192,9 @@ uint32_t Dictionary::hash() const { Array Dictionary::keys() const { Array varr; - if (_p->variant_map.empty()) + if (_p->variant_map.empty()) { return varr; + } varr.resize(size()); @@ -202,8 +209,9 @@ Array Dictionary::keys() const { Array Dictionary::values() const { Array varr; - if (_p->variant_map.empty()) + if (_p->variant_map.empty()) { return varr; + } varr.resize(size()); @@ -219,14 +227,16 @@ Array Dictionary::values() const { const Variant *Dictionary::next(const Variant *p_key) const { if (p_key == nullptr) { // caller wants to get the first element - if (_p->variant_map.front()) + if (_p->variant_map.front()) { return &_p->variant_map.front().key(); + } return nullptr; } OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.find(*p_key); - if (E && E.next()) + if (E && E.next()) { return &E.next().key(); + } return nullptr; } diff --git a/core/engine.cpp b/core/engine.cpp index 25eac27921..43c5766431 100644 --- a/core/engine.cpp +++ b/core/engine.cpp @@ -46,8 +46,9 @@ int Engine::get_iterations_per_second() const { } void Engine::set_physics_jitter_fix(float p_threshold) { - if (p_threshold < 0) + if (p_threshold < 0) { p_threshold = 0; + } physics_jitter_fix = p_threshold; } @@ -97,8 +98,9 @@ Dictionary Engine::get_version_info() const { dict["hash"] = hash.length() == 0 ? String("unknown") : hash; String stringver = String(dict["major"]) + "." + String(dict["minor"]); - if ((int)dict["patch"] != 0) + if ((int)dict["patch"] != 0) { stringver += "." + String(dict["patch"]); + } stringver += "-" + String(dict["status"]) + " (" + String(dict["build"]) + ")"; dict["string"] = stringver; @@ -193,8 +195,9 @@ bool Engine::has_singleton(const String &p_name) const { }; void Engine::get_singletons(List<Singleton> *p_singletons) { - for (List<Singleton>::Element *E = singletons.front(); E; E = E->next()) + for (List<Singleton>::Element *E = singletons.front(); E; E = E->next()) { p_singletons->push_back(E->get()); + } } Engine *Engine::singleton = nullptr; diff --git a/core/error_macros.cpp b/core/error_macros.cpp index ff50c9786a..2fae939965 100644 --- a/core/error_macros.cpp +++ b/core/error_macros.cpp @@ -51,10 +51,11 @@ void remove_error_handler(ErrorHandlerList *p_handler) { while (l) { if (l == p_handler) { - if (prev) + if (prev) { prev->next = l->next; - else + } else { error_handler_list = l->next; + } break; } prev = l; diff --git a/core/func_ref.cpp b/core/func_ref.cpp index 9c0e1698c2..4427d94d2a 100644 --- a/core/func_ref.cpp +++ b/core/func_ref.cpp @@ -65,12 +65,14 @@ void FuncRef::set_function(const StringName &p_func) { } bool FuncRef::is_valid() const { - if (id.is_null()) + if (id.is_null()) { return false; + } Object *obj = ObjectDB::get_instance(id); - if (!obj) + if (!obj) { return false; + } return obj->has_method(function); } diff --git a/core/hash_map.h b/core/hash_map.h index a4bc811b67..78592f8d82 100644 --- a/core/hash_map.h +++ b/core/hash_map.h @@ -104,8 +104,9 @@ private: hash_table_power = MIN_HASH_TABLE_POWER; elements = 0; - for (int i = 0; i < (1 << MIN_HASH_TABLE_POWER); i++) + for (int i = 0; i < (1 << MIN_HASH_TABLE_POWER); i++) { hash_table[i] = nullptr; + } } void erase_hash_table() { @@ -136,12 +137,14 @@ private: new_hash_table_power--; } - if (new_hash_table_power < (int)MIN_HASH_TABLE_POWER) + if (new_hash_table_power < (int)MIN_HASH_TABLE_POWER) { new_hash_table_power = MIN_HASH_TABLE_POWER; + } } - if (new_hash_table_power == -1) + if (new_hash_table_power == -1) { return; + } Element **new_hash_table = memnew_arr(Element *, ((uint64_t)1 << new_hash_table_power)); ERR_FAIL_COND_MSG(!new_hash_table, "Out of memory."); @@ -205,13 +208,15 @@ private: } void copy_from(const HashMap &p_t) { - if (&p_t == this) + if (&p_t == this) { return; /* much less bother with that */ + } clear(); - if (!p_t.hash_table || p_t.hash_table_power == 0) + if (!p_t.hash_table || p_t.hash_table_power == 0) { return; /* not copying from empty table */ + } hash_table = memnew_arr(Element *, (uint64_t)1 << p_t.hash_table_power); hash_table_power = p_t.hash_table_power; @@ -243,17 +248,19 @@ public: Element *set(const Pair &p_pair) { Element *e = nullptr; - if (!hash_table) + if (!hash_table) { make_hash_table(); // if no table, make one - else + } else { e = const_cast<Element *>(get_element(p_pair.key)); + } /* if we made it up to here, the pair doesn't exist, create and assign */ if (!e) { e = create_element(p_pair.key); - if (!e) + if (!e) { return nullptr; + } check_hash_table(); // perform mantenience routine } @@ -289,25 +296,29 @@ public: */ _FORCE_INLINE_ TData *getptr(const TKey &p_key) { - if (unlikely(!hash_table)) + if (unlikely(!hash_table)) { return nullptr; + } Element *e = const_cast<Element *>(get_element(p_key)); - if (e) + if (e) { return &e->pair.data; + } return nullptr; } _FORCE_INLINE_ const TData *getptr(const TKey &p_key) const { - if (unlikely(!hash_table)) + if (unlikely(!hash_table)) { return nullptr; + } const Element *e = const_cast<Element *>(get_element(p_key)); - if (e) + if (e) { return &e->pair.data; + } return nullptr; } @@ -319,8 +330,9 @@ public: template <class C> _FORCE_INLINE_ TData *custom_getptr(C p_custom_key, uint32_t p_custom_hash) { - if (unlikely(!hash_table)) + if (unlikely(!hash_table)) { return nullptr; + } uint32_t hash = p_custom_hash; uint32_t index = hash & ((1 << hash_table_power) - 1); @@ -342,8 +354,9 @@ public: template <class C> _FORCE_INLINE_ const TData *custom_getptr(C p_custom_key, uint32_t p_custom_hash) const { - if (unlikely(!hash_table)) + if (unlikely(!hash_table)) { return nullptr; + } uint32_t hash = p_custom_hash; uint32_t index = hash & ((1 << hash_table_power) - 1); @@ -368,8 +381,9 @@ public: */ bool erase(const TKey &p_key) { - if (unlikely(!hash_table)) + if (unlikely(!hash_table)) { return false; + } uint32_t hash = Hasher::hash(p_key); uint32_t index = hash & ((1 << hash_table_power) - 1); @@ -389,10 +403,11 @@ public: memdelete(e); elements--; - if (elements == 0) + if (elements == 0) { erase_hash_table(); - else + } else { check_hash_table(); + } return true; } @@ -410,10 +425,11 @@ public: inline TData &operator[](const TKey &p_key) { //assignment Element *e = nullptr; - if (!hash_table) + if (!hash_table) { make_hash_table(); // if no table, make one - else + } else { e = const_cast<Element *>(get_element(p_key)); + } /* if we made it up to here, the pair doesn't exist, create */ if (!e) { @@ -441,8 +457,9 @@ public: * */ const TKey *next(const TKey *p_key) const { - if (unlikely(!hash_table)) + if (unlikely(!hash_table)) { return nullptr; + } if (!p_key) { /* get the first key */ @@ -508,8 +525,9 @@ public: } void get_key_value_ptr_array(const Pair **p_pairs) const { - if (unlikely(!hash_table)) + if (unlikely(!hash_table)) { return; + } for (int i = 0; i < (1 << hash_table_power); i++) { Element *e = hash_table[i]; while (e) { @@ -521,8 +539,9 @@ public: } void get_key_list(List<TKey> *p_keys) const { - if (unlikely(!hash_table)) + if (unlikely(!hash_table)) { return; + } for (int i = 0; i < (1 << hash_table_power); i++) { Element *e = hash_table[i]; while (e) { diff --git a/core/hashfuncs.h b/core/hashfuncs.h index ccecba5137..d984f6c524 100644 --- a/core/hashfuncs.h +++ b/core/hashfuncs.h @@ -53,8 +53,9 @@ static inline uint32_t hash_djb2(const char *p_cstr) { uint32_t hash = 5381; uint32_t c; - while ((c = *chr++)) + while ((c = *chr++)) { hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ + } return hash; } @@ -62,8 +63,9 @@ static inline uint32_t hash_djb2(const char *p_cstr) { static inline uint32_t hash_djb2_buffer(const uint8_t *p_buff, int p_len, uint32_t p_prev = 5381) { uint32_t hash = p_prev; - for (int i = 0; i < p_len; i++) + for (int i = 0; i < p_len; i++) { hash = ((hash << 5) + hash) + p_buff[i]; /* hash * 33 + c */ + } return hash; } @@ -90,12 +92,13 @@ static inline uint32_t hash_djb2_one_float(double p_in, uint32_t p_prev = 5381) } u; // Normalize +/- 0.0 and NaN values so they hash the same. - if (p_in == 0.0f) + if (p_in == 0.0f) { u.d = 0.0; - else if (Math::is_nan(p_in)) + } else if (Math::is_nan(p_in)) { u.d = Math_NAN; - else + } else { u.d = p_in; + } return ((p_prev << 5) + p_prev) + hash_one_uint64(u.i); } diff --git a/core/image.cpp b/core/image.cpp index 3fff93ed91..29be2ff5eb 100644 --- a/core/image.cpp +++ b/core/image.cpp @@ -244,12 +244,13 @@ void Image::get_format_min_pixel_size(Format p_format, int &r_w, int &r_h) { } int Image::get_format_pixel_rshift(Format p_format) { - if (p_format == FORMAT_DXT1 || p_format == FORMAT_RGTC_R || p_format == FORMAT_PVRTC4 || p_format == FORMAT_PVRTC4A || p_format == FORMAT_ETC || p_format == FORMAT_ETC2_R11 || p_format == FORMAT_ETC2_R11S || p_format == FORMAT_ETC2_RGB8 || p_format == FORMAT_ETC2_RGB8A1) + if (p_format == FORMAT_DXT1 || p_format == FORMAT_RGTC_R || p_format == FORMAT_PVRTC4 || p_format == FORMAT_PVRTC4A || p_format == FORMAT_ETC || p_format == FORMAT_ETC2_R11 || p_format == FORMAT_ETC2_R11S || p_format == FORMAT_ETC2_RGB8 || p_format == FORMAT_ETC2_RGB8A1) { return 1; - else if (p_format == FORMAT_PVRTC2 || p_format == FORMAT_PVRTC2A) + } else if (p_format == FORMAT_PVRTC2 || p_format == FORMAT_PVRTC2A) { return 2; - else + } else { return 0; + } } int Image::get_format_block_size(Format p_format) { @@ -380,10 +381,11 @@ bool Image::has_mipmaps() const { } int Image::get_mipmap_count() const { - if (mipmaps) + if (mipmaps) { return get_image_required_mipmaps(width, height, format); - else + } else { return 0; + } } //using template generates perfectly optimized code due to constant expression reduction and unused variable removal present in all compilers @@ -429,11 +431,13 @@ static void _convert(int p_width, int p_height, const uint8_t *p_src, uint8_t *p } void Image::convert(Format p_new_format) { - if (data.size() == 0) + if (data.size() == 0) { return; + } - if (p_new_format == format) + if (p_new_format == format) { return; + } if (format > FORMAT_RGBE9995 || p_new_format > FORMAT_RGBE9995) { ERR_FAIL_MSG("Cannot convert to <-> from compressed formats. Use compress() and decompress() instead."); @@ -561,8 +565,9 @@ void Image::convert(Format p_new_format) { _copy_internals_from(new_img); - if (gen_mipmaps) + if (gen_mipmaps) { generate_mipmaps(); + } } Image::Format Image::get_format() const { @@ -574,10 +579,11 @@ static double _bicubic_interp_kernel(double x) { double bc = 0; - if (x <= 1) + if (x <= 1) { bc = (1.5 * x - 2.5) * x * x + 1; - else if (x < 2) + } else if (x < 2) { bc = ((-0.5 * x + 2.5) * x - 4) * x + 2; + } return bc; } @@ -624,20 +630,24 @@ static void _scale_cubic(const uint8_t *__restrict p_src, uint8_t *__restrict p_ k1 = _bicubic_interp_kernel(dy - (double)n); oy2 = oy1 + n; - if (oy2 < 0) + if (oy2 < 0) { oy2 = 0; - if (oy2 > ymax) + } + if (oy2 > ymax) { oy2 = ymax; + } for (int m = -1; m < 3; m++) { // get X coefficient k2 = k1 * _bicubic_interp_kernel((double)m - dx); ox2 = ox1 + m; - if (ox2 < 0) + if (ox2 < 0) { ox2 = 0; - if (ox2 > xmax) + } + if (ox2 > xmax) { ox2 = xmax; + } // get pixel of original image const T *__restrict p = ((T *)p_src) + (oy2 * p_src_width + ox2) * CC; @@ -680,8 +690,9 @@ static void _scale_bilinear(const uint8_t *__restrict p_src, uint8_t *__restrict uint32_t src_yofs_up = src_yofs_up_fp >> FRAC_BITS; uint32_t src_yofs_down = (i + 1) * p_src_height / p_dst_height; - if (src_yofs_down >= p_src_height) + if (src_yofs_down >= p_src_height) { src_yofs_down = p_src_height - 1; + } //src_yofs_up*=CC; //src_yofs_down*=CC; @@ -694,8 +705,9 @@ static void _scale_bilinear(const uint8_t *__restrict p_src, uint8_t *__restrict uint32_t src_xofs_frac = src_xofs_left_fp & FRAC_MASK; uint32_t src_xofs_left = src_xofs_left_fp >> FRAC_BITS; uint32_t src_xofs_right = (j + 1) * p_src_width / p_dst_width; - if (src_xofs_right >= p_src_width) + if (src_xofs_right >= p_src_width) { src_xofs_right = p_src_width - 1; + } src_xofs_left *= CC; src_xofs_right *= CC; @@ -805,8 +817,9 @@ static void _scale_lanczos(const uint8_t *__restrict p_src, uint8_t *__restrict int32_t end_x = MIN(src_width - 1, int32_t(src_x) + half_kernel); // Create the kernel used by all the pixels of the column - for (int32_t target_x = start_x; target_x <= end_x; target_x++) + for (int32_t target_x = start_x; target_x <= end_x; target_x++) { kernel[target_x - start_x] = _lanczos((target_x + 0.5f - src_x) / scale_factor); + } for (int32_t buffer_y = 0; buffer_y < src_height; buffer_y++) { float pixel[CC] = { 0 }; @@ -819,17 +832,19 @@ static void _scale_lanczos(const uint8_t *__restrict p_src, uint8_t *__restrict const T *__restrict src_data = ((const T *)p_src) + (buffer_y * src_width + target_x) * CC; for (uint32_t i = 0; i < CC; i++) { - if (sizeof(T) == 2) //half float + if (sizeof(T) == 2) { //half float pixel[i] += Math::half_to_float(src_data[i]) * lanczos_val; - else + } else { pixel[i] += src_data[i] * lanczos_val; + } } } float *dst_data = ((float *)buffer) + (buffer_y * dst_width + buffer_x) * CC; - for (uint32_t i = 0; i < CC; i++) + for (uint32_t i = 0; i < CC; i++) { dst_data[i] = pixel[i] / weight; // Normalize the sum of all the samples + } } } @@ -850,8 +865,9 @@ static void _scale_lanczos(const uint8_t *__restrict p_src, uint8_t *__restrict int32_t start_y = MAX(0, int32_t(buffer_y) - half_kernel + 1); int32_t end_y = MIN(src_height - 1, int32_t(buffer_y) + half_kernel); - for (int32_t target_y = start_y; target_y <= end_y; target_y++) + for (int32_t target_y = start_y; target_y <= end_y; target_y++) { kernel[target_y - start_y] = _lanczos((target_y + 0.5f - buffer_y) / scale_factor); + } for (int32_t dst_x = 0; dst_x < dst_width; dst_x++) { float pixel[CC] = { 0 }; @@ -863,8 +879,9 @@ static void _scale_lanczos(const uint8_t *__restrict p_src, uint8_t *__restrict float *buffer_data = ((float *)buffer) + (target_y * dst_width + dst_x) * CC; - for (uint32_t i = 0; i < CC; i++) + for (uint32_t i = 0; i < CC; i++) { pixel[i] += buffer_data[i] * lanczos_val; + } } T *dst_data = ((T *)p_dst) + (dst_y * dst_width + dst_x) * CC; @@ -872,12 +889,13 @@ static void _scale_lanczos(const uint8_t *__restrict p_src, uint8_t *__restrict for (uint32_t i = 0; i < CC; i++) { pixel[i] /= weight; - if (sizeof(T) == 1) //byte + if (sizeof(T) == 1) { //byte dst_data[i] = CLAMP(Math::fast_ftoi(pixel[i]), 0, 255); - else if (sizeof(T) == 2) //half float + } else if (sizeof(T) == 2) { //half float dst_data[i] = Math::make_half_float(pixel[i]); - else // float + } else { // float dst_data[i] = pixel[i]; + } } } } @@ -910,8 +928,9 @@ void Image::resize_to_po2(bool p_square) { } if (w == width && h == height) { - if (!p_square || w == h) + if (!p_square || w == h) { return; //nothing to do + } } resize(w, h); @@ -929,8 +948,9 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) { ERR_FAIL_COND_MSG(p_height > MAX_HEIGHT, "Image height cannot be greater than " + itos(MAX_HEIGHT) + "."); ERR_FAIL_COND_MSG(p_width * p_height > MAX_PIXELS, "Too many pixels for image, maximum is " + itos(MAX_PIXELS)); - if (p_width == width && p_height == height) + if (p_width == width && p_height == height) { return; + } Image dst(p_width, p_height, false, format); @@ -1213,8 +1233,9 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) { dst._copy_internals_from(dst2); } - if (had_mipmaps) + if (had_mipmaps) { dst.generate_mipmaps(); + } _copy_internals_from(dst); } @@ -1233,8 +1254,9 @@ void Image::crop_from_point(int p_x, int p_y, int p_width, int p_height) { will most likely either not be used much, or in critical areas, for now it won't, because it's a waste of time. */ - if (p_width == width && p_height == height && p_x == 0 && p_y == 0) + if (p_width == width && p_height == height && p_x == 0 && p_y == 0) { return; + } uint8_t pdata[16]; //largest is 16 uint32_t pixel_size = get_format_pixel_size(format); @@ -1250,8 +1272,9 @@ void Image::crop_from_point(int p_x, int p_y, int p_width, int p_height) { for (int y = p_y; y < m_h; y++) { for (int x = p_x; x < m_w; x++) { if ((x >= width || y >= height)) { - for (uint32_t i = 0; i < pixel_size; i++) + for (uint32_t i = 0; i < pixel_size; i++) { pdata[i] = 0; + } } else { _get_pixelb(x, y, pixel_size, r, pdata); } @@ -1261,8 +1284,9 @@ void Image::crop_from_point(int p_x, int p_y, int p_width, int p_height) { } } - if (has_mipmaps()) + if (has_mipmaps()) { dst.generate_mipmaps(); + } _copy_internals_from(dst); } @@ -1362,15 +1386,17 @@ int Image::_get_dst_image_size(int p_width, int p_height, Format p_format, int & *r_mm_height = bh; } - if (p_mipmaps >= 0 && mm == p_mipmaps) + if (p_mipmaps >= 0 && mm == p_mipmaps) { break; + } if (p_mipmaps >= 0) { w = MAX(minw, w >> 1); h = MAX(minh, h >> 1); } else { - if (w == minw && h == minh) + if (w == minw && h == minh) { break; + } w = MAX(minw, w >> 1); h = MAX(minh, h >> 1); } @@ -1429,8 +1455,9 @@ void Image::expand_x2_hq2x() { Format current = format; - if (current != FORMAT_RGBA8) + if (current != FORMAT_RGBA8) { convert(FORMAT_RGBA8); + } Vector<uint8_t> dest; dest.resize(width * 2 * height * 2 * 4); @@ -1448,8 +1475,9 @@ void Image::expand_x2_hq2x() { height *= 2; data = dest; - if (current != FORMAT_RGBA8) + if (current != FORMAT_RGBA8) { convert(current); + } // FIXME: This is likely meant to use "used_mipmaps" as defined above, but if we do, // we end up with a regression: GH-22747 @@ -1609,17 +1637,19 @@ Error Image::generate_mipmaps(bool p_renormalize) { _generate_po2_mipmap<uint8_t, 2, false, Image::average_4_uint8, Image::renormalize_uint8>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h); break; case FORMAT_RGB8: - if (p_renormalize) + if (p_renormalize) { _generate_po2_mipmap<uint8_t, 3, true, Image::average_4_uint8, Image::renormalize_uint8>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h); - else + } else { _generate_po2_mipmap<uint8_t, 3, false, Image::average_4_uint8, Image::renormalize_uint8>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h); + } break; case FORMAT_RGBA8: - if (p_renormalize) + if (p_renormalize) { _generate_po2_mipmap<uint8_t, 4, true, Image::average_4_uint8, Image::renormalize_uint8>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h); - else + } else { _generate_po2_mipmap<uint8_t, 4, false, Image::average_4_uint8, Image::renormalize_uint8>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h); + } break; case FORMAT_RF: _generate_po2_mipmap<float, 1, false, Image::average_4_float, Image::renormalize_float>(reinterpret_cast<const float *>(&wp[prev_ofs]), reinterpret_cast<float *>(&wp[ofs]), prev_w, prev_h); @@ -1628,17 +1658,19 @@ Error Image::generate_mipmaps(bool p_renormalize) { _generate_po2_mipmap<float, 2, false, Image::average_4_float, Image::renormalize_float>(reinterpret_cast<const float *>(&wp[prev_ofs]), reinterpret_cast<float *>(&wp[ofs]), prev_w, prev_h); break; case FORMAT_RGBF: - if (p_renormalize) + if (p_renormalize) { _generate_po2_mipmap<float, 3, true, Image::average_4_float, Image::renormalize_float>(reinterpret_cast<const float *>(&wp[prev_ofs]), reinterpret_cast<float *>(&wp[ofs]), prev_w, prev_h); - else + } else { _generate_po2_mipmap<float, 3, false, Image::average_4_float, Image::renormalize_float>(reinterpret_cast<const float *>(&wp[prev_ofs]), reinterpret_cast<float *>(&wp[ofs]), prev_w, prev_h); + } break; case FORMAT_RGBAF: - if (p_renormalize) + if (p_renormalize) { _generate_po2_mipmap<float, 4, true, Image::average_4_float, Image::renormalize_float>(reinterpret_cast<const float *>(&wp[prev_ofs]), reinterpret_cast<float *>(&wp[ofs]), prev_w, prev_h); - else + } else { _generate_po2_mipmap<float, 4, false, Image::average_4_float, Image::renormalize_float>(reinterpret_cast<const float *>(&wp[prev_ofs]), reinterpret_cast<float *>(&wp[ofs]), prev_w, prev_h); + } break; case FORMAT_RH: @@ -1648,24 +1680,27 @@ Error Image::generate_mipmaps(bool p_renormalize) { _generate_po2_mipmap<uint16_t, 2, false, Image::average_4_half, Image::renormalize_half>(reinterpret_cast<const uint16_t *>(&wp[prev_ofs]), reinterpret_cast<uint16_t *>(&wp[ofs]), prev_w, prev_h); break; case FORMAT_RGBH: - if (p_renormalize) + if (p_renormalize) { _generate_po2_mipmap<uint16_t, 3, true, Image::average_4_half, Image::renormalize_half>(reinterpret_cast<const uint16_t *>(&wp[prev_ofs]), reinterpret_cast<uint16_t *>(&wp[ofs]), prev_w, prev_h); - else + } else { _generate_po2_mipmap<uint16_t, 3, false, Image::average_4_half, Image::renormalize_half>(reinterpret_cast<const uint16_t *>(&wp[prev_ofs]), reinterpret_cast<uint16_t *>(&wp[ofs]), prev_w, prev_h); + } break; case FORMAT_RGBAH: - if (p_renormalize) + if (p_renormalize) { _generate_po2_mipmap<uint16_t, 4, true, Image::average_4_half, Image::renormalize_half>(reinterpret_cast<const uint16_t *>(&wp[prev_ofs]), reinterpret_cast<uint16_t *>(&wp[ofs]), prev_w, prev_h); - else + } else { _generate_po2_mipmap<uint16_t, 4, false, Image::average_4_half, Image::renormalize_half>(reinterpret_cast<const uint16_t *>(&wp[prev_ofs]), reinterpret_cast<uint16_t *>(&wp[ofs]), prev_w, prev_h); + } break; case FORMAT_RGBE9995: - if (p_renormalize) + if (p_renormalize) { _generate_po2_mipmap<uint32_t, 1, true, Image::average_4_rgbe9995, Image::renormalize_rgbe9995>(reinterpret_cast<const uint32_t *>(&wp[prev_ofs]), reinterpret_cast<uint32_t *>(&wp[ofs]), prev_w, prev_h); - else + } else { _generate_po2_mipmap<uint32_t, 1, false, Image::average_4_rgbe9995, Image::renormalize_rgbe9995>(reinterpret_cast<const uint32_t *>(&wp[prev_ofs]), reinterpret_cast<uint32_t *>(&wp[ofs]), prev_w, prev_h); + } break; default: { @@ -1877,11 +1912,13 @@ Error Image::generate_mipmap_roughness(RoughnessChannel p_roughness_channel, con } void Image::clear_mipmaps() { - if (!mipmaps) + if (!mipmaps) { return; + } - if (empty()) + if (empty()) { return; + } int ofs, w, h; _get_mipmap_offset_and_size(1, ofs, w, h); @@ -1984,15 +2021,17 @@ void Image::create(const char **p_xpm) { } //skip spaces while (*line_ptr == ' ' || *line_ptr == '\t' || *line_ptr == 0) { - if (*line_ptr == 0) + if (*line_ptr == 0) { break; + } line_ptr++; } if (*line_ptr == 'c') { line_ptr++; while (*line_ptr == ' ' || *line_ptr == '\t' || *line_ptr == 0) { - if (*line_ptr == 0) + if (*line_ptr == 0) { break; + } line_ptr++; } @@ -2006,14 +2045,15 @@ void Image::create(const char **p_xpm) { for (int i = 0; i < 6; i++) { char v = line_ptr[i]; - if (v >= '0' && v <= '9') + if (v >= '0' && v <= '9') { v -= '0'; - else if (v >= 'A' && v <= 'F') + } else if (v >= 'A' && v <= 'F') { v = (v - 'A') + 10; - else if (v >= 'a' && v <= 'f') + } else if (v >= 'a' && v <= 'f') { v = (v - 'a') + 10; - else + } else { break; + } switch (i) { case 0: @@ -2057,8 +2097,9 @@ void Image::create(const char **p_xpm) { int y = line - colormap_size - 1; for (int x = 0; x < size_width; x++) { char pixelstr[6] = { 0, 0, 0, 0, 0, 0 }; - for (int i = 0; i < pixelchars; i++) + for (int i = 0; i < pixelchars; i++) { pixelstr[i] = line_ptr[x * pixelchars + i]; + } Color *colorptr = colormap.getptr(pixelstr); ERR_FAIL_COND(!colorptr); @@ -2069,8 +2110,9 @@ void Image::create(const char **p_xpm) { _put_pixelb(x, y, pixel_size, w, pixel); } - if (y == (size_height - 1)) + if (y == (size_height - 1)) { status = DONE; + } } break; default: { } @@ -2104,13 +2146,15 @@ void Image::create(const char **p_xpm) { bool Image::is_invisible() const { if (format == FORMAT_L8 || - format == FORMAT_RGB8 || format == FORMAT_RG8) + format == FORMAT_RGB8 || format == FORMAT_RG8) { return false; + } int len = data.size(); - if (len == 0) + if (len == 0) { return true; + } int w, h; _get_mipmap_offset_and_size(1, len, w, h); @@ -2150,8 +2194,9 @@ bool Image::is_invisible() const { Image::AlphaMode Image::detect_alpha() const { int len = data.size(); - if (len == 0) + if (len == 0) { return ALPHA_NONE; + } int w, h; _get_mipmap_offset_and_size(1, len, w, h); @@ -2185,12 +2230,13 @@ Image::AlphaMode Image::detect_alpha() const { } } - if (detected) + if (detected) { return ALPHA_BLEND; - else if (bit) + } else if (bit) { return ALPHA_BIT; - else + } else { return ALPHA_NONE; + } } Error Image::load(const String &p_path) { @@ -2203,8 +2249,9 @@ Error Image::load(const String &p_path) { } Error Image::save_png(const String &p_path) const { - if (save_png_func == nullptr) + if (save_png_func == nullptr) { return ERR_UNAVAILABLE; + } return save_png_func(p_path, Ref<Image>((Image *)this)); } @@ -2218,8 +2265,9 @@ Vector<uint8_t> Image::save_png_to_buffer() const { } Error Image::save_exr(const String &p_path, bool p_grayscale) const { - if (save_exr_func == nullptr) + if (save_exr_func == nullptr) { return ERR_UNAVAILABLE; + } return save_exr_func(p_path, Ref<Image>((Image *)this), p_grayscale); } @@ -2265,18 +2313,19 @@ bool Image::is_compressed() const { } Error Image::decompress() { - if (((format >= FORMAT_DXT1 && format <= FORMAT_RGTC_RG) || (format == FORMAT_DXT5_RA_AS_RG)) && _image_decompress_bc) + if (((format >= FORMAT_DXT1 && format <= FORMAT_RGTC_RG) || (format == FORMAT_DXT5_RA_AS_RG)) && _image_decompress_bc) { _image_decompress_bc(this); - else if (format >= FORMAT_BPTC_RGBA && format <= FORMAT_BPTC_RGBFU && _image_decompress_bptc) + } else if (format >= FORMAT_BPTC_RGBA && format <= FORMAT_BPTC_RGBFU && _image_decompress_bptc) { _image_decompress_bptc(this); - else if (format >= FORMAT_PVRTC2 && format <= FORMAT_PVRTC4A && _image_decompress_pvrtc) + } else if (format >= FORMAT_PVRTC2 && format <= FORMAT_PVRTC4A && _image_decompress_pvrtc) { _image_decompress_pvrtc(this); - else if (format == FORMAT_ETC && _image_decompress_etc1) + } else if (format == FORMAT_ETC && _image_decompress_etc1) { _image_decompress_etc1(this); - else if (format >= FORMAT_ETC2_R11 && format <= FORMAT_ETC2_RA_AS_RG && _image_decompress_etc2) + } else if (format >= FORMAT_ETC2_R11 && format <= FORMAT_ETC2_RA_AS_RG && _image_decompress_etc2) { _image_decompress_etc2(this); - else + } else { return ERR_UNAVAILABLE; + } return OK; } @@ -2343,35 +2392,43 @@ Image::Image(int p_width, int p_height, bool p_mipmaps, Format p_format, const V } Rect2 Image::get_used_rect() const { - if (format != FORMAT_LA8 && format != FORMAT_RGBA8 && format != FORMAT_RGBAF && format != FORMAT_RGBAH && format != FORMAT_RGBA4444 && format != FORMAT_RGB565) + if (format != FORMAT_LA8 && format != FORMAT_RGBA8 && format != FORMAT_RGBAF && format != FORMAT_RGBAH && format != FORMAT_RGBA4444 && format != FORMAT_RGB565) { return Rect2(Point2(), Size2(width, height)); + } int len = data.size(); - if (len == 0) + if (len == 0) { return Rect2(); + } int minx = 0xFFFFFF, miny = 0xFFFFFFF; int maxx = -1, maxy = -1; for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { - if (!(get_pixel(i, j).a > 0)) + if (!(get_pixel(i, j).a > 0)) { continue; - if (i > maxx) + } + if (i > maxx) { maxx = i; - if (j > maxy) + } + if (j > maxy) { maxy = j; - if (i < minx) + } + if (i < minx) { minx = i; - if (j < miny) + } + if (j < miny) { miny = j; + } } } - if (maxx == -1) + if (maxx == -1) { return Rect2(); - else + } else { return Rect2(minx, miny, maxx - minx + 1, maxy - miny + 1); + } } Ref<Image> Image::get_rect(const Rect2 &p_area) const { @@ -2391,13 +2448,16 @@ void Image::blit_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const Po Rect2i clipped_src_rect = Rect2i(0, 0, p_src->width, p_src->height).clip(p_src_rect); - if (p_dest.x < 0) + if (p_dest.x < 0) { clipped_src_rect.position.x = ABS(p_dest.x); - if (p_dest.y < 0) + } + if (p_dest.y < 0) { clipped_src_rect.position.y = ABS(p_dest.y); + } - if (clipped_src_rect.size.x <= 0 || clipped_src_rect.size.y <= 0) + if (clipped_src_rect.size.x <= 0 || clipped_src_rect.size.y <= 0) { return; + } Point2 src_underscan = Point2(MIN(0, p_src_rect.position.x), MIN(0, p_src_rect.position.y)); Rect2i dest_rect = Rect2i(0, 0, width, height).clip(Rect2i(p_dest - src_underscan, clipped_src_rect.size)); @@ -2443,13 +2503,16 @@ void Image::blit_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, co Rect2i clipped_src_rect = Rect2i(0, 0, p_src->width, p_src->height).clip(p_src_rect); - if (p_dest.x < 0) + if (p_dest.x < 0) { clipped_src_rect.position.x = ABS(p_dest.x); - if (p_dest.y < 0) + } + if (p_dest.y < 0) { clipped_src_rect.position.y = ABS(p_dest.y); + } - if (clipped_src_rect.size.x <= 0 || clipped_src_rect.size.y <= 0) + if (clipped_src_rect.size.x <= 0 || clipped_src_rect.size.y <= 0) { return; + } Point2 src_underscan = Point2(MIN(0, p_src_rect.position.x), MIN(0, p_src_rect.position.y)); Rect2i dest_rect = Rect2i(0, 0, width, height).clip(Rect2i(p_dest - src_underscan, clipped_src_rect.size)); @@ -2494,13 +2557,16 @@ void Image::blend_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const P Rect2i clipped_src_rect = Rect2i(0, 0, p_src->width, p_src->height).clip(p_src_rect); - if (p_dest.x < 0) + if (p_dest.x < 0) { clipped_src_rect.position.x = ABS(p_dest.x); - if (p_dest.y < 0) + } + if (p_dest.y < 0) { clipped_src_rect.position.y = ABS(p_dest.y); + } - if (clipped_src_rect.size.x <= 0 || clipped_src_rect.size.y <= 0) + if (clipped_src_rect.size.x <= 0 || clipped_src_rect.size.y <= 0) { return; + } Point2 src_underscan = Point2(MIN(0, p_src_rect.position.x), MIN(0, p_src_rect.position.y)); Rect2i dest_rect = Rect2i(0, 0, width, height).clip(Rect2i(p_dest - src_underscan, clipped_src_rect.size)); @@ -2541,13 +2607,16 @@ void Image::blend_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, c Rect2i clipped_src_rect = Rect2i(0, 0, p_src->width, p_src->height).clip(p_src_rect); - if (p_dest.x < 0) + if (p_dest.x < 0) { clipped_src_rect.position.x = ABS(p_dest.x); - if (p_dest.y < 0) + } + if (p_dest.y < 0) { clipped_src_rect.position.y = ABS(p_dest.y); + } - if (clipped_src_rect.size.x <= 0 || clipped_src_rect.size.y <= 0) + if (clipped_src_rect.size.x <= 0 || clipped_src_rect.size.y <= 0) { return; + } Point2 src_underscan = Point2(MIN(0, p_src_rect.position.x), MIN(0, p_src_rect.position.y)); Rect2i dest_rect = Rect2i(0, 0, width, height).clip(Rect2i(p_dest - src_underscan, clipped_src_rect.size)); @@ -2892,14 +2961,18 @@ Image::UsedChannels Image::detect_used_channels(CompressSource p_source) { for (int j = 0; j < height; j++) { Color col = get_pixel(i, j); - if (col.r > 0.001) + if (col.r > 0.001) { r = true; - if (col.g > 0.001) + } + if (col.g > 0.001) { g = true; - if (col.b > 0.001) + } + if (col.b > 0.001) { b = true; - if (col.a < 0.999) + } + if (col.a < 0.999) { a = true; + } if (col.r != col.b || col.r != col.g || col.b != col.g) { c = true; @@ -2909,18 +2982,19 @@ Image::UsedChannels Image::detect_used_channels(CompressSource p_source) { UsedChannels used_channels; - if (!c && !a) + if (!c && !a) { used_channels = USED_CHANNELS_L; - else if (!c && a) + } else if (!c && a) { used_channels = USED_CHANNELS_LA; - else if (r && !g && !b && !a) + } else if (r && !g && !b && !a) { used_channels = USED_CHANNELS_R; - else if (r && g && !b && !a) + } else if (r && g && !b && !a) { used_channels = USED_CHANNELS_RG; - else if (r && g && b && !a) + } else if (r && g && b && !a) { used_channels = USED_CHANNELS_RGB; - else + } else { used_channels = USED_CHANNELS_RGBA; + } if (p_source == COMPRESS_SOURCE_SRGB && (used_channels == USED_CHANNELS_R || used_channels == USED_CHANNELS_RG)) { //R and RG do not support SRGB @@ -3129,8 +3203,9 @@ void Image::normalmap_to_xy() { } Ref<Image> Image::rgbe_to_srgb() { - if (data.size() == 0) + if (data.size() == 0) { return Ref<Image>(); + } ERR_FAIL_COND_V(format != FORMAT_RGBE9995, Ref<Image>()); @@ -3193,13 +3268,15 @@ void Image::bumpmap_to_normalmap(float bump_scale) { for (int ty = 0; ty < height; ty++) { int py = ty + 1; - if (py >= height) + if (py >= height) { py -= height; + } for (int tx = 0; tx < width; tx++) { int px = tx + 1; - if (px >= width) + if (px >= width) { px -= width; + } float here = read_ptr[ty * width + tx]; float to_right = read_ptr[ty * width + px]; float above = read_ptr[py * width + tx]; @@ -3221,8 +3298,9 @@ void Image::bumpmap_to_normalmap(float bump_scale) { } void Image::srgb_to_linear() { - if (data.size() == 0) + if (data.size() == 0) { return; + } static const uint8_t srgb2lin[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 22, 22, 23, 23, 24, 24, 25, 26, 26, 27, 27, 28, 29, 29, 30, 31, 31, 32, 33, 33, 34, 35, 36, 36, 37, 38, 38, 39, 40, 41, 42, 42, 43, 44, 45, 46, 47, 47, 48, 49, 50, 51, 52, 53, 54, 55, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 70, 71, 72, 73, 74, 75, 76, 77, 78, 80, 81, 82, 83, 84, 85, 87, 88, 89, 90, 92, 93, 94, 95, 97, 98, 99, 101, 102, 103, 105, 106, 107, 109, 110, 112, 113, 114, 116, 117, 119, 120, 122, 123, 125, 126, 128, 129, 131, 132, 134, 135, 137, 139, 140, 142, 144, 145, 147, 148, 150, 152, 153, 155, 157, 159, 160, 162, 164, 166, 167, 169, 171, 173, 175, 176, 178, 180, 182, 184, 186, 188, 190, 192, 193, 195, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 218, 220, 222, 224, 226, 228, 230, 232, 235, 237, 239, 241, 243, 245, 248, 250, 252, 255 }; @@ -3251,11 +3329,13 @@ void Image::srgb_to_linear() { } void Image::premultiply_alpha() { - if (data.size() == 0) + if (data.size() == 0) { return; + } - if (format != FORMAT_RGBA8) + if (format != FORMAT_RGBA8) { return; //not needed + } uint8_t *data_ptr = data.ptrw(); @@ -3271,11 +3351,13 @@ void Image::premultiply_alpha() { } void Image::fix_alpha_edges() { - if (data.size() == 0) + if (data.size() == 0) { return; + } - if (format != FORMAT_RGBA8) + if (format != FORMAT_RGBA8) { return; //not needed + } Vector<uint8_t> dcopy = data; const uint8_t *srcptr = dcopy.ptr(); @@ -3291,8 +3373,9 @@ void Image::fix_alpha_edges() { const uint8_t *rptr = &srcptr[(i * width + j) * 4]; uint8_t *wptr = &data_ptr[(i * width + j) * 4]; - if (rptr[3] >= alpha_threshold) + if (rptr[3] >= alpha_threshold) { continue; + } int closest_dist = max_dist; uint8_t closest_color[3]; @@ -3307,13 +3390,15 @@ void Image::fix_alpha_edges() { int dy = i - k; int dx = j - l; int dist = dy * dy + dx * dx; - if (dist >= closest_dist) + if (dist >= closest_dist) { continue; + } const uint8_t *rp2 = &srcptr[(k * width + l) << 2]; - if (rp2[3] < alpha_threshold) + if (rp2[3] < alpha_threshold) { continue; + } closest_dist = dist; closest_color[0] = rp2[0]; diff --git a/core/input/input.cpp b/core/input/input.cpp index e81dfcf30f..dc1c207524 100644 --- a/core/input/input.cpp +++ b/core/input/input.cpp @@ -222,8 +222,9 @@ void Input::get_argument_options(const StringName &p_function, int p_idx, List<S for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { const PropertyInfo &pi = E->get(); - if (!pi.name.begins_with("input/")) + if (!pi.name.begins_with("input/")) { continue; + } String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length()); r_options->push_back(quote_style + name + quote_style); @@ -241,8 +242,9 @@ void Input::SpeedTrack::update(const Vector2 &p_delta_p) { accum += p_delta_p; accum_t += delta_t; - if (accum_t > max_ref_frame * 10) + if (accum_t > max_ref_frame * 10) { accum_t = max_ref_frame * 10; + } while (accum_t >= min_ref_frame) { float slice_t = min_ref_frame / accum_t; @@ -291,8 +293,9 @@ bool Input::is_action_pressed(const StringName &p_action) const { bool Input::is_action_just_pressed(const StringName &p_action) const { const Map<StringName, Action>::Element *E = action_state.find(p_action); - if (!E) + if (!E) { return false; + } if (Engine::get_singleton()->is_in_physics_frame()) { return E->get().pressed && E->get().physics_frame == Engine::get_singleton()->get_physics_frames(); @@ -303,8 +306,9 @@ bool Input::is_action_just_pressed(const StringName &p_action) const { bool Input::is_action_just_released(const StringName &p_action) const { const Map<StringName, Action>::Element *E = action_state.find(p_action); - if (!E) + if (!E) { return false; + } if (Engine::get_singleton()->is_in_physics_frame()) { return !E->get().pressed && E->get().physics_frame == Engine::get_singleton()->get_physics_frames(); @@ -315,8 +319,9 @@ bool Input::is_action_just_released(const StringName &p_action) const { float Input::get_action_strength(const StringName &p_action) const { const Map<StringName, Action>::Element *E = action_state.find(p_action); - if (!E) + if (!E) { return 0.0f; + } return E->get().strength; } @@ -446,10 +451,11 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em Ref<InputEventKey> k = p_event; if (k.is_valid() && !k->is_echo() && k->get_keycode() != 0) { - if (k->is_pressed()) + if (k->is_pressed()) { keys_pressed.insert(k->get_keycode()); - else + } else { keys_pressed.erase(k->get_keycode()); + } } Ref<InputEventMouseButton> mb = p_event; @@ -568,10 +574,11 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em if (jb.is_valid()) { int c = _combine_device(jb->get_button_index(), jb->get_device()); - if (jb->is_pressed()) + if (jb->is_pressed()) { joy_buttons_pressed.insert(c); - else + } else { joy_buttons_pressed.erase(c); + } } Ref<InputEventJoypadMotion> jm = p_event; @@ -603,8 +610,9 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em } } - if (event_dispatch_function) + if (event_dispatch_function) { event_dispatch_function(p_event); + } } void Input::set_joy_axis(int p_device, int p_axis, float p_value) { @@ -776,8 +784,9 @@ Input::CursorShape Input::get_default_cursor_shape() const { } void Input::set_default_cursor_shape(CursorShape p_shape) { - if (default_shape == p_shape) + if (default_shape == p_shape) { return; + } default_shape = p_shape; // The default shape is set in Viewport::_gui_input_event. To instantly @@ -794,8 +803,9 @@ Input::CursorShape Input::get_current_cursor_shape() const { } void Input::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) { - if (Engine::get_singleton()->is_editor_hint()) + if (Engine::get_singleton()->is_editor_hint()) { return; + } set_custom_mouse_cursor_func(p_cursor, p_shape, p_hotspot); } @@ -833,8 +843,9 @@ void Input::release_pressed_events() { _joy_axis.clear(); for (Map<StringName, Input::Action>::Element *E = action_state.front(); E; E = E->next()) { - if (E->get().pressed) + if (E->get().pressed) { action_release(E->key()); + } } } @@ -1064,8 +1075,9 @@ Input::JoyEvent Input::_get_mapped_axis_event(const JoyDeviceMapping &mapping, i const JoyBinding binding = mapping.bindings[i]; if (binding.inputType == TYPE_AXIS && binding.input.axis.axis == p_axis) { float value = p_value.value; - if (binding.input.axis.invert) + if (binding.input.axis.invert) { value = -value; + } if (binding.input.axis.range == FULL_AXIS || (binding.input.axis.range == POSITIVE_HALF_AXIS && value > 0) || (binding.input.axis.range == NEGATIVE_HALF_AXIS && value < 0)) { @@ -1152,16 +1164,18 @@ void Input::_get_mapped_hat_events(const JoyDeviceMapping &mapping, int p_hat, J JoyButtonList Input::_get_output_button(String output) { for (int i = 0; _joy_buttons[i]; i++) { - if (output == _joy_buttons[i]) + if (output == _joy_buttons[i]) { return JoyButtonList(i); + } } return JoyButtonList::JOY_INVALID_BUTTON; } JoyAxisList Input::_get_output_axis(String output) { for (int i = 0; _joy_axes[i]; i++) { - if (output == _joy_axes[i]) + if (output == _joy_axes[i]) { return JoyAxisList(i); + } } return JoyAxisList::JOY_INVALID_AXIS; } @@ -1183,25 +1197,28 @@ void Input::parse_mapping(String p_mapping) { int idx = 1; while (++idx < entry.size()) { - if (entry[idx] == "") + if (entry[idx] == "") { continue; + } String output = entry[idx].get_slice(":", 0).replace(" ", ""); String input = entry[idx].get_slice(":", 1).replace(" ", ""); ERR_CONTINUE_MSG(output.length() < 1 || input.length() < 2, String(entry[idx] + "\nInvalid device mapping entry: " + entry[idx])); - if (output == "platform") + if (output == "platform") { continue; + } JoyAxisRange output_range = FULL_AXIS; if (output[0] == '+' || output[0] == '-') { ERR_CONTINUE_MSG(output.length() < 2, String(entry[idx] + "\nInvalid output: " + entry[idx])); output = output.right(1); - if (output[0] == '+') + if (output[0] == '+') { output_range = POSITIVE_HALF_AXIS; - else if (output[0] == '-') + } else if (output[0] == '-') { output_range = NEGATIVE_HALF_AXIS; + } } JoyAxisRange input_range = FULL_AXIS; @@ -1213,8 +1230,9 @@ void Input::parse_mapping(String p_mapping) { input = input.right(1); } bool invert_axis = false; - if (input[input.length() - 1] == '~') + if (input[input.length() - 1] == '~') { invert_axis = true; + } JoyButtonList output_button = _get_output_button(output); JoyAxisList output_axis = _get_output_axis(output); @@ -1372,8 +1390,9 @@ Input::Input() { if (env_mapping != "") { Vector<String> entries = env_mapping.split("\n"); for (int i = 0; i < entries.size(); i++) { - if (entries[i] == "") + if (entries[i] == "") { continue; + } parse_mapping(entries[i]); } } diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp index 497ce79038..6ba082f86f 100644 --- a/core/input/input_event.cpp +++ b/core/input/input_event.cpp @@ -252,36 +252,45 @@ bool InputEventKey::is_echo() const { uint32_t InputEventKey::get_keycode_with_modifiers() const { uint32_t sc = keycode; - if (get_control()) + if (get_control()) { sc |= KEY_MASK_CTRL; - if (get_alt()) + } + if (get_alt()) { sc |= KEY_MASK_ALT; - if (get_shift()) + } + if (get_shift()) { sc |= KEY_MASK_SHIFT; - if (get_metakey()) + } + if (get_metakey()) { sc |= KEY_MASK_META; + } return sc; } uint32_t InputEventKey::get_physical_keycode_with_modifiers() const { uint32_t sc = physical_keycode; - if (get_control()) + if (get_control()) { sc |= KEY_MASK_CTRL; - if (get_alt()) + } + if (get_alt()) { sc |= KEY_MASK_ALT; - if (get_shift()) + } + if (get_shift()) { sc |= KEY_MASK_SHIFT; - if (get_metakey()) + } + if (get_metakey()) { sc |= KEY_MASK_META; + } return sc; } String InputEventKey::as_text() const { String kc = keycode_get_string(keycode); - if (kc == String()) + if (kc == String()) { return kc; + } if (get_metakey()) { kc = find_keycode_name(KEY_META) + ("+" + kc); @@ -300,8 +309,9 @@ String InputEventKey::as_text() const { bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const { Ref<InputEventKey> key = p_event; - if (key.is_null()) + if (key.is_null()) { return false; + } bool match = false; if (get_keycode() == 0) { @@ -316,18 +326,21 @@ bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool *p_pressed match = get_keycode() == key->get_keycode() && (!key->is_pressed() || (code & event_code) == code); } if (match) { - if (p_pressed != nullptr) + if (p_pressed != nullptr) { *p_pressed = key->is_pressed(); - if (p_strength != nullptr) + } + if (p_strength != nullptr) { *p_strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f; + } } return match; } bool InputEventKey::shortcut_match(const Ref<InputEvent> &p_event) const { Ref<InputEventKey> key = p_event; - if (key.is_null()) + if (key.is_null()) { return false; + } uint32_t code = get_keycode_with_modifiers(); uint32_t event_code = key->get_keycode_with_modifiers(); @@ -459,15 +472,18 @@ Ref<InputEvent> InputEventMouseButton::xformed_by(const Transform2D &p_xform, co bool InputEventMouseButton::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const { Ref<InputEventMouseButton> mb = p_event; - if (mb.is_null()) + if (mb.is_null()) { return false; + } bool match = mb->button_index == button_index; if (match) { - if (p_pressed != nullptr) + if (p_pressed != nullptr) { *p_pressed = mb->is_pressed(); - if (p_strength != nullptr) + } + if (p_strength != nullptr) { *p_strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f; + } } return match; @@ -616,8 +632,9 @@ String InputEventMouseMotion::as_text() const { bool InputEventMouseMotion::accumulate(const Ref<InputEvent> &p_event) { Ref<InputEventMouseMotion> motion = p_event; - if (motion.is_null()) + if (motion.is_null()) { return false; + } if (get_window_id() != motion->get_window_id()) { return false; @@ -698,15 +715,17 @@ bool InputEventJoypadMotion::is_pressed() const { bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const { Ref<InputEventJoypadMotion> jm = p_event; - if (jm.is_null()) + if (jm.is_null()) { return false; + } bool match = (axis == jm->axis); // Matches even if not in the same direction, but returns a "not pressed" event. if (match) { bool same_direction = (((axis_value < 0) == (jm->axis_value < 0)) || jm->axis_value == 0); bool pressed = same_direction ? Math::abs(jm->get_axis_value()) >= p_deadzone : false; - if (p_pressed != nullptr) + if (p_pressed != nullptr) { *p_pressed = pressed; + } if (p_strength != nullptr) { if (pressed) { if (p_deadzone == 1.0f) { @@ -765,15 +784,18 @@ float InputEventJoypadButton::get_pressure() const { bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const { Ref<InputEventJoypadButton> jb = p_event; - if (jb.is_null()) + if (jb.is_null()) { return false; + } bool match = button_index == jb->button_index; if (match) { - if (p_pressed != nullptr) + if (p_pressed != nullptr) { *p_pressed = jb->is_pressed(); - if (p_strength != nullptr) + } + if (p_strength != nullptr) { *p_strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f; + } } return match; @@ -781,8 +803,9 @@ bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event, bool * bool InputEventJoypadButton::shortcut_match(const Ref<InputEvent> &p_event) const { Ref<InputEventJoypadButton> button = p_event; - if (button.is_null()) + if (button.is_null()) { return false; + } return button_index == button->button_index; } @@ -963,8 +986,9 @@ float InputEventAction::get_strength() const { } bool InputEventAction::shortcut_match(const Ref<InputEvent> &p_event) const { - if (p_event.is_null()) + if (p_event.is_null()) { return false; + } return p_event->is_action(action); } @@ -975,15 +999,18 @@ bool InputEventAction::is_action(const StringName &p_action) const { bool InputEventAction::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const { Ref<InputEventAction> act = p_event; - if (act.is_null()) + if (act.is_null()) { return false; + } bool match = action == act->action; if (match) { - if (p_pressed != nullptr) + if (p_pressed != nullptr) { *p_pressed = act->pressed; - if (p_strength != nullptr) + } + if (p_strength != nullptr) { *p_strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f; + } } return match; } diff --git a/core/input/input_map.cpp b/core/input/input_map.cpp index d341b5ba4c..3cb4b43a26 100644 --- a/core/input/input_map.cpp +++ b/core/input/input_map.cpp @@ -70,8 +70,9 @@ void InputMap::erase_action(const StringName &p_action) { Array InputMap::_get_actions() { Array ret; List<StringName> actions = get_actions(); - if (actions.empty()) + if (actions.empty()) { return ret; + } for (const List<StringName>::Element *E = actions.front(); E; E = E->next()) { ret.push_back(E->get()); @@ -124,8 +125,9 @@ void InputMap::action_set_deadzone(const StringName &p_action, float p_deadzone) void InputMap::action_add_event(const StringName &p_action, const Ref<InputEvent> &p_event) { ERR_FAIL_COND_MSG(p_event.is_null(), "It's not a reference to a valid InputEvent object."); ERR_FAIL_COND_MSG(!input_map.has(p_action), "Request for nonexistent InputMap action '" + String(p_action) + "'."); - if (_find_event(input_map[p_action], p_event)) + if (_find_event(input_map[p_action], p_event)) { return; //already gots + } input_map[p_action].inputs.push_back(p_event); } @@ -139,8 +141,9 @@ void InputMap::action_erase_event(const StringName &p_action, const Ref<InputEve ERR_FAIL_COND_MSG(!input_map.has(p_action), "Request for nonexistent InputMap action '" + String(p_action) + "'."); List<Ref<InputEvent>>::Element *E = _find_event(input_map[p_action], p_event); - if (E) + if (E) { input_map[p_action].inputs.erase(E); + } } void InputMap::action_erase_events(const StringName &p_action) { @@ -163,8 +166,9 @@ Array InputMap::_get_action_list(const StringName &p_action) { const List<Ref<InputEvent>> *InputMap::get_action_list(const StringName &p_action) { const Map<StringName, Action>::Element *E = input_map.find(p_action); - if (!E) + if (!E) { return nullptr; + } return &E->get().inputs; } @@ -179,10 +183,12 @@ bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const Str Ref<InputEventAction> input_event_action = p_event; if (input_event_action.is_valid()) { - if (p_pressed != nullptr) + if (p_pressed != nullptr) { *p_pressed = input_event_action->is_pressed(); - if (p_strength != nullptr) + } + if (p_strength != nullptr) { *p_strength = (p_pressed != nullptr && *p_pressed) ? input_event_action->get_strength() : 0.0f; + } return input_event_action->get_action() == p_action; } @@ -190,10 +196,12 @@ bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const Str float strength; List<Ref<InputEvent>>::Element *event = _find_event(E->get(), p_event, &pressed, &strength); if (event != nullptr) { - if (p_pressed != nullptr) + if (p_pressed != nullptr) { *p_pressed = pressed; - if (p_strength != nullptr) + } + if (p_strength != nullptr) { *p_strength = strength; + } return true; } else { return false; @@ -213,8 +221,9 @@ void InputMap::load_from_globals() { for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { const PropertyInfo &pi = E->get(); - if (!pi.name.begins_with("input/")) + if (!pi.name.begins_with("input/")) { continue; + } String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length()); @@ -225,8 +234,9 @@ void InputMap::load_from_globals() { add_action(name, deadzone); for (int i = 0; i < events.size(); i++) { Ref<InputEvent> event = events[i]; - if (event.is_null()) + if (event.is_null()) { continue; + } action_add_event(name, event); } } diff --git a/core/io/compression.cpp b/core/io/compression.cpp index 1b6786d888..99ca8107e4 100644 --- a/core/io/compression.cpp +++ b/core/io/compression.cpp @@ -62,8 +62,9 @@ int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size, strm.opaque = Z_NULL; int level = p_mode == MODE_DEFLATE ? zlib_level : gzip_level; int err = deflateInit2(&strm, level, Z_DEFLATED, window_bits, 8, Z_DEFAULT_STRATEGY); - if (err != Z_OK) + if (err != Z_OK) { return -1; + } strm.avail_in = p_src_size; int aout = deflateBound(&strm, p_src_size); @@ -97,8 +98,9 @@ int Compression::get_max_compressed_buffer_size(int p_src_size, Mode p_mode) { switch (p_mode) { case MODE_FASTLZ: { int ss = p_src_size + p_src_size * 6 / 100; - if (ss < 66) + if (ss < 66) { ss = 66; + } return ss; } break; @@ -111,8 +113,9 @@ int Compression::get_max_compressed_buffer_size(int p_src_size, Mode p_mode) { strm.zfree = zipio_free; strm.opaque = Z_NULL; int err = deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, window_bits, 8, Z_DEFAULT_STRATEGY); - if (err != Z_OK) + if (err != Z_OK) { return -1; + } int aout = deflateBound(&strm, p_src_size); deflateEnd(&strm); return aout; diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp index 334c8f143e..1af9142317 100644 --- a/core/io/config_file.cpp +++ b/core/io/config_file.cpp @@ -63,8 +63,9 @@ PackedStringArray ConfigFile::_get_section_keys(const String &p_section) const { void ConfigFile::set_value(const String &p_section, const String &p_key, const Variant &p_value) { if (p_value.get_type() == Variant::NIL) { //erase - if (!values.has(p_section)) + if (!values.has(p_section)) { return; // ? + } values[p_section].erase(p_key); if (values[p_section].empty()) { values.erase(p_section); @@ -94,8 +95,9 @@ bool ConfigFile::has_section(const String &p_section) const { } bool ConfigFile::has_section_key(const String &p_section, const String &p_key) const { - if (!values.has(p_section)) + if (!values.has(p_section)) { return false; + } return values[p_section].has(p_key); } @@ -130,8 +132,9 @@ Error ConfigFile::save(const String &p_path) { FileAccess *file = FileAccess::open(p_path, FileAccess::WRITE, &err); if (err) { - if (file) + if (file) { memdelete(file); + } return err; } @@ -142,8 +145,9 @@ Error ConfigFile::save_encrypted(const String &p_path, const Vector<uint8_t> &p_ Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::WRITE, &err); - if (err) + if (err) { return err; + } FileAccessEncrypted *fae = memnew(FileAccessEncrypted); err = fae->open_and_parse(f, p_key, FileAccessEncrypted::MODE_WRITE_AES256); @@ -159,8 +163,9 @@ Error ConfigFile::save_encrypted_pass(const String &p_path, const String &p_pass Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::WRITE, &err); - if (err) + if (err) { return err; + } FileAccessEncrypted *fae = memnew(FileAccessEncrypted); err = fae->open_and_parse_password(f, p_pass, FileAccessEncrypted::MODE_WRITE_AES256); @@ -175,8 +180,9 @@ Error ConfigFile::save_encrypted_pass(const String &p_path, const String &p_pass Error ConfigFile::_internal_save(FileAccess *file) { for (OrderedHashMap<String, OrderedHashMap<String, Variant>>::Element E = values.front(); E; E = E.next()) { - if (E != values.front()) + if (E != values.front()) { file->store_string("\n"); + } file->store_string("[" + E.key() + "]\n\n"); for (OrderedHashMap<String, Variant>::Element F = E.get().front(); F; F = F.next()) { @@ -195,8 +201,9 @@ Error ConfigFile::load(const String &p_path) { Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); - if (!f) + if (!f) { return err; + } return _internal_load(p_path, f); } @@ -205,8 +212,9 @@ Error ConfigFile::load_encrypted(const String &p_path, const Vector<uint8_t> &p_ Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); - if (err) + if (err) { return err; + } FileAccessEncrypted *fae = memnew(FileAccessEncrypted); err = fae->open_and_parse(f, p_key, FileAccessEncrypted::MODE_READ); @@ -222,8 +230,9 @@ Error ConfigFile::load_encrypted_pass(const String &p_path, const String &p_pass Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); - if (err) + if (err) { return err; + } FileAccessEncrypted *fae = memnew(FileAccessEncrypted); err = fae->open_and_parse_password(f, p_pass, FileAccessEncrypted::MODE_READ); diff --git a/core/io/file_access_compressed.cpp b/core/io/file_access_compressed.cpp index 422100010c..7817ccb773 100644 --- a/core/io/file_access_compressed.cpp +++ b/core/io/file_access_compressed.cpp @@ -34,11 +34,12 @@ void FileAccessCompressed::configure(const String &p_magic, Compression::Mode p_mode, int p_block_size) { magic = p_magic.ascii().get_data(); - if (magic.length() > 4) + if (magic.length() > 4) { magic = magic.substr(0, 4); - else { - while (magic.length() < 4) + } else { + while (magic.length() < 4) { magic += " "; + } } cmode = p_mode; @@ -97,8 +98,9 @@ Error FileAccessCompressed::open_after_magic(FileAccess *p_base) { Error FileAccessCompressed::_open(const String &p_path, int p_mode_flags) { ERR_FAIL_COND_V(p_mode_flags == READ_WRITE, ERR_UNAVAILABLE); - if (f) + if (f) { close(); + } Error err; f = FileAccess::open(p_path, p_mode_flags, &err); @@ -134,8 +136,9 @@ Error FileAccessCompressed::_open(const String &p_path, int p_mode_flags) { } void FileAccessCompressed::close() { - if (!f) + if (!f) { return; + } if (writing) { //save block table and all compressed blocks @@ -165,8 +168,9 @@ void FileAccessCompressed::close() { } f->seek(16); //ok write block sizes - for (int i = 0; i < bc; i++) + for (int i = 0; i < bc; i++) { f->store_32(block_sizes[i]); + } f->seek_end(); f->store_buffer((const uint8_t *)mgc.get_data(), mgc.length()); //magic at the end too @@ -306,8 +310,9 @@ int FileAccessCompressed::get_buffer(uint8_t *p_dst, int p_length) const { } else { read_block--; at_end = true; - if (i < p_length - 1) + if (i < p_length - 1) { read_eof = true; + } return i; } } @@ -337,22 +342,25 @@ void FileAccessCompressed::store_8(uint8_t p_dest) { bool FileAccessCompressed::file_exists(const String &p_name) { FileAccess *fa = FileAccess::open(p_name, FileAccess::READ); - if (!fa) + if (!fa) { return false; + } memdelete(fa); return true; } uint64_t FileAccessCompressed::_get_modified_time(const String &p_file) { - if (f) + if (f) { return f->get_modified_time(p_file); - else + } else { return 0; + } } uint32_t FileAccessCompressed::_get_unix_permissions(const String &p_file) { - if (f) + if (f) { return f->_get_unix_permissions(p_file); + } return 0; } @@ -364,6 +372,7 @@ Error FileAccessCompressed::_set_unix_permissions(const String &p_file, uint32_t } FileAccessCompressed::~FileAccessCompressed() { - if (f) + if (f) { close(); + } } diff --git a/core/io/file_access_encrypted.cpp b/core/io/file_access_encrypted.cpp index ceda6c5eb2..5938914cb0 100644 --- a/core/io/file_access_encrypted.cpp +++ b/core/io/file_access_encrypted.cpp @@ -115,8 +115,9 @@ Error FileAccessEncrypted::_open(const String &p_path, int p_mode_flags) { } void FileAccessEncrypted::close() { - if (!file) + if (!file) { return; + } if (writing) { Vector<uint8_t> compressed; @@ -166,22 +167,25 @@ bool FileAccessEncrypted::is_open() const { } String FileAccessEncrypted::get_path() const { - if (file) + if (file) { return file->get_path(); - else + } else { return ""; + } } String FileAccessEncrypted::get_path_absolute() const { - if (file) + if (file) { return file->get_path_absolute(); - else + } else { return ""; + } } void FileAccessEncrypted::seek(size_t p_position) { - if (p_position > (size_t)data.size()) + if (p_position > (size_t)data.size()) { p_position = data.size(); + } pos = p_position; eofed = false; @@ -270,8 +274,9 @@ void FileAccessEncrypted::store_8(uint8_t p_dest) { bool FileAccessEncrypted::file_exists(const String &p_name) { FileAccess *fa = FileAccess::open(p_name, FileAccess::READ); - if (!fa) + if (!fa) { return false; + } memdelete(fa); return true; } @@ -290,6 +295,7 @@ Error FileAccessEncrypted::_set_unix_permissions(const String &p_file, uint32_t } FileAccessEncrypted::~FileAccessEncrypted() { - if (file) + if (file) { close(); + } } diff --git a/core/io/file_access_memory.cpp b/core/io/file_access_memory.cpp index 790f946752..3c5f846941 100644 --- a/core/io/file_access_memory.cpp +++ b/core/io/file_access_memory.cpp @@ -43,18 +43,20 @@ void FileAccessMemory::register_file(String p_name, Vector<uint8_t> p_data) { } String name; - if (ProjectSettings::get_singleton()) + if (ProjectSettings::get_singleton()) { name = ProjectSettings::get_singleton()->globalize_path(p_name); - else + } else { name = p_name; + } //name = DirAccess::normalize_path(name); (*files)[name] = p_data; } void FileAccessMemory::cleanup() { - if (!files) + if (!files) { return; + } memdelete(files); } diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp index 4b7f99e5b0..6890740d90 100644 --- a/core/io/file_access_network.cpp +++ b/core/io/file_access_network.cpp @@ -115,8 +115,9 @@ void FileAccessNetworkClient::_thread_func() { } } - if (accesses.has(id)) + if (accesses.has(id)) { fa = accesses[id]; + } switch (response) { case FileAccessNetwork::RESPONSE_OPEN: { @@ -140,8 +141,9 @@ void FileAccessNetworkClient::_thread_func() { block.resize(len); client->get_data(block.ptrw(), len); - if (fa) //may have been queued + if (fa) { //may have been queued fa->_set_block(offset, block); + } } break; case FileAccessNetwork::RESPONSE_FILE_EXISTS: { @@ -244,8 +246,9 @@ void FileAccessNetwork::_set_block(int p_offset, const Vector<uint8_t> &p_block) void FileAccessNetwork::_respond(size_t p_len, Error p_status) { DEBUG_PRINT("GOT RESPONSE - len: " + itos(p_len) + " status: " + itos(p_status)); response = p_status; - if (response != OK) + if (response != OK) { return; + } opened = true; total_size = p_len; int pc = ((total_size - 1) / page_size) + 1; @@ -254,8 +257,9 @@ void FileAccessNetwork::_respond(size_t p_len, Error p_status) { Error FileAccessNetwork::_open(const String &p_path, int p_mode_flags) { ERR_FAIL_COND_V(p_mode_flags != READ, ERR_UNAVAILABLE); - if (opened) + if (opened) { close(); + } FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton; DEBUG_PRINT("open: " + p_path); @@ -287,8 +291,9 @@ Error FileAccessNetwork::_open(const String &p_path, int p_mode_flags) { } void FileAccessNetwork::close() { - if (!opened) + if (!opened) { return; + } FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton; @@ -342,8 +347,9 @@ uint8_t FileAccessNetwork::get_8() const { } void FileAccessNetwork::_queue_page(int p_page) const { - if (p_page >= pages.size()) + if (p_page >= pages.size()) { return; + } if (pages[p_page].buffer.empty() && !pages[p_page].queued) { FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton; { diff --git a/core/io/file_access_pack.cpp b/core/io/file_access_pack.cpp index bb65a1afbc..00c4e76efe 100644 --- a/core/io/file_access_pack.cpp +++ b/core/io/file_access_pack.cpp @@ -54,12 +54,14 @@ void PackedData::add_path(const String &pkg_path, const String &path, uint64_t o pf.pack = pkg_path; pf.offset = ofs; pf.size = size; - for (int i = 0; i < 16; i++) + for (int i = 0; i < 16; i++) { pf.md5[i] = p_md5[i]; + } pf.src = p_src; - if (!exists || p_replace_files) + if (!exists || p_replace_files) { files[pmd5] = pf; + } if (!exists) { //search for dir @@ -106,8 +108,9 @@ PackedData::PackedData() { } void PackedData::_free_packed_dirs(PackedDir *p_dir) { - for (Map<String, PackedDir *>::Element *E = p_dir->subdirs.front(); E; E = E->next()) + for (Map<String, PackedDir *>::Element *E = p_dir->subdirs.front(); E; E = E->next()) { _free_packed_dirs(E->get()); + } memdelete(p_dir); } @@ -122,8 +125,9 @@ PackedData::~PackedData() { bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files) { FileAccess *f = FileAccess::open(p_path, FileAccess::READ); - if (!f) + if (!f) { return false; + } uint32_t magic = f->get_32(); @@ -252,8 +256,9 @@ uint8_t FileAccessPack::get_8() const { } int FileAccessPack::get_buffer(uint8_t *p_dst, int p_length) const { - if (eof) + if (eof) { return 0; + } uint64_t to_read = p_length; if (to_read + pos > pf.size) { @@ -263,8 +268,9 @@ int FileAccessPack::get_buffer(uint8_t *p_dst, int p_length) const { pos += p_length; - if (to_read <= 0) + if (to_read <= 0) { return 0; + } f->get_buffer(p_dst, to_read); return to_read; @@ -276,8 +282,9 @@ void FileAccessPack::set_endian_swap(bool p_swap) { } Error FileAccessPack::get_error() const { - if (eof) + if (eof) { return ERR_FILE_EOF; + } return OK; } @@ -308,8 +315,9 @@ FileAccessPack::FileAccessPack(const String &p_path, const PackedData::PackedFil } FileAccessPack::~FileAccessPack() { - if (f) + if (f) { memdelete(f); + } } ////////////////////////////////////////////////////////////////////////////////// @@ -378,8 +386,9 @@ Error DirAccessPack::change_dir(String p_dir) { nd = nd.simplify_path(); - if (nd == "") + if (nd == "") { nd = "."; + } if (nd.begins_with("/")) { nd = nd.replace_first("/", ""); @@ -390,10 +399,11 @@ Error DirAccessPack::change_dir(String p_dir) { PackedData::PackedDir *pd; - if (absolute) + if (absolute) { pd = PackedData::get_singleton()->root; - else + } else { pd = current; + } for (int i = 0; i < paths.size(); i++) { String p = paths[i]; diff --git a/core/io/file_access_pack.h b/core/io/file_access_pack.h index a5d4c1f1b6..320a6cb216 100644 --- a/core/io/file_access_pack.h +++ b/core/io/file_access_pack.h @@ -175,10 +175,12 @@ public: FileAccess *PackedData::try_open_path(const String &p_path) { PathMD5 pmd5(p_path.md5_buffer()); Map<PathMD5, PackedFile>::Element *E = files.find(pmd5); - if (!E) + if (!E) { return nullptr; //not found - if (E->get().offset == 0) + } + if (E->get().offset == 0) { return nullptr; //was erased + } return E->get().src->get_file(p_path, &E->get()); } diff --git a/core/io/file_access_zip.cpp b/core/io/file_access_zip.cpp index 5dde5aa6ce..c3a62706c7 100644 --- a/core/io/file_access_zip.cpp +++ b/core/io/file_access_zip.cpp @@ -149,14 +149,16 @@ unzFile ZipArchive::get_file_handle(String p_file) const { bool ZipArchive::try_open_pack(const String &p_path, bool p_replace_files) { //printf("opening zip pack %ls, %i, %i\n", p_name.c_str(), p_name.extension().nocasecmp_to("zip"), p_name.extension().nocasecmp_to("pcz")); - if (p_path.get_extension().nocasecmp_to("zip") != 0 && p_path.get_extension().nocasecmp_to("pcz") != 0) + if (p_path.get_extension().nocasecmp_to("zip") != 0 && p_path.get_extension().nocasecmp_to("pcz") != 0) { return false; + } zlib_filefunc_def io; FileAccess *fa = FileAccess::open(p_path, FileAccess::READ); - if (!fa) + if (!fa) { return false; + } io.opaque = fa; io.zopen_file = godot_open; io.zread_file = godot_read; @@ -252,8 +254,9 @@ Error FileAccessZip::_open(const String &p_path, int p_mode_flags) { } void FileAccessZip::close() { - if (!zfile) + if (!zfile) { return; + } ZipArchive *arch = ZipArchive::get_singleton(); ERR_FAIL_COND(!arch); @@ -300,12 +303,14 @@ uint8_t FileAccessZip::get_8() const { int FileAccessZip::get_buffer(uint8_t *p_dst, int p_length) const { ERR_FAIL_COND_V(!zfile, -1); at_eof = unzeof(zfile); - if (at_eof) + if (at_eof) { return 0; + } int read = unzReadCurrentFile(zfile, p_dst, p_length); ERR_FAIL_COND_V(read < 0, read); - if (read < p_length) + if (read < p_length) { at_eof = true; + } return read; } diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp index 2a1a435b8e..40debae9e5 100644 --- a/core/io/http_client.cpp +++ b/core/io/http_client.cpp @@ -240,8 +240,9 @@ int HTTPClient::get_response_code() const { } Error HTTPClient::get_response_headers(List<String> *r_response) { - if (!response_headers.size()) + if (!response_headers.size()) { return ERR_INVALID_PARAMETER; + } for (int i = 0; i < response_headers.size(); i++) { r_response->push_back(response_headers[i]); @@ -253,8 +254,9 @@ Error HTTPClient::get_response_headers(List<String> *r_response) { } void HTTPClient::close() { - if (tcp_connection->get_status() != StreamPeerTCP::STATUS_NONE) + if (tcp_connection->get_status() != StreamPeerTCP::STATUS_NONE) { tcp_connection->disconnect_from_host(); + } connection.unref(); status = STATUS_DISCONNECTED; @@ -393,8 +395,9 @@ Error HTTPClient::poll() { return ERR_CONNECTION_ERROR; } - if (rec == 0) + if (rec == 0) { return OK; // Still requesting, keep trying! + } response_str.push_back(byte); int rs = response_str.size(); @@ -424,8 +427,9 @@ Error HTTPClient::poll() { for (int i = 0; i < responses.size(); i++) { String header = responses[i].strip_edges(); String s = header.to_lower(); - if (s.length() == 0) + if (s.length() == 0) { continue; + } if (s.begins_with("content-length:")) { body_size = s.substr(s.find(":") + 1, s.length()).strip_edges().to_int(); body_left = body_size; @@ -501,8 +505,9 @@ PackedByteArray HTTPClient::read_response_body_chunk() { int rec = 0; err = _get_http_data(&b, 1, rec); - if (rec == 0) + if (rec == 0) { break; + } chunk.push_back(b); int cs = chunk.size(); @@ -524,8 +529,9 @@ PackedByteArray HTTPClient::read_response_body_chunk() { int rec = 0; err = _get_http_data(&b, 1, rec); - if (rec == 0) + if (rec == 0) { break; + } chunk.push_back(b); @@ -540,13 +546,13 @@ PackedByteArray HTTPClient::read_response_body_chunk() { for (int i = 0; i < chunk.size() - 2; i++) { char c = chunk[i]; int v = 0; - if (c >= '0' && c <= '9') + if (c >= '0' && c <= '9') { v = c - '0'; - else if (c >= 'a' && c <= 'f') + } else if (c >= 'a' && c <= 'f') { v = c - 'a' + 10; - else if (c >= 'A' && c <= 'F') + } else if (c >= 'A' && c <= 'F') { v = c - 'A' + 10; - else { + } else { ERR_PRINT("HTTP Chunk len not in hex!!"); status = STATUS_CONNECTION_ERROR; break; @@ -615,8 +621,9 @@ PackedByteArray HTTPClient::read_response_body_chunk() { body_left -= rec; } } - if (err != OK) + if (err != OK) { break; + } } } @@ -727,8 +734,9 @@ Dictionary HTTPClient::_get_response_headers_as_dictionary() { for (const List<String>::Element *E = rh.front(); E; E = E->next()) { const String &s = E->get(); int sp = s.find(":"); - if (sp == -1) + if (sp == -1) { continue; + } String key = s.substr(0, sp).strip_edges(); String value = s.substr(sp + 1, s.length()).strip_edges(); ret[key] = value; diff --git a/core/io/image_loader.cpp b/core/io/image_loader.cpp index 06e3cc029d..b1e92eb87f 100644 --- a/core/io/image_loader.cpp +++ b/core/io/image_loader.cpp @@ -36,8 +36,9 @@ bool ImageFormatLoader::recognize(const String &p_extension) const { List<String> extensions; get_recognized_extensions(&extensions); for (List<String>::Element *E = extensions.front(); E; E = E->next()) { - if (E->get().nocasecmp_to(p_extension) == 0) + if (E->get().nocasecmp_to(p_extension) == 0) { return true; + } } return false; @@ -59,23 +60,26 @@ Error ImageLoader::load_image(String p_file, Ref<Image> p_image, FileAccess *p_c String extension = p_file.get_extension(); for (int i = 0; i < loader.size(); i++) { - if (!loader[i]->recognize(extension)) + if (!loader[i]->recognize(extension)) { continue; + } Error err = loader[i]->load_image(p_image, f, p_force_linear, p_scale); if (err != OK) { ERR_PRINT("Error loading image: " + p_file); } if (err != ERR_FILE_UNRECOGNIZED) { - if (!p_custom) + if (!p_custom) { memdelete(f); + } return err; } } - if (!p_custom) + if (!p_custom) { memdelete(f); + } return ERR_FILE_UNRECOGNIZED; } @@ -88,8 +92,9 @@ void ImageLoader::get_recognized_extensions(List<String> *p_extensions) { ImageFormatLoader *ImageLoader::recognize(const String &p_extension) { for (int i = 0; i < loader.size(); i++) { - if (loader[i]->recognize(p_extension)) + if (loader[i]->recognize(p_extension)) { return loader[i]; + } } return nullptr; diff --git a/core/io/ip.cpp b/core/io/ip.cpp index 642602d0bc..653959b393 100644 --- a/core/io/ip.cpp +++ b/core/io/ip.cpp @@ -61,8 +61,9 @@ struct _IP_ResolverPrivate { IP::ResolverID find_empty_id() const { for (int i = 0; i < IP::RESOLVER_MAX_QUERIES; i++) { - if (queue[i].status == IP::RESOLVER_STATUS_NONE) + if (queue[i].status == IP::RESOLVER_STATUS_NONE) { return i; + } } return IP::RESOLVER_INVALID_ID; } @@ -76,14 +77,16 @@ struct _IP_ResolverPrivate { void resolve_queues() { for (int i = 0; i < IP::RESOLVER_MAX_QUERIES; i++) { - if (queue[i].status != IP::RESOLVER_STATUS_WAITING) + if (queue[i].status != IP::RESOLVER_STATUS_WAITING) { continue; + } queue[i].response = IP::get_singleton()->resolve_hostname(queue[i].hostname, queue[i].type); - if (!queue[i].response.is_valid()) + if (!queue[i].response.is_valid()) { queue[i].status = IP::RESOLVER_STATUS_ERROR; - else + } else { queue[i].status = IP::RESOLVER_STATUS_DONE; + } } } @@ -138,10 +141,11 @@ IP::ResolverID IP::resolve_hostname_queue_item(const String &p_hostname, IP::Typ } else { resolver->queue[id].response = IP_Address(); resolver->queue[id].status = IP::RESOLVER_STATUS_WAITING; - if (resolver->thread) + if (resolver->thread) { resolver->sem.post(); - else + } else { resolver->resolve_queues(); + } } return id; diff --git a/core/io/ip_address.cpp b/core/io/ip_address.cpp index 817c2f060a..89b317bf93 100644 --- a/core/io/ip_address.cpp +++ b/core/io/ip_address.cpp @@ -39,19 +39,23 @@ IP_Address::operator Variant() const { #include <string.h> IP_Address::operator String() const { - if (wildcard) + if (wildcard) { return "*"; + } - if (!valid) + if (!valid) { return ""; + } - if (is_ipv4()) + if (is_ipv4()) { // IPv4 address mapped to IPv6 return itos(field8[12]) + "." + itos(field8[13]) + "." + itos(field8[14]) + "." + itos(field8[15]); + } String ret; for (int i = 0; i < 8; i++) { - if (i > 0) + if (i > 0) { ret = ret + ":"; + } uint16_t num = (field8[i * 2] << 8) + field8[i * 2 + 1]; ret = ret + String::num_int64(num, 16); }; @@ -187,8 +191,9 @@ const uint8_t *IP_Address::get_ipv6() const { void IP_Address::set_ipv6(const uint8_t *p_buf) { clear(); valid = true; - for (int i = 0; i < 16; i++) + for (int i = 0; i < 16; i++) { field8[i] = p_buf[i]; + } } IP_Address::IP_Address(const String &p_string) { diff --git a/core/io/ip_address.h b/core/io/ip_address.h index 39948ce211..2f8f83503e 100644 --- a/core/io/ip_address.h +++ b/core/io/ip_address.h @@ -51,23 +51,32 @@ protected: public: //operator Variant() const; bool operator==(const IP_Address &p_ip) const { - if (p_ip.valid != valid) + if (p_ip.valid != valid) { return false; - if (!valid) + } + if (!valid) { return false; - for (int i = 0; i < 4; i++) - if (field32[i] != p_ip.field32[i]) + } + for (int i = 0; i < 4; i++) { + if (field32[i] != p_ip.field32[i]) { return false; + } + } return true; } + bool operator!=(const IP_Address &p_ip) const { - if (p_ip.valid != valid) + if (p_ip.valid != valid) { return true; - if (!valid) + } + if (!valid) { return true; - for (int i = 0; i < 4; i++) - if (field32[i] != p_ip.field32[i]) + } + for (int i = 0; i < 4; i++) { + if (field32[i] != p_ip.field32[i]) { return true; + } + } return false; } diff --git a/core/io/json.cpp b/core/io/json.cpp index baa62a4b0a..03f4e65220 100644 --- a/core/io/json.cpp +++ b/core/io/json.cpp @@ -48,8 +48,9 @@ const char *JSON::tk_name[TK_MAX] = { static String _make_indent(const String &p_indent, int p_size) { String indent_text = ""; if (!p_indent.empty()) { - for (int i = 0; i < p_size; i++) + for (int i = 0; i < p_size; i++) { indent_text += p_indent; + } } return indent_text; } @@ -98,8 +99,9 @@ String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_ List<Variant> keys; d.get_key_list(&keys); - if (p_sort_keys) + if (p_sort_keys) { keys.sort(); + } for (List<Variant>::Element *E = keys.front(); E; E = E->next()) { if (E != keys.front()) { @@ -241,8 +243,9 @@ Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_to str += res; } else { - if (p_str[index] == '\n') + if (p_str[index] == '\n') { line++; + } str += p_str[index]; } index++; @@ -294,27 +297,29 @@ Error JSON::_parse_value(Variant &value, Token &token, const CharType *p_str, in if (token.type == TK_CURLY_BRACKET_OPEN) { Dictionary d; Error err = _parse_object(d, p_str, index, p_len, line, r_err_str); - if (err) + if (err) { return err; + } value = d; return OK; } else if (token.type == TK_BRACKET_OPEN) { Array a; Error err = _parse_array(a, p_str, index, p_len, line, r_err_str); - if (err) + if (err) { return err; + } value = a; return OK; } else if (token.type == TK_IDENTIFIER) { String id = token.value; - if (id == "true") + if (id == "true") { value = true; - else if (id == "false") + } else if (id == "false") { value = false; - else if (id == "null") + } else if (id == "null") { value = Variant(); - else { + } else { r_err_str = "Expected 'true','false' or 'null', got '" + id + "'."; return ERR_PARSE_ERROR; } @@ -338,8 +343,9 @@ Error JSON::_parse_array(Array &array, const CharType *p_str, int &index, int p_ while (index < p_len) { Error err = _get_token(p_str, index, p_len, token, line, r_err_str); - if (err != OK) + if (err != OK) { return err; + } if (token.type == TK_BRACKET_CLOSE) { return OK; @@ -357,8 +363,9 @@ Error JSON::_parse_array(Array &array, const CharType *p_str, int &index, int p_ Variant v; err = _parse_value(v, token, p_str, index, p_len, line, r_err_str); - if (err) + if (err) { return err; + } array.push_back(v); need_comma = true; @@ -376,8 +383,9 @@ Error JSON::_parse_object(Dictionary &object, const CharType *p_str, int &index, while (index < p_len) { if (at_key) { Error err = _get_token(p_str, index, p_len, token, line, r_err_str); - if (err != OK) + if (err != OK) { return err; + } if (token.type == TK_CURLY_BRACKET_CLOSE) { return OK; @@ -400,8 +408,9 @@ Error JSON::_parse_object(Dictionary &object, const CharType *p_str, int &index, key = token.value; err = _get_token(p_str, index, p_len, token, line, r_err_str); - if (err != OK) + if (err != OK) { return err; + } if (token.type != TK_COLON) { r_err_str = "Expected ':'"; return ERR_PARSE_ERROR; @@ -409,13 +418,15 @@ Error JSON::_parse_object(Dictionary &object, const CharType *p_str, int &index, at_key = false; } else { Error err = _get_token(p_str, index, p_len, token, line, r_err_str); - if (err != OK) + if (err != OK) { return err; + } Variant v; err = _parse_value(v, token, p_str, index, p_len, line, r_err_str); - if (err) + if (err) { return err; + } object[key] = v; need_comma = true; at_key = true; @@ -434,8 +445,9 @@ Error JSON::parse(const String &p_json, Variant &r_ret, String &r_err_str, int & String aux_key; Error err = _get_token(str, idx, len, token, r_err_line, r_err_str); - if (err) + if (err) { return err; + } err = _parse_value(r_ret, token, str, idx, len, r_err_line, r_err_str); diff --git a/core/io/logger.cpp b/core/io/logger.cpp index 23165b575e..ef78b1194e 100644 --- a/core/io/logger.cpp +++ b/core/io/logger.cpp @@ -67,10 +67,11 @@ void Logger::log_error(const char *p_function, const char *p_file, int p_line, c } const char *err_details; - if (p_rationale && *p_rationale) + if (p_rationale && *p_rationale) { err_details = p_rationale; - else + } else { err_details = p_code; + } logf_error("%s: %s\n", err_type, err_details); logf_error(" at: %s (%s:%i) - %s\n", p_function, p_file, p_line, p_code); diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index fc0b037b07..eb39b1433f 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -107,8 +107,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int buf += 4; len -= 4; - if (r_len) + if (r_len) { *r_len = 4; + } switch (type & ENCODE_MASK) { case Variant::NIL: { @@ -118,23 +119,26 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); bool val = decode_uint32(buf); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4; + } } break; case Variant::INT: { if (type & ENCODE_FLAG_64) { ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA); int64_t val = decode_uint64(buf); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 8; + } } else { ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t val = decode_uint32(buf); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4; + } } } break; @@ -143,22 +147,25 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA); double val = decode_double(buf); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 8; + } } else { ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); float val = decode_float(buf); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4; + } } } break; case Variant::STRING: { String str; Error err = _decode_string(buf, len, r_len, str); - if (err) + if (err) { return err; + } r_variant = str; } break; @@ -171,8 +178,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int val.y = decode_float(&buf[4]); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4 * 2; + } } break; case Variant::VECTOR2I: { @@ -182,8 +190,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int val.y = decode_uint32(&buf[4]); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4 * 2; + } } break; case Variant::RECT2: { @@ -195,8 +204,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int val.size.y = decode_float(&buf[12]); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4 * 4; + } } break; case Variant::RECT2I: { @@ -208,8 +218,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int val.size.y = decode_uint32(&buf[12]); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4 * 4; + } } break; case Variant::VECTOR3: { @@ -220,8 +231,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int val.z = decode_float(&buf[8]); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4 * 3; + } } break; case Variant::VECTOR3I: { @@ -232,8 +244,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int val.z = decode_uint32(&buf[8]); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4 * 3; + } } break; case Variant::TRANSFORM2D: { @@ -247,8 +260,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4 * 6; + } } break; case Variant::PLANE: { @@ -260,8 +274,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int val.d = decode_float(&buf[12]); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4 * 4; + } } break; case Variant::QUAT: { @@ -273,8 +288,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int val.w = decode_float(&buf[12]); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4 * 4; + } } break; case Variant::AABB: { @@ -288,8 +304,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int val.size.z = decode_float(&buf[20]); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4 * 6; + } } break; case Variant::BASIS: { @@ -303,8 +320,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4 * 9; + } } break; case Variant::TRANSFORM: { @@ -321,8 +339,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4 * 12; + } } break; @@ -336,15 +355,17 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int val.a = decode_float(&buf[12]); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4 * 4; + } } break; case Variant::STRING_NAME: { String str; Error err = _decode_string(buf, len, r_len, str); - if (err) + if (err) { return err; + } r_variant = StringName(str); } break; @@ -366,24 +387,28 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int len -= 12; buf += 12; - if (flags & 2) // Obsolete format with property separate from subpath + if (flags & 2) { // Obsolete format with property separate from subpath subnamecount++; + } uint32_t total = namecount + subnamecount; - if (r_len) + if (r_len) { (*r_len) += 12; + } for (uint32_t i = 0; i < total; i++) { String str; Error err = _decode_string(buf, len, r_len, str); - if (err) + if (err) { return err; + } - if (i < namecount) + if (i < namecount) { names.push_back(str); - else + } else { subnames.push_back(str); + } } r_variant = NodePath(names, subnames, flags & 1); @@ -403,8 +428,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int //this _is_ allowed ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA); ObjectID val = ObjectID(decode_uint64(buf)); - if (r_len) + if (r_len) { (*r_len) += 8; + } if (val.is_null()) { r_variant = (Object *)nullptr; @@ -421,8 +447,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int String str; Error err = _decode_string(buf, len, r_len, str); - if (err) + if (err) { return err; + } if (str == String()) { r_variant = (Object *)nullptr; @@ -442,14 +469,16 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int for (int i = 0; i < count; i++) { str = String(); err = _decode_string(buf, len, r_len, str); - if (err) + if (err) { return err; + } Variant value; int used; err = decode_variant(value, buf, len, &used, p_allow_objects); - if (err) + if (err) { return err; + } buf += used; len -= used; @@ -573,8 +602,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int r_variant = data; if (r_len) { - if (count % 4) + if (count % 4) { (*r_len) += 4 - count % 4; + } (*r_len) += 4 + count; } @@ -685,15 +715,17 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int buf += 4; len -= 4; - if (r_len) + if (r_len) { (*r_len) += 4; + } //printf("string count: %i\n",count); for (int32_t i = 0; i < count; i++) { String str; Error err = _decode_string(buf, len, r_len, str); - if (err) + if (err) { return err; + } strings.push_back(str); } @@ -726,8 +758,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int int adv = 4 * 2 * count; - if (r_len) + if (r_len) { (*r_len) += adv; + } } r_variant = varray; @@ -760,8 +793,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int int adv = 4 * 3 * count; - if (r_len) + if (r_len) { (*r_len) += adv; + } } r_variant = varray; @@ -795,8 +829,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int int adv = 4 * 4 * count; - if (r_len) + if (r_len) { (*r_len) += adv; + } } r_variant = carray; @@ -927,8 +962,9 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo encode_uint32(uint32_t(np.get_name_count()) | 0x80000000, buf); //for compatibility with the old format encode_uint32(np.get_subname_count(), buf + 4); uint32_t np_flags = 0; - if (np.is_absolute()) + if (np.is_absolute()) { np_flags |= 1; + } encode_uint32(np_flags, buf + 8); @@ -942,17 +978,19 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo for (int i = 0; i < total; i++) { String str; - if (i < np.get_name_count()) + if (i < np.get_name_count()) { str = np.get_name(i); - else + } else { str = np.get_subname(i - np.get_name_count()); + } CharString utf8 = str.utf8(); int pad = 0; - if (utf8.length() % 4) + if (utf8.length() % 4) { pad = 4 - utf8.length() % 4; + } if (buf) { encode_uint32(utf8.length(), buf); @@ -1157,8 +1195,9 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo int pc = 0; for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) + if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) { continue; + } pc++; } @@ -1170,19 +1209,22 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 4; for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) + if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) { continue; + } _encode_string(E->get().name, buf, r_len); int len; Error err = encode_variant(obj->get(E->get().name), buf, len, p_full_objects); - if (err) + if (err) { return err; + } ERR_FAIL_COND_V(len % 4, ERR_BUG); r_len += len; - if (buf) + if (buf) { buf += len; + } } } } else { @@ -1230,15 +1272,17 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo encode_variant(E->get(), buf, len, p_full_objects); ERR_FAIL_COND_V(len % 4, ERR_BUG); r_len += len; - if (buf) + if (buf) { buf += len; + } Variant *v = d.getptr(E->get()); ERR_FAIL_COND_V(!v, ERR_BUG); encode_variant(*v, buf, len, p_full_objects); ERR_FAIL_COND_V(len % 4, ERR_BUG); r_len += len; - if (buf) + if (buf) { buf += len; + } } } break; @@ -1257,8 +1301,9 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo encode_variant(v.get(i), buf, len, p_full_objects); ERR_FAIL_COND_V(len % 4, ERR_BUG); r_len += len; - if (buf) + if (buf) { buf += len; + } } } break; @@ -1279,8 +1324,9 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 4 + datalen * datasize; while (r_len % 4) { r_len++; - if (buf) + if (buf) { *(buf++) = 0; + } } } break; @@ -1293,8 +1339,9 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo encode_uint32(datalen, buf); buf += 4; const int32_t *r = data.ptr(); - for (int32_t i = 0; i < datalen; i++) + for (int32_t i = 0; i < datalen; i++) { encode_uint32(r[i], &buf[i * datasize]); + } } r_len += 4 + datalen * datasize; @@ -1309,8 +1356,9 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo encode_uint64(datalen, buf); buf += 4; const int64_t *r = data.ptr(); - for (int64_t i = 0; i < datalen; i++) + for (int64_t i = 0; i < datalen; i++) { encode_uint64(r[i], &buf[i * datasize]); + } } r_len += 4 + datalen * datasize; @@ -1325,8 +1373,9 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo encode_uint32(datalen, buf); buf += 4; const float *r = data.ptr(); - for (int i = 0; i < datalen; i++) + for (int i = 0; i < datalen; i++) { encode_float(r[i], &buf[i * datasize]); + } } r_len += 4 + datalen * datasize; @@ -1341,8 +1390,9 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo encode_uint32(datalen, buf); buf += 4; const double *r = data.ptr(); - for (int i = 0; i < datalen; i++) + for (int i = 0; i < datalen; i++) { encode_double(r[i], &buf[i * datasize]); + } } r_len += 4 + datalen * datasize; @@ -1372,8 +1422,9 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 4 + utf8.length() + 1; while (r_len % 4) { r_len++; //pad - if (buf) + if (buf) { *(buf++) = 0; + } } } diff --git a/core/io/marshalls.h b/core/io/marshalls.h index 279f782b1a..c21a97ac8a 100644 --- a/core/io/marshalls.h +++ b/core/io/marshalls.h @@ -108,8 +108,9 @@ static inline int encode_cstring(const char *p_string, uint8_t *p_data) { len++; }; - if (p_data) + if (p_data) { *p_data = 0; + } return len + 1; } diff --git a/core/io/multiplayer_api.cpp b/core/io/multiplayer_api.cpp index a2f65660f2..2f17d9e746 100644 --- a/core/io/multiplayer_api.cpp +++ b/core/io/multiplayer_api.cpp @@ -53,8 +53,9 @@ _FORCE_INLINE_ bool _should_call_local(MultiplayerAPI::RPCMode mode, bool is_mas // Do nothing also. Remote cannot produce a local call. } break; case MultiplayerAPI::RPC_MODE_MASTERSYNC: { - if (is_master) + if (is_master) { r_skip_rpc = true; // I am the master, so skip remote call. + } [[fallthrough]]; } case MultiplayerAPI::RPC_MODE_REMOTESYNC: @@ -63,8 +64,9 @@ _FORCE_INLINE_ bool _should_call_local(MultiplayerAPI::RPCMode mode, bool is_mas return true; } break; case MultiplayerAPI::RPC_MODE_MASTER: { - if (is_master) + if (is_master) { r_skip_rpc = true; // I am the master, so skip remote call. + } return is_master; } break; case MultiplayerAPI::RPC_MODE_PUPPET: { @@ -97,13 +99,15 @@ _FORCE_INLINE_ bool _can_call_mode(Node *p_node, MultiplayerAPI::RPCMode mode, i } void MultiplayerAPI::poll() { - if (!network_peer.is_valid() || network_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_DISCONNECTED) + if (!network_peer.is_valid() || network_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_DISCONNECTED) { return; + } network_peer->poll(); - if (!network_peer.is_valid()) // It's possible that polling might have resulted in a disconnection, so check here. + if (!network_peer.is_valid()) { // It's possible that polling might have resulted in a disconnection, so check here. return; + } while (network_peer->get_available_packet_count()) { int sender = network_peer->get_packet_peer(); @@ -139,8 +143,9 @@ void MultiplayerAPI::set_root_node(Node *p_node) { } void MultiplayerAPI::set_network_peer(const Ref<NetworkedMultiplayerPeer> &p_peer) { - if (p_peer == network_peer) + if (p_peer == network_peer) { return; // Nothing to do + } ERR_FAIL_COND_MSG(p_peer.is_valid() && p_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_DISCONNECTED, "Supplied NetworkedMultiplayerPeer must be connecting or connected."); @@ -325,8 +330,9 @@ Node *MultiplayerAPI::_process_get_node(int p_from, const uint8_t *p_packet, uin node = root_node->get_node(np); - if (!node) + if (!node) { ERR_PRINT("Failed to get path from RPC: " + String(np) + "."); + } } else { // Use cached path. int id = p_node_target; @@ -341,8 +347,9 @@ Node *MultiplayerAPI::_process_get_node(int p_from, const uint8_t *p_packet, uin // Do proper caching later. node = root_node->get_node(ni->path); - if (!node) + if (!node) { ERR_PRINT("Failed to get cached path from RPC: " + String(ni->path) + "."); + } } return node; } @@ -529,11 +536,13 @@ bool MultiplayerAPI::_send_confirm_path(Node *p_node, NodePath p_path, PathSentC List<int> peers_to_add; // If one is missing, take note to add it. for (Set<int>::Element *E = connected_peers.front(); E; E = E->next()) { - if (p_target < 0 && E->get() == -p_target) + if (p_target < 0 && E->get() == -p_target) { continue; // Continue, excluded. + } - if (p_target > 0 && E->get() != p_target) + if (p_target > 0 && E->get() != p_target) { continue; // Continue, not for this peer. + } Map<int, bool>::Element *F = psc->confirmed_peers.find(E->get()); @@ -658,8 +667,9 @@ Error MultiplayerAPI::_encode_and_compress_variant(const Variant &p_variant, uin default: // Any other case is not yet compressed. Error err = encode_variant(p_variant, r_buffer, r_len, allow_object_decoding); - if (err != OK) + if (err != OK) { return err; + } if (r_buffer) { // The first byte is not used by the marshaling, so store the type // so we know how to decompress and decode this variant. @@ -684,48 +694,55 @@ Error MultiplayerAPI::_decode_and_decompress_variant(Variant &r_variant, const u case Variant::BOOL: { bool val = (buf[0] & VARIANT_META_BOOL_MASK) > 0; r_variant = val; - if (r_len) + if (r_len) { *r_len = 1; + } } break; case Variant::INT: { buf += 1; len -= 1; - if (r_len) + if (r_len) { *r_len = 1; + } if (encode_mode == ENCODE_8) { // 8 bits. ERR_FAIL_COND_V(len < 1, ERR_INVALID_DATA); int8_t val = buf[0]; r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 1; + } } else if (encode_mode == ENCODE_16) { // 16 bits. ERR_FAIL_COND_V(len < 2, ERR_INVALID_DATA); int16_t val = decode_uint16(buf); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 2; + } } else if (encode_mode == ENCODE_32) { // 32 bits. ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t val = decode_uint32(buf); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4; + } } else { // 64 bits. ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA); int64_t val = decode_uint64(buf); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 8; + } } } break; default: Error err = decode_variant(r_variant, p_buffer, p_len, r_len, allow_object_decoding); - if (err != OK) + if (err != OK) { return err; + } } return OK; @@ -925,11 +942,13 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p encode_cstring(pname.get_data(), &(packet_cache.write[ofs])); for (Set<int>::Element *E = connected_peers.front(); E; E = E->next()) { - if (p_to < 0 && E->get() == -p_to) + if (p_to < 0 && E->get() == -p_to) { continue; // Continue, excluded. + } - if (p_to > 0 && E->get() != p_to) + if (p_to > 0 && E->get() != p_to) { continue; // Continue, not for this peer. + } Map<int, bool>::Element *F = psc->confirmed_peers.find(E->get()); ERR_CONTINUE(!F); // Should never happen. diff --git a/core/io/net_socket.cpp b/core/io/net_socket.cpp index e92bc705ce..130a2e245e 100644 --- a/core/io/net_socket.cpp +++ b/core/io/net_socket.cpp @@ -33,8 +33,9 @@ NetSocket *(*NetSocket::_create)() = nullptr; NetSocket *NetSocket::create() { - if (_create) + if (_create) { return _create(); + } ERR_PRINT("Unable to create network socket, platform not supported"); return nullptr; diff --git a/core/io/packet_peer.cpp b/core/io/packet_peer.cpp index fe1c9a2eb1..6d37d95994 100644 --- a/core/io/packet_peer.cpp +++ b/core/io/packet_peer.cpp @@ -50,24 +50,28 @@ Error PacketPeer::get_packet_buffer(Vector<uint8_t> &r_buffer) { const uint8_t *buffer; int buffer_size; Error err = get_packet(&buffer, buffer_size); - if (err) + if (err) { return err; + } r_buffer.resize(buffer_size); - if (buffer_size == 0) + if (buffer_size == 0) { return OK; + } uint8_t *w = r_buffer.ptrw(); - for (int i = 0; i < buffer_size; i++) + for (int i = 0; i < buffer_size; i++) { w[i] = buffer[i]; + } return OK; } Error PacketPeer::put_packet_buffer(const Vector<uint8_t> &p_buffer) { int len = p_buffer.size(); - if (len == 0) + if (len == 0) { return OK; + } const uint8_t *r = p_buffer.ptr(); return put_packet(&r[0], len); @@ -77,8 +81,9 @@ Error PacketPeer::get_var(Variant &r_variant, bool p_allow_objects) { const uint8_t *buffer; int buffer_size; Error err = get_packet(&buffer, buffer_size); - if (err) + if (err) { return err; + } return decode_variant(r_variant, buffer, buffer_size, nullptr, p_allow_objects); } @@ -86,11 +91,13 @@ Error PacketPeer::get_var(Variant &r_variant, bool p_allow_objects) { Error PacketPeer::put_var(const Variant &p_packet, bool p_full_objects) { int len; Error err = encode_variant(p_packet, nullptr, len, p_full_objects); // compute len first - if (err) + if (err) { return err; + } - if (len == 0) + if (len == 0) { return OK; + } ERR_FAIL_COND_V_MSG(len > encode_buffer_max_size, ERR_OUT_OF_MEMORY, "Failed to encode variant, encode size is bigger then encode_buffer_max_size. Consider raising it via 'set_encode_buffer_max_size'."); @@ -168,10 +175,12 @@ Error PacketPeerStream::_poll_buffer() const { int read = 0; ERR_FAIL_COND_V(input_buffer.size() < ring_buffer.space_left(), ERR_UNAVAILABLE); Error err = peer->get_partial_data(input_buffer.ptrw(), ring_buffer.space_left(), read); - if (err) + if (err) { return err; - if (read == 0) + } + if (read == 0) { return OK; + } int w = ring_buffer.write(&input_buffer[0], read); ERR_FAIL_COND_V(w != read, ERR_BUG); @@ -193,8 +202,9 @@ int PacketPeerStream::get_available_packet_count() const { uint32_t len = decode_uint32(lbuf); remaining -= 4; ofs += 4; - if (len > remaining) + if (len > remaining) { break; + } remaining -= len; ofs += len; count++; @@ -228,19 +238,22 @@ Error PacketPeerStream::put_packet(const uint8_t *p_buffer, int p_buffer_size) { ERR_FAIL_COND_V(peer.is_null(), ERR_UNCONFIGURED); Error err = _poll_buffer(); //won't hurt to poll here too - if (err) + if (err) { return err; + } - if (p_buffer_size == 0) + if (p_buffer_size == 0) { return OK; + } ERR_FAIL_COND_V(p_buffer_size < 0, ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(p_buffer_size + 4 > output_buffer.size(), ERR_INVALID_PARAMETER); encode_uint32(p_buffer_size, output_buffer.ptrw()); uint8_t *dst = &output_buffer.write[4]; - for (int i = 0; i < p_buffer_size; i++) + for (int i = 0; i < p_buffer_size; i++) { dst[i] = p_buffer[i]; + } return peer->put_data(&output_buffer[0], p_buffer_size + 4); } diff --git a/core/io/packet_peer_udp.cpp b/core/io/packet_peer_udp.cpp index e36de8c228..862fca96fc 100644 --- a/core/io/packet_peer_udp.cpp +++ b/core/io/packet_peer_udp.cpp @@ -38,8 +38,9 @@ void PacketPeerUDP::set_blocking_mode(bool p_enable) { void PacketPeerUDP::set_broadcast_enabled(bool p_enabled) { broadcast = p_enabled; - if (_sock.is_valid() && _sock->is_open()) + if (_sock.is_valid() && _sock->is_open()) { _sock->set_broadcasting_enabled(p_enabled); + } } Error PacketPeerUDP::join_multicast_group(IP_Address p_multi_address, String p_if_name) { @@ -72,8 +73,9 @@ Error PacketPeerUDP::_set_dest_address(const String &p_address, int p_port) { ip = p_address; } else { ip = IP::get_singleton()->resolve_hostname(p_address); - if (!ip.is_valid()) + if (!ip.is_valid()) { return ERR_CANT_RESOLVE; + } } set_dest_address(ip, p_port); @@ -83,18 +85,21 @@ Error PacketPeerUDP::_set_dest_address(const String &p_address, int p_port) { int PacketPeerUDP::get_available_packet_count() const { // TODO we should deprecate this, and expose poll instead! Error err = const_cast<PacketPeerUDP *>(this)->_poll(); - if (err != OK) + if (err != OK) { return -1; + } return queue_count; } Error PacketPeerUDP::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { Error err = _poll(); - if (err != OK) + if (err != OK) { return err; - if (queue_count == 0) + } + if (queue_count == 0) { return ERR_UNAVAILABLE; + } uint32_t size = 0; uint8_t ipv6[16]; @@ -131,10 +136,11 @@ Error PacketPeerUDP::put_packet(const uint8_t *p_buffer, int p_buffer_size) { err = _sock->sendto(p_buffer, p_buffer_size, sent, peer_addr, peer_port); } if (err != OK) { - if (err != ERR_BUSY) + if (err != ERR_BUSY) { return FAILED; - else if (!blocking) + } else if (!blocking) { return ERR_BUSY; + } // Keep trying to send full packet continue; } @@ -157,13 +163,15 @@ Error PacketPeerUDP::listen(int p_port, const IP_Address &p_bind_address, int p_ Error err; IP::Type ip_type = IP::TYPE_ANY; - if (p_bind_address.is_valid()) + if (p_bind_address.is_valid()) { ip_type = p_bind_address.is_ipv4() ? IP::TYPE_IPV4 : IP::TYPE_IPV6; + } err = _sock->open(NetSocket::TYPE_UDP, ip_type); - if (err != OK) + if (err != OK) { return ERR_CANT_CREATE; + } _sock->set_blocking_enabled(false); _sock->set_reuse_address_enabled(true); @@ -235,8 +243,9 @@ bool PacketPeerUDP::is_connected_to_host() const { } void PacketPeerUDP::close() { - if (_sock.is_valid()) + if (_sock.is_valid()) { _sock->close(); + } rb.resize(16); queue_count = 0; connected = false; @@ -269,8 +278,9 @@ Error PacketPeerUDP::_poll() { } if (err != OK) { - if (err == ERR_BUSY) + if (err == ERR_BUSY) { break; + } return FAILED; } diff --git a/core/io/pck_packer.cpp b/core/io/pck_packer.cpp index 4863cd1dbb..06d22ce897 100644 --- a/core/io/pck_packer.cpp +++ b/core/io/pck_packer.cpp @@ -35,14 +35,16 @@ #include "core/version.h" static uint64_t _align(uint64_t p_n, int p_alignment) { - if (p_alignment == 0) + if (p_alignment == 0) { return p_n; + } uint64_t rest = p_n % p_alignment; - if (rest == 0) + if (rest == 0) { return p_n; - else + } else { return p_n + (p_alignment - rest); + } }; static void _pad(FileAccess *p_file, int p_bytes) { @@ -160,8 +162,9 @@ Error PCKPacker::flush(bool p_verbose) { }; }; - if (p_verbose) + if (p_verbose) { printf("\n"); + } file->close(); memdelete_arr(buf); diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index 230925c29b..5097f6d98b 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -96,8 +96,9 @@ enum { void ResourceLoaderBinary::_advance_padding(uint32_t p_len) { uint32_t extra = 4 - (p_len % 4); if (extra < 4) { - for (uint32_t i = 0; i < extra; i++) + for (uint32_t i = 0; i < extra; i++) { f->get_8(); //pad to 32 + } } } @@ -108,8 +109,9 @@ StringName ResourceLoaderBinary::_get_string() { if ((int)len > str_buf.size()) { str_buf.resize(len); } - if (len == 0) + if (len == 0) { return StringName(); + } f->get_buffer((uint8_t *)&str_buf[0], len); String s; s.parse_utf8(&str_buf[0]); @@ -286,10 +288,12 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { subname_count += 1; // has a property field, so we should count it as well } - for (int i = 0; i < name_count; i++) + for (int i = 0; i < name_count; i++) { names.push_back(_get_string()); - for (uint32_t i = 0; i < subname_count; i++) + } + for (uint32_t i = 0; i < subname_count; i++) { subnames.push_back(_get_string()); + } NodePath np = NodePath(names, subnames, absolute); @@ -512,8 +516,9 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { Vector<String> array; array.resize(len); String *w = array.ptrw(); - for (uint32_t i = 0; i < len; i++) + for (uint32_t i = 0; i < len; i++) { w[i] = get_unicode_string(); + } r_v = array; @@ -609,8 +614,9 @@ Ref<Resource> ResourceLoaderBinary::get_resource() { } Error ResourceLoaderBinary::load() { - if (error != OK) + if (error != OK) { return error; + } int stage = 0; @@ -680,8 +686,9 @@ Error ResourceLoaderBinary::load() { } } } else { - if (!use_nocache && !ResourceCache::has(res_path)) + if (!use_nocache && !ResourceCache::has(res_path)) { path = res_path; + } } uint64_t offset = internal_resources[i].offset; @@ -730,8 +737,9 @@ Error ResourceLoaderBinary::load() { Variant value; error = parse_variant(value); - if (error) + if (error) { return error; + } res->set(name, value); } @@ -783,8 +791,9 @@ String ResourceLoaderBinary::get_unicode_string() { if (len > str_buf.size()) { str_buf.resize(len); } - if (len == 0) + if (len == 0) { return String(); + } f->get_buffer((uint8_t *)&str_buf[0], len); String s; s.parse_utf8(&str_buf[0]); @@ -793,8 +802,9 @@ String ResourceLoaderBinary::get_unicode_string() { void ResourceLoaderBinary::get_dependencies(FileAccess *p_f, List<String> *p_dependencies, bool p_add_types) { open(p_f); - if (error) + if (error) { return; + } for (int i = 0; i < external_resources.size(); i++) { String dep = external_resources[i].path; @@ -861,8 +871,9 @@ void ResourceLoaderBinary::open(FileAccess *p_f) { print_bl("type: " + type); importmd_ofs = f->get_64(); - for (int i = 0; i < 14; i++) + for (int i = 0; i < 14; i++) { f->get_32(); //skip a few reserved fields + } uint32_t string_table_size = f->get_32(); string_map.resize(string_table_size); @@ -946,13 +957,15 @@ String ResourceLoaderBinary::recognize(FileAccess *p_f) { } ResourceLoaderBinary::~ResourceLoaderBinary() { - if (f) + if (f) { memdelete(f); + } } RES ResourceFormatLoaderBinary::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { - if (r_error) + if (r_error) { *r_error = ERR_FILE_CANT_OPEN; + } Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); @@ -1240,8 +1253,9 @@ String ResourceFormatLoaderBinary::get_resource_type(const String &p_path) const void ResourceFormatSaverBinaryInstance::_pad_buffer(FileAccess *f, int p_bytes) { int extra = 4 - (p_bytes % 4); if (extra < 4) { - for (int i = 0; i < extra; i++) + for (int i = 0; i < extra; i++) { f->store_8(0); //pad to 32 + } } } @@ -1430,8 +1444,9 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia NodePath np = p_property; f->store_16(np.get_name_count()); uint16_t snc = np.get_subname_count(); - if (np.is_absolute()) + if (np.is_absolute()) { snc |= 0x8000; + } f->store_16(snc); for (int i = 0; i < np.get_name_count(); i++) { if (string_map.has(np.get_name(i))) { @@ -1531,8 +1546,9 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia int len = arr.size(); f->store_32(len); const int32_t *r = arr.ptr(); - for (int i = 0; i < len; i++) + for (int i = 0; i < len; i++) { f->store_32(r[i]); + } } break; case Variant::PACKED_INT64_ARRAY: { @@ -1541,8 +1557,9 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia int len = arr.size(); f->store_32(len); const int64_t *r = arr.ptr(); - for (int i = 0; i < len; i++) + for (int i = 0; i < len; i++) { f->store_64(r[i]); + } } break; case Variant::PACKED_FLOAT32_ARRAY: { @@ -1628,8 +1645,9 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant case Variant::OBJECT: { RES res = p_variant; - if (res.is_null() || external_resources.has(res)) + if (res.is_null() || external_resources.has(res)) { return; + } if (!p_main && (!bundle_resources) && res->get_path().length() && res->get_path().find("::") == -1) { if (res->get_path() == path) { @@ -1641,8 +1659,9 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant return; } - if (resource_set.has(res)) + if (resource_set.has(res)) { return; + } List<PropertyInfo> property_list; @@ -1695,10 +1714,12 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant case Variant::NODE_PATH: { //take the chance and save node path strings NodePath np = p_variant; - for (int i = 0; i < np.get_name_count(); i++) + for (int i = 0; i < np.get_name_count(); i++) { get_string_index(np.get_name(i)); - for (int i = 0; i < np.get_subname_count(); i++) + } + for (int i = 0; i < np.get_subname_count(); i++) { get_string_index(np.get_subname(i)); + } } break; default: { @@ -1718,8 +1739,9 @@ void ResourceFormatSaverBinaryInstance::save_unicode_string(FileAccess *f, const int ResourceFormatSaverBinaryInstance::get_string_index(const String &p_string) { StringName s = p_string; - if (string_map.has(s)) + if (string_map.has(s)) { return string_map[s]; + } string_map[s] = strings.size(); strings.push_back(s); @@ -1733,8 +1755,9 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p fac->configure("RSCC"); f = fac; err = fac->_open(p_path, FileAccess::WRITE); - if (err) + if (err) { memdelete(f); + } } else { f = FileAccess::open(p_path, FileAccess::WRITE, &err); @@ -1748,8 +1771,9 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p big_endian = p_flags & ResourceSaver::FLAG_SAVE_BIG_ENDIAN; takeover_paths = p_flags & ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS; - if (!p_path.begins_with("res://")) + if (!p_path.begins_with("res://")) { takeover_paths = false; + } local_path = p_path.get_base_dir(); path = ProjectSettings::get_singleton()->localize_path(p_path); @@ -1765,8 +1789,9 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p if (big_endian) { f->store_32(1); f->set_endian_swap(true); - } else + } else { f->store_32(0); + } f->store_32(0); //64 bits file, false for now f->store_32(VERSION_MAJOR); @@ -1781,8 +1806,9 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p save_unicode_string(f, p_resource->get_class()); f->store_64(0); //offset to import metadata - for (int i = 0; i < 14; i++) + for (int i = 0; i < 14; i++) { f->store_32(0); // reserved + } List<ResourceData> resources; @@ -1795,8 +1821,9 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p E->get()->get_property_list(&property_list); for (List<PropertyInfo>::Element *F = property_list.front(); F; F = F->next()) { - if (skip_editor && F->get().name.begins_with("__editor")) + if (skip_editor && F->get().name.begins_with("__editor")) { continue; + } if ((F->get().usage & PROPERTY_USAGE_STORAGE)) { Property p; p.name_idx = get_string_index(F->get().name); @@ -1942,8 +1969,9 @@ bool ResourceFormatSaverBinary::recognize(const RES &p_resource) const { void ResourceFormatSaverBinary::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const { String base = p_resource->get_base_extension().to_lower(); p_extensions->push_back(base); - if (base != "res") + if (base != "res") { p_extensions->push_back("res"); + } } ResourceFormatSaverBinary *ResourceFormatSaverBinary::singleton = nullptr; diff --git a/core/io/resource_importer.cpp b/core/io/resource_importer.cpp index c2e27bc9c2..9ed159bd20 100644 --- a/core/io/resource_importer.cpp +++ b/core/io/resource_importer.cpp @@ -120,8 +120,9 @@ RES ResourceFormatImporter::load(const String &p_path, const String &p_original_ Error err = _get_path_and_type(p_path, pat); if (err != OK) { - if (r_error) + if (r_error) { *r_error = err; + } return RES(); } @@ -163,11 +164,13 @@ void ResourceFormatImporter::get_recognized_extensions_for_type(const String &p_ for (int i = 0; i < importers.size(); i++) { String res_type = importers[i]->get_resource_type(); - if (res_type == String()) + if (res_type == String()) { continue; + } - if (!ClassDB::is_parent_class(res_type, p_type)) + if (!ClassDB::is_parent_class(res_type, p_type)) { continue; + } List<String> local_exts; importers[i]->get_recognized_extensions(&local_exts); @@ -206,8 +209,9 @@ int ResourceFormatImporter::get_import_order(const String &p_path) const { importer = get_importer_by_extension(p_path.get_extension().to_lower()); } - if (importer.is_valid()) + if (importer.is_valid()) { return importer->get_import_order(); + } return 0; } @@ -215,10 +219,12 @@ int ResourceFormatImporter::get_import_order(const String &p_path) const { bool ResourceFormatImporter::handles_type(const String &p_type) const { for (int i = 0; i < importers.size(); i++) { String res_type = importers[i]->get_resource_type(); - if (res_type == String()) + if (res_type == String()) { continue; - if (ClassDB::is_parent_class(res_type, p_type)) + } + if (ClassDB::is_parent_class(res_type, p_type)) { return true; + } } return true; @@ -239,8 +245,9 @@ void ResourceFormatImporter::get_internal_resource_path_list(const String &p_pat Error err; FileAccess *f = FileAccess::open(p_path + ".import", FileAccess::READ, &err); - if (!f) + if (!f) { return; + } VariantParser::StreamFile stream; stream.f = f; diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index 8490cb5627..f9d2c9067c 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -59,8 +59,9 @@ bool ResourceFormatLoader::recognize_path(const String &p_path, const String &p_ } for (List<String>::Element *E = extensions.front(); E; E = E->next()) { - if (E->get().nocasecmp_to(extension) == 0) + if (E->get().nocasecmp_to(extension) == 0) { return true; + } } return false; @@ -84,8 +85,9 @@ String ResourceFormatLoader::get_resource_type(const String &p_path) const { } void ResourceFormatLoader::get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const { - if (p_type == "" || handles_type(p_type)) + if (p_type == "" || handles_type(p_type)) { get_recognized_extensions(p_extensions); + } } void ResourceLoader::get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) { @@ -116,12 +118,14 @@ RES ResourceFormatLoader::load(const String &p_path, const String &p_original_pa Variant res = get_script_instance()->call("load", p_path, p_original_path, p_use_sub_threads); if (res.get_type() == Variant::INT) { - if (r_error) + if (r_error) { *r_error = (Error)res.operator int64_t(); + } } else { - if (r_error) + if (r_error) { *r_error = OK; + } return res; } @@ -240,8 +244,9 @@ void ResourceLoader::_thread_load_function(void *p_userdata) { if (load_task.resource.is_valid()) { load_task.resource->set_path(load_task.local_path); - if (load_task.xl_remapped) + if (load_task.xl_remapped) { load_task.resource->set_as_translation_remapped(true); + } #ifdef TOOLS_ENABLED @@ -263,10 +268,11 @@ void ResourceLoader::_thread_load_function(void *p_userdata) { Error ResourceLoader::load_threaded_request(const String &p_path, const String &p_type_hint, bool p_use_sub_threads, const String &p_source_resource) { String local_path; - if (p_path.is_rel_path()) + if (p_path.is_rel_path()) { local_path = "res://" + p_path; - else + } else { local_path = ProjectSettings::get_singleton()->localize_path(p_path); + } thread_load_mutex->lock(); @@ -392,10 +398,11 @@ float ResourceLoader::_dependency_get_progress(const String &p_path) { ResourceLoader::ThreadLoadStatus ResourceLoader::load_threaded_get_status(const String &p_path, float *r_progress) { String local_path; - if (p_path.is_rel_path()) + if (p_path.is_rel_path()) { local_path = "res://" + p_path; - else + } else { local_path = ProjectSettings::get_singleton()->localize_path(p_path); + } thread_load_mutex->lock(); if (!thread_load_tasks.has(local_path)) { @@ -416,10 +423,11 @@ ResourceLoader::ThreadLoadStatus ResourceLoader::load_threaded_get_status(const RES ResourceLoader::load_threaded_get(const String &p_path, Error *r_error) { String local_path; - if (p_path.is_rel_path()) + if (p_path.is_rel_path()) { local_path = "res://" + p_path; - else + } else { local_path = ProjectSettings::get_singleton()->localize_path(p_path); + } thread_load_mutex->lock(); if (!thread_load_tasks.has(local_path)) { @@ -496,14 +504,16 @@ RES ResourceLoader::load_threaded_get(const String &p_path, Error *r_error) { } RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p_no_cache, Error *r_error) { - if (r_error) + if (r_error) { *r_error = ERR_CANT_OPEN; + } String local_path; - if (p_path.is_rel_path()) + if (p_path.is_rel_path()) { local_path = "res://" + p_path; - else + } else { local_path = ProjectSettings::get_singleton()->localize_path(p_path); + } if (!p_no_cache) { thread_load_mutex->lock(); @@ -586,8 +596,9 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p return RES(); } - if (xl_remapped) + if (xl_remapped) { res->set_as_translation_remapped(true); + } #ifdef TOOLS_ENABLED @@ -605,10 +616,11 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p bool ResourceLoader::exists(const String &p_path, const String &p_type_hint) { String local_path; - if (p_path.is_rel_path()) + if (p_path.is_rel_path()) { local_path = "res://" + p_path; - else + } else { local_path = ProjectSettings::get_singleton()->localize_path(p_path); + } if (ResourceCache::has(local_path)) { return true; // If cached, it probably exists @@ -623,8 +635,9 @@ bool ResourceLoader::exists(const String &p_path, const String &p_type_hint) { continue; } - if (loader[i]->exists(path)) + if (loader[i]->exists(path)) { return true; + } } return false; @@ -651,8 +664,9 @@ void ResourceLoader::remove_resource_format_loader(Ref<ResourceFormatLoader> p_f // Find loader int i = 0; for (; i < loader_count; ++i) { - if (loader[i] == p_format_loader) + if (loader[i] == p_format_loader) { break; + } } ERR_FAIL_COND(i >= loader_count); // Not found @@ -669,14 +683,16 @@ int ResourceLoader::get_import_order(const String &p_path) { String path = _path_remap(p_path); String local_path; - if (path.is_rel_path()) + if (path.is_rel_path()) { local_path = "res://" + path; - else + } else { local_path = ProjectSettings::get_singleton()->localize_path(path); + } for (int i = 0; i < loader_count; i++) { - if (!loader[i]->recognize_path(local_path)) + if (!loader[i]->recognize_path(local_path)) { continue; + } /* if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint)) continue; @@ -692,14 +708,16 @@ String ResourceLoader::get_import_group_file(const String &p_path) { String path = _path_remap(p_path); String local_path; - if (path.is_rel_path()) + if (path.is_rel_path()) { local_path = "res://" + path; - else + } else { local_path = ProjectSettings::get_singleton()->localize_path(path); + } for (int i = 0; i < loader_count; i++) { - if (!loader[i]->recognize_path(local_path)) + if (!loader[i]->recognize_path(local_path)) { continue; + } /* if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint)) continue; @@ -715,14 +733,16 @@ bool ResourceLoader::is_import_valid(const String &p_path) { String path = _path_remap(p_path); String local_path; - if (path.is_rel_path()) + if (path.is_rel_path()) { local_path = "res://" + path; - else + } else { local_path = ProjectSettings::get_singleton()->localize_path(path); + } for (int i = 0; i < loader_count; i++) { - if (!loader[i]->recognize_path(local_path)) + if (!loader[i]->recognize_path(local_path)) { continue; + } /* if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint)) continue; @@ -738,14 +758,16 @@ bool ResourceLoader::is_imported(const String &p_path) { String path = _path_remap(p_path); String local_path; - if (path.is_rel_path()) + if (path.is_rel_path()) { local_path = "res://" + path; - else + } else { local_path = ProjectSettings::get_singleton()->localize_path(path); + } for (int i = 0; i < loader_count; i++) { - if (!loader[i]->recognize_path(local_path)) + if (!loader[i]->recognize_path(local_path)) { continue; + } /* if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint)) continue; @@ -761,14 +783,16 @@ void ResourceLoader::get_dependencies(const String &p_path, List<String> *p_depe String path = _path_remap(p_path); String local_path; - if (path.is_rel_path()) + if (path.is_rel_path()) { local_path = "res://" + path; - else + } else { local_path = ProjectSettings::get_singleton()->localize_path(path); + } for (int i = 0; i < loader_count; i++) { - if (!loader[i]->recognize_path(local_path)) + if (!loader[i]->recognize_path(local_path)) { continue; + } /* if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint)) continue; @@ -782,14 +806,16 @@ Error ResourceLoader::rename_dependencies(const String &p_path, const Map<String String path = _path_remap(p_path); String local_path; - if (path.is_rel_path()) + if (path.is_rel_path()) { local_path = "res://" + path; - else + } else { local_path = ProjectSettings::get_singleton()->localize_path(path); + } for (int i = 0; i < loader_count; i++) { - if (!loader[i]->recognize_path(local_path)) + if (!loader[i]->recognize_path(local_path)) { continue; + } /* if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint)) continue; @@ -803,10 +829,11 @@ Error ResourceLoader::rename_dependencies(const String &p_path, const Map<String String ResourceLoader::get_resource_type(const String &p_path) { String local_path; - if (p_path.is_rel_path()) + if (p_path.is_rel_path()) { local_path = "res://" + p_path; - else + } else { local_path = ProjectSettings::get_singleton()->localize_path(p_path); + } for (int i = 0; i < loader_count; i++) { String result = loader[i]->get_resource_type(local_path); @@ -951,8 +978,9 @@ void ResourceLoader::reload_translation_remaps() { } void ResourceLoader::load_translation_remaps() { - if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps")) + if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps")) { return; + } Dictionary remaps = ProjectSettings::get_singleton()->get("locale/translation_remaps"); List<Variant> keys; @@ -974,8 +1002,9 @@ void ResourceLoader::clear_translation_remaps() { } void ResourceLoader::load_path_remaps() { - if (!ProjectSettings::get_singleton()->has_setting("path_remap/remapped_paths")) + if (!ProjectSettings::get_singleton()->has_setting("path_remap/remapped_paths")) { return; + } Vector<String> remaps = ProjectSettings::get_singleton()->get("path_remap/remapped_paths"); int rc = remaps.size(); @@ -1007,8 +1036,9 @@ Ref<ResourceFormatLoader> ResourceLoader::_find_custom_resource_format_loader(St } bool ResourceLoader::add_custom_resource_format_loader(String script_path) { - if (_find_custom_resource_format_loader(script_path).is_valid()) + if (_find_custom_resource_format_loader(script_path).is_valid()) { return false; + } Ref<Resource> res = ResourceLoader::load(script_path); ERR_FAIL_COND_V(res.is_null(), false); @@ -1032,8 +1062,9 @@ bool ResourceLoader::add_custom_resource_format_loader(String script_path) { void ResourceLoader::remove_custom_resource_format_loader(String script_path) { Ref<ResourceFormatLoader> custom_loader = _find_custom_resource_format_loader(script_path); - if (custom_loader.is_valid()) + if (custom_loader.is_valid()) { remove_resource_format_loader(custom_loader); + } } void ResourceLoader::add_custom_loaders() { diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h index 7d1c4b5d90..9322b5273a 100644 --- a/core/io/resource_loader.h +++ b/core/io/resource_loader.h @@ -158,8 +158,9 @@ public: static bool get_timestamp_on_load() { return timestamp_on_load; } static void notify_load_error(const String &p_err) { - if (err_notify) + if (err_notify) { err_notify(err_notify_ud, p_err); + } } static void set_error_notify_func(void *p_ud, ResourceLoadErrorNotify p_err_notify) { err_notify = p_err_notify; @@ -167,8 +168,9 @@ public: } static void notify_dependency_error(const String &p_path, const String &p_dependency, const String &p_type) { - if (dep_err_notify) + if (dep_err_notify) { dep_err_notify(dep_err_notify_ud, p_path, p_dependency, p_type); + } } static void set_dependency_error_notify_func(void *p_ud, DependencyErrorNotify p_err_notify) { dep_err_notify = p_err_notify; diff --git a/core/io/resource_saver.cpp b/core/io/resource_saver.cpp index 445f9d0c37..a8da215b61 100644 --- a/core/io/resource_saver.cpp +++ b/core/io/resource_saver.cpp @@ -86,28 +86,32 @@ Error ResourceSaver::save(const String &p_path, const RES &p_resource, uint32_t Error err = ERR_FILE_UNRECOGNIZED; for (int i = 0; i < saver_count; i++) { - if (!saver[i]->recognize(p_resource)) + if (!saver[i]->recognize(p_resource)) { continue; + } List<String> extensions; bool recognized = false; saver[i]->get_recognized_extensions(p_resource, &extensions); for (List<String>::Element *E = extensions.front(); E; E = E->next()) { - if (E->get().nocasecmp_to(extension) == 0) + if (E->get().nocasecmp_to(extension) == 0) { recognized = true; + } } - if (!recognized) + if (!recognized) { continue; + } String old_path = p_resource->get_path(); String local_path = ProjectSettings::get_singleton()->localize_path(p_path); RES rwcopy = p_resource; - if (p_flags & FLAG_CHANGE_PATH) + if (p_flags & FLAG_CHANGE_PATH) { rwcopy->set_path(local_path); + } err = saver[i]->save(p_path, p_resource, p_flags); @@ -122,11 +126,13 @@ Error ResourceSaver::save(const String &p_path, const RES &p_resource, uint32_t } #endif - if (p_flags & FLAG_CHANGE_PATH) + if (p_flags & FLAG_CHANGE_PATH) { rwcopy->set_path(old_path); + } - if (save_callback && p_path.begins_with("res://")) + if (save_callback && p_path.begins_with("res://")) { save_callback(p_resource, p_path); + } return OK; } @@ -166,8 +172,9 @@ void ResourceSaver::remove_resource_format_saver(Ref<ResourceFormatSaver> p_form // Find saver int i = 0; for (; i < saver_count; ++i) { - if (saver[i] == p_format_saver) + if (saver[i] == p_format_saver) { break; + } } ERR_FAIL_COND(i >= saver_count); // Not found @@ -190,8 +197,9 @@ Ref<ResourceFormatSaver> ResourceSaver::_find_custom_resource_format_saver(Strin } bool ResourceSaver::add_custom_resource_format_saver(String script_path) { - if (_find_custom_resource_format_saver(script_path).is_valid()) + if (_find_custom_resource_format_saver(script_path).is_valid()) { return false; + } Ref<Resource> res = ResourceLoader::load(script_path); ERR_FAIL_COND_V(res.is_null(), false); @@ -215,8 +223,9 @@ bool ResourceSaver::add_custom_resource_format_saver(String script_path) { void ResourceSaver::remove_custom_resource_format_saver(String script_path) { Ref<ResourceFormatSaver> custom_saver = _find_custom_resource_format_saver(script_path); - if (custom_saver.is_valid()) + if (custom_saver.is_valid()) { remove_resource_format_saver(custom_saver); + } } void ResourceSaver::add_custom_savers() { diff --git a/core/io/stream_peer.cpp b/core/io/stream_peer.cpp index e6175e78da..403f61bb24 100644 --- a/core/io/stream_peer.cpp +++ b/core/io/stream_peer.cpp @@ -34,8 +34,9 @@ Error StreamPeer::_put_data(const Vector<uint8_t> &p_data) { int len = p_data.size(); - if (len == 0) + if (len == 0) { return OK; + } const uint8_t *r = p_data.ptr(); return put_data(&r[0], len); } @@ -318,8 +319,9 @@ double StreamPeer::get_double() { } String StreamPeer::get_string(int p_bytes) { - if (p_bytes < 0) + if (p_bytes < 0) { p_bytes = get_u32(); + } ERR_FAIL_COND_V(p_bytes < 0, String()); Vector<char> buf; @@ -332,8 +334,9 @@ String StreamPeer::get_string(int p_bytes) { } String StreamPeer::get_utf8_string(int p_bytes) { - if (p_bytes < 0) + if (p_bytes < 0) { p_bytes = get_u32(); + } ERR_FAIL_COND_V(p_bytes < 0, String()); Vector<uint8_t> buf; @@ -421,8 +424,9 @@ void StreamPeerBuffer::_bind_methods() { } Error StreamPeerBuffer::put_data(const uint8_t *p_data, int p_bytes) { - if (p_bytes <= 0) + if (p_bytes <= 0) { return OK; + } if (pointer + p_bytes > data.size()) { data.resize(pointer + p_bytes); @@ -443,8 +447,9 @@ Error StreamPeerBuffer::put_partial_data(const uint8_t *p_data, int p_bytes, int Error StreamPeerBuffer::get_data(uint8_t *p_buffer, int p_bytes) { int recv; get_partial_data(p_buffer, p_bytes, recv); - if (recv != p_bytes) + if (recv != p_bytes) { return ERR_INVALID_PARAMETER; + } return OK; } diff --git a/core/io/stream_peer_ssl.cpp b/core/io/stream_peer_ssl.cpp index 92c775a565..3dc31c6769 100644 --- a/core/io/stream_peer_ssl.cpp +++ b/core/io/stream_peer_ssl.cpp @@ -35,8 +35,9 @@ StreamPeerSSL *(*StreamPeerSSL::_create)() = nullptr; StreamPeerSSL *StreamPeerSSL::create() { - if (_create) + if (_create) { return _create(); + } return nullptr; } diff --git a/core/io/stream_peer_tcp.cpp b/core/io/stream_peer_tcp.cpp index fd7ffa8458..cce728c30a 100644 --- a/core/io/stream_peer_tcp.cpp +++ b/core/io/stream_peer_tcp.cpp @@ -117,8 +117,9 @@ Error StreamPeerTCP::write(const uint8_t *p_data, int p_bytes, int &r_sent, bool } } - if (!_sock->is_open()) + if (!_sock->is_open()) { return FAILED; + } Error err; int data_to_send = p_bytes; @@ -257,8 +258,9 @@ StreamPeerTCP::Status StreamPeerTCP::get_status() { } void StreamPeerTCP::disconnect_from_host() { - if (_sock.is_valid() && _sock->is_open()) + if (_sock.is_valid() && _sock->is_open()) { _sock->close(); + } timeout = 0; status = STATUS_NONE; @@ -308,8 +310,9 @@ Error StreamPeerTCP::_connect(const String &p_address, int p_port) { ip = p_address; } else { ip = IP::get_singleton()->resolve_hostname(p_address); - if (!ip.is_valid()) + if (!ip.is_valid()) { return ERR_CANT_RESOLVE; + } } return connect_to_host(ip, p_port); diff --git a/core/io/tcp_server.cpp b/core/io/tcp_server.cpp index 706c650d7e..d7061b6bf4 100644 --- a/core/io/tcp_server.cpp +++ b/core/io/tcp_server.cpp @@ -47,8 +47,9 @@ Error TCP_Server::listen(uint16_t p_port, const IP_Address &p_bind_address) { IP::Type ip_type = IP::TYPE_ANY; // If the bind address is valid use its type as the socket type - if (p_bind_address.is_valid()) + if (p_bind_address.is_valid()) { ip_type = p_bind_address.is_ipv4() ? IP::TYPE_IPV4 : IP::TYPE_IPV6; + } err = _sock->open(NetSocket::TYPE_TCP, ip_type); @@ -82,8 +83,9 @@ bool TCP_Server::is_listening() const { bool TCP_Server::is_connection_available() const { ERR_FAIL_COND_V(!_sock.is_valid(), false); - if (!_sock->is_open()) + if (!_sock->is_open()) { return false; + } Error err = _sock->poll(NetSocket::POLL_TYPE_IN, 0); return (err == OK); @@ -99,8 +101,9 @@ Ref<StreamPeerTCP> TCP_Server::take_connection() { IP_Address ip; uint16_t port = 0; ns = _sock->accept(ip, port); - if (!ns.is_valid()) + if (!ns.is_valid()) { return conn; + } conn = Ref<StreamPeerTCP>(memnew(StreamPeerTCP)); conn->accept_socket(ns, ip, port); diff --git a/core/io/translation_loader_po.cpp b/core/io/translation_loader_po.cpp index 5e109699f5..0e0a948953 100644 --- a/core/io/translation_loader_po.cpp +++ b/core/io/translation_loader_po.cpp @@ -47,8 +47,9 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) { String msg_str; String config; - if (r_error) + if (r_error) { *r_error = ERR_FILE_CORRUPT; + } Ref<Translation> translation = Ref<Translation>(memnew(Translation)); int line = 1; @@ -77,10 +78,12 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) { } if (msg_id != "") { - if (!skip_this) + if (!skip_this) { translation->add_message(msg_id, msg_str); - } else if (config == "") + } + } else if (config == "") { config = msg_str; + } l = l.substr(5, l.length()).strip_edges(); status = STATUS_READING_ID; @@ -135,10 +138,11 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) { l = l.substr(0, end_pos); l = l.c_unescape(); - if (status == STATUS_READING_ID) + if (status == STATUS_READING_ID) { msg_id += l; - else + } else { msg_str += l; + } line++; } @@ -148,10 +152,12 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) { if (status == STATUS_READING_STRING) { if (msg_id != "") { - if (!skip_this) + if (!skip_this) { translation->add_message(msg_id, msg_str); - } else if (config == "") + } + } else if (config == "") { config = msg_str; + } } ERR_FAIL_COND_V_MSG(config == "", RES(), "No config found in file: " + f->get_path() + "."); @@ -160,8 +166,9 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) { for (int i = 0; i < configs.size(); i++) { String c = configs[i].strip_edges(); int p = c.find(":"); - if (p == -1) + if (p == -1) { continue; + } String prop = c.substr(0, p).strip_edges(); String value = c.substr(p + 1, c.length()).strip_edges(); @@ -170,15 +177,17 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) { } } - if (r_error) + if (r_error) { *r_error = OK; + } return translation; } RES TranslationLoaderPO::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { - if (r_error) + if (r_error) { *r_error = ERR_CANT_OPEN; + } FileAccess *f = FileAccess::open(p_path, FileAccess::READ); ERR_FAIL_COND_V_MSG(!f, RES(), "Cannot open file '" + p_path + "'."); @@ -196,7 +205,8 @@ bool TranslationLoaderPO::handles_type(const String &p_type) const { } String TranslationLoaderPO::get_resource_type(const String &p_path) const { - if (p_path.get_extension().to_lower() == "po") + if (p_path.get_extension().to_lower() == "po") { return "Translation"; + } return ""; } diff --git a/core/io/udp_server.cpp b/core/io/udp_server.cpp index 40180dcb09..1d329daf8b 100644 --- a/core/io/udp_server.cpp +++ b/core/io/udp_server.cpp @@ -46,13 +46,15 @@ Error UDPServer::listen(uint16_t p_port, const IP_Address &p_bind_address) { Error err; IP::Type ip_type = IP::TYPE_ANY; - if (p_bind_address.is_valid()) + if (p_bind_address.is_valid()) { ip_type = p_bind_address.is_ipv4() ? IP::TYPE_IPV4 : IP::TYPE_IPV6; + } err = _sock->open(NetSocket::TYPE_UDP, ip_type); - if (err != OK) + if (err != OK) { return ERR_CANT_CREATE; + } _sock->set_blocking_enabled(false); _sock->set_reuse_address_enabled(true); @@ -76,8 +78,9 @@ bool UDPServer::is_listening() const { bool UDPServer::is_connection_available() const { ERR_FAIL_COND_V(!_sock.is_valid(), false); - if (!_sock->is_open()) + if (!_sock->is_open()) { return false; + } Error err = _sock->poll(NetSocket::POLL_TYPE_IN, 0); return (err == OK); diff --git a/core/io/xml_parser.cpp b/core/io/xml_parser.cpp index d575e75f0c..11f82fef9d 100644 --- a/core/io/xml_parser.cpp +++ b/core/io/xml_parser.cpp @@ -38,9 +38,11 @@ VARIANT_ENUM_CAST(XMLParser::NodeType); static bool _equalsn(const CharType *str1, const CharType *str2, int len) { int i; - for (i = 0; i < len && str1[i] && str2[i]; ++i) - if (str1[i] != str2[i]) + for (i = 0; i < len && str1[i] && str2[i]; ++i) { + if (str1[i] != str2[i]) { return false; + } + } // if one (or both) of the strings was smaller then they // are only equal if they have the same length @@ -51,8 +53,9 @@ String XMLParser::_replace_special_characters(const String &origstr) { int pos = origstr.find("&"); int oldPos = 0; - if (pos == -1) + if (pos == -1) { return origstr; + } String newstr; @@ -83,8 +86,9 @@ String XMLParser::_replace_special_characters(const String &origstr) { pos = origstr.find("&", pos); } - if (oldPos < origstr.length() - 1) + if (oldPos < origstr.length() - 1) { newstr += (origstr.substr(oldPos, origstr.length() - oldPos)); + } return newstr; } @@ -99,12 +103,15 @@ bool XMLParser::_set_text(char *start, char *end) { // only white space, so that this text won't be reported if (end - start < 3) { char *p = start; - for (; p != end; ++p) - if (!_is_white_space(*p)) + for (; p != end; ++p) { + if (!_is_white_space(*p)) { break; + } + } - if (p == end) + if (p == end) { return false; + } } // set current text to the parsed text, and replace xml special characters @@ -125,8 +132,9 @@ void XMLParser::_parse_closing_xml_element() { ++P; const char *pBeginClose = P; - while (*P != '>') + while (*P != '>') { ++P; + } node_name = String::utf8(pBeginClose, (int)(P - pBeginClose)); #ifdef DEBUG_XML @@ -140,15 +148,17 @@ void XMLParser::_ignore_definition() { char *F = P; // move until end marked with '>' reached - while (*P != '>') + while (*P != '>') { ++P; + } node_name.parse_utf8(F, P - F); ++P; } bool XMLParser::_parse_cdata() { - if (*(P + 1) != '[') + if (*(P + 1) != '[') { return false; + } node_type = NODE_CDATA; @@ -159,8 +169,9 @@ bool XMLParser::_parse_cdata() { ++count; } - if (!*P) + if (!*P) { return true; + } char *cDataBegin = P; char *cDataEnd = nullptr; @@ -176,10 +187,11 @@ bool XMLParser::_parse_cdata() { ++P; } - if (cDataEnd) + if (cDataEnd) { node_name = String::utf8(cDataBegin, (int)(cDataEnd - cDataBegin)); - else + } else { node_name = ""; + } #ifdef DEBUG_XML print_line("XML CDATA: " + node_name); #endif @@ -197,10 +209,11 @@ void XMLParser::_parse_comment() { // move until end of comment reached while (count) { - if (*P == '>') + if (*P == '>') { --count; - else if (*P == '<') + } else if (*P == '<') { ++count; + } ++P; } @@ -222,46 +235,52 @@ void XMLParser::_parse_opening_xml_element() { const char *startName = P; // find end of element - while (*P != '>' && !_is_white_space(*P)) + while (*P != '>' && !_is_white_space(*P)) { ++P; + } const char *endName = P; // find attributes while (*P != '>') { - if (_is_white_space(*P)) + if (_is_white_space(*P)) { ++P; - else { + } else { if (*P != '/') { // we've got an attribute // read the attribute names const char *attributeNameBegin = P; - while (!_is_white_space(*P) && *P != '=') + while (!_is_white_space(*P) && *P != '=') { ++P; + } const char *attributeNameEnd = P; ++P; // read the attribute value // check for quotes and single quotes, thx to murphy - while ((*P != '\"') && (*P != '\'') && *P) + while ((*P != '\"') && (*P != '\'') && *P) { ++P; + } - if (!*P) // malformatted xml file + if (!*P) { // malformatted xml file return; + } const char attributeQuoteChar = *P; ++P; const char *attributeValueBegin = P; - while (*P != attributeQuoteChar && *P) + while (*P != attributeQuoteChar && *P) { ++P; + } - if (!*P) // malformatted xml file + if (!*P) { // malformatted xml file return; + } const char *attributeValueEnd = P; ++P; @@ -304,16 +323,19 @@ void XMLParser::_parse_current_node() { node_offset = P - data; // more forward until '<' found - while (*P != '<' && *P) + while (*P != '<' && *P) { ++P; + } - if (!*P) + if (!*P) { return; + } if (P - start > 0) { // we found some text, store it - if (_set_text(start, P)) + if (_set_text(start, P)) { return; + } } ++P; @@ -327,8 +349,9 @@ void XMLParser::_parse_current_node() { _ignore_definition(); break; case '!': - if (!_parse_cdata()) + if (!_parse_cdata()) { _parse_comment(); + } break; default: _parse_opening_xml_element(); @@ -417,8 +440,9 @@ String XMLParser::get_attribute_value(int p_idx) const { bool XMLParser::has_attribute(const String &p_name) const { for (int i = 0; i < attributes.size(); i++) { - if (attributes[i].name == p_name) + if (attributes[i].name == p_name) { return true; + } } return false; @@ -447,8 +471,9 @@ String XMLParser::get_attribute_value_safe(const String &p_name) const { } } - if (idx < 0) + if (idx < 0) { return ""; + } return attributes[idx].value; } @@ -496,8 +521,9 @@ Error XMLParser::open(const String &p_path) { void XMLParser::skip_section() { // skip if this element is empty anyway. - if (is_empty()) + if (is_empty()) { return; + } // read until we've reached the last element in this section int tagcount = 1; @@ -506,14 +532,16 @@ void XMLParser::skip_section() { if (get_node_type() == XMLParser::NODE_ELEMENT && !is_empty()) { ++tagcount; - } else if (get_node_type() == XMLParser::NODE_ELEMENT_END) + } else if (get_node_type() == XMLParser::NODE_ELEMENT_END) { --tagcount; + } } } void XMLParser::close() { - if (data) + if (data) { memdelete_arr(data); + } data = nullptr; length = 0; P = nullptr; @@ -535,6 +563,7 @@ XMLParser::XMLParser() { } XMLParser::~XMLParser() { - if (data) + if (data) { memdelete_arr(data); + } } diff --git a/core/io/zip_io.cpp b/core/io/zip_io.cpp index 68dd633e70..1979e91b8c 100644 --- a/core/io/zip_io.cpp +++ b/core/io/zip_io.cpp @@ -44,8 +44,9 @@ void *zipio_open(void *data, const char *p_fname, int mode) { f = FileAccess::open(fname, FileAccess::READ); } - if (!f) + if (!f) { return nullptr; + } return data; } diff --git a/core/list.h b/core/list.h index fc943790de..86e4a45036 100644 --- a/core/list.h +++ b/core/list.h @@ -149,14 +149,17 @@ private: first = p_I->next_ptr; }; - if (last == p_I) + if (last == p_I) { last = p_I->prev_ptr; + } - if (p_I->prev_ptr) + if (p_I->prev_ptr) { p_I->prev_ptr->next_ptr = p_I->next_ptr; + } - if (p_I->next_ptr) + if (p_I->next_ptr) { p_I->next_ptr->prev_ptr = p_I->prev_ptr; + } memdelete_allocator<Element, A>(const_cast<Element *>(p_I)); size_cache--; @@ -220,8 +223,9 @@ public: _data->last = n; - if (!_data->first) + if (!_data->first) { _data->first = n; + } _data->size_cache++; @@ -229,8 +233,9 @@ public: }; void pop_back() { - if (_data && _data->last) + if (_data && _data->last) { erase(_data->last); + } } /** @@ -256,8 +261,9 @@ public: _data->first = n; - if (!_data->last) + if (!_data->last) { _data->last = n; + } _data->size_cache++; @@ -265,8 +271,9 @@ public: }; void pop_front() { - if (_data && _data->first) + if (_data && _data->first) { erase(_data->first); + } } Element *insert_after(Element *p_element, const T &p_value) { @@ -328,8 +335,9 @@ public: Element *find(const T_v &p_val) { Element *it = front(); while (it) { - if (it->value == p_val) + if (it->value == p_val) { return it; + } it = it->next(); }; @@ -396,15 +404,19 @@ public: p_B->next_ptr = A_next; p_B->prev_ptr = A_prev; - if (p_A->prev_ptr) + if (p_A->prev_ptr) { p_A->prev_ptr->next_ptr = p_A; - if (p_A->next_ptr) + } + if (p_A->next_ptr) { p_A->next_ptr->prev_ptr = p_A; + } - if (p_B->prev_ptr) + if (p_B->prev_ptr) { p_B->prev_ptr->next_ptr = p_B; - if (p_B->next_ptr) + } + if (p_B->next_ptr) { p_B->next_ptr->prev_ptr = p_B; + } } /** * copy the list @@ -446,18 +458,21 @@ public: void move_to_back(Element *p_I) { ERR_FAIL_COND(p_I->data != _data); - if (!p_I->next_ptr) + if (!p_I->next_ptr) { return; + } if (_data->first == p_I) { _data->first = p_I->next_ptr; }; - if (_data->last == p_I) + if (_data->last == p_I) { _data->last = p_I->prev_ptr; + } - if (p_I->prev_ptr) + if (p_I->prev_ptr) { p_I->prev_ptr->next_ptr = p_I->next_ptr; + } p_I->next_ptr->prev_ptr = p_I->prev_ptr; @@ -480,20 +495,23 @@ public: void move_to_front(Element *p_I) { ERR_FAIL_COND(p_I->data != _data); - if (!p_I->prev_ptr) + if (!p_I->prev_ptr) { return; + } if (_data->first == p_I) { _data->first = p_I->next_ptr; }; - if (_data->last == p_I) + if (_data->last == p_I) { _data->last = p_I->prev_ptr; + } p_I->prev_ptr->next_ptr = p_I->next_ptr; - if (p_I->next_ptr) + if (p_I->next_ptr) { p_I->next_ptr->prev_ptr = p_I->prev_ptr; + } _data->first->prev_ptr = p_I; p_I->next_ptr = _data->first; @@ -541,8 +559,9 @@ public: template <class C> void sort_custom_inplace() { - if (size() < 2) + if (size() < 2) { return; + } Element *from = front(); Element *current = from; @@ -563,15 +582,17 @@ public: find = find->next_ptr; } - if (current->prev_ptr) + if (current->prev_ptr) { current->prev_ptr->next_ptr = current; - else + } else { from = current; + } - if (current->next_ptr) + if (current->next_ptr) { current->next_ptr->prev_ptr = current; - else + } else { to = current; + } } else { current->prev_ptr = nullptr; current->next_ptr = nullptr; @@ -597,8 +618,9 @@ public: //if you don't want to use auxiliary memory, use the in_place version int s = size(); - if (s < 2) + if (s < 2) { return; + } Element **aux_buffer = memnew_arr(Element *, s); diff --git a/core/local_vector.h b/core/local_vector.h index e8b02fe661..c8abb32bf5 100644 --- a/core/local_vector.h +++ b/core/local_vector.h @@ -76,8 +76,9 @@ public: void erase(const T &p_val) { U idx = find(p_val); - if (idx >= 0) + if (idx >= 0) { remove(idx); + } } void invert() { @@ -167,8 +168,9 @@ public: template <class C> void sort_custom() { U len = count; - if (len == 0) + if (len == 0) { return; + } SortArray<T, C> sorter; sorter.sort(data, len); diff --git a/core/map.h b/core/map.h index f9321f90b3..4861d6a026 100644 --- a/core/map.h +++ b/core/map.h @@ -138,13 +138,15 @@ private: inline void _rotate_left(Element *p_node) { Element *r = p_node->right; p_node->right = r->left; - if (r->left != _data._nil) + if (r->left != _data._nil) { r->left->parent = p_node; + } r->parent = p_node->parent; - if (p_node == p_node->parent->left) + if (p_node == p_node->parent->left) { p_node->parent->left = r; - else + } else { p_node->parent->right = r; + } r->left = p_node; p_node->parent = r; @@ -153,13 +155,15 @@ private: inline void _rotate_right(Element *p_node) { Element *l = p_node->left; p_node->left = l->right; - if (l->right != _data._nil) + if (l->right != _data._nil) { l->right->parent = p_node; + } l->parent = p_node->parent; - if (p_node == p_node->parent->right) + if (p_node == p_node->parent->right) { p_node->parent->right = l; - else + } else { p_node->parent->left = l; + } l->right = p_node; p_node->parent = l; @@ -179,8 +183,9 @@ private: node = node->parent; } - if (node->parent == _data._root) + if (node->parent == _data._root) { return nullptr; // No successor, as p_node = last node + } return node->parent; } } @@ -199,8 +204,9 @@ private: node = node->parent; } - if (node == _data._root) + if (node == _data._root) { return nullptr; // No predecessor, as p_node = first node + } return node->parent; } } @@ -210,12 +216,13 @@ private: C less; while (node != _data._nil) { - if (less(p_key, node->_key)) + if (less(p_key, node->_key)) { node = node->left; - else if (less(node->_key, p_key)) + } else if (less(node->_key, p_key)) { node = node->right; - else + } else { return node; // found + } } return nullptr; @@ -229,19 +236,22 @@ private: while (node != _data._nil) { prev = node; - if (less(p_key, node->_key)) + if (less(p_key, node->_key)) { node = node->left; - else if (less(node->_key, p_key)) + } else if (less(node->_key, p_key)) { node = node->right; - else + } else { return node; // found + } } - if (prev == nullptr) + if (prev == nullptr) { return nullptr; // tree empty + } - if (less(p_key, prev->_key)) + if (less(p_key, prev->_key)) { prev = prev->_prev; + } return prev; } @@ -302,11 +312,11 @@ private: while (node != _data._nil) { new_parent = node; - if (less(p_key, node->_key)) + if (less(p_key, node->_key)) { node = node->left; - else if (less(node->_key, p_key)) + } else if (less(node->_key, p_key)) { node = node->right; - else { + } else { node->_value = p_value; return node; // Return existing node with new value } @@ -328,10 +338,12 @@ private: new_node->_next = _successor(new_node); new_node->_prev = _predecessor(new_node); - if (new_node->_next) + if (new_node->_next) { new_node->_next->_prev = new_node; - if (new_node->_prev) + } + if (new_node->_prev) { new_node->_prev->_next = new_node; + } _data.size_cache++; _insert_rb_fix(new_node); @@ -426,10 +438,12 @@ private: rp->right = p_node->right; rp->parent = p_node->parent; rp->color = p_node->color; - if (p_node->left != _data._nil) + if (p_node->left != _data._nil) { p_node->left->parent = rp; - if (p_node->right != _data._nil) + } + if (p_node->right != _data._nil) { p_node->right->parent = rp; + } if (p_node == p_node->parent->left) { p_node->parent->left = rp; @@ -438,10 +452,12 @@ private: } } - if (p_node->_next) + if (p_node->_next) { p_node->_next->_prev = p_node->_prev; - if (p_node->_prev) + } + if (p_node->_prev) { p_node->_prev->_next = p_node->_next; + } memdelete_allocator<Element, A>(p_node); _data.size_cache--; @@ -449,19 +465,22 @@ private: } void _calculate_depth(Element *p_element, int &max_d, int d) const { - if (p_element == _data._nil) + if (p_element == _data._nil) { return; + } _calculate_depth(p_element->left, max_d, d + 1); _calculate_depth(p_element->right, max_d, d + 1); - if (d > max_d) + if (d > max_d) { max_d = d; + } } void _cleanup_tree(Element *p_element) { - if (p_element == _data._nil) + if (p_element == _data._nil) { return; + } _cleanup_tree(p_element->left); _cleanup_tree(p_element->right); @@ -478,32 +497,36 @@ private: public: const Element *find(const K &p_key) const { - if (!_data._root) + if (!_data._root) { return nullptr; + } const Element *res = _find(p_key); return res; } Element *find(const K &p_key) { - if (!_data._root) + if (!_data._root) { return nullptr; + } Element *res = _find(p_key); return res; } const Element *find_closest(const K &p_key) const { - if (!_data._root) + if (!_data._root) { return nullptr; + } const Element *res = _find_closest(p_key); return res; } Element *find_closest(const K &p_key) { - if (!_data._root) + if (!_data._root) { return nullptr; + } Element *res = _find_closest(p_key); return res; @@ -514,31 +537,37 @@ public: } Element *insert(const K &p_key, const V &p_value) { - if (!_data._root) + if (!_data._root) { _data._create_root(); + } return _insert(p_key, p_value); } void erase(Element *p_element) { - if (!_data._root || !p_element) + if (!_data._root || !p_element) { return; + } _erase(p_element); - if (_data.size_cache == 0 && _data._root) + if (_data.size_cache == 0 && _data._root) { _data._free_root(); + } } bool erase(const K &p_key) { - if (!_data._root) + if (!_data._root) { return false; + } Element *e = find(p_key); - if (!e) + if (!e) { return false; + } _erase(e); - if (_data.size_cache == 0 && _data._root) + if (_data.size_cache == 0 && _data._root) { _data._free_root(); + } return true; } @@ -550,40 +579,48 @@ public: } V &operator[](const K &p_key) { - if (!_data._root) + if (!_data._root) { _data._create_root(); + } Element *e = find(p_key); - if (!e) + if (!e) { e = insert(p_key, V()); + } return e->_value; } Element *front() const { - if (!_data._root) + if (!_data._root) { return nullptr; + } Element *e = _data._root->left; - if (e == _data._nil) + if (e == _data._nil) { return nullptr; + } - while (e->left != _data._nil) + while (e->left != _data._nil) { e = e->left; + } return e; } Element *back() const { - if (!_data._root) + if (!_data._root) { return nullptr; + } Element *e = _data._root->left; - if (e == _data._nil) + if (e == _data._nil) { return nullptr; + } - while (e->right != _data._nil) + while (e->right != _data._nil) { e = e->right; + } return e; } @@ -593,8 +630,9 @@ public: int calculate_depth() const { // used for debug mostly - if (!_data._root) + if (!_data._root) { return 0; + } int max_d = 0; _calculate_depth(_data._root->left, max_d, 0); @@ -602,8 +640,9 @@ public: } void clear() { - if (!_data._root) + if (!_data._root) { return; + } _cleanup_tree(_data._root->left); _data._root->left = _data._nil; diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp index a85a0e9db9..45c4a207c3 100644 --- a/core/math/a_star.cpp +++ b/core/math/a_star.cpp @@ -154,8 +154,9 @@ void AStar::connect_points(int p_id, int p_with_id, bool bidirectional) { } Segment s(p_id, p_with_id); - if (bidirectional) + if (bidirectional) { s.direction = Segment::BIDIRECTIONAL; + } Set<Segment>::Element *element = segments.find(s); if (element != nullptr) { @@ -197,15 +198,17 @@ void AStar::disconnect_points(int p_id, int p_with_id, bool bidirectional) { b->unlinked_neighbours.remove(a->id); } } else { - if (s.direction == Segment::NONE) + if (s.direction == Segment::NONE) { b->unlinked_neighbours.remove(a->id); - else + } else { a->unlinked_neighbours.set(b->id, b); + } } segments.erase(element); - if (s.direction != Segment::NONE) + if (s.direction != Segment::NONE) { segments.insert(s); + } } } @@ -273,8 +276,9 @@ int AStar::get_closest_point(const Vector3 &p_point, bool p_include_disabled) co real_t closest_dist = 1e20; for (OAHashMap<int, Point *>::Iterator it = points.iter(); it.valid; it = points.next_iter(it)) { - if (!p_include_disabled && !(*it.value)->enabled) + if (!p_include_disabled && !(*it.value)->enabled) { continue; // Disabled points should not be considered. + } real_t d = p_point.distance_squared_to((*it.value)->pos); if (closest_id < 0 || d < closest_dist) { @@ -320,8 +324,9 @@ Vector3 AStar::get_closest_position_in_segment(const Vector3 &p_point) const { bool AStar::_solve(Point *begin_point, Point *end_point) { pass++; - if (!end_point->enabled) + if (!end_point->enabled) { return false; + } bool found_route = false; @@ -379,8 +384,9 @@ bool AStar::_solve(Point *begin_point, Point *end_point) { } real_t AStar::_estimate_cost(int p_from_id, int p_to_id) { - if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_estimate_cost)) + if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_estimate_cost)) { return get_script_instance()->call(SceneStringNames::get_singleton()->_estimate_cost, p_from_id, p_to_id); + } Point *from_point; bool from_exists = points.lookup(p_from_id, from_point); @@ -394,8 +400,9 @@ real_t AStar::_estimate_cost(int p_from_id, int p_to_id) { } real_t AStar::_compute_cost(int p_from_id, int p_to_id) { - if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_compute_cost)) + if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_compute_cost)) { return get_script_instance()->call(SceneStringNames::get_singleton()->_compute_cost, p_from_id, p_to_id); + } Point *from_point; bool from_exists = points.lookup(p_from_id, from_point); @@ -427,8 +434,9 @@ Vector<Vector3> AStar::get_point_path(int p_from_id, int p_to_id) { Point *end_point = b; bool found_route = _solve(begin_point, end_point); - if (!found_route) + if (!found_route) { return Vector<Vector3>(); + } Point *p = end_point; int pc = 1; // Begin point @@ -475,8 +483,9 @@ Vector<int> AStar::get_id_path(int p_from_id, int p_to_id) { Point *end_point = b; bool found_route = _solve(begin_point, end_point); - if (!found_route) + if (!found_route) { return Vector<int>(); + } Point *p = end_point; int pc = 1; // Begin point @@ -647,8 +656,9 @@ Vector2 AStar2D::get_closest_position_in_segment(const Vector2 &p_point) const { } real_t AStar2D::_estimate_cost(int p_from_id, int p_to_id) { - if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_estimate_cost)) + if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_estimate_cost)) { return get_script_instance()->call(SceneStringNames::get_singleton()->_estimate_cost, p_from_id, p_to_id); + } AStar::Point *from_point; bool from_exists = astar.points.lookup(p_from_id, from_point); @@ -662,8 +672,9 @@ real_t AStar2D::_estimate_cost(int p_from_id, int p_to_id) { } real_t AStar2D::_compute_cost(int p_from_id, int p_to_id) { - if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_compute_cost)) + if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_compute_cost)) { return get_script_instance()->call(SceneStringNames::get_singleton()->_compute_cost, p_from_id, p_to_id); + } AStar::Point *from_point; bool from_exists = astar.points.lookup(p_from_id, from_point); @@ -695,8 +706,9 @@ Vector<Vector2> AStar2D::get_point_path(int p_from_id, int p_to_id) { AStar::Point *end_point = b; bool found_route = _solve(begin_point, end_point); - if (!found_route) + if (!found_route) { return Vector<Vector2>(); + } AStar::Point *p = end_point; int pc = 1; // Begin point @@ -743,8 +755,9 @@ Vector<int> AStar2D::get_id_path(int p_from_id, int p_to_id) { AStar::Point *end_point = b; bool found_route = _solve(begin_point, end_point); - if (!found_route) + if (!found_route) { return Vector<int>(); + } AStar::Point *p = end_point; int pc = 1; // Begin point @@ -775,8 +788,9 @@ Vector<int> AStar2D::get_id_path(int p_from_id, int p_to_id) { bool AStar2D::_solve(AStar::Point *begin_point, AStar::Point *end_point) { astar.pass++; - if (!end_point->enabled) + if (!end_point->enabled) { return false; + } bool found_route = false; diff --git a/core/math/aabb.cpp b/core/math/aabb.cpp index d9cb928944..f5c667dab0 100644 --- a/core/math/aabb.cpp +++ b/core/math/aabb.cpp @@ -78,23 +78,23 @@ AABB AABB::intersection(const AABB &p_aabb) const { Vector3 min, max; - if (src_min.x > dst_max.x || src_max.x < dst_min.x) + if (src_min.x > dst_max.x || src_max.x < dst_min.x) { return AABB(); - else { + } else { min.x = (src_min.x > dst_min.x) ? src_min.x : dst_min.x; max.x = (src_max.x < dst_max.x) ? src_max.x : dst_max.x; } - if (src_min.y > dst_max.y || src_max.y < dst_min.y) + if (src_min.y > dst_max.y || src_max.y < dst_min.y) { return AABB(); - else { + } else { min.y = (src_min.y > dst_min.y) ? src_min.y : dst_min.y; max.y = (src_max.y < dst_max.y) ? src_max.y : dst_max.y; } - if (src_min.z > dst_max.z || src_max.z < dst_min.z) + if (src_min.z > dst_max.z || src_max.z < dst_min.z) { return AABB(); - else { + } else { min.z = (src_min.z > dst_min.z) ? src_min.z : dst_min.z; max.z = (src_max.z < dst_max.z) ? src_max.z : dst_max.z; } @@ -134,8 +134,9 @@ bool AABB::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 * } } - if (r_clip) + if (r_clip) { *r_clip = c1; + } if (r_normal) { *r_normal = Vector3(); (*r_normal)[axis] = p_dir[axis] ? -1 : 1; @@ -158,16 +159,18 @@ bool AABB::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector real_t csign; if (seg_from < seg_to) { - if (seg_from > box_end || seg_to < box_begin) + if (seg_from > box_end || seg_to < box_begin) { return false; + } real_t length = seg_to - seg_from; cmin = (seg_from < box_begin) ? ((box_begin - seg_from) / length) : 0; cmax = (seg_to > box_end) ? ((box_end - seg_from) / length) : 1; csign = -1.0; } else { - if (seg_to > box_end || seg_from < box_begin) + if (seg_to > box_end || seg_from < box_begin) { return false; + } real_t length = seg_to - seg_from; cmin = (seg_from > box_end) ? (box_end - seg_from) / length : 0; cmax = (seg_to < box_begin) ? (box_begin - seg_from) / length : 1; @@ -179,10 +182,12 @@ bool AABB::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector axis = i; sign = csign; } - if (cmax < max) + if (cmax < max) { max = cmax; - if (max < min) + } + if (max < min) { return false; + } } Vector3 rel = p_to - p_from; @@ -193,8 +198,9 @@ bool AABB::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector *r_normal = normal; } - if (r_clip) + if (r_clip) { *r_clip = p_from + rel * min; + } return true; } @@ -215,10 +221,11 @@ bool AABB::intersects_plane(const Plane &p_plane) const { bool under = false; for (int i = 0; i < 8; i++) { - if (p_plane.distance_to(points[i]) > 0) + if (p_plane.distance_to(points[i]) > 0) { over = true; - else + } else { under = true; + } } return under && over; diff --git a/core/math/aabb.h b/core/math/aabb.h index a2dd50f4f3..9bbedfe59c 100644 --- a/core/math/aabb.h +++ b/core/math/aabb.h @@ -109,35 +109,47 @@ public: }; inline bool AABB::intersects(const AABB &p_aabb) const { - if (position.x >= (p_aabb.position.x + p_aabb.size.x)) + if (position.x >= (p_aabb.position.x + p_aabb.size.x)) { return false; - if ((position.x + size.x) <= p_aabb.position.x) + } + if ((position.x + size.x) <= p_aabb.position.x) { return false; - if (position.y >= (p_aabb.position.y + p_aabb.size.y)) + } + if (position.y >= (p_aabb.position.y + p_aabb.size.y)) { return false; - if ((position.y + size.y) <= p_aabb.position.y) + } + if ((position.y + size.y) <= p_aabb.position.y) { return false; - if (position.z >= (p_aabb.position.z + p_aabb.size.z)) + } + if (position.z >= (p_aabb.position.z + p_aabb.size.z)) { return false; - if ((position.z + size.z) <= p_aabb.position.z) + } + if ((position.z + size.z) <= p_aabb.position.z) { return false; + } return true; } inline bool AABB::intersects_inclusive(const AABB &p_aabb) const { - if (position.x > (p_aabb.position.x + p_aabb.size.x)) + if (position.x > (p_aabb.position.x + p_aabb.size.x)) { return false; - if ((position.x + size.x) < p_aabb.position.x) + } + if ((position.x + size.x) < p_aabb.position.x) { return false; - if (position.y > (p_aabb.position.y + p_aabb.size.y)) + } + if (position.y > (p_aabb.position.y + p_aabb.size.y)) { return false; - if ((position.y + size.y) < p_aabb.position.y) + } + if ((position.y + size.y) < p_aabb.position.y) { return false; - if (position.z > (p_aabb.position.z + p_aabb.size.z)) + } + if (position.z > (p_aabb.position.z + p_aabb.size.z)) { return false; - if ((position.z + size.z) < p_aabb.position.z) + } + if ((position.z + size.z) < p_aabb.position.z) { return false; + } return true; } @@ -202,8 +214,9 @@ bool AABB::intersects_convex_shape(const Plane *p_planes, int p_plane_count, con (p.normal.y > 0) ? -half_extents.y : half_extents.y, (p.normal.z > 0) ? -half_extents.z : half_extents.z); point += ofs; - if (p.is_point_over(point)) + if (p.is_point_over(point)) { return false; + } } // Make sure all points in the shape aren't fully separated from the AABB on @@ -243,26 +256,33 @@ bool AABB::inside_convex_shape(const Plane *p_planes, int p_plane_count) const { (p.normal.y < 0) ? -half_extents.y : half_extents.y, (p.normal.z < 0) ? -half_extents.z : half_extents.z); point += ofs; - if (p.is_point_over(point)) + if (p.is_point_over(point)) { return false; + } } return true; } bool AABB::has_point(const Vector3 &p_point) const { - if (p_point.x < position.x) + if (p_point.x < position.x) { return false; - if (p_point.y < position.y) + } + if (p_point.y < position.y) { return false; - if (p_point.z < position.z) + } + if (p_point.z < position.z) { return false; - if (p_point.x > position.x + size.x) + } + if (p_point.x > position.x + size.x) { return false; - if (p_point.y > position.y + size.y) + } + if (p_point.y > position.y + size.y) { return false; - if (p_point.z > position.z + size.z) + } + if (p_point.z > position.z + size.z) { return false; + } return true; } @@ -271,19 +291,25 @@ inline void AABB::expand_to(const Vector3 &p_vector) { Vector3 begin = position; Vector3 end = position + size; - if (p_vector.x < begin.x) + if (p_vector.x < begin.x) { begin.x = p_vector.x; - if (p_vector.y < begin.y) + } + if (p_vector.y < begin.y) { begin.y = p_vector.y; - if (p_vector.z < begin.z) + } + if (p_vector.z < begin.z) { begin.z = p_vector.z; + } - if (p_vector.x > end.x) + if (p_vector.x > end.x) { end.x = p_vector.x; - if (p_vector.y > end.y) + } + if (p_vector.y > end.y) { end.y = p_vector.y; - if (p_vector.z > end.z) + } + if (p_vector.z > end.z) { end.z = p_vector.z; + } position = begin; size = end - begin; @@ -348,12 +374,15 @@ bool AABB::smits_intersect_ray(const Vector3 &p_from, const Vector3 &p_dir, real tymin = (upbound.y - p_from.y) * divy; tymax = (position.y - p_from.y) * divy; } - if ((tmin > tymax) || (tymin > tmax)) + if ((tmin > tymax) || (tymin > tmax)) { return false; - if (tymin > tmin) + } + if (tymin > tmin) { tmin = tymin; - if (tymax < tmax) + } + if (tymax < tmax) { tmax = tymax; + } if (p_dir.z >= 0) { tzmin = (position.z - p_from.z) * divz; tzmax = (upbound.z - p_from.z) * divz; @@ -361,12 +390,15 @@ bool AABB::smits_intersect_ray(const Vector3 &p_from, const Vector3 &p_dir, real tzmin = (upbound.z - p_from.z) * divz; tzmax = (position.z - p_from.z) * divz; } - if ((tmin > tzmax) || (tzmin > tmax)) + if ((tmin > tzmax) || (tzmin > tmax)) { return false; - if (tzmin > tmin) + } + if (tzmin > tmin) { tmin = tzmin; - if (tzmax < tmax) + } + if (tzmax < tmax) { tmax = tzmax; + } return ((tmin < t1) && (tmax > t0)); } diff --git a/core/math/basis.cpp b/core/math/basis.cpp index 9981b673ed..cbfd09810c 100644 --- a/core/math/basis.cpp +++ b/core/math/basis.cpp @@ -114,12 +114,15 @@ bool Basis::is_rotation() const { } bool Basis::is_symmetric() const { - if (!Math::is_equal_approx_ratio(elements[0][1], elements[1][0], UNIT_EPSILON)) + if (!Math::is_equal_approx_ratio(elements[0][1], elements[1][0], UNIT_EPSILON)) { return false; - if (!Math::is_equal_approx_ratio(elements[0][2], elements[2][0], UNIT_EPSILON)) + } + if (!Math::is_equal_approx_ratio(elements[0][2], elements[2][0], UNIT_EPSILON)) { return false; - if (!Math::is_equal_approx_ratio(elements[1][2], elements[2][1], UNIT_EPSILON)) + } + if (!Math::is_equal_approx_ratio(elements[1][2], elements[2][1], UNIT_EPSILON)) { return false; + } return true; } @@ -555,8 +558,9 @@ bool Basis::is_equal_approx(const Basis &p_basis) const { bool Basis::is_equal_approx_ratio(const Basis &a, const Basis &b, real_t p_epsilon) const { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - if (!Math::is_equal_approx_ratio(a.elements[i][j], b.elements[i][j], p_epsilon)) + if (!Math::is_equal_approx_ratio(a.elements[i][j], b.elements[i][j], p_epsilon)) { return false; + } } } @@ -566,8 +570,9 @@ bool Basis::is_equal_approx_ratio(const Basis &a, const Basis &b, real_t p_epsil bool Basis::operator==(const Basis &p_matrix) const { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - if (elements[i][j] != p_matrix.elements[i][j]) + if (elements[i][j] != p_matrix.elements[i][j]) { return false; + } } } @@ -582,8 +587,9 @@ Basis::operator String() const { String mtx; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - if (i != 0 || j != 0) + if (i != 0 || j != 0) { mtx += ", "; + } mtx += rtos(elements[i][j]); } @@ -661,20 +667,22 @@ int Basis::get_orthogonal_index() const { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { real_t v = orth[i][j]; - if (v > 0.5) + if (v > 0.5) { v = 1.0; - else if (v < -0.5) + } else if (v < -0.5) { v = -1.0; - else + } else { v = 0; + } orth[i][j] = v; } } for (int i = 0; i < 24; i++) { - if (_ortho_bases[i] == orth) + if (_ortho_bases[i] == orth) { return i; + } } return 0; @@ -754,8 +762,9 @@ void Basis::get_axis_angle(Vector3 &r_axis, real_t &r_angle) const { real_t s = Math::sqrt((elements[1][2] - elements[2][1]) * (elements[1][2] - elements[2][1]) + (elements[2][0] - elements[0][2]) * (elements[2][0] - elements[0][2]) + (elements[0][1] - elements[1][0]) * (elements[0][1] - elements[1][0])); // s=|axis||sin(angle)|, used to normalise angle = Math::acos((elements[0][0] + elements[1][1] + elements[2][2] - 1) / 2); - if (angle < 0) + if (angle < 0) { s = -s; + } x = (elements[2][1] - elements[1][2]) / s; y = (elements[0][2] - elements[2][0]) / s; z = (elements[1][0] - elements[0][1]) / s; diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp index c7a3918fe5..81c602d8fe 100644 --- a/core/math/camera_matrix.cpp +++ b/core/math/camera_matrix.cpp @@ -469,23 +469,26 @@ void CameraMatrix::invert() { /** Divide column by minus pivot value **/ for (i = 0; i < 4; i++) { - if (i != k) + if (i != k) { matrix[i][k] /= (-pvt_val); + } } /** Reduce the matrix **/ for (i = 0; i < 4; i++) { hold = matrix[i][k]; for (j = 0; j < 4; j++) { - if (i != k && j != k) + if (i != k && j != k) { matrix[i][j] += hold * matrix[k][j]; + } } } /** Divide row by pivot **/ for (j = 0; j < 4; j++) { - if (j != k) + if (j != k) { matrix[k][j] /= pvt_val; + } } /** Replace pivot by reciprocal (at last we can touch it). **/ @@ -505,12 +508,13 @@ void CameraMatrix::invert() { } j = pvt_i[k]; /* Columns to swap correspond to pivot ROW */ - if (j != k) /* If columns are different */ + if (j != k) { /* If columns are different */ for (i = 0; i < 4; i++) { hold = matrix[i][k]; matrix[i][k] = -matrix[i][j]; matrix[i][j] = hold; } + } } } @@ -530,8 +534,9 @@ CameraMatrix CameraMatrix::operator*(const CameraMatrix &p_matrix) const { for (int j = 0; j < 4; j++) { for (int i = 0; i < 4; i++) { real_t ab = 0; - for (int k = 0; k < 4; k++) + for (int k = 0; k < 4; k++) { ab += matrix[k][i] * p_matrix.matrix[j][k]; + } new_matrix.matrix[j][i] = ab; } } @@ -604,9 +609,11 @@ void CameraMatrix::set_light_atlas_rect(const Rect2 &p_rect) { CameraMatrix::operator String() const { String str; - for (int i = 0; i < 4; i++) - for (int j = 0; j < 4; j++) + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { str += String((j > 0) ? ", " : "\n") + rtos(matrix[i][j]); + } + } return str; } diff --git a/core/math/delaunay_3d.h b/core/math/delaunay_3d.h index 8fdb52556f..014b4c4621 100644 --- a/core/math/delaunay_3d.h +++ b/core/math/delaunay_3d.h @@ -81,12 +81,15 @@ class Delaunay3D { _FORCE_INLINE_ Triangle() {} _FORCE_INLINE_ Triangle(uint32_t p_a, uint32_t p_b, uint32_t p_c) { - if (p_a > p_b) + if (p_a > p_b) { SWAP(p_a, p_b); - if (p_b > p_c) + } + if (p_b > p_c) { SWAP(p_b, p_c); - if (p_a > p_b) + } + if (p_a > p_b) { SWAP(p_a, p_b); + } triangle[0] = p_a; triangle[1] = p_b; diff --git a/core/math/disjoint_set.h b/core/math/disjoint_set.h index 4d93a0035b..198f46e111 100644 --- a/core/math/disjoint_set.h +++ b/core/math/disjoint_set.h @@ -109,8 +109,9 @@ void DisjointSet<T, C, AL>::create_union(T a, T b) { Element *y_root = get_parent(y); // Already in the same set - if (x_root == y_root) + if (x_root == y_root) { return; + } // Not in the same set, merge if (x_root->rank < y_root->rank) { diff --git a/core/math/expression.cpp b/core/math/expression.cpp index 7bfebded6a..81c1e7f564 100644 --- a/core/math/expression.cpp +++ b/core/math/expression.cpp @@ -111,8 +111,9 @@ const char *Expression::func_name[Expression::FUNC_MAX] = { Expression::BuiltinFunc Expression::find_function(const String &p_string) { for (int i = 0; i < FUNC_MAX; i++) { - if (p_string == func_name[i]) + if (p_string == func_name[i]) { return BuiltinFunc(i); + } } return FUNC_MAX; @@ -1036,8 +1037,9 @@ Error Expression::_get_token(Token &r_token) { exp_beg = true; } else if ((c == '-' || c == '+') && !exp_sign && !exp_beg) { - if (c == '-') + if (c == '-') { is_float = true; + } exp_sign = true; } else { @@ -1046,8 +1048,9 @@ Error Expression::_get_token(Token &r_token) { } break; } - if (reading == READING_DONE) + if (reading == READING_DONE) { break; + } num += String::chr(c); c = GET_CHAR(); } @@ -1056,10 +1059,11 @@ Error Expression::_get_token(Token &r_token) { r_token.type = TK_CONSTANT; - if (is_float) + if (is_float) { r_token.value = num.to_double(); - else + } else { r_token.value = num.to_int64(); + } return OK; } else if ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_') { @@ -1196,8 +1200,9 @@ Expression::ENode *Expression::_parse_expression() { Token tk; _get_token(tk); - if (error_set) + if (error_set) { return nullptr; + } switch (tk.type) { case TK_CURLY_BRACKET_OPEN: { @@ -1213,8 +1218,9 @@ Expression::ENode *Expression::_parse_expression() { str_ofs = cofs; //revert //parse an expression ENode *subexpr = _parse_expression(); - if (!subexpr) + if (!subexpr) { return nullptr; + } dn->dict.push_back(subexpr); _get_token(tk); @@ -1224,8 +1230,9 @@ Expression::ENode *Expression::_parse_expression() { } subexpr = _parse_expression(); - if (!subexpr) + if (!subexpr) { return nullptr; + } dn->dict.push_back(subexpr); @@ -1256,8 +1263,9 @@ Expression::ENode *Expression::_parse_expression() { str_ofs = cofs; //revert //parse an expression ENode *subexpr = _parse_expression(); - if (!subexpr) + if (!subexpr) { return nullptr; + } an->array.push_back(subexpr); cofs = str_ofs; @@ -1276,8 +1284,9 @@ Expression::ENode *Expression::_parse_expression() { case TK_PARENTHESIS_OPEN: { //a suexpression ENode *e = _parse_expression(); - if (error_set) + if (error_set) { return nullptr; + } _get_token(tk); if (tk.type != TK_PARENTHESIS_CLOSE) { _set_error("Expected ')'"); @@ -1308,8 +1317,9 @@ Expression::ENode *Expression::_parse_expression() { str_ofs = cofs2; //revert //parse an expression ENode *subexpr = _parse_expression(); - if (!subexpr) + if (!subexpr) { return nullptr; + } func_call->arguments.push_back(subexpr); @@ -1386,8 +1396,9 @@ Expression::ENode *Expression::_parse_expression() { str_ofs = cofs; //revert //parse an expression ENode *subexpr = _parse_expression(); - if (!subexpr) + if (!subexpr) { return nullptr; + } constructor->arguments.push_back(subexpr); @@ -1426,8 +1437,9 @@ Expression::ENode *Expression::_parse_expression() { str_ofs = cofs; //revert //parse an expression ENode *subexpr = _parse_expression(); - if (!subexpr) + if (!subexpr) { return nullptr; + } bifunc->arguments.push_back(subexpr); @@ -1476,8 +1488,9 @@ Expression::ENode *Expression::_parse_expression() { while (true) { int cofs2 = str_ofs; _get_token(tk); - if (error_set) + if (error_set) { return nullptr; + } bool done = false; @@ -1489,8 +1502,9 @@ Expression::ENode *Expression::_parse_expression() { index->base = expr; ENode *what = _parse_expression(); - if (!what) + if (!what) { return nullptr; + } index->index = what; @@ -1529,8 +1543,9 @@ Expression::ENode *Expression::_parse_expression() { str_ofs = cofs3; //revert //parse an expression ENode *subexpr = _parse_expression(); - if (!subexpr) + if (!subexpr) { return nullptr; + } func_call->arguments.push_back(subexpr); @@ -1563,8 +1578,9 @@ Expression::ENode *Expression::_parse_expression() { } break; } - if (done) + if (done) { break; + } } //push expression @@ -1579,8 +1595,9 @@ Expression::ENode *Expression::_parse_expression() { int cofs = str_ofs; _get_token(tk); - if (error_set) + if (error_set) { return nullptr; + } Variant::Operator op = Variant::OP_MAX; @@ -1843,8 +1860,9 @@ Expression::ENode *Expression::_parse_expression() { } bool Expression::_compile_expression() { - if (!expression_dirty) + if (!expression_dirty) { return error_set; + } if (nodes) { memdelete(nodes); @@ -1898,15 +1916,17 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: Variant a; bool ret = _execute(p_inputs, p_instance, op->nodes[0], a, r_error_str); - if (ret) + if (ret) { return true; + } Variant b; if (op->nodes[1]) { ret = _execute(p_inputs, p_instance, op->nodes[1], b, r_error_str); - if (ret) + if (ret) { return true; + } } bool valid = true; @@ -1922,14 +1942,16 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: Variant base; bool ret = _execute(p_inputs, p_instance, index->base, base, r_error_str); - if (ret) + if (ret) { return true; + } Variant idx; ret = _execute(p_inputs, p_instance, index->index, idx, r_error_str); - if (ret) + if (ret) { return true; + } bool valid; r_ret = base.get(idx, &valid); @@ -1944,8 +1966,9 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: Variant base; bool ret = _execute(p_inputs, p_instance, index->base, base, r_error_str); - if (ret) + if (ret) { return true; + } bool valid; r_ret = base.get_named(index->name, &valid); @@ -1964,8 +1987,9 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: Variant value; bool ret = _execute(p_inputs, p_instance, array->array[i], value, r_error_str); - if (ret) + if (ret) { return true; + } arr[i] = value; } @@ -1980,13 +2004,15 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: Variant key; bool ret = _execute(p_inputs, p_instance, dictionary->dict[i + 0], key, r_error_str); - if (ret) + if (ret) { return true; + } Variant value; ret = _execute(p_inputs, p_instance, dictionary->dict[i + 1], value, r_error_str); - if (ret) + if (ret) { return true; + } d[key] = value; } @@ -2005,8 +2031,9 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: Variant value; bool ret = _execute(p_inputs, p_instance, constructor->arguments[i], value, r_error_str); - if (ret) + if (ret) { return true; + } arr.write[i] = value; argp.write[i] = &arr[i]; } @@ -2031,8 +2058,9 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: for (int i = 0; i < bifunc->arguments.size(); i++) { Variant value; bool ret = _execute(p_inputs, p_instance, bifunc->arguments[i], value, r_error_str); - if (ret) + if (ret) { return true; + } arr.write[i] = value; argp.write[i] = &arr[i]; } @@ -2052,8 +2080,9 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: Variant base; bool ret = _execute(p_inputs, p_instance, call->base, base, r_error_str); - if (ret) + if (ret) { return true; + } Vector<Variant> arr; Vector<const Variant *> argp; @@ -2064,8 +2093,9 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: Variant value; ret = _execute(p_inputs, p_instance, call->arguments[i], value, r_error_str); - if (ret) + if (ret) { return true; + } arr.write[i] = value; argp.write[i] = &arr[i]; } diff --git a/core/math/expression.h b/core/math/expression.h index 2d67caca44..59a9a2f4ed 100644 --- a/core/math/expression.h +++ b/core/math/expression.h @@ -184,8 +184,9 @@ private: }; void _set_error(const String &p_err) { - if (error_set) + if (error_set) { return; + } error_str = p_err; error_set = true; } diff --git a/core/math/face3.cpp b/core/math/face3.cpp index e1be4f0acf..6d76e116be 100644 --- a/core/math/face3.cpp +++ b/core/math/face3.cpp @@ -64,8 +64,9 @@ int Face3::split_by_plane(const Plane &p_plane, Face3 p_res[3], bool p_is_point_ /* Check for Intersection between this and the next vertex*/ Vector3 inters; - if (!p_plane.intersects_segment(vertex[i], vertex[(i + 1) % 3], &inters)) + if (!p_plane.intersects_segment(vertex[i], vertex[(i + 1) % 3], &inters)) { continue; + } /* Intersection goes to both */ ERR_FAIL_COND_V(above_count >= 4, 0); @@ -127,23 +128,26 @@ Face3::Side Face3::get_side_of(const Face3 &p_face, ClockDirection p_clock_dir) for (int i = 0; i < 3; i++) { const Vector3 &v = p_face.vertex[i]; - if (plane.has_point(v)) //coplanar, don't bother + if (plane.has_point(v)) { //coplanar, don't bother continue; + } - if (plane.is_point_over(v)) + if (plane.is_point_over(v)) { over++; - else + } else { under++; + } } - if (over > 0 && under == 0) + if (over > 0 && under == 0) { return SIDE_OVER; - else if (under > 0 && over == 0) + } else if (under > 0 && over == 0) { return SIDE_UNDER; - else if (under == 0 && over == 0) + } else if (under == 0 && over == 0) { return SIDE_COPLANAR; - else + } else { return SIDE_SPANNING; + } } Vector3 Face3::get_random_point_inside() const { @@ -176,8 +180,9 @@ ClockDirection Face3::get_clock_dir() const { bool Face3::intersects_aabb(const AABB &p_aabb) const { /** TEST PLANE **/ - if (!p_aabb.intersects_plane(get_plane())) + if (!p_aabb.intersects_plane(get_plane())) { return false; + } #define TEST_AXIS(m_ax) \ /** TEST FACE AXIS */ \ @@ -218,16 +223,18 @@ bool Face3::intersects_aabb(const AABB &p_aabb) const { Vector3 axis = vec3_cross(e1, e2); - if (axis.length_squared() < 0.0001) + if (axis.length_squared() < 0.0001) { continue; // coplanar + } axis.normalize(); real_t minA, maxA, minB, maxB; p_aabb.project_range_in_plane(Plane(axis, 0), minA, maxA); project_range(axis, Transform(), minB, maxB); - if (maxA < minB || maxB < minA) + if (maxA < minB || maxB < minA) { return false; + } } } return true; @@ -242,11 +249,13 @@ void Face3::project_range(const Vector3 &p_normal, const Transform &p_transform, Vector3 v = p_transform.xform(vertex[i]); real_t d = p_normal.dot(v); - if (i == 0 || d > r_max) + if (i == 0 || d > r_max) { r_max = d; + } - if (i == 0 || d < r_min) + if (i == 0 || d < r_min) { r_min = d; + } } } @@ -254,8 +263,9 @@ void Face3::get_support(const Vector3 &p_normal, const Transform &p_transform, V #define _FACE_IS_VALID_SUPPORT_THRESHOLD 0.98 #define _EDGE_IS_VALID_SUPPORT_THRESHOLD 0.05 - if (p_max <= 0) + if (p_max <= 0) { return; + } Vector3 n = p_transform.basis.xform_inv(p_normal); @@ -287,8 +297,9 @@ void Face3::get_support(const Vector3 &p_normal, const Transform &p_transform, V /** TEST EDGES AS SUPPORT **/ for (int i = 0; i < 3; i++) { - if (i != vert_support_idx && i + 1 != vert_support_idx) + if (i != vert_support_idx && i + 1 != vert_support_idx) { continue; + } // check if edge is valid as a support real_t dot = (vertex[i] - vertex[(i + 1) % 3]).normalized().dot(n); @@ -296,8 +307,9 @@ void Face3::get_support(const Vector3 &p_normal, const Transform &p_transform, V if (dot < _EDGE_IS_VALID_SUPPORT_THRESHOLD) { *p_count = MIN(2, p_max); - for (int j = 0; j < *p_count; j++) + for (int j = 0; j < *p_count; j++) { p_vertices[j] = p_transform.xform(vertex[(j + i) % 3]); + } return; } diff --git a/core/math/face3.h b/core/math/face3.h index eb2b3b8bd5..fb40e8ab9e 100644 --- a/core/math/face3.h +++ b/core/math/face3.h @@ -111,8 +111,9 @@ bool Face3::intersects_aabb2(const AABB &p_aabb) const { real_t dist_a = perp.dot(ofs + sup) - d; real_t dist_b = perp.dot(ofs - sup) - d; - if (dist_a * dist_b > 0) + if (dist_a * dist_b > 0) { return false; //does not intersect the plane + } #define TEST_AXIS(m_ax) \ { \ @@ -209,8 +210,9 @@ bool Face3::intersects_aabb2(const AABB &p_aabb) const { Vector3 axis = vec3_cross(e1, e2); - if (axis.length_squared() < 0.0001) + if (axis.length_squared() < 0.0001) { continue; // coplanar + } //axis.normalize(); Vector3 sup2 = Vector3( @@ -228,15 +230,18 @@ bool Face3::intersects_aabb2(const AABB &p_aabb) const { for (int k = 0; k < 3; k++) { real_t vert_d = axis.dot(vertex[k]); - if (vert_d > maxT) + if (vert_d > maxT) { maxT = vert_d; + } - if (vert_d < minT) + if (vert_d < minT) { minT = vert_d; + } } - if (maxB < minT || maxT < minB) + if (maxB < minT || maxT < minB) { return false; + } } } return true; diff --git a/core/math/geometry.cpp b/core/math/geometry.cpp index f1676ec152..f6f22e1db2 100644 --- a/core/math/geometry.cpp +++ b/core/math/geometry.cpp @@ -90,8 +90,9 @@ void Geometry::MeshData::optimize_vertices() { new_vertices.resize(vtx_remap.size()); for (int i = 0; i < vertices.size(); i++) { - if (vtx_remap.has(i)) + if (vtx_remap.has(i)) { new_vertices.write[vtx_remap[i]] = vertices[i]; + } } vertices = new_vertices; } @@ -126,11 +127,13 @@ static bool _connect_faces(_FaceClassify *p_faces, int len, int p_group) { } for (int i = 0; i < len; i++) { - if (p_faces[i].group != p_group) + if (p_faces[i].group != p_group) { continue; + } for (int j = i + 1; j < len; j++) { - if (p_faces[j].group != p_group) + if (p_faces[j].group != p_group) { continue; + } for (int k = 0; k < 3; k++) { Vector3 vi1 = p_faces[i].face.vertex[k]; @@ -159,29 +162,34 @@ static bool _connect_faces(_FaceClassify *p_faces, int len, int p_group) { p_faces[j].links[l].edge = k; } } - if (error) + if (error) { break; + } } - if (error) + if (error) { break; + } } - if (error) + if (error) { break; + } } for (int i = 0; i < len; i++) { p_faces[i].valid = true; for (int j = 0; j < 3; j++) { - if (p_faces[i].links[j].face == -1) + if (p_faces[i].links[j].face == -1) { p_faces[i].valid = false; + } } } return error; } static bool _group_face(_FaceClassify *p_faces, int len, int p_index, int p_group) { - if (p_faces[p_index].group >= 0) + if (p_faces[p_index].group >= 0) { return false; + } p_faces[p_index].group = p_group; @@ -218,8 +226,9 @@ Vector<Vector<Face3>> Geometry::separate_objects(Vector<Face3> p_array) { int group = 0; for (int i = 0; i < len; i++) { - if (!_fcptr[i].valid) + if (!_fcptr[i].valid) { continue; + } if (_group_face(_fcptr, len, i, group)) { group++; } @@ -236,8 +245,9 @@ Vector<Vector<Face3>> Geometry::separate_objects(Vector<Face3> p_array) { Vector<Face3> *group_faces = objects.ptrw(); for (int i = 0; i < len; i++) { - if (!_fcptr[i].valid) + if (!_fcptr[i].valid) { continue; + } if (_fcptr[i].group >= 0 && _fcptr[i].group < group) { group_faces[_fcptr[i].group].push_back(_fcptr[i].face); } @@ -279,8 +289,9 @@ static inline void _plot_face(uint8_t ***p_cell_status, int x, int y, int z, int aabb.position = aabb.position * voxelsize; aabb.size = aabb.size * voxelsize; - if (!p_face.intersects_aabb(aabb)) + if (!p_face.intersects_aabb(aabb)) { return; + } if (len_x == 1 && len_y == 1 && len_z == 1) { p_cell_status[x][y][z] = _CELL_SOLID; @@ -326,8 +337,9 @@ static inline void _plot_face(uint8_t ***p_cell_status, int x, int y, int z, int } static inline void _mark_outside(uint8_t ***p_cell_status, int x, int y, int z, int len_x, int len_y, int len_z) { - if (p_cell_status[x][y][z] & 3) + if (p_cell_status[x][y][z] & 3) { return; // Nothing to do, already used and/or visited. + } p_cell_status[x][y][z] = _CELL_PREV_FIRST; @@ -413,15 +425,19 @@ static inline void _mark_outside(uint8_t ***p_cell_status, int x, int y, int z, ERR_FAIL(); } - if (next_x < 0 || next_x >= len_x) + if (next_x < 0 || next_x >= len_x) { continue; - if (next_y < 0 || next_y >= len_y) + } + if (next_y < 0 || next_y >= len_y) { continue; - if (next_z < 0 || next_z >= len_z) + } + if (next_z < 0 || next_z >= len_z) { continue; + } - if (p_cell_status[next_x][next_y][next_z] & 3) + if (p_cell_status[next_x][next_y][next_z] & 3) { continue; + } x = next_x; y = next_y; @@ -435,8 +451,9 @@ static inline void _build_faces(uint8_t ***p_cell_status, int x, int y, int z, i ERR_FAIL_INDEX(y, len_y); ERR_FAIL_INDEX(z, len_z); - if (p_cell_status[x][y][z] & _CELL_EXTERIOR) + if (p_cell_status[x][y][z] & _CELL_EXTERIOR) { return; + } #define vert(m_idx) Vector3(((m_idx)&4) >> 2, ((m_idx)&2) >> 1, (m_idx)&1) @@ -458,21 +475,27 @@ static inline void _build_faces(uint8_t ***p_cell_status, int x, int y, int z, i bool plot = false; - if (disp_x < 0 || disp_x >= len_x) + if (disp_x < 0 || disp_x >= len_x) { plot = true; - if (disp_y < 0 || disp_y >= len_y) + } + if (disp_y < 0 || disp_y >= len_y) { plot = true; - if (disp_z < 0 || disp_z >= len_z) + } + if (disp_z < 0 || disp_z >= len_z) { plot = true; + } - if (!plot && (p_cell_status[disp_x][disp_y][disp_z] & _CELL_EXTERIOR)) + if (!plot && (p_cell_status[disp_x][disp_y][disp_z] & _CELL_EXTERIOR)) { plot = true; + } - if (!plot) + if (!plot) { continue; + } - for (int j = 0; j < 4; j++) + for (int j = 0; j < 4; j++) { face_points[j] = vert(indices[i][j]) + Vector3(x, y, z); + } p_faces.push_back( Face3( @@ -510,20 +533,23 @@ Vector<Face3> Geometry::wrap_geometry(Vector<Face3> p_array, real_t *p_error) { // Determine amount of cells in grid axis. int div_x, div_y, div_z; - if (global_aabb.size.x / _MIN_SIZE < _MAX_LENGTH) + if (global_aabb.size.x / _MIN_SIZE < _MAX_LENGTH) { div_x = (int)(global_aabb.size.x / _MIN_SIZE) + 1; - else + } else { div_x = _MAX_LENGTH; + } - if (global_aabb.size.y / _MIN_SIZE < _MAX_LENGTH) + if (global_aabb.size.y / _MIN_SIZE < _MAX_LENGTH) { div_y = (int)(global_aabb.size.y / _MIN_SIZE) + 1; - else + } else { div_y = _MAX_LENGTH; + } - if (global_aabb.size.z / _MIN_SIZE < _MAX_LENGTH) + if (global_aabb.size.z / _MIN_SIZE < _MAX_LENGTH) { div_z = (int)(global_aabb.size.z / _MIN_SIZE) + 1; - else + } else { div_z = _MAX_LENGTH; + } Vector3 voxelsize = global_aabb.size; voxelsize.x /= div_x; @@ -614,8 +640,9 @@ Vector<Face3> Geometry::wrap_geometry(Vector<Face3> p_array, real_t *p_error) { } memdelete_arr(cell_status); - if (p_error) + if (p_error) { *p_error = voxelsize.length(); + } return wrapped_faces; } @@ -665,8 +692,9 @@ Geometry::MeshData Geometry::build_convex_mesh(const Vector<Plane> &p_planes) { Vector3 ref = Vector3(0.0, 1.0, 0.0); - if (ABS(p.normal.dot(ref)) > 0.95) + if (ABS(p.normal.dot(ref)) > 0.95) { ref = Vector3(0.0, 0.0, 1.0); // Change axis. + } Vector3 right = p.normal.cross(ref).normalized(); Vector3 up = p.normal.cross(right).normalized(); @@ -681,17 +709,20 @@ Geometry::MeshData Geometry::build_convex_mesh(const Vector<Plane> &p_planes) { vertices.push_back(center + up * subplane_size + right * subplane_size); for (int j = 0; j < p_planes.size(); j++) { - if (j == i) + if (j == i) { continue; + } Vector<Vector3> new_vertices; Plane clip = p_planes[j]; - if (clip.normal.dot(p.normal) > 0.95) + if (clip.normal.dot(p.normal) > 0.95) { continue; + } - if (vertices.size() < 3) + if (vertices.size() < 3) { break; + } for (int k = 0; k < vertices.size(); k++) { int k_n = (k + 1) % vertices.size(); @@ -713,8 +744,9 @@ Geometry::MeshData Geometry::build_convex_mesh(const Vector<Plane> &p_planes) { Vector3 rel = edge1_A - edge0_A; real_t den = clip.normal.dot(rel); - if (Math::is_zero_approx(den)) + if (Math::is_zero_approx(den)) { continue; // Point too short. + } real_t dist = -(clip.normal.dot(edge0_A) - clip.d) / den; Vector3 inters = edge0_A + rel * dist; @@ -725,8 +757,9 @@ Geometry::MeshData Geometry::build_convex_mesh(const Vector<Plane> &p_planes) { vertices = new_vertices; } - if (vertices.size() < 3) + if (vertices.size() < 3) { continue; + } // Result is a clockwise face. @@ -770,8 +803,9 @@ Geometry::MeshData Geometry::build_convex_mesh(const Vector<Plane> &p_planes) { } } - if (found) + if (found) { continue; + } MeshData::Edge edge; edge.a = a; edge.b = b; @@ -913,13 +947,15 @@ void Geometry::make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_resu int w = 1 << i; int max_h = 0; int max_w = 0; - if (w < widest) + if (w < widest) { continue; + } Vector<int> hmax; hmax.resize(w); - for (int j = 0; j < w; j++) + for (int j = 0; j < w; j++) { hmax.write[j] = 0; + } // Place them. int ofs = 0; @@ -931,29 +967,34 @@ void Geometry::make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_resu int from_y = 0; for (int k = 0; k < wrects[j].s.width; k++) { - if (hmax[ofs + k] > from_y) + if (hmax[ofs + k] > from_y) { from_y = hmax[ofs + k]; + } } wrects.write[j].p.x = ofs; wrects.write[j].p.y = from_y; int end_h = from_y + wrects[j].s.height; int end_w = ofs + wrects[j].s.width; - if (ofs == 0) + if (ofs == 0) { limit_h = end_h; + } for (int k = 0; k < wrects[j].s.width; k++) { hmax.write[ofs + k] = end_h; } - if (end_h > max_h) + if (end_h > max_h) { max_h = end_h; + } - if (end_w > max_w) + if (end_w > max_w) { max_w = end_w; + } - if (ofs == 0 || end_h > limit_h) // While h limit not reached, keep stacking. + if (ofs == 0 || end_h > limit_h) { // While h limit not reached, keep stacking. ofs += wrects[j].s.width; + } } _AtlasWorkRectResult result; @@ -1243,8 +1284,9 @@ static void edt(float *f, int stride, int n) { k = 0; for (int q = 0; q <= n - 1; q++) { - while (z[k + 1] < q) + while (z[k + 1] < q) { k++; + } d[q] = square(q - v[k]) + f[v[k] * stride]; } diff --git a/core/math/geometry.h b/core/math/geometry.h index b52b081016..a61bf20c4c 100644 --- a/core/math/geometry.h +++ b/core/math/geometry.h @@ -78,8 +78,9 @@ public: // clamp to segment S1. Else pick arbitrary s (here 0). if (denom != 0.0) { s = CLAMP((b * f - c * e) / denom, 0.0, 1.0); - } else + } else { s = 0.0; + } // Compute point on L2 closest to S1(s) using // t = Dot((P1 + D1*s) - P2,D2) / Dot(D2,D2) = (b*s + f) / e t = (b * s + f) / e; @@ -110,14 +111,18 @@ public: real_t mub = (d_of(p1, q1, q2, q1) + mua * d_of(q2, q1, p2, p1)) / d_of(q2, q1, q2, q1); // Clip the value between [0..1] constraining the solution to lie on the original curves. - if (mua < 0) + if (mua < 0) { mua = 0; - if (mub < 0) + } + if (mub < 0) { mub = 0; - if (mua > 1) + } + if (mua > 1) { mua = 1; - if (mub > 1) + } + if (mub > 1) { mub = 1; + } c1 = p1.lerp(p2, mua); c2 = q1.lerp(q2, mub); } @@ -158,22 +163,22 @@ public: if (tN < 0.0) { // tc < 0 => the t=0 edge is visible. tN = 0.0; // Recompute sc for this edge. - if (-d < 0.0) + if (-d < 0.0) { sN = 0.0; - else if (-d > a) + } else if (-d > a) { sN = sD; - else { + } else { sN = -d; sD = a; } } else if (tN > tD) { // tc > 1 => the t=1 edge is visible. tN = tD; // Recompute sc for this edge. - if ((-d + b) < 0.0) + if ((-d + b) < 0.0) { sN = 0; - else if ((-d + b) > a) + } else if ((-d + b) > a) { sN = sD; - else { + } else { sN = (-d + b); sD = a; } @@ -193,34 +198,39 @@ public: Vector3 e2 = p_v2 - p_v0; Vector3 h = p_dir.cross(e2); real_t a = e1.dot(h); - if (Math::is_zero_approx(a)) // Parallel test. + if (Math::is_zero_approx(a)) { // Parallel test. return false; + } real_t f = 1.0 / a; Vector3 s = p_from - p_v0; real_t u = f * s.dot(h); - if (u < 0.0 || u > 1.0) + if (u < 0.0 || u > 1.0) { return false; + } Vector3 q = s.cross(e1); real_t v = f * p_dir.dot(q); - if (v < 0.0 || u + v > 1.0) + if (v < 0.0 || u + v > 1.0) { return false; + } // At this stage we can compute t to find out where // the intersection point is on the line. real_t t = f * e2.dot(q); if (t > 0.00001) { // ray intersection - if (r_res) + if (r_res) { *r_res = p_from + p_dir * t; + } return true; - } else // This means that there is a line intersection but not a ray intersection. + } else { // This means that there is a line intersection but not a ray intersection. return false; + } } static inline bool segment_intersects_triangle(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2, Vector3 *r_res = nullptr) { @@ -229,67 +239,78 @@ public: Vector3 e2 = p_v2 - p_v0; Vector3 h = rel.cross(e2); real_t a = e1.dot(h); - if (Math::is_zero_approx(a)) // Parallel test. + if (Math::is_zero_approx(a)) { // Parallel test. return false; + } real_t f = 1.0 / a; Vector3 s = p_from - p_v0; real_t u = f * s.dot(h); - if (u < 0.0 || u > 1.0) + if (u < 0.0 || u > 1.0) { return false; + } Vector3 q = s.cross(e1); real_t v = f * rel.dot(q); - if (v < 0.0 || u + v > 1.0) + if (v < 0.0 || u + v > 1.0) { return false; + } // At this stage we can compute t to find out where // the intersection point is on the line. real_t t = f * e2.dot(q); if (t > CMP_EPSILON && t <= 1.0) { // Ray intersection. - if (r_res) + if (r_res) { *r_res = p_from + rel * t; + } return true; - } else // This means that there is a line intersection but not a ray intersection. + } else { // This means that there is a line intersection but not a ray intersection. return false; + } } static inline bool segment_intersects_sphere(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_sphere_pos, real_t p_sphere_radius, Vector3 *r_res = nullptr, Vector3 *r_norm = nullptr) { Vector3 sphere_pos = p_sphere_pos - p_from; Vector3 rel = (p_to - p_from); real_t rel_l = rel.length(); - if (rel_l < CMP_EPSILON) + if (rel_l < CMP_EPSILON) { return false; // Both points are the same. + } Vector3 normal = rel / rel_l; real_t sphere_d = normal.dot(sphere_pos); real_t ray_distance = sphere_pos.distance_to(normal * sphere_d); - if (ray_distance >= p_sphere_radius) + if (ray_distance >= p_sphere_radius) { return false; + } real_t inters_d2 = p_sphere_radius * p_sphere_radius - ray_distance * ray_distance; real_t inters_d = sphere_d; - if (inters_d2 >= CMP_EPSILON) + if (inters_d2 >= CMP_EPSILON) { inters_d -= Math::sqrt(inters_d2); + } // Check in segment. - if (inters_d < 0 || inters_d > rel_l) + if (inters_d < 0 || inters_d > rel_l) { return false; + } Vector3 result = p_from + normal * inters_d; - if (r_res) + if (r_res) { *r_res = result; - if (r_norm) + } + if (r_norm) { *r_norm = (result - p_sphere_pos).normalized(); + } return true; } @@ -297,8 +318,9 @@ public: static inline bool segment_intersects_cylinder(const Vector3 &p_from, const Vector3 &p_to, real_t p_height, real_t p_radius, Vector3 *r_res = nullptr, Vector3 *r_norm = nullptr) { Vector3 rel = (p_to - p_from); real_t rel_l = rel.length(); - if (rel_l < CMP_EPSILON) + if (rel_l < CMP_EPSILON) { return false; // Both points are the same. + } // First check if they are parallel. Vector3 normal = (rel / rel_l); @@ -315,13 +337,15 @@ public: real_t dist = z_dir.dot(p_from); - if (dist >= p_radius) + if (dist >= p_radius) { return false; // Too far away. + } // Convert to 2D. real_t w2 = p_radius * p_radius - dist * dist; - if (w2 < CMP_EPSILON) + if (w2 < CMP_EPSILON) { return false; // Avoid numerical error. + } Size2 size(Math::sqrt(w2), p_height * 0.5); Vector3 x_dir = z_dir.cross(Vector3(0, 0, 1)).normalized(); @@ -341,15 +365,17 @@ public: real_t cmin, cmax; if (seg_from < seg_to) { - if (seg_from > box_end || seg_to < box_begin) + if (seg_from > box_end || seg_to < box_begin) { return false; + } real_t length = seg_to - seg_from; cmin = (seg_from < box_begin) ? ((box_begin - seg_from) / length) : 0; cmax = (seg_to > box_end) ? ((box_end - seg_from) / length) : 1; } else { - if (seg_to > box_end || seg_from < box_begin) + if (seg_to > box_end || seg_from < box_begin) { return false; + } real_t length = seg_to - seg_from; cmin = (seg_from > box_end) ? (box_end - seg_from) / length : 0; cmax = (seg_to < box_begin) ? (box_begin - seg_from) / length : 1; @@ -359,10 +385,12 @@ public: min = cmin; axis = i; } - if (cmax < max) + if (cmax < max) { max = cmax; - if (max < min) + } + if (max < min) { return false; + } } // Convert to 3D again. @@ -378,10 +406,12 @@ public: res_normal.normalize(); - if (r_res) + if (r_res) { *r_res = result; - if (r_norm) + } + if (r_norm) { *r_norm = res_normal; + } return true; } @@ -392,8 +422,9 @@ public: Vector3 rel = p_to - p_from; real_t rel_l = rel.length(); - if (rel_l < CMP_EPSILON) + if (rel_l < CMP_EPSILON) { return false; + } Vector3 dir = rel / rel_l; @@ -404,15 +435,17 @@ public: real_t den = p.normal.dot(dir); - if (Math::abs(den) <= CMP_EPSILON) + if (Math::abs(den) <= CMP_EPSILON) { continue; // Ignore parallel plane. + } real_t dist = -p.distance_to(p_from) / den; if (den > 0) { // Backwards facing plane. - if (dist < max) + if (dist < max) { max = dist; + } } else { // Front facing plane. if (dist > min) { @@ -422,13 +455,16 @@ public: } } - if (max <= min || min < 0 || min > rel_l || min_index == -1) // Exit conditions. + if (max <= min || min < 0 || min > rel_l || min_index == -1) { // Exit conditions. return false; // No intersection. + } - if (p_res) + if (p_res) { *p_res = p_from + dir * min; - if (p_norm) + } + if (p_norm) { *p_norm = p_planes[min_index].normal; + } return true; } @@ -437,25 +473,28 @@ public: Vector3 p = p_point - p_segment[0]; Vector3 n = p_segment[1] - p_segment[0]; real_t l2 = n.length_squared(); - if (l2 < 1e-20) + if (l2 < 1e-20) { return p_segment[0]; // Both points are the same, just give any. + } real_t d = n.dot(p) / l2; - if (d <= 0.0) + if (d <= 0.0) { return p_segment[0]; // Before first point. - else if (d >= 1.0) + } else if (d >= 1.0) { return p_segment[1]; // After first point. - else + } else { return p_segment[0] + n * d; // Inside. + } } static Vector3 get_closest_point_to_segment_uncapped(const Vector3 &p_point, const Vector3 *p_segment) { Vector3 p = p_point - p_segment[0]; Vector3 n = p_segment[1] - p_segment[0]; real_t l2 = n.length_squared(); - if (l2 < 1e-20) + if (l2 < 1e-20) { return p_segment[0]; // Both points are the same, just give any. + } real_t d = n.dot(p) / l2; @@ -466,17 +505,19 @@ public: Vector2 p = p_point - p_segment[0]; Vector2 n = p_segment[1] - p_segment[0]; real_t l2 = n.length_squared(); - if (l2 < 1e-20) + if (l2 < 1e-20) { return p_segment[0]; // Both points are the same, just give any. + } real_t d = n.dot(p) / l2; - if (d <= 0.0) + if (d <= 0.0) { return p_segment[0]; // Before first point. - else if (d >= 1.0) + } else if (d >= 1.0) { return p_segment[1]; // After first point. - else + } else { return p_segment[0] + n * d; // Inside. + } } static bool is_point_in_triangle(const Vector2 &s, const Vector2 &a, const Vector2 &b, const Vector2 &c) { @@ -486,8 +527,9 @@ public: bool orientation = an.cross(bn) > 0; - if ((bn.cross(cn) > 0) != orientation) + if ((bn.cross(cn) > 0) != orientation) { return false; + } return (cn.cross(an) > 0) == orientation; } @@ -496,8 +538,9 @@ public: Vector2 p = p_point - p_segment[0]; Vector2 n = p_segment[1] - p_segment[0]; real_t l2 = n.length_squared(); - if (l2 < 1e-20) + if (l2 < 1e-20) { return p_segment[0]; // Both points are the same, just give any. + } real_t d = n.dot(p) / l2; @@ -524,24 +567,28 @@ public: Vector2 D = p_to_b - p_from_a; real_t ABlen = B.dot(B); - if (ABlen <= 0) + if (ABlen <= 0) { return false; + } Vector2 Bn = B / ABlen; C = Vector2(C.x * Bn.x + C.y * Bn.y, C.y * Bn.x - C.x * Bn.y); D = Vector2(D.x * Bn.x + D.y * Bn.y, D.y * Bn.x - D.x * Bn.y); - if ((C.y < 0 && D.y < 0) || (C.y >= 0 && D.y >= 0)) + if ((C.y < 0 && D.y < 0) || (C.y >= 0 && D.y >= 0)) { return false; + } real_t ABpos = D.x + (C.x - D.x) * D.y / (D.y - C.y); // Fail if segment C-D crosses line A-B outside of segment A-B. - if (ABpos < 0 || ABpos > 1.0) + if (ABpos < 0 || ABpos > 1.0) { return false; + } // (4) Apply the discovered position to line A-B in the original coordinate system. - if (r_result) + if (r_result) { *r_result = p_from_a + B * ABpos; + } return true; } @@ -551,18 +598,21 @@ public: Vector3 n1 = (p_point - p_v3).cross(p_point - p_v2); - if (face_n.dot(n1) < 0) + if (face_n.dot(n1) < 0) { return false; + } Vector3 n2 = (p_v1 - p_v3).cross(p_v1 - p_point); - if (face_n.dot(n2) < 0) + if (face_n.dot(n2) < 0) { return false; + } Vector3 n3 = (p_v1 - p_point).cross(p_v1 - p_v2); - if (face_n.dot(n3) < 0) + if (face_n.dot(n3) < 0) { return false; + } return true; } @@ -570,8 +620,10 @@ public: static inline bool triangle_sphere_intersection_test(const Vector3 *p_triangle, const Vector3 &p_normal, const Vector3 &p_sphere_pos, real_t p_sphere_radius, Vector3 &r_triangle_contact, Vector3 &r_sphere_contact) { real_t d = p_normal.dot(p_sphere_pos) - p_normal.dot(p_triangle[0]); - if (d > p_sphere_radius || d < -p_sphere_radius) // Not touching the plane of the face, return. + if (d > p_sphere_radius || d < -p_sphere_radius) { + // Not touching the plane of the face, return. return false; + } Vector3 contact = p_sphere_pos - (p_normal * d); @@ -663,8 +715,9 @@ public: // If the term we intend to square root is less than 0 then the answer won't be real, // so it definitely won't be t in the range 0 to 1. - if (sqrtterm < 0) + if (sqrtterm < 0) { return -1; + } // If we can assume that the line segment starts outside the circle (e.g. for continuous time collision detection) // then the following can be skipped and we can just return the equivalent of res1. @@ -672,10 +725,12 @@ public: real_t res1 = (-b - sqrtterm) / (2 * a); real_t res2 = (-b + sqrtterm) / (2 * a); - if (res1 >= 0 && res1 <= 1) + if (res1 >= 0 && res1 <= 1) { return res1; - if (res2 >= 0 && res2 <= 1) + } + if (res2 >= 0 && res2 <= 1) { return res2; + } return -1; } @@ -686,8 +741,9 @@ public: LOC_OUTSIDE = -1 }; - if (polygon.size() == 0) + if (polygon.size() == 0) { return polygon; + } int *location_cache = (int *)alloca(sizeof(int) * polygon.size()); int inside_count = 0; @@ -710,7 +766,6 @@ public: if (outside_count == 0) { return polygon; // No changes. - } else if (inside_count == 0) { return Vector<Vector3>(); // Empty. } @@ -818,15 +873,17 @@ public: static Vector<int> triangulate_polygon(const Vector<Vector2> &p_polygon) { Vector<int> triangles; - if (!Triangulate::triangulate(p_polygon, triangles)) + if (!Triangulate::triangulate(p_polygon, triangles)) { return Vector<int>(); //fail + } return triangles; } static bool is_polygon_clockwise(const Vector<Vector2> &p_polygon) { int c = p_polygon.size(); - if (c < 3) + if (c < 3) { return false; + } const Vector2 *p = p_polygon.ptr(); real_t sum = 0; for (int i = 0; i < c; i++) { @@ -841,8 +898,9 @@ public: // Alternate implementation that should be faster. static bool is_point_in_polygon(const Vector2 &p_point, const Vector<Vector2> &p_polygon) { int c = p_polygon.size(); - if (c < 3) + if (c < 3) { return false; + } const Vector2 *p = p_polygon.ptr(); Vector2 further_away(-1e20, -1e20); Vector2 further_away_opposite(1e20, 1e20); @@ -914,25 +972,29 @@ public: return (1 << 23) | (1 << 22) | (1 << 21) | (1 << 20); } else { int ret = 0; - if ((p_idx % 8) == 0) + if ((p_idx % 8) == 0) { ret |= (1 << (p_idx + 7)); - else + } else { ret |= (1 << (p_idx - 1)); - if ((p_idx % 8) == 7) + } + if ((p_idx % 8) == 7) { ret |= (1 << (p_idx - 7)); - else + } else { ret |= (1 << (p_idx + 1)); + } int mask = ret | (1 << p_idx); - if (p_idx < 8) + if (p_idx < 8) { ret |= 24; - else + } else { ret |= mask >> 8; + } - if (p_idx >= 16) + if (p_idx >= 16) { ret |= 25; - else + } else { ret |= mask << 8; + } return ret; } @@ -954,15 +1016,17 @@ public: // Build lower hull. for (int i = 0; i < n; ++i) { - while (k >= 2 && vec2_cross(H[k - 2], H[k - 1], P[i]) <= 0) + while (k >= 2 && vec2_cross(H[k - 2], H[k - 1], P[i]) <= 0) { k--; + } H.write[k++] = P[i]; } // Build upper hull. for (int i = n - 2, t = k + 1; i >= 0; i--) { - while (k >= t && vec2_cross(H[k - 2], H[k - 1], P[i]) <= 0) + while (k >= t && vec2_cross(H[k - 2], H[k - 1], P[i]) <= 0) { k--; + } H.write[k++] = P[i]; } @@ -983,14 +1047,18 @@ public: #define FINDMINMAX(x0, x1, x2, min, max) \ min = max = x0; \ - if (x1 < min) \ + if (x1 < min) { \ min = x1; \ - if (x1 > max) \ + } \ + if (x1 > max) { \ max = x1; \ - if (x2 < min) \ + } \ + if (x2 < min) { \ min = x2; \ - if (x2 > max) \ - max = x2; + } \ + if (x2 > max) { \ + max = x2; \ + } _FORCE_INLINE_ static bool planeBoxOverlap(Vector3 normal, float d, Vector3 maxbox) { int q; @@ -1004,10 +1072,12 @@ public: vmax[q] = -maxbox[q]; } } - if (normal.dot(vmin) + d > 0.0f) + if (normal.dot(vmin) + d > 0.0f) { return false; - if (normal.dot(vmax) + d >= 0.0f) + } + if (normal.dot(vmax) + d >= 0.0f) { return true; + } return false; } @@ -1024,8 +1094,9 @@ public: max = p0; \ } \ rad = fa * boxhalfsize.y + fb * boxhalfsize.z; \ - if (min > rad || max < -rad) \ - return false; + if (min > rad || max < -rad) { \ + return false; \ + } #define AXISTEST_X2(a, b, fa, fb) \ p0 = a * v0.y - b * v0.z; \ @@ -1038,8 +1109,9 @@ public: max = p0; \ } \ rad = fa * boxhalfsize.y + fb * boxhalfsize.z; \ - if (min > rad || max < -rad) \ - return false; + if (min > rad || max < -rad) { \ + return false; \ + } /*======================== Y-tests ========================*/ #define AXISTEST_Y02(a, b, fa, fb) \ @@ -1053,8 +1125,9 @@ public: max = p0; \ } \ rad = fa * boxhalfsize.x + fb * boxhalfsize.z; \ - if (min > rad || max < -rad) \ - return false; + if (min > rad || max < -rad) { \ + return false; \ + } #define AXISTEST_Y1(a, b, fa, fb) \ p0 = -a * v0.x + b * v0.z; \ @@ -1067,8 +1140,9 @@ public: max = p0; \ } \ rad = fa * boxhalfsize.x + fb * boxhalfsize.z; \ - if (min > rad || max < -rad) \ - return false; + if (min > rad || max < -rad) { \ + return false; \ + } /*======================== Z-tests ========================*/ @@ -1083,8 +1157,9 @@ public: max = p2; \ } \ rad = fa * boxhalfsize.x + fb * boxhalfsize.y; \ - if (min > rad || max < -rad) \ - return false; + if (min > rad || max < -rad) { \ + return false; \ + } #define AXISTEST_Z0(a, b, fa, fb) \ p0 = a * v0.x - b * v0.y; \ @@ -1097,8 +1172,9 @@ public: max = p0; \ } \ rad = fa * boxhalfsize.x + fb * boxhalfsize.y; \ - if (min > rad || max < -rad) \ - return false; + if (min > rad || max < -rad) { \ + return false; \ + } _FORCE_INLINE_ static bool triangle_box_overlap(const Vector3 &boxcenter, const Vector3 boxhalfsize, const Vector3 *triverts) { /* use separating axis theorem to test overlap between triangle and box */ @@ -1155,18 +1231,21 @@ public: /* test in X-direction */ FINDMINMAX(v0.x, v1.x, v2.x, min, max); - if (min > boxhalfsize.x || max < -boxhalfsize.x) + if (min > boxhalfsize.x || max < -boxhalfsize.x) { return false; + } /* test in Y-direction */ FINDMINMAX(v0.y, v1.y, v2.y, min, max); - if (min > boxhalfsize.y || max < -boxhalfsize.y) + if (min > boxhalfsize.y || max < -boxhalfsize.y) { return false; + } /* test in Z-direction */ FINDMINMAX(v0.z, v1.z, v2.z, min, max); - if (min > boxhalfsize.z || max < -boxhalfsize.z) + if (min > boxhalfsize.z || max < -boxhalfsize.z) { return false; + } /* Bullet 2: */ /* test if the box intersects the plane of the triangle */ diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp index 0c7a97e5c9..1585c96b38 100644 --- a/core/math/math_funcs.cpp +++ b/core/math/math_funcs.cpp @@ -94,16 +94,18 @@ double Math::dectime(double p_value, double p_amount, double p_step) { double sgn = p_value < 0 ? -1.0 : 1.0; double val = Math::abs(p_value); val -= p_amount * p_step; - if (val < 0.0) + if (val < 0.0) { val = 0.0; + } return val * sgn; } double Math::ease(double p_x, double p_c) { - if (p_x < 0) + if (p_x < 0) { p_x = 0; - else if (p_x > 1.0) + } else if (p_x > 1.0) { p_x = 1.0; + } if (p_c > 0) { if (p_c < 1.0) { return 1.0 - Math::pow(1.0 - p_x, 1.0 / p_c); @@ -118,8 +120,9 @@ double Math::ease(double p_x, double p_c) { } else { return (1.0 - Math::pow(1.0 - (p_x - 0.5) * 2.0, -p_c)) * 0.5 + 0.5; } - } else + } else { return 0; // no ease (raw) + } } double Math::stepify(double p_value, double p_step) { @@ -166,8 +169,9 @@ uint32_t Math::larger_prime(uint32_t p_val) { int idx = 0; while (true) { ERR_FAIL_COND_V(primes[idx] == 0, 0); - if (primes[idx] > p_val) + if (primes[idx] > p_val) { return primes[idx]; + } idx++; } } diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index 33a7d602c3..7a9fd60e23 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -232,14 +232,16 @@ public: static _ALWAYS_INLINE_ float range_lerp(float p_value, float p_istart, float p_istop, float p_ostart, float p_ostop) { return Math::lerp(p_ostart, p_ostop, Math::inverse_lerp(p_istart, p_istop, p_value)); } static _ALWAYS_INLINE_ double smoothstep(double p_from, double p_to, double p_weight) { - if (is_equal_approx(p_from, p_to)) + if (is_equal_approx(p_from, p_to)) { return p_from; + } double x = CLAMP((p_weight - p_from) / (p_to - p_from), 0.0, 1.0); return x * x * (3.0 - 2.0 * x); } static _ALWAYS_INLINE_ float smoothstep(float p_from, float p_to, float p_weight) { - if (is_equal_approx(p_from, p_to)) + if (is_equal_approx(p_from, p_to)) { return p_from; + } float x = CLAMP((p_weight - p_from) / (p_to - p_from), 0.0f, 1.0f); return x * x * (3.0f - 2.0f * x); } @@ -471,10 +473,11 @@ public: if (p_step != 0) { float a = Math::stepify(p_target - p_offset, p_step + p_separation) + p_offset; float b = a; - if (p_target >= 0) + if (p_target >= 0) { b -= p_separation; - else + } else { b += p_step; + } return (Math::abs(p_target - a) < Math::abs(p_target - b)) ? a : b; } return p_target; diff --git a/core/math/octree.h b/core/math/octree.h index 067103112d..c05fc4e9ed 100644 --- a/core/math/octree.h +++ b/core/math/octree.h @@ -190,12 +190,14 @@ private: } _FORCE_INLINE_ void _pair_reference(Element *p_A, Element *p_B) { - if (p_A == p_B || (p_A->userdata == p_B->userdata && p_A->userdata)) + if (p_A == p_B || (p_A->userdata == p_B->userdata && p_A->userdata)) { return; + } if (!(p_A->pairable_type & p_B->pairable_mask) && - !(p_B->pairable_type & p_A->pairable_mask)) + !(p_B->pairable_type & p_A->pairable_mask)) { return; // none can pair with none + } PairKey key(p_A->_id, p_B->_id); typename PairMap::Element *E = pair_map.find(key); @@ -220,8 +222,9 @@ private: } _FORCE_INLINE_ void _pair_unreference(Element *p_A, Element *p_B) { - if (p_A == p_B) + if (p_A == p_B) { return; + } PairKey key(p_A->_id, p_B->_id); typename PairMap::Element *E = pair_map.find(key); @@ -307,12 +310,14 @@ private: void _cull_point(Octant *p_octant, const Vector3 &p_point, T **p_result_array, int *p_result_idx, int p_result_max, int *p_subindex_array, uint32_t p_mask); void _remove_tree(Octant *p_octant) { - if (!p_octant) + if (!p_octant) { return; + } for (int i = 0; i < 8; i++) { - if (p_octant->children[i]) + if (p_octant->children[i]) { _remove_tree(p_octant->children[i]); + } } memdelete_allocator<Octant, AL>(p_octant); @@ -423,12 +428,15 @@ void Octree<T, use_pairs, AL>::_insert_element(Element *p_element, Octant *p_oct AABB aabb = p_octant->aabb; aabb.size *= 0.5; - if (i & 1) + if (i & 1) { aabb.position.x += aabb.size.x; - if (i & 2) + } + if (i & 2) { aabb.position.y += aabb.size.y; - if (i & 4) + } + if (i & 4) { aabb.position.z += aabb.size.z; + } if (aabb.intersects_inclusive(p_element->aabb)) { /* if actually intersects, create the child */ @@ -535,8 +543,9 @@ bool Octree<T, use_pairs, AL>::_remove_element_from_octant(Element *p_element, O while (true) { // check all exit conditions - if (p_octant == p_limit) // reached limit, nothing to erase, exit + if (p_octant == p_limit) { // reached limit, nothing to erase, exit return octant_removed; + } bool unpaired = false; @@ -583,8 +592,9 @@ bool Octree<T, use_pairs, AL>::_remove_element_from_octant(Element *p_element, O octant_removed = true; } - if (!removed && !unpaired) + if (!removed && !unpaired) { return octant_removed; // no reason to keep going up anymore! was already visited and was not removed + } p_octant = parent; } @@ -618,12 +628,14 @@ void Octree<T, use_pairs, AL>::_unpair_element(Element *p_element, Octant *p_oct p_octant->last_pass = pass; - if (p_octant->children_count == 0) + if (p_octant->children_count == 0) { return; // small optimization for leafs + } for (int i = 0; i < 8; i++) { - if (p_octant->children[i]) + if (p_octant->children[i]) { _unpair_element(p_element, p_octant->children[i]); + } } } @@ -654,12 +666,14 @@ void Octree<T, use_pairs, AL>::_pair_element(Element *p_element, Octant *p_octan } p_octant->last_pass = pass; - if (p_octant->children_count == 0) + if (p_octant->children_count == 0) { return; // small optimization for leafs + } for (int i = 0; i < 8; i++) { - if (p_octant->children[i]) + if (p_octant->children[i]) { _pair_element(p_element, p_octant->children[i]); + } } } @@ -673,8 +687,9 @@ void Octree<T, use_pairs, AL>::_remove_element(Element *p_element) { for (; I; I = I->next()) { Octant *o = I->get().octant; - if (!use_pairs) // small speedup + if (!use_pairs) { // small speedup o->elements.erase(I->get().E); + } _remove_element_from_octant(p_element, o); } @@ -690,14 +705,16 @@ void Octree<T, use_pairs, AL>::_remove_element(Element *p_element) { // erase children pairs, they are erased ONCE even if repeated pass++; for (int i = 0; i < 8; i++) { - if (o->children[i]) + if (o->children[i]) { _unpair_element(p_element, o->children[i]); + } } - if (p_element->pairable) + if (p_element->pairable) { o->pairable_elements.erase(I->get().E); - else + } else { o->elements.erase(I->get().E); + } } } @@ -742,8 +759,9 @@ OctreeElementID Octree<T, use_pairs, AL>::create(T *p_userdata, const AABB &p_aa if (!e.aabb.has_no_surface()) { _ensure_valid_root(p_aabb); _insert_element(&e, root); - if (use_pairs) + if (use_pairs) { _element_check_pairs(&e); + } } return last_element_id - 1; @@ -781,21 +799,24 @@ void Octree<T, use_pairs, AL>::move(OctreeElementID p_id, const AABB &p_aabb) { e.common_parent = nullptr; e.aabb = p_aabb; _insert_element(&e, root); - if (use_pairs) + if (use_pairs) { _element_check_pairs(&e); + } } return; } - if (!old_has_surf) // doing nothing + if (!old_has_surf) { // doing nothing return; + } // it still is enclosed in the same AABB it was assigned to if (e.container_aabb.encloses(p_aabb)) { e.aabb = p_aabb; - if (use_pairs) + if (use_pairs) { _element_check_pairs(&e); // must check pairs anyway + } return; } @@ -815,8 +836,9 @@ void Octree<T, use_pairs, AL>::move(OctreeElementID p_id, const AABB &p_aabb) { //src is now the place towards where insertion is going to happen pass++; - while (common_parent && !common_parent->aabb.encloses(p_aabb)) + while (common_parent && !common_parent->aabb.encloses(p_aabb)) { common_parent = common_parent->parent; + } ERR_FAIL_COND(!common_parent); @@ -838,10 +860,11 @@ void Octree<T, use_pairs, AL>::move(OctreeElementID p_id, const AABB &p_aabb) { o->elements.erase( F->get().E ); */ - if (use_pairs && e.pairable) + if (use_pairs && e.pairable) { o->pairable_elements.erase(F->get().E); - else + } else { o->elements.erase(F->get().E); + } if (_remove_element_from_octant(&e, o, common_parent->parent)) { owners.erase(F); @@ -858,8 +881,9 @@ void Octree<T, use_pairs, AL>::move(OctreeElementID p_id, const AABB &p_aabb) { // erase children pairs, unref ONCE pass++; for (int i = 0; i < 8; i++) { - if (o->children[i]) + if (o->children[i]) { _unpair_element(&e, o->children[i]); + } } } @@ -876,8 +900,9 @@ void Octree<T, use_pairs, AL>::set_pairable(OctreeElementID p_id, bool p_pairabl Element &e = E->get(); - if (p_pairable == e.pairable && e.pairable_type == p_pairable_type && e.pairable_mask == p_pairable_mask) + if (p_pairable == e.pairable && e.pairable_type == p_pairable_type && e.pairable_mask == p_pairable_mask) { return; // no changes, return + } if (!e.aabb.has_no_surface()) { _remove_element(&e); @@ -891,8 +916,9 @@ void Octree<T, use_pairs, AL>::set_pairable(OctreeElementID p_id, bool p_pairabl if (!e.aabb.has_no_surface()) { _ensure_valid_root(e.aabb); _insert_element(&e, root); - if (use_pairs) + if (use_pairs) { _element_check_pairs(&e); + } } } @@ -913,8 +939,9 @@ void Octree<T, use_pairs, AL>::erase(OctreeElementID p_id) { template <class T, bool use_pairs, class AL> void Octree<T, use_pairs, AL>::_cull_convex(Octant *p_octant, _CullConvexData *p_cull) { - if (*p_cull->result_idx == p_cull->result_max) + if (*p_cull->result_idx == p_cull->result_max) { return; //pointless + } if (!p_octant->elements.empty()) { typename List<Element *, AL>::Element *I; @@ -923,8 +950,9 @@ void Octree<T, use_pairs, AL>::_cull_convex(Octant *p_octant, _CullConvexData *p for (; I; I = I->next()) { Element *e = I->get(); - if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_cull->mask))) + if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_cull->mask))) { continue; + } e->last_pass = pass; if (e->aabb.intersects_convex_shape(p_cull->planes, p_cull->plane_count, p_cull->points, p_cull->point_count)) { @@ -945,8 +973,9 @@ void Octree<T, use_pairs, AL>::_cull_convex(Octant *p_octant, _CullConvexData *p for (; I; I = I->next()) { Element *e = I->get(); - if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_cull->mask))) + if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_cull->mask))) { continue; + } e->last_pass = pass; if (e->aabb.intersects_convex_shape(p_cull->planes, p_cull->plane_count, p_cull->points, p_cull->point_count)) { @@ -969,8 +998,9 @@ void Octree<T, use_pairs, AL>::_cull_convex(Octant *p_octant, _CullConvexData *p template <class T, bool use_pairs, class AL> void Octree<T, use_pairs, AL>::_cull_aabb(Octant *p_octant, const AABB &p_aabb, T **p_result_array, int *p_result_idx, int p_result_max, int *p_subindex_array, uint32_t p_mask) { - if (*p_result_idx == p_result_max) + if (*p_result_idx == p_result_max) { return; //pointless + } if (!p_octant->elements.empty()) { typename List<Element *, AL>::Element *I; @@ -978,15 +1008,17 @@ void Octree<T, use_pairs, AL>::_cull_aabb(Octant *p_octant, const AABB &p_aabb, for (; I; I = I->next()) { Element *e = I->get(); - if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask))) + if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask))) { continue; + } e->last_pass = pass; if (p_aabb.intersects_inclusive(e->aabb)) { if (*p_result_idx < p_result_max) { p_result_array[*p_result_idx] = e->userdata; - if (p_subindex_array) + if (p_subindex_array) { p_subindex_array[*p_result_idx] = e->subindex; + } (*p_result_idx)++; } else { @@ -1002,15 +1034,17 @@ void Octree<T, use_pairs, AL>::_cull_aabb(Octant *p_octant, const AABB &p_aabb, for (; I; I = I->next()) { Element *e = I->get(); - if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask))) + if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask))) { continue; + } e->last_pass = pass; if (p_aabb.intersects_inclusive(e->aabb)) { if (*p_result_idx < p_result_max) { p_result_array[*p_result_idx] = e->userdata; - if (p_subindex_array) + if (p_subindex_array) { p_subindex_array[*p_result_idx] = e->subindex; + } (*p_result_idx)++; } else { return; // pointless to continue @@ -1028,8 +1062,9 @@ void Octree<T, use_pairs, AL>::_cull_aabb(Octant *p_octant, const AABB &p_aabb, template <class T, bool use_pairs, class AL> void Octree<T, use_pairs, AL>::_cull_segment(Octant *p_octant, const Vector3 &p_from, const Vector3 &p_to, T **p_result_array, int *p_result_idx, int p_result_max, int *p_subindex_array, uint32_t p_mask) { - if (*p_result_idx == p_result_max) + if (*p_result_idx == p_result_max) { return; //pointless + } if (!p_octant->elements.empty()) { typename List<Element *, AL>::Element *I; @@ -1037,15 +1072,17 @@ void Octree<T, use_pairs, AL>::_cull_segment(Octant *p_octant, const Vector3 &p_ for (; I; I = I->next()) { Element *e = I->get(); - if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask))) + if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask))) { continue; + } e->last_pass = pass; if (e->aabb.intersects_segment(p_from, p_to)) { if (*p_result_idx < p_result_max) { p_result_array[*p_result_idx] = e->userdata; - if (p_subindex_array) + if (p_subindex_array) { p_subindex_array[*p_result_idx] = e->subindex; + } (*p_result_idx)++; } else { @@ -1061,16 +1098,18 @@ void Octree<T, use_pairs, AL>::_cull_segment(Octant *p_octant, const Vector3 &p_ for (; I; I = I->next()) { Element *e = I->get(); - if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask))) + if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask))) { continue; + } e->last_pass = pass; if (e->aabb.intersects_segment(p_from, p_to)) { if (*p_result_idx < p_result_max) { p_result_array[*p_result_idx] = e->userdata; - if (p_subindex_array) + if (p_subindex_array) { p_subindex_array[*p_result_idx] = e->subindex; + } (*p_result_idx)++; @@ -1090,8 +1129,9 @@ void Octree<T, use_pairs, AL>::_cull_segment(Octant *p_octant, const Vector3 &p_ template <class T, bool use_pairs, class AL> void Octree<T, use_pairs, AL>::_cull_point(Octant *p_octant, const Vector3 &p_point, T **p_result_array, int *p_result_idx, int p_result_max, int *p_subindex_array, uint32_t p_mask) { - if (*p_result_idx == p_result_max) + if (*p_result_idx == p_result_max) { return; //pointless + } if (!p_octant->elements.empty()) { typename List<Element *, AL>::Element *I; @@ -1099,15 +1139,17 @@ void Octree<T, use_pairs, AL>::_cull_point(Octant *p_octant, const Vector3 &p_po for (; I; I = I->next()) { Element *e = I->get(); - if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask))) + if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask))) { continue; + } e->last_pass = pass; if (e->aabb.has_point(p_point)) { if (*p_result_idx < p_result_max) { p_result_array[*p_result_idx] = e->userdata; - if (p_subindex_array) + if (p_subindex_array) { p_subindex_array[*p_result_idx] = e->subindex; + } (*p_result_idx)++; } else { @@ -1123,16 +1165,18 @@ void Octree<T, use_pairs, AL>::_cull_point(Octant *p_octant, const Vector3 &p_po for (; I; I = I->next()) { Element *e = I->get(); - if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask))) + if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask))) { continue; + } e->last_pass = pass; if (e->aabb.has_point(p_point)) { if (*p_result_idx < p_result_max) { p_result_array[*p_result_idx] = e->userdata; - if (p_subindex_array) + if (p_subindex_array) { p_subindex_array[*p_result_idx] = e->subindex; + } (*p_result_idx)++; @@ -1153,12 +1197,14 @@ void Octree<T, use_pairs, AL>::_cull_point(Octant *p_octant, const Vector3 &p_po template <class T, bool use_pairs, class AL> int Octree<T, use_pairs, AL>::cull_convex(const Vector<Plane> &p_convex, T **p_result_array, int p_result_max, uint32_t p_mask) { - if (!root || p_convex.size() == 0) + if (!root || p_convex.size() == 0) { return 0; + } Vector<Vector3> convex_points = Geometry::compute_convex_mesh_points(&p_convex[0], p_convex.size()); - if (convex_points.size() == 0) + if (convex_points.size() == 0) { return 0; + } int result_count = 0; pass++; @@ -1179,8 +1225,9 @@ int Octree<T, use_pairs, AL>::cull_convex(const Vector<Plane> &p_convex, T **p_r template <class T, bool use_pairs, class AL> int Octree<T, use_pairs, AL>::cull_aabb(const AABB &p_aabb, T **p_result_array, int p_result_max, int *p_subindex_array, uint32_t p_mask) { - if (!root) + if (!root) { return 0; + } int result_count = 0; pass++; @@ -1191,8 +1238,9 @@ int Octree<T, use_pairs, AL>::cull_aabb(const AABB &p_aabb, T **p_result_array, template <class T, bool use_pairs, class AL> int Octree<T, use_pairs, AL>::cull_segment(const Vector3 &p_from, const Vector3 &p_to, T **p_result_array, int p_result_max, int *p_subindex_array, uint32_t p_mask) { - if (!root) + if (!root) { return 0; + } int result_count = 0; pass++; @@ -1203,8 +1251,9 @@ int Octree<T, use_pairs, AL>::cull_segment(const Vector3 &p_from, const Vector3 template <class T, bool use_pairs, class AL> int Octree<T, use_pairs, AL>::cull_point(const Vector3 &p_point, T **p_result_array, int p_result_max, int *p_subindex_array, uint32_t p_mask) { - if (!root) + if (!root) { return 0; + } int result_count = 0; pass++; diff --git a/core/math/plane.cpp b/core/math/plane.cpp index 94bdd41bd4..df37ceb0e5 100644 --- a/core/math/plane.cpp +++ b/core/math/plane.cpp @@ -61,10 +61,11 @@ Vector3 Plane::get_any_perpendicular_normal() const { static const Vector3 p2 = Vector3(0, 1, 0); Vector3 p; - if (ABS(normal.dot(p1)) > 0.99) // if too similar to p1 + if (ABS(normal.dot(p1)) > 0.99) { // if too similar to p1 p = p2; // use p2 - else + } else { p = p1; // use p1 + } p -= normal * normal.dot(p); p.normalize(); @@ -82,8 +83,9 @@ bool Plane::intersect_3(const Plane &p_plane1, const Plane &p_plane2, Vector3 *r real_t denom = vec3_cross(normal0, normal1).dot(normal2); - if (Math::is_zero_approx(denom)) + if (Math::is_zero_approx(denom)) { return false; + } if (r_result) { *r_result = ((vec3_cross(normal1, normal2) * p_plane0.d) + diff --git a/core/math/plane.h b/core/math/plane.h index 017835a6da..9a3e5a485f 100644 --- a/core/math/plane.h +++ b/core/math/plane.h @@ -109,10 +109,11 @@ Plane::Plane(const Vector3 &p_point, const Vector3 &p_normal) : } Plane::Plane(const Vector3 &p_point1, const Vector3 &p_point2, const Vector3 &p_point3, ClockDirection p_dir) { - if (p_dir == CLOCKWISE) + if (p_dir == CLOCKWISE) { normal = (p_point1 - p_point3).cross(p_point1 - p_point2); - else + } else { normal = (p_point1 - p_point2).cross(p_point1 - p_point3); + } normal.normalize(); d = normal.dot(p_point1); diff --git a/core/math/quat.cpp b/core/math/quat.cpp index f4b708616e..c10f5da494 100644 --- a/core/math/quat.cpp +++ b/core/math/quat.cpp @@ -202,8 +202,9 @@ Quat Quat::slerpni(const Quat &q, const real_t &t) const { real_t dot = from.dot(q); - if (Math::absf(dot) > 0.9999) + if (Math::absf(dot) > 0.9999) { return from; + } real_t theta = Math::acos(dot), sinT = 1.0 / Math::sin(theta), @@ -237,9 +238,9 @@ void Quat::set_axis_angle(const Vector3 &axis, const real_t &angle) { ERR_FAIL_COND_MSG(!axis.is_normalized(), "The axis Vector3 must be normalized."); #endif real_t d = axis.length(); - if (d == 0) + if (d == 0) { set(0, 0, 0, 0); - else { + } else { real_t sin_angle = Math::sin(angle * 0.5); real_t cos_angle = Math::cos(angle * 0.5); real_t s = sin_angle / d; diff --git a/core/math/quick_hull.cpp b/core/math/quick_hull.cpp index ace8ac9878..fe16904448 100644 --- a/core/math/quick_hull.cpp +++ b/core/math/quick_hull.cpp @@ -75,8 +75,9 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me real_t max = 0, min = 0; for (int i = 0; i < p_points.size(); i++) { - if (!valid_points[i]) + if (!valid_points[i]) { continue; + } real_t d = p_points[i][longest_axis]; if (i == 0 || d < min) { simplex[0] = i; @@ -97,8 +98,9 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me Vector3 rel12 = p_points[simplex[0]] - p_points[simplex[1]]; for (int i = 0; i < p_points.size(); i++) { - if (!valid_points[i]) + if (!valid_points[i]) { continue; + } Vector3 n = rel12.cross(p_points[simplex[0]] - p_points[i]).cross(rel12).normalized(); real_t d = Math::abs(n.dot(p_points[simplex[0]]) - n.dot(p_points[i])); @@ -117,8 +119,9 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me Plane p(p_points[simplex[0]], p_points[simplex[1]], p_points[simplex[2]]); for (int i = 0; i < p_points.size(); i++) { - if (!valid_points[i]) + if (!valid_points[i]) { continue; + } real_t d = Math::abs(p.distance_to(p_points[i])); @@ -173,16 +176,21 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me /* COMPUTE AVAILABLE VERTICES */ for (int i = 0; i < p_points.size(); i++) { - if (i == simplex[0]) + if (i == simplex[0]) { continue; - if (i == simplex[1]) + } + if (i == simplex[1]) { continue; - if (i == simplex[2]) + } + if (i == simplex[2]) { continue; - if (i == simplex[3]) + } + if (i == simplex[3]) { continue; - if (!valid_points[i]) + } + if (!valid_points[i]) { continue; + } for (List<Face>::Element *E = faces.front(); E; E = E->next()) { if (E->get().plane.distance_to(p_points[i]) > over_tolerance) { @@ -288,8 +296,9 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me Face &lf = F->get()->get(); for (int i = 0; i < lf.points_over.size(); i++) { - if (lf.points_over[i] == f.points_over[next]) //do not add current one + if (lf.points_over[i] == f.points_over[next]) { //do not add current one continue; + } Vector3 p = p_points[lf.points_over[i]]; for (List<List<Face>::Element *>::Element *E = new_faces.front(); E; E = E->next()) { @@ -397,10 +406,11 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me Map<Edge, RetFaceConnect>::Element *F2 = ret_edges.find(e2); ERR_CONTINUE(!F2); //change faceconnect, point to this face instead - if (F2->get().left == O) + if (F2->get().left == O) { F2->get().left = E; - else if (F2->get().right == O) + } else if (F2->get().right == O) { F2->get().right = E; + } } break; @@ -409,11 +419,13 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me // remove all edge connections to this face for (Map<Edge, RetFaceConnect>::Element *G = ret_edges.front(); G; G = G->next()) { - if (G->get().left == O) + if (G->get().left == O) { G->get().left = nullptr; + } - if (G->get().right == O) + if (G->get().right == O) { G->get().right = nullptr; + } } ret_edges.erase(F); //remove the edge diff --git a/core/math/random_number_generator.h b/core/math/random_number_generator.h index 2b125433b3..920308e597 100644 --- a/core/math/random_number_generator.h +++ b/core/math/random_number_generator.h @@ -59,10 +59,11 @@ public: _FORCE_INLINE_ int randi_range(int from, int to) { unsigned int ret = randbase.rand(); - if (to < from) + if (to < from) { return ret % (from - to + 1) + to; - else + } else { return ret % (to - from + 1) + from; + } } RandomNumberGenerator() {} diff --git a/core/math/rect2.cpp b/core/math/rect2.cpp index 1e26f815ed..0cc3c4ca0f 100644 --- a/core/math/rect2.cpp +++ b/core/math/rect2.cpp @@ -48,16 +48,18 @@ bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2 real_t csign; if (seg_from < seg_to) { - if (seg_from > box_end || seg_to < box_begin) + if (seg_from > box_end || seg_to < box_begin) { return false; + } real_t length = seg_to - seg_from; cmin = (seg_from < box_begin) ? ((box_begin - seg_from) / length) : 0; cmax = (seg_to > box_end) ? ((box_end - seg_from) / length) : 1; csign = -1.0; } else { - if (seg_to > box_end || seg_from < box_begin) + if (seg_to > box_end || seg_from < box_begin) { return false; + } real_t length = seg_to - seg_from; cmin = (seg_from > box_end) ? (box_end - seg_from) / length : 0; cmax = (seg_to < box_begin) ? (box_begin - seg_from) / length : 1; @@ -69,10 +71,12 @@ bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2 axis = i; sign = csign; } - if (cmax < max) + if (cmax < max) { max = cmax; - if (max < min) + } + if (max < min) { return false; + } } Vector2 rel = p_to - p_from; @@ -83,8 +87,9 @@ bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2 *r_normal = normal; } - if (r_pos) + if (r_pos) { *r_pos = p_from + rel * min; + } return true; } @@ -103,14 +108,18 @@ bool Rect2::intersects_transformed(const Transform2D &p_xform, const Rect2 &p_re //base rect2 first (faster) - if (xf_points[0].y > position.y) + if (xf_points[0].y > position.y) { goto next1; - if (xf_points[1].y > position.y) + } + if (xf_points[1].y > position.y) { goto next1; - if (xf_points[2].y > position.y) + } + if (xf_points[2].y > position.y) { goto next1; - if (xf_points[3].y > position.y) + } + if (xf_points[3].y > position.y) { goto next1; + } return false; @@ -118,27 +127,35 @@ next1: low_limit = position.y + size.y; - if (xf_points[0].y < low_limit) + if (xf_points[0].y < low_limit) { goto next2; - if (xf_points[1].y < low_limit) + } + if (xf_points[1].y < low_limit) { goto next2; - if (xf_points[2].y < low_limit) + } + if (xf_points[2].y < low_limit) { goto next2; - if (xf_points[3].y < low_limit) + } + if (xf_points[3].y < low_limit) { goto next2; + } return false; next2: - if (xf_points[0].x > position.x) + if (xf_points[0].x > position.x) { goto next3; - if (xf_points[1].x > position.x) + } + if (xf_points[1].x > position.x) { goto next3; - if (xf_points[2].x > position.x) + } + if (xf_points[2].x > position.x) { goto next3; - if (xf_points[3].x > position.x) + } + if (xf_points[3].x > position.x) { goto next3; + } return false; @@ -146,14 +163,18 @@ next3: low_limit = position.x + size.x; - if (xf_points[0].x < low_limit) + if (xf_points[0].x < low_limit) { goto next4; - if (xf_points[1].x < low_limit) + } + if (xf_points[1].x < low_limit) { goto next4; - if (xf_points[2].x < low_limit) + } + if (xf_points[2].x < low_limit) { goto next4; - if (xf_points[3].x < low_limit) + } + if (xf_points[3].x < low_limit) { goto next4; + } return false; @@ -196,10 +217,12 @@ next4: maxb = MAX(dp, maxb); minb = MIN(dp, minb); - if (mina > maxb) + if (mina > maxb) { return false; - if (minb > maxa) + } + if (minb > maxa) { return false; + } maxa = p_xform.elements[1].dot(xf_points2[0]); mina = maxa; @@ -231,10 +254,12 @@ next4: maxb = MAX(dp, maxb); minb = MIN(dp, minb); - if (mina > maxb) + if (mina > maxb) { return false; - if (minb > maxa) + } + if (minb > maxa) { return false; + } return true; } diff --git a/core/math/rect2.h b/core/math/rect2.h index f6274ae32b..1b86dbd49a 100644 --- a/core/math/rect2.h +++ b/core/math/rect2.h @@ -48,23 +48,31 @@ struct Rect2 { inline bool intersects(const Rect2 &p_rect, const bool p_include_borders = false) const { if (p_include_borders) { - if (position.x > (p_rect.position.x + p_rect.size.width)) + if (position.x > (p_rect.position.x + p_rect.size.width)) { return false; - if ((position.x + size.width) < p_rect.position.x) + } + if ((position.x + size.width) < p_rect.position.x) { return false; - if (position.y > (p_rect.position.y + p_rect.size.height)) + } + if (position.y > (p_rect.position.y + p_rect.size.height)) { return false; - if ((position.y + size.height) < p_rect.position.y) + } + if ((position.y + size.height) < p_rect.position.y) { return false; + } } else { - if (position.x >= (p_rect.position.x + p_rect.size.width)) + if (position.x >= (p_rect.position.x + p_rect.size.width)) { return false; - if ((position.x + size.width) <= p_rect.position.x) + } + if ((position.x + size.width) <= p_rect.position.x) { return false; - if (position.y >= (p_rect.position.y + p_rect.size.height)) + } + if (position.y >= (p_rect.position.y + p_rect.size.height)) { return false; - if ((position.y + size.height) <= p_rect.position.y) + } + if ((position.y + size.height) <= p_rect.position.y) { return false; + } } return true; @@ -95,10 +103,11 @@ struct Rect2 { inside = false; } - if (inside) + if (inside) { return 0; - else + } else { return dist; + } } bool intersects_transformed(const Transform2D &p_xform, const Rect2 &p_rect) const; @@ -118,8 +127,9 @@ struct Rect2 { Rect2 new_rect = p_rect; - if (!intersects(new_rect)) + if (!intersects(new_rect)) { return Rect2(); + } new_rect.position.x = MAX(p_rect.position.x, position.x); new_rect.position.y = MAX(p_rect.position.y, position.y); @@ -148,15 +158,19 @@ struct Rect2 { return new_rect; }; inline bool has_point(const Point2 &p_point) const { - if (p_point.x < position.x) + if (p_point.x < position.x) { return false; - if (p_point.y < position.y) + } + if (p_point.y < position.y) { return false; + } - if (p_point.x >= (position.x + size.x)) + if (p_point.x >= (position.x + size.x)) { return false; - if (p_point.y >= (position.y + size.y)) + } + if (p_point.y >= (position.y + size.y)) { return false; + } return true; } @@ -204,15 +218,19 @@ struct Rect2 { Vector2 begin = position; Vector2 end = position + size; - if (p_vector.x < begin.x) + if (p_vector.x < begin.x) { begin.x = p_vector.x; - if (p_vector.y < begin.y) + } + if (p_vector.y < begin.y) { begin.y = p_vector.y; + } - if (p_vector.x > end.x) + if (p_vector.x > end.x) { end.x = p_vector.x; - if (p_vector.y > end.y) + } + if (p_vector.y > end.y) { end.y = p_vector.y; + } position = begin; size = end - begin; @@ -247,14 +265,18 @@ struct Rect2i { int get_area() const { return size.width * size.height; } inline bool intersects(const Rect2i &p_rect) const { - if (position.x > (p_rect.position.x + p_rect.size.width)) + if (position.x > (p_rect.position.x + p_rect.size.width)) { return false; - if ((position.x + size.width) < p_rect.position.x) + } + if ((position.x + size.width) < p_rect.position.x) { return false; - if (position.y > (p_rect.position.y + p_rect.size.height)) + } + if (position.y > (p_rect.position.y + p_rect.size.height)) { return false; - if ((position.y + size.height) < p_rect.position.y) + } + if ((position.y + size.height) < p_rect.position.y) { return false; + } return true; } @@ -272,8 +294,9 @@ struct Rect2i { Rect2i new_rect = p_rect; - if (!intersects(new_rect)) + if (!intersects(new_rect)) { return Rect2i(); + } new_rect.position.x = MAX(p_rect.position.x, position.x); new_rect.position.y = MAX(p_rect.position.y, position.y); @@ -302,15 +325,19 @@ struct Rect2i { return new_rect; }; bool has_point(const Point2 &p_point) const { - if (p_point.x < position.x) + if (p_point.x < position.x) { return false; - if (p_point.y < position.y) + } + if (p_point.y < position.y) { return false; + } - if (p_point.x >= (position.x + size.x)) + if (p_point.x >= (position.x + size.x)) { return false; - if (p_point.y >= (position.y + size.y)) + } + if (p_point.y >= (position.y + size.y)) { return false; + } return true; } @@ -356,15 +383,19 @@ struct Rect2i { Point2i begin = position; Point2i end = position + size; - if (p_vector.x < begin.x) + if (p_vector.x < begin.x) { begin.x = p_vector.x; - if (p_vector.y < begin.y) + } + if (p_vector.y < begin.y) { begin.y = p_vector.y; + } - if (p_vector.x > end.x) + if (p_vector.x > end.x) { end.x = p_vector.x; - if (p_vector.y > end.y) + } + if (p_vector.y > end.y) { end.y = p_vector.y; + } position = begin; size = end - begin; diff --git a/core/math/transform_2d.cpp b/core/math/transform_2d.cpp index eecfc862f5..dee1b3b23e 100644 --- a/core/math/transform_2d.cpp +++ b/core/math/transform_2d.cpp @@ -165,8 +165,9 @@ bool Transform2D::is_equal_approx(const Transform2D &p_transform) const { bool Transform2D::operator==(const Transform2D &p_transform) const { for (int i = 0; i < 3; i++) { - if (elements[i] != p_transform.elements[i]) + if (elements[i] != p_transform.elements[i]) { return false; + } } return true; @@ -174,8 +175,9 @@ bool Transform2D::operator==(const Transform2D &p_transform) const { bool Transform2D::operator!=(const Transform2D &p_transform) const { for (int i = 0; i < 3; i++) { - if (elements[i] != p_transform.elements[i]) + if (elements[i] != p_transform.elements[i]) { return true; + } } return false; diff --git a/core/math/triangle_mesh.cpp b/core/math/triangle_mesh.cpp index 9a608e3f1b..c9a546e385 100644 --- a/core/math/triangle_mesh.cpp +++ b/core/math/triangle_mesh.cpp @@ -85,8 +85,9 @@ int TriangleMesh::_create_bvh(BVH *p_bvh, BVH **p_bb, int p_from, int p_size, in } void TriangleMesh::get_indices(Vector<int> *r_triangles_indices) const { - if (!valid) + if (!valid) { return; + } const int triangles_num = triangles.size(); @@ -139,10 +140,11 @@ void TriangleMesh::create(const Vector<Vector3> &p_faces) { } f.indices[j] = vidx; - if (j == 0) + if (j == 0) { bw[i].aabb.position = vs; - else + } else { bw[i].aabb.expand_to(vs); + } } f.normal = Face3(r[i * 3 + 0], r[i * 3 + 1], r[i * 3 + 2]).get_plane().get_normal(); @@ -243,18 +245,21 @@ Vector3 TriangleMesh::get_area_normal(const AABB &p_aabb) const { if (level == 0) { done = true; break; - } else + } else { level--; + } continue; } } - if (done) + if (done) { break; + } } - if (n_count > 0) + if (n_count > 0) { n /= n_count; + } return n; } @@ -340,19 +345,22 @@ bool TriangleMesh::intersect_segment(const Vector3 &p_begin, const Vector3 &p_en if (level == 0) { done = true; break; - } else + } else { level--; + } continue; } } - if (done) + if (done) { break; + } } if (inters) { - if (n.dot(r_normal) > 0) + if (n.dot(r_normal) > 0) { r_normal = -r_normal; + } } return inters; @@ -437,19 +445,22 @@ bool TriangleMesh::intersect_ray(const Vector3 &p_begin, const Vector3 &p_dir, V if (level == 0) { done = true; break; - } else + } else { level--; + } continue; } } - if (done) + if (done) { break; + } } if (inters) { - if (n.dot(r_normal) > 0) + if (n.dot(r_normal) > 0) { r_normal = -r_normal; + } } return inters; @@ -506,16 +517,18 @@ bool TriangleMesh::intersect_convex_shape(const Plane *p_planes, int p_plane_cou if (p.intersects_segment(point, next_point, &res)) { bool inisde = true; for (int k = 0; k < p_plane_count; k++) { - if (k == i) + if (k == i) { continue; + } const Plane &pp = p_planes[k]; if (pp.is_point_over(res)) { inisde = false; break; } } - if (inisde) + if (inisde) { return true; + } } if (p.is_point_over(point)) { @@ -523,8 +536,9 @@ bool TriangleMesh::intersect_convex_shape(const Plane *p_planes, int p_plane_cou break; } } - if (over) + if (over) { return true; + } } stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; @@ -551,14 +565,16 @@ bool TriangleMesh::intersect_convex_shape(const Plane *p_planes, int p_plane_cou if (level == 0) { done = true; break; - } else + } else { level--; + } continue; } } - if (done) + if (done) { break; + } } return false; @@ -597,8 +613,9 @@ bool TriangleMesh::inside_convex_shape(const Plane *p_planes, int p_plane_count, switch (stack[level] >> VISITED_BIT_SHIFT) { case TEST_AABB_BIT: { bool intersects = scale.xform(b.aabb).intersects_convex_shape(p_planes, p_plane_count, p_points, p_point_count); - if (!intersects) + if (!intersects) { return false; + } bool inside = scale.xform(b.aabb).inside_convex_shape(p_planes, p_plane_count); if (inside) { @@ -611,8 +628,9 @@ bool TriangleMesh::inside_convex_shape(const Plane *p_planes, int p_plane_count, Vector3 point = scale.xform(vertexptr[s.indices[j]]); for (int i = 0; i < p_plane_count; i++) { const Plane &p = p_planes[i]; - if (p.is_point_over(point)) + if (p.is_point_over(point)) { return false; + } } } @@ -640,14 +658,16 @@ bool TriangleMesh::inside_convex_shape(const Plane *p_planes, int p_plane_count, if (level == 0) { done = true; break; - } else + } else { level--; + } continue; } } - if (done) + if (done) { break; + } } return true; @@ -658,8 +678,9 @@ bool TriangleMesh::is_valid() const { } Vector<Face3> TriangleMesh::get_faces() const { - if (!valid) + if (!valid) { return Vector<Face3>(); + } Vector<Face3> faces; int ts = triangles.size(); diff --git a/core/math/triangulate.cpp b/core/math/triangulate.cpp index c7b838fd10..7fab36ff50 100644 --- a/core/math/triangulate.cpp +++ b/core/math/triangulate.cpp @@ -102,16 +102,19 @@ bool Triangulate::snip(const Vector<Vector2> &p_contour, int u, int v, int w, in // To avoid that we allow zero-area triangles if all else failed. float threshold = relaxed ? -CMP_EPSILON : CMP_EPSILON; - if (threshold > (((Bx - Ax) * (Cy - Ay)) - ((By - Ay) * (Cx - Ax)))) + if (threshold > (((Bx - Ax) * (Cy - Ay)) - ((By - Ay) * (Cx - Ax)))) { return false; + } for (p = 0; p < n; p++) { - if ((p == u) || (p == v) || (p == w)) + if ((p == u) || (p == v) || (p == w)) { continue; + } Px = contour[V[p]].x; Py = contour[V[p]].y; - if (is_inside_triangle(Ax, Ay, Bx, By, Cx, Cy, Px, Py, relaxed)) + if (is_inside_triangle(Ax, Ay, Bx, By, Cx, Cy, Px, Py, relaxed)) { return false; + } } return true; @@ -121,20 +124,24 @@ bool Triangulate::triangulate(const Vector<Vector2> &contour, Vector<int> &resul /* allocate and initialize list of Vertices in polygon */ int n = contour.size(); - if (n < 3) + if (n < 3) { return false; + } Vector<int> V; V.resize(n); /* we want a counter-clockwise polygon in V */ - if (0.0 < get_area(contour)) - for (int v = 0; v < n; v++) + if (0.0 < get_area(contour)) { + for (int v = 0; v < n; v++) { V.write[v] = v; - else - for (int v = 0; v < n; v++) + } + } else { + for (int v = 0; v < n; v++) { V.write[v] = (n - 1) - v; + } + } bool relaxed = false; @@ -164,14 +171,17 @@ bool Triangulate::triangulate(const Vector<Vector2> &contour, Vector<int> &resul /* three consecutive vertices in current polygon, <u,v,w> */ int u = v; - if (nv <= u) + if (nv <= u) { u = 0; /* previous */ + } v = u + 1; - if (nv <= v) + if (nv <= v) { v = 0; /* new v */ + } int w = v + 1; - if (nv <= w) + if (nv <= w) { w = 0; /* next */ + } if (snip(contour, u, v, w, nv, V, relaxed)) { int a, b, c, s, t; @@ -187,8 +197,9 @@ bool Triangulate::triangulate(const Vector<Vector2> &contour, Vector<int> &resul result.push_back(c); /* remove v from remaining polygon */ - for (s = v, t = v + 1; t < nv; s++, t++) + for (s = v, t = v + 1; t < nv; s++, t++) { V.write[s] = V[t]; + } nv--; diff --git a/core/math/vector3.cpp b/core/math/vector3.cpp index 4a9b251406..568df48c62 100644 --- a/core/math/vector3.cpp +++ b/core/math/vector3.cpp @@ -85,10 +85,12 @@ Vector3 Vector3::cubic_interpolaten(const Vector3 &p_b, const Vector3 &p_pre_a, real_t bc = p1.distance_to(p2); real_t cd = p2.distance_to(p3); - if (ab > 0) + if (ab > 0) { p0 = p1 + (p0 - p1) * (bc / ab); - if (cd > 0) + } + if (cd > 0) { p3 = p2 + (p3 - p2) * (bc / cd); + } } real_t t = p_t; diff --git a/core/math/vector3.h b/core/math/vector3.h index 3e35a5bba2..0bc1a467f2 100644 --- a/core/math/vector3.h +++ b/core/math/vector3.h @@ -323,10 +323,11 @@ bool Vector3::operator!=(const Vector3 &p_v) const { bool Vector3::operator<(const Vector3 &p_v) const { if (Math::is_equal_approx(x, p_v.x)) { - if (Math::is_equal_approx(y, p_v.y)) + if (Math::is_equal_approx(y, p_v.y)) { return z < p_v.z; - else + } else { return y < p_v.y; + } } else { return x < p_v.x; } @@ -334,10 +335,11 @@ bool Vector3::operator<(const Vector3 &p_v) const { bool Vector3::operator>(const Vector3 &p_v) const { if (Math::is_equal_approx(x, p_v.x)) { - if (Math::is_equal_approx(y, p_v.y)) + if (Math::is_equal_approx(y, p_v.y)) { return z > p_v.z; - else + } else { return y > p_v.y; + } } else { return x > p_v.x; } @@ -345,10 +347,11 @@ bool Vector3::operator>(const Vector3 &p_v) const { bool Vector3::operator<=(const Vector3 &p_v) const { if (Math::is_equal_approx(x, p_v.x)) { - if (Math::is_equal_approx(y, p_v.y)) + if (Math::is_equal_approx(y, p_v.y)) { return z <= p_v.z; - else + } else { return y < p_v.y; + } } else { return x < p_v.x; } @@ -356,10 +359,11 @@ bool Vector3::operator<=(const Vector3 &p_v) const { bool Vector3::operator>=(const Vector3 &p_v) const { if (Math::is_equal_approx(x, p_v.x)) { - if (Math::is_equal_approx(y, p_v.y)) + if (Math::is_equal_approx(y, p_v.y)) { return z >= p_v.z; - else + } else { return y > p_v.y; + } } else { return x > p_v.x; } diff --git a/core/math/vector3i.h b/core/math/vector3i.h index 524f45b452..08729ad056 100644 --- a/core/math/vector3i.h +++ b/core/math/vector3i.h @@ -199,10 +199,11 @@ bool Vector3i::operator!=(const Vector3i &p_v) const { bool Vector3i::operator<(const Vector3i &p_v) const { if (x == p_v.x) { - if (y == p_v.y) + if (y == p_v.y) { return z < p_v.z; - else + } else { return y < p_v.y; + } } else { return x < p_v.x; } @@ -210,10 +211,11 @@ bool Vector3i::operator<(const Vector3i &p_v) const { bool Vector3i::operator>(const Vector3i &p_v) const { if (x == p_v.x) { - if (y == p_v.y) + if (y == p_v.y) { return z > p_v.z; - else + } else { return y > p_v.y; + } } else { return x > p_v.x; } @@ -221,10 +223,11 @@ bool Vector3i::operator>(const Vector3i &p_v) const { bool Vector3i::operator<=(const Vector3i &p_v) const { if (x == p_v.x) { - if (y == p_v.y) + if (y == p_v.y) { return z <= p_v.z; - else + } else { return y < p_v.y; + } } else { return x < p_v.x; } @@ -232,10 +235,11 @@ bool Vector3i::operator<=(const Vector3i &p_v) const { bool Vector3i::operator>=(const Vector3i &p_v) const { if (x == p_v.x) { - if (y == p_v.y) + if (y == p_v.y) { return z >= p_v.z; - else + } else { return y > p_v.y; + } } else { return x > p_v.x; } diff --git a/core/message_queue.cpp b/core/message_queue.cpp index 36914de0ba..8c71f760b2 100644 --- a/core/message_queue.cpp +++ b/core/message_queue.cpp @@ -50,8 +50,9 @@ Error MessageQueue::push_call(ObjectID p_id, const StringName &p_method, VARIANT int argc = 0; for (int i = 0; i < VARIANT_ARG_MAX; i++) { - if (argptr[i]->get_type() == Variant::NIL) + if (argptr[i]->get_type() == Variant::NIL) { break; + } argc++; } @@ -65,8 +66,9 @@ Error MessageQueue::push_set(ObjectID p_id, const StringName &p_prop, const Vari if ((buffer_end + room_needed) >= buffer_size) { String type; - if (ObjectDB::get_instance(p_id)) + if (ObjectDB::get_instance(p_id)) { type = ObjectDB::get_instance(p_id)->get_class(); + } print_line("Failed set: " + type + ":" + p_prop + " target ID: " + itos(p_id)); statistics(); ERR_FAIL_V_MSG(ERR_OUT_OF_MEMORY, "Message queue out of memory. Try increasing 'memory/limits/message_queue/max_size_kb' in project settings."); @@ -138,8 +140,9 @@ Error MessageQueue::push_callable(const Callable &p_callable, const Variant **p_ msg->args = p_argcount; msg->callable = p_callable; msg->type = TYPE_CALL; - if (p_show_error) + if (p_show_error) { msg->type |= FLAG_SHOW_ERROR; + } buffer_end += sizeof(Message); @@ -167,23 +170,26 @@ void MessageQueue::statistics() { if (target != nullptr) { switch (message->type & FLAG_MASK) { case TYPE_CALL: { - if (!call_count.has(message->callable)) + if (!call_count.has(message->callable)) { call_count[message->callable] = 0; + } call_count[message->callable]++; } break; case TYPE_NOTIFICATION: { - if (!notify_count.has(message->notification)) + if (!notify_count.has(message->notification)) { notify_count[message->notification] = 0; + } notify_count[message->notification]++; } break; case TYPE_SET: { StringName t = message->callable.get_method(); - if (!set_count.has(t)) + if (!set_count.has(t)) { set_count[t] = 0; + } set_count[t]++; @@ -198,8 +204,9 @@ void MessageQueue::statistics() { } read_pos += sizeof(Message); - if ((message->type & FLAG_MASK) != TYPE_NOTIFICATION) + if ((message->type & FLAG_MASK) != TYPE_NOTIFICATION) { read_pos += sizeof(Variant) * message->args; + } } print_line("TOTAL BYTES: " + itos(buffer_end)); @@ -261,8 +268,9 @@ void MessageQueue::flush() { Message *message = (Message *)&buffer[read_pos]; uint32_t advance = sizeof(Message); - if ((message->type & FLAG_MASK) != TYPE_NOTIFICATION) + if ((message->type & FLAG_MASK) != TYPE_NOTIFICATION) { advance += sizeof(Variant) * message->args; + } //pre-advance so this function is reentrant read_pos += advance; @@ -334,14 +342,16 @@ MessageQueue::~MessageQueue() { Variant *args = (Variant *)(message + 1); int argc = message->args; if ((message->type & FLAG_MASK) != TYPE_NOTIFICATION) { - for (int i = 0; i < argc; i++) + for (int i = 0; i < argc; i++) { args[i].~Variant(); + } } message->~Message(); read_pos += sizeof(Message); - if ((message->type & FLAG_MASK) != TYPE_NOTIFICATION) + if ((message->type & FLAG_MASK) != TYPE_NOTIFICATION) { read_pos += sizeof(Variant) * message->args; + } } singleton = nullptr; diff --git a/core/method_bind.cpp b/core/method_bind.cpp index a88e6e21b0..3244c63292 100644 --- a/core/method_bind.cpp +++ b/core/method_bind.cpp @@ -103,7 +103,8 @@ MethodBind::MethodBind() { MethodBind::~MethodBind() { #ifdef DEBUG_METHODS_ENABLED - if (argument_types) + if (argument_types) { memdelete_arr(argument_types); + } #endif } diff --git a/core/method_bind.h b/core/method_bind.h index 7f3da9c25e..ff2c771f81 100644 --- a/core/method_bind.h +++ b/core/method_bind.h @@ -157,8 +157,9 @@ struct VariantObjectClassChecker<Control *> { #define CHECK_NOARG(m_arg) \ { \ if (p_arg##m_arg.get_type() != Variant::NIL) { \ - if (r_argerror) \ + if (r_argerror) { \ *r_argerror = (m_arg - 1); \ + } \ return CALL_ERROR_EXTRA_ARGUMENT; \ } \ } @@ -230,19 +231,21 @@ public: _FORCE_INLINE_ Variant has_default_argument(int p_arg) const { int idx = argument_count - p_arg - 1; - if (idx < 0 || idx >= default_arguments.size()) + if (idx < 0 || idx >= default_arguments.size()) { return false; - else + } else { return true; + } } _FORCE_INLINE_ Variant get_default_argument(int p_arg) const { int idx = argument_count - p_arg - 1; - if (idx < 0 || idx >= default_arguments.size()) + if (idx < 0 || idx >= default_arguments.size()) { return Variant(); - else + } else { return default_arguments[idx]; + } } #ifdef DEBUG_METHODS_ENABLED diff --git a/core/node_path.cpp b/core/node_path.cpp index fd28815704..2a51dca74a 100644 --- a/core/node_path.cpp +++ b/core/node_path.cpp @@ -57,15 +57,17 @@ void NodePath::prepend_period() { } bool NodePath::is_absolute() const { - if (!data) + if (!data) { return false; + } return data->absolute; } int NodePath::get_name_count() const { - if (!data) + if (!data) { return 0; + } return data->path.size(); } @@ -77,8 +79,9 @@ StringName NodePath::get_name(int p_idx) const { } int NodePath::get_subname_count() const { - if (!data) + if (!data) { return 0; + } return data->subpath.size(); } @@ -97,14 +100,17 @@ void NodePath::unref() { } bool NodePath::operator==(const NodePath &p_path) const { - if (data == p_path.data) + if (data == p_path.data) { return true; + } - if (!data || !p_path.data) + if (!data || !p_path.data) { return false; + } - if (data->absolute != p_path.data->absolute) + if (data->absolute != p_path.data->absolute) { return false; + } int path_size = data->path.size(); @@ -122,16 +128,18 @@ bool NodePath::operator==(const NodePath &p_path) const { const StringName *r_path_ptr = p_path.data->path.ptr(); for (int i = 0; i < path_size; i++) { - if (l_path_ptr[i] != r_path_ptr[i]) + if (l_path_ptr[i] != r_path_ptr[i]) { return false; + } } const StringName *l_subpath_ptr = data->subpath.ptr(); const StringName *r_subpath_ptr = p_path.data->subpath.ptr(); for (int i = 0; i < subpath_size; i++) { - if (l_subpath_ptr[i] != r_subpath_ptr[i]) + if (l_subpath_ptr[i] != r_subpath_ptr[i]) { return false; + } } return true; @@ -142,8 +150,9 @@ bool NodePath::operator!=(const NodePath &p_path) const { } void NodePath::operator=(const NodePath &p_path) { - if (this == &p_path) + if (this == &p_path) { return; + } unref(); @@ -153,16 +162,19 @@ void NodePath::operator=(const NodePath &p_path) { } NodePath::operator String() const { - if (!data) + if (!data) { return String(); + } String ret; - if (data->absolute) + if (data->absolute) { ret = "/"; + } for (int i = 0; i < data->path.size(); i++) { - if (i > 0) + if (i > 0) { ret += "/"; + } ret += data->path[i].operator String(); } @@ -174,14 +186,16 @@ NodePath::operator String() const { } Vector<StringName> NodePath::get_names() const { - if (data) + if (data) { return data->path; + } return Vector<StringName>(); } Vector<StringName> NodePath::get_subnames() const { - if (data) + if (data) { return data->subpath; + } return Vector<StringName>(); } @@ -211,12 +225,15 @@ NodePath NodePath::rel_path_to(const NodePath &p_np) const { int common_parent = 0; while (true) { - if (src_dirs.size() == common_parent) + if (src_dirs.size() == common_parent) { break; - if (dst_dirs.size() == common_parent) + } + if (dst_dirs.size() == common_parent) { break; - if (src_dirs[common_parent] != dst_dirs[common_parent]) + } + if (src_dirs[common_parent] != dst_dirs[common_parent]) { break; + } common_parent++; } @@ -232,8 +249,9 @@ NodePath NodePath::rel_path_to(const NodePath &p_np) const { relpath.push_back(dst_dirs[i]); } - if (relpath.size() == 0) + if (relpath.size() == 0) { relpath.push_back("."); + } return NodePath(relpath, p_np.get_subnames(), false); } @@ -260,11 +278,13 @@ bool NodePath::is_empty() const { } void NodePath::simplify() { - if (!data) + if (!data) { return; + } for (int i = 0; i < data->path.size(); i++) { - if (data->path.size() == 1) + if (data->path.size() == 1) { break; + } if (data->path[i].operator String() == ".") { data->path.remove(i); i--; @@ -289,8 +309,9 @@ NodePath NodePath::simplified() const { } NodePath::NodePath(const Vector<StringName> &p_path, bool p_absolute) { - if (p_path.size() == 0) + if (p_path.size() == 0) { return; + } data = memnew(Data); data->refcount.init(); @@ -301,8 +322,9 @@ NodePath::NodePath(const Vector<StringName> &p_path, bool p_absolute) { } NodePath::NodePath(const Vector<StringName> &p_path, const Vector<StringName> &p_subpath, bool p_absolute) { - if (p_path.size() == 0 && p_subpath.size() == 0) + if (p_path.size() == 0 && p_subpath.size() == 0) { return; + } data = memnew(Data); data->refcount.init(); @@ -320,8 +342,9 @@ NodePath::NodePath(const NodePath &p_path) { } NodePath::NodePath(const String &p_path) { - if (p_path.length() == 0) + if (p_path.length() == 0) { return; + } String path = p_path; Vector<StringName> subpath; @@ -339,8 +362,9 @@ NodePath::NodePath(const String &p_path) { if (path[i] == ':' || path[i] == 0) { String str = path.substr(from, i - from); if (str == "") { - if (path[i] == 0) + if (path[i] == 0) { continue; // Allow end-of-path : + } ERR_FAIL_MSG("Invalid NodePath '" + p_path + "'."); } @@ -358,15 +382,17 @@ NodePath::NodePath(const String &p_path) { last_is_slash = true; has_slashes = true; } else { - if (last_is_slash) + if (last_is_slash) { slices++; + } last_is_slash = false; } } - if (slices == 0 && !absolute && !subpath.size()) + if (slices == 0 && !absolute && !subpath.size()) { return; + } data = memnew(Data); data->refcount.init(); @@ -375,8 +401,9 @@ NodePath::NodePath(const String &p_path) { data->subpath = subpath; data->hash_cache_valid = false; - if (slices == 0) + if (slices == 0) { return; + } data->path.resize(slices); last_is_slash = true; int from = (int)absolute; diff --git a/core/node_path.h b/core/node_path.h index 8f89b9fadf..7c06bf01ce 100644 --- a/core/node_path.h +++ b/core/node_path.h @@ -69,8 +69,9 @@ public: NodePath get_parent() const; _FORCE_INLINE_ uint32_t hash() const { - if (!data) + if (!data) { return 0; + } if (!data->hash_cache_valid) { _update_hash_cache(); } diff --git a/core/object.cpp b/core/object.cpp index 64b519f1b9..0a4e8a5890 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -75,24 +75,29 @@ PropertyInfo::operator Dictionary() const { PropertyInfo PropertyInfo::from_dict(const Dictionary &p_dict) { PropertyInfo pi; - if (p_dict.has("type")) + if (p_dict.has("type")) { pi.type = Variant::Type(int(p_dict["type"])); + } - if (p_dict.has("name")) + if (p_dict.has("name")) { pi.name = p_dict["name"]; + } - if (p_dict.has("class_name")) + if (p_dict.has("class_name")) { pi.class_name = p_dict["class_name"]; + } - if (p_dict.has("hint")) + if (p_dict.has("hint")) { pi.hint = PropertyHint(int(p_dict["hint"])); + } - if (p_dict.has("hint_string")) - + if (p_dict.has("hint_string")) { pi.hint_string = p_dict["hint_string"]; + } - if (p_dict.has("usage")) + if (p_dict.has("usage")) { pi.usage = p_dict["usage"]; + } return pi; } @@ -111,8 +116,9 @@ MethodInfo::operator Dictionary() const { d["name"] = name; d["args"] = convert_property_list(&arguments); Array da; - for (int i = 0; i < default_arguments.size(); i++) + for (int i = 0; i < default_arguments.size(); i++) { da.push_back(default_arguments[i]); + } d["default_args"] = da; d["flags"] = flags; d["id"] = id; @@ -124,8 +130,9 @@ MethodInfo::operator Dictionary() const { MethodInfo MethodInfo::from_dict(const Dictionary &p_dict) { MethodInfo mi; - if (p_dict.has("name")) + if (p_dict.has("name")) { mi.name = p_dict["name"]; + } Array args; if (p_dict.has("args")) { args = p_dict["args"]; @@ -147,8 +154,9 @@ MethodInfo MethodInfo::from_dict(const Dictionary &p_dict) { mi.return_val = PropertyInfo::from_dict(p_dict["return"]); } - if (p_dict.has("flags")) + if (p_dict.has("flags")) { mi.flags = p_dict["flags"]; + } return mi; } @@ -327,14 +335,18 @@ bool Object::Connection::operator<(const Connection &p_conn) const { Object::Connection::Connection(const Variant &p_variant) { Dictionary d = p_variant; - if (d.has("signal")) + if (d.has("signal")) { signal = d["signal"]; - if (d.has("callable")) + } + if (d.has("callable")) { callable = d["callable"]; - if (d.has("flags")) + } + if (d.has("flags")) { flags = d["flags"]; - if (d.has("binds")) + } + if (d.has("binds")) { binds = d["binds"]; + } } bool Object::_predelete() { @@ -366,8 +378,9 @@ void Object::set(const StringName &p_name, const Variant &p_value, bool *r_valid if (script_instance) { if (script_instance->set(p_name, p_value)) { - if (r_valid) + if (r_valid) { *r_valid = true; + } return; } } @@ -385,23 +398,26 @@ void Object::set(const StringName &p_name, const Variant &p_value, bool *r_valid if (p_name == CoreStringNames::get_singleton()->_script) { set_script(p_value); - if (r_valid) + if (r_valid) { *r_valid = true; + } return; } else if (p_name == CoreStringNames::get_singleton()->_meta) { //set_meta(p_name,p_value); metadata = p_value.duplicate(); - if (r_valid) + if (r_valid) { *r_valid = true; + } return; } //something inside the object... :| bool success = _setv(p_name, p_value); if (success) { - if (r_valid) + if (r_valid) { *r_valid = true; + } return; } @@ -409,8 +425,9 @@ void Object::set(const StringName &p_name, const Variant &p_value, bool *r_valid bool valid; setvar(p_name, p_value, &valid); if (valid) { - if (r_valid) + if (r_valid) { *r_valid = true; + } return; } } @@ -420,15 +437,17 @@ void Object::set(const StringName &p_name, const Variant &p_value, bool *r_valid bool valid; script_instance->property_set_fallback(p_name, p_value, &valid); if (valid) { - if (r_valid) + if (r_valid) { *r_valid = true; + } return; } } #endif - if (r_valid) + if (r_valid) { *r_valid = false; + } } Variant Object::get(const StringName &p_name, bool *r_valid) const { @@ -436,8 +455,9 @@ Variant Object::get(const StringName &p_name, bool *r_valid) const { if (script_instance) { if (script_instance->get(p_name, ret)) { - if (r_valid) + if (r_valid) { *r_valid = true; + } return ret; } } @@ -445,30 +465,34 @@ Variant Object::get(const StringName &p_name, bool *r_valid) const { //try built-in setgetter { if (ClassDB::get_property(const_cast<Object *>(this), p_name, ret)) { - if (r_valid) + if (r_valid) { *r_valid = true; + } return ret; } } if (p_name == CoreStringNames::get_singleton()->_script) { ret = get_script(); - if (r_valid) + if (r_valid) { *r_valid = true; + } return ret; } else if (p_name == CoreStringNames::get_singleton()->_meta) { ret = metadata; - if (r_valid) + if (r_valid) { *r_valid = true; + } return ret; } else { //something inside the object... :| bool success = _getv(p_name, ret); if (success) { - if (r_valid) + if (r_valid) { *r_valid = true; + } return ret; } @@ -477,8 +501,9 @@ Variant Object::get(const StringName &p_name, bool *r_valid) const { bool valid; ret = getvar(p_name, &valid); if (valid) { - if (r_valid) + if (r_valid) { *r_valid = true; + } return ret; } } @@ -488,23 +513,26 @@ Variant Object::get(const StringName &p_name, bool *r_valid) const { bool valid; ret = script_instance->property_get_fallback(p_name, &valid); if (valid) { - if (r_valid) + if (r_valid) { *r_valid = true; + } return ret; } } #endif - if (r_valid) + if (r_valid) { *r_valid = false; + } return Variant(); } } void Object::set_indexed(const Vector<StringName> &p_names, const Variant &p_value, bool *r_valid) { if (p_names.empty()) { - if (r_valid) + if (r_valid) { *r_valid = false; + } return; } if (p_names.size() == 1) { @@ -513,8 +541,9 @@ void Object::set_indexed(const Vector<StringName> &p_names, const Variant &p_val } bool valid = false; - if (!r_valid) + if (!r_valid) { r_valid = &valid; + } List<Variant> value_stack; @@ -554,8 +583,9 @@ void Object::set_indexed(const Vector<StringName> &p_names, const Variant &p_val Variant Object::get_indexed(const Vector<StringName> &p_names, bool *r_valid) const { if (p_names.empty()) { - if (r_valid) + if (r_valid) { *r_valid = false; + } return Variant(); } bool valid = false; @@ -564,11 +594,13 @@ Variant Object::get_indexed(const Vector<StringName> &p_names, bool *r_valid) co for (int i = 1; i < p_names.size(); i++) { current_value = current_value.get_named(p_names[i], &valid); - if (!valid) + if (!valid) { break; + } } - if (r_valid) + if (r_valid) { *r_valid = valid; + } return current_value; } @@ -741,14 +773,16 @@ bool Object::has_method(const StringName &p_method) const { } Variant Object::getvar(const Variant &p_key, bool *r_valid) const { - if (r_valid) + if (r_valid) { *r_valid = false; + } return Variant(); } void Object::setvar(const Variant &p_key, const Variant &p_value, bool *r_valid) { - if (r_valid) + if (r_valid) { *r_valid = false; + } } Variant Object::callv(const StringName &p_method, const Array &p_args) { @@ -774,8 +808,9 @@ Variant Object::call(const StringName &p_name, VARIANT_ARG_DECLARE) { int argc = 0; for (int i = 0; i < VARIANT_ARG_MAX; i++) { - if (argptr[i]->get_type() == Variant::NIL) + if (argptr[i]->get_type() == Variant::NIL) { break; + } argc++; } @@ -790,8 +825,9 @@ void Object::call_multilevel(const StringName &p_name, VARIANT_ARG_DECLARE) { int argc = 0; for (int i = 0; i < VARIANT_ARG_MAX; i++) { - if (argptr[i]->get_type() == Variant::NIL) + if (argptr[i]->get_type() == Variant::NIL) { break; + } argc++; } @@ -871,8 +907,9 @@ String Object::to_string() { if (script_instance) { bool valid; String ret = script_instance->to_string(&valid); - if (valid) + if (valid) { return ret; + } } return "[" + get_class() + ":" + itos(get_instance_id()) + "]"; } @@ -907,8 +944,9 @@ void Object::set_script_and_instance(const Variant &p_script, ScriptInstance *p_ } void Object::set_script(const Variant &p_script) { - if (script == p_script) + if (script == p_script) { return; + } if (script_instance) { memdelete(script_instance); @@ -933,18 +971,21 @@ void Object::set_script(const Variant &p_script) { } void Object::set_script_instance(ScriptInstance *p_instance) { - if (script_instance == p_instance) + if (script_instance == p_instance) { return; + } - if (script_instance) + if (script_instance) { memdelete(script_instance); + } script_instance = p_instance; - if (p_instance) + if (p_instance) { script = p_instance->get_script(); - else + } else { script = Variant(); + } } Variant Object::get_script() const { @@ -1023,8 +1064,9 @@ void Object::add_user_signal(const MethodInfo &p_signal) { } bool Object::_has_user_signal(const StringName &p_name) const { - if (!signal_map.has(p_name)) + if (!signal_map.has(p_name)) { return false; + } return signal_map[p_name].user.name.length() > 0; } @@ -1061,8 +1103,9 @@ Variant Object::_emit_signal(const Variant **p_args, int p_argcount, Callable::C } Error Object::emit_signal(const StringName &p_name, const Variant **p_args, int p_argcount) { - if (_block_signals) + if (_block_signals) { return ERR_CANT_ACQUIRE_RESOURCE; //no emit, signals blocked + } SignalData *s = signal_map.getptr(p_name); if (!s) { @@ -1128,8 +1171,9 @@ Error Object::emit_signal(const StringName &p_name, const Variant **p_args, int if (ce.error != Callable::CallError::CALL_OK) { #ifdef DEBUG_ENABLED - if (c.flags & CONNECT_PERSIST && Engine::get_singleton()->is_editor_hint() && (script.is_null() || !Ref<Script>(script)->is_tool())) + if (c.flags & CONNECT_PERSIST && Engine::get_singleton()->is_editor_hint() && (script.is_null() || !Ref<Script>(script)->is_tool())) { continue; + } #endif if (ce.error == Callable::CallError::CALL_ERROR_INVALID_METHOD && !ClassDB::class_exists(target->get_class_name())) { //most likely object is not initialized yet, do not throw error. @@ -1171,8 +1215,9 @@ Error Object::emit_signal(const StringName &p_name, VARIANT_ARG_DECLARE) { int argc = 0; for (int i = 0; i < VARIANT_ARG_MAX; i++) { - if (argptr[i]->get_type() == Variant::NIL) + if (argptr[i]->get_type() == Variant::NIL) { break; + } argc++; } @@ -1191,10 +1236,12 @@ void Object::_add_user_signal(const String &p_name, const Array &p_args) { Dictionary d = p_args[i]; PropertyInfo param; - if (d.has("name")) + if (d.has("name")) { param.name = d["name"]; - if (d.has("type")) + } + if (d.has("type")) { param.type = (Variant::Type)(int)d["type"]; + } mi.arguments.push_back(param); } @@ -1293,11 +1340,13 @@ void Object::get_all_signal_connections(List<Connection> *p_connections) const { void Object::get_signal_connection_list(const StringName &p_signal, List<Connection> *p_connections) const { const SignalData *s = signal_map.getptr(p_signal); - if (!s) + if (!s) { return; //nothing + } - for (int i = 0; i < s->slot_map.size(); i++) + for (int i = 0; i < s->slot_map.size(); i++) { p_connections->push_back(s->slot_map.getv(i).conn); + } } int Object::get_persistent_signal_connection_count() const { @@ -1395,11 +1444,13 @@ bool Object::is_connected(const StringName &p_signal, const Callable &p_callable const SignalData *s = signal_map.getptr(p_signal); if (!s) { bool signal_is_valid = ClassDB::has_signal(get_class_name(), p_signal); - if (signal_is_valid) + if (signal_is_valid) { return false; + } - if (!script.is_null() && Ref<Script>(script)->has_script_signal(p_signal)) + if (!script.is_null() && Ref<Script>(script)->has_script_signal(p_signal)) { return false; + } ERR_FAIL_V_MSG(false, "Nonexistent signal: " + p_signal + "."); } @@ -1466,16 +1517,18 @@ Variant Object::_get_indexed_bind(const NodePath &p_name) const { void Object::initialize_class() { static bool initialized = false; - if (initialized) + if (initialized) { return; + } ClassDB::_add_class<Object>(); _bind_methods(); initialized = true; } StringName Object::tr(const StringName &p_message) const { - if (!_can_translate || !TranslationServer::get_singleton()) + if (!_can_translate || !TranslationServer::get_singleton()) { return p_message; + } return TranslationServer::get_singleton()->translate(p_message); } @@ -1484,15 +1537,18 @@ void Object::_clear_internal_resource_paths(const Variant &p_var) { switch (p_var.get_type()) { case Variant::OBJECT: { RES r = p_var; - if (!r.is_valid()) + if (!r.is_valid()) { return; + } - if (!r->get_path().begins_with("res://") || r->get_path().find("::") == -1) + if (!r->get_path().begins_with("res://") || r->get_path().find("::") == -1) { return; //not an internal resource + } Object *object = p_var; - if (!object) + if (!object) { return; + } r->set_path(""); r->clear_internal_resource_paths(); @@ -1522,10 +1578,11 @@ void Object::_clear_internal_resource_paths(const Variant &p_var) { #ifdef TOOLS_ENABLED void Object::editor_set_section_unfold(const String &p_section, bool p_unfolded) { set_edited(true); - if (p_unfolded) + if (p_unfolded) { editor_section_folding.insert(p_section); - else + } else { editor_section_folding.erase(p_section); + } } bool Object::editor_is_section_unfolded(const String &p_section) { @@ -1669,13 +1726,15 @@ void Object::get_translatable_strings(List<String> *p_strings) const { get_property_list(&plist); for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_INTERNATIONALIZED)) + if (!(E->get().usage & PROPERTY_USAGE_INTERNATIONALIZED)) { continue; + } String text = get(E->get().name); - if (text == "") + if (text == "") { continue; + } p_strings->push_back(text); } @@ -1685,24 +1744,27 @@ Variant::Type Object::get_static_property_type(const StringName &p_property, boo bool valid; Variant::Type t = ClassDB::get_property_type(get_class_name(), p_property, &valid); if (valid) { - if (r_valid) + if (r_valid) { *r_valid = true; + } return t; } if (get_script_instance()) { return get_script_instance()->get_property_type(p_property, r_valid); } - if (r_valid) + if (r_valid) { *r_valid = false; + } return Variant::NIL; } Variant::Type Object::get_static_property_type_indexed(const Vector<StringName> &p_path, bool *r_valid) const { if (p_path.size() == 0) { - if (r_valid) + if (r_valid) { *r_valid = false; + } return Variant::NIL; } @@ -1710,8 +1772,9 @@ Variant::Type Object::get_static_property_type_indexed(const Vector<StringName> bool valid = false; Variant::Type t = get_static_property_type(p_path[0], &valid); if (!valid) { - if (r_valid) + if (r_valid) { *r_valid = false; + } return Variant::NIL; } @@ -1722,22 +1785,25 @@ Variant::Type Object::get_static_property_type_indexed(const Vector<StringName> for (int i = 1; i < p_path.size(); i++) { if (check.get_type() == Variant::OBJECT || check.get_type() == Variant::DICTIONARY || check.get_type() == Variant::ARRAY) { // We cannot be sure about the type of properties this types can have - if (r_valid) + if (r_valid) { *r_valid = false; + } return Variant::NIL; } check = check.get_named(p_path[i], &valid); if (!valid) { - if (r_valid) + if (r_valid) { *r_valid = false; + } return Variant::NIL; } } - if (r_valid) + if (r_valid) { *r_valid = true; + } return check.get_type(); } @@ -1812,8 +1878,9 @@ Object::Object() { } Object::~Object() { - if (script_instance) + if (script_instance) { memdelete(script_instance); + } script_instance = nullptr; const StringName *S = nullptr; @@ -1978,10 +2045,12 @@ void ObjectDB::cleanup() { Object *obj = object_slots[slot].object; String node_name; - if (obj->is_class("Node")) + if (obj->is_class("Node")) { node_name = " - Node name: " + String(obj->call("get_name")); - if (obj->is_class("Resource")) + } + if (obj->is_class("Resource")) { node_name = " - Resource name: " + String(obj->call("get_name")) + " Path: " + String(obj->call("get_path")); + } uint64_t id = uint64_t(slot) | (uint64_t(object_slots[slot].validator) << OBJECTDB_VALIDATOR_BITS) | (object_slots[slot].is_reference ? OBJECTDB_REFERENCE_BIT : 0); print_line("Leaked instance: " + String(obj->get_class()) + ":" + itos(id) + node_name); diff --git a/core/object.h b/core/object.h index 84db756323..95662f6208 100644 --- a/core/object.h +++ b/core/object.h @@ -260,8 +260,9 @@ public: return String(#m_class); \ } \ virtual const StringName *_get_class_namev() const { \ - if (!_class_name) \ + if (!_class_name) { \ _class_name = get_class_static(); \ + } \ return &_class_name; \ } \ static _FORCE_INLINE_ void *get_class_ptr_static() { \ @@ -281,8 +282,9 @@ public: static String get_category_static() { \ String category = m_inherits::get_category_static(); \ if (_get_category != m_inherits::_get_category) { \ - if (category != "") \ + if (category != "") { \ category += "/"; \ + } \ category += _get_category(); \ } \ return category; \ @@ -309,12 +311,14 @@ protected: public: \ static void initialize_class() { \ static bool initialized = false; \ - if (initialized) \ + if (initialized) { \ return; \ + } \ m_inherits::initialize_class(); \ ClassDB::_add_class<m_class>(); \ - if (m_class::_get_bind_methods() != m_inherits::_get_bind_methods()) \ + if (m_class::_get_bind_methods() != m_inherits::_get_bind_methods()) { \ _bind_methods(); \ + } \ initialized = true; \ } \ \ @@ -327,8 +331,9 @@ protected: } \ virtual bool _getv(const StringName &p_name, Variant &r_ret) const { \ if (m_class::_get_get() != m_inherits::_get_get()) { \ - if (_get(p_name, r_ret)) \ + if (_get(p_name, r_ret)) { \ return true; \ + } \ } \ return m_inherits::_getv(p_name, r_ret); \ } \ @@ -336,8 +341,9 @@ protected: return (bool (Object::*)(const StringName &, const Variant &)) & m_class::_set; \ } \ virtual bool _setv(const StringName &p_name, const Variant &p_property) { \ - if (m_inherits::_setv(p_name, p_property)) \ + if (m_inherits::_setv(p_name, p_property)) { \ return true; \ + } \ if (m_class::_get_set() != m_inherits::_get_set()) { \ return _set(p_name, p_property); \ } \ @@ -351,13 +357,15 @@ protected: m_inherits::_get_property_listv(p_list, p_reversed); \ } \ p_list->push_back(PropertyInfo(Variant::NIL, get_class_static(), PROPERTY_HINT_NONE, String(), PROPERTY_USAGE_CATEGORY)); \ - if (!_is_gpl_reversed()) \ + if (!_is_gpl_reversed()) { \ ClassDB::get_property_list(#m_class, p_list, true, this); \ + } \ if (m_class::_get_get_property_list() != m_inherits::_get_get_property_list()) { \ _get_property_list(p_list); \ } \ - if (_is_gpl_reversed()) \ + if (_is_gpl_reversed()) { \ ClassDB::get_property_list(#m_class, p_list, true, this); \ + } \ if (p_reversed) { \ m_inherits::_get_property_listv(p_list, p_reversed); \ } \ @@ -366,13 +374,15 @@ protected: return (void (Object::*)(int)) & m_class::_notification; \ } \ virtual void _notificationv(int p_notification, bool p_reversed) { \ - if (!p_reversed) \ + if (!p_reversed) { \ m_inherits::_notificationv(p_notification, p_reversed); \ + } \ if (m_class::_get_notification() != m_inherits::_get_notification()) { \ _notification(p_notification); \ } \ - if (p_reversed) \ + if (p_reversed) { \ m_inherits::_notificationv(p_notification, p_reversed); \ + } \ } \ \ private: @@ -526,8 +536,9 @@ protected: Variant _call_deferred_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error); virtual const StringName *_get_class_namev() const { - if (!_class_name) + if (!_class_name) { _class_name = get_class_static(); + } return &_class_name; } @@ -550,8 +561,9 @@ public: #ifdef TOOLS_ENABLED _FORCE_INLINE_ void _change_notify(const char *p_property = "") { _edited = true; - for (Set<Object *>::Element *E = change_receptors.front(); E; E = E->next()) + for (Set<Object *>::Element *E = change_receptors.front(); E; E = E->next()) { ((Object *)(E->get()))->_changed_callback(this, p_property); + } } #else _FORCE_INLINE_ void _change_notify(const char *p_what = "") {} @@ -574,12 +586,14 @@ public: #ifndef NO_SAFE_CAST return dynamic_cast<T *>(p_object); #else - if (!p_object) + if (!p_object) { return nullptr; - if (p_object->is_class_ptr(T::get_class_ptr_static())) + } + if (p_object->is_class_ptr(T::get_class_ptr_static())) { return static_cast<T *>(p_object); - else + } else { return nullptr; + } #endif } @@ -588,12 +602,14 @@ public: #ifndef NO_SAFE_CAST return dynamic_cast<const T *>(p_object); #else - if (!p_object) + if (!p_object) { return nullptr; - if (p_object->is_class_ptr(T::get_class_ptr_static())) + } + if (p_object->is_class_ptr(T::get_class_ptr_static())) { return static_cast<const T *>(p_object); - else + } else { return nullptr; + } #endif } diff --git a/core/os/dir_access.cpp b/core/os/dir_access.cpp index 5763c74862..9f2672e038 100644 --- a/core/os/dir_access.cpp +++ b/core/os/dir_access.cpp @@ -61,8 +61,9 @@ int DirAccess::get_current_drive() { String path = get_current_dir().to_lower(); for (int i = 0; i < get_drive_count(); i++) { String d = get_drive(i).to_lower(); - if (path.begins_with(d)) + if (path.begins_with(d)) { return i; + } } return 0; @@ -80,10 +81,11 @@ static Error _erase_recursive(DirAccess *da) { String n = da->get_next(); while (n != String()) { if (n != "." && n != "..") { - if (da->current_is_dir()) + if (da->current_is_dir()) { dirs.push_back(n); - else + } else { files.push_back(n); + } } n = da->get_next(); @@ -147,13 +149,13 @@ Error DirAccess::make_dir_recursive(String p_dir) { String base; - if (full_dir.begins_with("res://")) + if (full_dir.begins_with("res://")) { base = "res://"; - else if (full_dir.begins_with("user://")) + } else if (full_dir.begins_with("user://")) { base = "user://"; - else if (full_dir.begins_with("/")) + } else if (full_dir.begins_with("/")) { base = "/"; - else if (full_dir.find(":/") != -1) { + } else if (full_dir.find(":/") != -1) { base = full_dir.substr(0, full_dir.find(":/") + 2); } else { ERR_FAIL_V(ERR_INVALID_PARAMETER); @@ -229,8 +231,9 @@ DirAccess *DirAccess::open(const String &p_path, Error *r_error) { ERR_FAIL_COND_V_MSG(!da, nullptr, "Cannot create DirAccess for path '" + p_path + "'."); Error err = da->change_dir(p_path); - if (r_error) + if (r_error) { *r_error = err; + } if (err != OK) { memdelete(da); return nullptr; @@ -250,8 +253,9 @@ DirAccess *DirAccess::create(AccessType p_access) { String DirAccess::get_full_path(const String &p_path, AccessType p_access) { DirAccess *d = DirAccess::create(p_access); - if (!d) + if (!d) { return p_path; + } d->change_dir(p_path); String full = d->get_current_dir(); @@ -298,8 +302,9 @@ Error DirAccess::copy(String p_from, String p_to, int p_chmod_flags) { fdst->close(); err = FileAccess::set_unix_permissions(p_to, p_chmod_flags); // If running on a platform with no chmod support (i.e., Windows), don't fail - if (err == ERR_UNAVAILABLE) + if (err == ERR_UNAVAILABLE) { err = OK; + } } memdelete(fsrc); @@ -334,9 +339,9 @@ Error DirAccess::_copy_dir(DirAccess *p_target_da, String p_to, int p_chmod_flag String n = get_next(); while (n != String()) { if (n != "." && n != "..") { - if (current_is_dir()) + if (current_is_dir()) { dirs.push_back(n); - else { + } else { const String &rel_path = n; if (!n.is_rel_path()) { list_dir_end(); diff --git a/core/os/dir_access.h b/core/os/dir_access.h index 06b3abca8c..6bce9a4c12 100644 --- a/core/os/dir_access.h +++ b/core/os/dir_access.h @@ -133,8 +133,9 @@ struct DirAccessRef { DirAccessRef(DirAccess *fa) { f = fa; } ~DirAccessRef() { - if (f) + if (f) { memdelete(f); + } } }; diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp index 8b13e53812..f9ba8ff2d2 100644 --- a/core/os/file_access.cpp +++ b/core/os/file_access.cpp @@ -51,12 +51,14 @@ FileAccess *FileAccess::create(AccessType p_access) { } bool FileAccess::exists(const String &p_name) { - if (PackedData::get_singleton() && PackedData::get_singleton()->has_path(p_name)) + if (PackedData::get_singleton() && PackedData::get_singleton()->has_path(p_name)) { return true; + } FileAccess *f = open(p_name, READ); - if (!f) + if (!f) { return false; + } memdelete(f); return true; } @@ -90,8 +92,9 @@ FileAccess *FileAccess::open(const String &p_path, int p_mode_flags, Error *r_er if (!(p_mode_flags & WRITE) && PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled()) { ret = PackedData::get_singleton()->try_open_path(p_path); if (ret) { - if (r_error) + if (r_error) { *r_error = OK; + } return ret; } } @@ -99,8 +102,9 @@ FileAccess *FileAccess::open(const String &p_path, int p_mode_flags, Error *r_er ret = create_for_path(p_path); Error err = ret->_open(p_path, p_mode_flags); - if (r_error) + if (r_error) { *r_error = err; + } if (err != OK) { memdelete(ret); ret = nullptr; @@ -214,10 +218,11 @@ float FileAccess::get_float() const { }; real_t FileAccess::get_real() const { - if (real_is_double) + if (real_is_double) { return get_double(); - else + } else { return get_float(); + } } double FileAccess::get_double() const { @@ -233,8 +238,9 @@ String FileAccess::get_token() const { while (!eof_reached()) { if (c <= ' ') { - if (token.length()) + if (token.length()) { break; + } } else { token += c; } @@ -299,8 +305,9 @@ String FileAccess::get_line() const { if (c == '\n' || c == '\0') { line.push_back(0); return String::utf8(line.get_data()); - } else if (c != '\r') + } else if (c != '\r') { line.push_back(c); + } c = get_8(); } @@ -314,14 +321,16 @@ Vector<String> FileAccess::get_csv_line(const String &p_delim) const { String l; int qc = 0; do { - if (eof_reached()) + if (eof_reached()) { break; + } l += get_line() + "\n"; qc = 0; for (int i = 0; i < l.length(); i++) { - if (l[i] == '"') + if (l[i] == '"') { qc++; + } } } while (qc % 2); @@ -360,8 +369,9 @@ Vector<String> FileAccess::get_csv_line(const String &p_delim) const { int FileAccess::get_buffer(uint8_t *p_dst, int p_length) const { int i = 0; - for (i = 0; i < p_length && !eof_reached(); i++) + for (i = 0; i < p_length && !eof_reached(); i++) { p_dst[i] = get_8(); + } return i; } @@ -426,10 +436,11 @@ void FileAccess::store_64(uint64_t p_dest) { } void FileAccess::store_real(real_t p_real) { - if (sizeof(real_t) == 4) + if (sizeof(real_t) == 4) { store_float(p_real); - else + } else { store_double(p_real); + } } void FileAccess::store_float(float p_dest) { @@ -445,8 +456,9 @@ void FileAccess::store_double(double p_dest) { }; uint64_t FileAccess::get_modified_time(const String &p_file) { - if (PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled() && PackedData::get_singleton()->has_path(p_file)) + if (PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled() && PackedData::get_singleton()->has_path(p_file)) { return 0; + } FileAccess *fa = create_for_path(p_file); ERR_FAIL_COND_V_MSG(!fa, 0, "Cannot create FileAccess for path '" + p_file + "'."); @@ -457,8 +469,9 @@ uint64_t FileAccess::get_modified_time(const String &p_file) { } uint32_t FileAccess::get_unix_permissions(const String &p_file) { - if (PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled() && PackedData::get_singleton()->has_path(p_file)) + if (PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled() && PackedData::get_singleton()->has_path(p_file)) { return 0; + } FileAccess *fa = create_for_path(p_file); ERR_FAIL_COND_V_MSG(!fa, 0, "Cannot create FileAccess for path '" + p_file + "'."); @@ -478,8 +491,9 @@ Error FileAccess::set_unix_permissions(const String &p_file, uint32_t p_permissi } void FileAccess::store_string(const String &p_string) { - if (p_string.length() == 0) + if (p_string.length() == 0) { return; + } CharString cs = p_string.utf8(); store_buffer((uint8_t *)&cs[0], cs.length()); @@ -531,8 +545,9 @@ void FileAccess::store_csv_line(const Vector<String> &p_values, const String &p_ } void FileAccess::store_buffer(const uint8_t *p_src, int p_length) { - for (int i = 0; i < p_length; i++) + for (int i = 0; i < p_length; i++) { store_8(p_src[i]); + } } Vector<uint8_t> FileAccess::get_file_as_array(const String &p_path, Error *r_error) { @@ -570,8 +585,9 @@ String FileAccess::get_file_as_string(const String &p_path, Error *r_error) { String FileAccess::get_md5(const String &p_file) { FileAccess *f = FileAccess::open(p_file, READ); - if (!f) + if (!f) { return String(); + } CryptoCore::MD5Context ctx; ctx.start(); @@ -583,8 +599,9 @@ String FileAccess::get_md5(const String &p_file) { if (br > 0) { ctx.update(step, br); } - if (br < 4096) + if (br < 4096) { break; + } } unsigned char hash[16]; @@ -610,8 +627,9 @@ String FileAccess::get_multiple_md5(const Vector<String> &p_file) { if (br > 0) { ctx.update(step, br); } - if (br < 4096) + if (br < 4096) { break; + } } memdelete(f); } @@ -624,8 +642,9 @@ String FileAccess::get_multiple_md5(const Vector<String> &p_file) { String FileAccess::get_sha256(const String &p_file) { FileAccess *f = FileAccess::open(p_file, READ); - if (!f) + if (!f) { return String(); + } CryptoCore::SHA256Context ctx; ctx.start(); @@ -637,8 +656,9 @@ String FileAccess::get_sha256(const String &p_file) { if (br > 0) { ctx.update(step, br); } - if (br < 4096) + if (br < 4096) { break; + } } unsigned char hash[32]; diff --git a/core/os/file_access.h b/core/os/file_access.h index a956ae12f4..48b9ee4269 100644 --- a/core/os/file_access.h +++ b/core/os/file_access.h @@ -190,8 +190,9 @@ struct FileAccessRef { FileAccessRef(FileAccess *fa) { f = fa; } ~FileAccessRef() { - if (f) + if (f) { memdelete(f); + } } }; diff --git a/core/os/main_loop.cpp b/core/os/main_loop.cpp index 1ce49b544b..dc68c2a9f9 100644 --- a/core/os/main_loop.cpp +++ b/core/os/main_loop.cpp @@ -59,23 +59,27 @@ void MainLoop::set_init_script(const Ref<Script> &p_init_script) { } void MainLoop::init() { - if (init_script.is_valid()) + if (init_script.is_valid()) { set_script(init_script); + } - if (get_script_instance()) + if (get_script_instance()) { get_script_instance()->call("_initialize"); + } } bool MainLoop::iteration(float p_time) { - if (get_script_instance()) + if (get_script_instance()) { return get_script_instance()->call("_iteration", p_time); + } return false; } bool MainLoop::idle(float p_time) { - if (get_script_instance()) + if (get_script_instance()) { return get_script_instance()->call("_idle", p_time); + } return false; } diff --git a/core/os/memory.h b/core/os/memory.h index 42723152e4..46ffb4124b 100644 --- a/core/os/memory.h +++ b/core/os/memory.h @@ -108,36 +108,42 @@ _ALWAYS_INLINE_ bool predelete_handler(void *) { template <class T> void memdelete(T *p_class) { - if (!predelete_handler(p_class)) + if (!predelete_handler(p_class)) { return; // doesn't want to be deleted - if (!__has_trivial_destructor(T)) + } + if (!__has_trivial_destructor(T)) { p_class->~T(); + } Memory::free_static(p_class, false); } template <class T, class A> void memdelete_allocator(T *p_class) { - if (!predelete_handler(p_class)) + if (!predelete_handler(p_class)) { return; // doesn't want to be deleted - if (!__has_trivial_destructor(T)) + } + if (!__has_trivial_destructor(T)) { p_class->~T(); + } A::free(p_class); } #define memdelete_notnull(m_v) \ { \ - if (m_v) \ + if (m_v) { \ memdelete(m_v); \ + } \ } #define memnew_arr(m_class, m_count) memnew_arr_template<m_class>(m_count) template <typename T> T *memnew_arr_template(size_t p_elements, const char *p_descr = "") { - if (p_elements == 0) + if (p_elements == 0) { return nullptr; + } /** overloading operator new[] cannot be done , because it may not return the real allocated address (it may pad the 'element count' before the actual array). Because of that, it must be done by hand. This is the same strategy used by std::vector, and the Vector class, so it should be safe.*/ diff --git a/core/os/os.cpp b/core/os/os.cpp index 4414b582bd..da9dabd401 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -178,14 +178,16 @@ static FileAccess *_OSPRF = nullptr; static void _OS_printres(Object *p_obj) { Resource *res = Object::cast_to<Resource>(p_obj); - if (!res) + if (!res) { return; + } String str = itos(res->get_instance_id()) + String(res->get_class()) + ":" + String(res->get_name()) + " - " + res->get_path(); - if (_OSPRF) + if (_OSPRF) { _OSPRF->store_line(str); - else + } else { print_line(str); + } } void OS::print_all_resources(String p_to_file) { @@ -202,8 +204,9 @@ void OS::print_all_resources(String p_to_file) { ObjectDB::debug_objects(_OS_printres); if (p_to_file != "") { - if (_OSPRF) + if (_OSPRF) { memdelete(_OSPRF); + } _OSPRF = nullptr; } } @@ -366,18 +369,21 @@ void OS::set_has_server_feature_callback(HasServerFeatureCallback p_callback) { } bool OS::has_feature(const String &p_feature) { - if (p_feature == get_name()) + if (p_feature == get_name()) { return true; + } #ifdef DEBUG_ENABLED - if (p_feature == "debug") + if (p_feature == "debug") { return true; + } #else if (p_feature == "release") return true; #endif #ifdef TOOLS_ENABLED - if (p_feature == "editor") + if (p_feature == "editor") { return true; + } #else if (p_feature == "standalone") return true; @@ -417,15 +423,17 @@ bool OS::has_feature(const String &p_feature) { } #endif - if (_check_internal_feature_support(p_feature)) + if (_check_internal_feature_support(p_feature)) { return true; + } if (has_server_feature_callback && has_server_feature_callback(p_feature)) { return true; } - if (ProjectSettings::get_singleton()->has_custom_feature(p_feature)) + if (ProjectSettings::get_singleton()->has_custom_feature(p_feature)) { return true; + } return false; } @@ -444,21 +452,24 @@ List<String> OS::get_restart_on_exit_arguments() const { } PackedStringArray OS::get_connected_midi_inputs() { - if (MIDIDriver::get_singleton()) + if (MIDIDriver::get_singleton()) { return MIDIDriver::get_singleton()->get_connected_inputs(); + } PackedStringArray list; return list; } void OS::open_midi_inputs() { - if (MIDIDriver::get_singleton()) + if (MIDIDriver::get_singleton()) { MIDIDriver::get_singleton()->open(); + } } void OS::close_midi_inputs() { - if (MIDIDriver::get_singleton()) + if (MIDIDriver::get_singleton()) { MIDIDriver::get_singleton()->close(); + } } OS::OS() { diff --git a/core/os/rw_lock.h b/core/os/rw_lock.h index e519cea439..1035072cce 100644 --- a/core/os/rw_lock.h +++ b/core/os/rw_lock.h @@ -57,12 +57,14 @@ class RWLockRead { public: RWLockRead(const RWLock *p_lock) { lock = const_cast<RWLock *>(p_lock); - if (lock) + if (lock) { lock->read_lock(); + } } ~RWLockRead() { - if (lock) + if (lock) { lock->read_unlock(); + } } }; @@ -72,12 +74,14 @@ class RWLockWrite { public: RWLockWrite(RWLock *p_lock) { lock = p_lock; - if (lock) + if (lock) { lock->write_lock(); + } } ~RWLockWrite() { - if (lock) + if (lock) { lock->write_unlock(); + } } }; diff --git a/core/os/semaphore.h b/core/os/semaphore.h index 3d9d1ab984..077e04704b 100644 --- a/core/os/semaphore.h +++ b/core/os/semaphore.h @@ -54,8 +54,9 @@ public: _ALWAYS_INLINE_ void wait() const { std::unique_lock<decltype(mutex_)> lock(mutex_); - while (!count_) // Handle spurious wake-ups. + while (!count_) { // Handle spurious wake-ups. condition_.wait(lock); + } --count_; } diff --git a/core/os/thread.cpp b/core/os/thread.cpp index 399efb19a4..70f960ed2a 100644 --- a/core/os/thread.cpp +++ b/core/os/thread.cpp @@ -38,8 +38,9 @@ Error (*Thread::set_name_func)(const String &) = nullptr; Thread::ID Thread::_main_thread_id = 0; Thread::ID Thread::get_caller_id() { - if (get_thread_id_func) + if (get_thread_id_func) { return get_thread_id_func(); + } return 0; } @@ -51,13 +52,15 @@ Thread *Thread::create(ThreadCreateCallback p_callback, void *p_user, const Sett } void Thread::wait_to_finish(Thread *p_thread) { - if (wait_to_finish_func) + if (wait_to_finish_func) { wait_to_finish_func(p_thread); + } } Error Thread::set_name(const String &p_name) { - if (set_name_func) + if (set_name_func) { return set_name_func(p_name); + } return ERR_UNAVAILABLE; }; diff --git a/core/os/threaded_array_processor.h b/core/os/threaded_array_processor.h index 0a435961e1..d27399e4cc 100644 --- a/core/os/threaded_array_processor.h +++ b/core/os/threaded_array_processor.h @@ -57,8 +57,9 @@ void process_array_thread(void *ud) { T &data = *(T *)ud; while (true) { uint32_t index = atomic_increment(&data.index); - if (index >= data.elements) + if (index >= data.elements) { break; + } data.process(index); } } diff --git a/core/packed_data_container.cpp b/core/packed_data_container.cpp index cbaf7e883b..b5aefd6f2c 100644 --- a/core/packed_data_container.cpp +++ b/core/packed_data_container.cpp @@ -36,8 +36,9 @@ Variant PackedDataContainer::getvar(const Variant &p_key, bool *r_valid) const { bool err = false; Variant ret = _key_at_ofs(0, p_key, err); - if (r_valid) + if (r_valid) { *r_valid = !err; + } return ret; } @@ -48,9 +49,9 @@ int PackedDataContainer::size() const { Variant PackedDataContainer::_iter_init_ofs(const Array &p_iter, uint32_t p_offset) { Array ref = p_iter; uint32_t size = _size(p_offset); - if (size == 0 || ref.size() != 1) + if (size == 0 || ref.size() != 1) { return false; - else { + } else { ref[0] = 0; return true; } @@ -59,11 +60,13 @@ Variant PackedDataContainer::_iter_init_ofs(const Array &p_iter, uint32_t p_offs Variant PackedDataContainer::_iter_next_ofs(const Array &p_iter, uint32_t p_offset) { Array ref = p_iter; int size = _size(p_offset); - if (ref.size() != 1) + if (ref.size() != 1) { return false; + } int pos = ref[0]; - if (pos < 0 || pos >= size) + if (pos < 0 || pos >= size) { return false; + } pos += 1; ref[0] = pos; return pos != size; @@ -72,8 +75,9 @@ Variant PackedDataContainer::_iter_next_ofs(const Array &p_iter, uint32_t p_offs Variant PackedDataContainer::_iter_get_ofs(const Variant &p_iter, uint32_t p_offset) { int size = _size(p_offset); int pos = p_iter; - if (pos < 0 || pos >= size) + if (pos < 0 || pos >= size) { return Variant(); + } const uint8_t *rd = data.ptr(); const uint8_t *r = &rd[p_offset]; @@ -170,16 +174,18 @@ Variant PackedDataContainer::_key_at_ofs(uint32_t p_ofs, const Variant &p_key, b uint32_t khash = decode_uint32(r + 8 + i * 12 + 0); if (khash == hash) { Variant key = _get_at_ofs(decode_uint32(r + 8 + i * 12 + 4), rd, err); - if (err) + if (err) { return Variant(); + } if (key == p_key) { //key matches, return value return _get_at_ofs(decode_uint32(r + 8 + i * 12 + 8), rd, err); } found = true; } else { - if (found) + if (found) { break; + } } } @@ -375,8 +381,9 @@ void PackedDataContainerRef::_bind_methods() { Variant PackedDataContainerRef::getvar(const Variant &p_key, bool *r_valid) const { bool err = false; Variant ret = from->_key_at_ofs(offset, p_key, err); - if (r_valid) + if (r_valid) { *r_valid = !err; + } return ret; } diff --git a/core/pool_allocator.cpp b/core/pool_allocator.cpp index 63fd1d7bd1..1dd215a787 100644 --- a/core/pool_allocator.cpp +++ b/core/pool_allocator.cpp @@ -53,8 +53,9 @@ void PoolAllocator::mt_unlock() const { } bool PoolAllocator::get_free_entry(EntryArrayPos *p_pos) { - if (entry_count == entry_max) + if (entry_count == entry_max) { return false; + } for (int i = 0; i < entry_max; i++) { if (entry_array[i].len == 0) { @@ -109,8 +110,9 @@ bool PoolAllocator::find_hole(EntryArrayPos *p_pos, int p_for_size) { void PoolAllocator::compact(int p_up_to) { uint32_t prev_entry_end_pos = 0; - if (p_up_to < 0) + if (p_up_to < 0) { p_up_to = entry_count; + } for (int i = 0; i < p_up_to; i++) { Entry &entry = entry_array[entry_indices[i]]; @@ -158,8 +160,9 @@ bool PoolAllocator::find_entry_index(EntryIndicesPos *p_map_pos, Entry *p_entry) } } - if (entry_pos == entry_max) + if (entry_pos == entry_max) { return false; + } *p_map_pos = entry_pos; return true; @@ -168,8 +171,9 @@ bool PoolAllocator::find_entry_index(EntryIndicesPos *p_map_pos, Entry *p_entry) PoolAllocator::ID PoolAllocator::alloc(int p_size) { ERR_FAIL_COND_V(p_size < 1, POOL_ALLOCATOR_INVALID_ID); #ifdef DEBUG_ENABLED - if (p_size > free_mem) + if (p_size > free_mem) { OS::get_singleton()->debug_break(); + } #endif ERR_FAIL_COND_V(p_size > free_mem, POOL_ALLOCATOR_INVALID_ID); @@ -221,8 +225,9 @@ PoolAllocator::ID PoolAllocator::alloc(int p_size) { entry.lock = 0; entry.check = (check_count++) & CHECK_MASK; free_mem -= size_to_alloc; - if (free_mem < free_mem_peak) + if (free_mem < free_mem_peak) { free_mem_peak = free_mem; + } ID retval = (entry_indices[new_entry_indices_pos] << CHECK_BITS) | entry.check; mt_unlock(); @@ -372,8 +377,9 @@ Error PoolAllocator::resize(ID p_mem, int p_new_size) { e->len = p_new_size; free_mem -= alloc_size; mt_unlock(); - if (free_mem < free_mem_peak) + if (free_mem < free_mem_peak) { free_mem_peak = free_mem; + } return OK; } @@ -387,8 +393,9 @@ Error PoolAllocator::resize(ID p_mem, int p_new_size) { e->len = p_new_size; free_mem -= alloc_size; mt_unlock(); - if (free_mem < free_mem_peak) + if (free_mem < free_mem_peak) { free_mem_peak = free_mem; + } return OK; } @@ -397,8 +404,9 @@ Error PoolAllocator::resize(ID p_mem, int p_new_size) { } Error PoolAllocator::lock(ID p_mem) { - if (!needs_locking) + if (!needs_locking) { return OK; + } mt_lock(); Entry *e = get_entry(p_mem); if (!e) { @@ -412,8 +420,9 @@ Error PoolAllocator::lock(ID p_mem) { } bool PoolAllocator::is_locked(ID p_mem) const { - if (!needs_locking) + if (!needs_locking) { return false; + } mt_lock(); const Entry *e = ((PoolAllocator *)(this))->get_entry(p_mem); @@ -493,8 +502,9 @@ void *PoolAllocator::get(ID p_mem) { } void PoolAllocator::unlock(ID p_mem) { - if (!needs_locking) + if (!needs_locking) { return; + } mt_lock(); Entry *e = get_entry(p_mem); if (!e) { @@ -568,16 +578,18 @@ PoolAllocator::PoolAllocator(int p_align, int p_size, bool p_needs_locking, int mem_ptr = Memory::alloc_static(p_size + p_align, true); uint8_t *mem8 = (uint8_t *)mem_ptr; uint64_t ofs = (uint64_t)mem8; - if (ofs % p_align) + if (ofs % p_align) { mem8 += p_align - (ofs % p_align); + } create_pool(mem8, p_size, p_max_entries); needs_locking = p_needs_locking; align = p_align; } PoolAllocator::~PoolAllocator() { - if (mem_ptr) + if (mem_ptr) { memfree(mem_ptr); + } memdelete_arr(entry_array); memdelete_arr(entry_indices); diff --git a/core/pool_allocator.h b/core/pool_allocator.h index cec95c7323..7d77af6266 100644 --- a/core/pool_allocator.h +++ b/core/pool_allocator.h @@ -99,8 +99,9 @@ private: } inline int aligned(int p_size) const { int rem = p_size % align; - if (rem) + if (rem) { p_size += align - rem; + } return p_size; } diff --git a/core/print_string.cpp b/core/print_string.cpp index b7903b6880..54de229471 100644 --- a/core/print_string.cpp +++ b/core/print_string.cpp @@ -53,10 +53,11 @@ void remove_print_handler(PrintHandlerList *p_handler) { while (l) { if (l == p_handler) { - if (prev) + if (prev) { prev->next = l->next; - else + } else { print_handler_list = l->next; + } break; } prev = l; @@ -69,8 +70,9 @@ void remove_print_handler(PrintHandlerList *p_handler) { } void print_line(String p_string) { - if (!_print_line_enabled) + if (!_print_line_enabled) { return; + } OS::get_singleton()->print("%s\n", p_string.utf8().get_data()); @@ -85,8 +87,9 @@ void print_line(String p_string) { } void print_error(String p_string) { - if (!_print_error_enabled) + if (!_print_error_enabled) { return; + } OS::get_singleton()->printerr("%s\n", p_string.utf8().get_data()); diff --git a/core/project_settings.cpp b/core/project_settings.cpp index fee9423a5e..cedc7f731f 100644 --- a/core/project_settings.cpp +++ b/core/project_settings.cpp @@ -54,12 +54,14 @@ String ProjectSettings::get_resource_path() const { }; String ProjectSettings::localize_path(const String &p_path) const { - if (resource_path == "") + if (resource_path == "") { return p_path; //not initialized yet + } if (p_path.begins_with("res://") || p_path.begins_with("user://") || - (p_path.is_abs_path() && !p_path.begins_with(resource_path))) + (p_path.is_abs_path() && !p_path.begins_with(resource_path))) { return p_path.simplify_path(); + } DirAccess *dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); @@ -140,9 +142,9 @@ String ProjectSettings::globalize_path(const String &p_path) const { bool ProjectSettings::_set(const StringName &p_name, const Variant &p_value) { _THREAD_SAFE_METHOD_ - if (p_value.get_type() == Variant::NIL) + if (p_value.get_type() == Variant::NIL) { props.erase(p_name); - else { + } else { if (p_name == CoreStringNames::get_singleton()->_custom_features) { Vector<String> custom_feature_array = String(p_value).split(","); for (int i = 0; i < custom_feature_array.size(); i++) { @@ -172,8 +174,9 @@ bool ProjectSettings::_set(const StringName &p_name, const Variant &p_value) { } if (props.has(p_name)) { - if (!props[p_name].overridden) + if (!props[p_name].overridden) { props[p_name].variant = p_value; + } } else { props[p_name] = VariantContainer(p_value, last_order++); @@ -215,17 +218,19 @@ void ProjectSettings::_get_property_list(List<PropertyInfo> *p_list) const { for (Map<StringName, VariantContainer>::Element *E = props.front(); E; E = E->next()) { const VariantContainer *v = &E->get(); - if (v->hide_from_editor) + if (v->hide_from_editor) { continue; + } _VCSort vc; vc.name = E->key(); vc.order = v->order; vc.type = v->variant.get_type(); - if (vc.name.begins_with("input/") || vc.name.begins_with("import/") || vc.name.begins_with("export/") || vc.name.begins_with("/remap") || vc.name.begins_with("/locale") || vc.name.begins_with("/autoload")) + if (vc.name.begins_with("input/") || vc.name.begins_with("import/") || vc.name.begins_with("export/") || vc.name.begins_with("/remap") || vc.name.begins_with("/locale") || vc.name.begins_with("/autoload")) { vc.flags = PROPERTY_USAGE_STORAGE; - else + } else { vc.flags = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE; + } if (v->restart_if_changed) { vc.flags |= PROPERTY_USAGE_RESTART_IF_CHANGED; @@ -236,27 +241,31 @@ void ProjectSettings::_get_property_list(List<PropertyInfo> *p_list) const { for (Set<_VCSort>::Element *E = vclist.front(); E; E = E->next()) { String prop_info_name = E->get().name; int dot = prop_info_name.find("."); - if (dot != -1) + if (dot != -1) { prop_info_name = prop_info_name.substr(0, dot); + } if (custom_prop_info.has(prop_info_name)) { PropertyInfo pi = custom_prop_info[prop_info_name]; pi.name = E->get().name; pi.usage = E->get().flags; p_list->push_back(pi); - } else + } else { p_list->push_back(PropertyInfo(E->get().type, E->get().name, PROPERTY_HINT_NONE, "", E->get().flags)); + } } } bool ProjectSettings::_load_resource_pack(const String &p_pack, bool p_replace_files) { - if (PackedData::get_singleton()->is_disabled()) + if (PackedData::get_singleton()->is_disabled()) { return false; + } bool ok = PackedData::get_singleton()->add_pack(p_pack, p_replace_files) == OK; - if (!ok) + if (!ok) { return false; + } //if data.pck is found, all directory access will be from here DirAccess::make_default<DirAccessPack>(DirAccess::ACCESS_RESOURCES); @@ -419,8 +428,9 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b if (p_upwards) { // Try to load settings ascending through parent directories d->change_dir(".."); - if (d->get_current_dir() == current_dir) + if (d->get_current_dir() == current_dir) { break; // not doing anything useful + } current_dir = d->get_current_dir(); } else { break; @@ -431,11 +441,13 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b resource_path = resource_path.replace("\\", "/"); // windows path to unix path just in case memdelete(d); - if (!found) + if (!found) { return err; + } - if (resource_path.length() && resource_path[resource_path.length() - 1] == '/') + if (resource_path.length() && resource_path[resource_path.length() - 1] == '/') { resource_path = resource_path.substr(0, resource_path.length() - 1); // chop end + } return OK; } @@ -652,29 +664,33 @@ Error ProjectSettings::_save_settings_binary(const String &p_file, const Map<Str for (Map<String, List<String>>::Element *E = props.front(); E; E = E->next()) { for (List<String>::Element *F = E->get().front(); F; F = F->next()) { String key = F->get(); - if (E->key() != "") + if (E->key() != "") { key = E->key() + "/" + key; + } Variant value; - if (p_custom.has(key)) + if (p_custom.has(key)) { value = p_custom[key]; - else + } else { value = get(key); + } file->store_32(key.length()); file->store_string(key); int len; err = encode_variant(value, nullptr, len, true); - if (err != OK) + if (err != OK) { memdelete(file); + } ERR_FAIL_COND_V_MSG(err != OK, ERR_INVALID_DATA, "Error when trying to encode Variant."); Vector<uint8_t> buff; buff.resize(len); err = encode_variant(value, buff.ptrw(), len, true); - if (err != OK) + if (err != OK) { memdelete(file); + } ERR_FAIL_COND_V_MSG(err != OK, ERR_INVALID_DATA, "Error when trying to encode Variant."); file->store_32(len); file->store_buffer(buff.ptr(), buff.size()); @@ -703,25 +719,30 @@ Error ProjectSettings::_save_settings_text(const String &p_file, const Map<Strin file->store_line(""); file->store_string("config_version=" + itos(CONFIG_VERSION) + "\n"); - if (p_custom_features != String()) + if (p_custom_features != String()) { file->store_string("custom_features=\"" + p_custom_features + "\"\n"); + } file->store_string("\n"); for (Map<String, List<String>>::Element *E = props.front(); E; E = E->next()) { - if (E != props.front()) + if (E != props.front()) { file->store_string("\n"); + } - if (E->key() != "") + if (E->key() != "") { file->store_string("[" + E->key() + "]\n\n"); + } for (List<String>::Element *F = E->get().front(); F; F = F->next()) { String key = F->get(); - if (E->key() != "") + if (E->key() != "") { key = E->key() + "/" + key; + } Variant value; - if (p_custom.has(key)) + if (p_custom.has(key)) { value = p_custom[key]; - else + } else { value = get(key); + } String vstr; VariantWriter::write_to_string(value, vstr); @@ -749,19 +770,22 @@ Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_cust for (Map<StringName, VariantContainer>::Element *G = props.front(); G; G = G->next()) { const VariantContainer *v = &G->get(); - if (v->hide_from_editor) + if (v->hide_from_editor) { continue; + } - if (p_custom.has(G->key())) + if (p_custom.has(G->key())) { continue; + } _VCSort vc; vc.name = G->key(); //*k; vc.order = v->order; vc.type = v->variant.get_type(); vc.flags = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE; - if (v->variant == v->initial) + if (v->variant == v->initial) { continue; + } vclist.insert(vc); } @@ -787,9 +811,9 @@ Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_cust int div = category.find("/"); - if (div < 0) + if (div < 0) { category = ""; - else { + } else { category = category.substr(0, div); name = name.substr(div + 1, name.size()); } @@ -799,18 +823,19 @@ Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_cust String custom_features; for (int i = 0; i < p_custom_features.size(); i++) { - if (i > 0) + if (i > 0) { custom_features += ","; + } String f = p_custom_features[i].strip_edges().replace("\"", ""); custom_features += f; } - if (p_path.ends_with(".godot")) + if (p_path.ends_with(".godot")) { return _save_settings_text(p_path, props, p_custom, custom_features); - else if (p_path.ends_with(".binary")) + } else if (p_path.ends_with(".binary")) { return _save_settings_binary(p_path, props, p_custom, custom_features); - else { + } else { ERR_FAIL_V_MSG(ERR_FILE_UNRECOGNIZED, "Unknown config file format: " + p_path + "."); } } @@ -834,8 +859,9 @@ Vector<String> ProjectSettings::get_optimizer_presets() const { Vector<String> names; for (List<PropertyInfo>::Element *E = pi.front(); E; E = E->next()) { - if (!E->get().name.begins_with("optimizer_presets/")) + if (!E->get().name.begins_with("optimizer_presets/")) { continue; + } names.push_back(E->get().name.get_slicec('/', 1)); } @@ -854,10 +880,12 @@ void ProjectSettings::_add_property_info_bind(const Dictionary &p_info) { pinfo.type = Variant::Type(p_info["type"].operator int()); ERR_FAIL_INDEX(pinfo.type, Variant::VARIANT_MAX); - if (p_info.has("hint")) + if (p_info.has("hint")) { pinfo.hint = PropertyHint(p_info["hint"].operator int()); - if (p_info.has("hint_string")) + } + if (p_info.has("hint_string")) { pinfo.hint_string = p_info["hint_string"]; + } set_custom_property_info(pinfo.name, pinfo); } @@ -881,15 +909,17 @@ bool ProjectSettings::is_using_datapack() const { } bool ProjectSettings::property_can_revert(const String &p_name) { - if (!props.has(p_name)) + if (!props.has(p_name)) { return false; + } return props[p_name].initial != props[p_name].variant; } Variant ProjectSettings::property_get_revert(const String &p_name) { - if (!props.has(p_name)) + if (!props.has(p_name)) { return Variant(); + } return props[p_name].initial; } @@ -948,8 +978,9 @@ ProjectSettings::ProjectSettings() { PackedStringArray extensions = PackedStringArray(); extensions.push_back("gd"); - if (Engine::get_singleton()->has_singleton("GodotSharp")) + if (Engine::get_singleton()->has_singleton("GodotSharp")) { extensions.push_back("cs"); + } extensions.push_back("shader"); GLOBAL_DEF("editor/search_in_file_extensions", extensions); diff --git a/core/reference.cpp b/core/reference.cpp index cc8a9854fb..d1dba0d9bf 100644 --- a/core/reference.cpp +++ b/core/reference.cpp @@ -103,12 +103,14 @@ Reference::Reference() : } Variant WeakRef::get_ref() const { - if (ref.is_null()) + if (ref.is_null()) { return Variant(); + } Object *obj = ObjectDB::get_instance(ref); - if (!obj) + if (!obj) { return Variant(); + } Reference *r = cast_to<Reference>(obj); if (r) { return REF(r); diff --git a/core/reference.h b/core/reference.h index 972fd500d0..f5794b0b67 100644 --- a/core/reference.h +++ b/core/reference.h @@ -59,21 +59,24 @@ class Ref { T *reference = nullptr; void ref(const Ref &p_from) { - if (p_from.reference == reference) + if (p_from.reference == reference) { return; + } unref(); reference = p_from.reference; - if (reference) + if (reference) { reference->reference(); + } } void ref_pointer(T *p_ref) { ERR_FAIL_COND(!p_ref); - if (p_ref->init_ref()) + if (p_ref->init_ref()) { reference = p_ref; + } } //virtual Reference * get_reference() const { return reference; } @@ -189,8 +192,9 @@ public: } Ref(T *p_reference) { - if (p_reference) + if (p_reference) { ref_pointer(p_reference); + } } Ref(const Variant &p_variant) { diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp index 230acb7e6e..3870141ecf 100644 --- a/core/register_core_types.cpp +++ b/core/register_core_types.cpp @@ -297,8 +297,9 @@ void unregister_core_types() { ResourceLoader::remove_resource_format_loader(resource_format_loader_crypto); resource_format_loader_crypto.unref(); - if (ip) + if (ip) { memdelete(ip); + } ResourceLoader::finalize(); diff --git a/core/resource.cpp b/core/resource.cpp index 7d0e29d664..0af8c9c2b3 100644 --- a/core/resource.cpp +++ b/core/resource.cpp @@ -46,8 +46,9 @@ void Resource::_resource_path_changed() { } void Resource::set_path(const String &p_path, bool p_take_over) { - if (path_cache == p_path) + if (path_cache == p_path) { return; + } if (path_cache != "") { ResourceCache::lock->write_lock(); @@ -116,22 +117,26 @@ bool Resource::editor_can_reload_from_file() { void Resource::reload_from_file() { String path = get_path(); - if (!path.is_resource_file()) + if (!path.is_resource_file()) { return; + } Ref<Resource> s = ResourceLoader::load(ResourceLoader::path_remap(path), get_class(), true); - if (!s.is_valid()) + if (!s.is_valid()) { return; + } List<PropertyInfo> pi; s->get_property_list(&pi); for (List<PropertyInfo>::Element *E = pi.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) + if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) { continue; - if (E->get().name == "resource_path") + } + if (E->get().name == "resource_path") { continue; //do not change path + } set(E->get().name, s->get(E->get().name)); } @@ -147,8 +152,9 @@ Ref<Resource> Resource::duplicate_for_local_scene(Node *p_for_scene, Map<Ref<Res r->local_scene = p_for_scene; for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) + if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) { continue; + } Variant p = get(E->get().name); if (p.get_type() == Variant::OBJECT) { RES sr = p; @@ -180,8 +186,9 @@ void Resource::configure_for_local_scene(Node *p_for_scene, Map<Ref<Resource>, R local_scene = p_for_scene; for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) + if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) { continue; + } Variant p = get(E->get().name); if (p.get_type() == Variant::OBJECT) { RES sr = p; @@ -205,8 +212,9 @@ Ref<Resource> Resource::duplicate(bool p_subresources) const { ERR_FAIL_COND_V(!r, Ref<Resource>()); for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) + if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) { continue; + } Variant p = get(E->get().name); if ((p.get_type() == Variant::DICTIONARY || p.get_type() == Variant::ARRAY)) { @@ -284,8 +292,9 @@ bool Resource::is_local_to_scene() const { } Node *Resource::get_local_scene() const { - if (local_scene) + if (local_scene) { return local_scene; + } if (_get_local_scene_func) { return _get_local_scene_func(); @@ -295,15 +304,17 @@ Node *Resource::get_local_scene() const { } void Resource::setup_local_to_scene() { - if (get_script_instance()) + if (get_script_instance()) { get_script_instance()->call("_setup_local_to_scene"); + } } Node *(*Resource::_get_local_scene_func)() = nullptr; void Resource::set_as_translation_remapped(bool p_remapped) { - if (remapped_list.in_list() == p_remapped) + if (remapped_list.in_list() == p_remapped) { return; + } if (ResourceCache::lock) { ResourceCache::lock->write_lock(); @@ -419,8 +430,9 @@ void ResourceCache::setup() { } void ResourceCache::clear() { - if (resources.size()) + if (resources.size()) { ERR_PRINT("Resources Still in use at Exit!"); + } resources.clear(); memdelete(lock); @@ -501,14 +513,16 @@ void ResourceCache::dump(const char *p_file, bool p_short) { type_count[r->get_class()]++; if (!p_short) { - if (f) + if (f) { f->store_line(r->get_class() + ": " + r->get_path()); + } } } for (Map<String, int>::Element *E = type_count.front(); E; E = E->next()) { - if (f) + if (f) { f->store_line(E->key() + " count: " + itos(E->get())); + } } if (f) { f->close(); diff --git a/core/ring_buffer.h b/core/ring_buffer.h index 816a5f33e1..2fd622b86f 100644 --- a/core/ring_buffer.h +++ b/core/ring_buffer.h @@ -80,8 +80,9 @@ public: int left = data_left(); if ((p_offset + p_size) > left) { p_size -= left - p_offset; - if (p_size <= 0) + if (p_size <= 0) { return 0; + } } p_size = MIN(left, p_size); int pos = read_pos; @@ -105,8 +106,9 @@ public: int left = data_left(); if ((p_offset + p_max_size) > left) { p_max_size -= left - p_offset; - if (p_max_size <= 0) + if (p_max_size <= 0) { return 0; + } } p_max_size = MIN(left, p_max_size); int pos = read_pos; @@ -117,8 +119,9 @@ public: end = MIN(end, size()); int total = end - pos; for (int i = 0; i < total; i++) { - if (data[pos + i] == t) + if (data[pos + i] == t) { return i + (p_max_size - to_read); + } }; to_read -= total; pos = 0; diff --git a/core/safe_refcount.h b/core/safe_refcount.h index 8e23a0cf94..dc4e62354a 100644 --- a/core/safe_refcount.h +++ b/core/safe_refcount.h @@ -43,8 +43,9 @@ template <class T> static _ALWAYS_INLINE_ T atomic_conditional_increment(volatile T *pw) { - if (*pw == 0) + if (*pw == 0) { return 0; + } (*pw)++; @@ -81,8 +82,9 @@ static _ALWAYS_INLINE_ T atomic_add(volatile T *pw, volatile V val) { template <class T, class V> static _ALWAYS_INLINE_ T atomic_exchange_if_greater(volatile T *pw, volatile V val) { - if (val > *pw) + if (val > *pw) { *pw = val; + } return *pw; } @@ -98,10 +100,12 @@ template <class T> static _ALWAYS_INLINE_ T atomic_conditional_increment(volatile T *pw) { while (true) { T tmp = static_cast<T const volatile &>(*pw); - if (tmp == 0) + if (tmp == 0) { return 0; // if zero, can't add to it anymore - if (__sync_val_compare_and_swap(pw, tmp, tmp + 1) == tmp) + } + if (__sync_val_compare_and_swap(pw, tmp, tmp + 1) == tmp) { return tmp + 1; + } } } @@ -129,10 +133,12 @@ template <class T, class V> static _ALWAYS_INLINE_ T atomic_exchange_if_greater(volatile T *pw, volatile V val) { while (true) { T tmp = static_cast<T const volatile &>(*pw); - if (tmp >= val) + if (tmp >= val) { return tmp; // already greater, or equal - if (__sync_val_compare_and_swap(pw, tmp, val) == tmp) + } + if (__sync_val_compare_and_swap(pw, tmp, val) == tmp) { return val; + } } } diff --git a/core/script_language.cpp b/core/script_language.cpp index 6e5363e916..38a970f3c6 100644 --- a/core/script_language.cpp +++ b/core/script_language.cpp @@ -47,8 +47,9 @@ ScriptEditRequestFunction ScriptServer::edit_request_func = nullptr; void Script::_notification(int p_what) { if (p_what == NOTIFICATION_POSTINITIALIZE) { - if (EngineDebugger::is_active()) + if (EngineDebugger::is_active()) { EngineDebugger::get_script_debugger()->set_break_language(get_language()); + } } } @@ -161,8 +162,9 @@ void ScriptServer::init_languages() { for (int i = 0; i < script_classes.size(); i++) { Dictionary c = script_classes[i]; - if (!c.has("class") || !c.has("language") || !c.has("path") || !c.has("base")) + if (!c.has("class") || !c.has("language") || !c.has("path") || !c.has("base")) { continue; + } add_global_class(c["class"], c["base"], c["language"], c["path"]); } } @@ -285,8 +287,9 @@ void ScriptInstance::get_property_state(List<Pair<StringName, Variant>> &state) if (E->get().usage & PROPERTY_USAGE_STORAGE) { Pair<StringName, Variant> p; p.first = E->get().name; - if (get(p.first, p.second)) + if (get(p.first, p.second)) { state.push_back(p); + } } } } @@ -295,8 +298,9 @@ Variant ScriptInstance::call(const StringName &p_method, VARIANT_ARG_DECLARE) { VARIANT_ARGPTRS; int argc = 0; for (int i = 0; i < VARIANT_ARG_MAX; i++) { - if (argptr[i]->get_type() == Variant::NIL) + if (argptr[i]->get_type() == Variant::NIL) { break; + } argc++; } @@ -315,13 +319,15 @@ void ScriptInstance::call_multilevel_reversed(const StringName &p_method, const } void ScriptInstance::property_set_fallback(const StringName &, const Variant &, bool *r_valid) { - if (r_valid) + if (r_valid) { *r_valid = false; + } } Variant ScriptInstance::property_get_fallback(const StringName &, bool *r_valid) { - if (r_valid) + if (r_valid) { *r_valid = false; + } return Variant(); } @@ -329,8 +335,9 @@ void ScriptInstance::call_multilevel(const StringName &p_method, VARIANT_ARG_DEC VARIANT_ARGPTRS; int argc = 0; for (int i = 0; i < VARIANT_ARG_MAX; i++) { - if (argptr[i]->get_type() == Variant::NIL) + if (argptr[i]->get_type() == Variant::NIL) { break; + } argc++; } @@ -349,8 +356,9 @@ void ScriptLanguage::frame() { } bool PlaceHolderScriptInstance::set(const StringName &p_name, const Variant &p_value) { - if (script->is_placeholder_fallback_enabled()) + if (script->is_placeholder_fallback_enabled()) { return false; + } if (values.has(p_name)) { Variant defval; @@ -414,26 +422,30 @@ void PlaceHolderScriptInstance::get_property_list(List<PropertyInfo> *p_properti Variant::Type PlaceHolderScriptInstance::get_property_type(const StringName &p_name, bool *r_is_valid) const { if (values.has(p_name)) { - if (r_is_valid) + if (r_is_valid) { *r_is_valid = true; + } return values[p_name].get_type(); } if (constants.has(p_name)) { - if (r_is_valid) + if (r_is_valid) { *r_is_valid = true; + } return constants[p_name].get_type(); } - if (r_is_valid) + if (r_is_valid) { *r_is_valid = false; + } return Variant::NIL; } void PlaceHolderScriptInstance::get_method_list(List<MethodInfo> *p_list) const { - if (script->is_placeholder_fallback_enabled()) + if (script->is_placeholder_fallback_enabled()) { return; + } if (script.is_valid()) { script->get_script_method_list(p_list); @@ -441,8 +453,9 @@ void PlaceHolderScriptInstance::get_method_list(List<MethodInfo> *p_list) const } bool PlaceHolderScriptInstance::has_method(const StringName &p_method) const { - if (script->is_placeholder_fallback_enabled()) + if (script->is_placeholder_fallback_enabled()) { return false; + } if (script.is_valid()) { return script->has_method(p_method); @@ -457,8 +470,9 @@ void PlaceHolderScriptInstance::update(const List<PropertyInfo> &p_properties, c new_values.insert(n); if (!values.has(n) || values[n].get_type() != E->get().type) { - if (p_values.has(n)) + if (p_values.has(n)) { values[n] = p_values[n]; + } } } @@ -466,8 +480,9 @@ void PlaceHolderScriptInstance::update(const List<PropertyInfo> &p_properties, c List<StringName> to_remove; for (Map<StringName, Variant>::Element *E = values.front(); E; E = E->next()) { - if (!new_values.has(E->key())) + if (!new_values.has(E->key())) { to_remove.push_back(E->key()); + } Variant defval; if (script->get_property_default_value(E->key(), defval)) { @@ -514,8 +529,9 @@ void PlaceHolderScriptInstance::property_set_fallback(const StringName &p_name, } } - if (r_valid) + if (r_valid) { *r_valid = false; // Cannot change the value in either case + } } Variant PlaceHolderScriptInstance::property_get_fallback(const StringName &p_name, bool *r_valid) { @@ -523,21 +539,24 @@ Variant PlaceHolderScriptInstance::property_get_fallback(const StringName &p_nam const Map<StringName, Variant>::Element *E = values.find(p_name); if (E) { - if (r_valid) + if (r_valid) { *r_valid = true; + } return E->value(); } E = constants.find(p_name); if (E) { - if (r_valid) + if (r_valid) { *r_valid = true; + } return E->value(); } } - if (r_valid) + if (r_valid) { *r_valid = false; + } return Variant(); } diff --git a/core/script_language.h b/core/script_language.h index 602ac42b2f..b6c2a47245 100644 --- a/core/script_language.h +++ b/core/script_language.h @@ -204,8 +204,9 @@ public: virtual void call_multilevel_reversed(const StringName &p_method, const Variant **p_args, int p_argcount); virtual void notification(int p_notification) = 0; virtual String to_string(bool *r_valid) { - if (r_valid) + if (r_valid) { *r_valid = false; + } return String(); } diff --git a/core/self_list.h b/core/self_list.h index c70d2a8c0a..3104bcb714 100644 --- a/core/self_list.h +++ b/core/self_list.h @@ -115,8 +115,9 @@ private: public: _FORCE_INLINE_ bool in_list() const { return _root; } _FORCE_INLINE_ void remove_from_list() { - if (_root) + if (_root) { _root->remove(this); + } } _FORCE_INLINE_ SelfList<T> *next() { return _next; } _FORCE_INLINE_ SelfList<T> *prev() { return _prev; } @@ -129,8 +130,9 @@ public: } _FORCE_INLINE_ ~SelfList() { - if (_root) + if (_root) { _root->remove(this); + } } }; diff --git a/core/set.h b/core/set.h index 88eccc7ea8..1bc0a3f41e 100644 --- a/core/set.h +++ b/core/set.h @@ -125,13 +125,15 @@ private: inline void _rotate_left(Element *p_node) { Element *r = p_node->right; p_node->right = r->left; - if (r->left != _data._nil) + if (r->left != _data._nil) { r->left->parent = p_node; + } r->parent = p_node->parent; - if (p_node == p_node->parent->left) + if (p_node == p_node->parent->left) { p_node->parent->left = r; - else + } else { p_node->parent->right = r; + } r->left = p_node; p_node->parent = r; @@ -140,13 +142,15 @@ private: inline void _rotate_right(Element *p_node) { Element *l = p_node->left; p_node->left = l->right; - if (l->right != _data._nil) + if (l->right != _data._nil) { l->right->parent = p_node; + } l->parent = p_node->parent; - if (p_node == p_node->parent->right) + if (p_node == p_node->parent->right) { p_node->parent->right = l; - else + } else { p_node->parent->left = l; + } l->right = p_node; p_node->parent = l; @@ -166,8 +170,9 @@ private: node = node->parent; } - if (node->parent == _data._root) + if (node->parent == _data._root) { return nullptr; // No successor, as p_node = last node + } return node->parent; } } @@ -186,8 +191,9 @@ private: node = node->parent; } - if (node == _data._root) + if (node == _data._root) { return nullptr; // No predecessor, as p_node = first node. + } return node->parent; } } @@ -197,12 +203,13 @@ private: C less; while (node != _data._nil) { - if (less(p_value, node->value)) + if (less(p_value, node->value)) { node = node->left; - else if (less(node->value, p_value)) + } else if (less(node->value, p_value)) { node = node->right; - else + } else { return node; // found + } } return nullptr; @@ -216,19 +223,22 @@ private: while (node != _data._nil) { prev = node; - if (less(p_value, node->value)) + if (less(p_value, node->value)) { node = node->left; - else if (less(node->value, p_value)) + } else if (less(node->value, p_value)) { node = node->right; - else + } else { return node; // found + } } - if (prev == nullptr) + if (prev == nullptr) { return nullptr; // tree empty + } - if (less(prev->value, p_value)) + if (less(prev->value, p_value)) { prev = prev->_next; + } return prev; } @@ -289,11 +299,11 @@ private: while (node != _data._nil) { new_parent = node; - if (less(p_value, node->value)) + if (less(p_value, node->value)) { node = node->left; - else if (less(node->value, p_value)) + } else if (less(node->value, p_value)) { node = node->right; - else { + } else { return node; // Return existing node } } @@ -313,10 +323,12 @@ private: new_node->_next = _successor(new_node); new_node->_prev = _predecessor(new_node); - if (new_node->_next) + if (new_node->_next) { new_node->_next->_prev = new_node; - if (new_node->_prev) + } + if (new_node->_prev) { new_node->_prev->_next = new_node; + } _data.size_cache++; _insert_rb_fix(new_node); @@ -411,10 +423,12 @@ private: rp->right = p_node->right; rp->parent = p_node->parent; rp->color = p_node->color; - if (p_node->left != _data._nil) + if (p_node->left != _data._nil) { p_node->left->parent = rp; - if (p_node->right != _data._nil) + } + if (p_node->right != _data._nil) { p_node->right->parent = rp; + } if (p_node == p_node->parent->left) { p_node->parent->left = rp; @@ -423,10 +437,12 @@ private: } } - if (p_node->_next) + if (p_node->_next) { p_node->_next->_prev = p_node->_prev; - if (p_node->_prev) + } + if (p_node->_prev) { p_node->_prev->_next = p_node->_next; + } memdelete_allocator<Element, A>(p_node); _data.size_cache--; @@ -434,19 +450,22 @@ private: } void _calculate_depth(Element *p_element, int &max_d, int d) const { - if (p_element == _data._nil) + if (p_element == _data._nil) { return; + } _calculate_depth(p_element->left, max_d, d + 1); _calculate_depth(p_element->right, max_d, d + 1); - if (d > max_d) + if (d > max_d) { max_d = d; + } } void _cleanup_tree(Element *p_element) { - if (p_element == _data._nil) + if (p_element == _data._nil) { return; + } _cleanup_tree(p_element->left); _cleanup_tree(p_element->right); @@ -463,16 +482,18 @@ private: public: const Element *find(const T &p_value) const { - if (!_data._root) + if (!_data._root) { return nullptr; + } const Element *res = _find(p_value); return res; } Element *find(const T &p_value) { - if (!_data._root) + if (!_data._root) { return nullptr; + } Element *res = _find(p_value); return res; @@ -487,58 +508,70 @@ public: } Element *insert(const T &p_value) { - if (!_data._root) + if (!_data._root) { _data._create_root(); + } return _insert(p_value); } void erase(Element *p_element) { - if (!_data._root || !p_element) + if (!_data._root || !p_element) { return; + } _erase(p_element); - if (_data.size_cache == 0 && _data._root) + if (_data.size_cache == 0 && _data._root) { _data._free_root(); + } } bool erase(const T &p_value) { - if (!_data._root) + if (!_data._root) { return false; + } Element *e = find(p_value); - if (!e) + if (!e) { return false; + } _erase(e); - if (_data.size_cache == 0 && _data._root) + if (_data.size_cache == 0 && _data._root) { _data._free_root(); + } return true; } Element *front() const { - if (!_data._root) + if (!_data._root) { return nullptr; + } Element *e = _data._root->left; - if (e == _data._nil) + if (e == _data._nil) { return nullptr; + } - while (e->left != _data._nil) + while (e->left != _data._nil) { e = e->left; + } return e; } Element *back() const { - if (!_data._root) + if (!_data._root) { return nullptr; + } Element *e = _data._root->left; - if (e == _data._nil) + if (e == _data._nil) { return nullptr; + } - while (e->right != _data._nil) + while (e->right != _data._nil) { e = e->right; + } return e; } @@ -548,8 +581,9 @@ public: int calculate_depth() const { // used for debug mostly - if (!_data._root) + if (!_data._root) { return 0; + } int max_d = 0; _calculate_depth(_data._root->left, max_d, 0); @@ -557,8 +591,9 @@ public: } void clear() { - if (!_data._root) + if (!_data._root) { return; + } _cleanup_tree(_data._root->left); _data._root->left = _data._nil; diff --git a/core/sort_array.h b/core/sort_array.h index 2dd7c20eae..93cc6f727d 100644 --- a/core/sort_array.h +++ b/core/sort_array.h @@ -62,25 +62,28 @@ public: Comparator compare; inline const T &median_of_3(const T &a, const T &b, const T &c) const { - if (compare(a, b)) - if (compare(b, c)) + if (compare(a, b)) { + if (compare(b, c)) { return b; - else if (compare(a, c)) + } else if (compare(a, c)) { return c; - else + } else { return a; - else if (compare(a, c)) + } + } else if (compare(a, c)) { return a; - else if (compare(b, c)) + } else if (compare(b, c)) { return c; - else + } else { return b; + } } inline int bitlog(int n) const { int k; - for (k = 0; n != 1; n >>= 1) + for (k = 0; n != 1; n >>= 1) { ++k; + } return k; } @@ -109,8 +112,9 @@ public: int second_child = 2 * p_hole_idx + 2; while (second_child < p_len) { - if (compare(p_array[p_first + second_child], p_array[p_first + (second_child - 1)])) + if (compare(p_array[p_first + second_child], p_array[p_first + (second_child - 1)])) { second_child--; + } p_array[p_first + p_hole_idx] = p_array[p_first + second_child]; p_hole_idx = second_child; @@ -131,32 +135,38 @@ public: } inline void make_heap(int p_first, int p_last, T *p_array) const { - if (p_last - p_first < 2) + if (p_last - p_first < 2) { return; + } int len = p_last - p_first; int parent = (len - 2) / 2; while (true) { adjust_heap(p_first, parent, len, p_array[p_first + parent], p_array); - if (parent == 0) + if (parent == 0) { return; + } parent--; } } inline void partial_sort(int p_first, int p_last, int p_middle, T *p_array) const { make_heap(p_first, p_middle, p_array); - for (int i = p_middle; i < p_last; i++) - if (compare(p_array[i], p_array[p_first])) + for (int i = p_middle; i < p_last; i++) { + if (compare(p_array[i], p_array[p_first])) { pop_heap(p_first, p_middle, i, p_array[i], p_array); + } + } sort_heap(p_first, p_middle, p_array); } inline void partial_select(int p_first, int p_last, int p_middle, T *p_array) const { make_heap(p_first, p_middle, p_array); - for (int i = p_middle; i < p_last; i++) - if (compare(p_array[i], p_array[p_first])) + for (int i = p_middle; i < p_last; i++) { + if (compare(p_array[i], p_array[p_first])) { pop_heap(p_first, p_middle, i, p_array[i], p_array); + } + } } inline int partitioner(int p_first, int p_last, T p_pivot, T *p_array) const { @@ -178,8 +188,9 @@ public: p_last--; } - if (!(p_first < p_last)) + if (!(p_first < p_last)) { return p_first; + } SWAP(p_array[p_first], p_array[p_last]); p_first++; @@ -228,10 +239,11 @@ public: p_array[p_last - 1]), p_array); - if (cut <= p_nth) + if (cut <= p_nth) { p_first = cut; - else + } else { p_last = cut; + } } insertion_sort(p_first, p_last, p_array); @@ -253,24 +265,29 @@ public: inline void linear_insert(int p_first, int p_last, T *p_array) const { T val = p_array[p_last]; if (compare(val, p_array[p_first])) { - for (int i = p_last; i > p_first; i--) + for (int i = p_last; i > p_first; i--) { p_array[i] = p_array[i - 1]; + } p_array[p_first] = val; - } else + } else { unguarded_linear_insert(p_last, val, p_array); + } } inline void insertion_sort(int p_first, int p_last, T *p_array) const { - if (p_first == p_last) + if (p_first == p_last) { return; - for (int i = p_first + 1; i != p_last; i++) + } + for (int i = p_first + 1; i != p_last; i++) { linear_insert(p_first, i, p_array); + } } inline void unguarded_insertion_sort(int p_first, int p_last, T *p_array) const { - for (int i = p_first; i != p_last; i++) + for (int i = p_first; i != p_last; i++) { unguarded_linear_insert(i, p_array[i], p_array); + } } inline void final_insertion_sort(int p_first, int p_last, T *p_array) const { @@ -294,8 +311,9 @@ public: } inline void nth_element(int p_first, int p_last, int p_nth, T *p_array) const { - if (p_first == p_last || p_nth == p_last) + if (p_first == p_last || p_nth == p_last) { return; + } introselect(p_first, p_nth, p_last, p_array, bitlog(p_last - p_first) * 2); } }; diff --git a/core/string_buffer.h b/core/string_buffer.h index 0f0b572efb..956a6333d9 100644 --- a/core/string_buffer.h +++ b/core/string_buffer.h @@ -118,8 +118,9 @@ StringBuffer<SHORT_BUFFER_SIZE> &StringBuffer<SHORT_BUFFER_SIZE>::append(const C template <int SHORT_BUFFER_SIZE> StringBuffer<SHORT_BUFFER_SIZE> &StringBuffer<SHORT_BUFFER_SIZE>::reserve(int p_size) { - if (p_size < SHORT_BUFFER_SIZE || p_size < buffer.size()) + if (p_size < SHORT_BUFFER_SIZE || p_size < buffer.size()) { return *this; + } bool need_copy = string_length > 0 && buffer.empty(); buffer.resize(next_power_of_2(p_size)); diff --git a/core/string_builder.cpp b/core/string_builder.cpp index 6b105611f0..c8d6498f27 100644 --- a/core/string_builder.cpp +++ b/core/string_builder.cpp @@ -33,8 +33,9 @@ #include <string.h> StringBuilder &StringBuilder::append(const String &p_string) { - if (p_string == String()) + if (p_string == String()) { return *this; + } strings.push_back(p_string); appended_strings.push_back(-1); @@ -56,8 +57,9 @@ StringBuilder &StringBuilder::append(const char *p_cstring) { } String StringBuilder::as_string() const { - if (string_length == 0) + if (string_length == 0) { return ""; + } CharType *buffer = memnew_arr(CharType, string_length); diff --git a/core/string_name.cpp b/core/string_name.cpp index 7f2da6151e..cbf6009681 100644 --- a/core/string_name.cpp +++ b/core/string_name.cpp @@ -132,8 +132,9 @@ bool StringName::operator!=(const StringName &p_name) const { } void StringName::operator=(const StringName &p_name) { - if (this == &p_name) + if (this == &p_name) { return; + } unref(); @@ -157,8 +158,9 @@ StringName::StringName(const char *p_name) { ERR_FAIL_COND(!configured); - if (!p_name || p_name[0] == 0) + if (!p_name || p_name[0] == 0) { return; //empty, ignore + } MutexLock lock(mutex); @@ -170,8 +172,9 @@ StringName::StringName(const char *p_name) { while (_data) { // compare hash first - if (_data->hash == hash && _data->get_name() == p_name) + if (_data->hash == hash && _data->get_name() == p_name) { break; + } _data = _data->next; } @@ -190,8 +193,9 @@ StringName::StringName(const char *p_name) { _data->cname = nullptr; _data->next = _table[idx]; _data->prev = nullptr; - if (_table[idx]) + if (_table[idx]) { _table[idx]->prev = _data; + } _table[idx] = _data; } @@ -212,8 +216,9 @@ StringName::StringName(const StaticCString &p_static_string) { while (_data) { // compare hash first - if (_data->hash == hash && _data->get_name() == p_static_string.ptr) + if (_data->hash == hash && _data->get_name() == p_static_string.ptr) { break; + } _data = _data->next; } @@ -232,8 +237,9 @@ StringName::StringName(const StaticCString &p_static_string) { _data->cname = p_static_string.ptr; _data->next = _table[idx]; _data->prev = nullptr; - if (_table[idx]) + if (_table[idx]) { _table[idx]->prev = _data; + } _table[idx] = _data; } @@ -242,8 +248,9 @@ StringName::StringName(const String &p_name) { ERR_FAIL_COND(!configured); - if (p_name == String()) + if (p_name == String()) { return; + } MutexLock lock(mutex); @@ -253,8 +260,9 @@ StringName::StringName(const String &p_name) { _data = _table[idx]; while (_data) { - if (_data->hash == hash && _data->get_name() == p_name) + if (_data->hash == hash && _data->get_name() == p_name) { break; + } _data = _data->next; } @@ -273,8 +281,9 @@ StringName::StringName(const String &p_name) { _data->cname = nullptr; _data->next = _table[idx]; _data->prev = nullptr; - if (_table[idx]) + if (_table[idx]) { _table[idx]->prev = _data; + } _table[idx] = _data; } @@ -282,8 +291,9 @@ StringName StringName::search(const char *p_name) { ERR_FAIL_COND_V(!configured, StringName()); ERR_FAIL_COND_V(!p_name, StringName()); - if (!p_name[0]) + if (!p_name[0]) { return StringName(); + } MutexLock lock(mutex); @@ -294,8 +304,9 @@ StringName StringName::search(const char *p_name) { while (_data) { // compare hash first - if (_data->hash == hash && _data->get_name() == p_name) + if (_data->hash == hash && _data->get_name() == p_name) { break; + } _data = _data->next; } @@ -310,8 +321,9 @@ StringName StringName::search(const CharType *p_name) { ERR_FAIL_COND_V(!configured, StringName()); ERR_FAIL_COND_V(!p_name, StringName()); - if (!p_name[0]) + if (!p_name[0]) { return StringName(); + } MutexLock lock(mutex); @@ -323,8 +335,9 @@ StringName StringName::search(const CharType *p_name) { while (_data) { // compare hash first - if (_data->hash == hash && _data->get_name() == p_name) + if (_data->hash == hash && _data->get_name() == p_name) { break; + } _data = _data->next; } @@ -348,8 +361,9 @@ StringName StringName::search(const String &p_name) { while (_data) { // compare hash first - if (_data->hash == hash && p_name == _data->get_name()) + if (_data->hash == hash && p_name == _data->get_name()) { break; + } _data = _data->next; } diff --git a/core/string_name.h b/core/string_name.h index 0517696ab1..df6b458581 100644 --- a/core/string_name.h +++ b/core/string_name.h @@ -96,10 +96,11 @@ public: return _data == p_name._data; } _FORCE_INLINE_ uint32_t hash() const { - if (_data) + if (_data) { return _data->hash; - else + } else { return 0; + } } _FORCE_INLINE_ const void *data_unique_pointer() const { return (void *)_data; @@ -108,10 +109,11 @@ public: _FORCE_INLINE_ operator String() const { if (_data) { - if (_data->cname) + if (_data->cname) { return String(_data->cname); - else + } else { return _data->name; + } } return String(); @@ -127,15 +129,17 @@ public: const char *r_cname = r._data ? r._data->cname : ""; if (l_cname) { - if (r_cname) + if (r_cname) { return is_str_less(l_cname, r_cname); - else + } else { return is_str_less(l_cname, r._data->name.ptr()); + } } else { - if (r_cname) + if (r_cname) { return is_str_less(l._data->name.ptr(), r_cname); - else + } else { return is_str_less(l._data->name.ptr(), r._data->name.ptr()); + } } } }; diff --git a/core/translation.cpp b/core/translation.cpp index 2eaccc6c4e..f3c1489ce4 100644 --- a/core/translation.cpp +++ b/core/translation.cpp @@ -854,8 +854,9 @@ void Translation::add_message(const StringName &p_src_text, const StringName &p_ StringName Translation::get_message(const StringName &p_src_text) const { const Map<StringName, StringName>::Element *E = translation_map.find(p_src_text); - if (!E) + if (!E) { return StringName(); + } return E->get(); } @@ -895,8 +896,9 @@ bool TranslationServer::is_locale_valid(const String &p_locale) { const char **ptr = locale_list; while (*ptr) { - if (*ptr == p_locale) + if (*ptr == p_locale) { return true; + } ptr++; } @@ -965,8 +967,9 @@ String TranslationServer::get_locale() const { } String TranslationServer::get_locale_name(const String &p_locale) const { - if (!locale_name_map.has(p_locale)) + if (!locale_name_map.has(p_locale)) { return String(); + } return locale_name_map[p_locale]; } @@ -1024,8 +1027,9 @@ void TranslationServer::clear() { StringName TranslationServer::translate(const StringName &p_message) const { // Match given message against the translation catalog for the project locale. - if (!enabled) + if (!enabled) { return p_message; + } ERR_FAIL_COND_V_MSG(locale.length() < 2, p_message, "Could not translate message as configured locale '" + locale + "' is invalid."); @@ -1125,8 +1129,9 @@ bool TranslationServer::_load_translations(const String &p_from) { for (int i = 0; i < tcount; i++) { Ref<Translation> tr = ResourceLoader::load(r[i]); - if (tr.is_valid()) + if (tr.is_valid()) { add_translation(tr); + } } } return true; @@ -1138,18 +1143,20 @@ bool TranslationServer::_load_translations(const String &p_from) { void TranslationServer::setup() { String test = GLOBAL_DEF("locale/test", ""); test = test.strip_edges(); - if (test != "") + if (test != "") { set_locale(test); - else + } else { set_locale(OS::get_singleton()->get_locale()); + } fallback = GLOBAL_DEF("locale/fallback", "en"); #ifdef TOOLS_ENABLED { String options = ""; int idx = 0; while (locale_list[idx]) { - if (idx > 0) + if (idx > 0) { options += ","; + } options += locale_list[idx]; idx++; } diff --git a/core/type_info.h b/core/type_info.h index afc0dd2107..e3d2b5bd53 100644 --- a/core/type_info.h +++ b/core/type_info.h @@ -258,8 +258,9 @@ struct GetTypeInfo<const T *, typename EnableIf<TypeInherits<Object, T>::value>: template <typename T> inline StringName __constant_get_enum_name(T param, const String &p_constant) { - if (GetTypeInfo<T>::VARIANT_TYPE == Variant::NIL) + if (GetTypeInfo<T>::VARIANT_TYPE == Variant::NIL) { ERR_PRINT("Missing VARIANT_ENUM_CAST for constant's enum: " + p_constant); + } return GetTypeInfo<T>::get_class_info().class_name; } diff --git a/core/typedefs.h b/core/typedefs.h index bafbffcded..4bfa5debac 100644 --- a/core/typedefs.h +++ b/core/typedefs.h @@ -185,8 +185,9 @@ static _FORCE_INLINE_ T nearest_power_of_2_templated(T x) { // Function to find the nearest (bigger) power of 2 to an integer. static inline unsigned int nearest_shift(unsigned int p_number) { for (int i = 30; i >= 0; i--) { - if (p_number & (1 << i)) + if (p_number & (1 << i)) { return i + 1; + } } return 0; diff --git a/core/undo_redo.cpp b/core/undo_redo.cpp index d1a71a6b64..90750f2c6e 100644 --- a/core/undo_redo.cpp +++ b/core/undo_redo.cpp @@ -33,15 +33,17 @@ #include "core/os/os.h" void UndoRedo::_discard_redo() { - if (current_action == actions.size() - 1) + if (current_action == actions.size() - 1) { return; + } for (int i = current_action + 1; i < actions.size(); i++) { for (List<Operation>::Element *E = actions.write[i].do_ops.front(); E; E = E->next()) { if (E->get().type == Operation::TYPE_REFERENCE) { Object *obj = ObjectDB::get_instance(E->get().object); - if (obj) + if (obj) { memdelete(obj); + } } } //ERASE do data @@ -68,8 +70,9 @@ void UndoRedo::create_action(const String &p_name, MergeMode p_mode) { if (E->get().type == Operation::TYPE_REFERENCE) { Object *obj = ObjectDB::get_instance(E->get().object); - if (obj) + if (obj) { memdelete(obj); + } } E = E->next(); @@ -101,8 +104,9 @@ void UndoRedo::add_do_method(Object *p_object, const StringName &p_method, VARIA ERR_FAIL_COND((current_action + 1) >= actions.size()); Operation do_op; do_op.object = p_object->get_instance_id(); - if (Object::cast_to<Resource>(p_object)) + if (Object::cast_to<Resource>(p_object)) { do_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object)); + } do_op.type = Operation::TYPE_METHOD; do_op.name = p_method; @@ -120,13 +124,15 @@ void UndoRedo::add_undo_method(Object *p_object, const StringName &p_method, VAR ERR_FAIL_COND((current_action + 1) >= actions.size()); // No undo if the merge mode is MERGE_ENDS - if (merge_mode == MERGE_ENDS) + if (merge_mode == MERGE_ENDS) { return; + } Operation undo_op; undo_op.object = p_object->get_instance_id(); - if (Object::cast_to<Resource>(p_object)) + if (Object::cast_to<Resource>(p_object)) { undo_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object)); + } undo_op.type = Operation::TYPE_METHOD; undo_op.name = p_method; @@ -143,8 +149,9 @@ void UndoRedo::add_do_property(Object *p_object, const StringName &p_property, c ERR_FAIL_COND((current_action + 1) >= actions.size()); Operation do_op; do_op.object = p_object->get_instance_id(); - if (Object::cast_to<Resource>(p_object)) + if (Object::cast_to<Resource>(p_object)) { do_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object)); + } do_op.type = Operation::TYPE_PROPERTY; do_op.name = p_property; @@ -158,13 +165,15 @@ void UndoRedo::add_undo_property(Object *p_object, const StringName &p_property, ERR_FAIL_COND((current_action + 1) >= actions.size()); // No undo if the merge mode is MERGE_ENDS - if (merge_mode == MERGE_ENDS) + if (merge_mode == MERGE_ENDS) { return; + } Operation undo_op; undo_op.object = p_object->get_instance_id(); - if (Object::cast_to<Resource>(p_object)) + if (Object::cast_to<Resource>(p_object)) { undo_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object)); + } undo_op.type = Operation::TYPE_PROPERTY; undo_op.name = p_property; @@ -178,8 +187,9 @@ void UndoRedo::add_do_reference(Object *p_object) { ERR_FAIL_COND((current_action + 1) >= actions.size()); Operation do_op; do_op.object = p_object->get_instance_id(); - if (Object::cast_to<Resource>(p_object)) + if (Object::cast_to<Resource>(p_object)) { do_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object)); + } do_op.type = Operation::TYPE_REFERENCE; actions.write[current_action + 1].do_ops.push_back(do_op); @@ -191,13 +201,15 @@ void UndoRedo::add_undo_reference(Object *p_object) { ERR_FAIL_COND((current_action + 1) >= actions.size()); // No undo if the merge mode is MERGE_ENDS - if (merge_mode == MERGE_ENDS) + if (merge_mode == MERGE_ENDS) { return; + } Operation undo_op; undo_op.object = p_object->get_instance_id(); - if (Object::cast_to<Resource>(p_object)) + if (Object::cast_to<Resource>(p_object)) { undo_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object)); + } undo_op.type = Operation::TYPE_REFERENCE; actions.write[current_action + 1].undo_ops.push_back(undo_op); @@ -206,14 +218,16 @@ void UndoRedo::add_undo_reference(Object *p_object) { void UndoRedo::_pop_history_tail() { _discard_redo(); - if (!actions.size()) + if (!actions.size()) { return; + } for (List<Operation>::Element *E = actions.write[0].undo_ops.front(); E; E = E->next()) { if (E->get().type == Operation::TYPE_REFERENCE) { Object *obj = ObjectDB::get_instance(E->get().object); - if (obj) + if (obj) { memdelete(obj); + } } } @@ -230,8 +244,9 @@ bool UndoRedo::is_committing_action() const { void UndoRedo::commit_action() { ERR_FAIL_COND(action_level <= 0); action_level--; - if (action_level > 0) + if (action_level > 0) { return; //still nested + } if (merging) { version--; @@ -251,8 +266,9 @@ void UndoRedo::_process_operation_list(List<Operation>::Element *E) { Operation &op = E->get(); Object *obj = ObjectDB::get_instance(op.object); - if (!obj) //may have been deleted and this is fine + if (!obj) { //may have been deleted and this is fine continue; + } switch (op.type) { case Operation::TYPE_METHOD: { @@ -276,8 +292,9 @@ void UndoRedo::_process_operation_list(List<Operation>::Element *E) { } #ifdef TOOLS_ENABLED Resource *res = Object::cast_to<Resource>(obj); - if (res) + if (res) { res->set_edited(true); + } #endif @@ -289,8 +306,9 @@ void UndoRedo::_process_operation_list(List<Operation>::Element *E) { obj->set(op.name, op.args[0]); #ifdef TOOLS_ENABLED Resource *res = Object::cast_to<Resource>(obj); - if (res) + if (res) { res->set_edited(true); + } #endif if (property_callback) { property_callback(prop_callback_ud, obj, op.name, op.args[0]); @@ -306,8 +324,9 @@ void UndoRedo::_process_operation_list(List<Operation>::Element *E) { bool UndoRedo::redo() { ERR_FAIL_COND_V(action_level > 0, false); - if ((current_action + 1) >= actions.size()) + if ((current_action + 1) >= actions.size()) { return false; //nothing to redo + } current_action++; @@ -320,8 +339,9 @@ bool UndoRedo::redo() { bool UndoRedo::undo() { ERR_FAIL_COND_V(action_level > 0, false); - if (current_action < 0) + if (current_action < 0) { return false; //nothing to redo + } _process_operation_list(actions.write[current_action].undo_ops.front()); current_action--; version--; @@ -334,8 +354,9 @@ void UndoRedo::clear_history(bool p_increase_version) { ERR_FAIL_COND(action_level > 0); _discard_redo(); - while (actions.size()) + while (actions.size()) { _pop_history_tail(); + } if (p_increase_version) { version++; @@ -345,8 +366,9 @@ void UndoRedo::clear_history(bool p_increase_version) { String UndoRedo::get_current_action_name() const { ERR_FAIL_COND_V(action_level > 0, ""); - if (current_action < 0) + if (current_action < 0) { return ""; + } return actions[current_action].name; } diff --git a/core/ustring.cpp b/core/ustring.cpp index a1a2280066..ed096bd475 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -83,8 +83,9 @@ bool select_word(const String &p_s, int p_col, int &r_beg, int &r_end) { end++; } - if (end < s.length()) + if (end < s.length()) { end += 1; + } r_beg = beg; r_end = end; @@ -114,10 +115,11 @@ CharString &CharString::operator+=(char p_char) { } const char *CharString::get_data() const { - if (size()) + if (size()) { return &operator[](0); - else + } else { return ""; + } } CharString &CharString::operator=(const char *p_cstr) { @@ -153,8 +155,9 @@ void String::copy_from(const char *p_cstr) { int len = 0; const char *ptr = p_cstr; - while (*(ptr++) != 0) + while (*(ptr++) != 0) { len++; + } if (len == 0) { resize(0); @@ -178,8 +181,9 @@ void String::copy_from(const CharType *p_cstr, const int p_clip_to) { int len = 0; const CharType *ptr = p_cstr; - while ((p_clip_to < 0 || len < p_clip_to) && *(ptr++) != 0) + while ((p_clip_to < 0 || len < p_clip_to) && *(ptr++) != 0) { len++; + } if (len == 0) { resize(0); @@ -211,10 +215,12 @@ void String::copy_from(const CharType &p_char) { } bool String::operator==(const String &p_str) const { - if (length() != p_str.length()) + if (length() != p_str.length()) { return false; - if (empty()) + } + if (empty()) { return true; + } int l = length(); @@ -223,8 +229,9 @@ bool String::operator==(const String &p_str) const { /* Compare char by char */ for (int i = 0; i < l; i++) { - if (src[i] != dst[i]) + if (src[i] != dst[i]) { return false; + } } return true; @@ -255,8 +262,9 @@ String &String::operator+=(const String &p_str) { return *this; } - if (p_str.empty()) + if (p_str.empty()) { return *this; + } int from = length(); @@ -267,8 +275,9 @@ String &String::operator+=(const String &p_str) { set(length(), 0); - for (int i = 0; i < p_str.length(); i++) + for (int i = 0; i < p_str.length(); i++) { dst[from + i] = src[i]; + } return *this; } @@ -287,13 +296,15 @@ String &String::operator+=(CharType p_char) { } String &String::operator+=(const char *p_str) { - if (!p_str || p_str[0] == 0) + if (!p_str || p_str[0] == 0) { return *this; + } int src_len = 0; const char *ptr = p_str; - while (*(ptr++) != 0) + while (*(ptr++) != 0) { src_len++; + } int from = length(); @@ -303,8 +314,9 @@ String &String::operator+=(const char *p_str) { set(length(), 0); - for (int i = 0; i < src_len; i++) + for (int i = 0; i < src_len; i++) { dst[from + i] = p_str[i]; + } return *this; } @@ -320,18 +332,21 @@ void String::operator=(const CharType *p_str) { bool String::operator==(const StrRange &p_str_range) const { int len = p_str_range.len; - if (length() != len) + if (length() != len) { return false; - if (empty()) + } + if (empty()) { return true; + } const CharType *c_str = p_str_range.c_str; const CharType *dst = &operator[](0); /* Compare char by char */ for (int i = 0; i < len; i++) { - if (c_str[i] != dst[i]) + if (c_str[i] != dst[i]) { return false; + } } return true; @@ -341,13 +356,16 @@ bool String::operator==(const char *p_str) const { int len = 0; const char *aux = p_str; - while (*(aux++) != 0) + while (*(aux++) != 0) { len++; + } - if (length() != len) + if (length() != len) { return false; - if (empty()) + } + if (empty()) { return true; + } int l = length(); @@ -355,8 +373,9 @@ bool String::operator==(const char *p_str) const { /* Compare char by char */ for (int i = 0; i < l; i++) { - if (p_str[i] != dst[i]) + if (p_str[i] != dst[i]) { return false; + } } return true; @@ -366,13 +385,16 @@ bool String::operator==(const CharType *p_str) const { int len = 0; const CharType *aux = p_str; - while (*(aux++) != 0) + while (*(aux++) != 0) { len++; + } - if (length() != len) + if (length() != len) { return false; - if (empty()) + } + if (empty()) { return true; + } int l = length(); @@ -380,8 +402,9 @@ bool String::operator==(const CharType *p_str) const { /* Compare char by char */ for (int i = 0; i < l; i++) { - if (p_str[i] != dst[i]) + if (p_str[i] != dst[i]) { return false; + } } return true; @@ -396,10 +419,12 @@ bool String::operator!=(const CharType *p_str) const { } bool String::operator<(const CharType *p_str) const { - if (empty() && p_str[0] == 0) + if (empty() && p_str[0] == 0) { return false; - if (empty()) + } + if (empty()) { return true; + } return is_str_less(c_str(), p_str); } @@ -409,10 +434,12 @@ bool String::operator<=(const String &p_str) const { } bool String::operator<(const char *p_str) const { - if (empty() && p_str[0] == 0) + if (empty() && p_str[0] == 0) { return false; - if (empty()) + } + if (empty()) { return true; + } return is_str_less(c_str(), p_str); } @@ -422,27 +449,31 @@ bool String::operator<(const String &p_str) const { } signed char String::nocasecmp_to(const String &p_str) const { - if (empty() && p_str.empty()) + if (empty() && p_str.empty()) { return 0; - if (empty()) + } + if (empty()) { return -1; - if (p_str.empty()) + } + if (p_str.empty()) { return 1; + } const CharType *that_str = p_str.c_str(); const CharType *this_str = c_str(); while (true) { - if (*that_str == 0 && *this_str == 0) + if (*that_str == 0 && *this_str == 0) { return 0; //we're equal - else if (*this_str == 0) + } else if (*this_str == 0) { return -1; //if this is empty, and the other one is not, then we're less.. I think? - else if (*that_str == 0) + } else if (*that_str == 0) { return 1; //otherwise the other one is smaller.. - else if (_find_upper(*this_str) < _find_upper(*that_str)) //more than + } else if (_find_upper(*this_str) < _find_upper(*that_str)) { //more than return -1; - else if (_find_upper(*this_str) > _find_upper(*that_str)) //less than + } else if (_find_upper(*this_str) > _find_upper(*that_str)) { //less than return 1; + } this_str++; that_str++; @@ -450,27 +481,31 @@ signed char String::nocasecmp_to(const String &p_str) const { } signed char String::casecmp_to(const String &p_str) const { - if (empty() && p_str.empty()) + if (empty() && p_str.empty()) { return 0; - if (empty()) + } + if (empty()) { return -1; - if (p_str.empty()) + } + if (p_str.empty()) { return 1; + } const CharType *that_str = p_str.c_str(); const CharType *this_str = c_str(); while (true) { - if (*that_str == 0 && *this_str == 0) + if (*that_str == 0 && *this_str == 0) { return 0; //we're equal - else if (*this_str == 0) + } else if (*this_str == 0) { return -1; //if this is empty, and the other one is not, then we're less.. I think? - else if (*that_str == 0) + } else if (*that_str == 0) { return 1; //otherwise the other one is smaller.. - else if (*this_str < *that_str) //more than + } else if (*this_str < *that_str) { //more than return -1; - else if (*this_str > *that_str) //less than + } else if (*this_str > *that_str) { //less than return 1; + } this_str++; that_str++; @@ -483,53 +518,63 @@ signed char String::naturalnocasecmp_to(const String &p_str) const { if (this_str && that_str) { while (*this_str == '.' || *that_str == '.') { - if (*this_str++ != '.') + if (*this_str++ != '.') { return 1; - if (*that_str++ != '.') + } + if (*that_str++ != '.') { return -1; - if (!*that_str) + } + if (!*that_str) { return 1; - if (!*this_str) + } + if (!*this_str) { return -1; + } } while (*this_str) { - if (!*that_str) + if (!*that_str) { return 1; - else if (IS_DIGIT(*this_str)) { + } else if (IS_DIGIT(*this_str)) { int64_t this_int, that_int; - if (!IS_DIGIT(*that_str)) + if (!IS_DIGIT(*that_str)) { return -1; + } /* Compare the numbers */ this_int = to_int(this_str, -1, true); that_int = to_int(that_str, -1, true); - if (this_int < that_int) + if (this_int < that_int) { return -1; - else if (this_int > that_int) + } else if (this_int > that_int) { return 1; + } /* Skip */ - while (IS_DIGIT(*this_str)) + while (IS_DIGIT(*this_str)) { this_str++; - while (IS_DIGIT(*that_str)) + } + while (IS_DIGIT(*that_str)) { that_str++; - } else if (IS_DIGIT(*that_str)) + } + } else if (IS_DIGIT(*that_str)) { return 1; - else { - if (_find_upper(*this_str) < _find_upper(*that_str)) //more than + } else { + if (_find_upper(*this_str) < _find_upper(*that_str)) { //more than return -1; - else if (_find_upper(*this_str) > _find_upper(*that_str)) //less than + } else if (_find_upper(*this_str) > _find_upper(*that_str)) { //less than return 1; + } this_str++; that_str++; } } - if (*that_str) + if (*that_str) { return -1; + } } return 0; @@ -546,8 +591,9 @@ String String::capitalize() const { String slice = aux.get_slicec(' ', i); if (slice.length() > 0) { slice[0] = _find_upper(slice[0]); - if (i > 0) + if (i > 0) { cap += " "; + } cap += slice; } } @@ -610,10 +656,12 @@ String String::get_with_code_lines() const { } int String::get_slice_count(String p_splitter) const { - if (empty()) + if (empty()) { return 0; - if (p_splitter.empty()) + } + if (p_splitter.empty()) { return 0; + } int pos = 0; int slices = 1; @@ -627,22 +675,26 @@ int String::get_slice_count(String p_splitter) const { } String String::get_slice(String p_splitter, int p_slice) const { - if (empty() || p_splitter.empty()) + if (empty() || p_splitter.empty()) { return ""; + } int pos = 0; int prev_pos = 0; //int slices=1; - if (p_slice < 0) + if (p_slice < 0) { return ""; - if (find(p_splitter) == -1) + } + if (find(p_splitter) == -1) { return *this; + } int i = 0; while (true) { pos = find(p_splitter, pos); - if (pos == -1) + if (pos == -1) { pos = length(); //reached end + } int from = prev_pos; //int to=pos; @@ -651,8 +703,9 @@ String String::get_slice(String p_splitter, int p_slice) const { return substr(from, pos - from); } - if (pos == length()) //reached end and no find + if (pos == length()) { //reached end and no find break; + } pos += p_splitter.length(); prev_pos = pos; i++; @@ -662,11 +715,13 @@ String String::get_slice(String p_splitter, int p_slice) const { } String String::get_slicec(CharType p_splitter, int p_slice) const { - if (empty()) + if (empty()) { return String(); + } - if (p_slice < 0) + if (p_slice < 0) { return String(); + } const CharType *c = this->ptr(); int i = 0; @@ -693,16 +748,18 @@ Vector<String> String::split_spaces() const { int from = 0; int i = 0; int len = length(); - if (len == 0) + if (len == 0) { return ret; + } bool inside = false; while (true) { bool empty = operator[](i) < 33; - if (i == 0) + if (i == 0) { inside = !empty; + } if (!empty && !inside) { inside = true; @@ -714,8 +771,9 @@ Vector<String> String::split_spaces() const { inside = false; } - if (i == len) + if (i == len) { break; + } i++; } @@ -729,12 +787,13 @@ Vector<String> String::split(const String &p_splitter, bool p_allow_empty, int p while (true) { int end = find(p_splitter, from); - if (end < 0) + if (end < 0) { end = len; + } if (p_allow_empty || (end > from)) { - if (p_maxsplit <= 0) + if (p_maxsplit <= 0) { ret.push_back(substr(from, end - from)); - else { + } else { // Put rest of the string and leave cycle. if (p_maxsplit == ret.size()) { ret.push_back(substr(from, len)); @@ -746,8 +805,9 @@ Vector<String> String::split(const String &p_splitter, bool p_allow_empty, int p } } - if (end == len) + if (end == len) { break; + } from = end + p_splitter.length(); } @@ -796,13 +856,16 @@ Vector<float> String::split_floats(const String &p_splitter, bool p_allow_empty) while (true) { int end = find(p_splitter, from); - if (end < 0) + if (end < 0) { end = len; - if (p_allow_empty || (end > from)) + } + if (p_allow_empty || (end > from)) { ret.push_back(String::to_double(&c_str()[from])); + } - if (end == len) + if (end == len) { break; + } from = end + p_splitter.length(); } @@ -829,8 +892,9 @@ Vector<float> String::split_floats_mk(const Vector<String> &p_splitters, bool p_ ret.push_back(String::to_double(&c_str()[from])); } - if (end == len) + if (end == len) { break; + } from = end + spl_len; } @@ -845,13 +909,16 @@ Vector<int> String::split_ints(const String &p_splitter, bool p_allow_empty) con while (true) { int end = find(p_splitter, from); - if (end < 0) + if (end < 0) { end = len; - if (p_allow_empty || (end > from)) + } + if (p_allow_empty || (end > from)) { ret.push_back(String::to_int(&c_str()[from], end - from)); + } - if (end == len) + if (end == len) { break; + } from = end + p_splitter.length(); } @@ -874,11 +941,13 @@ Vector<int> String::split_ints_mk(const Vector<String> &p_splitters, bool p_allo spl_len = p_splitters[idx].length(); } - if (p_allow_empty || (end > from)) + if (p_allow_empty || (end > from)) { ret.push_back(String::to_int(&c_str()[from], end - from)); + } - if (end == len) + if (end == len) { break; + } from = end + spl_len; } @@ -911,8 +980,9 @@ String String::to_upper() const { for (int i = 0; i < upper.size(); i++) { const CharType s = upper[i]; const CharType t = _find_upper(s); - if (s != t) // avoid copy on write + if (s != t) { // avoid copy on write upper[i] = t; + } } return upper; @@ -924,8 +994,9 @@ String String::to_lower() const { for (int i = 0; i < lower.size(); i++) { const CharType s = lower[i]; const CharType t = _find_lower(s); - if (s != t) // avoid copy on write + if (s != t) { // avoid copy on write lower[i] = t; + } } return lower; @@ -965,8 +1036,9 @@ String String::chr(CharType p_char) { String String::num(double p_num, int p_decimals) { #ifndef NO_USE_STDLIB - if (p_decimals > 16) + if (p_decimals > 16) { p_decimals = 16; + } char fmt[7]; fmt[0] = '%'; @@ -1003,8 +1075,9 @@ String String::num(double p_num, int p_decimals) { bool period = false; int z = 0; while (buf[z]) { - if (buf[z] == '.') + if (buf[z] == '.') { period = true; + } z++; } @@ -1116,8 +1189,9 @@ String String::num_int64(int64_t p_num, int base, bool capitalize_hex) { chars++; } while (n); - if (sign) + if (sign) { chars++; + } String s; s.resize(chars + 1); CharType *c = s.ptrw(); @@ -1135,8 +1209,9 @@ String String::num_int64(int64_t p_num, int base, bool capitalize_hex) { n /= base; } while (n); - if (sign) + if (sign) { c[0] = '-'; + } return s; } @@ -1196,11 +1271,13 @@ String String::num_real(double p_num) { dec_max = dec_max * 10 + 9; digit++; - if ((dec - (float)((int)dec)) < 1e-6) + if ((dec - (float)((int)dec)) < 1e-6) { break; + } - if (digit == decimals) + if (digit == decimals) { break; + } } dec *= 10; @@ -1227,10 +1304,9 @@ String String::num_real(double p_num) { sd = ".0"; } - if (intn == 0) - + if (intn == 0) { s = "0"; - else { + } else { while (intn) { CharType num = '0' + (intn % 10); intn /= 10; @@ -1239,8 +1315,9 @@ String String::num_real(double p_num) { } s = s + sd; - if (neg) + if (neg) { s = "-" + s; + } return s; } @@ -1275,14 +1352,16 @@ String String::num_scientific(double p_num) { } CharString String::ascii(bool p_allow_extended) const { - if (!length()) + if (!length()) { return CharString(); + } CharString cs; cs.resize(size()); - for (int i = 0; i < size(); i++) + for (int i = 0; i < size(); i++) { cs[i] = operator[](i); + } return cs; } @@ -1297,8 +1376,9 @@ String String::utf8(const char *p_utf8, int p_len) { bool String::parse_utf8(const char *p_utf8, int p_len) { #define _UNICERROR(m_err) print_line("Unicode parsing error: " + String(m_err) + ". Is the string valid UTF-8?"); - if (!p_utf8) + if (!p_utf8) { return true; + } String aux; @@ -1310,8 +1390,9 @@ bool String::parse_utf8(const char *p_utf8, int p_len) { bool has_bom = uint8_t(p_utf8[0]) == 0xEF && uint8_t(p_utf8[1]) == 0xBB && uint8_t(p_utf8[2]) == 0xBF; if (has_bom) { //just skip it - if (p_len >= 0) + if (p_len >= 0) { p_len -= 3; + } p_utf8 += 3; } } @@ -1325,19 +1406,19 @@ bool String::parse_utf8(const char *p_utf8, int p_len) { uint8_t c = *ptrtmp >= 0 ? *ptrtmp : uint8_t(256 + *ptrtmp); /* Determine the number of characters in sequence */ - if ((c & 0x80) == 0) + if ((c & 0x80) == 0) { skip = 0; - else if ((c & 0xE0) == 0xC0) + } else if ((c & 0xE0) == 0xC0) { skip = 1; - else if ((c & 0xF0) == 0xE0) + } else if ((c & 0xF0) == 0xE0) { skip = 2; - else if ((c & 0xF8) == 0xF0) + } else if ((c & 0xF8) == 0xF0) { skip = 3; - else if ((c & 0xFC) == 0xF8) + } else if ((c & 0xFC) == 0xF8) { skip = 4; - else if ((c & 0xFE) == 0xFC) + } else if ((c & 0xFE) == 0xFC) { skip = 5; - else { + } else { _UNICERROR("invalid skip"); return true; //invalid utf8 } @@ -1377,19 +1458,19 @@ bool String::parse_utf8(const char *p_utf8, int p_len) { int len = 0; /* Determine the number of characters in sequence */ - if ((*p_utf8 & 0x80) == 0) + if ((*p_utf8 & 0x80) == 0) { len = 1; - else if ((*p_utf8 & 0xE0) == 0xC0) + } else if ((*p_utf8 & 0xE0) == 0xC0) { len = 2; - else if ((*p_utf8 & 0xF0) == 0xE0) + } else if ((*p_utf8 & 0xF0) == 0xE0) { len = 3; - else if ((*p_utf8 & 0xF8) == 0xF0) + } else if ((*p_utf8 & 0xF8) == 0xF0) { len = 4; - else if ((*p_utf8 & 0xFC) == 0xF8) + } else if ((*p_utf8 & 0xFC) == 0xF8) { len = 5; - else if ((*p_utf8 & 0xFE) == 0xFC) + } else if ((*p_utf8 & 0xFE) == 0xFC) { len = 6; - else { + } else { _UNICERROR("invalid len"); return true; //invalid UTF8 @@ -1410,9 +1491,9 @@ bool String::parse_utf8(const char *p_utf8, int p_len) { uint32_t unichar = 0; - if (len == 1) + if (len == 1) { unichar = *p_utf8; - else { + } else { unichar = (0xFF >> (len + 1)) & *p_utf8; for (int i = 1; i < len; i++) { @@ -1443,16 +1524,17 @@ bool String::parse_utf8(const char *p_utf8, int p_len) { CharString String::utf8() const { int l = length(); - if (!l) + if (!l) { return CharString(); + } const CharType *d = &operator[](0); int fl = 0; for (int i = 0; i < l; i++) { uint32_t c = d[i]; - if (c <= 0x7f) // 7 bits. + if (c <= 0x7f) { // 7 bits. fl += 1; - else if (c <= 0x7ff) { // 11 bits + } else if (c <= 0x7ff) { // 11 bits fl += 2; } else if (c <= 0xffff) { // 16 bits fl += 3; @@ -1479,9 +1561,9 @@ CharString String::utf8() const { for (int i = 0; i < l; i++) { uint32_t c = d[i]; - if (c <= 0x7f) // 7 bits. + if (c <= 0x7f) { // 7 bits. APPEND_CHAR(c); - else if (c <= 0x7ff) { // 11 bits + } else if (c <= 0x7ff) { // 11 bits APPEND_CHAR(uint32_t(0xc0 | ((c >> 6) & 0x1f))); // Top 5 bits. APPEND_CHAR(uint32_t(0x80 | (c & 0x3f))); // Bottom 6 bits. @@ -1537,15 +1619,17 @@ String::String(const CharType *p_str, int p_clip_to_len) { } String::String(const StrRange &p_range) { - if (!p_range.c_str) + if (!p_range.c_str) { return; + } copy_from(p_range.c_str, p_range.len); } int String::hex_to_int(bool p_with_prefix) const { - if (p_with_prefix && length() < 3) + if (p_with_prefix && length() < 3) { return 0; + } const CharType *s = ptr(); @@ -1556,8 +1640,9 @@ int String::hex_to_int(bool p_with_prefix) const { } if (p_with_prefix) { - if (s[0] != '0' || s[1] != 'x') + if (s[0] != '0' || s[1] != 'x') { return 0; + } s += 2; } @@ -1584,8 +1669,9 @@ int String::hex_to_int(bool p_with_prefix) const { } int64_t String::hex_to_int64(bool p_with_prefix) const { - if (p_with_prefix && length() < 3) + if (p_with_prefix && length() < 3) { return 0; + } const CharType *s = ptr(); @@ -1596,8 +1682,9 @@ int64_t String::hex_to_int64(bool p_with_prefix) const { } if (p_with_prefix) { - if (s[0] != '0' || s[1] != 'x') + if (s[0] != '0' || s[1] != 'x') { return 0; + } s += 2; } @@ -1624,8 +1711,9 @@ int64_t String::hex_to_int64(bool p_with_prefix) const { } int64_t String::bin_to_int64(bool p_with_prefix) const { - if (p_with_prefix && length() < 3) + if (p_with_prefix && length() < 3) { return 0; + } const CharType *s = ptr(); @@ -1636,8 +1724,9 @@ int64_t String::bin_to_int64(bool p_with_prefix) const { } if (p_with_prefix) { - if (s[0] != '0' || s[1] != 'b') + if (s[0] != '0' || s[1] != 'b') { return 0; + } s += 2; } @@ -1662,8 +1751,9 @@ int64_t String::bin_to_int64(bool p_with_prefix) const { } int String::to_int() const { - if (length() == 0) + if (length() == 0) { return 0; + } int to = (find(".") >= 0) ? find(".") : length(); @@ -1686,8 +1776,9 @@ int String::to_int() const { } int64_t String::to_int64() const { - if (length() == 0) + if (length() == 0) { return 0; + } int to = (find(".") >= 0) ? find(".") : length(); @@ -1711,11 +1802,12 @@ int64_t String::to_int64() const { int String::to_int(const char *p_str, int p_len) { int to = 0; - if (p_len >= 0) + if (p_len >= 0) { to = p_len; - else { - while (p_str[to] != 0 && p_str[to] != '.') + } else { + while (p_str[to] != 0 && p_str[to] != '.') { to++; + } } int integer = 0; @@ -1730,8 +1822,9 @@ int String::to_int(const char *p_str, int p_len) { } else if (c == '-' && integer == 0) { sign = -sign; - } else if (c != ' ') + } else if (c != ' ') { break; + } } return integer * sign; @@ -1743,8 +1836,9 @@ bool String::is_numeric() const { }; int s = 0; - if (operator[](0) == '-') + if (operator[](0) == '-') { ++s; + } bool dot = false; for (int i = s; i < length(); i++) { CharType c = operator[](i); @@ -1995,8 +2089,9 @@ double String::to_double(const CharType *p_str, const CharType **r_end) { } int64_t String::to_int(const CharType *p_str, int p_len, bool p_clamp) { - if (p_len == 0 || !p_str[0]) + if (p_len == 0 || !p_str[0]) { return 0; + } ///@todo make more exact so saving and loading does not lose precision int64_t integer = 0; @@ -2058,8 +2153,9 @@ int64_t String::to_int(const CharType *p_str, int p_len, bool p_clamp) { } double String::to_double() const { - if (empty()) + if (empty()) { return 0; + } #ifndef NO_USE_STDLIB return built_in_strtod<CharType>(c_str()); //return wcstod(c_str(),nullptr ); DOES NOT WORK ON ANDROID :( @@ -2086,24 +2182,27 @@ uint32_t String::hash(const char *p_cstr) { uint32_t hashv = 5381; uint32_t c; - while ((c = *p_cstr++)) + while ((c = *p_cstr++)) { hashv = ((hashv << 5) + hashv) + c; /* hash * 33 + c */ + } return hashv; } uint32_t String::hash(const char *p_cstr, int p_len) { uint32_t hashv = 5381; - for (int i = 0; i < p_len; i++) + for (int i = 0; i < p_len; i++) { hashv = ((hashv << 5) + hashv) + p_cstr[i]; /* hash * 33 + c */ + } return hashv; } uint32_t String::hash(const CharType *p_cstr, int p_len) { uint32_t hashv = 5381; - for (int i = 0; i < p_len; i++) + for (int i = 0; i < p_len; i++) { hashv = ((hashv << 5) + hashv) + p_cstr[i]; /* hash * 33 + c */ + } return hashv; } @@ -2112,8 +2211,9 @@ uint32_t String::hash(const CharType *p_cstr) { uint32_t hashv = 5381; uint32_t c; - while ((c = *p_cstr++)) + while ((c = *p_cstr++)) { hashv = ((hashv << 5) + hashv) + c; /* hash * 33 + c */ + } return hashv; } @@ -2125,8 +2225,9 @@ uint32_t String::hash() const { uint32_t hashv = 5381; uint32_t c; - while ((c = *chr++)) + while ((c = *chr++)) { hashv = ((hashv << 5) + hashv) + c; /* hash * 33 + c */ + } return hashv; } @@ -2138,8 +2239,9 @@ uint64_t String::hash64() const { uint64_t hashv = 5381; uint64_t c; - while ((c = *chr++)) + while ((c = *chr++)) { hashv = ((hashv << 5) + hashv) + c; /* hash * 33 + c */ + } return hashv; } @@ -2206,29 +2308,35 @@ Vector<uint8_t> String::sha256_buffer() const { } String String::insert(int p_at_pos, const String &p_string) const { - if (p_at_pos < 0) + if (p_at_pos < 0) { return *this; + } - if (p_at_pos > length()) + if (p_at_pos > length()) { p_at_pos = length(); + } String pre; - if (p_at_pos > 0) + if (p_at_pos > 0) { pre = substr(0, p_at_pos); + } String post; - if (p_at_pos < length()) + if (p_at_pos < length()) { post = substr(p_at_pos, length() - p_at_pos); + } return pre + p_string + post; } String String::substr(int p_from, int p_chars) const { - if (p_chars == -1) + if (p_chars == -1) { p_chars = length() - p_from; + } - if (empty() || p_from < 0 || p_from >= length() || p_chars <= 0) + if (empty() || p_from < 0 || p_from >= length() || p_chars <= 0) { return ""; + } if ((p_from + p_chars) > length()) { p_chars = length() - p_from; @@ -2256,15 +2364,17 @@ int String::find_last(const String &p_str) const { } int String::find(const String &p_str, int p_from) const { - if (p_from < 0) + if (p_from < 0) { return -1; + } const int src_len = p_str.length(); const int len = length(); - if (src_len == 0 || len == 0) + if (src_len == 0 || len == 0) { return -1; // won't find anything! + } const CharType *src = c_str(); const CharType *str = p_str.c_str(); @@ -2285,27 +2395,31 @@ int String::find(const String &p_str, int p_from) const { } } - if (found) + if (found) { return i; + } } return -1; } int String::find(const char *p_str, int p_from) const { - if (p_from < 0) + if (p_from < 0) { return -1; + } const int len = length(); - if (len == 0) + if (len == 0) { return -1; // won't find anything! + } const CharType *src = c_str(); int src_len = 0; - while (p_str[src_len] != '\0') + while (p_str[src_len] != '\0') { src_len++; + } if (src_len == 1) { const char needle = p_str[0]; @@ -2333,8 +2447,9 @@ int String::find(const char *p_str, int p_from) const { } } - if (found) + if (found) { return i; + } } } @@ -2346,18 +2461,21 @@ int String::find_char(const CharType &p_char, int p_from) const { } int String::findmk(const Vector<String> &p_keys, int p_from, int *r_key) const { - if (p_from < 0) + if (p_from < 0) { return -1; - if (p_keys.size() == 0) + } + if (p_keys.size() == 0) { return -1; + } //int src_len=p_str.length(); const String *keys = &p_keys[0]; int key_count = p_keys.size(); int len = length(); - if (len == 0) + if (len == 0) { return -1; // won't find anything! + } const CharType *src = c_str(); @@ -2365,8 +2483,9 @@ int String::findmk(const Vector<String> &p_keys, int p_from, int *r_key) const { bool found = true; for (int k = 0; k < key_count; k++) { found = true; - if (r_key) + if (r_key) { *r_key = k; + } const CharType *cmp = keys[k].c_str(); int l = keys[k].length(); @@ -2383,25 +2502,29 @@ int String::findmk(const Vector<String> &p_keys, int p_from, int *r_key) const { break; } } - if (found) + if (found) { break; + } } - if (found) + if (found) { return i; + } } return -1; } int String::findn(const String &p_str, int p_from) const { - if (p_from < 0) + if (p_from < 0) { return -1; + } int src_len = p_str.length(); - if (src_len == 0 || length() == 0) + if (src_len == 0 || length() == 0) { return -1; // won't find anything! + } const CharType *srcd = c_str(); @@ -2424,8 +2547,9 @@ int String::findn(const String &p_str, int p_from) const { } } - if (found) + if (found) { return i; + } } return -1; @@ -2434,20 +2558,23 @@ int String::findn(const String &p_str, int p_from) const { int String::rfind(const String &p_str, int p_from) const { // establish a limit int limit = length() - p_str.length(); - if (limit < 0) + if (limit < 0) { return -1; + } // establish a starting point - if (p_from < 0) + if (p_from < 0) { p_from = limit; - else if (p_from > limit) + } else if (p_from > limit) { p_from = limit; + } int src_len = p_str.length(); int len = length(); - if (src_len == 0 || len == 0) + if (src_len == 0 || len == 0) { return -1; // won't find anything! + } const CharType *src = c_str(); @@ -2467,8 +2594,9 @@ int String::rfind(const String &p_str, int p_from) const { } } - if (found) + if (found) { return i; + } } return -1; @@ -2477,20 +2605,23 @@ int String::rfind(const String &p_str, int p_from) const { int String::rfindn(const String &p_str, int p_from) const { // establish a limit int limit = length() - p_str.length(); - if (limit < 0) + if (limit < 0) { return -1; + } // establish a starting point - if (p_from < 0) + if (p_from < 0) { p_from = limit; - else if (p_from > limit) + } else if (p_from > limit) { p_from = limit; + } int src_len = p_str.length(); int len = length(); - if (src_len == 0 || len == 0) + if (src_len == 0 || len == 0) { return -1; // won't find anything! + } const CharType *src = c_str(); @@ -2513,8 +2644,9 @@ int String::rfindn(const String &p_str, int p_from) const { } } - if (found) + if (found) { return i; + } } return -1; @@ -2522,26 +2654,30 @@ int String::rfindn(const String &p_str, int p_from) const { bool String::ends_with(const String &p_string) const { int pos = find_last(p_string); - if (pos == -1) + if (pos == -1) { return false; + } return pos + p_string.length() == length(); } bool String::begins_with(const String &p_string) const { - if (p_string.length() > length()) + if (p_string.length() > length()) { return false; + } int l = p_string.length(); - if (l == 0) + if (l == 0) { return true; + } const CharType *src = &p_string[0]; const CharType *str = &operator[](0); int i = 0; for (; i < l; i++) { - if (src[i] != str[i]) + if (src[i] != str[i]) { return false; + } } // only if i == l the p_string matches the beginning @@ -2550,15 +2686,17 @@ bool String::begins_with(const String &p_string) const { bool String::begins_with(const char *p_string) const { int l = length(); - if (l == 0 || !p_string) + if (l == 0 || !p_string) { return false; + } const CharType *str = &operator[](0); int i = 0; while (*p_string && i < l) { - if (*p_string != str[i]) + if (*p_string != str[i]) { return false; + } i++; p_string++; } @@ -2720,15 +2858,17 @@ static bool _wildcard_match(const CharType *p_pattern, const CharType *p_string, } bool String::match(const String &p_wildcard) const { - if (!p_wildcard.length() || !length()) + if (!p_wildcard.length() || !length()) { return false; + } return _wildcard_match(p_wildcard.c_str(), c_str(), true); } bool String::matchn(const String &p_wildcard) const { - if (!p_wildcard.length() || !length()) + if (!p_wildcard.length() || !length()) { return false; + } return _wildcard_match(p_wildcard.c_str(), c_str(), false); } @@ -2832,8 +2972,9 @@ String String::replace(const char *p_key, const char *p_with) const { new_string += substr(search_from, result - search_from); new_string += p_with; int k = 0; - while (p_key[k] != '\0') + while (p_key[k] != '\0') { k++; + } search_from = result + k; } @@ -2882,29 +3023,35 @@ String String::repeat(int p_count) const { new_string.resize(length() * p_count + 1); - for (int i = 0; i < p_count; i++) - for (int j = 0; j < length(); j++) + for (int i = 0; i < p_count; i++) { + for (int j = 0; j < length(); j++) { new_string[i * length() + j] = src[j]; + } + } return new_string; } String String::left(int p_pos) const { - if (p_pos <= 0) + if (p_pos <= 0) { return ""; + } - if (p_pos >= length()) + if (p_pos >= length()) { return *this; + } return substr(0, p_pos); } String String::right(int p_pos) const { - if (p_pos >= length()) + if (p_pos >= length()) { return ""; + } - if (p_pos <= 0) + if (p_pos <= 0) { return *this; + } return substr(p_pos, (length() - p_pos)); } @@ -2925,8 +3072,9 @@ String String::dedent() const { for (int i = 0; i < length(); i++) { CharType c = operator[](i); if (c == '\n') { - if (has_text) + if (has_text) { new_string += substr(indent_stop, i - indent_stop); + } new_string += "\n"; has_text = false; line_start = i + 1; @@ -2942,14 +3090,16 @@ String String::dedent() const { } if (has_indent && indent_stop < 0) { int j = i - line_start; - if (j >= indent.length() || c != indent[j]) + if (j >= indent.length() || c != indent[j]) { indent_stop = i; + } } } } - if (has_text) + if (has_text) { new_string += substr(indent_stop, length() - indent_stop); + } return new_string; } @@ -2960,24 +3110,27 @@ String String::strip_edges(bool left, bool right) const { if (left) { for (int i = 0; i < len; i++) { - if (operator[](i) <= 32) + if (operator[](i) <= 32) { beg++; - else + } else { break; + } } } if (right) { for (int i = (int)(len - 1); i >= 0; i--) { - if (operator[](i) <= 32) + if (operator[](i) <= 32) { end--; - else + } else { break; + } } } - if (beg == 0 && end == len) + if (beg == 0 && end == len) { return *this; + } return substr(beg, end - beg); } @@ -2986,8 +3139,9 @@ String String::strip_escapes() const { String new_string; for (int i = 0; i < length(); i++) { // Escape characters on first page of the ASCII table, before 32 (Space). - if (operator[](i) < 32) + if (operator[](i) < 32) { continue; + } new_string += operator[](i); } @@ -2999,12 +3153,14 @@ String String::lstrip(const String &p_chars) const { int beg; for (beg = 0; beg < len; beg++) { - if (p_chars.find_char(get(beg)) == -1) + if (p_chars.find_char(get(beg)) == -1) { break; + } } - if (beg == 0) + if (beg == 0) { return *this; + } return substr(beg, len - beg); } @@ -3014,12 +3170,14 @@ String String::rstrip(const String &p_chars) const { int end; for (end = len - 1; end >= 0; end--) { - if (p_chars.find_char(get(end)) == -1) + if (p_chars.find_char(get(end)) == -1) { break; + } } - if (end == len - 1) + if (end == len - 1) { return *this; + } return substr(0, end + 1); } @@ -3041,8 +3199,9 @@ String String::simplify_path() const { s = s.substr(1, s.length() - 1); } else { int p = s.find(":/"); - if (p == -1) + if (p == -1) { p = s.find(":\\"); + } if (p != -1 && p < s.find("/")) { drive = s.substr(0, p + 2); s = s.substr(p + 2, s.length()); @@ -3052,10 +3211,11 @@ String String::simplify_path() const { s = s.replace("\\", "/"); while (true) { // in case of using 2 or more slash String compare = s.replace("//", "/"); - if (s == compare) + if (s == compare) { break; - else + } else { s = compare; + } } Vector<String> dirs = s.split("/", false); @@ -3079,8 +3239,9 @@ String String::simplify_path() const { s = ""; for (int i = 0; i < dirs.size(); i++) { - if (i > 0) + if (i > 0) { s += "/"; + } s += dirs[i]; } @@ -3088,12 +3249,13 @@ String String::simplify_path() const { } static int _humanize_digits(int p_num) { - if (p_num < 100) + if (p_num < 100) { return 2; - else if (p_num < 1024) + } else if (p_num < 1024) { return 1; - else + } else { return 0; + } } String String::humanize_size(uint64_t p_size) { @@ -3121,32 +3283,36 @@ String String::humanize_size(uint64_t p_size) { } bool String::is_abs_path() const { - if (length() > 1) + if (length() > 1) { return (operator[](0) == '/' || operator[](0) == '\\' || find(":/") != -1 || find(":\\") != -1); - else if ((length()) == 1) + } else if ((length()) == 1) { return (operator[](0) == '/' || operator[](0) == '\\'); - else + } else { return false; + } } bool String::is_valid_identifier() const { int len = length(); - if (len == 0) + if (len == 0) { return false; + } const wchar_t *str = &operator[](0); for (int i = 0; i < len; i++) { if (i == 0) { - if (str[0] >= '0' && str[0] <= '9') + if (str[0] >= '0' && str[0] <= '9') { return false; // no start with number plz + } } bool valid_char = (str[i] >= '0' && str[i] <= '9') || (str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z') || str[i] == '_'; - if (!valid_char) + if (!valid_char) { return false; + } } return true; @@ -3296,11 +3462,11 @@ String String::xml_escape(bool p_escape_quotes) const { str = str.replace("\"", """); } /* - for (int i=1;i<32;i++) { +for (int i=1;i<32;i++) { - char chr[2]={i,0}; - str=str.replace(chr,"&#"+String::num(i)+";"); - }*/ + char chr[2]={i,0}; + str=str.replace(chr,"&#"+String::num(i)+";"); +}*/ return str; } @@ -3331,37 +3497,45 @@ static _FORCE_INLINE_ int _xml_unescape(const CharType *p_src, int p_src_len, Ch c |= ct; } - if (p_dst) + if (p_dst) { *p_dst = c; + } } else if (p_src_len >= 4 && p_src[1] == 'g' && p_src[2] == 't' && p_src[3] == ';') { - if (p_dst) + if (p_dst) { *p_dst = '>'; + } eat = 4; } else if (p_src_len >= 4 && p_src[1] == 'l' && p_src[2] == 't' && p_src[3] == ';') { - if (p_dst) + if (p_dst) { *p_dst = '<'; + } eat = 4; } else if (p_src_len >= 5 && p_src[1] == 'a' && p_src[2] == 'm' && p_src[3] == 'p' && p_src[4] == ';') { - if (p_dst) + if (p_dst) { *p_dst = '&'; + } eat = 5; } else if (p_src_len >= 6 && p_src[1] == 'q' && p_src[2] == 'u' && p_src[3] == 'o' && p_src[4] == 't' && p_src[5] == ';') { - if (p_dst) + if (p_dst) { *p_dst = '"'; + } eat = 6; } else if (p_src_len >= 6 && p_src[1] == 'a' && p_src[2] == 'p' && p_src[3] == 'o' && p_src[4] == 's' && p_src[5] == ';') { - if (p_dst) + if (p_dst) { *p_dst = '\''; + } eat = 6; } else { - if (p_dst) + if (p_dst) { *p_dst = *p_src; + } eat = 1; } - if (p_dst) + if (p_dst) { p_dst++; + } len++; p_src += eat; @@ -3384,8 +3558,9 @@ String String::xml_unescape() const { String str; int l = length(); int len = _xml_unescape(c_str(), l, nullptr); - if (len == 0) + if (len == 0) { return String(); + } str.resize(len + 1); _xml_unescape(c_str(), l, str.ptrw()); str[len] = 0; @@ -3426,8 +3601,9 @@ String String::pad_zeros(int p_digits) const { end = s.length(); } - if (end == 0) + if (end == 0) { return s; + } int begin = 0; @@ -3435,8 +3611,9 @@ String String::pad_zeros(int p_digits) const { begin++; } - if (begin >= end) + if (begin >= end) { return s; + } while (end - begin < p_digits) { s = s.insert(begin, "0"); @@ -3465,16 +3642,19 @@ String String::trim_suffix(const String &p_suffix) const { bool String::is_valid_integer() const { int len = length(); - if (len == 0) + if (len == 0) { return false; + } int from = 0; - if (len != 1 && (operator[](0) == '+' || operator[](0) == '-')) + if (len != 1 && (operator[](0) == '+' || operator[](0) == '-')) { from++; + } for (int i = from; i < len; i++) { - if (operator[](i) < '0' || operator[](i) > '9') + if (operator[](i) < '0' || operator[](i) > '9') { return false; // no start with number plz + } } return true; @@ -3483,16 +3663,19 @@ bool String::is_valid_integer() const { bool String::is_valid_hex_number(bool p_with_prefix) const { int len = length(); - if (len == 0) + if (len == 0) { return false; + } int from = 0; - if (len != 1 && (operator[](0) == '+' || operator[](0) == '-')) + if (len != 1 && (operator[](0) == '+' || operator[](0) == '-')) { from++; + } if (p_with_prefix) { - if (len < 3) + if (len < 3) { return false; + } if (operator[](from) != '0' || operator[](from + 1) != 'x') { return false; } @@ -3501,8 +3684,9 @@ bool String::is_valid_hex_number(bool p_with_prefix) const { for (int i = from; i < len; i++) { CharType c = operator[](i); - if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) + if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) { continue; + } return false; } @@ -3512,8 +3696,9 @@ bool String::is_valid_hex_number(bool p_with_prefix) const { bool String::is_valid_float() const { int len = length(); - if (len == 0) + if (len == 0) { return false; + } int from = 0; if (operator[](0) == '+' || operator[](0) == '-') { @@ -3528,18 +3713,20 @@ bool String::is_valid_float() const { for (int i = from; i < len; i++) { if (operator[](i) >= '0' && operator[](i) <= '9') { - if (exponent_found) + if (exponent_found) { exponent_values_found = true; - else + } else { numbers_found = true; + } } else if (numbers_found && !exponent_found && operator[](i) == 'e') { exponent_found = true; } else if (!period_found && !exponent_found && operator[](i) == '.') { period_found = true; } else if ((operator[](i) == '-' || operator[](i) == '+') && exponent_found && !exponent_values_found && !sign_found) { sign_found = true; - } else + } else { return false; // no start with number plz + } } return numbers_found; @@ -3550,19 +3737,22 @@ String String::path_to_file(const String &p_path) const { String src = this->replace("\\", "/"); String dst = p_path.replace("\\", "/").get_base_dir(); String rel = src.path_to(dst); - if (rel == dst) // failed + if (rel == dst) { // failed return p_path; - else + } else { return rel + p_path.get_file(); + } } String String::path_to(const String &p_path) const { String src = this->replace("\\", "/"); String dst = p_path.replace("\\", "/"); - if (!src.ends_with("/")) + if (!src.ends_with("/")) { src += "/"; - if (!dst.ends_with("/")) + } + if (!dst.ends_with("/")) { dst += "/"; + } String base; @@ -3583,8 +3773,9 @@ String String::path_to(const String &p_path) const { String src_begin = src.get_slicec('/', 0); String dst_begin = dst.get_slicec('/', 0); - if (src_begin != dst_begin) + if (src_begin != dst_begin) { return p_path; //impossible to do this + } base = src_begin; src = src.substr(src_begin.length(), src.length()); @@ -3599,12 +3790,15 @@ String String::path_to(const String &p_path) const { int common_parent = 0; while (true) { - if (src_dirs.size() == common_parent) + if (src_dirs.size() == common_parent) { break; - if (dst_dirs.size() == common_parent) + } + if (dst_dirs.size() == common_parent) { break; - if (src_dirs[common_parent] != dst_dirs[common_parent]) + } + if (src_dirs[common_parent] != dst_dirs[common_parent]) { break; + } common_parent++; } @@ -3620,8 +3814,9 @@ String String::path_to(const String &p_path) const { dir += dst_dirs[i] + "/"; } - if (dir.length() == 0) + if (dir.length() == 0) { dir = "./"; + } return dir; } @@ -3647,29 +3842,35 @@ bool String::is_valid_ip_address() const { Vector<String> ip = split(":"); for (int i = 0; i < ip.size(); i++) { String n = ip[i]; - if (n.empty()) + if (n.empty()) { continue; + } if (n.is_valid_hex_number(false)) { int nint = n.hex_to_int(false); - if (nint < 0 || nint > 0xffff) + if (nint < 0 || nint > 0xffff) { return false; + } continue; }; - if (!n.is_valid_ip_address()) + if (!n.is_valid_ip_address()) { return false; + } }; } else { Vector<String> ip = split("."); - if (ip.size() != 4) + if (ip.size() != 4) { return false; + } for (int i = 0; i < ip.size(); i++) { String n = ip[i]; - if (!n.is_valid_integer()) + if (!n.is_valid_integer()) { return false; + } int val = n.to_int(); - if (val < 0 || val > 255) + if (val < 0 || val > 255) { return false; + } } }; @@ -3702,33 +3903,38 @@ String String::get_base_dir() const { } int sep = MAX(rs.find_last("/"), rs.find_last("\\")); - if (sep == -1) + if (sep == -1) { return base; + } return base + rs.substr(0, sep); } String String::get_file() const { int sep = MAX(find_last("/"), find_last("\\")); - if (sep == -1) + if (sep == -1) { return *this; + } return substr(sep + 1, length()); } String String::get_extension() const { int pos = find_last("."); - if (pos < 0 || pos < MAX(find_last("/"), find_last("\\"))) + if (pos < 0 || pos < MAX(find_last("/"), find_last("\\"))) { return ""; + } return substr(pos + 1, length()); } String String::plus_file(const String &p_file) const { - if (empty()) + if (empty()) { return p_file; - if (operator[](length() - 1) == '/' || (p_file.size() > 0 && p_file.operator[](0) == '/')) + } + if (operator[](length() - 1) == '/' || (p_file.size() > 0 && p_file.operator[](0) == '/')) { return *this + p_file; + } return *this + "/" + p_file; } @@ -3763,21 +3969,23 @@ String String::percent_decode() const { uint8_t a = LOWERCASE(cs[i + 1]); uint8_t b = LOWERCASE(cs[i + 2]); - if (a >= '0' && a <= '9') + if (a >= '0' && a <= '9') { c = (a - '0') << 4; - else if (a >= 'a' && a <= 'f') + } else if (a >= 'a' && a <= 'f') { c = (a - 'a' + 10) << 4; - else + } else { continue; + } uint8_t d = 0; - if (b >= '0' && b <= '9') + if (b >= '0' && b <= '9') { d = (b - '0'); - else if (b >= 'a' && b <= 'f') + } else if (b >= 'a' && b <= 'f') { d = (b - 'a' + 10); - else + } else { continue; + } c += d; i += 2; } @@ -3802,8 +4010,9 @@ String String::property_name_encode() const { String String::get_basename() const { int pos = find_last("."); - if (pos < 0 || pos < MAX(find_last("/"), find_last("\\"))) + if (pos < 0 || pos < MAX(find_last("/"), find_last("\\"))) { return *this; + } return substr(0, pos); } @@ -3829,8 +4038,9 @@ String String::rpad(int min_length, const String &character) const { String s = *this; int padding = min_length - s.length(); if (padding > 0) { - for (int i = 0; i < padding; i++) + for (int i = 0; i < padding; i++) { s = s + character; + } } return s; @@ -3841,8 +4051,9 @@ String String::lpad(int min_length, const String &character) const { String s = *this; int padding = min_length - s.length(); if (padding > 0) { - for (int i = 0; i < padding; i++) + for (int i = 0; i < padding; i++) { s = character + s; + } } return s; diff --git a/core/ustring.h b/core/ustring.h index 34f9c18bad..5b13a1c704 100644 --- a/core/ustring.h +++ b/core/ustring.h @@ -51,8 +51,9 @@ class CharProxy { public: _FORCE_INLINE_ operator T() const { - if (unlikely(_index == _cowdata.size())) + if (unlikely(_index == _cowdata.size())) { return _null; + } return _cowdata.get(_index); } @@ -83,8 +84,9 @@ public: _FORCE_INLINE_ char get(int p_index) const { return _cowdata.get(p_index); } _FORCE_INLINE_ void set(int p_index, const char &p_elem) { _cowdata.set(p_index, p_elem); } _FORCE_INLINE_ const char &operator[](int p_index) const { - if (unlikely(p_index == _cowdata.size())) + if (unlikely(p_index == _cowdata.size())) { return _null; + } return _cowdata.get(p_index); } @@ -151,8 +153,9 @@ public: Error resize(int p_size) { return _cowdata.resize(p_size); } _FORCE_INLINE_ const CharType &operator[](int p_index) const { - if (unlikely(p_index == _cowdata.size())) + if (unlikely(p_index == _cowdata.size())) { return _null; + } return _cowdata.get(p_index); } @@ -388,16 +391,17 @@ struct NaturalNoCaseComparator { template <typename L, typename R> _FORCE_INLINE_ bool is_str_less(const L *l_ptr, const R *r_ptr) { while (true) { - if (*l_ptr == 0 && *r_ptr == 0) + if (*l_ptr == 0 && *r_ptr == 0) { return false; - else if (*l_ptr == 0) + } else if (*l_ptr == 0) { return true; - else if (*r_ptr == 0) + } else if (*r_ptr == 0) { return false; - else if (*l_ptr < *r_ptr) + } else if (*l_ptr < *r_ptr) { return true; - else if (*l_ptr > *r_ptr) + } else if (*l_ptr > *r_ptr) { return false; + } l_ptr++; r_ptr++; diff --git a/core/variant.cpp b/core/variant.cpp index 1098d031e5..62d710e493 100644 --- a/core/variant.cpp +++ b/core/variant.cpp @@ -182,10 +182,12 @@ String Variant::get_type_name(Variant::Type p_type) { } bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { - if (p_type_from == p_type_to) + if (p_type_from == p_type_to) { return true; - if (p_type_to == NIL && p_type_from != NIL) //nil can convert to anything + } + if (p_type_to == NIL && p_type_from != NIL) { //nil can convert to anything return true; + } if (p_type_from == NIL) { return (p_type_to == OBJECT); @@ -465,16 +467,18 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { if (valid_types) { int i = 0; while (valid_types[i] != NIL) { - if (p_type_from == valid_types[i]) + if (p_type_from == valid_types[i]) { return true; + } i++; } } else if (invalid_types) { int i = 0; while (invalid_types[i] != NIL) { - if (p_type_from == invalid_types[i]) + if (p_type_from == invalid_types[i]) { return false; + } i++; } @@ -485,10 +489,12 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { } bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type_to) { - if (p_type_from == p_type_to) + if (p_type_from == p_type_to) { return true; - if (p_type_to == NIL && p_type_from != NIL) //nil can convert to anything + } + if (p_type_to == NIL && p_type_from != NIL) { //nil can convert to anything return true; + } if (p_type_from == NIL) { return (p_type_to == OBJECT); @@ -768,8 +774,9 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type if (valid_types) { int i = 0; while (valid_types[i] != NIL) { - if (p_type_from == valid_types[i]) + if (p_type_from == valid_types[i]) { return true; + } i++; } } @@ -778,8 +785,9 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type } bool Variant::operator==(const Variant &p_variant) const { - if (type != p_variant.type) //evaluation of operator== needs to be more strict + if (type != p_variant.type) { //evaluation of operator== needs to be more strict return false; + } bool v; Variant r; evaluate(OP_EQUAL, *this, p_variant, r, v); @@ -787,8 +795,9 @@ bool Variant::operator==(const Variant &p_variant) const { } bool Variant::operator!=(const Variant &p_variant) const { - if (type != p_variant.type) //evaluation of operator== needs to be more strict + if (type != p_variant.type) { //evaluation of operator== needs to be more strict return true; + } bool v; Variant r; evaluate(OP_NOT_EQUAL, *this, p_variant, r, v); @@ -796,8 +805,9 @@ bool Variant::operator!=(const Variant &p_variant) const { } bool Variant::operator<(const Variant &p_variant) const { - if (type != p_variant.type) //if types differ, then order by type first + if (type != p_variant.type) { //if types differ, then order by type first return type < p_variant.type; + } bool v; Variant r; evaluate(OP_LESS, *this, p_variant, r, v); @@ -1678,14 +1688,16 @@ String Variant::stringify(List<const void *> &stack) const { String mtx("("); for (int i = 0; i < 3; i++) { - if (i != 0) + if (i != 0) { mtx += ", "; + } mtx += "("; for (int j = 0; j < 3; j++) { - if (j != 0) + if (j != 0) { mtx += ", "; + } mtx += Variant(mat3.elements[i][j]).operator String(); } @@ -1729,8 +1741,9 @@ String Variant::stringify(List<const void *> &stack) const { pairs.sort(); for (int i = 0; i < pairs.size(); i++) { - if (i > 0) + if (i > 0) { str += ", "; + } str += pairs[i].key + ":" + pairs[i].value; } str += "}"; @@ -1741,8 +1754,9 @@ String Variant::stringify(List<const void *> &stack) const { Vector<Vector2> vec = operator Vector<Vector2>(); String str("["); for (int i = 0; i < vec.size(); i++) { - if (i > 0) + if (i > 0) { str += ", "; + } str = str + Variant(vec[i]); } str += "]"; @@ -1752,8 +1766,9 @@ String Variant::stringify(List<const void *> &stack) const { Vector<Vector3> vec = operator Vector<Vector3>(); String str("["); for (int i = 0; i < vec.size(); i++) { - if (i > 0) + if (i > 0) { str += ", "; + } str = str + Variant(vec[i]); } str += "]"; @@ -1763,8 +1778,9 @@ String Variant::stringify(List<const void *> &stack) const { Vector<String> vec = operator Vector<String>(); String str("["); for (int i = 0; i < vec.size(); i++) { - if (i > 0) + if (i > 0) { str += ", "; + } str = str + vec[i]; } str += "]"; @@ -1774,8 +1790,9 @@ String Variant::stringify(List<const void *> &stack) const { Vector<int32_t> vec = operator Vector<int32_t>(); String str("["); for (int i = 0; i < vec.size(); i++) { - if (i > 0) + if (i > 0) { str += ", "; + } str = str + itos(vec[i]); } str += "]"; @@ -1785,8 +1802,9 @@ String Variant::stringify(List<const void *> &stack) const { Vector<int64_t> vec = operator Vector<int64_t>(); String str("["); for (int i = 0; i < vec.size(); i++) { - if (i > 0) + if (i > 0) { str += ", "; + } str = str + itos(vec[i]); } str += "]"; @@ -1796,8 +1814,9 @@ String Variant::stringify(List<const void *> &stack) const { Vector<float> vec = operator Vector<float>(); String str("["); for (int i = 0; i < vec.size(); i++) { - if (i > 0) + if (i > 0) { str += ", "; + } str = str + rtos(vec[i]); } str += "]"; @@ -1807,8 +1826,9 @@ String Variant::stringify(List<const void *> &stack) const { Vector<double> vec = operator Vector<double>(); String str("["); for (int i = 0; i < vec.size(); i++) { - if (i > 0) + if (i > 0) { str += ", "; + } str = str + rtos(vec[i]); } str += "]"; @@ -1823,8 +1843,9 @@ String Variant::stringify(List<const void *> &stack) const { String str("["); for (int i = 0; i < arr.size(); i++) { - if (i) + if (i) { str += ", "; + } str += arr[i].stringify(stack); } @@ -1840,8 +1861,9 @@ String Variant::stringify(List<const void *> &stack) const { }; return _get_obj().obj->to_string(); - } else + } else { return "[Object:null]"; + } } break; case CALLABLE: { @@ -1865,121 +1887,131 @@ String Variant::stringify(List<const void *> &stack) const { } Variant::operator Vector2() const { - if (type == VECTOR2) + if (type == VECTOR2) { return *reinterpret_cast<const Vector2 *>(_data._mem); - else if (type == VECTOR2I) + } else if (type == VECTOR2I) { return *reinterpret_cast<const Vector2i *>(_data._mem); - else if (type == VECTOR3) + } else if (type == VECTOR3) { return Vector2(reinterpret_cast<const Vector3 *>(_data._mem)->x, reinterpret_cast<const Vector3 *>(_data._mem)->y); - else if (type == VECTOR3I) + } else if (type == VECTOR3I) { return Vector2(reinterpret_cast<const Vector3i *>(_data._mem)->x, reinterpret_cast<const Vector3i *>(_data._mem)->y); - else + } else { return Vector2(); + } } Variant::operator Vector2i() const { - if (type == VECTOR2I) + if (type == VECTOR2I) { return *reinterpret_cast<const Vector2i *>(_data._mem); - else if (type == VECTOR2) + } else if (type == VECTOR2) { return *reinterpret_cast<const Vector2 *>(_data._mem); - else if (type == VECTOR3) + } else if (type == VECTOR3) { return Vector2(reinterpret_cast<const Vector3 *>(_data._mem)->x, reinterpret_cast<const Vector3 *>(_data._mem)->y); - else if (type == VECTOR3I) + } else if (type == VECTOR3I) { return Vector2(reinterpret_cast<const Vector3i *>(_data._mem)->x, reinterpret_cast<const Vector3i *>(_data._mem)->y); - else + } else { return Vector2i(); + } } Variant::operator Rect2() const { - if (type == RECT2) + if (type == RECT2) { return *reinterpret_cast<const Rect2 *>(_data._mem); - else if (type == RECT2I) + } else if (type == RECT2I) { return *reinterpret_cast<const Rect2i *>(_data._mem); - else + } else { return Rect2(); + } } Variant::operator Rect2i() const { - if (type == RECT2I) + if (type == RECT2I) { return *reinterpret_cast<const Rect2i *>(_data._mem); - else if (type == RECT2) + } else if (type == RECT2) { return *reinterpret_cast<const Rect2 *>(_data._mem); - else + } else { return Rect2i(); + } } Variant::operator Vector3() const { - if (type == VECTOR3) + if (type == VECTOR3) { return *reinterpret_cast<const Vector3 *>(_data._mem); - else if (type == VECTOR3I) + } else if (type == VECTOR3I) { return *reinterpret_cast<const Vector3i *>(_data._mem); - else if (type == VECTOR2) + } else if (type == VECTOR2) { return Vector3(reinterpret_cast<const Vector2 *>(_data._mem)->x, reinterpret_cast<const Vector2 *>(_data._mem)->y, 0.0); - else if (type == VECTOR2I) + } else if (type == VECTOR2I) { return Vector3(reinterpret_cast<const Vector2i *>(_data._mem)->x, reinterpret_cast<const Vector2i *>(_data._mem)->y, 0.0); - else + } else { return Vector3(); + } } Variant::operator Vector3i() const { - if (type == VECTOR3I) + if (type == VECTOR3I) { return *reinterpret_cast<const Vector3i *>(_data._mem); - else if (type == VECTOR3) + } else if (type == VECTOR3) { return *reinterpret_cast<const Vector3 *>(_data._mem); - else if (type == VECTOR2) + } else if (type == VECTOR2) { return Vector3i(reinterpret_cast<const Vector2 *>(_data._mem)->x, reinterpret_cast<const Vector2 *>(_data._mem)->y, 0.0); - else if (type == VECTOR2I) + } else if (type == VECTOR2I) { return Vector3i(reinterpret_cast<const Vector2i *>(_data._mem)->x, reinterpret_cast<const Vector2i *>(_data._mem)->y, 0.0); - else + } else { return Vector3i(); + } } Variant::operator Plane() const { - if (type == PLANE) + if (type == PLANE) { return *reinterpret_cast<const Plane *>(_data._mem); - else + } else { return Plane(); + } } Variant::operator ::AABB() const { - if (type == AABB) + if (type == AABB) { return *_data._aabb; - else + } else { return ::AABB(); + } } Variant::operator Basis() const { - if (type == BASIS) + if (type == BASIS) { return *_data._basis; - else if (type == QUAT) + } else if (type == QUAT) { return *reinterpret_cast<const Quat *>(_data._mem); - else if (type == VECTOR3) { + } else if (type == VECTOR3) { return Basis(*reinterpret_cast<const Vector3 *>(_data._mem)); - } else if (type == TRANSFORM) // unexposed in Variant::can_convert? + } else if (type == TRANSFORM) { // unexposed in Variant::can_convert? return _data._transform->basis; - else + } else { return Basis(); + } } Variant::operator Quat() const { - if (type == QUAT) + if (type == QUAT) { return *reinterpret_cast<const Quat *>(_data._mem); - else if (type == BASIS) + } else if (type == BASIS) { return *_data._basis; - else if (type == TRANSFORM) + } else if (type == TRANSFORM) { return _data._transform->basis; - else + } else { return Quat(); + } } Variant::operator Transform() const { - if (type == TRANSFORM) + if (type == TRANSFORM) { return *_data._transform; - else if (type == BASIS) + } else if (type == BASIS) { return Transform(*_data._basis, Vector3()); - else if (type == QUAT) + } else if (type == QUAT) { return Transform(Basis(*reinterpret_cast<const Quat *>(_data._mem)), Vector3()); - else if (type == TRANSFORM2D) { + } else if (type == TRANSFORM2D) { const Transform2D &t = *_data._transform2d; Transform m; m.basis.elements[0][0] = t.elements[0][0]; @@ -1989,8 +2021,9 @@ Variant::operator Transform() const { m.origin[0] = t.elements[2][0]; m.origin[1] = t.elements[2][1]; return m; - } else + } else { return Transform(); + } } Variant::operator Transform2D() const { @@ -2006,34 +2039,37 @@ Variant::operator Transform2D() const { m.elements[2][0] = t.origin[0]; m.elements[2][1] = t.origin[1]; return m; - } else + } else { return Transform2D(); + } } Variant::operator Color() const { - if (type == COLOR) + if (type == COLOR) { return *reinterpret_cast<const Color *>(_data._mem); - else if (type == STRING) + } else if (type == STRING) { return Color::html(operator String()); - else if (type == INT) + } else if (type == INT) { return Color::hex(operator int()); - else + } else { return Color(); + } } Variant::operator NodePath() const { - if (type == NODE_PATH) + if (type == NODE_PATH) { return *reinterpret_cast<const NodePath *>(_data._mem); - else if (type == STRING) + } else if (type == STRING) { return NodePath(operator String()); - else + } else { return NodePath(); + } } Variant::operator RID() const { - if (type == _RID) + if (type == _RID) { return *reinterpret_cast<const RID *>(_data._mem); - else if (type == OBJECT && _get_obj().obj == nullptr) { + } else if (type == OBJECT && _get_obj().obj == nullptr) { return RID(); } else if (type == OBJECT && _get_obj().obj) { #ifdef DEBUG_ENABLED @@ -2053,10 +2089,11 @@ Variant::operator RID() const { } Variant::operator Object *() const { - if (type == OBJECT) + if (type == OBJECT) { return _get_obj().obj; - else + } else { return nullptr; + } } Object *Variant::get_validated_object_with_check(bool &r_previously_freed) const { @@ -2071,45 +2108,51 @@ Object *Variant::get_validated_object_with_check(bool &r_previously_freed) const } Object *Variant::get_validated_object() const { - if (type == OBJECT) + if (type == OBJECT) { return ObjectDB::get_instance(_get_obj().id); - else + } else { return nullptr; + } } Variant::operator Node *() const { - if (type == OBJECT) + if (type == OBJECT) { return Object::cast_to<Node>(_get_obj().obj); - else + } else { return nullptr; + } } Variant::operator Control *() const { - if (type == OBJECT) + if (type == OBJECT) { return Object::cast_to<Control>(_get_obj().obj); - else + } else { return nullptr; + } } Variant::operator Dictionary() const { - if (type == DICTIONARY) + if (type == DICTIONARY) { return *reinterpret_cast<const Dictionary *>(_data._mem); - else + } else { return Dictionary(); + } } Variant::operator Callable() const { - if (type == CALLABLE) + if (type == CALLABLE) { return *reinterpret_cast<const Callable *>(_data._mem); - else + } else { return Callable(); + } } Variant::operator Signal() const { - if (type == SIGNAL) + if (type == SIGNAL) { return *reinterpret_cast<const Signal *>(_data._mem); - else + } else { return Signal(); + } } template <class DA, class SA> @@ -2164,73 +2207,83 @@ inline DA _convert_array_from_variant(const Variant &p_variant) { } Variant::operator Array() const { - if (type == ARRAY) + if (type == ARRAY) { return *reinterpret_cast<const Array *>(_data._mem); - else + } else { return _convert_array_from_variant<Array>(*this); + } } Variant::operator Vector<uint8_t>() const { - if (type == PACKED_BYTE_ARRAY) + if (type == PACKED_BYTE_ARRAY) { return static_cast<PackedArrayRef<uint8_t> *>(_data.packed_array)->array; - else + } else { return _convert_array_from_variant<Vector<uint8_t>>(*this); + } } Variant::operator Vector<int32_t>() const { - if (type == PACKED_INT32_ARRAY) + if (type == PACKED_INT32_ARRAY) { return static_cast<PackedArrayRef<int32_t> *>(_data.packed_array)->array; - else + } else { return _convert_array_from_variant<Vector<int>>(*this); + } } Variant::operator Vector<int64_t>() const { - if (type == PACKED_INT64_ARRAY) + if (type == PACKED_INT64_ARRAY) { return static_cast<PackedArrayRef<int64_t> *>(_data.packed_array)->array; - else + } else { return _convert_array_from_variant<Vector<int64_t>>(*this); + } } Variant::operator Vector<float>() const { - if (type == PACKED_FLOAT32_ARRAY) + if (type == PACKED_FLOAT32_ARRAY) { return static_cast<PackedArrayRef<float> *>(_data.packed_array)->array; - else + } else { return _convert_array_from_variant<Vector<float>>(*this); + } } Variant::operator Vector<double>() const { - if (type == PACKED_FLOAT64_ARRAY) + if (type == PACKED_FLOAT64_ARRAY) { return static_cast<PackedArrayRef<double> *>(_data.packed_array)->array; - else + } else { return _convert_array_from_variant<Vector<double>>(*this); + } } Variant::operator Vector<String>() const { - if (type == PACKED_STRING_ARRAY) + if (type == PACKED_STRING_ARRAY) { return static_cast<PackedArrayRef<String> *>(_data.packed_array)->array; - else + } else { return _convert_array_from_variant<Vector<String>>(*this); + } } Variant::operator Vector<Vector3>() const { - if (type == PACKED_VECTOR3_ARRAY) + if (type == PACKED_VECTOR3_ARRAY) { return static_cast<PackedArrayRef<Vector3> *>(_data.packed_array)->array; - else + } else { return _convert_array_from_variant<Vector<Vector3>>(*this); + } } Variant::operator Vector<Vector2>() const { - if (type == PACKED_VECTOR2_ARRAY) + if (type == PACKED_VECTOR2_ARRAY) { return static_cast<PackedArrayRef<Vector2> *>(_data.packed_array)->array; - else + } else { return _convert_array_from_variant<Vector<Vector2>>(*this); + } } Variant::operator Vector<Color>() const { - if (type == PACKED_COLOR_ARRAY) + if (type == PACKED_COLOR_ARRAY) { return static_cast<PackedArrayRef<Color> *>(_data.packed_array)->array; - else + } else { return _convert_array_from_variant<Vector<Color>>(*this); + } } /* helpers */ @@ -2239,8 +2292,9 @@ Variant::operator Vector<RID>() const { Array va = operator Array(); Vector<RID> rids; rids.resize(va.size()); - for (int i = 0; i < rids.size(); i++) + for (int i = 0; i < rids.size(); i++) { rids.write[i] = va[i]; + } return rids; } @@ -2248,14 +2302,16 @@ Variant::operator Vector<Plane>() const { Array va = operator Array(); Vector<Plane> planes; int va_size = va.size(); - if (va_size == 0) + if (va_size == 0) { return planes; + } planes.resize(va_size); Plane *w = planes.ptrw(); - for (int i = 0; i < va_size; i++) + for (int i = 0; i < va_size; i++) { w[i] = va[i]; + } return planes; } @@ -2264,15 +2320,17 @@ Variant::operator Vector<Face3>() const { Vector<Vector3> va = operator Vector<Vector3>(); Vector<Face3> faces; int va_size = va.size(); - if (va_size == 0) + if (va_size == 0) { return faces; + } faces.resize(va_size / 3); Face3 *w = faces.ptrw(); const Vector3 *r = va.ptr(); - for (int i = 0; i < va_size; i++) + for (int i = 0; i < va_size; i++) { w[i / 3].vertex[i % 3] = r[i]; + } return faces; } @@ -2281,13 +2339,15 @@ Variant::operator Vector<Variant>() const { Array va = operator Array(); Vector<Variant> variants; int va_size = va.size(); - if (va_size == 0) + if (va_size == 0) { return variants; + } variants.resize(va_size); Variant *w = variants.ptrw(); - for (int i = 0; i < va_size; i++) + for (int i = 0; i < va_size; i++) { w[i] = va[i]; + } return variants; } @@ -2621,8 +2681,9 @@ Variant::Variant(const Vector<Face3> &p_face_array) { Vector3 *w = vertices.ptrw(); for (int i = 0; i < face_count; i++) { - for (int j = 0; j < 3; j++) + for (int j = 0; j < 3; j++) { w[i * 3 + j] = r[i].vertex[j]; + } } } @@ -2647,14 +2708,16 @@ Variant::Variant(const Vector<StringName> &p_array) { Vector<String> v; int len = p_array.size(); v.resize(len); - for (int i = 0; i < len; i++) + for (int i = 0; i < len; i++) { v.set(i, p_array[i]); + } *this = v; } void Variant::operator=(const Variant &p_variant) { - if (unlikely(this == &p_variant)) + if (unlikely(this == &p_variant)) { return; + } if (unlikely(type != p_variant.type)) { reference(p_variant); @@ -3132,8 +3195,9 @@ uint32_t Variant::hash() const { return true bool Variant::hash_compare(const Variant &p_variant) const { - if (type != p_variant.type) + if (type != p_variant.type) { return false; + } switch (type) { case FLOAT: { @@ -3171,8 +3235,9 @@ bool Variant::hash_compare(const Variant &p_variant) const { Transform2D *r = p_variant._data._transform2d; for (int i = 0; i < 3; i++) { - if (!(hash_compare_vector2(l->elements[i], r->elements[i]))) + if (!(hash_compare_vector2(l->elements[i], r->elements[i]))) { return false; + } } return true; @@ -3220,8 +3285,9 @@ bool Variant::hash_compare(const Variant &p_variant) const { const Basis *r = p_variant._data._basis; for (int i = 0; i < 3; i++) { - if (!(hash_compare_vector3(l->elements[i], r->elements[i]))) + if (!(hash_compare_vector3(l->elements[i], r->elements[i]))) { return false; + } } return true; @@ -3232,8 +3298,9 @@ bool Variant::hash_compare(const Variant &p_variant) const { const Transform *r = p_variant._data._transform; for (int i = 0; i < 3; i++) { - if (!(hash_compare_vector3(l->basis.elements[i], r->basis.elements[i]))) + if (!(hash_compare_vector3(l->basis.elements[i], r->basis.elements[i]))) { return false; + } } return hash_compare_vector3(l->origin, r->origin); @@ -3250,12 +3317,14 @@ bool Variant::hash_compare(const Variant &p_variant) const { const Array &l = *(reinterpret_cast<const Array *>(_data._mem)); const Array &r = *(reinterpret_cast<const Array *>(p_variant._data._mem)); - if (l.size() != r.size()) + if (l.size() != r.size()) { return false; + } for (int i = 0; i < l.size(); ++i) { - if (!l[i].hash_compare(r[i])) + if (!l[i].hash_compare(r[i])) { return false; + } } return true; @@ -3362,8 +3431,9 @@ Variant Variant::call(const StringName &p_method, VARIANT_ARG_DECLARE) { VARIANT_ARGPTRS; int argc = 0; for (int i = 0; i < VARIANT_ARG_MAX; i++) { - if (argptr[i]->get_type() == Variant::NIL) + if (argptr[i]->get_type() == Variant::NIL) { break; + } argc++; } diff --git a/core/variant.h b/core/variant.h index 70de8479e3..b24cf968de 100644 --- a/core/variant.h +++ b/core/variant.h @@ -471,8 +471,9 @@ public: Variant(const Variant &p_variant); _FORCE_INLINE_ Variant() {} _FORCE_INLINE_ ~Variant() { - if (type != Variant::NIL) + if (type != Variant::NIL) { clear(); + } } }; diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 61b1e91d6c..82b1f29805 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -59,14 +59,16 @@ struct _VariantCall { VariantFunc func; _FORCE_INLINE_ bool verify_arguments(const Variant **p_args, Callable::CallError &r_error) { - if (arg_count == 0) + if (arg_count == 0) { return true; + } const Variant::Type *tptr = &arg_types[0]; for (int i = 0; i < arg_count; i++) { - if (tptr[i] == Variant::NIL || tptr[i] == p_args[i]->type) + if (tptr[i] == Variant::NIL || tptr[i] == p_args[i]->type) { continue; // all good + } if (!Variant::can_convert(p_args[i]->type, tptr[i])) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = i; @@ -97,21 +99,25 @@ struct _VariantCall { #endif ERR_FAIL_COND(p_argcount > VARIANT_ARG_MAX); const Variant *newargs[VARIANT_ARG_MAX]; - for (int i = 0; i < p_argcount; i++) + for (int i = 0; i < p_argcount; i++) { newargs[i] = p_args[i]; + } // fill in any remaining parameters with defaults int first_default_arg = arg_count - def_argcount; - for (int i = p_argcount; i < arg_count; i++) + for (int i = p_argcount; i < arg_count; i++) { newargs[i] = &default_args[i - first_default_arg]; + } #ifdef DEBUG_ENABLED - if (!verify_arguments(newargs, r_error)) + if (!verify_arguments(newargs, r_error)) { return; + } #endif func(r_ret, p_self, newargs); } else { #ifdef DEBUG_ENABLED - if (!verify_arguments(p_args, r_error)) + if (!verify_arguments(p_args, r_error)) { return; + } #endif func(r_ret, p_self, p_args); } @@ -156,8 +162,9 @@ struct _VariantCall { funcdata.arg_names.push_back(p_argtype1.name); #endif - } else + } else { goto end; + } if (p_argtype2.name) { funcdata.arg_types.push_back(p_argtype2.type); @@ -165,8 +172,9 @@ struct _VariantCall { funcdata.arg_names.push_back(p_argtype2.name); #endif - } else + } else { goto end; + } if (p_argtype3.name) { funcdata.arg_types.push_back(p_argtype3.type); @@ -174,24 +182,27 @@ struct _VariantCall { funcdata.arg_names.push_back(p_argtype3.name); #endif - } else + } else { goto end; + } if (p_argtype4.name) { funcdata.arg_types.push_back(p_argtype4.type); #ifdef DEBUG_ENABLED funcdata.arg_names.push_back(p_argtype4.name); #endif - } else + } else { goto end; + } if (p_argtype5.name) { funcdata.arg_types.push_back(p_argtype5.type); #ifdef DEBUG_ENABLED funcdata.arg_names.push_back(p_argtype5.name); #endif - } else + } else { goto end; + } end: @@ -455,26 +466,29 @@ struct _VariantCall { //return vector3 if intersected, nil if not static void _call_Plane_intersect_3(Variant &r_ret, Variant &p_self, const Variant **p_args) { Vector3 result; - if (reinterpret_cast<Plane *>(p_self._data._mem)->intersect_3(*p_args[0], *p_args[1], &result)) + if (reinterpret_cast<Plane *>(p_self._data._mem)->intersect_3(*p_args[0], *p_args[1], &result)) { r_ret = result; - else + } else { r_ret = Variant(); + } } static void _call_Plane_intersects_ray(Variant &r_ret, Variant &p_self, const Variant **p_args) { Vector3 result; - if (reinterpret_cast<Plane *>(p_self._data._mem)->intersects_ray(*p_args[0], *p_args[1], &result)) + if (reinterpret_cast<Plane *>(p_self._data._mem)->intersects_ray(*p_args[0], *p_args[1], &result)) { r_ret = result; - else + } else { r_ret = Variant(); + } } static void _call_Plane_intersects_segment(Variant &r_ret, Variant &p_self, const Variant **p_args) { Vector3 result; - if (reinterpret_cast<Plane *>(p_self._data._mem)->intersects_segment(*p_args[0], *p_args[1], &result)) + if (reinterpret_cast<Plane *>(p_self._data._mem)->intersects_segment(*p_args[0], *p_args[1], &result)) { r_ret = result; - else + } else { r_ret = Variant(); + } } VCALL_LOCALMEM0R(Quat, length); @@ -1121,26 +1135,30 @@ struct _VariantCall { cd.func = p_func; cd.arg_count = 0; - if (p_name1 == "") + if (p_name1 == "") { goto end; + } cd.arg_count++; cd.arg_names.push_back(p_name1); cd.arg_types.push_back(p_type1); - if (p_name2 == "") + if (p_name2 == "") { goto end; + } cd.arg_count++; cd.arg_names.push_back(p_name2); cd.arg_types.push_back(p_type2); - if (p_name3 == "") + if (p_name3 == "") { goto end; + } cd.arg_count++; cd.arg_names.push_back(p_name3); cd.arg_types.push_back(p_type3); - if (p_name4 == "") + if (p_name4 == "") { goto end; + } cd.arg_count++; cd.arg_names.push_back(p_name4); cd.arg_types.push_back(p_type4); @@ -1241,8 +1259,9 @@ void Variant::call_ptr(const StringName &p_method, const Variant **p_args, int p } } - if (r_error.error == Callable::CallError::CALL_OK && r_ret) + if (r_error.error == Callable::CallError::CALL_OK && r_ret) { *r_ret = ret; + } } #define VCALL(m_type, m_method) _VariantCall::_call_##m_type##_##m_method @@ -1425,8 +1444,9 @@ Variant Variant::construct(const Variant::Type p_type, const Variant **p_args, i for (List<_VariantCall::ConstructData>::Element *E = c.constructors.front(); E; E = E->next()) { const _VariantCall::ConstructData &cd = E->get(); - if (cd.arg_count != p_argcount) + if (cd.arg_count != p_argcount) { continue; + } //validate parameters for (int i = 0; i < cd.arg_count; i++) { @@ -1450,8 +1470,9 @@ Variant Variant::construct(const Variant::Type p_type, const Variant **p_args, i bool Variant::has_method(const StringName &p_method) const { if (type == OBJECT) { Object *obj = get_validated_object(); - if (!obj) + if (!obj) { return false; + } return obj->has_method(p_method); } @@ -1464,8 +1485,9 @@ Vector<Variant::Type> Variant::get_method_argument_types(Variant::Type p_type, c const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type]; const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method); - if (!E) + if (!E) { return Vector<Variant::Type>(); + } return E->get().arg_types; } @@ -1474,8 +1496,9 @@ bool Variant::is_method_const(Variant::Type p_type, const StringName &p_method) const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type]; const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method); - if (!E) + if (!E) { return false; + } return E->get()._const; } @@ -1484,8 +1507,9 @@ Vector<StringName> Variant::get_method_argument_names(Variant::Type p_type, cons const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type]; const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method); - if (!E) + if (!E) { return Vector<StringName>(); + } return E->get().arg_names; } @@ -1494,11 +1518,13 @@ Variant::Type Variant::get_method_return_type(Variant::Type p_type, const String const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type]; const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method); - if (!E) + if (!E) { return Variant::NIL; + } - if (r_has_return) + if (r_has_return) { *r_has_return = E->get().returns; + } return E->get().return_type; } @@ -1507,8 +1533,9 @@ Vector<Variant> Variant::get_method_default_arguments(Variant::Type p_type, cons const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type]; const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method); - if (!E) + if (!E) { return Vector<Variant>(); + } return E->get().default_args; } @@ -1541,8 +1568,9 @@ void Variant::get_method_list(List<MethodInfo> *p_list) const { ret.type = fd.return_type; if (fd.returns) { ret.name = "ret"; - if (fd.return_type == Variant::NIL) + if (fd.return_type == Variant::NIL) { ret.usage = PROPERTY_USAGE_NIL_IS_VARIANT; + } } mi.return_val = ret; #endif @@ -1592,10 +1620,12 @@ void Variant::get_constructor_list(Variant::Type p_type, List<MethodInfo> *p_lis } //default constructors for (int i = 0; i < VARIANT_MAX; i++) { - if (i == p_type) + if (i == p_type) { continue; - if (!Variant::can_convert(Variant::Type(i), p_type)) + } + if (!Variant::can_convert(Variant::Type(i), p_type)) { continue; + } MethodInfo mi; mi.name = Variant::get_type_name(p_type); @@ -1634,8 +1664,9 @@ bool Variant::has_constant(Variant::Type p_type, const StringName &p_value) { } Variant Variant::get_constant_value(Variant::Type p_type, const StringName &p_value, bool *r_valid) { - if (r_valid) + if (r_valid) { *r_valid = false; + } ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, 0); _VariantCall::ConstantData &cd = _VariantCall::constant_data[p_type]; @@ -1644,15 +1675,17 @@ Variant Variant::get_constant_value(Variant::Type p_type, const StringName &p_va if (!E) { Map<StringName, Variant>::Element *F = cd.variant_value.find(p_value); if (F) { - if (r_valid) + if (r_valid) { *r_valid = true; + } return F->get(); } else { return -1; } } - if (r_valid) + if (r_valid) { *r_valid = true; + } return E->get(); } diff --git a/core/variant_op.cpp b/core/variant_op.cpp index 1d75d52db0..8641187f97 100644 --- a/core/variant_op.cpp +++ b/core/variant_op.cpp @@ -916,10 +916,12 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, int asize = array_a.size(); int bsize = array_b.size(); sum.resize(asize + bsize); - for (int i = 0; i < asize; i++) + for (int i = 0; i < asize; i++) { sum[i] = array_a[i]; - for (int i = 0; i < bsize; i++) + } + for (int i = 0; i < bsize; i++) { sum[i + asize] = array_b[i]; + } _RETURN(sum); } @@ -1946,13 +1948,15 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const { case OBJECT: { #ifdef DEBUG_ENABLED if (!_get_obj().obj) { - if (r_valid) + if (r_valid) { *r_valid = false; + } return "Instance base is null."; } else { if (EngineDebugger::is_active() && !_get_obj().id.is_reference() && ObjectDB::get_instance(_get_obj().id) == nullptr) { - if (r_valid) + if (r_valid) { *r_valid = false; + } return "Attempted use of stray pointer object."; } } @@ -2043,16 +2047,19 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) return; } break; case STRING: { - if (p_index.type != Variant::INT && p_index.type != Variant::FLOAT) + if (p_index.type != Variant::INT && p_index.type != Variant::FLOAT) { return; + } int idx = p_index; String *str = reinterpret_cast<String *>(_data._mem); int len = str->length(); - if (idx < 0) + if (idx < 0) { idx += len; - if (idx < 0 || idx >= len) + } + if (idx < 0 || idx >= len) { return; + } String chr; if (p_value.type == Variant::INT || p_value.type == Variant::FLOAT) { @@ -2069,15 +2076,17 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } break; case VECTOR2: { - if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) + if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) { return; + } if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { // scalar index int idx = p_index; - if (idx < 0) + if (idx < 0) { idx += 2; + } if (idx >= 0 && idx < 2) { Vector2 *v = reinterpret_cast<Vector2 *>(_data._mem); valid = true; @@ -2102,15 +2111,17 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } break; case VECTOR2I: { - if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) + if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) { return; + } if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { // scalar index int idx = p_index; - if (idx < 0) + if (idx < 0) { idx += 2; + } if (idx >= 0 && idx < 2) { Vector2i *v = reinterpret_cast<Vector2i *>(_data._mem); valid = true; @@ -2135,8 +2146,9 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } break; case RECT2: { - if (p_value.type != Variant::VECTOR2) + if (p_value.type != Variant::VECTOR2) { return; + } if (p_index.get_type() == Variant::STRING) { //scalar name @@ -2159,8 +2171,9 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } } break; case RECT2I: { - if (p_value.type != Variant::VECTOR2I) + if (p_value.type != Variant::VECTOR2I) { return; + } if (p_index.get_type() == Variant::STRING) { //scalar name @@ -2183,14 +2196,16 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } } break; case TRANSFORM2D: { - if (p_value.type != Variant::VECTOR2) + if (p_value.type != Variant::VECTOR2) { return; + } if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { int index = p_index; - if (index < 0) + if (index < 0) { index += 3; + } if (index >= 0 && index < 3) { Transform2D *v = _data._transform2d; @@ -2219,14 +2234,16 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } break; case VECTOR3: { - if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) + if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) { return; + } if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { //scalar index int idx = p_index; - if (idx < 0) + if (idx < 0) { idx += 3; + } if (idx >= 0 && idx < 3) { Vector3 *v = reinterpret_cast<Vector3 *>(_data._mem); valid = true; @@ -2254,14 +2271,16 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } break; case VECTOR3I: { - if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) + if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) { return; + } if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { //scalar index int idx = p_index; - if (idx < 0) + if (idx < 0) { idx += 3; + } if (idx >= 0 && idx < 3) { Vector3i *v = reinterpret_cast<Vector3i *>(_data._mem); valid = true; @@ -2294,29 +2313,33 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) const String *str = reinterpret_cast<const String *>(p_index._data._mem); Plane *v = reinterpret_cast<Plane *>(_data._mem); if (*str == "x") { - if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) + if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) { return; + } valid = true; v->normal.x = p_value; return; } else if (*str == "y") { - if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) + if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) { return; + } valid = true; v->normal.y = p_value; return; } else if (*str == "z") { - if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) + if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) { return; + } valid = true; v->normal.z = p_value; return; } else if (*str == "normal") { - if (p_value.type != Variant::VECTOR3) + if (p_value.type != Variant::VECTOR3) { return; + } valid = true; v->normal = p_value; @@ -2330,8 +2353,9 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } break; case QUAT: { - if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) + if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) { return; + } if (p_index.get_type() == Variant::STRING) { const String *str = reinterpret_cast<const String *>(p_index._data._mem); @@ -2357,8 +2381,9 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } break; case AABB: { - if (p_value.type != Variant::VECTOR3) + if (p_value.type != Variant::VECTOR3) { return; + } if (p_index.get_type() == Variant::STRING) { //scalar name @@ -2381,14 +2406,16 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } } break; case BASIS: { - if (p_value.type != Variant::VECTOR3) + if (p_value.type != Variant::VECTOR3) { return; + } if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { int index = p_index; - if (index < 0) + if (index < 0) { index += 3; + } if (index >= 0 && index < 3) { Basis *v = _data._basis; @@ -2418,20 +2445,23 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } break; case TRANSFORM: { if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { - if (p_value.type != Variant::VECTOR3) + if (p_value.type != Variant::VECTOR3) { return; + } int index = p_index; - if (index < 0) + if (index < 0) { index += 4; + } if (index >= 0 && index < 4) { Transform *v = _data._transform; valid = true; - if (index == 3) + if (index == 3) { v->origin = p_value; - else + } else { v->basis.set_axis(index, p_value); + } return; } } else if (p_index.get_type() == Variant::STRING) { @@ -2439,15 +2469,17 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) const String *str = reinterpret_cast<const String *>(p_index._data._mem); if (*str == "basis") { - if (p_value.type != Variant::BASIS) + if (p_value.type != Variant::BASIS) { return; + } valid = true; v->basis = p_value; return; } if (*str == "origin") { - if (p_value.type != Variant::VECTOR3) + if (p_value.type != Variant::VECTOR3) { return; + } valid = true; v->origin = p_value; return; @@ -2456,8 +2488,9 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } break; case COLOR: { - if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) + if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) { return; + } if (p_index.get_type() == Variant::STRING) { const String *str = reinterpret_cast<const String *>(p_index._data._mem); @@ -2509,8 +2542,9 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } } else if (p_index.get_type() == Variant::INT) { int idx = p_index; - if (idx < 0) + if (idx < 0) { idx += 4; + } if (idx >= 0 && idx < 4) { Color *v = reinterpret_cast<Color *>(_data._mem); (*v)[idx] = p_value; @@ -2594,8 +2628,9 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { int idx = p_index; const String *str = reinterpret_cast<const String *>(_data._mem); - if (idx < 0) + if (idx < 0) { idx += str->length(); + } if (idx >= 0 && idx < str->length()) { valid = true; return str->substr(idx, 1); @@ -2607,8 +2642,9 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { // scalar index int idx = p_index; - if (idx < 0) + if (idx < 0) { idx += 2; + } if (idx >= 0 && idx < 2) { const Vector2 *v = reinterpret_cast<const Vector2 *>(_data._mem); valid = true; @@ -2633,8 +2669,9 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { // scalar index int idx = p_index; - if (idx < 0) + if (idx < 0) { idx += 2; + } if (idx >= 0 && idx < 2) { const Vector2i *v = reinterpret_cast<const Vector2i *>(_data._mem); valid = true; @@ -2695,8 +2732,9 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { //scalar index int idx = p_index; - if (idx < 0) + if (idx < 0) { idx += 3; + } if (idx >= 0 && idx < 3) { const Vector3 *v = reinterpret_cast<const Vector3 *>(_data._mem); valid = true; @@ -2723,8 +2761,9 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { //scalar index int idx = p_index; - if (idx < 0) + if (idx < 0) { idx += 3; + } if (idx >= 0 && idx < 3) { const Vector3i *v = reinterpret_cast<const Vector3i *>(_data._mem); valid = true; @@ -2751,8 +2790,9 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { int index = p_index; - if (index < 0) + if (index < 0) { index += 3; + } if (index >= 0 && index < 3) { const Transform2D *v = _data._transform2d; @@ -2841,8 +2881,9 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { case BASIS: { if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { int index = p_index; - if (index < 0) + if (index < 0) { index += 3; + } if (index >= 0 && index < 3) { const Basis *v = _data._basis; @@ -2869,8 +2910,9 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { case TRANSFORM: { if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { int index = p_index; - if (index < 0) + if (index < 0) { index += 4; + } if (index >= 0 && index < 4) { const Transform *v = _data._transform; valid = true; @@ -2931,8 +2973,9 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { } } else if (p_index.get_type() == Variant::INT) { int idx = p_index; - if (idx < 0) + if (idx < 0) { idx += 4; + } if (idx >= 0 && idx < 4) { const Color *v = reinterpret_cast<const Color *>(_data._mem); valid = true; @@ -2992,8 +3035,9 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { } bool Variant::in(const Variant &p_index, bool *r_valid) const { - if (r_valid) + if (r_valid) { *r_valid = true; + } switch (type) { case STRING: { @@ -3029,8 +3073,9 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const { return valid; } else { - if (r_valid) + if (r_valid) { *r_valid = false; + } } return false; } break; @@ -3044,8 +3089,9 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const { int l = arr->size(); if (l) { for (int i = 0; i < l; i++) { - if (evaluate(OP_EQUAL, (*arr)[i], p_index)) + if (evaluate(OP_EQUAL, (*arr)[i], p_index)) { return true; + } } } @@ -3060,8 +3106,9 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const { if (l) { const uint8_t *r = arr->ptr(); for (int i = 0; i < l; i++) { - if (r[i] == index) + if (r[i] == index) { return true; + } } } @@ -3077,8 +3124,9 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const { if (l) { const int32_t *r = arr->ptr(); for (int32_t i = 0; i < l; i++) { - if (r[i] == index) + if (r[i] == index) { return true; + } } } @@ -3093,8 +3141,9 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const { if (l) { const int64_t *r = arr->ptr(); for (int64_t i = 0; i < l; i++) { - if (r[i] == index) + if (r[i] == index) { return true; + } } } @@ -3109,8 +3158,9 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const { if (l) { const float *r = arr->ptr(); for (int i = 0; i < l; i++) { - if (r[i] == index) + if (r[i] == index) { return true; + } } } @@ -3126,8 +3176,9 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const { if (l) { const double *r = arr->ptr(); for (int i = 0; i < l; i++) { - if (r[i] == index) + if (r[i] == index) { return true; + } } } @@ -3144,8 +3195,9 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const { if (l) { const String *r = arr->ptr(); for (int i = 0; i < l; i++) { - if (r[i] == index) + if (r[i] == index) { return true; + } } } @@ -3162,8 +3214,9 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const { if (l) { const Vector2 *r = arr->ptr(); for (int i = 0; i < l; i++) { - if (r[i] == index) + if (r[i] == index) { return true; + } } } @@ -3180,8 +3233,9 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const { if (l) { const Vector3 *r = arr->ptr(); for (int i = 0; i < l; i++) { - if (r[i] == index) + if (r[i] == index) { return true; + } } } @@ -3198,8 +3252,9 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const { if (l) { const Color *r = arr->ptr(); for (int i = 0; i < l; i++) { - if (r[i] == index) + if (r[i] == index) { return true; + } } } @@ -3210,8 +3265,9 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const { } } - if (r_valid) + if (r_valid) { *r_valid = false; + } return false; } @@ -3439,15 +3495,17 @@ bool Variant::iter_init(Variant &r_iter, bool &valid) const { case STRING: { const String *str = reinterpret_cast<const String *>(_data._mem); - if (str->empty()) + if (str->empty()) { return false; + } r_iter = 0; return true; } break; case DICTIONARY: { const Dictionary *dic = reinterpret_cast<const Dictionary *>(_data._mem); - if (dic->empty()) + if (dic->empty()) { return false; + } const Variant *next = dic->next(nullptr); r_iter = *next; @@ -3456,76 +3514,86 @@ bool Variant::iter_init(Variant &r_iter, bool &valid) const { } break; case ARRAY: { const Array *arr = reinterpret_cast<const Array *>(_data._mem); - if (arr->empty()) + if (arr->empty()) { return false; + } r_iter = 0; return true; } break; case PACKED_BYTE_ARRAY: { const Vector<uint8_t> *arr = &PackedArrayRef<uint8_t>::get_array(_data.packed_array); - if (arr->size() == 0) + if (arr->size() == 0) { return false; + } r_iter = 0; return true; } break; case PACKED_INT32_ARRAY: { const Vector<int32_t> *arr = &PackedArrayRef<int32_t>::get_array(_data.packed_array); - if (arr->size() == 0) + if (arr->size() == 0) { return false; + } r_iter = 0; return true; } break; case PACKED_INT64_ARRAY: { const Vector<int64_t> *arr = &PackedArrayRef<int64_t>::get_array(_data.packed_array); - if (arr->size() == 0) + if (arr->size() == 0) { return false; + } r_iter = 0; return true; } break; case PACKED_FLOAT32_ARRAY: { const Vector<float> *arr = &PackedArrayRef<float>::get_array(_data.packed_array); - if (arr->size() == 0) + if (arr->size() == 0) { return false; + } r_iter = 0; return true; } break; case PACKED_FLOAT64_ARRAY: { const Vector<double> *arr = &PackedArrayRef<double>::get_array(_data.packed_array); - if (arr->size() == 0) + if (arr->size() == 0) { return false; + } r_iter = 0; return true; } break; case PACKED_STRING_ARRAY: { const Vector<String> *arr = &PackedArrayRef<String>::get_array(_data.packed_array); - if (arr->size() == 0) + if (arr->size() == 0) { return false; + } r_iter = 0; return true; } break; case PACKED_VECTOR2_ARRAY: { const Vector<Vector2> *arr = &PackedArrayRef<Vector2>::get_array(_data.packed_array); - if (arr->size() == 0) + if (arr->size() == 0) { return false; + } r_iter = 0; return true; } break; case PACKED_VECTOR3_ARRAY: { const Vector<Vector3> *arr = &PackedArrayRef<Vector3>::get_array(_data.packed_array); - if (arr->size() == 0) + if (arr->size() == 0) { return false; + } r_iter = 0; return true; } break; case PACKED_COLOR_ARRAY: { const Vector<Color> *arr = &PackedArrayRef<Color>::get_array(_data.packed_array); - if (arr->size() == 0) + if (arr->size() == 0) { return false; + } r_iter = 0; return true; @@ -3544,16 +3612,18 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { case INT: { int64_t idx = r_iter; idx++; - if (idx >= _data._int) + if (idx >= _data._int) { return false; + } r_iter = idx; return true; } break; case FLOAT: { int64_t idx = r_iter; idx++; - if (idx >= _data._float) + if (idx >= _data._float) { return false; + } r_iter = idx; return true; } break; @@ -3563,8 +3633,9 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { double idx = r_iter; idx++; - if (idx >= to) + if (idx >= to) { return false; + } r_iter = idx; return true; @@ -3575,8 +3646,9 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { int64_t idx = r_iter; idx++; - if (idx >= to) + if (idx >= to) { return false; + } r_iter = idx; return true; @@ -3588,11 +3660,13 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { double idx = r_iter; idx += step; - if (step < 0 && idx <= to) + if (step < 0 && idx <= to) { return false; + } - if (step > 0 && idx >= to) + if (step > 0 && idx >= to) { return false; + } r_iter = idx; return true; @@ -3604,11 +3678,13 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { int64_t idx = r_iter; idx += step; - if (step < 0 && idx <= to) + if (step < 0 && idx <= to) { return false; + } - if (step > 0 && idx >= to) + if (step > 0 && idx >= to) { return false; + } r_iter = idx; return true; @@ -3649,16 +3725,18 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { const String *str = reinterpret_cast<const String *>(_data._mem); int idx = r_iter; idx++; - if (idx >= str->length()) + if (idx >= str->length()) { return false; + } r_iter = idx; return true; } break; case DICTIONARY: { const Dictionary *dic = reinterpret_cast<const Dictionary *>(_data._mem); const Variant *next = dic->next(&r_iter); - if (!next) + if (!next) { return false; + } r_iter = *next; return true; @@ -3668,8 +3746,9 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { const Array *arr = reinterpret_cast<const Array *>(_data._mem); int idx = r_iter; idx++; - if (idx >= arr->size()) + if (idx >= arr->size()) { return false; + } r_iter = idx; return true; } break; @@ -3677,8 +3756,9 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { const Vector<uint8_t> *arr = &PackedArrayRef<uint8_t>::get_array(_data.packed_array); int idx = r_iter; idx++; - if (idx >= arr->size()) + if (idx >= arr->size()) { return false; + } r_iter = idx; return true; @@ -3687,8 +3767,9 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { const Vector<int32_t> *arr = &PackedArrayRef<int32_t>::get_array(_data.packed_array); int32_t idx = r_iter; idx++; - if (idx >= arr->size()) + if (idx >= arr->size()) { return false; + } r_iter = idx; return true; @@ -3697,8 +3778,9 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { const Vector<int64_t> *arr = &PackedArrayRef<int64_t>::get_array(_data.packed_array); int64_t idx = r_iter; idx++; - if (idx >= arr->size()) + if (idx >= arr->size()) { return false; + } r_iter = idx; return true; @@ -3707,8 +3789,9 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { const Vector<float> *arr = &PackedArrayRef<float>::get_array(_data.packed_array); int idx = r_iter; idx++; - if (idx >= arr->size()) + if (idx >= arr->size()) { return false; + } r_iter = idx; return true; @@ -3717,8 +3800,9 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { const Vector<double> *arr = &PackedArrayRef<double>::get_array(_data.packed_array); int idx = r_iter; idx++; - if (idx >= arr->size()) + if (idx >= arr->size()) { return false; + } r_iter = idx; return true; @@ -3727,8 +3811,9 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { const Vector<String> *arr = &PackedArrayRef<String>::get_array(_data.packed_array); int idx = r_iter; idx++; - if (idx >= arr->size()) + if (idx >= arr->size()) { return false; + } r_iter = idx; return true; } break; @@ -3736,8 +3821,9 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { const Vector<Vector2> *arr = &PackedArrayRef<Vector2>::get_array(_data.packed_array); int idx = r_iter; idx++; - if (idx >= arr->size()) + if (idx >= arr->size()) { return false; + } r_iter = idx; return true; } break; @@ -3745,8 +3831,9 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { const Vector<Vector3> *arr = &PackedArrayRef<Vector3>::get_array(_data.packed_array); int idx = r_iter; idx++; - if (idx >= arr->size()) + if (idx >= arr->size()) { return false; + } r_iter = idx; return true; } break; @@ -3754,8 +3841,9 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { const Vector<Color> *arr = &PackedArrayRef<Color>::get_array(_data.packed_array); int idx = r_iter; idx++; - if (idx >= arr->size()) + if (idx >= arr->size()) { return false; + } r_iter = idx; return true; } break; @@ -4129,16 +4217,18 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant & CharType chr = ' '; if (i < split) { - if (i < sa.length()) + if (i < sa.length()) { chr = sa[i]; - else if (i < sb.length()) + } else if (i < sb.length()) { chr = sb[i]; + } } else { - if (i < sb.length()) + if (i < sb.length()) { chr = sb[i]; - else if (i < sa.length()) + } else if (i < sa.length()) { chr = sa[i]; + } } dst[i] = chr; diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp index 3a38720a27..9fe98265dd 100644 --- a/core/variant_parser.cpp +++ b/core/variant_parser.cpp @@ -150,8 +150,9 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri r_token.type = TK_EOF; return OK; } - if (ch == '\n') + if (ch == '\n') { break; + } } break; @@ -278,8 +279,9 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri str += res; } else { - if (ch == '\n') + if (ch == '\n') { line++; + } str += ch; } } @@ -362,8 +364,9 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri } break; } - if (reading == READING_DONE) + if (reading == READING_DONE) { break; + } num += c; c = p_stream->get_char(); } @@ -372,10 +375,11 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri r_token.type = TK_NUMBER; - if (is_float) + if (is_float) { r_token.value = num.as_double(); - else + } else { r_token.value = num.as_int(); + } return OK; } else if ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_') { @@ -484,35 +488,38 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, if (token.type == TK_CURLY_BRACKET_OPEN) { Dictionary d; Error err = _parse_dictionary(d, p_stream, line, r_err_str, p_res_parser); - if (err) + if (err) { return err; + } value = d; return OK; } else if (token.type == TK_BRACKET_OPEN) { Array a; Error err = _parse_array(a, p_stream, line, r_err_str, p_res_parser); - if (err) + if (err) { return err; + } value = a; return OK; } else if (token.type == TK_IDENTIFIER) { String id = token.value; - if (id == "true") + if (id == "true") { value = true; - else if (id == "false") + } else if (id == "false") { value = false; - else if (id == "null" || id == "nil") + } else if (id == "null" || id == "nil") { value = Variant(); - else if (id == "inf") + } else if (id == "inf") { value = Math_INF; - else if (id == "nan") + } else if (id == "nan") { value = Math_NAN; - else if (id == "Vector2") { + } else if (id == "Vector2") { Vector<float> args; Error err = _parse_construct<float>(p_stream, args, line, r_err_str); - if (err) + if (err) { return err; + } if (args.size() != 2) { r_err_str = "Expected 2 arguments for constructor"; @@ -523,8 +530,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, } else if (id == "Vector2i") { Vector<int32_t> args; Error err = _parse_construct<int32_t>(p_stream, args, line, r_err_str); - if (err) + if (err) { return err; + } if (args.size() != 2) { r_err_str = "Expected 2 arguments for constructor"; @@ -535,8 +543,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, } else if (id == "Rect2") { Vector<float> args; Error err = _parse_construct<float>(p_stream, args, line, r_err_str); - if (err) + if (err) { return err; + } if (args.size() != 4) { r_err_str = "Expected 4 arguments for constructor"; @@ -547,8 +556,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, } else if (id == "Rect2i") { Vector<int32_t> args; Error err = _parse_construct<int32_t>(p_stream, args, line, r_err_str); - if (err) + if (err) { return err; + } if (args.size() != 4) { r_err_str = "Expected 4 arguments for constructor"; @@ -559,8 +569,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, } else if (id == "Vector3") { Vector<float> args; Error err = _parse_construct<float>(p_stream, args, line, r_err_str); - if (err) + if (err) { return err; + } if (args.size() != 3) { r_err_str = "Expected 3 arguments for constructor"; @@ -571,8 +582,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, } else if (id == "Vector3i") { Vector<int32_t> args; Error err = _parse_construct<int32_t>(p_stream, args, line, r_err_str); - if (err) + if (err) { return err; + } if (args.size() != 3) { r_err_str = "Expected 3 arguments for constructor"; @@ -584,8 +596,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, Vector<float> args; Error err = _parse_construct<float>(p_stream, args, line, r_err_str); - if (err) + if (err) { return err; + } if (args.size() != 6) { r_err_str = "Expected 6 arguments for constructor"; @@ -599,8 +612,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, } else if (id == "Plane") { Vector<float> args; Error err = _parse_construct<float>(p_stream, args, line, r_err_str); - if (err) + if (err) { return err; + } if (args.size() != 4) { r_err_str = "Expected 4 arguments for constructor"; @@ -611,8 +625,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, } else if (id == "Quat") { Vector<float> args; Error err = _parse_construct<float>(p_stream, args, line, r_err_str); - if (err) + if (err) { return err; + } if (args.size() != 4) { r_err_str = "Expected 4 arguments for constructor"; @@ -624,8 +639,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, } else if (id == "AABB" || id == "Rect3") { Vector<float> args; Error err = _parse_construct<float>(p_stream, args, line, r_err_str); - if (err) + if (err) { return err; + } if (args.size() != 6) { r_err_str = "Expected 6 arguments for constructor"; @@ -638,8 +654,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, Vector<float> args; Error err = _parse_construct<float>(p_stream, args, line, r_err_str); - if (err) + if (err) { return err; + } if (args.size() != 9) { r_err_str = "Expected 9 arguments for constructor"; @@ -650,8 +667,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, } else if (id == "Transform") { Vector<float> args; Error err = _parse_construct<float>(p_stream, args, line, r_err_str); - if (err) + if (err) { return err; + } if (args.size() != 12) { r_err_str = "Expected 12 arguments for constructor"; @@ -663,8 +681,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, } else if (id == "Color") { Vector<float> args; Error err = _parse_construct<float>(p_stream, args, line, r_err_str); - if (err) + if (err) { return err; + } if (args.size() != 4) { r_err_str = "Expected 4 arguments for constructor"; @@ -758,8 +777,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, if (at_key) { Error err = get_token(p_stream, token2, line, r_err_str); - if (err != OK) + if (err != OK) { return err; + } if (token2.type == TK_PARENTHESIS_CLOSE) { Reference *reference = Object::cast_to<Reference>(obj); @@ -790,8 +810,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, err = get_token(p_stream, token2, line, r_err_str); - if (err != OK) + if (err != OK) { return err; + } if (token2.type != TK_COLON) { r_err_str = "Expected ':'"; return ERR_PARSE_ERROR; @@ -799,13 +820,15 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, at_key = false; } else { Error err = get_token(p_stream, token2, line, r_err_str); - if (err != OK) + if (err != OK) { return err; + } Variant v; err = parse_value(token2, v, p_stream, line, r_err_str, p_res_parser); - if (err) + if (err) { return err; + } obj->set(key, v); need_comma = true; at_key = true; @@ -822,8 +845,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, if (p_res_parser && id == "Resource" && p_res_parser->func) { RES res; Error err = p_res_parser->func(p_res_parser->userdata, p_stream, res, line, r_err_str); - if (err) + if (err) { return err; + } value = res; @@ -831,8 +855,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, } else if (p_res_parser && id == "ExtResource" && p_res_parser->ext_func) { RES res; Error err = p_res_parser->ext_func(p_res_parser->userdata, p_stream, res, line, r_err_str); - if (err) + if (err) { return err; + } value = res; @@ -840,8 +865,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, } else if (p_res_parser && id == "SubResource" && p_res_parser->sub_func) { RES res; Error err = p_res_parser->sub_func(p_res_parser->userdata, p_stream, res, line, r_err_str); - if (err) + if (err) { return err; + } value = res; @@ -874,8 +900,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, } else if (id == "PackedByteArray" || id == "PoolByteArray" || id == "ByteArray") { Vector<uint8_t> args; Error err = _parse_construct<uint8_t>(p_stream, args, line, r_err_str); - if (err) + if (err) { return err; + } Vector<uint8_t> arr; { @@ -894,8 +921,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, } else if (id == "PackedInt32Array" || id == "PackedIntArray" || id == "PoolIntArray" || id == "IntArray") { Vector<int32_t> args; Error err = _parse_construct<int32_t>(p_stream, args, line, r_err_str); - if (err) + if (err) { return err; + } Vector<int32_t> arr; { @@ -914,8 +942,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, } else if (id == "PackedInt64Array") { Vector<int64_t> args; Error err = _parse_construct<int64_t>(p_stream, args, line, r_err_str); - if (err) + if (err) { return err; + } Vector<int64_t> arr; { @@ -934,8 +963,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, } else if (id == "PackedFloat32Array" || id == "PackedRealArray" || id == "PoolRealArray" || id == "FloatArray") { Vector<float> args; Error err = _parse_construct<float>(p_stream, args, line, r_err_str); - if (err) + if (err) { return err; + } Vector<float> arr; { @@ -953,8 +983,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, } else if (id == "PackedFloat64Array") { Vector<double> args; Error err = _parse_construct<double>(p_stream, args, line, r_err_str); - if (err) + if (err) { return err; + } Vector<double> arr; { @@ -1021,8 +1052,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, } else if (id == "PackedVector2Array" || id == "PoolVector2Array" || id == "Vector2Array") { Vector<float> args; Error err = _parse_construct<float>(p_stream, args, line, r_err_str); - if (err) + if (err) { return err; + } Vector<Vector2> arr; { @@ -1041,8 +1073,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, } else if (id == "PackedVector3Array" || id == "PoolVector3Array" || id == "Vector3Array") { Vector<float> args; Error err = _parse_construct<float>(p_stream, args, line, r_err_str); - if (err) + if (err) { return err; + } Vector<Vector3> arr; { @@ -1061,8 +1094,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, } else if (id == "PackedColorArray" || id == "PoolColorArray" || id == "ColorArray") { Vector<float> args; Error err = _parse_construct<float>(p_stream, args, line, r_err_str); - if (err) + if (err) { return err; + } Vector<Color> arr; { @@ -1113,8 +1147,9 @@ Error VariantParser::_parse_array(Array &array, Stream *p_stream, int &line, Str } Error err = get_token(p_stream, token, line, r_err_str); - if (err != OK) + if (err != OK) { return err; + } if (token.type == TK_BRACKET_CLOSE) { return OK; @@ -1132,8 +1167,9 @@ Error VariantParser::_parse_array(Array &array, Stream *p_stream, int &line, Str Variant v; err = parse_value(token, v, p_stream, line, r_err_str, p_res_parser); - if (err) + if (err) { return err; + } array.push_back(v); need_comma = true; @@ -1154,8 +1190,9 @@ Error VariantParser::_parse_dictionary(Dictionary &object, Stream *p_stream, int if (at_key) { Error err = get_token(p_stream, token, line, r_err_str); - if (err != OK) + if (err != OK) { return err; + } if (token.type == TK_CURLY_BRACKET_CLOSE) { return OK; @@ -1173,13 +1210,15 @@ Error VariantParser::_parse_dictionary(Dictionary &object, Stream *p_stream, int err = parse_value(token, key, p_stream, line, r_err_str, p_res_parser); - if (err) + if (err) { return err; + } err = get_token(p_stream, token, line, r_err_str); - if (err != OK) + if (err != OK) { return err; + } if (token.type != TK_COLON) { r_err_str = "Expected ':'"; return ERR_PARSE_ERROR; @@ -1187,13 +1226,15 @@ Error VariantParser::_parse_dictionary(Dictionary &object, Stream *p_stream, int at_key = false; } else { Error err = get_token(p_stream, token, line, r_err_str); - if (err != OK) + if (err != OK) { return err; + } Variant v; err = parse_value(token, v, p_stream, line, r_err_str, p_res_parser); - if (err) + if (err) { return err; + } object[key] = v; need_comma = true; at_key = true; @@ -1219,8 +1260,9 @@ Error VariantParser::_parse_tag(Token &token, Stream *p_stream, int &line, Strin r_err_str = "Unexpected EOF while parsing simple tag"; return ERR_PARSE_ERROR; } - if (c == ']') + if (c == ']') { break; + } r_tag.name += String::chr(c); } @@ -1246,8 +1288,9 @@ Error VariantParser::_parse_tag(Token &token, Stream *p_stream, int &line, Strin } get_token(p_stream, token, line, r_err_str); - if (token.type == TK_BRACKET_CLOSE) + if (token.type == TK_BRACKET_CLOSE) { break; + } if (parsing_tag && token.type == TK_PERIOD) { r_tag.name += "."; //support tags such as [someprop.Android] for specific platforms @@ -1279,8 +1322,9 @@ Error VariantParser::_parse_tag(Token &token, Stream *p_stream, int &line, Strin get_token(p_stream, token, line, r_err_str); Variant value; Error err = parse_value(token, value, p_stream, line, r_err_str, p_res_parser); - if (err) + if (err) { return err; + } r_tag.fields[id] = value; } @@ -1319,8 +1363,9 @@ Error VariantParser::parse_tag_assign_eof(Stream *p_stream, int &line, String &r c = p_stream->get_char(); } - if (p_stream->is_eof()) + if (p_stream->is_eof()) { return ERR_FILE_EOF; + } if (c == ';') { //comment while (true) { @@ -1328,8 +1373,9 @@ Error VariantParser::parse_tag_assign_eof(Stream *p_stream, int &line, String &r if (p_stream->is_eof()) { return ERR_FILE_EOF; } - if (ch == '\n') + if (ch == '\n') { break; + } } continue; } @@ -1348,8 +1394,9 @@ Error VariantParser::parse_tag_assign_eof(Stream *p_stream, int &line, String &r p_stream->saved = '"'; Token tk; Error err = get_token(p_stream, tk, line, r_err_str); - if (err) + if (err) { return err; + } if (tk.type != TK_STRING) { r_err_str = "Error reading quoted string"; return ERR_INVALID_DATA; @@ -1375,8 +1422,9 @@ Error VariantParser::parse_tag_assign_eof(Stream *p_stream, int &line, String &r Error VariantParser::parse(Stream *p_stream, Variant &r_ret, String &r_err_str, int &r_err_line, ResourceParser *p_res_parser) { Token token; Error err = get_token(p_stream, token, r_err_line, r_err_str); - if (err) + if (err) { return err; + } if (token.type == TK_EOF) { return ERR_FILE_EOF; @@ -1390,10 +1438,11 @@ Error VariantParser::parse(Stream *p_stream, Variant &r_ret, String &r_err_str, //////////////////////////////////////////////////////////////////////////////// static String rtosfix(double p_value) { - if (p_value == 0.0) + if (p_value == 0.0) { return "0"; //avoid negative zero (-0) being written, which may annoy git, svn, etc. for changes when they don't exist. - else + } else { return rtoss(p_value); + } } Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_string_func, void *p_store_string_ud, EncodeResourceFunc p_encode_res_func, void *p_encode_res_ud) { @@ -1410,8 +1459,9 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str case Variant::FLOAT: { String s = rtosfix(p_variant.operator real_t()); if (s != "inf" && s != "nan") { - if (s.find(".") == -1 && s.find("e") == -1) + if (s.find(".") == -1 && s.find("e") == -1) { s += ".0"; + } } p_store_string_func(p_store_string_ud, s); } break; @@ -1467,8 +1517,9 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str Transform2D m3 = p_variant; for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) { - if (i != 0 || j != 0) + if (i != 0 || j != 0) { s += ", "; + } s += rtosfix(m3.elements[i][j]); } } @@ -1481,8 +1532,9 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str Basis m3 = p_variant; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - if (i != 0 || j != 0) + if (i != 0 || j != 0) { s += ", "; + } s += rtosfix(m3.elements[i][j]); } } @@ -1496,8 +1548,9 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str Basis &m3 = t.basis; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - if (i != 0 || j != 0) + if (i != 0 || j != 0) { s += ", "; + } s += rtosfix(m3.elements[i][j]); } } @@ -1602,8 +1655,9 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str write(E->get(), p_store_string_func, p_store_string_ud, p_encode_res_func, p_encode_res_ud); p_store_string_func(p_store_string_ud, ": "); write(dict[E->get()], p_store_string_func, p_store_string_ud, p_encode_res_func, p_encode_res_ud); - if (E->next()) + if (E->next()) { p_store_string_func(p_store_string_ud, ",\n"); + } } p_store_string_func(p_store_string_ud, "\n}"); @@ -1614,8 +1668,9 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str Array array = p_variant; int len = array.size(); for (int i = 0; i < len; i++) { - if (i > 0) + if (i > 0) { p_store_string_func(p_store_string_ud, ", "); + } write(array[i], p_store_string_func, p_store_string_ud, p_encode_res_func, p_encode_res_ud); } p_store_string_func(p_store_string_ud, " ]"); @@ -1630,8 +1685,9 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str const uint8_t *ptr = data.ptr(); for (int i = 0; i < len; i++) { - if (i > 0) + if (i > 0) { p_store_string_func(p_store_string_ud, ", "); + } p_store_string_func(p_store_string_ud, itos(ptr[i])); } @@ -1646,8 +1702,9 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str const int32_t *ptr = data.ptr(); for (int32_t i = 0; i < len; i++) { - if (i > 0) + if (i > 0) { p_store_string_func(p_store_string_ud, ", "); + } p_store_string_func(p_store_string_ud, itos(ptr[i])); } @@ -1662,8 +1719,9 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str const int64_t *ptr = data.ptr(); for (int64_t i = 0; i < len; i++) { - if (i > 0) + if (i > 0) { p_store_string_func(p_store_string_ud, ", "); + } p_store_string_func(p_store_string_ud, itos(ptr[i])); } @@ -1678,8 +1736,9 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str const float *ptr = data.ptr(); for (int i = 0; i < len; i++) { - if (i > 0) + if (i > 0) { p_store_string_func(p_store_string_ud, ", "); + } p_store_string_func(p_store_string_ud, rtosfix(ptr[i])); } @@ -1693,8 +1752,9 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str const double *ptr = data.ptr(); for (int i = 0; i < len; i++) { - if (i > 0) + if (i > 0) { p_store_string_func(p_store_string_ud, ", "); + } p_store_string_func(p_store_string_ud, rtosfix(ptr[i])); } @@ -1711,8 +1771,9 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str //write_string("\n"); for (int i = 0; i < len; i++) { - if (i > 0) + if (i > 0) { p_store_string_func(p_store_string_ud, ", "); + } String str = ptr[i]; p_store_string_func(p_store_string_ud, "\"" + str.c_escape() + "\""); } @@ -1727,8 +1788,9 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str const Vector2 *ptr = data.ptr(); for (int i = 0; i < len; i++) { - if (i > 0) + if (i > 0) { p_store_string_func(p_store_string_ud, ", "); + } p_store_string_func(p_store_string_ud, rtosfix(ptr[i].x) + ", " + rtosfix(ptr[i].y)); } @@ -1742,8 +1804,9 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str const Vector3 *ptr = data.ptr(); for (int i = 0; i < len; i++) { - if (i > 0) + if (i > 0) { p_store_string_func(p_store_string_ud, ", "); + } p_store_string_func(p_store_string_ud, rtosfix(ptr[i].x) + ", " + rtosfix(ptr[i].y) + ", " + rtosfix(ptr[i].z)); } @@ -1758,8 +1821,9 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str const Color *ptr = data.ptr(); for (int i = 0; i < len; i++) { - if (i > 0) + if (i > 0) { p_store_string_func(p_store_string_ud, ", "); + } p_store_string_func(p_store_string_ud, rtosfix(ptr[i].r) + ", " + rtosfix(ptr[i].g) + ", " + rtosfix(ptr[i].b) + ", " + rtosfix(ptr[i].a)); } diff --git a/core/vector.h b/core/vector.h index 4521b29339..696984ac28 100644 --- a/core/vector.h +++ b/core/vector.h @@ -70,8 +70,9 @@ public: void remove(int p_index) { _cowdata.remove(p_index); } void erase(const T &p_val) { int idx = find(p_val); - if (idx >= 0) + if (idx >= 0) { remove(idx); + } } void invert(); @@ -94,8 +95,9 @@ public: template <class C> void sort_custom() { int len = _cowdata.size(); - if (len == 0) + if (len == 0) { return; + } T *data = ptrw(); SortArray<T, C> sorter; @@ -168,12 +170,14 @@ void Vector<T>::invert() { template <class T> void Vector<T>::append_array(Vector<T> p_other) { const int ds = p_other.size(); - if (ds == 0) + if (ds == 0) { return; + } const int bs = size(); resize(bs + ds); - for (int i = 0; i < ds; ++i) + for (int i = 0; i < ds; ++i) { ptrw()[bs + i] = p_other[i]; + } } template <class T> diff --git a/core/vmap.h b/core/vmap.h index 358b6260a4..c91ea9b3c9 100644 --- a/core/vmap.h +++ b/core/vmap.h @@ -54,8 +54,9 @@ private: _FORCE_INLINE_ int _find(const T &p_val, bool &r_exact) const { r_exact = false; - if (_cowdata.empty()) + if (_cowdata.empty()) { return 0; + } int low = 0; int high = _cowdata.size() - 1; @@ -63,8 +64,9 @@ private: int middle = 0; #ifdef DEBUG_ENABLED - if (low > high) + if (low > high) { ERR_PRINT("low > high, this may be a bug"); + } #endif while (low <= high) { middle = (low + high) / 2; @@ -80,14 +82,16 @@ private: } //return the position where this would be inserted - if (a[middle].key < p_val) + if (a[middle].key < p_val) { middle++; + } return middle; } _FORCE_INLINE_ int _find_exact(const T &p_val) const { - if (_cowdata.empty()) + if (_cowdata.empty()) { return -1; + } int low = 0; int high = _cowdata.size() - 1; @@ -127,8 +131,9 @@ public: void erase(const T &p_val) { int pos = _find_exact(p_val); - if (pos < 0) + if (pos < 0) { return; + } _cowdata.remove(pos); } diff --git a/core/vset.h b/core/vset.h index 45516bdb05..034b8fe851 100644 --- a/core/vset.h +++ b/core/vset.h @@ -40,8 +40,9 @@ class VSet { _FORCE_INLINE_ int _find(const T &p_val, bool &r_exact) const { r_exact = false; - if (_data.empty()) + if (_data.empty()) { return 0; + } int low = 0; int high = _data.size() - 1; @@ -49,8 +50,9 @@ class VSet { int middle = 0; #ifdef DEBUG_ENABLED - if (low > high) + if (low > high) { ERR_PRINT("low > high, this may be a bug"); + } #endif while (low <= high) { @@ -67,14 +69,16 @@ class VSet { } //return the position where this would be inserted - if (a[middle] < p_val) + if (a[middle] < p_val) { middle++; + } return middle; } _FORCE_INLINE_ int _find_exact(const T &p_val) const { - if (_data.empty()) + if (_data.empty()) { return -1; + } int low = 0; int high = _data.size() - 1; @@ -100,8 +104,9 @@ public: void insert(const T &p_val) { bool exact; int pos = _find(p_val, exact); - if (exact) + if (exact) { return; + } _data.insert(pos, p_val); } @@ -111,8 +116,9 @@ public: void erase(const T &p_val) { int pos = _find_exact(p_val); - if (pos < 0) + if (pos < 0) { return; + } _data.remove(pos); } |