diff options
Diffstat (limited to 'core/math')
-rw-r--r-- | core/math/a_star.cpp | 14 | ||||
-rw-r--r-- | core/math/a_star_grid_2d.cpp | 16 | ||||
-rw-r--r-- | core/math/a_star_grid_2d.h | 2 | ||||
-rw-r--r-- | core/math/bvh.h | 2 | ||||
-rw-r--r-- | core/math/geometry_3d.cpp | 2 | ||||
-rw-r--r-- | core/math/transform_2d.cpp | 39 |
6 files changed, 24 insertions, 51 deletions
diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp index 646bdea758..f0f160940d 100644 --- a/core/math/a_star.cpp +++ b/core/math/a_star.cpp @@ -327,7 +327,7 @@ bool AStar3D::_solve(Point *begin_point, Point *end_point) { bool found_route = false; - Vector<Point *> open_list; + LocalVector<Point *> open_list; SortArray<Point *, SortPoints> sorter; begin_point->g_score = 0; @@ -335,19 +335,19 @@ bool AStar3D::_solve(Point *begin_point, Point *end_point) { open_list.push_back(begin_point); while (!open_list.is_empty()) { - Point *p = open_list[0]; // The currently processed point + Point *p = open_list[0]; // The currently processed point. if (p == end_point) { found_route = true; break; } - sorter.pop_heap(0, open_list.size(), open_list.ptrw()); // Remove the current point from the open list + sorter.pop_heap(0, open_list.size(), open_list.ptr()); // Remove the current point from the open list. open_list.remove_at(open_list.size() - 1); - p->closed_pass = pass; // Mark the point as closed + p->closed_pass = pass; // Mark the point as closed. for (OAHashMap<int64_t, Point *>::Iterator it = p->neighbors.iter(); it.valid; it = p->neighbors.next_iter(it)) { - Point *e = *(it.value); // The neighbor point + Point *e = *(it.value); // The neighbor point. if (!e->enabled || e->closed_pass == pass) { continue; @@ -370,9 +370,9 @@ bool AStar3D::_solve(Point *begin_point, Point *end_point) { e->f_score = e->g_score + _estimate_cost(e->id, end_point->id); if (new_point) { // The position of the new points is already known. - sorter.push_heap(0, open_list.size() - 1, 0, e, open_list.ptrw()); + sorter.push_heap(0, open_list.size() - 1, 0, e, open_list.ptr()); } else { - sorter.push_heap(0, open_list.find(e), 0, e, open_list.ptrw()); + sorter.push_heap(0, open_list.find(e), 0, e, open_list.ptr()); } } } diff --git a/core/math/a_star_grid_2d.cpp b/core/math/a_star_grid_2d.cpp index 677e609763..139dc3afb1 100644 --- a/core/math/a_star_grid_2d.cpp +++ b/core/math/a_star_grid_2d.cpp @@ -265,7 +265,7 @@ AStarGrid2D::Point *AStarGrid2D::_jump(Point *p_from, Point *p_to) { return nullptr; } -void AStarGrid2D::_get_nbors(Point *p_point, List<Point *> &r_nbors) { +void AStarGrid2D::_get_nbors(Point *p_point, LocalVector<Point *> &r_nbors) { bool ts0 = false, td0 = false, ts1 = false, td1 = false, ts2 = false, td2 = false, @@ -378,7 +378,7 @@ bool AStarGrid2D::_solve(Point *p_begin_point, Point *p_end_point) { bool found_route = false; - Vector<Point *> open_list; + LocalVector<Point *> open_list; SortArray<Point *, SortPoints> sorter; p_begin_point->g_score = 0; @@ -394,14 +394,14 @@ bool AStarGrid2D::_solve(Point *p_begin_point, Point *p_end_point) { break; } - sorter.pop_heap(0, open_list.size(), open_list.ptrw()); // Remove the current point from the open list. + sorter.pop_heap(0, open_list.size(), open_list.ptr()); // Remove the current point from the open list. open_list.remove_at(open_list.size() - 1); p->closed_pass = pass; // Mark the point as closed. - List<Point *> nbors; + LocalVector<Point *> nbors; _get_nbors(p, nbors); - for (List<Point *>::Element *E = nbors.front(); E; E = E->next()) { - Point *e = E->get(); // The neighbor point. + + for (Point *e : nbors) { real_t weight_scale = 1.0; if (jumping_enabled) { @@ -433,9 +433,9 @@ bool AStarGrid2D::_solve(Point *p_begin_point, Point *p_end_point) { e->f_score = e->g_score + _estimate_cost(e->id, p_end_point->id); if (new_point) { // The position of the new points is already known. - sorter.push_heap(0, open_list.size() - 1, 0, e, open_list.ptrw()); + sorter.push_heap(0, open_list.size() - 1, 0, e, open_list.ptr()); } else { - sorter.push_heap(0, open_list.find(e), 0, e, open_list.ptrw()); + sorter.push_heap(0, open_list.find(e), 0, e, open_list.ptr()); } } } diff --git a/core/math/a_star_grid_2d.h b/core/math/a_star_grid_2d.h index 6b9012a5e3..e4e62ec360 100644 --- a/core/math/a_star_grid_2d.h +++ b/core/math/a_star_grid_2d.h @@ -124,7 +124,7 @@ private: // Internal routines. return &points[p_y][p_x]; } - void _get_nbors(Point *p_point, List<Point *> &r_nbors); + void _get_nbors(Point *p_point, LocalVector<Point *> &r_nbors); Point *_jump(Point *p_from, Point *p_to); bool _solve(Point *p_begin_point, Point *p_end_point); diff --git a/core/math/bvh.h b/core/math/bvh.h index 357d483375..ea8289607e 100644 --- a/core/math/bvh.h +++ b/core/math/bvh.h @@ -780,7 +780,7 @@ private: if (p_thread_safe) { _mutex = p_mutex; - if (_mutex->try_lock() != OK) { + if (!_mutex->try_lock()) { WARN_PRINT("Info : multithread BVH access detected (benign)"); _mutex->lock(); } diff --git a/core/math/geometry_3d.cpp b/core/math/geometry_3d.cpp index 4786110054..590483bf20 100644 --- a/core/math/geometry_3d.cpp +++ b/core/math/geometry_3d.cpp @@ -151,7 +151,7 @@ void Geometry3D::MeshData::optimize_vertices() { } } - for (MeshData::Edge edge : edges) { + for (MeshData::Edge &edge : edges) { int a = edge.vertex_a; int b = edge.vertex_b; diff --git a/core/math/transform_2d.cpp b/core/math/transform_2d.cpp index 910995d717..96010b4096 100644 --- a/core/math/transform_2d.cpp +++ b/core/math/transform_2d.cpp @@ -263,39 +263,12 @@ real_t Transform2D::basis_determinant() const { return columns[0].x * columns[1].y - columns[0].y * columns[1].x; } -Transform2D Transform2D::interpolate_with(const Transform2D &p_transform, const real_t p_c) const { - //extract parameters - Vector2 p1 = get_origin(); - Vector2 p2 = p_transform.get_origin(); - - real_t r1 = get_rotation(); - real_t r2 = p_transform.get_rotation(); - - Size2 s1 = get_scale(); - Size2 s2 = p_transform.get_scale(); - - //slerp rotation - Vector2 v1(Math::cos(r1), Math::sin(r1)); - Vector2 v2(Math::cos(r2), Math::sin(r2)); - - real_t dot = v1.dot(v2); - - dot = CLAMP(dot, (real_t)-1.0, (real_t)1.0); - - Vector2 v; - - if (dot > 0.9995f) { - v = v1.lerp(v2, p_c).normalized(); //linearly interpolate to avoid numerical precision issues - } else { - real_t angle = p_c * Math::acos(dot); - Vector2 v3 = (v2 - v1 * dot).normalized(); - v = v1 * Math::cos(angle) + v3 * Math::sin(angle); - } - - //construct matrix - Transform2D res(v.angle(), p1.lerp(p2, p_c)); - res.scale_basis(s1.lerp(s2, p_c)); - return res; +Transform2D Transform2D::interpolate_with(const Transform2D &p_transform, const real_t p_weight) const { + return Transform2D( + Math::lerp_angle(get_rotation(), p_transform.get_rotation(), p_weight), + get_scale().lerp(p_transform.get_scale(), p_weight), + Math::lerp_angle(get_skew(), p_transform.get_skew(), p_weight), + get_origin().lerp(p_transform.get_origin(), p_weight)); } void Transform2D::operator*=(const real_t p_val) { |