diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2020-05-14 23:09:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-14 23:09:03 +0200 |
commit | 00949f0c5fcc6a4f8382a4a97d5591fd9ec380f8 (patch) | |
tree | 2b1c31f45add24085b64425ce440f577424c16a1 /core/io/marshalls.cpp | |
parent | 5046f666a1181675b39f156c38346525dc1c444e (diff) | |
parent | 0ee0fa42e6639b6fa474b7cf6afc6b1a78142185 (diff) |
Merge pull request #38738 from akien-mga/cause-we-never-go-out-of-style
Style: Remove new line at block start, enforce line between functions, enforce braces in if and loop blocks
Diffstat (limited to 'core/io/marshalls.cpp')
-rw-r--r-- | core/io/marshalls.cpp | 271 |
1 files changed, 104 insertions, 167 deletions
diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index abf27954b8..eb39b1433f 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -49,7 +49,6 @@ void EncodedObjectAsID::set_object_id(ObjectID p_id) { } ObjectID EncodedObjectAsID::get_object_id() const { - return id; } @@ -97,7 +96,6 @@ static Error _decode_string(const uint8_t *&buf, int &len, int *r_len, String &r } Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len, bool p_allow_objects) { - const uint8_t *buf = p_buffer; int len = p_len; @@ -109,95 +107,95 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int buf += 4; len -= 4; - if (r_len) + if (r_len) { *r_len = 4; + } switch (type & ENCODE_MASK) { - case Variant::NIL: { - r_variant = Variant(); } break; case Variant::BOOL: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); bool val = decode_uint32(buf); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4; + } } break; case Variant::INT: { - if (type & ENCODE_FLAG_64) { ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA); int64_t val = decode_uint64(buf); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 8; + } } else { ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t val = decode_uint32(buf); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4; + } } } break; case Variant::FLOAT: { - if (type & ENCODE_FLAG_64) { ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA); double val = decode_double(buf); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 8; + } } else { ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); float val = decode_float(buf); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4; + } } } break; case Variant::STRING: { - String str; Error err = _decode_string(buf, len, r_len, str); - if (err) + if (err) { return err; + } r_variant = str; } break; // math types case Variant::VECTOR2: { - ERR_FAIL_COND_V(len < 4 * 2, ERR_INVALID_DATA); Vector2 val; val.x = decode_float(&buf[0]); val.y = decode_float(&buf[4]); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4 * 2; + } } break; 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) + if (r_len) { (*r_len) += 4 * 2; + } } break; case Variant::RECT2: { - ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA); Rect2 val; val.position.x = decode_float(&buf[0]); @@ -206,12 +204,12 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int val.size.y = decode_float(&buf[12]); r_variant = val; - if (r_len) + if (r_len) { (*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]); @@ -220,12 +218,12 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int val.size.y = decode_uint32(&buf[12]); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4 * 4; + } } break; case Variant::VECTOR3: { - ERR_FAIL_COND_V(len < 4 * 3, ERR_INVALID_DATA); Vector3 val; val.x = decode_float(&buf[0]); @@ -233,12 +231,12 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int val.z = decode_float(&buf[8]); r_variant = val; - if (r_len) + if (r_len) { (*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]); @@ -246,29 +244,28 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int val.z = decode_uint32(&buf[8]); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4 * 3; + } } break; case Variant::TRANSFORM2D: { - ERR_FAIL_COND_V(len < 4 * 6, ERR_INVALID_DATA); Transform2D val; for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) { - val.elements[i][j] = decode_float(&buf[(i * 2 + j) * 4]); } } r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4 * 6; + } } break; case Variant::PLANE: { - ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA); Plane val; val.normal.x = decode_float(&buf[0]); @@ -277,12 +274,12 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int val.d = decode_float(&buf[12]); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4 * 4; + } } break; case Variant::QUAT: { - ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA); Quat val; val.x = decode_float(&buf[0]); @@ -291,12 +288,12 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int val.w = decode_float(&buf[12]); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4 * 4; + } } break; case Variant::AABB: { - ERR_FAIL_COND_V(len < 4 * 6, ERR_INVALID_DATA); AABB val; val.position.x = decode_float(&buf[0]); @@ -307,34 +304,32 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int val.size.z = decode_float(&buf[20]); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4 * 6; + } } break; case Variant::BASIS: { - ERR_FAIL_COND_V(len < 4 * 9, ERR_INVALID_DATA); Basis val; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - val.elements[i][j] = decode_float(&buf[(i * 3 + j) * 4]); } } r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4 * 9; + } } break; case Variant::TRANSFORM: { - ERR_FAIL_COND_V(len < 4 * 12, ERR_INVALID_DATA); Transform val; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - val.basis.elements[i][j] = decode_float(&buf[(i * 3 + j) * 4]); } } @@ -344,14 +339,14 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4 * 12; + } } break; // misc types case Variant::COLOR: { - ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA); Color val; val.r = decode_float(&buf[0]); @@ -360,22 +355,22 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int val.a = decode_float(&buf[12]); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4 * 4; + } } break; case Variant::STRING_NAME: { - String str; Error err = _decode_string(buf, len, r_len, str); - if (err) + if (err) { return err; + } r_variant = StringName(str); } break; case Variant::NODE_PATH: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t strlen = decode_uint32(buf); @@ -392,25 +387,28 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int len -= 12; buf += 12; - if (flags & 2) // Obsolete format with property separate from subpath + if (flags & 2) { // Obsolete format with property separate from subpath subnamecount++; + } uint32_t total = namecount + subnamecount; - if (r_len) + if (r_len) { (*r_len) += 12; + } for (uint32_t i = 0; i < total; i++) { - String str; Error err = _decode_string(buf, len, r_len, str); - if (err) + if (err) { return err; + } - if (i < namecount) + if (i < namecount) { names.push_back(str); - else + } else { subnames.push_back(str); + } } r_variant = NodePath(names, subnames, flags & 1); @@ -423,17 +421,16 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::_RID: { - r_variant = RID(); } break; case Variant::OBJECT: { - if (type & ENCODE_FLAG_OBJECT_AS_ID) { //this _is_ allowed ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA); ObjectID val = ObjectID(decode_uint64(buf)); - if (r_len) + if (r_len) { (*r_len) += 8; + } if (val.is_null()) { r_variant = (Object *)nullptr; @@ -450,13 +447,13 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int String str; Error err = _decode_string(buf, len, r_len, str); - if (err) + if (err) { return err; + } if (str == String()) { r_variant = (Object *)nullptr; } else { - Object *obj = ClassDB::instance(str); ERR_FAIL_COND_V(!obj, ERR_UNAVAILABLE); @@ -470,17 +467,18 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } for (int i = 0; i < count; i++) { - str = String(); err = _decode_string(buf, len, r_len, str); - if (err) + if (err) { return err; + } Variant value; int used; err = decode_variant(value, buf, len, &used, p_allow_objects); - if (err) + if (err) { return err; + } buf += used; len -= used; @@ -502,16 +500,13 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::CALLABLE: { - r_variant = Callable(); } break; case Variant::SIGNAL: { - r_variant = Signal(); } break; case Variant::DICTIONARY: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t count = decode_uint32(buf); // bool shared = count&0x80000000; @@ -527,7 +522,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int Dictionary d; for (int i = 0; i < count; i++) { - Variant key, value; int used; @@ -556,7 +550,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::ARRAY: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t count = decode_uint32(buf); // bool shared = count&0x80000000; @@ -572,7 +565,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int Array varr; for (int i = 0; i < count; i++) { - int used = 0; Variant v; Error err = decode_variant(v, buf, len, &used, p_allow_objects); @@ -591,7 +583,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int // arrays case Variant::PACKED_BYTE_ARRAY: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t count = decode_uint32(buf); buf += 4; @@ -604,7 +595,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int data.resize(count); uint8_t *w = data.ptrw(); for (int32_t i = 0; i < count; i++) { - w[i] = buf[i]; } } @@ -612,14 +602,14 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int r_variant = data; if (r_len) { - if (count % 4) + if (count % 4) { (*r_len) += 4 - count % 4; + } (*r_len) += 4 + count; } } break; case Variant::PACKED_INT32_ARRAY: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t count = decode_uint32(buf); buf += 4; @@ -634,7 +624,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int data.resize(count); int32_t *w = data.ptrw(); for (int32_t i = 0; i < count; i++) { - w[i] = decode_uint32(&buf[i * 4]); } } @@ -645,7 +634,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::PACKED_INT64_ARRAY: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int64_t count = decode_uint64(buf); buf += 4; @@ -660,7 +648,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int data.resize(count); int64_t *w = data.ptrw(); for (int64_t i = 0; i < count; i++) { - w[i] = decode_uint64(&buf[i * 8]); } } @@ -671,7 +658,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::PACKED_FLOAT32_ARRAY: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t count = decode_uint32(buf); buf += 4; @@ -686,7 +672,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int data.resize(count); float *w = data.ptrw(); for (int32_t i = 0; i < count; i++) { - w[i] = decode_float(&buf[i * 4]); } } @@ -698,7 +683,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::PACKED_FLOAT64_ARRAY: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int64_t count = decode_uint64(buf); buf += 4; @@ -713,7 +697,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int data.resize(count); double *w = data.ptrw(); for (int64_t i = 0; i < count; i++) { - w[i] = decode_double(&buf[i * 8]); } } @@ -725,7 +708,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::PACKED_STRING_ARRAY: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t count = decode_uint32(buf); @@ -733,16 +715,17 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int buf += 4; len -= 4; - if (r_len) + if (r_len) { (*r_len) += 4; + } //printf("string count: %i\n",count); for (int32_t i = 0; i < count; i++) { - String str; Error err = _decode_string(buf, len, r_len, str); - if (err) + if (err) { return err; + } strings.push_back(str); } @@ -751,7 +734,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::PACKED_VECTOR2_ARRAY: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t count = decode_uint32(buf); buf += 4; @@ -770,22 +752,21 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int Vector2 *w = varray.ptrw(); for (int32_t i = 0; i < count; i++) { - w[i].x = decode_float(buf + i * 4 * 2 + 4 * 0); w[i].y = decode_float(buf + i * 4 * 2 + 4 * 1); } int adv = 4 * 2 * count; - if (r_len) + if (r_len) { (*r_len) += adv; + } } r_variant = varray; } break; case Variant::PACKED_VECTOR3_ARRAY: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t count = decode_uint32(buf); buf += 4; @@ -805,7 +786,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int Vector3 *w = varray.ptrw(); for (int32_t i = 0; i < count; i++) { - w[i].x = decode_float(buf + i * 4 * 3 + 4 * 0); w[i].y = decode_float(buf + i * 4 * 3 + 4 * 1); w[i].z = decode_float(buf + i * 4 * 3 + 4 * 2); @@ -813,15 +793,15 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int int adv = 4 * 3 * count; - if (r_len) + if (r_len) { (*r_len) += adv; + } } r_variant = varray; } break; case Variant::PACKED_COLOR_ARRAY: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t count = decode_uint32(buf); buf += 4; @@ -841,7 +821,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int Color *w = carray.ptrw(); for (int32_t i = 0; i < count; i++) { - w[i].r = decode_float(buf + i * 4 * 4 + 4 * 0); w[i].g = decode_float(buf + i * 4 * 4 + 4 * 1); w[i].b = decode_float(buf + i * 4 * 4 + 4 * 2); @@ -850,8 +829,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int int adv = 4 * 4 * count; - if (r_len) + if (r_len) { (*r_len) += adv; + } } r_variant = carray; @@ -866,7 +846,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } static void _encode_string(const String &p_string, uint8_t *&buf, int &r_len) { - CharString utf8 = p_string.utf8(); if (buf) { @@ -886,7 +865,6 @@ static void _encode_string(const String &p_string, uint8_t *&buf, int &r_len) { } Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bool p_full_objects) { - uint8_t *buf = r_buffer; r_len = 0; @@ -894,7 +872,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo uint32_t flags = 0; switch (p_variant.get_type()) { - case Variant::INT: { int64_t val = p_variant; if (val > (int64_t)INT_MAX || val < (int64_t)INT_MIN) { @@ -902,7 +879,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } } break; case Variant::FLOAT: { - double d = p_variant; float f = d; if (double(f) != d) { @@ -910,7 +886,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } } break; case Variant::OBJECT: { - // Test for potential wrong values sent by the debugger when it breaks. Object *obj = p_variant.get_validated_object(); if (!obj) { @@ -937,13 +912,10 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 4; switch (p_variant.get_type()) { - case Variant::NIL: { - //nothing to do } break; case Variant::BOOL: { - if (buf) { encode_uint32(p_variant.operator bool(), buf); } @@ -952,7 +924,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::INT: { - if (flags & ENCODE_FLAG_64) { //64 bits if (buf) { @@ -969,7 +940,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } } break; case Variant::FLOAT: { - if (flags & ENCODE_FLAG_64) { if (buf) { encode_double(p_variant.operator double(), buf); @@ -978,7 +948,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 8; } else { - if (buf) { encode_float(p_variant.operator float(), buf); } @@ -988,14 +957,14 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::NODE_PATH: { - NodePath np = p_variant; if (buf) { encode_uint32(uint32_t(np.get_name_count()) | 0x80000000, buf); //for compatibility with the old format encode_uint32(np.get_subname_count(), buf + 4); uint32_t np_flags = 0; - if (np.is_absolute()) + if (np.is_absolute()) { np_flags |= 1; + } encode_uint32(np_flags, buf + 8); @@ -1007,20 +976,21 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo int total = np.get_name_count() + np.get_subname_count(); for (int i = 0; i < total; i++) { - String str; - if (i < np.get_name_count()) + if (i < np.get_name_count()) { str = np.get_name(i); - else + } else { str = np.get_subname(i - np.get_name_count()); + } CharString utf8 = str.utf8(); int pad = 0; - if (utf8.length() % 4) + if (utf8.length() % 4) { pad = 4 - utf8.length() % 4; + } if (buf) { encode_uint32(utf8.length(), buf); @@ -1034,19 +1004,16 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::STRING: { - _encode_string(p_variant, buf, r_len); } break; case Variant::STRING_NAME: { - _encode_string(p_variant, buf, r_len); } break; // math types case Variant::VECTOR2: { - if (buf) { Vector2 v2 = p_variant; encode_float(v2.x, &buf[0]); @@ -1057,7 +1024,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::VECTOR2I: { - if (buf) { Vector2i v2 = p_variant; encode_uint32(v2.x, &buf[0]); @@ -1068,7 +1034,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::RECT2: { - if (buf) { Rect2 r2 = p_variant; encode_float(r2.position.x, &buf[0]); @@ -1080,7 +1045,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::RECT2I: { - if (buf) { Rect2i r2 = p_variant; encode_uint32(r2.position.x, &buf[0]); @@ -1092,7 +1056,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::VECTOR3: { - if (buf) { Vector3 v3 = p_variant; encode_float(v3.x, &buf[0]); @@ -1104,7 +1067,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::VECTOR3I: { - if (buf) { Vector3i v3 = p_variant; encode_uint32(v3.x, &buf[0]); @@ -1116,12 +1078,10 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::TRANSFORM2D: { - if (buf) { Transform2D val = p_variant; for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) { - copymem(&buf[(i * 2 + j) * 4], &val.elements[i][j], sizeof(float)); } } @@ -1131,7 +1091,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::PLANE: { - if (buf) { Plane p = p_variant; encode_float(p.normal.x, &buf[0]); @@ -1144,7 +1103,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::QUAT: { - if (buf) { Quat q = p_variant; encode_float(q.x, &buf[0]); @@ -1157,7 +1115,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::AABB: { - if (buf) { AABB aabb = p_variant; encode_float(aabb.position.x, &buf[0]); @@ -1172,12 +1129,10 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::BASIS: { - if (buf) { Basis val = p_variant; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - copymem(&buf[(i * 3 + j) * 4], &val.elements[i][j], sizeof(float)); } } @@ -1187,12 +1142,10 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::TRANSFORM: { - if (buf) { Transform val = p_variant; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - copymem(&buf[(i * 3 + j) * 4], &val.basis.elements[i][j], sizeof(float)); } } @@ -1208,7 +1161,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo // misc types case Variant::COLOR: { - if (buf) { Color c = p_variant; encode_float(c.r, &buf[0]); @@ -1221,18 +1173,13 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::_RID: { - } break; case Variant::CALLABLE: { - } break; case Variant::SIGNAL: { - } break; case Variant::OBJECT: { - if (p_full_objects) { - Object *obj = p_variant; if (!obj) { if (buf) { @@ -1248,9 +1195,9 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo int pc = 0; for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { - - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) + if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) { continue; + } pc++; } @@ -1262,25 +1209,26 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 4; for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { - - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) + if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) { continue; + } _encode_string(E->get().name, buf, r_len); int len; Error err = encode_variant(obj->get(E->get().name), buf, len, p_full_objects); - if (err) + if (err) { return err; + } ERR_FAIL_COND_V(len % 4, ERR_BUG); r_len += len; - if (buf) + if (buf) { buf += len; + } } } } else { if (buf) { - Object *obj = p_variant.get_validated_object(); ObjectID id; if (obj) { @@ -1295,7 +1243,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::DICTIONARY: { - Dictionary d = p_variant; if (buf) { @@ -1308,7 +1255,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo d.get_key_list(&keys); for (List<Variant>::Element *E = keys.front(); E; E = E->next()) { - /* CharString utf8 = E->->utf8(); @@ -1326,20 +1272,21 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo encode_variant(E->get(), buf, len, p_full_objects); ERR_FAIL_COND_V(len % 4, ERR_BUG); r_len += len; - if (buf) + if (buf) { buf += len; + } Variant *v = d.getptr(E->get()); ERR_FAIL_COND_V(!v, ERR_BUG); encode_variant(*v, buf, len, p_full_objects); ERR_FAIL_COND_V(len % 4, ERR_BUG); r_len += len; - if (buf) + if (buf) { buf += len; + } } } break; case Variant::ARRAY: { - Array v = p_variant; if (buf) { @@ -1350,19 +1297,18 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 4; for (int i = 0; i < v.size(); i++) { - int len; encode_variant(v.get(i), buf, len, p_full_objects); ERR_FAIL_COND_V(len % 4, ERR_BUG); r_len += len; - if (buf) + if (buf) { buf += len; + } } } break; // arrays case Variant::PACKED_BYTE_ARRAY: { - Vector<uint8_t> data = p_variant; int datalen = data.size(); int datasize = sizeof(uint8_t); @@ -1378,13 +1324,13 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 4 + datalen * datasize; while (r_len % 4) { r_len++; - if (buf) + if (buf) { *(buf++) = 0; + } } } break; case Variant::PACKED_INT32_ARRAY: { - Vector<int32_t> data = p_variant; int datalen = data.size(); int datasize = sizeof(int32_t); @@ -1393,15 +1339,15 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo encode_uint32(datalen, buf); buf += 4; const int32_t *r = data.ptr(); - for (int32_t i = 0; i < datalen; i++) + for (int32_t i = 0; i < datalen; i++) { encode_uint32(r[i], &buf[i * datasize]); + } } r_len += 4 + datalen * datasize; } break; case Variant::PACKED_INT64_ARRAY: { - Vector<int64_t> data = p_variant; int datalen = data.size(); int datasize = sizeof(int64_t); @@ -1410,15 +1356,15 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo encode_uint64(datalen, buf); buf += 4; const int64_t *r = data.ptr(); - for (int64_t i = 0; i < datalen; i++) + for (int64_t i = 0; i < datalen; i++) { encode_uint64(r[i], &buf[i * datasize]); + } } r_len += 4 + datalen * datasize; } break; case Variant::PACKED_FLOAT32_ARRAY: { - Vector<float> data = p_variant; int datalen = data.size(); int datasize = sizeof(float); @@ -1427,15 +1373,15 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo encode_uint32(datalen, buf); buf += 4; const float *r = data.ptr(); - for (int i = 0; i < datalen; i++) + for (int i = 0; i < datalen; i++) { encode_float(r[i], &buf[i * datasize]); + } } r_len += 4 + datalen * datasize; } break; case Variant::PACKED_FLOAT64_ARRAY: { - Vector<double> data = p_variant; int datalen = data.size(); int datasize = sizeof(double); @@ -1444,15 +1390,15 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo encode_uint32(datalen, buf); buf += 4; const double *r = data.ptr(); - for (int i = 0; i < datalen; i++) + for (int i = 0; i < datalen; i++) { encode_double(r[i], &buf[i * datasize]); + } } r_len += 4 + datalen * datasize; } break; case Variant::PACKED_STRING_ARRAY: { - Vector<String> data = p_variant; int len = data.size(); @@ -1464,7 +1410,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 4; for (int i = 0; i < len; i++) { - CharString utf8 = data.get(i).utf8(); if (buf) { @@ -1477,14 +1422,14 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 4 + utf8.length() + 1; while (r_len % 4) { r_len++; //pad - if (buf) + if (buf) { *(buf++) = 0; + } } } } break; case Variant::PACKED_VECTOR2_ARRAY: { - Vector<Vector2> data = p_variant; int len = data.size(); @@ -1496,9 +1441,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 4; if (buf) { - for (int i = 0; i < len; i++) { - Vector2 v = data.get(i); encode_float(v.x, &buf[0]); @@ -1511,7 +1454,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::PACKED_VECTOR3_ARRAY: { - Vector<Vector3> data = p_variant; int len = data.size(); @@ -1523,9 +1465,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 4; if (buf) { - for (int i = 0; i < len; i++) { - Vector3 v = data.get(i); encode_float(v.x, &buf[0]); @@ -1539,7 +1479,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::PACKED_COLOR_ARRAY: { - Vector<Color> data = p_variant; int len = data.size(); @@ -1551,9 +1490,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 4; if (buf) { - for (int i = 0; i < len; i++) { - Color c = data.get(i); encode_float(c.r, &buf[0]); |