summaryrefslogtreecommitdiff
path: root/core/object
diff options
context:
space:
mode:
Diffstat (limited to 'core/object')
-rw-r--r--core/object/callable_method_pointer.h82
-rw-r--r--core/object/class_db.cpp2
-rw-r--r--core/object/class_db.h5
-rw-r--r--core/object/object.h6
-rw-r--r--core/object/script_language.cpp2
-rw-r--r--core/object/script_language.h4
-rw-r--r--core/object/script_language_extension.h4
7 files changed, 94 insertions, 11 deletions
diff --git a/core/object/callable_method_pointer.h b/core/object/callable_method_pointer.h
index 577d4b9fbd..f2a440b49a 100644
--- a/core/object/callable_method_pointer.h
+++ b/core/object/callable_method_pointer.h
@@ -245,4 +245,86 @@ Callable create_custom_callable_function_pointer(T *p_instance,
#define callable_mp(I, M) create_custom_callable_function_pointer(I, M)
#endif
+// STATIC VERSIONS
+
+template <class... P>
+class CallableCustomStaticMethodPointer : public CallableCustomMethodPointerBase {
+ struct Data {
+ void (*method)(P...);
+ } data;
+
+public:
+ virtual ObjectID get_object() const {
+ return ObjectID();
+ }
+
+ virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const {
+ call_with_variant_args_static_ret(data.method, p_arguments, p_argcount, r_return_value, r_call_error);
+ r_return_value = Variant();
+ }
+
+ CallableCustomStaticMethodPointer(void (*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 <class T, class... 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.
+ CCMP *ccmp = memnew(CCMP(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 <class R, class... P>
+class CallableCustomStaticMethodPointerRet : public CallableCustomMethodPointerBase {
+ struct Data {
+ R(*method)
+ (P...);
+ } data;
+
+public:
+ virtual ObjectID get_object() const {
+ return ObjectID();
+ }
+
+ virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const {
+ 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 <class R, class... 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.
+ CCMP *ccmp = memnew(CCMP(p_method));
+#ifdef DEBUG_METHODS_ENABLED
+ ccmp->set_text(p_func_text + 1); // Try to get rid of the ampersand.
+#endif
+ return Callable(ccmp);
+}
+
+#ifdef DEBUG_METHODS_ENABLED
+#define callable_mp_static(M) create_custom_callable_static_function_pointer(#M, M)
+#else
+#define callable_mp_static(M) create_custom_callable_static_function_pointer(M)
+#endif
+
#endif // CALLABLE_METHOD_POINTER_H
diff --git a/core/object/class_db.cpp b/core/object/class_db.cpp
index d19cbf2642..f61bd24efd 100644
--- a/core/object/class_db.cpp
+++ b/core/object/class_db.cpp
@@ -1390,7 +1390,7 @@ void ClassDB::get_extensions_for_type(const StringName &p_class, List<String> *p
}
HashMap<StringName, HashMap<StringName, Variant>> ClassDB::default_values;
-RBSet<StringName> ClassDB::default_values_cached;
+HashSet<StringName> ClassDB::default_values_cached;
Variant ClassDB::class_get_default_property_value(const StringName &p_class, const StringName &p_property, bool *r_valid) {
if (!default_values_cached.has(p_class)) {
diff --git a/core/object/class_db.h b/core/object/class_db.h
index 67b71ab058..2448a86e33 100644
--- a/core/object/class_db.h
+++ b/core/object/class_db.h
@@ -38,6 +38,7 @@
// Makes callable_mp readily available in all classes connecting signals.
// Needs to come after method_bind and object have been included.
#include "core/object/callable_method_pointer.h"
+#include "core/templates/hash_set.h"
#define DEFVAL(m_defval) (m_defval)
@@ -110,7 +111,7 @@ public:
#ifdef DEBUG_METHODS_ENABLED
List<StringName> constant_order;
List<StringName> method_order;
- RBSet<StringName> methods_in_properties;
+ HashSet<StringName> methods_in_properties;
List<MethodInfo> virtual_methods;
HashMap<StringName, MethodInfo> virtual_methods_map;
HashMap<StringName, Vector<Error>> method_error_values;
@@ -149,7 +150,7 @@ public:
static void _add_class2(const StringName &p_class, const StringName &p_inherits);
static HashMap<StringName, HashMap<StringName, Variant>> default_values;
- static RBSet<StringName> default_values_cached;
+ static HashSet<StringName> default_values_cached;
// Native structs, used by binder
struct NativeStruct {
diff --git a/core/object/object.h b/core/object/object.h
index ca7b9965f1..988d261d77 100644
--- a/core/object/object.h
+++ b/core/object/object.h
@@ -37,9 +37,9 @@
#include "core/os/rw_lock.h"
#include "core/os/spin_lock.h"
#include "core/templates/hash_map.h"
+#include "core/templates/hash_set.h"
#include "core/templates/list.h"
#include "core/templates/rb_map.h"
-#include "core/templates/rb_set.h"
#include "core/templates/safe_refcount.h"
#include "core/templates/vmap.h"
#include "core/variant/callable_bind.h"
@@ -510,7 +510,7 @@ private:
#ifdef TOOLS_ENABLED
bool _edited = false;
uint32_t _edited_version = 0;
- RBSet<String> editor_section_folding;
+ HashSet<String> editor_section_folding;
#endif
ScriptInstance *script_instance = nullptr;
Variant script; // Reference does not exist yet, store it in a Variant.
@@ -815,7 +815,7 @@ public:
#ifdef TOOLS_ENABLED
void editor_set_section_unfold(const String &p_section, bool p_unfolded);
bool editor_is_section_unfolded(const String &p_section);
- const RBSet<String> &editor_get_section_folding() const { return editor_section_folding; }
+ const HashSet<String> &editor_get_section_folding() const { return editor_section_folding; }
void editor_clear_section_folding() { editor_section_folding.clear(); }
#endif
diff --git a/core/object/script_language.cpp b/core/object/script_language.cpp
index 1546d52fd2..66c9a80193 100644
--- a/core/object/script_language.cpp
+++ b/core/object/script_language.cpp
@@ -475,7 +475,7 @@ bool PlaceHolderScriptInstance::has_method(const StringName &p_method) const {
}
void PlaceHolderScriptInstance::update(const List<PropertyInfo> &p_properties, const HashMap<StringName, Variant> &p_values) {
- RBSet<StringName> new_values;
+ HashSet<StringName> new_values;
for (const PropertyInfo &E : p_properties) {
StringName n = E.name;
new_values.insert(n);
diff --git a/core/object/script_language.h b/core/object/script_language.h
index b1481a372e..0a8e79a24e 100644
--- a/core/object/script_language.h
+++ b/core/object/script_language.h
@@ -155,7 +155,7 @@ public:
virtual int get_member_line(const StringName &p_member) const { return -1; }
virtual void get_constants(HashMap<StringName, Variant> *p_constants) {}
- virtual void get_members(RBSet<StringName> *p_constants) {}
+ virtual void get_members(HashSet<StringName> *p_constants) {}
virtual bool is_placeholder_fallback_enabled() const { return false; }
@@ -283,7 +283,7 @@ public:
virtual Ref<Script> make_template(const String &p_template, const String &p_class_name, const String &p_base_class_name) const { return Ref<Script>(); }
virtual Vector<ScriptTemplate> get_built_in_templates(StringName p_object) { return Vector<ScriptTemplate>(); }
virtual bool is_using_templates() { return false; }
- virtual bool validate(const String &p_script, const String &p_path = "", List<String> *r_functions = nullptr, List<ScriptError> *r_errors = nullptr, List<Warning> *r_warnings = nullptr, RBSet<int> *r_safe_lines = nullptr) const = 0;
+ virtual bool validate(const String &p_script, const String &p_path = "", List<String> *r_functions = nullptr, List<ScriptError> *r_errors = nullptr, List<Warning> *r_warnings = nullptr, HashSet<int> *r_safe_lines = nullptr) const = 0;
virtual String validate_path(const String &p_path) const { return ""; }
virtual Script *create_script() const = 0;
virtual bool has_named_classes() const = 0;
diff --git a/core/object/script_language_extension.h b/core/object/script_language_extension.h
index 5ffa6c5a70..406a431a11 100644
--- a/core/object/script_language_extension.h
+++ b/core/object/script_language_extension.h
@@ -163,7 +163,7 @@ public:
}
}
GDVIRTUAL0RC(TypedArray<StringName>, _get_members)
- virtual void get_members(RBSet<StringName> *p_members) override {
+ virtual void get_members(HashSet<StringName> *p_members) override {
TypedArray<StringName> members;
GDVIRTUAL_REQUIRED_CALL(_get_members, members);
for (int i = 0; i < members.size(); i++) {
@@ -282,7 +282,7 @@ public:
EXBIND0R(bool, is_using_templates)
GDVIRTUAL6RC(Dictionary, _validate, const String &, const String &, bool, bool, bool, bool)
- virtual bool validate(const String &p_script, const String &p_path = "", List<String> *r_functions = nullptr, List<ScriptError> *r_errors = nullptr, List<Warning> *r_warnings = nullptr, RBSet<int> *r_safe_lines = nullptr) const override {
+ virtual bool validate(const String &p_script, const String &p_path = "", List<String> *r_functions = nullptr, List<ScriptError> *r_errors = nullptr, List<Warning> *r_warnings = nullptr, HashSet<int> *r_safe_lines = nullptr) const override {
Dictionary ret;
GDVIRTUAL_REQUIRED_CALL(_validate, p_script, p_path, r_functions != nullptr, r_errors != nullptr, r_warnings != nullptr, r_safe_lines != nullptr, ret);
if (!ret.has("valid")) {