Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Style: Apply selected clang-tidy checks #47642

Merged
merged 4 commits into from
Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/crypto/crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,9 @@ RES ResourceFormatLoaderCrypto::load(const String &p_path, const String &p_origi
return key;
} else if (el == "pub") {
CryptoKey *key = CryptoKey::create();
if (key)
if (key) {
key->load(p_path, true);
}
return key;
}
return nullptr;
Expand Down
29 changes: 17 additions & 12 deletions core/math/dynamic_bvh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ DynamicBVH::Node *DynamicBVH::_create_node_with_volume(Node *p_parent, const Vol
void DynamicBVH::_insert_leaf(Node *p_root, Node *p_leaf) {
if (!bvh_root) {
bvh_root = p_leaf;
p_leaf->parent = 0;
p_leaf->parent = nullptr;
} else {
if (!p_root->is_leaf()) {
do {
Expand All @@ -71,7 +71,7 @@ void DynamicBVH::_insert_leaf(Node *p_root, Node *p_leaf) {
} while (!p_root->is_leaf());
}
Node *prev = p_root->parent;
Node *node = _create_node_with_volume(prev, p_leaf->volume.merge(p_root->volume), 0);
Node *node = _create_node_with_volume(prev, p_leaf->volume.merge(p_root->volume), nullptr);
if (prev) {
prev->childs[p_root->get_index_in_parent()] = node;
node->childs[0] = p_root;
Expand All @@ -85,7 +85,7 @@ void DynamicBVH::_insert_leaf(Node *p_root, Node *p_leaf) {
break;
}
node = prev;
} while (0 != (prev = node->parent));
} while (nullptr != (prev = node->parent));
} else {
node->childs[0] = p_root;
p_root->parent = node;
Expand All @@ -98,8 +98,8 @@ void DynamicBVH::_insert_leaf(Node *p_root, Node *p_leaf) {

DynamicBVH::Node *DynamicBVH::_remove_leaf(Node *leaf) {
if (leaf == bvh_root) {
bvh_root = 0;
return (0);
bvh_root = nullptr;
return (nullptr);
} else {
Node *parent = leaf->parent;
Node *prev = parent->parent;
Expand All @@ -113,13 +113,14 @@ DynamicBVH::Node *DynamicBVH::_remove_leaf(Node *leaf) {
prev->volume = prev->childs[0]->volume.merge(prev->childs[1]->volume);
if (pb.is_not_equal_to(prev->volume)) {
prev = prev->parent;
} else
} else {
break;
}
}
return (prev ? prev : bvh_root);
} else {
bvh_root = sibling;
sibling->parent = 0;
sibling->parent = nullptr;
_delete_node(parent);
return (bvh_root);
}
Expand Down Expand Up @@ -262,10 +263,11 @@ DynamicBVH::Node *DynamicBVH::_node_sort(Node *n, Node *&r) {
Node *s = p->childs[j];
Node *q = p->parent;
ERR_FAIL_COND_V(n != p->childs[i], nullptr);
if (q)
if (q) {
q->childs[p->get_index_in_parent()] = n;
else
} else {
r = n;
}
s->parent = n;
p->parent = n;
n->parent = q;
Expand Down Expand Up @@ -307,8 +309,9 @@ void DynamicBVH::optimize_top_down(int bu_threshold) {
}

void DynamicBVH::optimize_incremental(int passes) {
if (passes < 0)
if (passes < 0) {
passes = total_leaves;
}
if (bvh_root && (passes > 0)) {
do {
Node *node = bvh_root;
Expand Down Expand Up @@ -345,8 +348,9 @@ void DynamicBVH::_update(Node *leaf, int lookahead) {
for (int i = 0; (i < lookahead) && root->parent; ++i) {
root = root->parent;
}
} else
} else {
root = bvh_root;
}
}
_insert_leaf(root, leaf);
}
Expand All @@ -370,8 +374,9 @@ bool DynamicBVH::update(const ID &p_id, const AABB &p_box) {
for (int i = 0; (i < lkhd) && base->parent; ++i) {
base = base->parent;
}
} else
} else {
base = bvh_root;
}
}
leaf->volume = volume;
_insert_leaf(base, leaf);
Expand Down
35 changes: 22 additions & 13 deletions core/math/dynamic_bvh.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,16 @@ class DynamicBVH {
_FORCE_INLINE_ Volume merge(const Volume &b) const {
Volume r;
for (int i = 0; i < 3; ++i) {
if (min[i] < b.min[i])
if (min[i] < b.min[i]) {
r.min[i] = min[i];
else
} else {
r.min[i] = b.min[i];
if (max[i] > b.max[i])
}
if (max[i] > b.max[i]) {
r.max[i] = max[i];
else
} else {
r.max[i] = b.max[i];
}
}
return r;
}
Expand Down Expand Up @@ -202,10 +204,11 @@ class DynamicBVH {

//
int count_leaves() const {
if (is_internal())
if (is_internal()) {
return childs[0]->count_leaves() + childs[1]->count_leaves();
else
} else {
return (1);
}
}

bool is_left_of_axis(const Vector3 &org, const Vector3 &axis) const {
Expand Down Expand Up @@ -254,31 +257,37 @@ class DynamicBVH {
tymin = (bounds[raySign[1]].y - rayFrom.y) * rayInvDirection.y;
tymax = (bounds[1 - raySign[1]].y - rayFrom.y) * rayInvDirection.y;

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;
}

tzmin = (bounds[raySign[2]].z - rayFrom.z) * rayInvDirection.z;
tzmax = (bounds[1 - raySign[2]].z - rayFrom.z) * rayInvDirection.z;

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 < lambda_max) && (tmax > lambda_min));
}

public:
// Methods
void clear();
bool is_empty() const { return (0 == bvh_root); }
bool is_empty() const { return (nullptr == bvh_root); }
void optimize_bottom_up();
void optimize_top_down(int bu_threshold = 128);
void optimize_incremental(int passes);
Expand Down
6 changes: 4 additions & 2 deletions core/variant/variant_setget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -891,8 +891,9 @@ struct VariantIndexedSetGet_Array {
static void ptr_get(const void *base, int64_t index, void *member) {
/* avoid ptrconvert for performance*/
const Array &v = *reinterpret_cast<const Array *>(base);
if (index < 0)
if (index < 0) {
index += v.size();
}
OOB_TEST(index, v.size());
PtrToArg<Variant>::encode(v[index], member);
}
Expand Down Expand Up @@ -925,8 +926,9 @@ struct VariantIndexedSetGet_Array {
static void ptr_set(void *base, int64_t index, const void *member) {
/* avoid ptrconvert for performance*/
Array &v = *reinterpret_cast<Array *>(base);
if (index < 0)
if (index < 0) {
index += v.size();
}
OOB_TEST(index, v.size());
v.set(index, PtrToArg<Variant>::convert(member));
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/vulkan/vulkan_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ Error VulkanContext::_check_capabilities() {
if (func != nullptr) {
VkPhysicalDeviceSubgroupProperties subgroupProperties;
subgroupProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES;
subgroupProperties.pNext = NULL;
subgroupProperties.pNext = nullptr;

VkPhysicalDeviceProperties2 physicalDeviceProperties;
physicalDeviceProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
Expand Down
6 changes: 3 additions & 3 deletions editor/editor_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2570,9 +2570,9 @@ void EditorInspector::_update_script_class_properties(const Object &p_object, Li
}

// Script Variables -> to insert: NodeC..B..A -> bottom (insert_here)
List<PropertyInfo>::Element *script_variables = NULL;
List<PropertyInfo>::Element *bottom = NULL;
List<PropertyInfo>::Element *insert_here = NULL;
List<PropertyInfo>::Element *script_variables = nullptr;
List<PropertyInfo>::Element *bottom = nullptr;
List<PropertyInfo>::Element *insert_here = nullptr;
for (List<PropertyInfo>::Element *E = r_list.front(); E; E = E->next()) {
PropertyInfo &pi = E->get();
if (pi.name != "Script Variables") {
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1379,7 +1379,7 @@ void EditorNode::_save_scene_with_preview(String p_file, int p_idx) {
// which would result in an invalid texture.
if (c3d == 0 && c2d == 0) {
img.instance();
img->create(1, 1, 0, Image::FORMAT_RGB8);
img->create(1, 1, false, Image::FORMAT_RGB8);
} else if (c3d < c2d) {
Ref<ViewportTexture> viewport_texture = scene_root->get_texture();
if (viewport_texture->get_width() > 0 && viewport_texture->get_height() > 0) {
Expand Down
6 changes: 4 additions & 2 deletions editor/editor_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,14 +649,16 @@ class EditorPropertyLayersGrid : public Control {
Color color = get_theme_color("highlight_color", "Editor");
for (int i = 0; i < 2; i++) {
Point2 ofs(4, vofs);
if (i == 1)
if (i == 1) {
ofs.y += bsize + 1;
}

ofs += rect.position;
for (int j = 0; j < 10; j++) {
Point2 o = ofs + Point2(j * (bsize + 1), 0);
if (j >= 5)
if (j >= 5) {
o.x += 1;
}

const int idx = i * 10 + j;
const bool on = value & (1 << idx);
Expand Down
6 changes: 4 additions & 2 deletions editor/editor_translation_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@
EditorTranslationParser *EditorTranslationParser::singleton = nullptr;

Error EditorTranslationParserPlugin::parse_file(const String &p_path, Vector<String> *r_ids, Vector<Vector<String>> *r_ids_ctx_plural) {
if (!get_script_instance())
if (!get_script_instance()) {
return ERR_UNAVAILABLE;
}

if (get_script_instance()->has_method("parse_file")) {
Array ids;
Expand Down Expand Up @@ -70,8 +71,9 @@ Error EditorTranslationParserPlugin::parse_file(const String &p_path, Vector<Str
}

void EditorTranslationParserPlugin::get_recognized_extensions(List<String> *r_extensions) const {
if (!get_script_instance())
if (!get_script_instance()) {
return;
}

if (get_script_instance()->has_method("get_recognized_extensions")) {
Array extensions = get_script_instance()->call("get_recognized_extensions");
Expand Down
6 changes: 4 additions & 2 deletions editor/filesystem_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2621,8 +2621,9 @@ void FileSystemDock::_get_imported_files(const String &p_path, Vector<String> &f
}

void FileSystemDock::_update_import_dock() {
if (!import_dock_needs_update)
if (!import_dock_needs_update) {
return;
}

// List selected.
Vector<String> selected;
Expand All @@ -2633,8 +2634,9 @@ void FileSystemDock::_update_import_dock() {
} else {
// Use the file list.
for (int i = 0; i < files->get_item_count(); i++) {
if (!files->is_selected(i))
if (!files->is_selected(i)) {
continue;
}

selected.push_back(files->get_item_metadata(i));
}
Expand Down
2 changes: 1 addition & 1 deletion editor/import/editor_import_collada.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1688,7 +1688,7 @@ Node *EditorSceneImporterCollada::import_scene(const String &p_path, uint32_t p_
state.use_mesh_builtin_materials = true;
state.bake_fps = p_bake_fps;

Error err = state.load(p_path, flags, p_flags & EditorSceneImporter::IMPORT_GENERATE_TANGENT_ARRAYS, 0);
Error err = state.load(p_path, flags, p_flags & EditorSceneImporter::IMPORT_GENERATE_TANGENT_ARRAYS, false);

if (r_err) {
*r_err = err;
Expand Down
2 changes: 1 addition & 1 deletion editor/import/resource_importer_obj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ static Error _parse_obj(const String &p_path, List<Ref<Mesh>> &r_meshes, bool p_
Node *EditorOBJImporter::import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, List<String> *r_missing_deps, Error *r_err) {
List<Ref<Mesh>> meshes;

Error err = _parse_obj(p_path, meshes, false, p_flags & IMPORT_GENERATE_TANGENT_ARRAYS, 0, Vector3(1, 1, 1), Vector3(0, 0, 0), r_missing_deps);
Error err = _parse_obj(p_path, meshes, false, p_flags & IMPORT_GENERATE_TANGENT_ARRAYS, false, Vector3(1, 1, 1), Vector3(0, 0, 0), r_missing_deps);

if (err != OK) {
if (r_err) {
Expand Down
Loading