diff options
Diffstat (limited to 'core/math')
-rw-r--r-- | core/math/SCsub | 2 | ||||
-rw-r--r-- | core/math/a_star.cpp | 203 | ||||
-rw-r--r-- | core/math/a_star.h | 16 | ||||
-rw-r--r-- | core/math/aabb.h | 4 | ||||
-rw-r--r-- | core/math/audio_frame.h | 6 | ||||
-rw-r--r-- | core/math/camera_matrix.cpp | 2 | ||||
-rw-r--r-- | core/math/camera_matrix.h | 2 | ||||
-rw-r--r-- | core/math/disjoint_set.h | 2 | ||||
-rw-r--r-- | core/math/expression.cpp | 80 | ||||
-rw-r--r-- | core/math/expression.h | 4 | ||||
-rw-r--r-- | core/math/geometry.cpp | 18 | ||||
-rw-r--r-- | core/math/geometry.h | 32 | ||||
-rw-r--r-- | core/math/octree.h | 54 | ||||
-rw-r--r-- | core/math/quat.h | 2 | ||||
-rw-r--r-- | core/math/quick_hull.cpp | 6 | ||||
-rw-r--r-- | core/math/quick_hull.h | 8 | ||||
-rw-r--r-- | core/math/rect2.h | 2 | ||||
-rw-r--r-- | core/math/triangulate.h | 2 |
18 files changed, 313 insertions, 132 deletions
diff --git a/core/math/SCsub b/core/math/SCsub index be438fcfbe..c8fdac207e 100644 --- a/core/math/SCsub +++ b/core/math/SCsub @@ -1,6 +1,6 @@ #!/usr/bin/env python -Import('env') +Import("env") env_math = env.Clone() diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp index 847d4d8681..3e3e6c50a7 100644 --- a/core/math/a_star.cpp +++ b/core/math/a_star.cpp @@ -66,7 +66,7 @@ void AStar::add_point(int p_id, const Vector3 &p_pos, real_t p_weight_scale) { pt->id = p_id; pt->pos = p_pos; pt->weight_scale = p_weight_scale; - pt->prev_point = NULL; + pt->prev_point = nullptr; pt->open_pass = 0; pt->closed_pass = 0; pt->enabled = true; @@ -167,7 +167,7 @@ void AStar::connect_points(int p_id, int p_with_id, bool bidirectional) { if (bidirectional) s.direction = Segment::BIDIRECTIONAL; Set<Segment>::Element *element = segments.find(s); - if (element != NULL) { + if (element != nullptr) { s.direction |= element->get().direction; if (s.direction == Segment::BIDIRECTIONAL) { // Both are neighbours of each other now @@ -194,7 +194,7 @@ void AStar::disconnect_points(int p_id, int p_with_id, bool bidirectional) { int remove_direction = bidirectional ? (int)Segment::BIDIRECTIONAL : s.direction; Set<Segment>::Element *element = segments.find(s); - if (element != NULL) { + if (element != nullptr) { // s is the new segment // Erase the directions to be removed s.direction = (element->get().direction & ~remove_direction); @@ -255,7 +255,7 @@ bool AStar::are_points_connected(int p_id, int p_with_id, bool bidirectional) co Segment s(p_id, p_with_id); const Set<Segment>::Element *element = segments.find(s); - return element != NULL && + return element != nullptr && (bidirectional || (element->get().direction & s.direction) == s.direction); } @@ -399,7 +399,7 @@ bool AStar::_solve(Point *begin_point, Point *end_point) { return found_route; } -float AStar::_estimate_cost(int p_from_id, int p_to_id) { +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)) return get_script_instance()->call(SceneStringNames::get_singleton()->_estimate_cost, p_from_id, p_to_id); @@ -415,7 +415,7 @@ float AStar::_estimate_cost(int p_from_id, int p_to_id) { return from_point->pos.distance_to(to_point->pos); } -float AStar::_compute_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)) return get_script_instance()->call(SceneStringNames::get_singleton()->_compute_cost, p_from_id, p_to_id); @@ -677,25 +677,195 @@ Vector2 AStar2D::get_closest_position_in_segment(const Vector2 &p_point) const { return Vector2(p.x, p.y); } +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)) + 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); + ERR_FAIL_COND_V(!from_exists, 0); + + AStar::Point *to_point; + bool to_exists = astar.points.lookup(p_to_id, to_point); + ERR_FAIL_COND_V(!to_exists, 0); + + return from_point->pos.distance_to(to_point->pos); +} + +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)) + 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); + ERR_FAIL_COND_V(!from_exists, 0); + + AStar::Point *to_point; + bool to_exists = astar.points.lookup(p_to_id, to_point); + ERR_FAIL_COND_V(!to_exists, 0); + + return from_point->pos.distance_to(to_point->pos); +} + Vector<Vector2> AStar2D::get_point_path(int p_from_id, int p_to_id) { - PackedVector3Array pv = astar.get_point_path(p_from_id, p_to_id); - int size = pv.size(); - PackedVector2Array path; - path.resize(size); + AStar::Point *a; + bool from_exists = astar.points.lookup(p_from_id, a); + ERR_FAIL_COND_V(!from_exists, Vector<Vector2>()); + + AStar::Point *b; + bool to_exists = astar.points.lookup(p_to_id, b); + ERR_FAIL_COND_V(!to_exists, Vector<Vector2>()); + + if (a == b) { + Vector<Vector2> ret; + ret.push_back(Vector2(a->pos.x, a->pos.y)); + return ret; + } + + AStar::Point *begin_point = a; + AStar::Point *end_point = b; + + bool found_route = _solve(begin_point, end_point); + if (!found_route) return Vector<Vector2>(); + + AStar::Point *p = end_point; + int pc = 1; // Begin point + while (p != begin_point) { + pc++; + p = p->prev_point; + } + + Vector<Vector2> path; + path.resize(pc); + { - const Vector3 *r = pv.ptr(); Vector2 *w = path.ptrw(); - for (int i = 0; i < size; i++) { - Vector3 p = r[i]; - w[i] = Vector2(p.x, p.y); + + AStar::Point *p2 = end_point; + int idx = pc - 1; + while (p2 != begin_point) { + w[idx--] = Vector2(p2->pos.x, p2->pos.y); + p2 = p2->prev_point; } + + w[0] = Vector2(p2->pos.x, p2->pos.y); // Assign first } + return path; } Vector<int> AStar2D::get_id_path(int p_from_id, int p_to_id) { - return astar.get_id_path(p_from_id, p_to_id); + + AStar::Point *a; + bool from_exists = astar.points.lookup(p_from_id, a); + ERR_FAIL_COND_V(!from_exists, Vector<int>()); + + AStar::Point *b; + bool to_exists = astar.points.lookup(p_to_id, b); + ERR_FAIL_COND_V(!to_exists, Vector<int>()); + + if (a == b) { + Vector<int> ret; + ret.push_back(a->id); + return ret; + } + + AStar::Point *begin_point = a; + AStar::Point *end_point = b; + + bool found_route = _solve(begin_point, end_point); + if (!found_route) return Vector<int>(); + + AStar::Point *p = end_point; + int pc = 1; // Begin point + while (p != begin_point) { + pc++; + p = p->prev_point; + } + + Vector<int> path; + path.resize(pc); + + { + int *w = path.ptrw(); + + p = end_point; + int idx = pc - 1; + while (p != begin_point) { + w[idx--] = p->id; + p = p->prev_point; + } + + w[0] = p->id; // Assign first + } + + return path; +} + +bool AStar2D::_solve(AStar::Point *begin_point, AStar::Point *end_point) { + + astar.pass++; + + if (!end_point->enabled) return false; + + bool found_route = false; + + Vector<AStar::Point *> open_list; + SortArray<AStar::Point *, AStar::SortPoints> sorter; + + begin_point->g_score = 0; + begin_point->f_score = _estimate_cost(begin_point->id, end_point->id); + open_list.push_back(begin_point); + + while (!open_list.empty()) { + + AStar::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 + open_list.remove(open_list.size() - 1); + p->closed_pass = astar.pass; // Mark the point as closed + + for (OAHashMap<int, AStar::Point *>::Iterator it = p->neighbours.iter(); it.valid; it = p->neighbours.next_iter(it)) { + + AStar::Point *e = *(it.value); // The neighbour point + + if (!e->enabled || e->closed_pass == astar.pass) { + continue; + } + + real_t tentative_g_score = p->g_score + _compute_cost(p->id, e->id) * e->weight_scale; + + bool new_point = false; + + if (e->open_pass != astar.pass) { // The point wasn't inside the open list. + e->open_pass = astar.pass; + open_list.push_back(e); + new_point = true; + } else if (tentative_g_score >= e->g_score) { // The new path is worse than the previous. + continue; + } + + e->prev_point = p; + e->g_score = tentative_g_score; + 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()); + } else { + sorter.push_heap(0, open_list.find(e), 0, e, open_list.ptrw()); + } + } + } + + return found_route; } void AStar2D::_bind_methods() { @@ -728,6 +898,9 @@ void AStar2D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_point_path", "from_id", "to_id"), &AStar2D::get_point_path); ClassDB::bind_method(D_METHOD("get_id_path", "from_id", "to_id"), &AStar2D::get_id_path); + + BIND_VMETHOD(MethodInfo(Variant::FLOAT, "_estimate_cost", PropertyInfo(Variant::INT, "from_id"), PropertyInfo(Variant::INT, "to_id"))); + BIND_VMETHOD(MethodInfo(Variant::FLOAT, "_compute_cost", PropertyInfo(Variant::INT, "from_id"), PropertyInfo(Variant::INT, "to_id"))); } AStar2D::AStar2D() { diff --git a/core/math/a_star.h b/core/math/a_star.h index bfcf0c09d3..8c10ace33c 100644 --- a/core/math/a_star.h +++ b/core/math/a_star.h @@ -28,8 +28,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef ASTAR_H -#define ASTAR_H +#ifndef A_STAR_H +#define A_STAR_H #include "core/oa_hash_map.h" #include "core/reference.h" @@ -43,6 +43,7 @@ class AStar : public Reference { GDCLASS(AStar, Reference); + friend class AStar2D; struct Point { @@ -124,8 +125,8 @@ class AStar : public Reference { protected: static void _bind_methods(); - virtual float _estimate_cost(int p_from_id, int p_to_id); - virtual float _compute_cost(int p_from_id, int p_to_id); + virtual real_t _estimate_cost(int p_from_id, int p_to_id); + virtual real_t _compute_cost(int p_from_id, int p_to_id); public: int get_available_point_id() const; @@ -166,9 +167,14 @@ class AStar2D : public Reference { GDCLASS(AStar2D, Reference); AStar astar; + bool _solve(AStar::Point *begin_point, AStar::Point *end_point); + protected: static void _bind_methods(); + virtual real_t _estimate_cost(int p_from_id, int p_to_id); + virtual real_t _compute_cost(int p_from_id, int p_to_id); + public: int get_available_point_id() const; @@ -204,4 +210,4 @@ public: ~AStar2D(); }; -#endif // ASTAR_H +#endif // A_STAR_H diff --git a/core/math/aabb.h b/core/math/aabb.h index d9d50c7139..eca74e6755 100644 --- a/core/math/aabb.h +++ b/core/math/aabb.h @@ -72,8 +72,8 @@ public: AABB merge(const AABB &p_with) const; void merge_with(const AABB &p_aabb); ///merge with another AABB AABB intersection(const AABB &p_aabb) const; ///get box where two intersect, empty if no intersection occurs - bool intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector3 *r_clip = NULL, Vector3 *r_normal = NULL) const; - bool intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *r_clip = NULL, Vector3 *r_normal = NULL) const; + bool intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector3 *r_clip = nullptr, Vector3 *r_normal = nullptr) const; + bool intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *r_clip = nullptr, Vector3 *r_normal = nullptr) const; _FORCE_INLINE_ bool smits_intersect_ray(const Vector3 &p_from, const Vector3 &p_dir, real_t t0, real_t t1) const; _FORCE_INLINE_ bool intersects_convex_shape(const Plane *p_planes, int p_plane_count) const; diff --git a/core/math/audio_frame.h b/core/math/audio_frame.h index 6477d029d5..e1dbb385e4 100644 --- a/core/math/audio_frame.h +++ b/core/math/audio_frame.h @@ -28,8 +28,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef AUDIOFRAME_H -#define AUDIOFRAME_H +#ifndef AUDIO_FRAME_H +#define AUDIO_FRAME_H #include "core/math/vector2.h" #include "core/typedefs.h" @@ -140,4 +140,4 @@ struct AudioFrame { _ALWAYS_INLINE_ AudioFrame() {} }; -#endif +#endif // AUDIO_FRAME_H diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp index c4981b954b..c36070e47f 100644 --- a/core/math/camera_matrix.cpp +++ b/core/math/camera_matrix.cpp @@ -145,7 +145,7 @@ void CameraMatrix::set_for_hmd(int p_eye, real_t p_aspect, real_t p_intraocular_ f3 *= p_oversample; // always apply KEEP_WIDTH aspect ratio - f3 *= p_aspect; + f3 /= p_aspect; switch (p_eye) { case 1: { // left eye diff --git a/core/math/camera_matrix.h b/core/math/camera_matrix.h index 60f7d15974..c10193bc84 100644 --- a/core/math/camera_matrix.h +++ b/core/math/camera_matrix.h @@ -124,4 +124,4 @@ Vector3 CameraMatrix::xform(const Vector3 &p_vec3) const { return ret / w; } -#endif +#endif // CAMERA_MATRIX_H diff --git a/core/math/disjoint_set.h b/core/math/disjoint_set.h index fb89941ce4..32b9875e4c 100644 --- a/core/math/disjoint_set.h +++ b/core/math/disjoint_set.h @@ -152,4 +152,4 @@ void DisjointSet<T, C, AL>::get_members(Vector<T> &out_members, T representative } } -#endif +#endif // DISJOINT_SET_H diff --git a/core/math/expression.cpp b/core/math/expression.cpp index 04fda9d09a..859b9be8c5 100644 --- a/core/math/expression.cpp +++ b/core/math/expression.cpp @@ -760,7 +760,7 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant PackedByteArray barr; bool full_objects = *p_inputs[1]; int len; - Error err = encode_variant(*p_inputs[0], NULL, len, full_objects); + Error err = encode_variant(*p_inputs[0], nullptr, len, full_objects); if (err) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; @@ -791,7 +791,7 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant Variant ret; { const uint8_t *r = varr.ptr(); - Error err = decode_variant(ret, r, varr.size(), NULL, allow_objects); + Error err = decode_variant(ret, r, varr.size(), nullptr, allow_objects); if (err != OK) { r_error_str = RTR("Not enough bytes for decoding bytes, or invalid format."); r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; @@ -1298,12 +1298,12 @@ Expression::ENode *Expression::_parse_expression() { while (true) { //keep appending stuff to expression - ENode *expr = NULL; + ENode *expr = nullptr; Token tk; _get_token(tk); if (error_set) - return NULL; + return nullptr; switch (tk.type) { case TK_CURLY_BRACKET_OPEN: { @@ -1321,18 +1321,18 @@ Expression::ENode *Expression::_parse_expression() { //parse an expression ENode *subexpr = _parse_expression(); if (!subexpr) - return NULL; + return nullptr; dn->dict.push_back(subexpr); _get_token(tk); if (tk.type != TK_COLON) { _set_error("Expected ':'"); - return NULL; + return nullptr; } subexpr = _parse_expression(); if (!subexpr) - return NULL; + return nullptr; dn->dict.push_back(subexpr); @@ -1365,7 +1365,7 @@ Expression::ENode *Expression::_parse_expression() { //parse an expression ENode *subexpr = _parse_expression(); if (!subexpr) - return NULL; + return nullptr; an->array.push_back(subexpr); cofs = str_ofs; @@ -1385,11 +1385,11 @@ Expression::ENode *Expression::_parse_expression() { //a suexpression ENode *e = _parse_expression(); if (error_set) - return NULL; + return nullptr; _get_token(tk); if (tk.type != TK_PARENTHESIS_CLOSE) { _set_error("Expected ')'"); - return NULL; + return nullptr; } expr = e; @@ -1419,7 +1419,7 @@ Expression::ENode *Expression::_parse_expression() { //parse an expression ENode *subexpr = _parse_expression(); if (!subexpr) - return NULL; + return nullptr; func_call->arguments.push_back(subexpr); @@ -1484,7 +1484,7 @@ Expression::ENode *Expression::_parse_expression() { _get_token(tk); if (tk.type != TK_PARENTHESIS_OPEN) { _set_error("Expected '('"); - return NULL; + return nullptr; } ConstructorNode *constructor = alloc_node<ConstructorNode>(); @@ -1501,7 +1501,7 @@ Expression::ENode *Expression::_parse_expression() { //parse an expression ENode *subexpr = _parse_expression(); if (!subexpr) - return NULL; + return nullptr; constructor->arguments.push_back(subexpr); @@ -1525,7 +1525,7 @@ Expression::ENode *Expression::_parse_expression() { _get_token(tk); if (tk.type != TK_PARENTHESIS_OPEN) { _set_error("Expected '('"); - return NULL; + return nullptr; } BuiltinFuncNode *bifunc = alloc_node<BuiltinFuncNode>(); @@ -1542,7 +1542,7 @@ Expression::ENode *Expression::_parse_expression() { //parse an expression ENode *subexpr = _parse_expression(); if (!subexpr) - return NULL; + return nullptr; bifunc->arguments.push_back(subexpr); @@ -1584,7 +1584,7 @@ Expression::ENode *Expression::_parse_expression() { default: { _set_error("Expected expression."); - return NULL; + return nullptr; } break; } @@ -1594,7 +1594,7 @@ Expression::ENode *Expression::_parse_expression() { int cofs2 = str_ofs; _get_token(tk); if (error_set) - return NULL; + return nullptr; bool done = false; @@ -1607,14 +1607,14 @@ Expression::ENode *Expression::_parse_expression() { ENode *what = _parse_expression(); if (!what) - return NULL; + return nullptr; index->index = what; _get_token(tk); if (tk.type != TK_BRACKET_CLOSE) { _set_error("Expected ']' at end of index."); - return NULL; + return nullptr; } expr = index; @@ -1624,7 +1624,7 @@ Expression::ENode *Expression::_parse_expression() { _get_token(tk); if (tk.type != TK_IDENTIFIER) { _set_error("Expected identifier after '.'"); - return NULL; + return nullptr; } StringName identifier = tk.value; @@ -1648,7 +1648,7 @@ Expression::ENode *Expression::_parse_expression() { //parse an expression ENode *subexpr = _parse_expression(); if (!subexpr) - return NULL; + return nullptr; func_call->arguments.push_back(subexpr); @@ -1698,7 +1698,7 @@ Expression::ENode *Expression::_parse_expression() { int cofs = str_ofs; _get_token(tk); if (error_set) - return NULL; + return nullptr; Variant::Operator op = Variant::OP_MAX; @@ -1805,7 +1805,7 @@ Expression::ENode *Expression::_parse_expression() { default: { _set_error("Parser bug, invalid operator in expression: " + itos(expression[i].op)); - return NULL; + return nullptr; } } @@ -1822,7 +1822,7 @@ Expression::ENode *Expression::_parse_expression() { if (next_op == -1) { _set_error("Yet another parser bug...."); - ERR_FAIL_V(NULL); + ERR_FAIL_V(nullptr); } // OK! create operator.. @@ -1835,7 +1835,7 @@ Expression::ENode *Expression::_parse_expression() { if (expr_pos == expression.size()) { //can happen.. _set_error("Unexpected end of expression..."); - return NULL; + return nullptr; } } @@ -1845,7 +1845,7 @@ Expression::ENode *Expression::_parse_expression() { OperatorNode *op = alloc_node<OperatorNode>(); op->op = expression[i].op; op->nodes[0] = expression[i + 1].node; - op->nodes[1] = NULL; + op->nodes[1] = nullptr; expression.write[i].is_op = false; expression.write[i].node = op; expression.remove(i + 1); @@ -1855,7 +1855,7 @@ Expression::ENode *Expression::_parse_expression() { if (next_op < 1 || next_op >= (expression.size() - 1)) { _set_error("Parser bug..."); - ERR_FAIL_V(NULL); + ERR_FAIL_V(nullptr); } OperatorNode *op = alloc_node<OperatorNode>(); @@ -1864,7 +1864,7 @@ Expression::ENode *Expression::_parse_expression() { if (expression[next_op - 1].is_op) { _set_error("Parser bug..."); - ERR_FAIL_V(NULL); + ERR_FAIL_V(nullptr); } if (expression[next_op + 1].is_op) { @@ -1874,7 +1874,7 @@ Expression::ENode *Expression::_parse_expression() { // due to how precedence works, unaries will always disappear first _set_error("Unexpected two consecutive operators."); - return NULL; + return nullptr; } op->nodes[0] = expression[next_op - 1].node; //expression goes as left @@ -1897,8 +1897,8 @@ bool Expression::_compile_expression() { if (nodes) { memdelete(nodes); - nodes = NULL; - root = NULL; + nodes = nullptr; + root = nullptr; } error_str = String(); @@ -1908,11 +1908,11 @@ bool Expression::_compile_expression() { root = _parse_expression(); if (error_set) { - root = NULL; + root = nullptr; if (nodes) { memdelete(nodes); } - nodes = NULL; + nodes = nullptr; return true; } @@ -2151,8 +2151,8 @@ Error Expression::parse(const String &p_expression, const Vector<String> &p_inpu if (nodes) { memdelete(nodes); - nodes = NULL; - root = NULL; + nodes = nullptr; + root = nullptr; } error_str = String(); @@ -2164,11 +2164,11 @@ Error Expression::parse(const String &p_expression, const Vector<String> &p_inpu root = _parse_expression(); if (error_set) { - root = NULL; + root = nullptr; if (nodes) { memdelete(nodes); } - nodes = NULL; + nodes = nullptr; return ERR_INVALID_PARAMETER; } @@ -2212,9 +2212,11 @@ Expression::Expression() : output_type(Variant::NIL), sequenced(false), error_set(true), - root(NULL), - nodes(NULL), + root(nullptr), + nodes(nullptr), execution_error(false) { + str_ofs = 0; + expression_dirty = false; } Expression::~Expression() { diff --git a/core/math/expression.h b/core/math/expression.h index bbf946bb0a..78de225ebf 100644 --- a/core/math/expression.h +++ b/core/math/expression.h @@ -219,7 +219,7 @@ private: Type type; - ENode() { next = NULL; } + ENode() { next = nullptr; } virtual ~ENode() { if (next) { memdelete(next); @@ -352,7 +352,7 @@ protected: public: Error parse(const String &p_expression, const Vector<String> &p_input_names = Vector<String>()); - Variant execute(Array p_inputs, Object *p_base = NULL, bool p_show_error = true); + Variant execute(Array p_inputs, Object *p_base = nullptr, bool p_show_error = true); bool has_execute_failed() const; String get_error_text() const; diff --git a/core/math/geometry.cpp b/core/math/geometry.cpp index 69c7abfd30..3e07e9253e 100644 --- a/core/math/geometry.cpp +++ b/core/math/geometry.cpp @@ -214,9 +214,9 @@ static bool _group_face(_FaceClassify *p_faces, int len, int p_index, int p_grou return true; } -Vector<Vector<Face3> > Geometry::separate_objects(Vector<Face3> p_array) { +Vector<Vector<Face3>> Geometry::separate_objects(Vector<Face3> p_array) { - Vector<Vector<Face3> > objects; + Vector<Vector<Face3>> objects; int len = p_array.size(); @@ -235,7 +235,7 @@ Vector<Vector<Face3> > Geometry::separate_objects(Vector<Face3> p_array) { bool error = _connect_faces(_fcptr, len, -1); - ERR_FAIL_COND_V_MSG(error, Vector<Vector<Face3> >(), "Invalid geometry."); + ERR_FAIL_COND_V_MSG(error, Vector<Vector<Face3>>(), "Invalid geometry."); // Group connected faces in separate objects. @@ -679,8 +679,8 @@ Vector<Face3> Geometry::wrap_geometry(Vector<Face3> p_array, real_t *p_error) { return wrapped_faces; } -Vector<Vector<Vector2> > Geometry::decompose_polygon_in_convex(Vector<Point2> polygon) { - Vector<Vector<Vector2> > decomp; +Vector<Vector<Vector2>> Geometry::decompose_polygon_in_convex(Vector<Point2> polygon) { + Vector<Vector<Vector2>> decomp; List<TriangulatorPoly> in_poly, out_poly; TriangulatorPoly inp; @@ -1076,7 +1076,7 @@ void Geometry::make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_resu r_size = Size2(results[best].max_w, results[best].max_h); } -Vector<Vector<Point2> > Geometry::_polypaths_do_operation(PolyBooleanOperation p_op, const Vector<Point2> &p_polypath_a, const Vector<Point2> &p_polypath_b, bool is_a_open) { +Vector<Vector<Point2>> Geometry::_polypaths_do_operation(PolyBooleanOperation p_op, const Vector<Point2> &p_polypath_a, const Vector<Point2> &p_polypath_b, bool is_a_open) { using namespace ClipperLib; @@ -1111,7 +1111,7 @@ Vector<Vector<Point2> > Geometry::_polypaths_do_operation(PolyBooleanOperation p clp.Execute(op, paths); // Works on closed polygons only. } // Have to scale points down now. - Vector<Vector<Point2> > polypaths; + Vector<Vector<Point2>> polypaths; for (Paths::size_type i = 0; i < paths.size(); ++i) { Vector<Vector2> polypath; @@ -1128,7 +1128,7 @@ Vector<Vector<Point2> > Geometry::_polypaths_do_operation(PolyBooleanOperation p return polypaths; } -Vector<Vector<Point2> > Geometry::_polypath_offset(const Vector<Point2> &p_polypath, real_t p_delta, PolyJoinType p_join_type, PolyEndType p_end_type) { +Vector<Vector<Point2>> Geometry::_polypath_offset(const Vector<Point2> &p_polypath, real_t p_delta, PolyJoinType p_join_type, PolyEndType p_end_type) { using namespace ClipperLib; @@ -1162,7 +1162,7 @@ Vector<Vector<Point2> > Geometry::_polypath_offset(const Vector<Point2> &p_polyp co.Execute(paths, p_delta * SCALE_FACTOR); // Inflate/deflate. // Have to scale points down now. - Vector<Vector<Point2> > polypaths; + Vector<Vector<Point2>> polypaths; for (Paths::size_type i = 0; i < paths.size(); ++i) { Vector<Vector2> polypath; diff --git a/core/math/geometry.h b/core/math/geometry.h index a94d00bf77..e47d18b056 100644 --- a/core/math/geometry.h +++ b/core/math/geometry.h @@ -790,44 +790,44 @@ public: END_ROUND }; - static Vector<Vector<Point2> > merge_polygons_2d(const Vector<Point2> &p_polygon_a, const Vector<Point2> &p_polygon_b) { + static Vector<Vector<Point2>> merge_polygons_2d(const Vector<Point2> &p_polygon_a, const Vector<Point2> &p_polygon_b) { return _polypaths_do_operation(OPERATION_UNION, p_polygon_a, p_polygon_b); } - static Vector<Vector<Point2> > clip_polygons_2d(const Vector<Point2> &p_polygon_a, const Vector<Point2> &p_polygon_b) { + static Vector<Vector<Point2>> clip_polygons_2d(const Vector<Point2> &p_polygon_a, const Vector<Point2> &p_polygon_b) { return _polypaths_do_operation(OPERATION_DIFFERENCE, p_polygon_a, p_polygon_b); } - static Vector<Vector<Point2> > intersect_polygons_2d(const Vector<Point2> &p_polygon_a, const Vector<Point2> &p_polygon_b) { + static Vector<Vector<Point2>> intersect_polygons_2d(const Vector<Point2> &p_polygon_a, const Vector<Point2> &p_polygon_b) { return _polypaths_do_operation(OPERATION_INTERSECTION, p_polygon_a, p_polygon_b); } - static Vector<Vector<Point2> > exclude_polygons_2d(const Vector<Point2> &p_polygon_a, const Vector<Point2> &p_polygon_b) { + static Vector<Vector<Point2>> exclude_polygons_2d(const Vector<Point2> &p_polygon_a, const Vector<Point2> &p_polygon_b) { return _polypaths_do_operation(OPERATION_XOR, p_polygon_a, p_polygon_b); } - static Vector<Vector<Point2> > clip_polyline_with_polygon_2d(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon) { + static Vector<Vector<Point2>> clip_polyline_with_polygon_2d(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon) { return _polypaths_do_operation(OPERATION_DIFFERENCE, p_polyline, p_polygon, true); } - static Vector<Vector<Point2> > intersect_polyline_with_polygon_2d(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon) { + static Vector<Vector<Point2>> intersect_polyline_with_polygon_2d(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon) { return _polypaths_do_operation(OPERATION_INTERSECTION, p_polyline, p_polygon, true); } - static Vector<Vector<Point2> > offset_polygon_2d(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type) { + static Vector<Vector<Point2>> offset_polygon_2d(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type) { return _polypath_offset(p_polygon, p_delta, p_join_type, END_POLYGON); } - static Vector<Vector<Point2> > offset_polyline_2d(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type, PolyEndType p_end_type) { + static Vector<Vector<Point2>> offset_polyline_2d(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type, PolyEndType p_end_type) { - ERR_FAIL_COND_V_MSG(p_end_type == END_POLYGON, Vector<Vector<Point2> >(), "Attempt to offset a polyline like a polygon (use offset_polygon_2d instead)."); + ERR_FAIL_COND_V_MSG(p_end_type == END_POLYGON, Vector<Vector<Point2>>(), "Attempt to offset a polyline like a polygon (use offset_polygon_2d instead)."); return _polypath_offset(p_polygon, p_delta, p_join_type, p_end_type); } @@ -891,7 +891,7 @@ public: for (int i = 0; i < c; i++) { const Vector2 &v1 = p[i]; const Vector2 &v2 = p[(i + 1) % c]; - if (segment_intersects_segment_2d(v1, v2, p_point, further_away, NULL)) { + if (segment_intersects_segment_2d(v1, v2, p_point, further_away, nullptr)) { intersections++; } } @@ -899,10 +899,10 @@ public: return (intersections & 1); } - static Vector<Vector<Face3> > separate_objects(Vector<Face3> p_array); + static Vector<Vector<Face3>> separate_objects(Vector<Face3> p_array); // Create a "wrap" that encloses the given geometry. - static Vector<Face3> wrap_geometry(Vector<Face3> p_array, real_t *p_error = NULL); + static Vector<Face3> wrap_geometry(Vector<Face3> p_array, real_t *p_error = nullptr); struct MeshData { @@ -1004,7 +1004,7 @@ public: H.resize(k); return H; } - static Vector<Vector<Vector2> > decompose_polygon_in_convex(Vector<Point2> polygon); + static Vector<Vector<Vector2>> decompose_polygon_in_convex(Vector<Point2> polygon); static MeshData build_convex_mesh(const Vector<Plane> &p_planes); static Vector<Plane> build_sphere_planes(real_t p_radius, int p_lats, int p_lons, Vector3::Axis p_axis = Vector3::AXIS_Z); @@ -1015,8 +1015,8 @@ public: static void make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_result, Size2i &r_size); private: - static Vector<Vector<Point2> > _polypaths_do_operation(PolyBooleanOperation p_op, const Vector<Point2> &p_polypath_a, const Vector<Point2> &p_polypath_b, bool is_a_open = false); - static Vector<Vector<Point2> > _polypath_offset(const Vector<Point2> &p_polypath, real_t p_delta, PolyJoinType p_join_type, PolyEndType p_end_type); + static Vector<Vector<Point2>> _polypaths_do_operation(PolyBooleanOperation p_op, const Vector<Point2> &p_polypath_a, const Vector<Point2> &p_polypath_b, bool is_a_open = false); + static Vector<Vector<Point2>> _polypath_offset(const Vector<Point2> &p_polypath, real_t p_delta, PolyJoinType p_join_type, PolyEndType p_end_type); }; -#endif +#endif // GEOMETRY_H diff --git a/core/math/octree.h b/core/math/octree.h index 5478bdaf77..5225fbecb4 100644 --- a/core/math/octree.h +++ b/core/math/octree.h @@ -119,9 +119,9 @@ private: children_count = 0; parent_index = -1; last_pass = 0; - parent = NULL; + parent = nullptr; for (int i = 0; i < 8; i++) - children[i] = NULL; + children[i] = nullptr; } ~Octant() { @@ -171,7 +171,7 @@ private: octree = 0; pairable_mask = 0; pairable_type = 0; - common_parent = NULL; + common_parent = nullptr; } }; @@ -308,19 +308,19 @@ private: while (root && root->children_count < 2 && !root->elements.size() && !(use_pairs && root->pairable_elements.size())) { - Octant *new_root = NULL; + Octant *new_root = nullptr; if (root->children_count == 1) { for (int i = 0; i < 8; i++) { if (root->children[i]) { new_root = root->children[i]; - root->children[i] = NULL; + root->children[i] = nullptr; break; } } ERR_FAIL_COND(!new_root); - new_root->parent = NULL; + new_root->parent = nullptr; new_root->parent_index = -1; } @@ -332,7 +332,7 @@ private: void _insert_element(Element *p_element, Octant *p_octant); void _ensure_valid_root(const AABB &p_aabb); - bool _remove_element_from_octant(Element *p_element, Octant *p_octant, Octant *p_limit = NULL); + bool _remove_element_from_octant(Element *p_element, Octant *p_octant, Octant *p_limit = nullptr); void _remove_element(Element *p_element); void _pair_element(Element *p_element, Octant *p_octant); void _unpair_element(Element *p_element, Octant *p_octant); @@ -377,10 +377,10 @@ public: int get_subindex(OctreeElementID p_id) const; int cull_convex(const Vector<Plane> &p_convex, T **p_result_array, int p_result_max, uint32_t p_mask = 0xFFFFFFFF); - int cull_aabb(const AABB &p_aabb, T **p_result_array, int p_result_max, int *p_subindex_array = NULL, uint32_t p_mask = 0xFFFFFFFF); - int cull_segment(const Vector3 &p_from, const Vector3 &p_to, T **p_result_array, int p_result_max, int *p_subindex_array = NULL, uint32_t p_mask = 0xFFFFFFFF); + int cull_aabb(const AABB &p_aabb, T **p_result_array, int p_result_max, int *p_subindex_array = nullptr, uint32_t p_mask = 0xFFFFFFFF); + int cull_segment(const Vector3 &p_from, const Vector3 &p_to, T **p_result_array, int p_result_max, int *p_subindex_array = nullptr, uint32_t p_mask = 0xFFFFFFFF); - int cull_point(const Vector3 &p_point, T **p_result_array, int p_result_max, int *p_subindex_array = NULL, uint32_t p_mask = 0xFFFFFFFF); + int cull_point(const Vector3 &p_point, T **p_result_array, int p_result_max, int *p_subindex_array = nullptr, uint32_t p_mask = 0xFFFFFFFF); void set_pair_callback(PairCallback p_callback, void *p_userdata); void set_unpair_callback(UnpairCallback p_callback, void *p_userdata); @@ -396,7 +396,7 @@ public: template <class T, bool use_pairs, class AL> T *Octree<T, use_pairs, AL>::get(OctreeElementID p_id) const { const typename ElementMap::Element *E = element_map.find(p_id); - ERR_FAIL_COND_V(!E, NULL); + ERR_FAIL_COND_V(!E, nullptr); return E->get().userdata; } @@ -442,7 +442,7 @@ void Octree<T, use_pairs, AL>::_insert_element(Element *p_element, Octant *p_oct p_element->octant_owners.push_back(owner); - if (p_element->common_parent == NULL) { + if (p_element->common_parent == nullptr) { p_element->common_parent = p_octant; p_element->container_aabb = p_octant->aabb; } else { @@ -463,7 +463,7 @@ void Octree<T, use_pairs, AL>::_insert_element(Element *p_element, Octant *p_oct } else { /* not big enough, send it to subitems */ int splits = 0; - bool candidate = p_element->common_parent == NULL; + bool candidate = p_element->common_parent == nullptr; for (int i = 0; i < 8; i++) { @@ -552,7 +552,7 @@ void Octree<T, use_pairs, AL>::_ensure_valid_root(const AABB &p_aabb) { root = memnew_allocator(Octant, AL); - root->parent = NULL; + root->parent = nullptr; root->parent_index = -1; root->aabb = base; @@ -634,11 +634,11 @@ bool Octree<T, use_pairs, AL>::_remove_element_from_octant(Element *p_element, O if (p_octant == root) { // won't have a parent, just erase - root = NULL; + root = nullptr; } else { ERR_FAIL_INDEX_V(p_octant->parent_index, 8, octant_removed); - parent->children[p_octant->parent_index] = NULL; + parent->children[p_octant->parent_index] = nullptr; parent->children_count--; } @@ -852,12 +852,12 @@ void Octree<T, use_pairs, AL>::move(OctreeElementID p_id, const AABB &p_aabb) { if (old_has_surf) { _remove_element(&e); // removing - e.common_parent = NULL; + e.common_parent = nullptr; e.aabb = AABB(); _optimize(); } else { _ensure_valid_root(p_aabb); // inserting - e.common_parent = NULL; + e.common_parent = nullptr; e.aabb = p_aabb; _insert_element(&e, root); if (use_pairs) @@ -884,7 +884,7 @@ void Octree<T, use_pairs, AL>::move(OctreeElementID p_id, const AABB &p_aabb) { combined.merge_with(p_aabb); _ensure_valid_root(combined); - ERR_FAIL_COND(e.octant_owners.front() == NULL); + ERR_FAIL_COND(e.octant_owners.front() == nullptr); /* FIND COMMON PARENT */ @@ -902,7 +902,7 @@ void Octree<T, use_pairs, AL>::move(OctreeElementID p_id, const AABB &p_aabb) { //prepare for reinsert e.octant_owners.clear(); - e.common_parent = NULL; + e.common_parent = nullptr; e.aabb = p_aabb; _insert_element(&e, common_parent); // reinsert from this point @@ -971,7 +971,7 @@ void Octree<T, use_pairs, AL>::set_pairable(OctreeElementID p_id, bool p_pairabl e.pairable = p_pairable; e.pairable_type = p_pairable_type; e.pairable_mask = p_pairable_mask; - e.common_parent = NULL; + e.common_parent = nullptr; if (!e.aabb.has_no_surface()) { _ensure_valid_root(e.aabb); @@ -1364,15 +1364,15 @@ Octree<T, use_pairs, AL>::Octree(real_t p_unit_size) { last_element_id = 1; pass = 1; unit_size = p_unit_size; - root = NULL; + root = nullptr; octant_count = 0; pair_count = 0; - pair_callback = NULL; - unpair_callback = NULL; - pair_callback_userdata = NULL; - unpair_callback_userdata = NULL; + pair_callback = nullptr; + unpair_callback = nullptr; + pair_callback_userdata = nullptr; + unpair_callback_userdata = nullptr; } -#endif +#endif // OCTREE_H diff --git a/core/math/quat.h b/core/math/quat.h index 11ae03dffb..b3135ad1ca 100644 --- a/core/math/quat.h +++ b/core/math/quat.h @@ -231,4 +231,4 @@ bool Quat::operator!=(const Quat &p_quat) const { return x != p_quat.x || y != p_quat.y || z != p_quat.z || w != p_quat.w; } -#endif +#endif // QUAT_H diff --git a/core/math/quick_hull.cpp b/core/math/quick_hull.cpp index 63dd18091f..7fbb26c377 100644 --- a/core/math/quick_hull.cpp +++ b/core/math/quick_hull.cpp @@ -399,7 +399,7 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me ERR_CONTINUE(!F); List<Geometry::MeshData::Face>::Element *O = F->get().left == E ? F->get().right : F->get().left; ERR_CONTINUE(O == E); - ERR_CONTINUE(O == NULL); + ERR_CONTINUE(O == nullptr); if (O->get().plane.is_equal_approx(f.plane)) { //merge and delete edge and contiguous face, while repointing edges (uuugh!) @@ -440,10 +440,10 @@ 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) - G->get().left = NULL; + G->get().left = nullptr; if (G->get().right == O) - G->get().right = NULL; + G->get().right = nullptr; } ret_edges.erase(F); //remove the edge diff --git a/core/math/quick_hull.h b/core/math/quick_hull.h index aea9ffad8b..173f919a73 100644 --- a/core/math/quick_hull.h +++ b/core/math/quick_hull.h @@ -77,15 +77,15 @@ private: struct FaceConnect { List<Face>::Element *left, *right; FaceConnect() { - left = NULL; - right = NULL; + left = nullptr; + right = nullptr; } }; struct RetFaceConnect { List<Geometry::MeshData::Face>::Element *left, *right; RetFaceConnect() { - left = NULL; - right = NULL; + left = nullptr; + right = nullptr; } }; diff --git a/core/math/rect2.h b/core/math/rect2.h index 3b9660e2f0..30dbfdbbe5 100644 --- a/core/math/rect2.h +++ b/core/math/rect2.h @@ -105,7 +105,7 @@ struct Rect2 { bool intersects_transformed(const Transform2D &p_xform, const Rect2 &p_rect) const; - bool intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2 *r_pos = NULL, Point2 *r_normal = NULL) const; + bool intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2 *r_pos = nullptr, Point2 *r_normal = nullptr) const; inline bool encloses(const Rect2 &p_rect) const { diff --git a/core/math/triangulate.h b/core/math/triangulate.h index f9bcb37141..c453b77ecf 100644 --- a/core/math/triangulate.h +++ b/core/math/triangulate.h @@ -58,4 +58,4 @@ private: static bool snip(const Vector<Vector2> &p_contour, int u, int v, int w, int n, const Vector<int> &V, bool relaxed); }; -#endif +#endif // TRIANGULATE_H |