summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/SCsub1
-rw-r--r--core/config/SCsub1
-rw-r--r--core/config/engine.cpp8
-rw-r--r--core/config/engine.h3
-rw-r--r--core/core_bind.cpp17
-rw-r--r--core/core_bind.h5
-rw-r--r--core/crypto/SCsub1
-rw-r--r--core/debugger/SCsub1
-rw-r--r--core/error/SCsub1
-rw-r--r--core/extension/SCsub1
-rw-r--r--core/input/SCsub1
-rw-r--r--core/io/SCsub1
-rw-r--r--core/io/pck_packer.cpp12
-rw-r--r--core/io/pck_packer.h4
-rw-r--r--core/io/resource.cpp19
-rw-r--r--core/io/resource.h5
-rw-r--r--core/math/SCsub1
-rw-r--r--core/object/SCsub1
-rw-r--r--core/object/callable_method_pointer.h137
-rw-r--r--core/object/object.cpp19
-rw-r--r--core/object/object.h1
-rw-r--r--core/object/script_language.cpp12
-rw-r--r--core/object/script_language.h5
-rw-r--r--core/object/undo_redo.cpp8
-rw-r--r--core/object/undo_redo.h1
-rw-r--r--core/os/SCsub1
-rw-r--r--core/string/SCsub1
-rw-r--r--core/string/ustring.cpp25
-rw-r--r--core/string/ustring.h1
-rw-r--r--core/templates/SCsub1
-rw-r--r--core/variant/SCsub1
-rw-r--r--core/variant/binder_common.h4
-rw-r--r--core/variant/callable.cpp7
-rw-r--r--core/variant/callable.h1
-rw-r--r--core/variant/variant_call.cpp1
-rw-r--r--core/variant/variant_op.h30
36 files changed, 223 insertions, 116 deletions
diff --git a/core/SCsub b/core/SCsub
index c8267ae960..8bda230b87 100644
--- a/core/SCsub
+++ b/core/SCsub
@@ -1,4 +1,5 @@
#!/usr/bin/env python
+from misc.utility.scons_hints import *
Import("env")
diff --git a/core/config/SCsub b/core/config/SCsub
index bf70285490..1417a258c1 100644
--- a/core/config/SCsub
+++ b/core/config/SCsub
@@ -1,4 +1,5 @@
#!/usr/bin/env python
+from misc.utility.scons_hints import *
Import("env")
diff --git a/core/config/engine.cpp b/core/config/engine.cpp
index 9cdc21fe8e..d77c913314 100644
--- a/core/config/engine.cpp
+++ b/core/config/engine.cpp
@@ -267,6 +267,14 @@ bool Engine::is_extra_gpu_memory_tracking_enabled() const {
return extra_gpu_memory_tracking;
}
+void Engine::set_print_to_stdout(bool p_enabled) {
+ CoreGlobals::print_line_enabled = p_enabled;
+}
+
+bool Engine::is_printing_to_stdout() const {
+ return CoreGlobals::print_line_enabled;
+}
+
void Engine::set_print_error_messages(bool p_enabled) {
CoreGlobals::print_error_enabled = p_enabled;
}
diff --git a/core/config/engine.h b/core/config/engine.h
index f858eba328..a0b1ffa981 100644
--- a/core/config/engine.h
+++ b/core/config/engine.h
@@ -128,6 +128,9 @@ public:
void set_time_scale(double p_scale);
double get_time_scale() const;
+ void set_print_to_stdout(bool p_enabled);
+ bool is_printing_to_stdout() const;
+
void set_print_error_messages(bool p_enabled);
bool is_printing_error_messages() const;
void print_header(const String &p_string) const;
diff --git a/core/core_bind.cpp b/core/core_bind.cpp
index bbfbb6e3cd..891e3a28c9 100644
--- a/core/core_bind.cpp
+++ b/core/core_bind.cpp
@@ -184,6 +184,10 @@ void ResourceSaver::remove_resource_format_saver(Ref<ResourceFormatSaver> p_form
::ResourceSaver::remove_resource_format_saver(p_format_saver);
}
+ResourceUID::ID ResourceSaver::get_resource_id_for_path(const String &p_path, bool p_generate) {
+ return ::ResourceSaver::get_resource_id_for_path(p_path, p_generate);
+}
+
ResourceSaver *ResourceSaver::singleton = nullptr;
void ResourceSaver::_bind_methods() {
@@ -191,6 +195,7 @@ void ResourceSaver::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_recognized_extensions", "type"), &ResourceSaver::get_recognized_extensions);
ClassDB::bind_method(D_METHOD("add_resource_format_saver", "format_saver", "at_front"), &ResourceSaver::add_resource_format_saver, DEFVAL(false));
ClassDB::bind_method(D_METHOD("remove_resource_format_saver", "format_saver"), &ResourceSaver::remove_resource_format_saver);
+ ClassDB::bind_method(D_METHOD("get_resource_id_for_path", "path", "generate"), &ResourceSaver::get_resource_id_for_path, DEFVAL(false));
BIND_BITFIELD_FLAG(FLAG_NONE);
BIND_BITFIELD_FLAG(FLAG_RELATIVE_PATHS);
@@ -1848,6 +1853,14 @@ String Engine::get_write_movie_path() const {
return ::Engine::get_singleton()->get_write_movie_path();
}
+void Engine::set_print_to_stdout(bool p_enabled) {
+ ::Engine::get_singleton()->set_print_to_stdout(p_enabled);
+}
+
+bool Engine::is_printing_to_stdout() const {
+ return ::Engine::get_singleton()->is_printing_to_stdout();
+}
+
void Engine::set_print_error_messages(bool p_enabled) {
::Engine::get_singleton()->set_print_error_messages(p_enabled);
}
@@ -1916,10 +1929,14 @@ void Engine::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_write_movie_path"), &Engine::get_write_movie_path);
+ ClassDB::bind_method(D_METHOD("set_print_to_stdout", "enabled"), &Engine::set_print_to_stdout);
+ ClassDB::bind_method(D_METHOD("is_printing_to_stdout"), &Engine::is_printing_to_stdout);
+
ClassDB::bind_method(D_METHOD("set_print_error_messages", "enabled"), &Engine::set_print_error_messages);
ClassDB::bind_method(D_METHOD("is_printing_error_messages"), &Engine::is_printing_error_messages);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "print_error_messages"), "set_print_error_messages", "is_printing_error_messages");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "print_to_stdout"), "set_print_to_stdout", "is_printing_to_stdout");
ADD_PROPERTY(PropertyInfo(Variant::INT, "physics_ticks_per_second"), "set_physics_ticks_per_second", "get_physics_ticks_per_second");
ADD_PROPERTY(PropertyInfo(Variant::INT, "max_physics_steps_per_frame"), "set_max_physics_steps_per_frame", "get_max_physics_steps_per_frame");
ADD_PROPERTY(PropertyInfo(Variant::INT, "max_fps"), "set_max_fps", "get_max_fps");
diff --git a/core/core_bind.h b/core/core_bind.h
index 2a31e64425..ce0bde3c05 100644
--- a/core/core_bind.h
+++ b/core/core_bind.h
@@ -116,6 +116,8 @@ public:
void add_resource_format_saver(Ref<ResourceFormatSaver> p_format_saver, bool p_at_front);
void remove_resource_format_saver(Ref<ResourceFormatSaver> p_format_saver);
+ ResourceUID::ID get_resource_id_for_path(const String &p_path, bool p_generate = false);
+
ResourceSaver() { singleton = this; }
};
@@ -567,6 +569,9 @@ public:
// `set_write_movie_path()` is not exposed to the scripting API as changing it at run-time has no effect.
String get_write_movie_path() const;
+ void set_print_to_stdout(bool p_enabled);
+ bool is_printing_to_stdout() const;
+
void set_print_error_messages(bool p_enabled);
bool is_printing_error_messages() const;
diff --git a/core/crypto/SCsub b/core/crypto/SCsub
index 8cff3cf679..3cea6bfb47 100644
--- a/core/crypto/SCsub
+++ b/core/crypto/SCsub
@@ -1,4 +1,5 @@
#!/usr/bin/env python
+from misc.utility.scons_hints import *
Import("env")
diff --git a/core/debugger/SCsub b/core/debugger/SCsub
index 19a6549225..ab81175894 100644
--- a/core/debugger/SCsub
+++ b/core/debugger/SCsub
@@ -1,4 +1,5 @@
#!/usr/bin/env python
+from misc.utility.scons_hints import *
Import("env")
diff --git a/core/error/SCsub b/core/error/SCsub
index dfd6248a94..08089d31b0 100644
--- a/core/error/SCsub
+++ b/core/error/SCsub
@@ -1,4 +1,5 @@
#!/usr/bin/env python
+from misc.utility.scons_hints import *
Import("env")
diff --git a/core/extension/SCsub b/core/extension/SCsub
index 6ab2d2b0a6..8688ca5b6e 100644
--- a/core/extension/SCsub
+++ b/core/extension/SCsub
@@ -1,4 +1,5 @@
#!/usr/bin/env python
+from misc.utility.scons_hints import *
Import("env")
diff --git a/core/input/SCsub b/core/input/SCsub
index d8e6f33156..521f7702e4 100644
--- a/core/input/SCsub
+++ b/core/input/SCsub
@@ -1,4 +1,5 @@
#!/usr/bin/env python
+from misc.utility.scons_hints import *
Import("env")
diff --git a/core/io/SCsub b/core/io/SCsub
index 19a6549225..ab81175894 100644
--- a/core/io/SCsub
+++ b/core/io/SCsub
@@ -1,4 +1,5 @@
#!/usr/bin/env python
+from misc.utility.scons_hints import *
Import("env")
diff --git a/core/io/pck_packer.cpp b/core/io/pck_packer.cpp
index a7c715c318..93179d9a11 100644
--- a/core/io/pck_packer.cpp
+++ b/core/io/pck_packer.cpp
@@ -47,12 +47,12 @@ static int _get_pad(int p_alignment, int p_n) {
}
void PCKPacker::_bind_methods() {
- ClassDB::bind_method(D_METHOD("pck_start", "pck_name", "alignment", "key", "encrypt_directory"), &PCKPacker::pck_start, DEFVAL(32), DEFVAL("0000000000000000000000000000000000000000000000000000000000000000"), DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("pck_start", "pck_path", "alignment", "key", "encrypt_directory"), &PCKPacker::pck_start, DEFVAL(32), DEFVAL("0000000000000000000000000000000000000000000000000000000000000000"), DEFVAL(false));
ClassDB::bind_method(D_METHOD("add_file", "pck_path", "source_path", "encrypt"), &PCKPacker::add_file, DEFVAL(false));
ClassDB::bind_method(D_METHOD("flush", "verbose"), &PCKPacker::flush, DEFVAL(false));
}
-Error PCKPacker::pck_start(const String &p_file, int p_alignment, const String &p_key, bool p_encrypt_directory) {
+Error PCKPacker::pck_start(const String &p_pck_path, int p_alignment, const String &p_key, bool p_encrypt_directory) {
ERR_FAIL_COND_V_MSG((p_key.is_empty() || !p_key.is_valid_hex_number(false) || p_key.length() != 64), ERR_CANT_CREATE, "Invalid Encryption Key (must be 64 characters long).");
ERR_FAIL_COND_V_MSG(p_alignment <= 0, ERR_CANT_CREATE, "Invalid alignment, must be greater then 0.");
@@ -83,8 +83,8 @@ Error PCKPacker::pck_start(const String &p_file, int p_alignment, const String &
}
enc_dir = p_encrypt_directory;
- file = FileAccess::open(p_file, FileAccess::WRITE);
- ERR_FAIL_COND_V_MSG(file.is_null(), ERR_CANT_CREATE, "Can't open file to write: " + String(p_file) + ".");
+ file = FileAccess::open(p_pck_path, FileAccess::WRITE);
+ ERR_FAIL_COND_V_MSG(file.is_null(), ERR_CANT_CREATE, "Can't open file to write: " + String(p_pck_path) + ".");
alignment = p_alignment;
@@ -106,7 +106,7 @@ Error PCKPacker::pck_start(const String &p_file, int p_alignment, const String &
return OK;
}
-Error PCKPacker::add_file(const String &p_file, const String &p_src, bool p_encrypt) {
+Error PCKPacker::add_file(const String &p_pck_path, const String &p_src, bool p_encrypt) {
ERR_FAIL_COND_V_MSG(file.is_null(), ERR_INVALID_PARAMETER, "File must be opened before use.");
Ref<FileAccess> f = FileAccess::open(p_src, FileAccess::READ);
@@ -117,7 +117,7 @@ Error PCKPacker::add_file(const String &p_file, const String &p_src, bool p_encr
File pf;
// Simplify path here and on every 'files' access so that paths that have extra '/'
// symbols in them still match to the MD5 hash for the saved path.
- pf.path = p_file.simplify_path();
+ pf.path = p_pck_path.simplify_path();
pf.src_path = p_src;
pf.ofs = ofs;
pf.size = f->get_length();
diff --git a/core/io/pck_packer.h b/core/io/pck_packer.h
index 8764fc90a0..5aac833532 100644
--- a/core/io/pck_packer.h
+++ b/core/io/pck_packer.h
@@ -58,8 +58,8 @@ class PCKPacker : public RefCounted {
Vector<File> files;
public:
- Error pck_start(const String &p_file, int p_alignment = 32, const String &p_key = "0000000000000000000000000000000000000000000000000000000000000000", bool p_encrypt_directory = false);
- Error add_file(const String &p_file, const String &p_src, bool p_encrypt = false);
+ Error pck_start(const String &p_pck_path, int p_alignment = 32, const String &p_key = "0000000000000000000000000000000000000000000000000000000000000000", bool p_encrypt_directory = false);
+ Error add_file(const String &p_pck_path, const String &p_src, bool p_encrypt = false);
Error flush(bool p_verbose = false);
PCKPacker() {}
diff --git a/core/io/resource.cpp b/core/io/resource.cpp
index 6177cba6a4..5f8a4b85a4 100644
--- a/core/io/resource.cpp
+++ b/core/io/resource.cpp
@@ -96,6 +96,7 @@ String Resource::get_path() const {
void Resource::set_path_cache(const String &p_path) {
path_cache = p_path;
+ GDVIRTUAL_CALL(_set_path_cache, p_path);
}
String Resource::generate_scene_unique_id() {
@@ -188,6 +189,7 @@ void Resource::disconnect_changed(const Callable &p_callable) {
}
void Resource::reset_state() {
+ GDVIRTUAL_CALL(_reset_state);
}
Error Resource::copy_from(const Ref<Resource> &p_resource) {
@@ -495,9 +497,9 @@ void Resource::set_as_translation_remapped(bool p_remapped) {
}
}
-#ifdef TOOLS_ENABLED
//helps keep IDs same number when loading/saving scenes. -1 clears ID and it Returns -1 when no id stored
void Resource::set_id_for_path(const String &p_path, const String &p_id) {
+#ifdef TOOLS_ENABLED
if (p_id.is_empty()) {
ResourceCache::path_cache_lock.write_lock();
ResourceCache::resource_path_cache[p_path].erase(get_path());
@@ -507,9 +509,11 @@ void Resource::set_id_for_path(const String &p_path, const String &p_id) {
ResourceCache::resource_path_cache[p_path][get_path()] = p_id;
ResourceCache::path_cache_lock.write_unlock();
}
+#endif
}
String Resource::get_id_for_path(const String &p_path) const {
+#ifdef TOOLS_ENABLED
ResourceCache::path_cache_lock.read_lock();
if (ResourceCache::resource_path_cache[p_path].has(get_path())) {
String result = ResourceCache::resource_path_cache[p_path][get_path()];
@@ -519,13 +523,16 @@ String Resource::get_id_for_path(const String &p_path) const {
ResourceCache::path_cache_lock.read_unlock();
return "";
}
-}
+#else
+ return "";
#endif
+}
void Resource::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_path", "path"), &Resource::_set_path);
ClassDB::bind_method(D_METHOD("take_over_path", "path"), &Resource::_take_over_path);
ClassDB::bind_method(D_METHOD("get_path"), &Resource::get_path);
+ ClassDB::bind_method(D_METHOD("set_path_cache", "path"), &Resource::set_path_cache);
ClassDB::bind_method(D_METHOD("set_name", "name"), &Resource::set_name);
ClassDB::bind_method(D_METHOD("get_name"), &Resource::get_name);
ClassDB::bind_method(D_METHOD("get_rid"), &Resource::get_rid);
@@ -533,6 +540,12 @@ void Resource::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_local_to_scene"), &Resource::is_local_to_scene);
ClassDB::bind_method(D_METHOD("get_local_scene"), &Resource::get_local_scene);
ClassDB::bind_method(D_METHOD("setup_local_to_scene"), &Resource::setup_local_to_scene);
+ ClassDB::bind_method(D_METHOD("reset_state"), &Resource::reset_state);
+
+ ClassDB::bind_method(D_METHOD("set_id_for_path", "path", "id"), &Resource::set_id_for_path);
+ ClassDB::bind_method(D_METHOD("get_id_for_path", "path"), &Resource::get_id_for_path);
+
+ ClassDB::bind_method(D_METHOD("is_built_in"), &Resource::is_built_in);
ClassDB::bind_static_method("Resource", D_METHOD("generate_scene_unique_id"), &Resource::generate_scene_unique_id);
ClassDB::bind_method(D_METHOD("set_scene_unique_id", "id"), &Resource::set_scene_unique_id);
@@ -552,6 +565,8 @@ void Resource::_bind_methods() {
GDVIRTUAL_BIND(_setup_local_to_scene);
GDVIRTUAL_BIND(_get_rid);
+ GDVIRTUAL_BIND(_reset_state);
+ GDVIRTUAL_BIND(_set_path_cache, "path");
}
Resource::Resource() :
diff --git a/core/io/resource.h b/core/io/resource.h
index 2c1a431255..8966c0233c 100644
--- a/core/io/resource.h
+++ b/core/io/resource.h
@@ -89,6 +89,9 @@ protected:
GDVIRTUAL0RC(RID, _get_rid);
+ GDVIRTUAL1C(_set_path_cache, String);
+ GDVIRTUAL0(_reset_state);
+
public:
static Node *(*_get_local_scene_func)(); //used by editor
static void (*_update_configuration_warning)(); //used by editor
@@ -144,11 +147,9 @@ public:
virtual RID get_rid() const; // some resources may offer conversion to RID
-#ifdef TOOLS_ENABLED
//helps keep IDs same number when loading/saving scenes. -1 clears ID and it Returns -1 when no id stored
void set_id_for_path(const String &p_path, const String &p_id);
String get_id_for_path(const String &p_path) const;
-#endif
Resource();
~Resource();
diff --git a/core/math/SCsub b/core/math/SCsub
index c8fdac207e..6ea3ab6b12 100644
--- a/core/math/SCsub
+++ b/core/math/SCsub
@@ -1,4 +1,5 @@
#!/usr/bin/env python
+from misc.utility.scons_hints import *
Import("env")
diff --git a/core/object/SCsub b/core/object/SCsub
index 7c00bb719e..3d0d2c14dd 100644
--- a/core/object/SCsub
+++ b/core/object/SCsub
@@ -1,4 +1,5 @@
#!/usr/bin/env python
+from misc.utility.scons_hints import *
Import("env")
diff --git a/core/object/callable_method_pointer.h b/core/object/callable_method_pointer.h
index 1b29e1778a..86c66593bd 100644
--- a/core/object/callable_method_pointer.h
+++ b/core/object/callable_method_pointer.h
@@ -37,6 +37,8 @@
#include "core/variant/binder_common.h"
#include "core/variant/callable.h"
+#include <type_traits>
+
class CallableCustomMethodPointerBase : public CallableCustom {
uint32_t *comp_ptr = nullptr;
uint32_t comp_size;
@@ -77,12 +79,13 @@ public:
virtual uint32_t hash() const;
};
-template <typename T, typename... P>
+template <typename T, typename R, typename... P>
class CallableCustomMethodPointer : public CallableCustomMethodPointerBase {
struct Data {
T *instance;
uint64_t object_id;
- void (T::*method)(P...);
+ R(T::*method)
+ (P...);
} data;
public:
@@ -100,10 +103,14 @@ public:
virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const {
ERR_FAIL_NULL_MSG(ObjectDB::get_instance(ObjectID(data.object_id)), "Invalid Object id '" + uitos(data.object_id) + "', can't call method.");
- call_with_variant_args(data.instance, data.method, p_arguments, p_argcount, r_call_error);
+ if constexpr (std::is_same<R, void>::value) {
+ call_with_variant_args(data.instance, data.method, p_arguments, p_argcount, r_call_error);
+ } else {
+ call_with_variant_args_ret(data.instance, data.method, p_arguments, p_argcount, r_return_value, r_call_error);
+ }
}
- CallableCustomMethodPointer(T *p_instance, void (T::*p_method)(P...)) {
+ CallableCustomMethodPointer(T *p_instance, R (T::*p_method)(P...)) {
memset(&data, 0, sizeof(Data)); // Clear beforehand, may have padding bytes.
data.instance = p_instance;
data.object_id = p_instance->get_instance_id();
@@ -118,7 +125,7 @@ Callable create_custom_callable_function_pointer(T *p_instance,
const char *p_func_text,
#endif
void (T::*p_method)(P...)) {
- typedef CallableCustomMethodPointer<T, P...> CCMP; // Messes with memnew otherwise.
+ typedef CallableCustomMethodPointer<T, void, P...> CCMP; // Messes with memnew otherwise.
CCMP *ccmp = memnew(CCMP(p_instance, p_method));
#ifdef DEBUG_METHODS_ENABLED
ccmp->set_text(p_func_text + 1); // Try to get rid of the ampersand.
@@ -126,51 +133,13 @@ Callable create_custom_callable_function_pointer(T *p_instance,
return Callable(ccmp);
}
-// VERSION WITH RETURN
-
-template <typename T, typename R, typename... P>
-class CallableCustomMethodPointerRet : public CallableCustomMethodPointerBase {
- struct Data {
- T *instance;
- uint64_t object_id;
- R(T::*method)
- (P...);
- } data;
-
-public:
- virtual ObjectID get_object() const {
- if (ObjectDB::get_instance(ObjectID(data.object_id)) == nullptr) {
- return ObjectID();
- }
- return data.instance->get_instance_id();
- }
-
- virtual int get_argument_count(bool &r_is_valid) const {
- r_is_valid = true;
- return sizeof...(P);
- }
-
- virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const {
- ERR_FAIL_NULL_MSG(ObjectDB::get_instance(ObjectID(data.object_id)), "Invalid Object id '" + uitos(data.object_id) + "', can't call method.");
- call_with_variant_args_ret(data.instance, data.method, p_arguments, p_argcount, r_return_value, r_call_error);
- }
-
- CallableCustomMethodPointerRet(T *p_instance, R (T::*p_method)(P...)) {
- memset(&data, 0, sizeof(Data)); // Clear beforehand, may have padding bytes.
- data.instance = p_instance;
- data.object_id = p_instance->get_instance_id();
- data.method = p_method;
- _setup((uint32_t *)&data, sizeof(Data));
- }
-};
-
template <typename T, typename R, typename... P>
Callable create_custom_callable_function_pointer(T *p_instance,
#ifdef DEBUG_METHODS_ENABLED
const char *p_func_text,
#endif
R (T::*p_method)(P...)) {
- typedef CallableCustomMethodPointerRet<T, R, P...> CCMP; // Messes with memnew otherwise.
+ typedef CallableCustomMethodPointer<T, R, P...> CCMP; // Messes with memnew otherwise.
CCMP *ccmp = memnew(CCMP(p_instance, p_method));
#ifdef DEBUG_METHODS_ENABLED
ccmp->set_text(p_func_text + 1); // Try to get rid of the ampersand.
@@ -178,10 +147,10 @@ Callable create_custom_callable_function_pointer(T *p_instance,
return Callable(ccmp);
}
-// CONST VERSION WITH RETURN
+// CONST VERSION
template <typename T, typename R, typename... P>
-class CallableCustomMethodPointerRetC : public CallableCustomMethodPointerBase {
+class CallableCustomMethodPointerC : public CallableCustomMethodPointerBase {
struct Data {
T *instance;
uint64_t object_id;
@@ -204,10 +173,14 @@ public:
virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const override {
ERR_FAIL_NULL_MSG(ObjectDB::get_instance(ObjectID(data.object_id)), "Invalid Object id '" + uitos(data.object_id) + "', can't call method.");
- call_with_variant_args_retc(data.instance, data.method, p_arguments, p_argcount, r_return_value, r_call_error);
+ if constexpr (std::is_same<R, void>::value) {
+ call_with_variant_argsc(data.instance, data.method, p_arguments, p_argcount, r_call_error);
+ } else {
+ call_with_variant_args_retc(data.instance, data.method, p_arguments, p_argcount, r_return_value, r_call_error);
+ }
}
- CallableCustomMethodPointerRetC(T *p_instance, R (T::*p_method)(P...) const) {
+ CallableCustomMethodPointerC(T *p_instance, R (T::*p_method)(P...) const) {
memset(&data, 0, sizeof(Data)); // Clear beforehand, may have padding bytes.
data.instance = p_instance;
data.object_id = p_instance->get_instance_id();
@@ -216,13 +189,27 @@ public:
}
};
+template <typename T, typename... P>
+Callable create_custom_callable_function_pointer(T *p_instance,
+#ifdef DEBUG_METHODS_ENABLED
+ const char *p_func_text,
+#endif
+ void (T::*p_method)(P...) const) {
+ typedef CallableCustomMethodPointerC<T, void, P...> CCMP; // Messes with memnew otherwise.
+ CCMP *ccmp = memnew(CCMP(p_instance, p_method));
+#ifdef DEBUG_METHODS_ENABLED
+ ccmp->set_text(p_func_text + 1); // Try to get rid of the ampersand.
+#endif
+ return Callable(ccmp);
+}
+
template <typename T, typename R, typename... P>
Callable create_custom_callable_function_pointer(T *p_instance,
#ifdef DEBUG_METHODS_ENABLED
const char *p_func_text,
#endif
R (T::*p_method)(P...) const) {
- typedef CallableCustomMethodPointerRetC<T, R, P...> CCMP; // Messes with memnew otherwise.
+ typedef CallableCustomMethodPointerC<T, R, P...> CCMP; // Messes with memnew otherwise.
CCMP *ccmp = memnew(CCMP(p_instance, p_method));
#ifdef DEBUG_METHODS_ENABLED
ccmp->set_text(p_func_text + 1); // Try to get rid of the ampersand.
@@ -238,10 +225,11 @@ Callable create_custom_callable_function_pointer(T *p_instance,
// STATIC VERSIONS
-template <typename... P>
+template <typename R, typename... P>
class CallableCustomStaticMethodPointer : public CallableCustomMethodPointerBase {
struct Data {
- void (*method)(P...);
+ R(*method)
+ (P...);
} data;
public:
@@ -259,24 +247,27 @@ public:
}
virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const override {
- call_with_variant_args_static_ret(data.method, p_arguments, p_argcount, r_return_value, r_call_error);
- r_return_value = Variant();
+ if constexpr (std::is_same<R, void>::value) {
+ call_with_variant_args_static(data.method, p_arguments, p_argcount, r_call_error);
+ } else {
+ call_with_variant_args_static_ret(data.method, p_arguments, p_argcount, r_return_value, r_call_error);
+ }
}
- CallableCustomStaticMethodPointer(void (*p_method)(P...)) {
+ CallableCustomStaticMethodPointer(R (*p_method)(P...)) {
memset(&data, 0, sizeof(Data)); // Clear beforehand, may have padding bytes.
data.method = p_method;
_setup((uint32_t *)&data, sizeof(Data));
}
};
-template <typename T, typename... P>
+template <typename... P>
Callable create_custom_callable_static_function_pointer(
#ifdef DEBUG_METHODS_ENABLED
const char *p_func_text,
#endif
void (*p_method)(P...)) {
- typedef CallableCustomStaticMethodPointer<P...> CCMP; // Messes with memnew otherwise.
+ typedef CallableCustomStaticMethodPointer<void, P...> CCMP; // Messes with memnew otherwise.
CCMP *ccmp = memnew(CCMP(p_method));
#ifdef DEBUG_METHODS_ENABLED
ccmp->set_text(p_func_text + 1); // Try to get rid of the ampersand.
@@ -285,44 +276,12 @@ Callable create_custom_callable_static_function_pointer(
}
template <typename R, typename... P>
-class CallableCustomStaticMethodPointerRet : public CallableCustomMethodPointerBase {
- struct Data {
- R(*method)
- (P...);
- } data;
-
-public:
- virtual bool is_valid() const override {
- return true;
- }
-
- virtual ObjectID get_object() const override {
- return ObjectID();
- }
-
- virtual int get_argument_count(bool &r_is_valid) const override {
- r_is_valid = true;
- return sizeof...(P);
- }
-
- virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const override {
- call_with_variant_args_static_ret(data.method, p_arguments, p_argcount, r_return_value, r_call_error);
- }
-
- CallableCustomStaticMethodPointerRet(R (*p_method)(P...)) {
- memset(&data, 0, sizeof(Data)); // Clear beforehand, may have padding bytes.
- data.method = p_method;
- _setup((uint32_t *)&data, sizeof(Data));
- }
-};
-
-template <typename R, typename... P>
Callable create_custom_callable_static_function_pointer(
#ifdef DEBUG_METHODS_ENABLED
const char *p_func_text,
#endif
R (*p_method)(P...)) {
- typedef CallableCustomStaticMethodPointerRet<R, P...> CCMP; // Messes with memnew otherwise.
+ typedef CallableCustomStaticMethodPointer<R, P...> CCMP; // Messes with memnew otherwise.
CCMP *ccmp = memnew(CCMP(p_method));
#ifdef DEBUG_METHODS_ENABLED
ccmp->set_text(p_func_text + 1); // Try to get rid of the ampersand.
diff --git a/core/object/object.cpp b/core/object/object.cpp
index 2d9d468d38..b3a4ec6e2e 100644
--- a/core/object/object.cpp
+++ b/core/object/object.cpp
@@ -1457,6 +1457,24 @@ bool Object::is_connected(const StringName &p_signal, const Callable &p_callable
return s->slot_map.has(*p_callable.get_base_comparator());
}
+bool Object::has_connections(const StringName &p_signal) const {
+ const SignalData *s = signal_map.getptr(p_signal);
+ if (!s) {
+ bool signal_is_valid = ClassDB::has_signal(get_class_name(), p_signal);
+ if (signal_is_valid) {
+ return false;
+ }
+
+ if (!script.is_null() && Ref<Script>(script)->has_script_signal(p_signal)) {
+ return false;
+ }
+
+ ERR_FAIL_V_MSG(false, "Nonexistent signal: " + p_signal + ".");
+ }
+
+ return !s->slot_map.is_empty();
+}
+
void Object::disconnect(const StringName &p_signal, const Callable &p_callable) {
_disconnect(p_signal, p_callable);
}
@@ -1697,6 +1715,7 @@ void Object::_bind_methods() {
ClassDB::bind_method(D_METHOD("connect", "signal", "callable", "flags"), &Object::connect, DEFVAL(0));
ClassDB::bind_method(D_METHOD("disconnect", "signal", "callable"), &Object::disconnect);
ClassDB::bind_method(D_METHOD("is_connected", "signal", "callable"), &Object::is_connected);
+ ClassDB::bind_method(D_METHOD("has_connections", "signal"), &Object::has_connections);
ClassDB::bind_method(D_METHOD("set_block_signals", "enable"), &Object::set_block_signals);
ClassDB::bind_method(D_METHOD("is_blocking_signals"), &Object::is_blocking_signals);
diff --git a/core/object/object.h b/core/object/object.h
index 1274247d71..763e2974b9 100644
--- a/core/object/object.h
+++ b/core/object/object.h
@@ -932,6 +932,7 @@ public:
MTVIRTUAL Error connect(const StringName &p_signal, const Callable &p_callable, uint32_t p_flags = 0);
MTVIRTUAL void disconnect(const StringName &p_signal, const Callable &p_callable);
MTVIRTUAL bool is_connected(const StringName &p_signal, const Callable &p_callable) const;
+ MTVIRTUAL bool has_connections(const StringName &p_signal) const;
template <typename... VarArgs>
void call_deferred(const StringName &p_name, VarArgs... p_args) {
diff --git a/core/object/script_language.cpp b/core/object/script_language.cpp
index d2fc7392c8..c5856a8a81 100644
--- a/core/object/script_language.cpp
+++ b/core/object/script_language.cpp
@@ -191,7 +191,17 @@ void Script::reload_from_file() {
set_source_code(rel->get_source_code());
set_last_modified_time(rel->get_last_modified_time());
- reload();
+ // Only reload the script when there are no compilation errors to prevent printing the error messages twice.
+ if (rel->is_valid()) {
+ if (Engine::get_singleton()->is_editor_hint() && is_tool()) {
+ get_language()->reload_tool_script(this, true);
+ } else {
+ // It's important to set p_keep_state to true in order to manage reloading scripts
+ // that are currently instantiated.
+ reload(true);
+ }
+ }
+
#else
Resource::reload_from_file();
#endif
diff --git a/core/object/script_language.h b/core/object/script_language.h
index d0023d70e8..3ddfbb3e7d 100644
--- a/core/object/script_language.h
+++ b/core/object/script_language.h
@@ -112,7 +112,10 @@ class Script : public Resource {
OBJ_SAVE_TYPE(Script);
protected:
- virtual bool editor_can_reload_from_file() override { return false; } // this is handled by editor better
+ // Scripts are reloaded via the Script Editor when edited in Godot,
+ // the LSP server when edited in a connected external editor, or
+ // through EditorFileSystem::_update_script_documentation when updated directly on disk.
+ virtual bool editor_can_reload_from_file() override { return false; }
void _notification(int p_what);
static void _bind_methods();
diff --git a/core/object/undo_redo.cpp b/core/object/undo_redo.cpp
index 4d67cd930e..03537dbeb1 100644
--- a/core/object/undo_redo.cpp
+++ b/core/object/undo_redo.cpp
@@ -48,7 +48,7 @@ void UndoRedo::Operation::delete_reference() {
}
}
-void UndoRedo::_discard_redo() {
+void UndoRedo::discard_redo() {
if (current_action == actions.size() - 1) {
return;
}
@@ -89,7 +89,7 @@ void UndoRedo::create_action(const String &p_name, MergeMode p_mode, bool p_back
uint64_t ticks = OS::get_singleton()->get_ticks_msec();
if (action_level == 0) {
- _discard_redo();
+ discard_redo();
// Check if the merge operation is valid
if (p_mode != MERGE_DISABLE && actions.size() && actions[actions.size() - 1].name == p_name && actions[actions.size() - 1].backward_undo_ops == p_backward_undo_ops && actions[actions.size() - 1].last_tick + 800 > ticks) {
@@ -288,7 +288,7 @@ void UndoRedo::end_force_keep_in_merge_ends() {
}
void UndoRedo::_pop_history_tail() {
- _discard_redo();
+ discard_redo();
if (!actions.size()) {
return;
@@ -455,7 +455,7 @@ String UndoRedo::get_action_name(int p_id) {
void UndoRedo::clear_history(bool p_increase_version) {
ERR_FAIL_COND(action_level > 0);
- _discard_redo();
+ discard_redo();
while (actions.size()) {
_pop_history_tail();
diff --git a/core/object/undo_redo.h b/core/object/undo_redo.h
index 19d178635c..ded962670c 100644
--- a/core/object/undo_redo.h
+++ b/core/object/undo_redo.h
@@ -129,6 +129,7 @@ public:
int get_current_action();
String get_action_name(int p_id);
void clear_history(bool p_increase_version = true);
+ void discard_redo();
bool has_undo() const;
bool has_redo() const;
diff --git a/core/os/SCsub b/core/os/SCsub
index 19a6549225..ab81175894 100644
--- a/core/os/SCsub
+++ b/core/os/SCsub
@@ -1,4 +1,5 @@
#!/usr/bin/env python
+from misc.utility.scons_hints import *
Import("env")
diff --git a/core/string/SCsub b/core/string/SCsub
index 3217166f18..b06e32eb88 100644
--- a/core/string/SCsub
+++ b/core/string/SCsub
@@ -1,4 +1,5 @@
#!/usr/bin/env python
+from misc.utility.scons_hints import *
Import("env")
diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp
index 2683addd4b..391a203d5b 100644
--- a/core/string/ustring.cpp
+++ b/core/string/ustring.cpp
@@ -4626,7 +4626,7 @@ bool String::is_absolute_path() const {
String String::validate_ascii_identifier() const {
if (is_empty()) {
- return "_"; // Empty string is not a valid identifier;
+ return "_"; // Empty string is not a valid identifier.
}
String result;
@@ -4647,6 +4647,29 @@ String String::validate_ascii_identifier() const {
return result;
}
+String String::validate_unicode_identifier() const {
+ if (is_empty()) {
+ return "_"; // Empty string is not a valid identifier.
+ }
+
+ String result;
+ if (is_unicode_identifier_start(operator[](0))) {
+ result = *this;
+ } else {
+ result = "_" + *this;
+ }
+
+ int len = result.length();
+ char32_t *buffer = result.ptrw();
+ for (int i = 0; i < len; i++) {
+ if (!is_unicode_identifier_continue(buffer[i])) {
+ buffer[i] = '_';
+ }
+ }
+
+ return result;
+}
+
bool String::is_valid_ascii_identifier() const {
int len = length();
diff --git a/core/string/ustring.h b/core/string/ustring.h
index 11f15031f9..5d4b209c25 100644
--- a/core/string/ustring.h
+++ b/core/string/ustring.h
@@ -460,6 +460,7 @@ public:
static String get_invalid_node_name_characters(bool p_allow_internal = false);
String validate_node_name() const;
String validate_ascii_identifier() const;
+ String validate_unicode_identifier() const;
String validate_filename() const;
bool is_valid_ascii_identifier() const;
diff --git a/core/templates/SCsub b/core/templates/SCsub
index 8c4c843a33..7f806d5609 100644
--- a/core/templates/SCsub
+++ b/core/templates/SCsub
@@ -1,4 +1,5 @@
#!/usr/bin/env python
+from misc.utility.scons_hints import *
Import("env")
diff --git a/core/variant/SCsub b/core/variant/SCsub
index 7f4c8b7788..8264503a22 100644
--- a/core/variant/SCsub
+++ b/core/variant/SCsub
@@ -1,4 +1,5 @@
#!/usr/bin/env python
+from misc.utility.scons_hints import *
Import("env")
diff --git a/core/variant/binder_common.h b/core/variant/binder_common.h
index fa49767d46..0aa49f6d68 100644
--- a/core/variant/binder_common.h
+++ b/core/variant/binder_common.h
@@ -466,7 +466,7 @@ void call_with_variant_argsc(T *p_instance, void (T::*p_method)(P...) const, con
return;
}
#endif
- call_with_variant_args_helper<T, P...>(p_instance, p_method, p_args, r_error, BuildIndexSequence<sizeof...(P)>{});
+ call_with_variant_argsc_helper<T, P...>(p_instance, p_method, p_args, r_error, BuildIndexSequence<sizeof...(P)>{});
}
template <typename T, typename... P>
@@ -830,7 +830,7 @@ void call_with_variant_args_static_ret(R (*p_method)(P...), const Variant **p_ar
}
template <typename... P>
-void call_with_variant_args_static_ret(void (*p_method)(P...), const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) {
+void call_with_variant_args_static(void (*p_method)(P...), const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
#ifdef DEBUG_METHODS_ENABLED
if ((size_t)p_argcount > sizeof...(P)) {
r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
diff --git a/core/variant/callable.cpp b/core/variant/callable.cpp
index 9dff5c1e91..bb2d0313f6 100644
--- a/core/variant/callable.cpp
+++ b/core/variant/callable.cpp
@@ -545,6 +545,13 @@ bool Signal::is_connected(const Callable &p_callable) const {
return obj->is_connected(name, p_callable);
}
+bool Signal::has_connections() const {
+ Object *obj = get_object();
+ ERR_FAIL_NULL_V(obj, false);
+
+ return obj->has_connections(name);
+}
+
Array Signal::get_connections() const {
Object *obj = get_object();
if (!obj) {
diff --git a/core/variant/callable.h b/core/variant/callable.h
index 63757d9d6e..e3c940a0e5 100644
--- a/core/variant/callable.h
+++ b/core/variant/callable.h
@@ -192,6 +192,7 @@ public:
Error connect(const Callable &p_callable, uint32_t p_flags = 0);
void disconnect(const Callable &p_callable);
bool is_connected(const Callable &p_callable) const;
+ bool has_connections() const;
Array get_connections() const;
Signal(const Object *p_object, const StringName &p_name);
diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp
index 178c0bc4ec..63fb5e8d94 100644
--- a/core/variant/variant_call.cpp
+++ b/core/variant/variant_call.cpp
@@ -2121,6 +2121,7 @@ static void _register_variant_builtin_methods_misc() {
bind_method(Signal, disconnect, sarray("callable"), varray());
bind_method(Signal, is_connected, sarray("callable"), varray());
bind_method(Signal, get_connections, sarray(), varray());
+ bind_method(Signal, has_connections, sarray(), varray());
bind_custom(Signal, emit, _VariantCall::func_Signal_emit, false, Variant);
diff --git a/core/variant/variant_op.h b/core/variant/variant_op.h
index ac39a4135f..0bd8b830e0 100644
--- a/core/variant/variant_op.h
+++ b/core/variant/variant_op.h
@@ -923,7 +923,10 @@ public:
static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
bool valid = true;
String result = do_mod(*VariantGetInternalPtr<S>::get_ptr(left), &valid);
- ERR_FAIL_COND_MSG(!valid, result);
+ if (unlikely(!valid)) {
+ *VariantGetInternalPtr<String>::get_ptr(r_ret) = *VariantGetInternalPtr<S>::get_ptr(left);
+ ERR_FAIL_MSG(vformat("String formatting error: %s.", result));
+ }
*VariantGetInternalPtr<String>::get_ptr(r_ret) = result;
}
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
@@ -948,7 +951,10 @@ public:
static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
bool valid = true;
String result = do_mod(*VariantGetInternalPtr<S>::get_ptr(left), *VariantGetInternalPtr<Array>::get_ptr(right), &valid);
- ERR_FAIL_COND_MSG(!valid, result);
+ if (unlikely(!valid)) {
+ *VariantGetInternalPtr<String>::get_ptr(r_ret) = *VariantGetInternalPtr<S>::get_ptr(left);
+ ERR_FAIL_MSG(vformat("String formatting error: %s.", result));
+ }
*VariantGetInternalPtr<String>::get_ptr(r_ret) = result;
}
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
@@ -976,7 +982,10 @@ public:
static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
bool valid = true;
String result = do_mod(*VariantGetInternalPtr<S>::get_ptr(left), right->get_validated_object(), &valid);
- ERR_FAIL_COND_MSG(!valid, result);
+ if (unlikely(!valid)) {
+ *VariantGetInternalPtr<String>::get_ptr(r_ret) = *VariantGetInternalPtr<S>::get_ptr(left);
+ ERR_FAIL_MSG(vformat("String formatting error: %s.", result));
+ }
*VariantGetInternalPtr<String>::get_ptr(r_ret) = result;
}
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
@@ -1003,7 +1012,10 @@ public:
static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
bool valid = true;
String result = do_mod(*VariantGetInternalPtr<S>::get_ptr(left), *VariantGetInternalPtr<T>::get_ptr(right), &valid);
- ERR_FAIL_COND_MSG(!valid, result);
+ if (unlikely(!valid)) {
+ *VariantGetInternalPtr<String>::get_ptr(r_ret) = *VariantGetInternalPtr<S>::get_ptr(left);
+ ERR_FAIL_MSG(vformat("String formatting error: %s.", result));
+ }
*VariantGetInternalPtr<String>::get_ptr(r_ret) = result;
}
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
@@ -1492,7 +1504,10 @@ public:
}
static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
Object *l = right->get_validated_object();
- ERR_FAIL_NULL(l);
+ if (unlikely(!l)) {
+ *VariantGetInternalPtr<bool>::get_ptr(r_ret) = false;
+ ERR_FAIL_MSG("Invalid base object for 'in'.");
+ }
const String &a = *VariantGetInternalPtr<String>::get_ptr(left);
bool valid;
@@ -1526,7 +1541,10 @@ public:
}
static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
Object *l = right->get_validated_object();
- ERR_FAIL_NULL(l);
+ if (unlikely(!l)) {
+ *VariantGetInternalPtr<bool>::get_ptr(r_ret) = false;
+ ERR_FAIL_MSG("Invalid base object for 'in'.");
+ }
const StringName &a = *VariantGetInternalPtr<StringName>::get_ptr(left);
bool valid;