From 68e708cd25cb08bf4bbac857def1b61232bdf5ad Mon Sep 17 00:00:00 2001 From: sanikoyes Date: Wed, 10 Apr 2013 16:37:04 +0800 Subject: Add Matrix32/Vector2Array support for marshal library --- core/io/marshalls.cpp | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) (limited to 'core/io') 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 @@ -140,6 +140,23 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int * if (r_len) (*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: { @@ -648,6 +665,45 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int * r_variant=strings; + } 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 varray; + + if (r_len) { + (*r_len)+=4; + } + + if (count) { + varray.resize(count); + DVector::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: { @@ -887,6 +943,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: { @@ -1249,6 +1321,34 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) { } } + } break; + case Variant::VECTOR2_ARRAY: { + + DVector 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