1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-12 13:20:55 +00:00

Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks

This commit is contained in:
Rémi Verschelde
2021-05-04 14:41:06 +02:00
parent 64a63e0861
commit b5e1e05ef2
1439 changed files with 1 additions and 34187 deletions

View File

@@ -33,30 +33,25 @@
#include "core/sort_array.h"
int TriangleMesh::_create_bvh(BVH *p_bvh, BVH **p_bb, int p_from, int p_size, int p_depth, int &max_depth, int &max_alloc) {
if (p_depth > max_depth) {
max_depth = p_depth;
}
if (p_size == 1) {
return p_bb[p_from] - p_bvh;
} else if (p_size == 0) {
return -1;
}
AABB aabb;
aabb = p_bb[p_from]->aabb;
for (int i = 1; i < p_size; i++) {
aabb.merge_with(p_bb[p_from + i]->aabb);
}
int li = aabb.get_longest_axis_index();
switch (li) {
case Vector3::AXIS_X: {
SortArray<BVH *, BVHCmpX> sort_x;
sort_x.nth_element(0, p_size, p_size / 2, &p_bb[p_from]);
@@ -90,7 +85,6 @@ int TriangleMesh::_create_bvh(BVH *p_bvh, BVH **p_bb, int p_from, int p_size, in
}
void TriangleMesh::get_indices(PoolVector<int> *r_triangles_indices) const {
if (!valid)
return;
@@ -110,7 +104,6 @@ void TriangleMesh::get_indices(PoolVector<int> *r_triangles_indices) const {
}
void TriangleMesh::create(const PoolVector<Vector3> &p_faces) {
valid = false;
int fc = p_faces.size();
@@ -122,7 +115,6 @@ void TriangleMesh::create(const PoolVector<Vector3> &p_faces) {
PoolVector<BVH>::Write bw = bvh.write();
{
//create faces and indices and base bvh
//except for the Set for repeated triangles, everything
//goes in-place.
@@ -132,12 +124,10 @@ void TriangleMesh::create(const PoolVector<Vector3> &p_faces) {
Map<Vector3, int> db;
for (int i = 0; i < fc; i++) {
Triangle &f = w[i];
const Vector3 *v = &r[i * 3];
for (int j = 0; j < 3; j++) {
int vidx = -1;
Vector3 vs = v[j].snapped(Vector3(0.0001, 0.0001, 0.0001));
Map<Vector3, int>::Element *E = db.find(vs);
@@ -174,7 +164,6 @@ void TriangleMesh::create(const PoolVector<Vector3> &p_faces) {
bwptrs.resize(fc);
PoolVector<BVH *>::Write bwp = bwptrs.write();
for (int i = 0; i < fc; i++) {
bwp[i] = &bw[i];
}
@@ -189,7 +178,6 @@ void TriangleMesh::create(const PoolVector<Vector3> &p_faces) {
}
Vector3 TriangleMesh::get_area_normal(const AABB &p_aabb) const {
uint32_t *stack = (uint32_t *)alloca(sizeof(int) * max_depth);
enum {
@@ -218,23 +206,18 @@ Vector3 TriangleMesh::get_area_normal(const AABB &p_aabb) const {
stack[0] = pos;
while (true) {
uint32_t node = stack[level] & NODE_IDX_MASK;
const BVH &b = bvhptr[node];
bool done = false;
switch (stack[level] >> VISITED_BIT_SHIFT) {
case TEST_AABB_BIT: {
bool valid = b.aabb.intersects(p_aabb);
if (!valid) {
stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
} else {
if (b.face_index >= 0) {
const Triangle &s = triangleptr[b.face_index];
n += s.normal;
n_count++;
@@ -242,28 +225,24 @@ Vector3 TriangleMesh::get_area_normal(const AABB &p_aabb) const {
stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
} else {
stack[level] = (VISIT_LEFT_BIT << VISITED_BIT_SHIFT) | node;
}
}
continue;
}
case VISIT_LEFT_BIT: {
stack[level] = (VISIT_RIGHT_BIT << VISITED_BIT_SHIFT) | node;
stack[level + 1] = b.left | TEST_AABB_BIT;
level++;
continue;
}
case VISIT_RIGHT_BIT: {
stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
stack[level + 1] = b.right | TEST_AABB_BIT;
level++;
continue;
}
case VISIT_DONE_BIT: {
if (level == 0) {
done = true;
break;
@@ -284,7 +263,6 @@ Vector3 TriangleMesh::get_area_normal(const AABB &p_aabb) const {
}
bool TriangleMesh::intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_point, Vector3 &r_normal) const {
uint32_t *stack = (uint32_t *)alloca(sizeof(int) * max_depth);
enum {
@@ -315,35 +293,28 @@ bool TriangleMesh::intersect_segment(const Vector3 &p_begin, const Vector3 &p_en
stack[0] = pos;
while (true) {
uint32_t node = stack[level] & NODE_IDX_MASK;
const BVH &b = bvhptr[node];
bool done = false;
switch (stack[level] >> VISITED_BIT_SHIFT) {
case TEST_AABB_BIT: {
bool valid = b.aabb.intersects_segment(p_begin, p_end);
//bool valid = b.aabb.intersects(ray_aabb);
if (!valid) {
stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
} else {
if (b.face_index >= 0) {
const Triangle &s = triangleptr[b.face_index];
Face3 f3(vertexptr[s.indices[0]], vertexptr[s.indices[1]], vertexptr[s.indices[2]]);
Vector3 res;
if (f3.intersects_segment(p_begin, p_end, &res)) {
real_t nd = n.dot(res);
if (nd < d) {
d = nd;
r_point = res;
r_normal = f3.get_plane().get_normal();
@@ -354,28 +325,24 @@ bool TriangleMesh::intersect_segment(const Vector3 &p_begin, const Vector3 &p_en
stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
} else {
stack[level] = (VISIT_LEFT_BIT << VISITED_BIT_SHIFT) | node;
}
}
continue;
}
case VISIT_LEFT_BIT: {
stack[level] = (VISIT_RIGHT_BIT << VISITED_BIT_SHIFT) | node;
stack[level + 1] = b.left | TEST_AABB_BIT;
level++;
continue;
}
case VISIT_RIGHT_BIT: {
stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
stack[level + 1] = b.right | TEST_AABB_BIT;
level++;
continue;
}
case VISIT_DONE_BIT: {
if (level == 0) {
done = true;
break;
@@ -390,7 +357,6 @@ bool TriangleMesh::intersect_segment(const Vector3 &p_begin, const Vector3 &p_en
}
if (inters) {
if (n.dot(r_normal) > 0)
r_normal = -r_normal;
}
@@ -399,7 +365,6 @@ bool TriangleMesh::intersect_segment(const Vector3 &p_begin, const Vector3 &p_en
}
bool TriangleMesh::intersect_ray(const Vector3 &p_begin, const Vector3 &p_dir, Vector3 &r_point, Vector3 &r_normal) const {
uint32_t *stack = (uint32_t *)alloca(sizeof(int) * max_depth);
enum {
@@ -430,33 +395,26 @@ bool TriangleMesh::intersect_ray(const Vector3 &p_begin, const Vector3 &p_dir, V
stack[0] = pos;
while (true) {
uint32_t node = stack[level] & NODE_IDX_MASK;
const BVH &b = bvhptr[node];
bool done = false;
switch (stack[level] >> VISITED_BIT_SHIFT) {
case TEST_AABB_BIT: {
bool valid = b.aabb.intersects_ray(p_begin, p_dir);
if (!valid) {
stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
} else {
if (b.face_index >= 0) {
const Triangle &s = triangleptr[b.face_index];
Face3 f3(vertexptr[s.indices[0]], vertexptr[s.indices[1]], vertexptr[s.indices[2]]);
Vector3 res;
if (f3.intersects_ray(p_begin, p_dir, &res)) {
real_t nd = n.dot(res);
if (nd < d) {
d = nd;
r_point = res;
r_normal = f3.get_plane().get_normal();
@@ -467,28 +425,24 @@ bool TriangleMesh::intersect_ray(const Vector3 &p_begin, const Vector3 &p_dir, V
stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
} else {
stack[level] = (VISIT_LEFT_BIT << VISITED_BIT_SHIFT) | node;
}
}
continue;
}
case VISIT_LEFT_BIT: {
stack[level] = (VISIT_RIGHT_BIT << VISITED_BIT_SHIFT) | node;
stack[level + 1] = b.left | TEST_AABB_BIT;
level++;
continue;
}
case VISIT_RIGHT_BIT: {
stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
stack[level + 1] = b.right | TEST_AABB_BIT;
level++;
continue;
}
case VISIT_DONE_BIT: {
if (level == 0) {
done = true;
break;
@@ -503,7 +457,6 @@ bool TriangleMesh::intersect_ray(const Vector3 &p_begin, const Vector3 &p_dir, V
}
if (inters) {
if (n.dot(r_normal) > 0)
r_normal = -r_normal;
}
@@ -540,23 +493,18 @@ bool TriangleMesh::intersect_convex_shape(const Plane *p_planes, int p_plane_cou
stack[0] = pos;
while (true) {
uint32_t node = stack[level] & NODE_IDX_MASK;
const BVH &b = bvhptr[node];
bool done = false;
switch (stack[level] >> VISITED_BIT_SHIFT) {
case TEST_AABB_BIT: {
bool valid = b.aabb.intersects_convex_shape(p_planes, p_plane_count, p_points, p_point_count);
if (!valid) {
stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
} else {
if (b.face_index >= 0) {
const Triangle &s = triangleptr[b.face_index];
for (int j = 0; j < 3; ++j) {
@@ -594,28 +542,24 @@ bool TriangleMesh::intersect_convex_shape(const Plane *p_planes, int p_plane_cou
stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
} else {
stack[level] = (VISIT_LEFT_BIT << VISITED_BIT_SHIFT) | node;
}
}
continue;
}
case VISIT_LEFT_BIT: {
stack[level] = (VISIT_RIGHT_BIT << VISITED_BIT_SHIFT) | node;
stack[level + 1] = b.left | TEST_AABB_BIT;
level++;
continue;
}
case VISIT_RIGHT_BIT: {
stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
stack[level + 1] = b.right | TEST_AABB_BIT;
level++;
continue;
}
case VISIT_DONE_BIT: {
if (level == 0) {
done = true;
break;
@@ -661,25 +605,21 @@ bool TriangleMesh::inside_convex_shape(const Plane *p_planes, int p_plane_count,
stack[0] = pos;
while (true) {
uint32_t node = stack[level] & NODE_IDX_MASK;
const BVH &b = bvhptr[node];
bool done = false;
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)
return false;
bool inside = scale.xform(b.aabb).inside_convex_shape(p_planes, p_plane_count);
if (inside) {
stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
} else {
if (b.face_index >= 0) {
const Triangle &s = triangleptr[b.face_index];
for (int j = 0; j < 3; ++j) {
@@ -694,28 +634,24 @@ bool TriangleMesh::inside_convex_shape(const Plane *p_planes, int p_plane_count,
stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
} else {
stack[level] = (VISIT_LEFT_BIT << VISITED_BIT_SHIFT) | node;
}
}
continue;
}
case VISIT_LEFT_BIT: {
stack[level] = (VISIT_RIGHT_BIT << VISITED_BIT_SHIFT) | node;
stack[level + 1] = b.left | TEST_AABB_BIT;
level++;
continue;
}
case VISIT_RIGHT_BIT: {
stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
stack[level + 1] = b.right | TEST_AABB_BIT;
level++;
continue;
}
case VISIT_DONE_BIT: {
if (level == 0) {
done = true;
break;
@@ -733,12 +669,10 @@ bool TriangleMesh::inside_convex_shape(const Plane *p_planes, int p_plane_count,
}
bool TriangleMesh::is_valid() const {
return valid;
}
PoolVector<Face3> TriangleMesh::get_faces() const {
if (!valid)
return PoolVector<Face3>();
@@ -761,7 +695,6 @@ PoolVector<Face3> TriangleMesh::get_faces() const {
}
TriangleMesh::TriangleMesh() {
valid = false;
max_depth = 0;
}