summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorEmmanuel Leblond <emmanuel.leblond@gmail.com>2022-11-10 15:57:56 +0100
committerEmmanuel Leblond <emmanuel.leblond@gmail.com>2022-11-12 04:18:21 +0100
commit39c039a363497d60c63cf58a7b83723b11df2894 (patch)
tree59072d1a3ac5dedbbf51a6339c78d9b7f4004fe0 /core
parentdca5cb8e40fd2a348a59ea73c597eb742c14c980 (diff)
Revert removal of GDNativeExtensionScriptInstanceInfo::get_property_type_func in GDExtension
This function pointer is needed to stay close to internal Godot's ScriptInstance class. Besides, by removing this function pointer, we had to do property list create/free each time we want to access type which is quadratic complexity :/
Diffstat (limited to 'core')
-rw-r--r--core/extension/gdnative_interface.h2
-rw-r--r--core/object/script_language_extension.h20
2 files changed, 9 insertions, 13 deletions
diff --git a/core/extension/gdnative_interface.h b/core/extension/gdnative_interface.h
index 68eed5a161..a361e40096 100644
--- a/core/extension/gdnative_interface.h
+++ b/core/extension/gdnative_interface.h
@@ -309,6 +309,7 @@ typedef GDNativeBool (*GDNativeExtensionScriptInstanceSet)(GDNativeExtensionScri
typedef GDNativeBool (*GDNativeExtensionScriptInstanceGet)(GDNativeExtensionScriptInstanceDataPtr p_instance, const GDNativeStringNamePtr p_name, GDNativeVariantPtr r_ret);
typedef const GDNativePropertyInfo *(*GDNativeExtensionScriptInstanceGetPropertyList)(GDNativeExtensionScriptInstanceDataPtr p_instance, uint32_t *r_count);
typedef void (*GDNativeExtensionScriptInstanceFreePropertyList)(GDNativeExtensionScriptInstanceDataPtr p_instance, const GDNativePropertyInfo *p_list);
+typedef GDNativeVariantType (*GDNativeExtensionScriptInstanceGetPropertyType)(GDNativeExtensionScriptInstanceDataPtr p_instance, const GDNativeStringNamePtr p_name, GDNativeBool *r_is_valid);
typedef GDNativeBool (*GDNativeExtensionScriptInstancePropertyCanRevert)(GDNativeExtensionScriptInstanceDataPtr p_instance, const GDNativeStringNamePtr p_name);
typedef GDNativeBool (*GDNativeExtensionScriptInstancePropertyGetRevert)(GDNativeExtensionScriptInstanceDataPtr p_instance, const GDNativeStringNamePtr p_name, GDNativeVariantPtr r_ret);
@@ -354,6 +355,7 @@ typedef struct {
GDNativeExtensionScriptInstanceGetMethodList get_method_list_func;
GDNativeExtensionScriptInstanceFreeMethodList free_method_list_func;
+ GDNativeExtensionScriptInstanceGetPropertyType get_property_type_func;
GDNativeExtensionScriptInstanceHasMethod has_method_func;
diff --git a/core/object/script_language_extension.h b/core/object/script_language_extension.h
index c287a6f71a..9a2a176096 100644
--- a/core/object/script_language_extension.h
+++ b/core/object/script_language_extension.h
@@ -681,21 +681,15 @@ public:
}
}
virtual Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid = nullptr) const override {
- Variant::Type type = Variant::Type::NIL;
- if (native_info->get_property_list_func) {
- uint32_t pcount;
- const GDNativePropertyInfo *pinfo = native_info->get_property_list_func(instance, &pcount);
- for (uint32_t i = 0; i < pcount; i++) {
- if (p_name == *reinterpret_cast<StringName *>(pinfo->name)) {
- type = Variant::Type(pinfo->type);
- break;
- }
- }
- if (native_info->free_property_list_func) {
- native_info->free_property_list_func(instance, pinfo);
+ if (native_info->get_property_type_func) {
+ GDNativeBool is_valid = 0;
+ GDNativeVariantType type = native_info->get_property_type_func(instance, (const GDNativeStringNamePtr)&p_name, &is_valid);
+ if (r_is_valid) {
+ *r_is_valid = is_valid != 0;
}
+ return Variant::Type(type);
}
- return type;
+ return Variant::NIL;
}
virtual bool property_can_revert(const StringName &p_name) const override {