Update typed array API to match "GDScript: Fix typed arrays".

pull/1026/head
bruvzg 2023-01-31 11:27:47 +02:00
parent 014eda2535
commit 37f6e35974
No known key found for this signature in database
GPG Key ID: 7960FCF39844EC38
5 changed files with 221 additions and 228 deletions

View File

@ -696,6 +696,7 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl
result.append("\tconst Variant &operator[](int p_index) const;") result.append("\tconst Variant &operator[](int p_index) const;")
result.append("\tVariant &operator[](int p_index);") result.append("\tVariant &operator[](int p_index);")
result.append("\tvoid set_typed(uint32_t p_type, const StringName &p_class_name, const Variant &p_script);") result.append("\tvoid set_typed(uint32_t p_type, const StringName &p_class_name, const Variant &p_script);")
result.append("\tvoid _ref(const Array &p_from) const;")
if class_name == "Dictionary": if class_name == "Dictionary":
result.append("\tconst Variant &operator[](const Variant &p_key) const;") result.append("\tconst Variant &operator[](const Variant &p_key) const;")

View File

@ -18912,6 +18912,19 @@
"is_static": false, "is_static": false,
"hash": 3173160232 "hash": 3173160232
}, },
{
"name": "assign",
"is_vararg": false,
"is_const": false,
"is_static": false,
"hash": 2307260970,
"arguments": [
{
"name": "array",
"type": "Array"
}
]
},
{ {
"name": "push_back", "name": "push_back",
"is_vararg": false, "is_vararg": false,
@ -19366,20 +19379,6 @@
"is_static": false, "is_static": false,
"hash": 1460142086 "hash": 1460142086
}, },
{
"name": "typed_assign",
"return_type": "bool",
"is_vararg": false,
"is_const": false,
"is_static": false,
"hash": 1485459766,
"arguments": [
{
"name": "array",
"type": "Array"
}
]
},
{ {
"name": "is_typed", "name": "is_typed",
"return_type": "bool", "return_type": "bool",
@ -19388,6 +19387,20 @@
"is_static": false, "is_static": false,
"hash": 3918633141 "hash": 3918633141
}, },
{
"name": "is_same_typed",
"return_type": "bool",
"is_vararg": false,
"is_const": true,
"is_static": false,
"hash": 2988181878,
"arguments": [
{
"name": "array",
"type": "Array"
}
]
},
{ {
"name": "get_typed_builtin", "name": "get_typed_builtin",
"return_type": "int", "return_type": "int",
@ -30737,6 +30750,43 @@
} }
] ]
}, },
{
"name": "set_input_reset",
"is_const": false,
"is_vararg": false,
"is_static": false,
"is_virtual": false,
"hash": 300928843,
"arguments": [
{
"name": "input",
"type": "int",
"meta": "int32"
},
{
"name": "enable",
"type": "bool"
}
]
},
{
"name": "is_input_reset",
"is_const": true,
"is_vararg": false,
"is_static": false,
"is_virtual": false,
"hash": 1116898809,
"return_value": {
"type": "bool"
},
"arguments": [
{
"name": "input",
"type": "int",
"meta": "int32"
}
]
},
{ {
"name": "set_xfade_time", "name": "set_xfade_time",
"is_const": false, "is_const": false,
@ -30788,31 +30838,6 @@
"return_value": { "return_value": {
"type": "Curve" "type": "Curve"
} }
},
{
"name": "set_reset",
"is_const": false,
"is_vararg": false,
"is_static": false,
"is_virtual": false,
"hash": 2586408642,
"arguments": [
{
"name": "reset",
"type": "bool"
}
]
},
{
"name": "is_reset",
"is_const": true,
"is_vararg": false,
"is_static": false,
"is_virtual": false,
"hash": 36873697,
"return_value": {
"type": "bool"
}
} }
], ],
"properties": [ "properties": [
@ -30828,12 +30853,6 @@
"setter": "set_xfade_curve", "setter": "set_xfade_curve",
"getter": "get_xfade_curve" "getter": "get_xfade_curve"
}, },
{
"type": "bool",
"name": "reset",
"setter": "set_reset",
"getter": "is_reset"
},
{ {
"type": "int", "type": "int",
"name": "input_count", "name": "input_count",
@ -70751,23 +70770,14 @@
"is_vararg": false, "is_vararg": false,
"is_static": false, "is_static": false,
"is_virtual": false, "is_virtual": false,
"hash": 3871247334, "hash": 1262296096,
"return_value": { "return_value": {
"type": "enum::Error" "type": "enum::Error"
}, },
"arguments": [ "arguments": [
{ {
"name": "key", "name": "server_options",
"type": "CryptoKey" "type": "TLSOptions"
},
{
"name": "certificate",
"type": "X509Certificate"
},
{
"name": "chain",
"type": "X509Certificate",
"default_value": "null"
} }
] ]
}, },
@ -75968,18 +75978,14 @@
"is_vararg": false, "is_vararg": false,
"is_static": false, "is_static": false,
"is_virtual": false, "is_virtual": false,
"hash": 3447544237, "hash": 1262296096,
"return_value": { "return_value": {
"type": "enum::Error" "type": "enum::Error"
}, },
"arguments": [ "arguments": [
{ {
"name": "key", "name": "server_options",
"type": "CryptoKey" "type": "TLSOptions"
},
{
"name": "certificate",
"type": "X509Certificate"
} }
] ]
}, },
@ -75989,23 +75995,19 @@
"is_vararg": false, "is_vararg": false,
"is_static": false, "is_static": false,
"is_virtual": false, "is_virtual": false,
"hash": 2959136280, "hash": 3097527179,
"return_value": { "return_value": {
"type": "enum::Error" "type": "enum::Error"
}, },
"arguments": [ "arguments": [
{
"name": "certificate",
"type": "X509Certificate"
},
{ {
"name": "hostname", "name": "hostname",
"type": "String" "type": "String"
}, },
{ {
"name": "verify", "name": "client_options",
"type": "bool", "type": "TLSOptions",
"default_value": "true" "default_value": "null"
} }
] ]
}, },
@ -106783,7 +106785,7 @@
"is_vararg": false, "is_vararg": false,
"is_static": false, "is_static": false,
"is_virtual": false, "is_virtual": false,
"hash": 2602796911, "hash": 1970282951,
"return_value": { "return_value": {
"type": "enum::Error" "type": "enum::Error"
}, },
@ -106799,14 +106801,9 @@
"default_value": "-1" "default_value": "-1"
}, },
{ {
"name": "use_tls", "name": "tls_options",
"type": "bool", "type": "TLSOptions",
"default_value": "false" "default_value": "null"
},
{
"name": "verify_host",
"type": "bool",
"default_value": "true"
} }
] ]
}, },
@ -107209,7 +107206,7 @@
"is_vararg": false, "is_vararg": false,
"is_static": false, "is_static": false,
"is_virtual": false, "is_virtual": false,
"hash": 1899023990, "hash": 2720304520,
"return_value": { "return_value": {
"type": "enum::Error" "type": "enum::Error"
}, },
@ -107223,11 +107220,6 @@
"type": "PackedStringArray", "type": "PackedStringArray",
"default_value": "PackedStringArray()" "default_value": "PackedStringArray()"
}, },
{
"name": "tls_validate_domain",
"type": "bool",
"default_value": "true"
},
{ {
"name": "method", "name": "method",
"type": "enum::HTTPClient.Method", "type": "enum::HTTPClient.Method",
@ -107246,7 +107238,7 @@
"is_vararg": false, "is_vararg": false,
"is_static": false, "is_static": false,
"is_virtual": false, "is_virtual": false,
"hash": 3236422912, "hash": 4282724657,
"return_value": { "return_value": {
"type": "enum::Error" "type": "enum::Error"
}, },
@ -107260,11 +107252,6 @@
"type": "PackedStringArray", "type": "PackedStringArray",
"default_value": "PackedStringArray()" "default_value": "PackedStringArray()"
}, },
{
"name": "tls_validate_domain",
"type": "bool",
"default_value": "true"
},
{ {
"name": "method", "name": "method",
"type": "enum::HTTPClient.Method", "type": "enum::HTTPClient.Method",
@ -107285,6 +107272,20 @@
"is_virtual": false, "is_virtual": false,
"hash": 3218959716 "hash": 3218959716
}, },
{
"name": "set_tls_options",
"is_const": false,
"is_vararg": false,
"is_static": false,
"is_virtual": false,
"hash": 2210231844,
"arguments": [
{
"name": "client_options",
"type": "TLSOptions"
}
]
},
{ {
"name": "get_http_client_status", "name": "get_http_client_status",
"is_const": true, "is_const": true,
@ -109060,7 +109061,7 @@
"is_vararg": false, "is_vararg": false,
"is_static": false, "is_static": false,
"is_virtual": false, "is_virtual": false,
"hash": 3422491167, "hash": 4094210332,
"return_value": { "return_value": {
"type": "enum::Error" "type": "enum::Error"
}, },
@ -109074,12 +109075,6 @@
"type": "enum::Image.CompressSource", "type": "enum::Image.CompressSource",
"default_value": "0" "default_value": "0"
}, },
{
"name": "lossy_quality",
"type": "float",
"meta": "float",
"default_value": "0.7"
},
{ {
"name": "astc_format", "name": "astc_format",
"type": "enum::Image.ASTCFormat", "type": "enum::Image.ASTCFormat",
@ -109093,7 +109088,7 @@
"is_vararg": false, "is_vararg": false,
"is_static": false, "is_static": false,
"is_virtual": false, "is_virtual": false,
"hash": 180597543, "hash": 279105990,
"return_value": { "return_value": {
"type": "enum::Error" "type": "enum::Error"
}, },
@ -109106,12 +109101,6 @@
"name": "channels", "name": "channels",
"type": "enum::Image.UsedChannels" "type": "enum::Image.UsedChannels"
}, },
{
"name": "lossy_quality",
"type": "float",
"meta": "float",
"default_value": "0.7"
},
{ {
"name": "astc_format", "name": "astc_format",
"type": "enum::Image.ASTCFormat", "type": "enum::Image.ASTCFormat",
@ -110130,7 +110119,7 @@
{ {
"name": "blend_shapes", "name": "blend_shapes",
"type": "typedarray::Array", "type": "typedarray::Array",
"default_value": "[]" "default_value": "Array[Array]([])"
}, },
{ {
"name": "lods", "name": "lods",
@ -142942,7 +142931,7 @@
"is_vararg": false, "is_vararg": false,
"is_static": false, "is_static": false,
"is_virtual": false, "is_virtual": false,
"hash": 293566484, "hash": 1801538152,
"return_value": { "return_value": {
"type": "enum::Error" "type": "enum::Error"
}, },
@ -142952,18 +142941,12 @@
"type": "PacketPeerUDP" "type": "PacketPeerUDP"
}, },
{ {
"name": "validate_certs", "name": "hostname",
"type": "bool", "type": "String"
"default_value": "true"
}, },
{ {
"name": "for_hostname", "name": "client_options",
"type": "String", "type": "TLSOptions",
"default_value": "\"\""
},
{
"name": "valid_certificate",
"type": "X509Certificate",
"default_value": "null" "default_value": "null"
} }
] ]
@ -152015,7 +151998,7 @@
{ {
"name": "exclude", "name": "exclude",
"type": "typedarray::RID", "type": "typedarray::RID",
"default_value": "[]" "default_value": "Array[RID]([])"
} }
] ]
}, },
@ -152277,7 +152260,7 @@
{ {
"name": "exclude", "name": "exclude",
"type": "typedarray::RID", "type": "typedarray::RID",
"default_value": "[]" "default_value": "Array[RID]([])"
} }
] ]
}, },
@ -179773,7 +179756,7 @@
{ {
"name": "specialization_constants", "name": "specialization_constants",
"type": "typedarray::RDPipelineSpecializationConstant", "type": "typedarray::RDPipelineSpecializationConstant",
"default_value": "[]" "default_value": "Array[RDPipelineSpecializationConstant]([])"
} }
] ]
}, },
@ -179812,7 +179795,7 @@
{ {
"name": "specialization_constants", "name": "specialization_constants",
"type": "typedarray::RDPipelineSpecializationConstant", "type": "typedarray::RDPipelineSpecializationConstant",
"default_value": "[]" "default_value": "Array[RDPipelineSpecializationConstant]([])"
} }
] ]
}, },
@ -179967,7 +179950,7 @@
{ {
"name": "storage_textures", "name": "storage_textures",
"type": "Array", "type": "Array",
"default_value": "[]" "default_value": "Array[RID]([])"
} }
] ]
}, },
@ -180032,7 +180015,7 @@
{ {
"name": "storage_textures", "name": "storage_textures",
"type": "typedarray::RID", "type": "typedarray::RID",
"default_value": "[]" "default_value": "Array[RID]([])"
} }
] ]
}, },
@ -212668,7 +212651,7 @@
"is_vararg": false, "is_vararg": false,
"is_static": false, "is_static": false,
"is_virtual": false, "is_virtual": false,
"hash": 2359858912, "hash": 4292689651,
"return_value": { "return_value": {
"type": "enum::Error" "type": "enum::Error"
}, },
@ -212678,17 +212661,8 @@
"type": "StreamPeer" "type": "StreamPeer"
}, },
{ {
"name": "private_key", "name": "server_options",
"type": "CryptoKey" "type": "TLSOptions"
},
{
"name": "certificate",
"type": "X509Certificate"
},
{
"name": "chain",
"type": "X509Certificate",
"default_value": "null"
} }
] ]
}, },
@ -212698,7 +212672,7 @@
"is_vararg": false, "is_vararg": false,
"is_static": false, "is_static": false,
"is_virtual": false, "is_virtual": false,
"hash": 127827767, "hash": 1325480781,
"return_value": { "return_value": {
"type": "enum::Error" "type": "enum::Error"
}, },
@ -212708,18 +212682,12 @@
"type": "StreamPeer" "type": "StreamPeer"
}, },
{ {
"name": "validate_certs", "name": "common_name",
"type": "bool", "type": "String"
"default_value": "false"
}, },
{ {
"name": "for_hostname", "name": "client_options",
"type": "String", "type": "TLSOptions",
"default_value": "\"\""
},
{
"name": "valid_certificate",
"type": "X509Certificate",
"default_value": "null" "default_value": "null"
} }
] ]
@ -212753,39 +212721,6 @@
"is_static": false, "is_static": false,
"is_virtual": false, "is_virtual": false,
"hash": 3218959716 "hash": 3218959716
},
{
"name": "set_blocking_handshake_enabled",
"is_const": false,
"is_vararg": false,
"is_static": false,
"is_virtual": false,
"hash": 2586408642,
"arguments": [
{
"name": "enabled",
"type": "bool"
}
]
},
{
"name": "is_blocking_handshake_enabled",
"is_const": true,
"is_vararg": false,
"is_static": false,
"is_virtual": false,
"hash": 36873697,
"return_value": {
"type": "bool"
}
}
],
"properties": [
{
"type": "bool",
"name": "blocking_handshake",
"setter": "set_blocking_handshake_enabled",
"getter": "is_blocking_handshake_enabled"
} }
] ]
}, },
@ -215651,6 +215586,77 @@
} }
] ]
}, },
{
"name": "TLSOptions",
"is_refcounted": true,
"is_instantiable": false,
"inherits": "RefCounted",
"api_type": "core",
"methods": [
{
"name": "client",
"is_const": false,
"is_vararg": false,
"is_static": true,
"is_virtual": false,
"hash": 3565000357,
"return_value": {
"type": "TLSOptions"
},
"arguments": [
{
"name": "trusted_chain",
"type": "X509Certificate",
"default_value": "null"
},
{
"name": "common_name_override",
"type": "String",
"default_value": "\"\""
}
]
},
{
"name": "client_unsafe",
"is_const": false,
"is_vararg": false,
"is_static": true,
"is_virtual": false,
"hash": 2090251749,
"return_value": {
"type": "TLSOptions"
},
"arguments": [
{
"name": "trusted_chain",
"type": "X509Certificate",
"default_value": "null"
}
]
},
{
"name": "server",
"is_const": false,
"is_vararg": false,
"is_static": true,
"is_virtual": false,
"hash": 36969539,
"return_value": {
"type": "TLSOptions"
},
"arguments": [
{
"name": "key",
"type": "CryptoKey"
},
{
"name": "certificate",
"type": "X509Certificate"
}
]
}
]
},
{ {
"name": "TabBar", "name": "TabBar",
"is_refcounted": false, "is_refcounted": false,
@ -258837,7 +258843,7 @@
"is_vararg": false, "is_vararg": false,
"is_static": false, "is_static": false,
"is_virtual": false, "is_virtual": false,
"hash": 3369256093, "hash": 3097527179,
"return_value": { "return_value": {
"type": "enum::Error" "type": "enum::Error"
}, },
@ -258847,13 +258853,8 @@
"type": "String" "type": "String"
}, },
{ {
"name": "verify_tls", "name": "tls_client_options",
"type": "bool", "type": "TLSOptions",
"default_value": "true"
},
{
"name": "tls_certificate",
"type": "X509Certificate",
"default_value": "null" "default_value": "null"
} }
] ]
@ -258864,7 +258865,7 @@
"is_vararg": false, "is_vararg": false,
"is_static": false, "is_static": false,
"is_virtual": false, "is_virtual": false,
"hash": 2363339283, "hash": 337374795,
"return_value": { "return_value": {
"type": "enum::Error" "type": "enum::Error"
}, },
@ -258880,13 +258881,8 @@
"default_value": "\"*\"" "default_value": "\"*\""
}, },
{ {
"name": "tls_key", "name": "tls_server_options",
"type": "CryptoKey", "type": "TLSOptions",
"default_value": "null"
},
{
"name": "tls_certificate",
"type": "X509Certificate",
"default_value": "null" "default_value": "null"
} }
] ]
@ -259195,7 +259191,7 @@
"is_vararg": false, "is_vararg": false,
"is_static": false, "is_static": false,
"is_virtual": false, "is_virtual": false,
"hash": 3369256093, "hash": 3097527179,
"return_value": { "return_value": {
"type": "enum::Error" "type": "enum::Error"
}, },
@ -259205,13 +259201,8 @@
"type": "String" "type": "String"
}, },
{ {
"name": "verify_tls", "name": "tls_client_options",
"type": "bool", "type": "TLSOptions",
"default_value": "true"
},
{
"name": "trusted_tls_certificate",
"type": "X509Certificate",
"default_value": "null" "default_value": "null"
} }
] ]

View File

@ -551,6 +551,7 @@ typedef struct {
GDExtensionVariantPtr (*array_operator_index)(GDExtensionTypePtr p_self, GDExtensionInt p_index); // p_self should be an Array ptr GDExtensionVariantPtr (*array_operator_index)(GDExtensionTypePtr p_self, GDExtensionInt p_index); // p_self should be an Array ptr
GDExtensionVariantPtr (*array_operator_index_const)(GDExtensionConstTypePtr p_self, GDExtensionInt p_index); // p_self should be an Array ptr GDExtensionVariantPtr (*array_operator_index_const)(GDExtensionConstTypePtr p_self, GDExtensionInt p_index); // p_self should be an Array ptr
void (*array_ref)(GDExtensionTypePtr p_self, GDExtensionConstTypePtr p_from); // p_self should be an Array ptr
void (*array_set_typed)(GDExtensionTypePtr p_self, uint32_t p_type, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstVariantPtr p_script); // p_self should be an Array ptr void (*array_set_typed)(GDExtensionTypePtr p_self, uint32_t p_type, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstVariantPtr p_script); // p_self should be an Array ptr
/* Dictionary functions */ /* Dictionary functions */

View File

@ -39,14 +39,9 @@ namespace godot {
template <class T> template <class T>
class TypedArray : public Array { class TypedArray : public Array {
public: public:
template <class U>
_FORCE_INLINE_ void operator=(const TypedArray<U> &p_array) {
static_assert(__is_base_of(T, U));
typed_assign(p_array);
}
_FORCE_INLINE_ void operator=(const Array &p_array) { _FORCE_INLINE_ void operator=(const Array &p_array) {
typed_assign(p_array); ERR_FAIL_COND_MSG(!is_same_typed(p_array), "Cannot assign an array with a different element type.");
_ref(p_array);
} }
_FORCE_INLINE_ TypedArray(const Variant &p_variant) : _FORCE_INLINE_ TypedArray(const Variant &p_variant) :
Array(p_variant.operator Array(), Variant::OBJECT, T::get_class_static(), Variant()) { Array(p_variant.operator Array(), Variant::OBJECT, T::get_class_static(), Variant()) {
@ -61,22 +56,23 @@ public:
// specialization for the rest of variant types // specialization for the rest of variant types
#define MAKE_TYPED_ARRAY(m_type, m_variant_type) \ #define MAKE_TYPED_ARRAY(m_type, m_variant_type) \
template <> \ template <> \
class TypedArray<m_type> : public Array { \ class TypedArray<m_type> : public Array { \
public: \ public: \
_FORCE_INLINE_ void operator=(const Array &p_array) { \ _FORCE_INLINE_ void operator=(const Array &p_array) { \
typed_assign(p_array); \ ERR_FAIL_COND_MSG(!is_same_typed(p_array), "Cannot assign an array with a different element type."); \
} \ _ref(p_array); \
_FORCE_INLINE_ TypedArray(const Variant &p_variant) : \ } \
Array(p_variant.operator Array(), m_variant_type, StringName(), Variant()) { \ _FORCE_INLINE_ TypedArray(const Variant &p_variant) : \
} \ Array(p_variant.operator Array(), m_variant_type, StringName(), Variant()) { \
_FORCE_INLINE_ TypedArray(const Array &p_array) : \ } \
Array(p_array, m_variant_type, StringName(), Variant()) { \ _FORCE_INLINE_ TypedArray(const Array &p_array) : \
} \ Array(p_array, m_variant_type, StringName(), Variant()) { \
_FORCE_INLINE_ TypedArray() { \ } \
set_typed(m_variant_type, StringName(), Variant()); \ _FORCE_INLINE_ TypedArray() { \
} \ set_typed(m_variant_type, StringName(), Variant()); \
} \
}; };
MAKE_TYPED_ARRAY(bool, Variant::BOOL) MAKE_TYPED_ARRAY(bool, Variant::BOOL)

View File

@ -212,6 +212,10 @@ void Array::set_typed(uint32_t p_type, const StringName &p_class_name, const Var
internal::gde_interface->array_set_typed((GDExtensionTypePtr *)this, p_type, (GDExtensionConstStringNamePtr)&p_class_name, (GDExtensionConstVariantPtr)&p_script); internal::gde_interface->array_set_typed((GDExtensionTypePtr *)this, p_type, (GDExtensionConstStringNamePtr)&p_class_name, (GDExtensionConstVariantPtr)&p_script);
} }
void Array::_ref(const Array &p_from) const {
internal::gde_interface->array_ref((GDExtensionTypePtr *)this, (GDExtensionConstTypePtr *)&p_from);
}
const Variant &Dictionary::operator[](const Variant &p_key) const { const Variant &Dictionary::operator[](const Variant &p_key) const {
const Variant *var = (const Variant *)internal::gde_interface->dictionary_operator_index_const((GDExtensionTypePtr *)this, (GDExtensionVariantPtr)&p_key); const Variant *var = (const Variant *)internal::gde_interface->dictionary_operator_index_const((GDExtensionTypePtr *)this, (GDExtensionVariantPtr)&p_key);
return *var; return *var;