From 1abdffe7a029daf634f57132cb5ab5d82a7ccfc9 Mon Sep 17 00:00:00 2001 From: kobewi Date: Fri, 5 Aug 2022 20:35:08 +0200 Subject: Replace Array return types with TypedArray 2 --- core/object/object.cpp | 30 ++++++++++++++++++------------ core/object/object.h | 15 +++++++++------ core/object/script_language.cpp | 13 +++++++------ core/object/script_language.h | 8 +++++--- 4 files changed, 39 insertions(+), 27 deletions(-) (limited to 'core/object') diff --git a/core/object/object.cpp b/core/object/object.cpp index 5203685c7f..7dd18c38ce 100644 --- a/core/object/object.cpp +++ b/core/object/object.cpp @@ -38,6 +38,7 @@ #include "core/os/os.h" #include "core/string/print_string.h" #include "core/string/translation.h" +#include "core/variant/typed_array.h" #ifdef DEBUG_ENABLED @@ -102,8 +103,8 @@ PropertyInfo PropertyInfo::from_dict(const Dictionary &p_dict) { return pi; } -Array convert_property_list(const List *p_list) { - Array va; +TypedArray convert_property_list(const List *p_list) { + TypedArray va; for (const List::Element *E = p_list->front(); E; E = E->next()) { va.push_back(Dictionary(E->get())); } @@ -912,16 +913,16 @@ void Object::remove_meta(const StringName &p_name) { set_meta(p_name, Variant()); } -Array Object::_get_property_list_bind() const { +TypedArray Object::_get_property_list_bind() const { List lpi; get_property_list(&lpi); return convert_property_list(&lpi); } -Array Object::_get_method_list_bind() const { +TypedArray Object::_get_method_list_bind() const { List ml; get_method_list(&ml); - Array ret; + TypedArray ret; for (List::Element *E = ml.front(); E; E = E->next()) { Dictionary d = E->get(); @@ -1109,11 +1110,11 @@ void Object::_add_user_signal(const String &p_name, const Array &p_args) { add_user_signal(mi); } -Array Object::_get_signal_list() const { +TypedArray Object::_get_signal_list() const { List signal_list; get_signal_list(&signal_list); - Array ret; + TypedArray ret; for (const MethodInfo &E : signal_list) { ret.push_back(Dictionary(E)); } @@ -1121,11 +1122,11 @@ Array Object::_get_signal_list() const { return ret; } -Array Object::_get_signal_connection_list(const StringName &p_signal) const { +TypedArray Object::_get_signal_connection_list(const StringName &p_signal) const { List conns; get_all_signal_connections(&conns); - Array ret; + TypedArray ret; for (const Connection &c : conns) { if (c.signal.get_name() == p_signal) { @@ -1136,8 +1137,8 @@ Array Object::_get_signal_connection_list(const StringName &p_signal) const { return ret; } -Array Object::_get_incoming_connections() const { - Array ret; +TypedArray Object::_get_incoming_connections() const { + TypedArray ret; int connections_amount = connections.size(); for (int idx_conn = 0; idx_conn < connections_amount; idx_conn++) { ret.push_back(connections[idx_conn]); @@ -1553,7 +1554,12 @@ void Object::_bind_methods() { miget.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; BIND_OBJ_CORE_METHOD(miget); - BIND_OBJ_CORE_METHOD(MethodInfo(Variant::ARRAY, "_get_property_list")); + MethodInfo plget("_get_property_list"); + plget.return_val.type = Variant::ARRAY; + plget.return_val.hint = PROPERTY_HINT_ARRAY_TYPE; + plget.return_val.hint_string = "Dictionary"; + BIND_OBJ_CORE_METHOD(plget); + BIND_OBJ_CORE_METHOD(MethodInfo(Variant::BOOL, "_property_can_revert", PropertyInfo(Variant::STRING_NAME, "property"))); MethodInfo mipgr("_property_get_revert", PropertyInfo(Variant::STRING_NAME, "property")); mipgr.return_val.name = "Variant"; diff --git a/core/object/object.h b/core/object/object.h index 093b104664..47681c0223 100644 --- a/core/object/object.h +++ b/core/object/object.h @@ -45,6 +45,9 @@ #include "core/variant/callable_bind.h" #include "core/variant/variant.h" +template +class TypedArray; + enum PropertyHint { PROPERTY_HINT_NONE, ///< no hint provided. PROPERTY_HINT_RANGE, ///< hint_text = "min,max[,step][,or_greater][,or_lesser][,no_slider][,radians][,degrees][,exp][,suffix:] range. @@ -207,7 +210,7 @@ struct PropertyInfo { } }; -Array convert_property_list(const List *p_list); +TypedArray convert_property_list(const List *p_list); enum MethodFlags { METHOD_FLAG_NORMAL = 1, @@ -597,9 +600,9 @@ private: void _add_user_signal(const String &p_name, const Array &p_args = Array()); bool _has_user_signal(const StringName &p_name) const; Error _emit_signal(const Variant **p_args, int p_argcount, Callable::CallError &r_error); - Array _get_signal_list() const; - Array _get_signal_connection_list(const StringName &p_signal) const; - Array _get_incoming_connections() const; + TypedArray _get_signal_list() const; + TypedArray _get_signal_connection_list(const StringName &p_signal) const; + TypedArray _get_incoming_connections() const; void _set_bind(const StringName &p_set, const Variant &p_value); Variant _get_bind(const StringName &p_name) const; void _set_indexed_bind(const NodePath &p_name, const Variant &p_value); @@ -698,8 +701,8 @@ protected: } Vector _get_meta_list_bind() const; - Array _get_property_list_bind() const; - Array _get_method_list_bind() const; + TypedArray _get_property_list_bind() const; + TypedArray _get_method_list_bind() const; void _clear_internal_resource_paths(const Variant &p_var); diff --git a/core/object/script_language.cpp b/core/object/script_language.cpp index b06c2e8896..e56d2e80b9 100644 --- a/core/object/script_language.cpp +++ b/core/object/script_language.cpp @@ -34,6 +34,7 @@ #include "core/core_string_names.h" #include "core/debugger/engine_debugger.h" #include "core/debugger/script_debugger.h" +#include "core/variant/typed_array.h" #include @@ -61,8 +62,8 @@ Variant Script::_get_property_default_value(const StringName &p_property) { return ret; } -Array Script::_get_script_property_list() { - Array ret; +TypedArray Script::_get_script_property_list() { + TypedArray ret; List list; get_script_property_list(&list); for (const PropertyInfo &E : list) { @@ -71,8 +72,8 @@ Array Script::_get_script_property_list() { return ret; } -Array Script::_get_script_method_list() { - Array ret; +TypedArray Script::_get_script_method_list() { + TypedArray ret; List list; get_script_method_list(&list); for (const MethodInfo &E : list) { @@ -81,8 +82,8 @@ Array Script::_get_script_method_list() { return ret; } -Array Script::_get_script_signal_list() { - Array ret; +TypedArray Script::_get_script_signal_list() { + TypedArray ret; List list; get_script_signal_list(&list); for (const MethodInfo &E : list) { diff --git a/core/object/script_language.h b/core/object/script_language.h index bfdedbe4a5..12a21150bc 100644 --- a/core/object/script_language.h +++ b/core/object/script_language.h @@ -37,6 +37,8 @@ #include "core/templates/rb_map.h" class ScriptLanguage; +template +class TypedArray; typedef void (*ScriptEditRequestFunction)(const String &p_path); @@ -108,9 +110,9 @@ protected: virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder) {} Variant _get_property_default_value(const StringName &p_property); - Array _get_script_property_list(); - Array _get_script_method_list(); - Array _get_script_signal_list(); + TypedArray _get_script_property_list(); + TypedArray _get_script_method_list(); + TypedArray _get_script_signal_list(); Dictionary _get_script_constant_map(); public: -- cgit v1.2.3