summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorreduz <reduzio@gmail.com>2014-04-10 09:18:27 -0300
committerreduz <reduzio@gmail.com>2014-04-10 09:18:27 -0300
commita5f556c9ff7c80f5a30559cd22223e8a613d0a60 (patch)
tree5f1142e06b292a64bb76b9e51de10487d2d39bde
parentc74d918d570e2e7ac01643be892220982a4a4921 (diff)
parent68e708cd25cb08bf4bbac857def1b61232bdf5ad (diff)
Merge pull request #274 from sanikoyes/hotifx-Marshal-Matrix32-Support
Add Matrix32/Vector2Array support for marshal library
-rw-r--r--core/io/marshalls.cpp100
1 files changed, 100 insertions, 0 deletions
diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp
index df951c759a..c6c15af5e0 100644
--- a/core/io/marshalls.cpp
+++ b/core/io/marshalls.cpp
@@ -141,6 +141,23 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
(*r_len)+=4*3;
} break;
+ case Variant::MATRIX32: {
+
+ ERR_FAIL_COND_V(len<(int)4*6,ERR_INVALID_DATA);
+ Matrix32 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)
+ (*r_len)+=4*6;
+
+ } break;
case Variant::PLANE: {
ERR_FAIL_COND_V(len<(int)4*4,ERR_INVALID_DATA);
@@ -649,6 +666,45 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
} break;
+ case Variant::VECTOR2_ARRAY: {
+
+ ERR_FAIL_COND_V(len<4,ERR_INVALID_DATA);
+ uint32_t count = decode_uint32(buf);
+ ERR_FAIL_COND_V(count<0,ERR_INVALID_DATA);
+ buf+=4;
+ len-=4;
+
+ ERR_FAIL_COND_V((int)count*4*2>len,ERR_INVALID_DATA);
+ DVector<Vector2> varray;
+
+ if (r_len) {
+ (*r_len)+=4;
+ }
+
+ if (count) {
+ varray.resize(count);
+ DVector<Vector2>::Write w = varray.write();
+ const float *r = (const float*)buf;
+
+ for(int i=0;i<(int)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)
+ (*r_len)+=adv;
+ len-=adv;
+ buf+=adv;
+
+ }
+
+ r_variant=varray;
+
+ } break;
case Variant::VECTOR3_ARRAY: {
ERR_FAIL_COND_V(len<4,ERR_INVALID_DATA);
@@ -888,6 +944,22 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
r_len+=3*4;
} break;
+ case Variant::MATRIX32: {
+
+ if (buf) {
+ Matrix32 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));
+ }
+ }
+ }
+
+
+ r_len+=6*4;
+
+ } break;
case Variant::PLANE: {
if (buf) {
@@ -1250,6 +1322,34 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
}
} break;
+ case Variant::VECTOR2_ARRAY: {
+
+ DVector<Vector2> data = p_variant;
+ int len=data.size();
+
+ if (buf) {
+ encode_uint32(len,buf);
+ buf+=4;
+ }
+
+ r_len+=4;
+
+ if (buf) {
+
+ for(int i=0;i<len;i++) {
+
+ Vector2 v = data.get(i);
+
+ encode_float(v.x,&buf[0]);
+ encode_float(v.y,&buf[4]);
+ buf+=4*2;
+
+ }
+ }
+
+ r_len+=4*2*len;
+
+ } break;
case Variant::VECTOR3_ARRAY: {
DVector<Vector3> data = p_variant;