diff options
Diffstat (limited to 'core/object/object.cpp')
-rw-r--r-- | core/object/object.cpp | 134 |
1 files changed, 66 insertions, 68 deletions
diff --git a/core/object/object.cpp b/core/object/object.cpp index a8a49bd22e..7db62fdc5c 100644 --- a/core/object/object.cpp +++ b/core/object/object.cpp @@ -416,12 +416,22 @@ void Object::set(const StringName &p_name, const Variant &p_value, bool *r_valid } return; - } else if (p_name == CoreStringNames::get_singleton()->_meta) { - metadata = p_value.duplicate(); - if (r_valid) { - *r_valid = true; + } else { + OrderedHashMap<StringName, Variant>::Element *E = metadata_properties.getptr(p_name); + if (E) { + E->get() = p_value; + if (r_valid) { + *r_valid = true; + } + return; + } else if (p_name.operator String().begins_with("metadata/")) { + // Must exist, otherwise duplicate() will not work. + set_meta(p_name.operator String().replace_first("metadata/", ""), p_value); + if (r_valid) { + *r_valid = true; + } + return; } - return; } // Something inside the object... :| @@ -496,9 +506,12 @@ Variant Object::get(const StringName &p_name, bool *r_valid) const { *r_valid = true; } return ret; + } + + const OrderedHashMap<StringName, Variant>::Element *E = metadata_properties.getptr(p_name); - } else if (p_name == CoreStringNames::get_singleton()->_meta) { - ret = metadata; + if (E) { + ret = E->get(); if (r_valid) { *r_valid = true; } @@ -624,8 +637,12 @@ void Object::get_property_list(List<PropertyInfo> *p_list, bool p_reversed) cons } if (_extension) { - p_list->push_back(PropertyInfo(Variant::NIL, _extension->class_name, PROPERTY_HINT_NONE, String(), PROPERTY_USAGE_CATEGORY)); - ClassDB::get_property_list(_extension->class_name, p_list, true, this); + const ObjectNativeExtension *current_extension = _extension; + while (current_extension) { + p_list->push_back(PropertyInfo(Variant::NIL, current_extension->class_name, PROPERTY_HINT_NONE, String(), PROPERTY_USAGE_CATEGORY)); + ClassDB::get_property_list(current_extension->class_name, p_list, true, this); + current_extension = current_extension->parent; + } } if (_extension && _extension->get_property_list) { @@ -644,13 +661,20 @@ void Object::get_property_list(List<PropertyInfo> *p_list, bool p_reversed) cons if (!is_class("Script")) { // can still be set, but this is for user-friendliness p_list->push_back(PropertyInfo(Variant::OBJECT, "script", PROPERTY_HINT_RESOURCE_TYPE, "Script", PROPERTY_USAGE_DEFAULT)); } - if (!metadata.is_empty()) { - p_list->push_back(PropertyInfo(Variant::DICTIONARY, "__meta__", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL)); - } + if (script_instance && !p_reversed) { p_list->push_back(PropertyInfo(Variant::NIL, "Script Variables", PROPERTY_HINT_NONE, String(), PROPERTY_USAGE_CATEGORY)); script_instance->get_property_list(p_list); } + + for (OrderedHashMap<StringName, Variant>::ConstElement K = metadata.front(); K; K = K.next()) { + PropertyInfo pi = PropertyInfo(K.value().get_type(), "metadata/" + K.key().operator String()); + if (K.value().get_type() == Variant::OBJECT) { + pi.hint = PROPERTY_HINT_RESOURCE_TYPE; + pi.hint_string = "Resource"; + } + p_list->push_back(pi); + } } void Object::_validate_property(PropertyInfo &property) const { @@ -679,7 +703,7 @@ Variant Object::_call_bind(const Variant **p_args, int p_argcount, Callable::Cal StringName method = *p_args[0]; - return call(method, &p_args[1], p_argcount - 1, r_error); + return callp(method, &p_args[1], p_argcount - 1, r_error); } Variant Object::_call_deferred_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { @@ -700,7 +724,7 @@ Variant Object::_call_deferred_bind(const Variant **p_args, int p_argcount, Call StringName method = *p_args[0]; - MessageQueue::get_singleton()->push_call(get_instance_id(), method, &p_args[1], p_argcount - 1, true); + MessageQueue::get_singleton()->push_callp(get_instance_id(), method, &p_args[1], p_argcount - 1, true); return Variant(); } @@ -750,31 +774,14 @@ Variant Object::callv(const StringName &p_method, const Array &p_args) { } Callable::CallError ce; - Variant ret = call(p_method, argptrs, p_args.size(), ce); + Variant ret = callp(p_method, argptrs, p_args.size(), ce); if (ce.error != Callable::CallError::CALL_OK) { ERR_FAIL_V_MSG(Variant(), "Error calling method from 'callv': " + Variant::get_call_error_text(this, p_method, argptrs, p_args.size(), ce) + "."); } return ret; } -Variant Object::call(const StringName &p_name, VARIANT_ARG_DECLARE) { - VARIANT_ARGPTRS; - - int argc = 0; - for (int i = 0; i < VARIANT_ARG_MAX; i++) { - if (argptr[i]->get_type() == Variant::NIL) { - break; - } - argc++; - } - - Callable::CallError error; - - Variant ret = call(p_name, argptr, argc, error); - return ret; -} - -Variant Object::call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { +Variant Object::callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { r_error.error = Callable::CallError::CALL_OK; if (p_method == CoreStringNames::get_singleton()->_free) { @@ -808,7 +815,7 @@ Variant Object::call(const StringName &p_method, const Variant **p_args, int p_a OBJ_DEBUG_LOCK if (script_instance) { - ret = script_instance->call(p_method, p_args, p_argcount, r_error); + ret = script_instance->callp(p_method, p_args, p_argcount, r_error); //force jumptable switch (r_error.error) { case Callable::CallError::CALL_OK: @@ -858,7 +865,9 @@ String Object::to_string() { } } if (_extension && _extension->to_string) { - return _extension->to_string(_extension_instance); + String ret; + _extension->to_string(_extension_instance, &ret); + return ret; } return "[" + get_class() + ":" + itos(get_instance_id()) + "]"; } @@ -928,11 +937,23 @@ bool Object::has_meta(const StringName &p_name) const { void Object::set_meta(const StringName &p_name, const Variant &p_value) { if (p_value.get_type() == Variant::NIL) { - metadata.erase(p_name); + if (metadata.has(p_name)) { + metadata.erase(p_name); + metadata_properties.erase("metadata/" + p_name.operator String()); + notify_property_list_changed(); + } return; } - metadata[p_name] = p_value; + OrderedHashMap<StringName, Variant>::Element E = metadata.find(p_name); + if (E) { + E.value() = p_value; + } else { + ERR_FAIL_COND(!p_name.operator String().is_valid_identifier()); + E = metadata.insert(p_name, p_value); + metadata_properties["metadata/" + p_name.operator String()] = E; + notify_property_list_changed(); + } } Variant Object::get_meta(const StringName &p_name) const { @@ -941,7 +962,7 @@ Variant Object::get_meta(const StringName &p_name) const { } void Object::remove_meta(const StringName &p_name) { - metadata.erase(p_name); + set_meta(p_name, Variant()); } Array Object::_get_property_list_bind() const { @@ -967,20 +988,16 @@ Array Object::_get_method_list_bind() const { Vector<StringName> Object::_get_meta_list_bind() const { Vector<StringName> _metaret; - List<Variant> keys; - metadata.get_key_list(&keys); - for (const Variant &E : keys) { - _metaret.push_back(E); + for (OrderedHashMap<StringName, Variant>::ConstElement K = metadata.front(); K; K = K.next()) { + _metaret.push_back(K.key()); } return _metaret; } void Object::get_meta_list(List<StringName> *p_list) const { - List<Variant> keys; - metadata.get_key_list(&keys); - for (const Variant &E : keys) { - p_list->push_back(E); + for (OrderedHashMap<StringName, Variant>::ConstElement K = metadata.front(); K; K = K.next()) { + p_list->push_back(K.key()); } } @@ -1027,12 +1044,12 @@ Variant Object::_emit_signal(const Variant **p_args, int p_argcount, Callable::C args = &p_args[1]; } - emit_signal(signal, args, argc); + emit_signalp(signal, args, argc); return Variant(); } -Error Object::emit_signal(const StringName &p_name, const Variant **p_args, int p_argcount) { +Error Object::emit_signalp(const StringName &p_name, const Variant **p_args, int p_argcount) { if (_block_signals) { return ERR_CANT_ACQUIRE_RESOURCE; //no emit, signals blocked } @@ -1091,7 +1108,7 @@ Error Object::emit_signal(const StringName &p_name, const Variant **p_args, int } if (c.flags & CONNECT_DEFERRED) { - MessageQueue::get_singleton()->push_callable(c.callable, args, argc, true); + MessageQueue::get_singleton()->push_callablep(c.callable, args, argc, true); } else { Callable::CallError ce; _emitting = true; @@ -1139,21 +1156,6 @@ Error Object::emit_signal(const StringName &p_name, const Variant **p_args, int return err; } -Error Object::emit_signal(const StringName &p_name, VARIANT_ARG_DECLARE) { - VARIANT_ARGPTRS; - - int argc = 0; - - for (int i = 0; i < VARIANT_ARG_MAX; i++) { - if (argptr[i]->get_type() == Variant::NIL) { - break; - } - argc++; - } - - return emit_signal(p_name, argptr, argc); -} - void Object::_add_user_signal(const String &p_name, const Array &p_args) { // this version of add_user_signal is meant to be used from scripts or external apis // without access to ADD_SIGNAL in bind_methods @@ -1648,10 +1650,6 @@ void Object::_bind_methods() { BIND_ENUM_CONSTANT(CONNECT_REFERENCE_COUNTED); } -void Object::call_deferred(const StringName &p_method, VARIANT_ARG_DECLARE) { - MessageQueue::get_singleton()->push_call(this, p_method, VARIANT_ARG_PASS); -} - void Object::set_deferred(const StringName &p_property, const Variant &p_value) { MessageQueue::get_singleton()->push_set(this, p_property, p_value); } |