summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/class_db.cpp13
-rw-r--r--core/class_db.h1
-rw-r--r--core/math/a_star.cpp22
-rw-r--r--core/math/a_star.h4
-rw-r--r--core/math/vector2.h7
-rw-r--r--core/math/vector3.h7
-rw-r--r--core/os/file_access.cpp32
-rw-r--r--core/os/file_access.h3
-rw-r--r--core/ustring.cpp18
-rw-r--r--core/ustring.h8
-rw-r--r--core/variant_call.cpp6
-rw-r--r--core/vmap.h2
-rw-r--r--core/vset.h2
13 files changed, 119 insertions, 6 deletions
diff --git a/core/class_db.cpp b/core/class_db.cpp
index f7b446707d..0c844657a4 100644
--- a/core/class_db.cpp
+++ b/core/class_db.cpp
@@ -312,6 +312,19 @@ void ClassDB::get_inheriters_from_class(const StringName &p_class, List<StringNa
}
}
+void ClassDB::get_direct_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes) {
+
+ OBJTYPE_RLOCK;
+
+ const StringName *k = NULL;
+
+ while ((k = classes.next(k))) {
+
+ if (*k != p_class && get_parent_class(*k) == p_class)
+ p_classes->push_back(*k);
+ }
+}
+
StringName ClassDB::get_parent_class_nocheck(const StringName &p_class) {
OBJTYPE_RLOCK;
diff --git a/core/class_db.h b/core/class_db.h
index f18a7113d7..efa1a46866 100644
--- a/core/class_db.h
+++ b/core/class_db.h
@@ -214,6 +214,7 @@ public:
static void get_class_list(List<StringName> *p_classes);
static void get_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes);
+ static void get_direct_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes);
static StringName get_parent_class_nocheck(const StringName &p_class);
static StringName get_parent_class(const StringName &p_class);
static bool class_exists(const StringName &p_class);
diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp
index 6c3b84d49a..e1388ad2ac 100644
--- a/core/math/a_star.cpp
+++ b/core/math/a_star.cpp
@@ -55,6 +55,7 @@ void AStar::add_point(int p_id, const Vector3 &p_pos, real_t p_weight_scale) {
pt->weight_scale = p_weight_scale;
pt->prev_point = NULL;
pt->last_pass = 0;
+ pt->enabled = true;
points[p_id] = pt;
} else {
points[p_id]->pos = p_pos;
@@ -242,6 +243,9 @@ bool AStar::_solve(Point *begin_point, Point *end_point) {
pass++;
+ if (!end_point->enabled)
+ return false;
+
SelfList<Point>::List open_list;
bool found_route = false;
@@ -249,6 +253,10 @@ bool AStar::_solve(Point *begin_point, Point *end_point) {
for (Set<Point *>::Element *E = begin_point->neighbours.front(); E; E = E->next()) {
Point *n = E->get();
+
+ if (!n->enabled)
+ continue;
+
n->prev_point = begin_point;
n->distance = _compute_cost(begin_point->id, n->id) * n->weight_scale;
n->last_pass = pass;
@@ -290,6 +298,9 @@ bool AStar::_solve(Point *begin_point, Point *end_point) {
Point *e = E->get();
+ if (!e->enabled)
+ continue;
+
real_t distance = _compute_cost(p->id, e->id) * e->weight_scale + p->distance;
if (e->last_pass == pass) {
@@ -438,6 +449,14 @@ PoolVector<int> AStar::get_id_path(int p_from_id, int p_to_id) {
return path;
}
+void AStar::set_point_disabled(int p_id, bool p_disabled) {
+ points[p_id]->enabled = !p_disabled;
+}
+
+bool AStar::is_point_disabled(int p_id) const {
+ return !points[p_id]->enabled;
+}
+
void AStar::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_available_point_id"), &AStar::get_available_point_id);
@@ -450,6 +469,9 @@ void AStar::_bind_methods() {
ClassDB::bind_method(D_METHOD("has_point", "id"), &AStar::has_point);
ClassDB::bind_method(D_METHOD("get_points"), &AStar::get_points);
+ ClassDB::bind_method(D_METHOD("set_point_disabled", "id", "disabled"), &AStar::set_point_disabled, DEFVAL(true));
+ ClassDB::bind_method(D_METHOD("is_point_disabled", "id"), &AStar::is_point_disabled);
+
ClassDB::bind_method(D_METHOD("get_point_connections", "id"), &AStar::get_point_connections);
ClassDB::bind_method(D_METHOD("connect_points", "id", "to_id", "bidirectional"), &AStar::connect_points, DEFVAL(true));
diff --git a/core/math/a_star.h b/core/math/a_star.h
index d094bc4863..c63e1aa4dc 100644
--- a/core/math/a_star.h
+++ b/core/math/a_star.h
@@ -54,6 +54,7 @@ class AStar : public Reference {
Vector3 pos;
real_t weight_scale;
uint64_t last_pass;
+ bool enabled;
Set<Point *> neighbours;
@@ -114,6 +115,9 @@ public:
PoolVector<int> get_point_connections(int p_id);
Array get_points();
+ void set_point_disabled(int p_id, bool p_disabled = true);
+ bool is_point_disabled(int p_id) const;
+
void connect_points(int p_id, int p_with_id, bool bidirectional = true);
void disconnect_points(int p_id, int p_with_id);
bool are_points_connected(int p_id, int p_with_id) const;
diff --git a/core/math/vector2.h b/core/math/vector2.h
index a20326f667..ae2d1ec660 100644
--- a/core/math/vector2.h
+++ b/core/math/vector2.h
@@ -65,6 +65,7 @@ struct Vector2 {
real_t distance_squared_to(const Vector2 &p_vector2) const;
real_t angle_to(const Vector2 &p_vector2) const;
real_t angle_to_point(const Vector2 &p_vector2) const;
+ _FORCE_INLINE_ Vector2 direction_to(const Vector2 &p_b) const;
real_t dot(const Vector2 &p_other) const;
real_t cross(const Vector2 &p_other) const;
@@ -236,6 +237,12 @@ Vector2 Vector2::slerp(const Vector2 &p_b, real_t p_t) const {
return rotated(theta * p_t);
}
+Vector2 Vector2::direction_to(const Vector2 &p_b) const {
+ Vector2 ret(p_b.x - x, p_b.y - y);
+ ret.normalize();
+ return ret;
+}
+
Vector2 Vector2::linear_interpolate(const Vector2 &p_a, const Vector2 &p_b, real_t p_t) {
Vector2 res = p_a;
diff --git a/core/math/vector3.h b/core/math/vector3.h
index b11838d16e..e9074c5bd4 100644
--- a/core/math/vector3.h
+++ b/core/math/vector3.h
@@ -112,6 +112,7 @@ struct Vector3 {
_FORCE_INLINE_ Vector3 project(const Vector3 &p_b) const;
_FORCE_INLINE_ real_t angle_to(const Vector3 &p_b) const;
+ _FORCE_INLINE_ Vector3 direction_to(const Vector3 &p_b) const;
_FORCE_INLINE_ Vector3 slide(const Vector3 &p_normal) const;
_FORCE_INLINE_ Vector3 bounce(const Vector3 &p_normal) const;
@@ -244,6 +245,12 @@ real_t Vector3::angle_to(const Vector3 &p_b) const {
return Math::atan2(cross(p_b).length(), dot(p_b));
}
+Vector3 Vector3::direction_to(const Vector3 &p_b) const {
+ Vector3 ret(p_b.x - x, p_b.y - y, p_b.z - z);
+ ret.normalize();
+ return ret;
+}
+
/* Operators */
Vector3 &Vector3::operator+=(const Vector3 &p_v) {
diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp
index 39d9f45bd7..4be1364278 100644
--- a/core/os/file_access.cpp
+++ b/core/os/file_access.cpp
@@ -571,10 +571,16 @@ void FileAccess::store_buffer(const uint8_t *p_src, int p_length) {
store_8(p_src[i]);
}
-Vector<uint8_t> FileAccess::get_file_as_array(const String &p_path) {
+Vector<uint8_t> FileAccess::get_file_as_array(const String &p_path, Error *r_error) {
- FileAccess *f = FileAccess::open(p_path, READ);
- ERR_FAIL_COND_V(!f, Vector<uint8_t>());
+ FileAccess *f = FileAccess::open(p_path, READ, r_error);
+ if (!f) {
+ if (r_error) { // if error requested, do not throw error
+ return Vector<uint8_t>();
+ } else {
+ ERR_FAIL_COND_V(!f, Vector<uint8_t>());
+ }
+ }
Vector<uint8_t> data;
data.resize(f->get_len());
f->get_buffer(data.ptrw(), data.size());
@@ -582,6 +588,26 @@ Vector<uint8_t> FileAccess::get_file_as_array(const String &p_path) {
return data;
}
+String FileAccess::get_file_as_string(const String &p_path, Error *r_error) {
+
+ Error err;
+ Vector<uint8_t> array = get_file_as_array(p_path, &err);
+ if (r_error) {
+ *r_error = err;
+ }
+ if (err != OK) {
+ if (r_error) {
+ return String();
+ } else {
+ ERR_FAIL_COND_V(err != OK, String());
+ }
+ }
+
+ String ret;
+ ret.parse_utf8((const char *)array.ptr(), array.size());
+ return ret;
+}
+
String FileAccess::get_md5(const String &p_file) {
FileAccess *f = FileAccess::open(p_file, READ);
diff --git a/core/os/file_access.h b/core/os/file_access.h
index c65b75369c..9df2a5cade 100644
--- a/core/os/file_access.h
+++ b/core/os/file_access.h
@@ -164,7 +164,8 @@ public:
static String get_sha256(const String &p_file);
static String get_multiple_md5(const Vector<String> &p_file);
- static Vector<uint8_t> get_file_as_array(const String &p_path);
+ static Vector<uint8_t> get_file_as_array(const String &p_path, Error *r_error = NULL);
+ static String get_file_as_string(const String &p_path, Error *r_error = NULL);
template <class T>
static void make_default(AccessType p_access) {
diff --git a/core/ustring.cpp b/core/ustring.cpp
index ff8fcaaaaf..d60bd16921 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -3748,6 +3748,24 @@ bool String::is_valid_html_color() const {
return Color::html_is_valid(*this);
}
+bool String::is_valid_filename() const {
+
+ String stripped = strip_edges();
+ if (*this != stripped) {
+ return false;
+ }
+
+ if (stripped == String()) {
+ return false;
+ }
+
+ if (find(":") != -1 || find("/") != -1 || find("\\") != -1 || find("?") != -1 || find("*") != -1 || find("\"") != -1 || find("|") != -1 || find("%") != -1 || find("<") != -1 || find(">") != -1) {
+ return false;
+ } else {
+ return true;
+ }
+}
+
bool String::is_valid_ip_address() const {
if (find(":") >= 0) {
diff --git a/core/ustring.h b/core/ustring.h
index 9288c1526e..85103057df 100644
--- a/core/ustring.h
+++ b/core/ustring.h
@@ -335,6 +335,7 @@ public:
bool is_valid_hex_number(bool p_with_prefix) const;
bool is_valid_html_color() const;
bool is_valid_ip_address() const;
+ bool is_valid_filename() const;
/**
* The constructors must not depend on other overloads
@@ -406,11 +407,18 @@ _FORCE_INLINE_ bool is_str_less(const L *l_ptr, const R *r_ptr) {
//tool translate
#ifdef TOOLS_ENABLED
+//gets parsed
String TTR(const String &);
+//use for c strings
+#define TTRC(m_value) m_value
+//use to avoid parsing (for use later with C strings)
+#define TTRGET(m_value) TTR(m_value)
#else
#define TTR(m_val) (String())
+#define TTRCDEF(m_value) (m_value)
+#define TTRC(m_value) (m_value)
#endif
diff --git a/core/variant_call.cpp b/core/variant_call.cpp
index 9ef7b7e7e6..143b07418e 100644
--- a/core/variant_call.cpp
+++ b/core/variant_call.cpp
@@ -294,6 +294,7 @@ struct _VariantCall {
VCALL_LOCALMEM1R(String, is_valid_hex_number);
VCALL_LOCALMEM0R(String, is_valid_html_color);
VCALL_LOCALMEM0R(String, is_valid_ip_address);
+ VCALL_LOCALMEM0R(String, is_valid_filename);
VCALL_LOCALMEM0R(String, to_int);
VCALL_LOCALMEM0R(String, to_float);
VCALL_LOCALMEM0R(String, hex_to_int);
@@ -341,6 +342,7 @@ struct _VariantCall {
VCALL_LOCALMEM1R(Vector2, project);
VCALL_LOCALMEM1R(Vector2, angle_to);
VCALL_LOCALMEM1R(Vector2, angle_to_point);
+ VCALL_LOCALMEM1R(Vector2, direction_to);
VCALL_LOCALMEM2R(Vector2, linear_interpolate);
VCALL_LOCALMEM2R(Vector2, slerp);
VCALL_LOCALMEM4R(Vector2, cubic_interpolate);
@@ -397,6 +399,7 @@ struct _VariantCall {
VCALL_LOCALMEM1R(Vector3, distance_squared_to);
VCALL_LOCALMEM1R(Vector3, project);
VCALL_LOCALMEM1R(Vector3, angle_to);
+ VCALL_LOCALMEM1R(Vector3, direction_to);
VCALL_LOCALMEM1R(Vector3, slide);
VCALL_LOCALMEM1R(Vector3, bounce);
VCALL_LOCALMEM1R(Vector3, reflect);
@@ -1540,6 +1543,7 @@ void register_variant_methods() {
ADDFUNC1R(STRING, BOOL, String, is_valid_hex_number, BOOL, "with_prefix", varray(false));
ADDFUNC0R(STRING, BOOL, String, is_valid_html_color, varray());
ADDFUNC0R(STRING, BOOL, String, is_valid_ip_address, varray());
+ ADDFUNC0R(STRING, BOOL, String, is_valid_filename, varray());
ADDFUNC0R(STRING, INT, String, to_int, varray());
ADDFUNC0R(STRING, REAL, String, to_float, varray());
ADDFUNC0R(STRING, INT, String, hex_to_int, varray());
@@ -1556,6 +1560,7 @@ void register_variant_methods() {
ADDFUNC0R(VECTOR2, REAL, Vector2, angle, varray());
ADDFUNC0R(VECTOR2, REAL, Vector2, length_squared, varray());
ADDFUNC0R(VECTOR2, BOOL, Vector2, is_normalized, varray());
+ ADDFUNC1R(VECTOR2, VECTOR2, Vector2, direction_to, VECTOR2, "b", varray());
ADDFUNC1R(VECTOR2, REAL, Vector2, distance_to, VECTOR2, "to", varray());
ADDFUNC1R(VECTOR2, REAL, Vector2, distance_squared_to, VECTOR2, "to", varray());
ADDFUNC1R(VECTOR2, VECTOR2, Vector2, project, VECTOR2, "b", varray());
@@ -1604,6 +1609,7 @@ void register_variant_methods() {
ADDFUNC2R(VECTOR3, VECTOR3, Vector3, linear_interpolate, VECTOR3, "b", REAL, "t", varray());
ADDFUNC2R(VECTOR3, VECTOR3, Vector3, slerp, VECTOR3, "b", REAL, "t", varray());
ADDFUNC4R(VECTOR3, VECTOR3, Vector3, cubic_interpolate, VECTOR3, "b", VECTOR3, "pre_a", VECTOR3, "post_b", REAL, "t", varray());
+ ADDFUNC1R(VECTOR3, VECTOR3, Vector3, direction_to, VECTOR3, "b", varray());
ADDFUNC1R(VECTOR3, REAL, Vector3, dot, VECTOR3, "b", varray());
ADDFUNC1R(VECTOR3, VECTOR3, Vector3, cross, VECTOR3, "b", varray());
ADDFUNC1R(VECTOR3, BASIS, Vector3, outer, VECTOR3, "b", varray());
diff --git a/core/vmap.h b/core/vmap.h
index f46ed70a0f..fde9723d71 100644
--- a/core/vmap.h
+++ b/core/vmap.h
@@ -65,7 +65,7 @@ private:
const Pair *a = _cowdata.ptr();
int middle = 0;
-#if DEBUG_ENABLED
+#ifdef DEBUG_ENABLED
if (low > high)
ERR_PRINT("low > high, this may be a bug");
#endif
diff --git a/core/vset.h b/core/vset.h
index 678ec507ba..5f087a5a03 100644
--- a/core/vset.h
+++ b/core/vset.h
@@ -50,7 +50,7 @@ class VSet {
const T *a = &_data[0];
int middle = 0;
-#if DEBUG_ENABLED
+#ifdef DEBUG_ENABLED
if (low > high)
ERR_PRINT("low > high, this may be a bug");
#endif