summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2021-07-24 21:54:48 +0200
committerGitHub <noreply@github.com>2021-07-24 21:54:48 +0200
commitfb821b83986dcfd610b7330f4128e169e8368c45 (patch)
tree4ac91709cb2a366d9717237c0ad0a87287a60a48 /core
parent2ee395a277a424dd8d6431d4a32f0ff6f60271e8 (diff)
parent20818c12b79829f6101e15b21e92ee05f25f56e7 (diff)
Merge pull request #50535 from ChristopheClaustre/packedbytearray_decode_api
Change in PackedByteArray decode api and docs
Diffstat (limited to 'core')
-rw-r--r--core/variant/variant_call.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp
index c77a5af6d7..a9645da045 100644
--- a/core/variant/variant_call.cpp
+++ b/core/variant/variant_call.cpp
@@ -750,6 +750,42 @@ struct _VariantCall {
return 0;
}
+ static PackedInt32Array func_PackedByteArray_decode_s32_array(PackedByteArray *p_instance) {
+ uint64_t size = p_instance->size();
+ const uint8_t *r = p_instance->ptr();
+ PackedInt32Array dest;
+ dest.resize(size / sizeof(int32_t));
+ memcpy(dest.ptrw(), r, size);
+ return dest;
+ }
+
+ static PackedInt64Array func_PackedByteArray_decode_s64_array(PackedByteArray *p_instance) {
+ uint64_t size = p_instance->size();
+ const uint8_t *r = p_instance->ptr();
+ PackedInt64Array dest;
+ dest.resize(size / sizeof(int64_t));
+ memcpy(dest.ptrw(), r, size);
+ return dest;
+ }
+
+ static PackedFloat32Array func_PackedByteArray_decode_float_array(PackedByteArray *p_instance) {
+ uint64_t size = p_instance->size();
+ const uint8_t *r = p_instance->ptr();
+ PackedFloat32Array dest;
+ dest.resize(size / sizeof(float));
+ memcpy(dest.ptrw(), r, size);
+ return dest;
+ }
+
+ static PackedFloat64Array func_PackedByteArray_decode_double_array(PackedByteArray *p_instance) {
+ uint64_t size = p_instance->size();
+ const uint8_t *r = p_instance->ptr();
+ PackedFloat64Array dest;
+ dest.resize(size / sizeof(double));
+ memcpy(dest.ptrw(), r, size);
+ return dest;
+ }
+
static void func_PackedByteArray_encode_u8(PackedByteArray *p_instance, int64_t p_offset, int64_t p_value) {
uint64_t size = p_instance->size();
ERR_FAIL_COND(p_offset < 0 || p_offset > int64_t(size) - 1);
@@ -1824,6 +1860,11 @@ static void _register_variant_builtin_methods() {
bind_function(PackedByteArray, decode_var, _VariantCall::func_PackedByteArray_decode_var, sarray("byte_offset", "allow_objects"), varray(false));
bind_function(PackedByteArray, decode_var_size, _VariantCall::func_PackedByteArray_decode_var_size, sarray("byte_offset", "allow_objects"), varray(false));
+ bind_function(PackedByteArray, to_int32_array, _VariantCall::func_PackedByteArray_decode_s32_array, sarray(), varray());
+ bind_function(PackedByteArray, to_int64_array, _VariantCall::func_PackedByteArray_decode_s64_array, sarray(), varray());
+ bind_function(PackedByteArray, to_float32_array, _VariantCall::func_PackedByteArray_decode_float_array, sarray(), varray());
+ bind_function(PackedByteArray, to_float64_array, _VariantCall::func_PackedByteArray_decode_double_array, sarray(), varray());
+
bind_functionnc(PackedByteArray, encode_u8, _VariantCall::func_PackedByteArray_encode_u8, sarray("byte_offset", "value"), varray());
bind_functionnc(PackedByteArray, encode_s8, _VariantCall::func_PackedByteArray_encode_s8, sarray("byte_offset", "value"), varray());
bind_functionnc(PackedByteArray, encode_u16, _VariantCall::func_PackedByteArray_encode_u16, sarray("byte_offset", "value"), varray());