Skip to content

Commit

Permalink
Merge pull request #61867 from Bromeon/refactor/property-info
Browse files Browse the repository at this point in the history
  • Loading branch information
akien-mga authored Jun 30, 2022
2 parents c5ad34d + 60ffadd commit daa055d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 27 deletions.
28 changes: 5 additions & 23 deletions core/extension/native_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,7 @@ class NativeExtensionMethodBind : public MethodBind {
virtual PropertyInfo _gen_argument_type_info(int p_arg) const override {
GDNativePropertyInfo pinfo;
get_argument_info_func(method_userdata, p_arg, &pinfo);
PropertyInfo ret;
ret.type = Variant::Type(pinfo.type);
ret.name = pinfo.name;
ret.class_name = pinfo.class_name;
ret.hint = PropertyHint(pinfo.hint);
ret.usage = pinfo.usage;
ret.class_name = pinfo.class_name;
return ret;
return PropertyInfo(pinfo);
}

public:
Expand Down Expand Up @@ -204,16 +197,11 @@ void NativeExtension::_register_extension_class_property(const GDNativeExtension
NativeExtension *self = static_cast<NativeExtension *>(p_library);

StringName class_name = p_class_name;
ERR_FAIL_COND_MSG(!self->extension_classes.has(class_name), "Attempt to register extension class property '" + String(p_info->name) + "' for unexisting class '" + class_name + "'.");
String property_name = p_info->name;
ERR_FAIL_COND_MSG(!self->extension_classes.has(class_name), "Attempt to register extension class property '" + property_name + "' for unexisting class '" + class_name + "'.");

//Extension *extension = &self->extension_classes[class_name];
PropertyInfo pinfo;
pinfo.type = Variant::Type(p_info->type);
pinfo.name = p_info->name;
pinfo.class_name = p_info->class_name;
pinfo.hint = PropertyHint(p_info->hint);
pinfo.hint_string = p_info->hint_string;
pinfo.usage = p_info->usage;
PropertyInfo pinfo(*p_info);

ClassDB::add_property(class_name, pinfo, p_setter, p_getter);
}
Expand Down Expand Up @@ -245,13 +233,7 @@ void NativeExtension::_register_extension_class_signal(const GDNativeExtensionCl
MethodInfo s;
s.name = p_signal_name;
for (int i = 0; i < p_argument_count; i++) {
PropertyInfo arg;
arg.type = Variant::Type(p_argument_info[i].type);
arg.name = p_argument_info[i].name;
arg.class_name = p_argument_info[i].class_name;
arg.hint = PropertyHint(p_argument_info[i].hint);
arg.hint_string = p_argument_info[i].hint_string;
arg.usage = p_argument_info[i].usage;
PropertyInfo arg(p_argument_info[i]);
s.arguments.push_back(arg);
}
ClassDB::add_signal(class_name, s);
Expand Down
2 changes: 1 addition & 1 deletion core/object/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ void Object::get_property_list(List<PropertyInfo> *p_list, bool p_reversed) cons
uint32_t pcount;
const GDNativePropertyInfo *pinfo = _extension->get_property_list(_extension_instance, &pcount);
for (uint32_t i = 0; i < pcount; i++) {
p_list->push_back(PropertyInfo(Variant::Type(pinfo[i].type), pinfo[i].class_name, PropertyHint(pinfo[i].hint), pinfo[i].hint_string, pinfo[i].usage, pinfo[i].class_name));
p_list->push_back(PropertyInfo(pinfo[i]));
}
if (_extension->free_property_list) {
_extension->free_property_list(_extension_instance, pinfo);
Expand Down
8 changes: 8 additions & 0 deletions core/object/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,14 @@ struct PropertyInfo {
type(Variant::OBJECT),
class_name(p_class_name) {}

explicit PropertyInfo(const GDNativePropertyInfo &pinfo) :
type((Variant::Type)pinfo.type),
name(pinfo.name),
class_name(pinfo.class_name), // can be null
hint((PropertyHint)pinfo.hint),
hint_string(pinfo.hint_string), // can be null
usage(pinfo.usage) {}

bool operator==(const PropertyInfo &p_info) const {
return ((type == p_info.type) &&
(name == p_info.name) &&
Expand Down
6 changes: 3 additions & 3 deletions core/object/script_language_extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ class ScriptInstanceExtension : public ScriptInstance {
uint32_t pcount;
const GDNativePropertyInfo *pinfo = native_info->get_property_list_func(instance, &pcount);
for (uint32_t i = 0; i < pcount; i++) {
p_list->push_back(PropertyInfo(Variant::Type(pinfo[i].type), pinfo[i].class_name, PropertyHint(pinfo[i].hint), pinfo[i].hint_string, pinfo[i].usage, pinfo[i].class_name));
p_list->push_back(PropertyInfo(pinfo[i]));
}
if (native_info->free_property_list_func) {
native_info->free_property_list_func(instance, pinfo);
Expand Down Expand Up @@ -716,9 +716,9 @@ class ScriptInstanceExtension : public ScriptInstance {
m.name = minfo[i].name;
m.flags = minfo[i].flags;
m.id = minfo[i].id;
m.return_val = PropertyInfo(Variant::Type(minfo[i].return_value.type), minfo[i].return_value.class_name, PropertyHint(minfo[i].return_value.hint), minfo[i].return_value.hint_string, minfo[i].return_value.usage, minfo[i].return_value.class_name);
m.return_val = PropertyInfo(minfo[i].return_value);
for (uint32_t j = 0; j < minfo[i].argument_count; j++) {
m.arguments.push_back(PropertyInfo(Variant::Type(minfo[i].arguments[j].type), minfo[i].arguments[j].class_name, PropertyHint(minfo[i].arguments[j].hint), minfo[i].arguments[j].hint_string, minfo[i].arguments[j].usage, minfo[i].arguments[j].class_name));
m.arguments.push_back(PropertyInfo(minfo[i].arguments[j]));
}
const Variant *def_values = (const Variant *)minfo[i].default_arguments;
for (uint32_t j = 0; j < minfo[i].default_argument_count; j++) {
Expand Down

0 comments on commit daa055d

Please sign in to comment.