summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/bind/core_bind.cpp8
-rw-r--r--core/bind/core_bind.h1
-rw-r--r--core/callable.cpp29
-rw-r--r--core/callable.h6
-rw-r--r--core/callable_bind.cpp193
-rw-r--r--core/callable_bind.h85
-rw-r--r--core/core_string_names.cpp2
-rw-r--r--core/core_string_names.h2
-rw-r--r--core/io/http_client.cpp4
-rw-r--r--core/math/geometry_3d.h48
-rw-r--r--core/math/vector2.h8
-rw-r--r--core/object.cpp14
-rw-r--r--core/object.h1
-rw-r--r--core/thread_work_pool.h27
-rw-r--r--core/ustring.cpp41
-rw-r--r--core/variant_call.cpp15
16 files changed, 406 insertions, 78 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp
index c68222c767..baf5d4b928 100644
--- a/core/bind/core_bind.cpp
+++ b/core/bind/core_bind.cpp
@@ -1156,10 +1156,6 @@ Vector<Vector3> _Geometry3D::clip_polygon(const Vector<Vector3> &p_points, const
return Geometry3D::clip_polygon(p_points, p_plane);
}
-int _Geometry3D::get_uv84_normal_bit(const Vector3 &p_vector) {
- return Geometry3D::get_uv84_normal_bit(p_vector);
-}
-
void _Geometry3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("build_box_planes", "extents"), &_Geometry3D::build_box_planes);
ClassDB::bind_method(D_METHOD("build_cylinder_planes", "radius", "height", "sides", "axis"), &_Geometry3D::build_cylinder_planes, DEFVAL(Vector3::AXIS_Z));
@@ -1171,8 +1167,6 @@ void _Geometry3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_closest_point_to_segment_uncapped", "point", "s1", "s2"), &_Geometry3D::get_closest_point_to_segment_uncapped);
- ClassDB::bind_method(D_METHOD("get_uv84_normal_bit", "normal"), &_Geometry3D::get_uv84_normal_bit);
-
ClassDB::bind_method(D_METHOD("ray_intersects_triangle", "from", "dir", "a", "b", "c"), &_Geometry3D::ray_intersects_triangle);
ClassDB::bind_method(D_METHOD("segment_intersects_triangle", "from", "to", "a", "b", "c"), &_Geometry3D::segment_intersects_triangle);
ClassDB::bind_method(D_METHOD("segment_intersects_sphere", "from", "to", "sphere_position", "sphere_radius"), &_Geometry3D::segment_intersects_sphere);
@@ -1743,11 +1737,13 @@ Error _Directory::rename(String p_from, String p_to) {
ERR_FAIL_COND_V_MSG(!is_open(), ERR_UNCONFIGURED, "Directory must be opened before use.");
if (!p_from.is_rel_path()) {
DirAccess *d = DirAccess::create_for_path(p_from);
+ ERR_FAIL_COND_V_MSG(!d->file_exists(p_from), ERR_DOES_NOT_EXIST, "File does not exist.");
Error err = d->rename(p_from, p_to);
memdelete(d);
return err;
}
+ ERR_FAIL_COND_V_MSG(!d->file_exists(p_from), ERR_DOES_NOT_EXIST, "File does not exist.");
return d->rename(p_from, p_to);
}
diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h
index 5c9520d7fe..e75e740cd5 100644
--- a/core/bind/core_bind.h
+++ b/core/bind/core_bind.h
@@ -344,7 +344,6 @@ public:
Vector<Vector3> segment_intersects_sphere(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_sphere_pos, real_t p_sphere_radius);
Vector<Vector3> segment_intersects_cylinder(const Vector3 &p_from, const Vector3 &p_to, float p_height, float p_radius);
Vector<Vector3> segment_intersects_convex(const Vector3 &p_from, const Vector3 &p_to, const Vector<Plane> &p_planes);
- int get_uv84_normal_bit(const Vector3 &p_vector);
Vector<Vector3> clip_polygon(const Vector<Vector3> &p_points, const Plane &p_plane);
diff --git a/core/callable.cpp b/core/callable.cpp
index b7bdc715f8..c368565687 100644
--- a/core/callable.cpp
+++ b/core/callable.cpp
@@ -30,6 +30,7 @@
#include "callable.h"
+#include "callable_bind.h"
#include "core/script_language.h"
#include "message_queue.h"
#include "object.h"
@@ -53,6 +54,18 @@ void Callable::call(const Variant **p_arguments, int p_argcount, Variant &r_retu
}
}
+Callable Callable::bind(const Variant **p_arguments, int p_argcount) const {
+ Vector<Variant> args;
+ args.resize(p_argcount);
+ for (int i = 0; i < p_argcount; i++) {
+ args.write[i] = *p_arguments[i];
+ }
+ return Callable(memnew(CallableCustomBind(*this, args)));
+}
+Callable Callable::unbind(int p_argcount) const {
+ return Callable(memnew(CallableCustomUnbind(*this, p_argcount)));
+}
+
Object *Callable::get_object() const {
if (is_null()) {
return nullptr;
@@ -85,6 +98,18 @@ CallableCustom *Callable::get_custom() const {
return custom;
}
+const Callable *Callable::get_base_comparator() const {
+ const Callable *comparator = nullptr;
+ if (is_custom()) {
+ comparator = custom->get_base_comparator();
+ }
+ if (comparator) {
+ return comparator;
+ } else {
+ return this;
+ }
+}
+
uint32_t Callable::hash() const {
if (is_custom()) {
return custom->hash();
@@ -258,6 +283,10 @@ Callable::~Callable() {
}
}
+const Callable *CallableCustom::get_base_comparator() const {
+ return nullptr;
+}
+
CallableCustom::CallableCustom() {
ref_count.init();
}
diff --git a/core/callable.h b/core/callable.h
index 7fd6b54cf7..936272a681 100644
--- a/core/callable.h
+++ b/core/callable.h
@@ -80,6 +80,9 @@ public:
return method != StringName();
}
+ Callable bind(const Variant **p_arguments, int p_argcount) const;
+ Callable unbind(int p_argcount) const;
+
Object *get_object() const;
ObjectID get_object_id() const;
StringName get_method() const;
@@ -87,6 +90,8 @@ public:
uint32_t hash() const;
+ const Callable *get_base_comparator() const; //used for bind/unbind to do less precise comparisons (ignoring binds) in signal connect/disconnect
+
bool operator==(const Callable &p_callable) const;
bool operator!=(const Callable &p_callable) const;
bool operator<(const Callable &p_callable) const;
@@ -119,6 +124,7 @@ public:
virtual CompareLessFunc get_compare_less_func() const = 0;
virtual ObjectID get_object() const = 0; //must always be able to provide an object
virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const = 0;
+ virtual const Callable *get_base_comparator() const;
CallableCustom();
virtual ~CallableCustom() {}
diff --git a/core/callable_bind.cpp b/core/callable_bind.cpp
new file mode 100644
index 0000000000..da08d3ccbd
--- /dev/null
+++ b/core/callable_bind.cpp
@@ -0,0 +1,193 @@
+/*************************************************************************/
+/* callable_bind.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#include "callable_bind.h"
+
+//////////////////////////////////
+
+uint32_t CallableCustomBind::hash() const {
+ return callable.hash();
+}
+String CallableCustomBind::get_as_text() const {
+ return callable.operator String();
+}
+
+bool CallableCustomBind::_equal_func(const CallableCustom *p_a, const CallableCustom *p_b) {
+ const CallableCustomBind *a = (const CallableCustomBind *)p_a;
+ const CallableCustomBind *b = (const CallableCustomBind *)p_b;
+
+ if (!(a->callable != b->callable)) {
+ return false;
+ }
+
+ if (a->binds.size() != b->binds.size()) {
+ return false;
+ }
+
+ return true;
+}
+
+bool CallableCustomBind::_less_func(const CallableCustom *p_a, const CallableCustom *p_b) {
+ const CallableCustomBind *a = (const CallableCustomBind *)p_a;
+ const CallableCustomBind *b = (const CallableCustomBind *)p_b;
+
+ if (a->callable < b->callable) {
+ return true;
+ } else if (b->callable < a->callable) {
+ return false;
+ }
+
+ return a->binds.size() < b->binds.size();
+}
+
+CallableCustom::CompareEqualFunc CallableCustomBind::get_compare_equal_func() const {
+ return _equal_func;
+}
+CallableCustom::CompareLessFunc CallableCustomBind::get_compare_less_func() const {
+ return _less_func;
+}
+ObjectID CallableCustomBind::get_object() const {
+ return callable.get_object_id();
+}
+const Callable *CallableCustomBind::get_base_comparator() const {
+ return &callable;
+}
+
+void CallableCustomBind::call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const {
+ const Variant **args = (const Variant **)alloca(sizeof(const Variant **) * (binds.size() + p_argcount));
+ for (int i = 0; i < p_argcount; i++) {
+ args[i] = (const Variant *)p_arguments[i];
+ }
+ for (int i = 0; i < binds.size(); i++) {
+ args[i + p_argcount] = (const Variant *)&binds[i];
+ }
+
+ callable.call(args, p_argcount + binds.size(), r_return_value, r_call_error);
+}
+
+CallableCustomBind::CallableCustomBind(const Callable &p_callable, const Vector<Variant> &p_binds) {
+ callable = p_callable;
+ binds = p_binds;
+}
+
+CallableCustomBind::~CallableCustomBind() {
+}
+
+//////////////////////////////////
+
+uint32_t CallableCustomUnbind::hash() const {
+ return callable.hash();
+}
+String CallableCustomUnbind::get_as_text() const {
+ return callable.operator String();
+}
+
+bool CallableCustomUnbind::_equal_func(const CallableCustom *p_a, const CallableCustom *p_b) {
+ const CallableCustomUnbind *a = (const CallableCustomUnbind *)p_a;
+ const CallableCustomUnbind *b = (const CallableCustomUnbind *)p_b;
+
+ if (!(a->callable != b->callable)) {
+ return false;
+ }
+
+ if (a->argcount != b->argcount) {
+ return false;
+ }
+
+ return true;
+}
+
+bool CallableCustomUnbind::_less_func(const CallableCustom *p_a, const CallableCustom *p_b) {
+ const CallableCustomUnbind *a = (const CallableCustomUnbind *)p_a;
+ const CallableCustomUnbind *b = (const CallableCustomUnbind *)p_b;
+
+ if (a->callable < b->callable) {
+ return true;
+ } else if (b->callable < a->callable) {
+ return false;
+ }
+
+ return a->argcount < b->argcount;
+}
+
+CallableCustom::CompareEqualFunc CallableCustomUnbind::get_compare_equal_func() const {
+ return _equal_func;
+}
+CallableCustom::CompareLessFunc CallableCustomUnbind::get_compare_less_func() const {
+ return _less_func;
+}
+ObjectID CallableCustomUnbind::get_object() const {
+ return callable.get_object_id();
+}
+const Callable *CallableCustomUnbind::get_base_comparator() const {
+ return &callable;
+}
+
+void CallableCustomUnbind::call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const {
+ if (argcount > p_argcount) {
+ r_call_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
+ r_call_error.argument = 0;
+ r_call_error.expected = argcount;
+ return;
+ }
+ callable.call(p_arguments, p_argcount - argcount, r_return_value, r_call_error);
+}
+
+CallableCustomUnbind::CallableCustomUnbind(const Callable &p_callable, int p_argcount) {
+ callable = p_callable;
+ argcount = p_argcount;
+}
+
+CallableCustomUnbind::~CallableCustomUnbind() {
+}
+
+Callable callable_bind(const Callable &p_callable, const Variant &p_arg1) {
+ return p_callable.bind((const Variant **)&p_arg1, 1);
+}
+
+Callable callable_bind(const Callable &p_callable, const Variant &p_arg1, const Variant &p_arg2) {
+ const Variant *args[2] = { &p_arg1, &p_arg2 };
+ return p_callable.bind(args, 2);
+}
+
+Callable callable_bind(const Callable &p_callable, const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3) {
+ const Variant *args[3] = { &p_arg1, &p_arg2, &p_arg3 };
+ return p_callable.bind(args, 3);
+}
+
+Callable callable_bind(const Callable &p_callable, const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3, const Variant &p_arg4) {
+ const Variant *args[4] = { &p_arg1, &p_arg2, &p_arg3, &p_arg4 };
+ return p_callable.bind(args, 4);
+}
+
+Callable callable_bind(const Callable &p_callable, const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3, const Variant &p_arg4, const Variant &p_arg5) {
+ const Variant *args[5] = { &p_arg1, &p_arg2, &p_arg3, &p_arg4, &p_arg5 };
+ return p_callable.bind(args, 5);
+}
diff --git a/core/callable_bind.h b/core/callable_bind.h
new file mode 100644
index 0000000000..21b9228be3
--- /dev/null
+++ b/core/callable_bind.h
@@ -0,0 +1,85 @@
+/*************************************************************************/
+/* callable_bind.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#ifndef CALLABLE_BIND_H
+#define CALLABLE_BIND_H
+
+#include "core/callable.h"
+#include "core/variant.h"
+
+class CallableCustomBind : public CallableCustom {
+ Callable callable;
+ Vector<Variant> binds;
+
+ static bool _equal_func(const CallableCustom *p_a, const CallableCustom *p_b);
+ static bool _less_func(const CallableCustom *p_a, const CallableCustom *p_b);
+
+public:
+ //for every type that inherits, these must always be the same for this type
+ virtual uint32_t hash() const;
+ virtual String get_as_text() const;
+ virtual CompareEqualFunc get_compare_equal_func() const;
+ virtual CompareLessFunc get_compare_less_func() const;
+ virtual ObjectID get_object() const; //must always be able to provide an object
+ virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const;
+ virtual const Callable *get_base_comparator() const;
+
+ CallableCustomBind(const Callable &p_callable, const Vector<Variant> &p_binds);
+ virtual ~CallableCustomBind();
+};
+
+class CallableCustomUnbind : public CallableCustom {
+ Callable callable;
+ int argcount;
+
+ static bool _equal_func(const CallableCustom *p_a, const CallableCustom *p_b);
+ static bool _less_func(const CallableCustom *p_a, const CallableCustom *p_b);
+
+public:
+ //for every type that inherits, these must always be the same for this type
+ virtual uint32_t hash() const;
+ virtual String get_as_text() const;
+ virtual CompareEqualFunc get_compare_equal_func() const;
+ virtual CompareLessFunc get_compare_less_func() const;
+ virtual ObjectID get_object() const; //must always be able to provide an object
+ virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const;
+ virtual const Callable *get_base_comparator() const;
+
+ CallableCustomUnbind(const Callable &p_callable, int p_argcount);
+ virtual ~CallableCustomUnbind();
+};
+
+Callable callable_bind(const Callable &p_callable, const Variant &p_arg1);
+Callable callable_bind(const Callable &p_callable, const Variant &p_arg1, const Variant &p_arg2);
+Callable callable_bind(const Callable &p_callable, const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3);
+Callable callable_bind(const Callable &p_callable, const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3, const Variant &p_arg4);
+Callable callable_bind(const Callable &p_callable, const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3, const Variant &p_arg4, const Variant &p_arg5);
+
+#endif // CALLABLE_BIND_H
diff --git a/core/core_string_names.cpp b/core/core_string_names.cpp
index 1d3b333efc..6f86f107e6 100644
--- a/core/core_string_names.cpp
+++ b/core/core_string_names.cpp
@@ -73,6 +73,8 @@ CoreStringNames::CoreStringNames() :
a8(StaticCString::create("a8")),
call(StaticCString::create("call")),
call_deferred(StaticCString::create("call_deferred")),
+ bind(StaticCString::create("bind")),
+ unbind(StaticCString::create("unbind")),
emit(StaticCString::create("emit")),
notification(StaticCString::create("notification")) {
}
diff --git a/core/core_string_names.h b/core/core_string_names.h
index 1a18c84572..43597ef301 100644
--- a/core/core_string_names.h
+++ b/core/core_string_names.h
@@ -92,6 +92,8 @@ public:
StringName call;
StringName call_deferred;
+ StringName bind;
+ StringName unbind;
StringName emit;
StringName notification;
};
diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp
index 46e45500bf..a25413b21b 100644
--- a/core/io/http_client.cpp
+++ b/core/io/http_client.cpp
@@ -96,6 +96,10 @@ Error HTTPClient::connect_to_host(const String &p_host, int p_port, bool p_ssl,
void HTTPClient::set_connection(const Ref<StreamPeer> &p_connection) {
ERR_FAIL_COND_MSG(p_connection.is_null(), "Connection is not a reference to a valid StreamPeer object.");
+ if (connection == p_connection) {
+ return;
+ }
+
close();
connection = p_connection;
status = STATUS_CONNECTED;
diff --git a/core/math/geometry_3d.h b/core/math/geometry_3d.h
index 6bbf518141..11cac8f108 100644
--- a/core/math/geometry_3d.h
+++ b/core/math/geometry_3d.h
@@ -636,54 +636,6 @@ public:
void optimize_vertices();
};
- _FORCE_INLINE_ static int get_uv84_normal_bit(const Vector3 &p_vector) {
- int lat = Math::fast_ftoi(Math::floor(Math::acos(p_vector.dot(Vector3(0, 1, 0))) * 4.0 / Math_PI + 0.5));
-
- if (lat == 0) {
- return 24;
- } else if (lat == 4) {
- return 25;
- }
-
- int lon = Math::fast_ftoi(Math::floor((Math_PI + Math::atan2(p_vector.x, p_vector.z)) * 8.0 / (Math_PI * 2.0) + 0.5)) % 8;
-
- return lon + (lat - 1) * 8;
- }
-
- _FORCE_INLINE_ static int get_uv84_normal_bit_neighbors(int p_idx) {
- if (p_idx == 24) {
- return 1 | 2 | 4 | 8;
- } else if (p_idx == 25) {
- return (1 << 23) | (1 << 22) | (1 << 21) | (1 << 20);
- } else {
- int ret = 0;
- if ((p_idx % 8) == 0) {
- ret |= (1 << (p_idx + 7));
- } else {
- ret |= (1 << (p_idx - 1));
- }
- if ((p_idx % 8) == 7) {
- ret |= (1 << (p_idx - 7));
- } else {
- ret |= (1 << (p_idx + 1));
- }
-
- int mask = ret | (1 << p_idx);
- if (p_idx < 8) {
- ret |= 24;
- } else {
- ret |= mask >> 8;
- }
-
- if (p_idx >= 16) {
- ret |= 25;
- } else {
- ret |= mask << 8;
- }
-
- return ret;
- }
- }
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);
static Vector<Plane> build_box_planes(const Vector3 &p_extents);
diff --git a/core/math/vector2.h b/core/math/vector2.h
index f41bcc15bc..c2a2656e72 100644
--- a/core/math/vector2.h
+++ b/core/math/vector2.h
@@ -65,6 +65,14 @@ struct Vector2 {
real_t length() const;
real_t length_squared() const;
+ Vector2 min(const Vector2 &p_vector2) const {
+ return Vector2(MIN(x, p_vector2.x), MIN(y, p_vector2.y));
+ }
+
+ Vector2 max(const Vector2 &p_vector2) const {
+ return Vector2(MAX(x, p_vector2.x), MAX(y, p_vector2.y));
+ }
+
real_t distance_to(const Vector2 &p_vector2) const;
real_t distance_squared_to(const Vector2 &p_vector2) const;
real_t angle_to(const Vector2 &p_vector2) const;
diff --git a/core/object.cpp b/core/object.cpp
index 67c605c39b..0d9e5c5116 100644
--- a/core/object.cpp
+++ b/core/object.cpp
@@ -1315,9 +1315,10 @@ Error Object::connect(const StringName &p_signal, const Callable &p_callable, co
Callable target = p_callable;
- if (s->slot_map.has(target)) {
+ //compare with the base callable, so binds can be ignored
+ if (s->slot_map.has(*target.get_base_comparator())) {
if (p_flags & CONNECT_REFERENCE_COUNTED) {
- s->slot_map[target].reference_count++;
+ s->slot_map[*target.get_base_comparator()].reference_count++;
return OK;
} else {
ERR_FAIL_V_MSG(ERR_INVALID_PARAMETER, "Signal '" + p_signal + "' is already connected to given callable '" + p_callable + "' in that object.");
@@ -1337,7 +1338,8 @@ Error Object::connect(const StringName &p_signal, const Callable &p_callable, co
slot.reference_count = 1;
}
- s->slot_map[target] = slot;
+ //use callable version as key, so binds can be ignored
+ s->slot_map[*target.get_base_comparator()] = slot;
return OK;
}
@@ -1364,7 +1366,7 @@ bool Object::is_connected(const StringName &p_signal, const Callable &p_callable
Callable target = p_callable;
- return s->slot_map.has(target);
+ return s->slot_map.has(*target.get_base_comparator());
//const Map<Signal::Target,Signal::Slot>::Element *E = s->slot_map.find(target);
//return (E!=nullptr );
}
@@ -1386,7 +1388,7 @@ void Object::_disconnect(const StringName &p_signal, const Callable &p_callable,
SignalData *s = signal_map.getptr(p_signal);
ERR_FAIL_COND_MSG(!s, vformat("Nonexistent signal '%s' in %s.", p_signal, to_string()));
- ERR_FAIL_COND_MSG(!s->slot_map.has(p_callable), "Disconnecting nonexistent signal '" + p_signal + "', callable: " + p_callable + ".");
+ ERR_FAIL_COND_MSG(!s->slot_map.has(*p_callable.get_base_comparator()), "Disconnecting nonexistent signal '" + p_signal + "', callable: " + p_callable + ".");
SignalData::Slot *slot = &s->slot_map[p_callable];
@@ -1398,7 +1400,7 @@ void Object::_disconnect(const StringName &p_signal, const Callable &p_callable,
}
target_object->connections.erase(slot->cE);
- s->slot_map.erase(p_callable);
+ s->slot_map.erase(*p_callable.get_base_comparator());
if (s->slot_map.empty() && ClassDB::has_signal(get_class_name(), p_signal)) {
//not user signal, delete
diff --git a/core/object.h b/core/object.h
index 12ef600dfc..f600e597ec 100644
--- a/core/object.h
+++ b/core/object.h
@@ -31,6 +31,7 @@
#ifndef OBJECT_H
#define OBJECT_H
+#include "core/callable_bind.h"
#include "core/hash_map.h"
#include "core/list.h"
#include "core/map.h"
diff --git a/core/thread_work_pool.h b/core/thread_work_pool.h
index e21d3974ee..661060aa3f 100644
--- a/core/thread_work_pool.h
+++ b/core/thread_work_pool.h
@@ -73,13 +73,15 @@ class ThreadWorkPool {
ThreadData *threads = nullptr;
uint32_t thread_count = 0;
+ BaseWork *current_work = nullptr;
static void _thread_function(ThreadData *p_thread);
public:
template <class C, class M, class U>
- void do_work(uint32_t p_elements, C *p_instance, M p_method, U p_userdata) {
+ void begin_work(uint32_t p_elements, C *p_instance, M p_method, U p_userdata) {
ERR_FAIL_COND(!threads); //never initialized
+ ERR_FAIL_COND(current_work != nullptr);
index.store(0);
@@ -90,16 +92,37 @@ public:
w->index = &index;
w->max_elements = p_elements;
+ current_work = w;
+
for (uint32_t i = 0; i < thread_count; i++) {
threads[i].work = w;
threads[i].start.post();
}
+ }
+
+ bool is_working() const {
+ return current_work != nullptr;
+ }
+
+ uint32_t get_work_index() const {
+ return index;
+ }
+
+ void end_work() {
+ ERR_FAIL_COND(current_work == nullptr);
for (uint32_t i = 0; i < thread_count; i++) {
threads[i].completed.wait();
threads[i].work = nullptr;
}
- memdelete(w);
+ memdelete(current_work);
+ current_work = nullptr;
+ }
+
+ template <class C, class M, class U>
+ void do_work(uint32_t p_elements, C *p_instance, M p_method, U p_userdata) {
+ begin_work(p_elements, p_instance, p_method, p_userdata);
+ end_work();
}
void init(int p_thread_count = -1);
diff --git a/core/ustring.cpp b/core/ustring.cpp
index 0033c31e20..e382ef3746 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -787,29 +787,46 @@ signed char String::naturalnocasecmp_to(const String &p_str) const {
if (!*that_str) {
return 1;
} else if (IS_DIGIT(*this_str)) {
- int64_t this_int, that_int;
-
if (!IS_DIGIT(*that_str)) {
return -1;
}
- /* Compare the numbers */
- this_int = to_int(this_str, -1, true);
- that_int = to_int(that_str, -1, true);
+ // Keep ptrs to start of numerical sequences
+ const char32_t *this_substr = this_str;
+ const char32_t *that_substr = that_str;
- if (this_int < that_int) {
- return -1;
- } else if (this_int > that_int) {
- return 1;
- }
-
- /* Skip */
+ // Compare lengths of both numerical sequences, ignoring leading zeros
while (IS_DIGIT(*this_str)) {
this_str++;
}
while (IS_DIGIT(*that_str)) {
that_str++;
}
+ while (*this_substr == '0') {
+ this_substr++;
+ }
+ while (*that_substr == '0') {
+ that_substr++;
+ }
+ int this_len = this_str - this_substr;
+ int that_len = that_str - that_substr;
+
+ if (this_len < that_len) {
+ return -1;
+ } else if (this_len > that_len) {
+ return 1;
+ }
+
+ // If lengths equal, compare lexicographically
+ while (this_substr != this_str && that_substr != that_str) {
+ if (*this_substr < *that_substr) {
+ return -1;
+ } else if (*this_substr > *that_substr) {
+ return 1;
+ }
+ this_substr++;
+ that_substr++;
+ }
} else if (IS_DIGIT(*that_str)) {
return 1;
} else {
diff --git a/core/variant_call.cpp b/core/variant_call.cpp
index 5fd970c8e1..6ee63e1610 100644
--- a/core/variant_call.cpp
+++ b/core/variant_call.cpp
@@ -586,6 +586,7 @@ struct _VariantCall {
VCALL_LOCALMEM0(Callable, get_object_id);
VCALL_LOCALMEM0(Callable, get_method);
VCALL_LOCALMEM0(Callable, hash);
+ VCALL_LOCALMEM1R(Callable, unbind);
VCALL_LOCALMEM0R(Signal, is_null);
VCALL_LOCALMEM0R(Signal, get_object);
@@ -1347,11 +1348,14 @@ void Variant::call_ptr(const StringName &p_method, const Variant **p_args, int p
if (p_method == CoreStringNames::get_singleton()->call) {
reinterpret_cast<const Callable *>(_data._mem)->call(p_args, p_argcount, ret, r_error);
valid = true;
- }
- if (p_method == CoreStringNames::get_singleton()->call_deferred) {
+ } else if (p_method == CoreStringNames::get_singleton()->call_deferred) {
reinterpret_cast<const Callable *>(_data._mem)->call_deferred(p_args, p_argcount);
valid = true;
+ } else if (p_method == CoreStringNames::get_singleton()->bind) {
+ ret = reinterpret_cast<const Callable *>(_data._mem)->bind(p_args, p_argcount);
+ valid = true;
}
+
} else if (type == SIGNAL) {
if (p_method == CoreStringNames::get_singleton()->emit) {
if (r_ret) {
@@ -1696,9 +1700,13 @@ void Variant::get_method_list(List<MethodInfo> *p_list) const {
if (type == CALLABLE) {
MethodInfo mi;
+
+ mi.name = "bind";
+ mi.flags |= METHOD_FLAG_VARARG;
+ p_list->push_back(mi);
+
mi.name = "call";
mi.return_val.usage = PROPERTY_USAGE_NIL_IS_VARIANT;
- mi.flags |= METHOD_FLAG_VARARG;
p_list->push_back(mi);
@@ -2130,6 +2138,7 @@ void register_variant_methods() {
ADDFUNC0R(CALLABLE, INT, Callable, get_object_id, varray());
ADDFUNC0R(CALLABLE, STRING_NAME, Callable, get_method, varray());
ADDFUNC0R(CALLABLE, INT, Callable, hash, varray());
+ ADDFUNC1R(CALLABLE, CALLABLE, Callable, unbind, INT, "argcount", varray());
ADDFUNC0R(SIGNAL, BOOL, Signal, is_null, varray());
ADDFUNC0R(SIGNAL, OBJECT, Signal, get_object, varray());