From 5cd0ea7e60d7878d2bf21fb9854062a67f1b756f Mon Sep 17 00:00:00 2001 From: Relintai Date: Tue, 9 Aug 2022 15:50:30 +0200 Subject: [PATCH] Fix serializing variants into binary files. --- core/io/resource_format_binary.cpp | 91 ++++++++++++++++++++++++------ 1 file changed, 74 insertions(+), 17 deletions(-) diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index aafef2399..87ff98a99 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -1350,6 +1350,13 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia f->store_real(val.x); f->store_real(val.y); + } break; + case Variant::VECTOR2I: { + f->store_32(VARIANT_VECTOR2I); + Vector2i val = p_property; + f->store_32(val.x); + f->store_32(val.y); + } break; case Variant::RECT2: { f->store_32(VARIANT_RECT2); @@ -1359,6 +1366,15 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia f->store_real(val.size.x); f->store_real(val.size.y); + } break; + case Variant::RECT2I: { + f->store_32(VARIANT_RECT2I); + Rect2i val = p_property; + f->store_32(val.position.x); + f->store_32(val.position.y); + f->store_32(val.size.x); + f->store_32(val.size.y); + } break; case Variant::VECTOR3: { f->store_32(VARIANT_VECTOR3); @@ -1368,6 +1384,26 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia f->store_real(val.z); } break; + case Variant::VECTOR3I: { + f->store_32(VARIANT_VECTOR3I); + Vector3i val = p_property; + f->store_32(val.x); + f->store_32(val.y); + f->store_32(val.z); + + } break; + case Variant::TRANSFORM2D: { + f->store_32(VARIANT_MATRIX32); + Transform2D val = p_property; + f->store_real(val.elements[0].x); + f->store_real(val.elements[0].y); + f->store_real(val.elements[1].x); + f->store_real(val.elements[1].y); + f->store_real(val.elements[2].x); + f->store_real(val.elements[2].y); + + } break; + case Variant::PLANE: { f->store_32(VARIANT_PLANE); Plane val = p_property; @@ -1396,17 +1432,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia f->store_real(val.size.y); f->store_real(val.size.z); - } break; - case Variant::TRANSFORM2D: { - f->store_32(VARIANT_MATRIX32); - Transform2D val = p_property; - f->store_real(val.elements[0].x); - f->store_real(val.elements[0].y); - f->store_real(val.elements[1].x); - f->store_real(val.elements[1].y); - f->store_real(val.elements[2].x); - f->store_real(val.elements[2].y); - } break; case Variant::BASIS: { f->store_32(VARIANT_MATRIX3); @@ -1422,6 +1447,7 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia f->store_real(val.elements[2].z); } break; + case Variant::TRANSFORM: { f->store_32(VARIANT_TRANSFORM); Transform val = p_property; @@ -1502,6 +1528,12 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia //internal resource } + } break; + case Variant::STRING_NAME: { + f->store_32(VARIANT_STRING_NAME); + String val = p_property; + save_unicode_string(f, val); + } break; case Variant::DICTIONARY: { f->store_32(VARIANT_DICTIONARY); @@ -1573,6 +1605,30 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia save_unicode_string(f, r[i]); } + } break; + case Variant::POOL_VECTOR2_ARRAY: { + f->store_32(VARIANT_VECTOR2_ARRAY); + PoolVector arr = p_property; + int len = arr.size(); + f->store_32(len); + PoolVector::Read r = arr.read(); + for (int i = 0; i < len; i++) { + f->store_real(r[i].x); + f->store_real(r[i].y); + } + + } break; + case Variant::POOL_VECTOR2I_ARRAY: { + f->store_32(VARIANT_VECTOR2I_ARRAY); + PoolVector arr = p_property; + int len = arr.size(); + f->store_32(len); + PoolVector::Read r = arr.read(); + for (int i = 0; i < len; i++) { + f->store_32(r[i].x); + f->store_32(r[i].y); + } + } break; case Variant::POOL_VECTOR3_ARRAY: { f->store_32(VARIANT_VECTOR3_ARRAY); @@ -1587,15 +1643,16 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } } break; - case Variant::POOL_VECTOR2_ARRAY: { - f->store_32(VARIANT_VECTOR2_ARRAY); - PoolVector arr = p_property; + case Variant::POOL_VECTOR3I_ARRAY: { + f->store_32(VARIANT_VECTOR3I_ARRAY); + PoolVector arr = p_property; int len = arr.size(); f->store_32(len); - PoolVector::Read r = arr.read(); + PoolVector::Read r = arr.read(); for (int i = 0; i < len; i++) { - f->store_real(r[i].x); - f->store_real(r[i].y); + f->store_32(r[i].x); + f->store_32(r[i].y); + f->store_32(r[i].z); } } break;