summaryrefslogtreecommitdiff
path: root/core/io
diff options
context:
space:
mode:
authorJuan Linietsky <juan@godotengine.org>2020-02-22 00:26:41 -0300
committerJuan Linietsky <reduzio@gmail.com>2020-02-22 23:16:44 +0100
commit6da0eef9e6695e0da17953d80a1e6b0b673b4678 (patch)
tree1b08291b93a47f81c2a810f58996e1135777672a /core/io
parenta7891b9d120e1cb49bcdcffc1107f692ed481d86 (diff)
Add support for Vector2i, Rect2i and Vector3i to Variant
WARNING: Requires C++17 'guaranteed copy elision' to fix ambiguous operator problems in Variant. This was added for this commit (and future C++17 uses) in #36457.
Diffstat (limited to 'core/io')
-rw-r--r--core/io/marshalls.cpp74
-rw-r--r--core/io/resource_format_binary.cpp56
2 files changed, 130 insertions, 0 deletions
diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp
index b77ef40fd3..e97c26e05d 100644
--- a/core/io/marshalls.cpp
+++ b/core/io/marshalls.cpp
@@ -187,6 +187,18 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
(*r_len) += 4 * 2;
} break; // 5
+ case Variant::VECTOR2I: {
+
+ ERR_FAIL_COND_V(len < 4 * 2, ERR_INVALID_DATA);
+ Vector2i val;
+ val.x = decode_uint32(&buf[0]);
+ val.y = decode_uint32(&buf[4]);
+ r_variant = val;
+
+ if (r_len)
+ (*r_len) += 4 * 2;
+
+ } break; // 5
case Variant::RECT2: {
ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA);
@@ -201,6 +213,20 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
(*r_len) += 4 * 4;
} break;
+ case Variant::RECT2I: {
+
+ ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA);
+ Rect2i val;
+ val.position.x = decode_uint32(&buf[0]);
+ val.position.y = decode_uint32(&buf[4]);
+ val.size.x = decode_uint32(&buf[8]);
+ val.size.y = decode_uint32(&buf[12]);
+ r_variant = val;
+
+ if (r_len)
+ (*r_len) += 4 * 4;
+
+ } break;
case Variant::VECTOR3: {
ERR_FAIL_COND_V(len < 4 * 3, ERR_INVALID_DATA);
@@ -214,6 +240,19 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
(*r_len) += 4 * 3;
} break;
+ case Variant::VECTOR3I: {
+
+ ERR_FAIL_COND_V(len < 4 * 3, ERR_INVALID_DATA);
+ Vector3i val;
+ val.x = decode_uint32(&buf[0]);
+ val.y = decode_uint32(&buf[4]);
+ val.z = decode_uint32(&buf[8]);
+ r_variant = val;
+
+ if (r_len)
+ (*r_len) += 4 * 3;
+
+ } break;
case Variant::TRANSFORM2D: {
ERR_FAIL_COND_V(len < 4 * 6, ERR_INVALID_DATA);
@@ -967,6 +1006,17 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 2 * 4;
} break; // 5
+ case Variant::VECTOR2I: {
+
+ if (buf) {
+ Vector2i v2 = p_variant;
+ encode_uint32(v2.x, &buf[0]);
+ encode_uint32(v2.y, &buf[4]);
+ }
+
+ r_len += 2 * 4;
+
+ } break; // 5
case Variant::RECT2: {
if (buf) {
@@ -979,6 +1029,18 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 4 * 4;
} break;
+ case Variant::RECT2I: {
+
+ if (buf) {
+ Rect2i r2 = p_variant;
+ encode_uint32(r2.position.x, &buf[0]);
+ encode_uint32(r2.position.y, &buf[4]);
+ encode_uint32(r2.size.x, &buf[8]);
+ encode_uint32(r2.size.y, &buf[12]);
+ }
+ r_len += 4 * 4;
+
+ } break;
case Variant::VECTOR3: {
if (buf) {
@@ -991,6 +1053,18 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 3 * 4;
} break;
+ case Variant::VECTOR3I: {
+
+ if (buf) {
+ Vector3i v3 = p_variant;
+ encode_uint32(v3.x, &buf[0]);
+ encode_uint32(v3.y, &buf[4]);
+ encode_uint32(v3.z, &buf[8]);
+ }
+
+ r_len += 3 * 4;
+
+ } break;
case Variant::TRANSFORM2D: {
if (buf) {
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index 144e48d0da..518323c5c4 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -76,6 +76,9 @@ enum {
VARIANT_CALLABLE = 42,
VARIANT_SIGNAL = 43,
VARIANT_STRING_NAME = 44,
+ VARIANT_VECTOR2I = 45,
+ VARIANT_RECT2I = 46,
+ VARIANT_VECTOR3I = 47,
OBJECT_EMPTY = 0,
OBJECT_EXTERNAL_RESOURCE = 1,
OBJECT_INTERNAL_RESOURCE = 2,
@@ -159,6 +162,14 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
r_v = v;
} break;
+ case VARIANT_VECTOR2I: {
+
+ Vector2i v;
+ v.x = f->get_32();
+ v.y = f->get_32();
+ r_v = v;
+
+ } break;
case VARIANT_RECT2: {
Rect2 v;
@@ -169,6 +180,16 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
r_v = v;
} break;
+ case VARIANT_RECT2I: {
+
+ Rect2i v;
+ v.position.x = f->get_32();
+ v.position.y = f->get_32();
+ v.size.x = f->get_32();
+ v.size.y = f->get_32();
+ r_v = v;
+
+ } break;
case VARIANT_VECTOR3: {
Vector3 v;
@@ -177,6 +198,14 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
v.z = f->get_real();
r_v = v;
} break;
+ case VARIANT_VECTOR3I: {
+
+ Vector3i v;
+ v.x = f->get_32();
+ v.y = f->get_32();
+ v.z = f->get_32();
+ r_v = v;
+ } break;
case VARIANT_PLANE: {
Plane v;
@@ -1293,6 +1322,14 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
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);
@@ -1303,6 +1340,16 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
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);
@@ -1312,6 +1359,15 @@ 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::PLANE: {
f->store_32(VARIANT_PLANE);