diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2020-09-07 16:59:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-07 16:59:26 +0200 |
commit | 8eb295cc54696671a6f3c4e94c14b4b7ceba11ea (patch) | |
tree | c26b5c8c3bc586c3aa3bc830ad1a4d16b3b68603 | |
parent | 82efb06aaa946d23cab13ee6db796ebb26e19b96 (diff) | |
parent | 8f1a6d74892a3252dc8a7b9515f40f390ae2c771 (diff) |
Merge pull request #39100 from Wavesonics/pool-byte-array-fix
Fixed PackedByteArray GDScript functions
-rw-r--r-- | core/variant_call.cpp | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 7a1fdbaafe..d150ae28d7 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -630,14 +630,14 @@ struct _VariantCall { VCALL_LOCALMEM0R(Array, min); static void _call_PackedByteArray_get_string_from_ascii(Variant &r_ret, Variant &p_self, const Variant **p_args) { - PackedByteArray *ba = reinterpret_cast<PackedByteArray *>(p_self._data._mem); + Variant::PackedArrayRef<uint8_t> *ba = reinterpret_cast<Variant::PackedArrayRef<uint8_t> *>(p_self._data.packed_array); String s; - if (ba->size() > 0) { - const uint8_t *r = ba->ptr(); + if (ba->array.size() > 0) { + const uint8_t *r = ba->array.ptr(); CharString cs; - cs.resize(ba->size() + 1); - copymem(cs.ptrw(), r, ba->size()); - cs[ba->size()] = 0; + cs.resize(ba->array.size() + 1); + copymem(cs.ptrw(), r, ba->array.size()); + cs[ba->array.size()] = 0; s = cs.get_data(); } @@ -645,11 +645,12 @@ struct _VariantCall { } static void _call_PackedByteArray_get_string_from_utf8(Variant &r_ret, Variant &p_self, const Variant **p_args) { - PackedByteArray *ba = reinterpret_cast<PackedByteArray *>(p_self._data._mem); + Variant::PackedArrayRef<uint8_t> *ba = reinterpret_cast<Variant::PackedArrayRef<uint8_t> *>(p_self._data.packed_array); + String s; - if (ba->size() > 0) { - const uint8_t *r = ba->ptr(); - s.parse_utf8((const char *)r, ba->size()); + if (ba->array.size() > 0) { + const uint8_t *r = ba->array.ptr(); + s.parse_utf8((const char *)r, ba->array.size()); } r_ret = s; } @@ -675,22 +676,23 @@ struct _VariantCall { } static void _call_PackedByteArray_compress(Variant &r_ret, Variant &p_self, const Variant **p_args) { - PackedByteArray *ba = reinterpret_cast<PackedByteArray *>(p_self._data._mem); + Variant::PackedArrayRef<uint8_t> *ba = reinterpret_cast<Variant::PackedArrayRef<uint8_t> *>(p_self._data.packed_array); PackedByteArray compressed; - if (ba->size() > 0) { - Compression::Mode mode = (Compression::Mode)(int)(*p_args[0]); - compressed.resize(Compression::get_max_compressed_buffer_size(ba->size(), mode)); - int result = Compression::compress(compressed.ptrw(), ba->ptr(), ba->size(), mode); + if (ba->array.size() > 0) { + Compression::Mode mode = (Compression::Mode)(int)(*p_args[0]); + compressed.resize(Compression::get_max_compressed_buffer_size(ba->array.size(), mode)); + int result = Compression::compress(compressed.ptrw(), ba->array.ptr(), ba->array.size(), mode); result = result >= 0 ? result : 0; compressed.resize(result); } + r_ret = compressed; } static void _call_PackedByteArray_decompress(Variant &r_ret, Variant &p_self, const Variant **p_args) { - PackedByteArray *ba = reinterpret_cast<PackedByteArray *>(p_self._data._mem); + Variant::PackedArrayRef<uint8_t> *ba = reinterpret_cast<Variant::PackedArrayRef<uint8_t> *>(p_self._data.packed_array); PackedByteArray decompressed; Compression::Mode mode = (Compression::Mode)(int)(*p_args[1]); @@ -702,7 +704,7 @@ struct _VariantCall { } decompressed.resize(buffer_size); - int result = Compression::decompress(decompressed.ptrw(), buffer_size, ba->ptr(), ba->size(), mode); + int result = Compression::decompress(decompressed.ptrw(), buffer_size, ba->array.ptr(), ba->array.size(), mode); result = result >= 0 ? result : 0; decompressed.resize(result); @@ -711,13 +713,13 @@ struct _VariantCall { } static void _call_PackedByteArray_hex_encode(Variant &r_ret, Variant &p_self, const Variant **p_args) { - PackedByteArray *ba = reinterpret_cast<PackedByteArray *>(p_self._data._mem); - if (ba->size() == 0) { + Variant::PackedArrayRef<uint8_t> *ba = reinterpret_cast<Variant::PackedArrayRef<uint8_t> *>(p_self._data.packed_array); + if (ba->array.size() == 0) { r_ret = String(); return; } - const uint8_t *r = ba->ptr(); - String s = String::hex_encode_buffer(&r[0], ba->size()); + const uint8_t *r = ba->array.ptr(); + String s = String::hex_encode_buffer(&r[0], ba->array.size()); r_ret = s; } |