diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2024-05-03 12:25:26 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-05-03 12:25:26 +0200 |
commit | 03e6fbb010c3546593bd91a0dabc045a9882705a (patch) | |
tree | 3fecc6c86700d555245a71ac2b6421c5296a3132 /core/variant/variant_parser.cpp | |
parent | d898f37e35ac4966fc7d54a009d05181fd3b232e (diff) | |
parent | f9b488508ccc294db03d427c15c182864fae74de (diff) | |
download | redot-engine-03e6fbb010c3546593bd91a0dabc045a9882705a.tar.gz |
Merge pull request #85474 from fire/packedvector4array
Add `PackedVector4Array` Variant type
Diffstat (limited to 'core/variant/variant_parser.cpp')
-rw-r--r-- | core/variant/variant_parser.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/core/variant/variant_parser.cpp b/core/variant/variant_parser.cpp index 50f8007efa..9a0dd712ed 100644 --- a/core/variant/variant_parser.cpp +++ b/core/variant/variant_parser.cpp @@ -1395,6 +1395,24 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, } value = arr; + } else if (id == "PackedVector4Array" || id == "PoolVector4Array" || id == "Vector4Array") { + Vector<real_t> args; + Error err = _parse_construct<real_t>(p_stream, args, line, r_err_str); + if (err) { + return err; + } + + Vector<Vector4> arr; + { + int len = args.size() / 4; + arr.resize(len); + Vector4 *w = arr.ptrw(); + for (int i = 0; i < len; i++) { + w[i] = Vector4(args[i * 4 + 0], args[i * 4 + 1], args[i * 4 + 2], args[i * 4 + 3]); + } + } + + value = arr; } else if (id == "PackedColorArray" || id == "PoolColorArray" || id == "ColorArray") { Vector<float> args; Error err = _parse_construct<float>(p_stream, args, line, r_err_str); @@ -2248,6 +2266,21 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str p_store_string_func(p_store_string_ud, ")"); } break; + case Variant::PACKED_VECTOR4_ARRAY: { + p_store_string_func(p_store_string_ud, "PackedVector4Array("); + Vector<Vector4> data = p_variant; + int len = data.size(); + const Vector4 *ptr = data.ptr(); + + for (int i = 0; i < len; i++) { + if (i > 0) { + p_store_string_func(p_store_string_ud, ", "); + } + p_store_string_func(p_store_string_ud, rtos_fix(ptr[i].x) + ", " + rtos_fix(ptr[i].y) + ", " + rtos_fix(ptr[i].z) + ", " + rtos_fix(ptr[i].w)); + } + + p_store_string_func(p_store_string_ud, ")"); + } break; default: { ERR_PRINT("Unknown variant type"); |