diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/array.cpp | 18 | ||||
| -rw-r--r-- | core/array.h | 6 | ||||
| -rw-r--r-- | core/io/aes256.cpp | 170 | ||||
| -rw-r--r-- | core/io/resource_format_binary.cpp | 2 | ||||
| -rw-r--r-- | core/object.cpp | 4 | ||||
| -rw-r--r-- | core/os/os.h | 3 | ||||
| -rw-r--r-- | core/ustring.cpp | 22 | ||||
| -rw-r--r-- | core/variant_call.cpp | 6 | ||||
| -rw-r--r-- | core/variant_op.cpp | 2 | ||||
| -rw-r--r-- | core/variant_parser.cpp | 13 | ||||
| -rw-r--r-- | core/vector.h | 38 |
11 files changed, 183 insertions, 101 deletions
diff --git a/core/array.cpp b/core/array.cpp index ab9f19d6a0..41af460d83 100644 --- a/core/array.cpp +++ b/core/array.cpp @@ -222,6 +222,24 @@ void Array::invert(){ } +void Array::push_front(const Variant& p_value) { + + _p->array.insert(0,p_value); +} + +void Array::pop_back(){ + + if (!_p->array.empty()) + _p->array.resize( _p->array.size() -1 ); + +} +void Array::pop_front(){ + + if (!_p->array.empty()) + _p->array.remove(0); + +} + Array::Array(const Array& p_from) { diff --git a/core/array.h b/core/array.h index 904309b257..c29b4355ca 100644 --- a/core/array.h +++ b/core/array.h @@ -53,7 +53,7 @@ public: bool empty() const; void clear(); - bool is_shared() const; + bool is_shared() const; bool operator==(const Array& p_array) const; @@ -75,6 +75,10 @@ public: void erase(const Variant& p_value); + void push_front(const Variant& p_value); + void pop_back(); + void pop_front(); + Array(const Array& p_from); Array(bool p_shared=false); ~Array(); diff --git a/core/io/aes256.cpp b/core/io/aes256.cpp index e7f465dcc6..cfdac0214d 100644 --- a/core/io/aes256.cpp +++ b/core/io/aes256.cpp @@ -1,8 +1,8 @@ -/* +/* * Byte-oriented AES-256 implementation. -* All lookup tables replaced with 'on the fly' calculations. +* All lookup tables replaced with 'on the fly' calculations. * -* Copyright (c) 2007-2009 Ilya O. Levin, http://www.literatecode.com +* Copyright (c) 2007-2011 Ilya O. Levin, http://www.literatecode.com * Other contributors: Hal Finney * * Permission to use, copy, modify, and distribute this software for any @@ -19,13 +19,33 @@ */ #include "aes256.h" -#define F(x) (((x)<<1) ^ ((((x)>>7) & 1) * 0x1b)) #define FD(x) (((x) >> 1) ^ (((x) & 1) ? 0x8d : 0)) -// #define BACK_TO_TABLES +#define BACK_TO_TABLES + +static uint8_t rj_xtime(uint8_t); +static void aes_subBytes(uint8_t *); +static void aes_subBytes_inv(uint8_t *); +static void aes_addRoundKey(uint8_t *, uint8_t *); +static void aes_addRoundKey_cpy(uint8_t *, uint8_t *, uint8_t *); +static void aes_shiftRows(uint8_t *); +static void aes_shiftRows_inv(uint8_t *); +static void aes_mixColumns(uint8_t *); +static void aes_mixColumns_inv(uint8_t *); +static void aes_expandEncKey(uint8_t *, uint8_t *); +static void aes_expandDecKey(uint8_t *, uint8_t *); +#ifndef BACK_TO_TABLES +static uint8_t gf_alog(uint8_t); +static uint8_t gf_log(uint8_t); +static uint8_t gf_mulinv(uint8_t); +static uint8_t rj_sbox(uint8_t); +static uint8_t rj_sbox_inv(uint8_t); +#endif + #ifdef BACK_TO_TABLES -const uint8_t sbox[256] = { +static const uint8_t sbox[256] = +{ 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, @@ -59,7 +79,8 @@ const uint8_t sbox[256] = { 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16 }; -const uint8_t sboxinv[256] = { +static const uint8_t sboxinv[256] = +{ 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, @@ -100,55 +121,62 @@ const uint8_t sboxinv[256] = { #else /* tableless subroutines */ /* -------------------------------------------------------------------------- */ -uint8_t gf_alog(uint8_t x) // calculate anti-logarithm gen 3 +static uint8_t gf_alog(uint8_t x) // calculate anti-logarithm gen 3 { - uint8_t atb = 1, z; + uint8_t y = 1, i; - while (x--) {z = atb; atb <<= 1; if (z & 0x80) atb^= 0x1b; atb ^= z;} + for (i = 0; i < x; i++) y ^= rj_xtime(y); - return atb; + return y; } /* gf_alog */ /* -------------------------------------------------------------------------- */ -uint8_t gf_log(uint8_t x) // calculate logarithm gen 3 +static uint8_t gf_log(uint8_t x) // calculate logarithm gen 3 { - uint8_t atb = 1, i = 0, z; + uint8_t y, i = 0; - do { - if (atb == x) break; - z = atb; atb <<= 1; if (z & 0x80) atb^= 0x1b; atb ^= z; - } while (++i > 0); + if (x) + for (i = 1, y = 1; i > 0; i++ ) + { + y ^= rj_xtime(y); + if (y == x) break; + } return i; } /* gf_log */ /* -------------------------------------------------------------------------- */ -uint8_t gf_mulinv(uint8_t x) // calculate multiplicative inverse +static uint8_t gf_mulinv(uint8_t x) // calculate multiplicative inverse { return (x) ? gf_alog(255 - gf_log(x)) : 0; } /* gf_mulinv */ /* -------------------------------------------------------------------------- */ -uint8_t rj_sbox(uint8_t x) +static uint8_t rj_sbox(uint8_t x) { uint8_t y, sb; sb = y = gf_mulinv(x); - y = (y<<1)|(y>>7); sb ^= y; y = (y<<1)|(y>>7); sb ^= y; - y = (y<<1)|(y>>7); sb ^= y; y = (y<<1)|(y>>7); sb ^= y; + y = (uint8_t)(y << 1) | (y >> 7), sb ^= y; + y = (uint8_t)(y << 1) | (y >> 7), sb ^= y; + y = (uint8_t)(y << 1) | (y >> 7), sb ^= y; + y = (uint8_t)(y << 1) | (y >> 7), sb ^= y; return (sb ^ 0x63); } /* rj_sbox */ /* -------------------------------------------------------------------------- */ -uint8_t rj_sbox_inv(uint8_t x) +static uint8_t rj_sbox_inv(uint8_t x) { uint8_t y, sb; y = x ^ 0x63; - sb = y = (y<<1)|(y>>7); - y = (y<<2)|(y>>6); sb ^= y; y = (y<<3)|(y>>5); sb ^= y; + sb = y = (uint8_t)(y << 1) | (y >> 7); + y = (uint8_t)(y << 2) | (y >> 6); + sb ^= y; + y = (uint8_t)(y << 3) | (y >> 5); + sb ^= y; return gf_mulinv(sb); } /* rj_sbox_inv */ @@ -156,13 +184,14 @@ uint8_t rj_sbox_inv(uint8_t x) #endif /* -------------------------------------------------------------------------- */ -uint8_t rj_xtime(uint8_t x) +static uint8_t rj_xtime(uint8_t x) { - return (x & 0x80) ? ((x << 1) ^ 0x1b) : (x << 1); + uint8_t y = (uint8_t)(x << 1); + return (x & 0x80) ? (y ^ 0x1b) : y; } /* rj_xtime */ /* -------------------------------------------------------------------------- */ -void aes_subBytes(uint8_t *buf) +static void aes_subBytes(uint8_t *buf) { register uint8_t i = 16; @@ -170,7 +199,7 @@ void aes_subBytes(uint8_t *buf) } /* aes_subBytes */ /* -------------------------------------------------------------------------- */ -void aes_subBytes_inv(uint8_t *buf) +static void aes_subBytes_inv(uint8_t *buf) { register uint8_t i = 16; @@ -178,7 +207,7 @@ void aes_subBytes_inv(uint8_t *buf) } /* aes_subBytes_inv */ /* -------------------------------------------------------------------------- */ -void aes_addRoundKey(uint8_t *buf, uint8_t *key) +static void aes_addRoundKey(uint8_t *buf, uint8_t *key) { register uint8_t i = 16; @@ -186,49 +215,54 @@ void aes_addRoundKey(uint8_t *buf, uint8_t *key) } /* aes_addRoundKey */ /* -------------------------------------------------------------------------- */ -void aes_addRoundKey_cpy(uint8_t *buf, uint8_t *key, uint8_t *cpk) +static void aes_addRoundKey_cpy(uint8_t *buf, uint8_t *key, uint8_t *cpk) { register uint8_t i = 16; - while (i--) buf[i] ^= (cpk[i] = key[i]), cpk[16+i] = key[16 + i]; + while (i--) buf[i] ^= (cpk[i] = key[i]), cpk[16 + i] = key[16 + i]; } /* aes_addRoundKey_cpy */ /* -------------------------------------------------------------------------- */ -void aes_shiftRows(uint8_t *buf) +static void aes_shiftRows(uint8_t *buf) { register uint8_t i, j; /* to make it potentially parallelable :) */ - i = buf[1]; buf[1] = buf[5]; buf[5] = buf[9]; buf[9] = buf[13]; buf[13] = i; - i = buf[10]; buf[10] = buf[2]; buf[2] = i; - j = buf[3]; buf[3] = buf[15]; buf[15] = buf[11]; buf[11] = buf[7]; buf[7] = j; - j = buf[14]; buf[14] = buf[6]; buf[6] = j; + i = buf[1], buf[1] = buf[5], buf[5] = buf[9], buf[9] = buf[13], buf[13] = i; + i = buf[10], buf[10] = buf[2], buf[2] = i; + j = buf[3], buf[3] = buf[15], buf[15] = buf[11], buf[11] = buf[7], buf[7] = j; + j = buf[14], buf[14] = buf[6], buf[6] = j; } /* aes_shiftRows */ /* -------------------------------------------------------------------------- */ -void aes_shiftRows_inv(uint8_t *buf) +static void aes_shiftRows_inv(uint8_t *buf) { register uint8_t i, j; /* same as above :) */ - i = buf[1]; buf[1] = buf[13]; buf[13] = buf[9]; buf[9] = buf[5]; buf[5] = i; - i = buf[2]; buf[2] = buf[10]; buf[10] = i; - j = buf[3]; buf[3] = buf[7]; buf[7] = buf[11]; buf[11] = buf[15]; buf[15] = j; - j = buf[6]; buf[6] = buf[14]; buf[14] = j; + i = buf[1], buf[1] = buf[13], buf[13] = buf[9], buf[9] = buf[5], buf[5] = i; + i = buf[2], buf[2] = buf[10], buf[10] = i; + j = buf[3], buf[3] = buf[7], buf[7] = buf[11], buf[11] = buf[15], buf[15] = j; + j = buf[6], buf[6] = buf[14], buf[14] = j; } /* aes_shiftRows_inv */ /* -------------------------------------------------------------------------- */ -void aes_mixColumns(uint8_t *buf) +static void aes_mixColumns(uint8_t *buf) { register uint8_t i, a, b, c, d, e; for (i = 0; i < 16; i += 4) { - a = buf[i]; b = buf[i + 1]; c = buf[i + 2]; d = buf[i + 3]; + a = buf[i]; + b = buf[i + 1]; + c = buf[i + 2]; + d = buf[i + 3]; e = a ^ b ^ c ^ d; - buf[i] ^= e ^ rj_xtime(a^b); buf[i+1] ^= e ^ rj_xtime(b^c); - buf[i+2] ^= e ^ rj_xtime(c^d); buf[i+3] ^= e ^ rj_xtime(d^a); + buf[i] ^= e ^ rj_xtime(a ^ b); + buf[i + 1] ^= e ^ rj_xtime(b ^ c); + buf[i + 2] ^= e ^ rj_xtime(c ^ d); + buf[i + 3] ^= e ^ rj_xtime(d ^ a); } } /* aes_mixColumns */ @@ -239,17 +273,23 @@ void aes_mixColumns_inv(uint8_t *buf) for (i = 0; i < 16; i += 4) { - a = buf[i]; b = buf[i + 1]; c = buf[i + 2]; d = buf[i + 3]; + a = buf[i]; + b = buf[i + 1]; + c = buf[i + 2]; + d = buf[i + 3]; e = a ^ b ^ c ^ d; z = rj_xtime(e); - x = e ^ rj_xtime(rj_xtime(z^a^c)); y = e ^ rj_xtime(rj_xtime(z^b^d)); - buf[i] ^= x ^ rj_xtime(a^b); buf[i+1] ^= y ^ rj_xtime(b^c); - buf[i+2] ^= x ^ rj_xtime(c^d); buf[i+3] ^= y ^ rj_xtime(d^a); + x = e ^ rj_xtime(rj_xtime(z ^ a ^ c)); + y = e ^ rj_xtime(rj_xtime(z ^ b ^ d)); + buf[i] ^= x ^ rj_xtime(a ^ b); + buf[i + 1] ^= y ^ rj_xtime(b ^ c); + buf[i + 2] ^= x ^ rj_xtime(c ^ d); + buf[i + 3] ^= y ^ rj_xtime(d ^ a); } } /* aes_mixColumns_inv */ /* -------------------------------------------------------------------------- */ -void aes_expandEncKey(uint8_t *k, uint8_t *rc) +static void aes_expandEncKey(uint8_t *k, uint8_t *rc) { register uint8_t i; @@ -257,35 +297,35 @@ void aes_expandEncKey(uint8_t *k, uint8_t *rc) k[1] ^= rj_sbox(k[30]); k[2] ^= rj_sbox(k[31]); k[3] ^= rj_sbox(k[28]); - *rc = F( *rc); + *rc = rj_xtime( *rc); - for(i = 4; i < 16; i += 4) k[i] ^= k[i-4], k[i+1] ^= k[i-3], - k[i+2] ^= k[i-2], k[i+3] ^= k[i-1]; + for(i = 4; i < 16; i += 4) k[i] ^= k[i - 4], k[i + 1] ^= k[i - 3], + k[i + 2] ^= k[i - 2], k[i + 3] ^= k[i - 1]; k[16] ^= rj_sbox(k[12]); k[17] ^= rj_sbox(k[13]); k[18] ^= rj_sbox(k[14]); k[19] ^= rj_sbox(k[15]); - for(i = 20; i < 32; i += 4) k[i] ^= k[i-4], k[i+1] ^= k[i-3], - k[i+2] ^= k[i-2], k[i+3] ^= k[i-1]; + for(i = 20; i < 32; i += 4) k[i] ^= k[i - 4], k[i + 1] ^= k[i - 3], + k[i + 2] ^= k[i - 2], k[i + 3] ^= k[i - 1]; } /* aes_expandEncKey */ /* -------------------------------------------------------------------------- */ -void aes_expandDecKey(uint8_t *k, uint8_t *rc) +void aes_expandDecKey(uint8_t *k, uint8_t *rc) { uint8_t i; - for(i = 28; i > 16; i -= 4) k[i+0] ^= k[i-4], k[i+1] ^= k[i-3], - k[i+2] ^= k[i-2], k[i+3] ^= k[i-1]; + for(i = 28; i > 16; i -= 4) k[i + 0] ^= k[i - 4], k[i + 1] ^= k[i - 3], + k[i + 2] ^= k[i - 2], k[i + 3] ^= k[i - 1]; k[16] ^= rj_sbox(k[12]); k[17] ^= rj_sbox(k[13]); k[18] ^= rj_sbox(k[14]); k[19] ^= rj_sbox(k[15]); - for(i = 12; i > 0; i -= 4) k[i+0] ^= k[i-4], k[i+1] ^= k[i-3], - k[i+2] ^= k[i-2], k[i+3] ^= k[i-1]; + for(i = 12; i > 0; i -= 4) k[i + 0] ^= k[i - 4], k[i + 1] ^= k[i - 3], + k[i + 2] ^= k[i - 2], k[i + 3] ^= k[i - 1]; *rc = FD(*rc); k[0] ^= rj_sbox(k[29]) ^ (*rc); @@ -302,7 +342,7 @@ void aes256_init(aes256_context *ctx, uint8_t *k) register uint8_t i; for (i = 0; i < sizeof(ctx->key); i++) ctx->enckey[i] = ctx->deckey[i] = k[i]; - for (i = 8;--i;) aes_expandEncKey(ctx->deckey, &rcon); + for (i = 8; --i;) aes_expandEncKey(ctx->deckey, &rcon); } /* aes256_init */ /* -------------------------------------------------------------------------- */ @@ -310,7 +350,7 @@ void aes256_done(aes256_context *ctx) { register uint8_t i; - for (i = 0; i < sizeof(ctx->key); i++) + for (i = 0; i < sizeof(ctx->key); i++) ctx->key[i] = ctx->enckey[i] = ctx->deckey[i] = 0; } /* aes256_done */ @@ -330,7 +370,7 @@ void aes256_encrypt_ecb(aes256_context *ctx, uint8_t *buf) } aes_subBytes(buf); aes_shiftRows(buf); - aes_expandEncKey(ctx->key, &rcon); + aes_expandEncKey(ctx->key, &rcon); aes_addRoundKey(buf, ctx->key); } /* aes256_encrypt */ @@ -345,7 +385,7 @@ void aes256_decrypt_ecb(aes256_context *ctx, uint8_t *buf) for (i = 14, rcon = 0x80; --i;) { - if( ( i & 1 ) ) + if( ( i & 1 ) ) { aes_expandDecKey(ctx->key, &rcon); aes_addRoundKey(buf, &ctx->key[16]); @@ -355,5 +395,5 @@ void aes256_decrypt_ecb(aes256_context *ctx, uint8_t *buf) aes_shiftRows_inv(buf); aes_subBytes_inv(buf); } - aes_addRoundKey( buf, ctx->key); + aes_addRoundKey( buf, ctx->key); } /* aes256_decrypt */ diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index 4cd3cd595f..9a3a191b3b 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -853,6 +853,8 @@ String ResourceInteractiveLoaderBinary::get_unicode_string() { if (len>str_buf.size()) { str_buf.resize(len); } + if (len==0) + return String(); f->get_buffer((uint8_t*)&str_buf[0],len); String s; s.parse_utf8(&str_buf[0]); diff --git a/core/object.cpp b/core/object.cpp index 96f0c86832..f6ba76a0b5 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -1405,6 +1405,10 @@ bool Object::is_connected(const StringName& p_signal, Object *p_to_object, const bool signal_is_valid = ObjectTypeDB::has_signal(get_type_name(),p_signal); if (signal_is_valid) return false; + + if (!script.is_null() && Ref<Script>(script)->has_script_signal(p_signal)) + return false; + ERR_EXPLAIN("Nonexistent signal: "+p_signal); ERR_FAIL_COND_V(!s,false); } diff --git a/core/os/os.h b/core/os/os.h index e5338b4a02..ab1a07276c 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -75,7 +75,7 @@ public: bool fullscreen; bool resizable; float get_aspect() const { return (float)width/(float)height; } - VideoMode(int p_width=640,int p_height=480,bool p_fullscreen=false, bool p_resizable = true) {width=p_width; height=p_height; fullscreen=p_fullscreen; resizable = p_resizable; } + VideoMode(int p_width=1280,int p_height=720,bool p_fullscreen=false, bool p_resizable = true) {width=p_width; height=p_height; fullscreen=p_fullscreen; resizable = p_resizable; } }; protected: friend class Main; @@ -184,6 +184,7 @@ public: virtual void set_low_processor_usage_mode(bool p_enabled); virtual bool is_in_low_processor_usage_mode() const; + virtual String get_installed_templates_path() const { return ""; }; virtual String get_executable_path() const; virtual Error execute(const String& p_path, const List<String>& p_arguments,bool p_blocking,ProcessID *r_child_id=NULL,String* r_pipe=NULL,int *r_exitcode=NULL)=0; virtual Error kill(const ProcessID& p_pid)=0; diff --git a/core/ustring.cpp b/core/ustring.cpp index f3c89a7908..bf2494e9b5 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -897,17 +897,8 @@ String String::num(double p_num,int p_decimals) { } char buf[256]; -#if defined(__GNUC__) -#ifdef MINGW_ENABLED - //snprintf is inexplicably broken in mingw - //sprintf(buf,fmt,p_num); - _snprintf(buf,256,fmt,p_num); -#else +#if defined(__GNUC__) || defined(_MSC_VER) snprintf(buf,256,fmt,p_num); -#endif - -#elif defined(_MSC_VER) - _snprintf(buf,256,fmt,p_num); #else sprintf(buf,fmt,p_num); #endif @@ -1178,10 +1169,7 @@ String String::num_scientific(double p_num) { char buf[256]; -#if defined(_MSC_VER) || defined(MINGW_ENABLED) - - _snprintf(buf,256,"%lg",p_num); -#elif defined(__GNUC__) +#if defined(__GNUC__) || defined(_MSC_VER) snprintf(buf,256,"%lg",p_num); #else sprintf(buf,"%.16lg",p_num); @@ -3096,7 +3084,11 @@ String String::http_escape() const { res += ord; } else { char h_Val[3]; - snprintf(h_Val, 3, "%.2X", ord); +#if defined(__GNUC__) || defined(_MSC_VER) + snprintf(h_Val, 3, "%.2X", ord); +#else + sprintf(h_Val, "%.2X", ord); +#endif res += "%"; res += h_Val; } diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 2d10cf4d44..2ac876c8f4 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -450,6 +450,9 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var VCALL_LOCALMEM0(Array,clear); VCALL_LOCALMEM0R(Array,hash); VCALL_LOCALMEM1(Array,push_back); + VCALL_LOCALMEM1(Array,push_front); + VCALL_LOCALMEM0(Array,pop_back); + VCALL_LOCALMEM0(Array,pop_front); VCALL_LOCALMEM1(Array,append); VCALL_LOCALMEM1(Array,resize); VCALL_LOCALMEM2(Array,insert); @@ -1426,12 +1429,15 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl ADDFUNC0(ARRAY,NIL,Array,clear,varray()); ADDFUNC0(ARRAY,INT,Array,hash,varray()); ADDFUNC1(ARRAY,NIL,Array,push_back,NIL,"value",varray()); + ADDFUNC1(ARRAY,NIL,Array,push_front,NIL,"value",varray()); ADDFUNC1(ARRAY,NIL,Array,append,NIL,"value",varray()); ADDFUNC1(ARRAY,NIL,Array,resize,INT,"pos",varray()); ADDFUNC2(ARRAY,NIL,Array,insert,INT,"pos",NIL,"value",varray()); ADDFUNC1(ARRAY,NIL,Array,remove,INT,"pos",varray()); ADDFUNC1(ARRAY,NIL,Array,erase,NIL,"value",varray()); ADDFUNC1(ARRAY,INT,Array,find,NIL,"value",varray()); + ADDFUNC0(ARRAY,NIL,Array,pop_back,varray()); + ADDFUNC0(ARRAY,NIL,Array,pop_front,varray()); ADDFUNC0(ARRAY,NIL,Array,sort,varray()); ADDFUNC2(ARRAY,NIL,Array,sort_custom,OBJECT,"obj",STRING,"func",varray()); ADDFUNC0(ARRAY,NIL,Array,invert,varray()); diff --git a/core/variant_op.cpp b/core/variant_op.cpp index 1bcfa7d2ae..e33b79e63c 100644 --- a/core/variant_op.cpp +++ b/core/variant_op.cpp @@ -2635,7 +2635,7 @@ bool Variant::in(const Variant& p_index, bool *r_valid) const { if (l) { for(int i=0;i<l;i++) { - if ((*arr)[i]==p_index) + if (evaluate(OP_EQUAL,(*arr)[i],p_index)) return true; } diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp index fed8c28740..239b129388 100644 --- a/core/variant_parser.cpp +++ b/core/variant_parser.cpp @@ -460,6 +460,19 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in value=Vector2(args[0],args[1]); return OK; + } else if (id=="Rect2"){ + + Vector<float> args; + Error err = _parse_construct<float>(p_stream,args,line,r_err_str); + if (err) + return err; + + if (args.size()!=4) { + r_err_str="Expected 4 arguments for constructor"; + } + + value=Rect2(args[0],args[1],args[2],args[3]); + return OK; } else if (id=="Vector3"){ Vector<float> args; diff --git a/core/vector.h b/core/vector.h index d103400622..78dff5eadb 100644 --- a/core/vector.h +++ b/core/vector.h @@ -42,7 +42,7 @@ template<class T> class Vector { - mutable void* _ptr; + mutable T* _ptr; // internal helpers @@ -51,21 +51,21 @@ class Vector { if (!_ptr) return NULL; - return reinterpret_cast<SafeRefCount*>(_ptr); + return reinterpret_cast<SafeRefCount*>((uint8_t*)_ptr-sizeof(int)-sizeof(SafeRefCount)); } _FORCE_INLINE_ int* _get_size() const { if (!_ptr) return NULL; - return reinterpret_cast<int*>(((uint8_t*)(_ptr))+sizeof(SafeRefCount)); + return reinterpret_cast<int*>((uint8_t*)_ptr-sizeof(int)); } _FORCE_INLINE_ T* _get_data() const { if (!_ptr) return NULL; - return reinterpret_cast<T*>(((uint8_t*)(_ptr))+sizeof(SafeRefCount)+sizeof(int)); + return reinterpret_cast<T*>(_ptr); } @@ -88,11 +88,11 @@ public: _FORCE_INLINE_ void clear() { resize(0); } _FORCE_INLINE_ int size() const { - - if (!_ptr) - return 0; + int* size = _get_size(); + if (size) + return *size; else - return *reinterpret_cast<int*>(((uint8_t*)(_ptr))+sizeof(SafeRefCount)); + return 0; } _FORCE_INLINE_ bool empty() const { return _ptr == 0; } Error resize(int p_size); @@ -174,7 +174,7 @@ void Vector<T>::_unref(void *p_data) { if (!p_data) return; - SafeRefCount *src = reinterpret_cast<SafeRefCount*>(p_data); + SafeRefCount *src = reinterpret_cast<SafeRefCount*>((uint8_t*)p_data-sizeof(int)-sizeof(SafeRefCount)); if (!src->unref()) return; // still in use @@ -189,7 +189,7 @@ void Vector<T>::_unref(void *p_data) { } // free mem - memfree(p_data); + memfree((uint8_t*)p_data-sizeof(int)-sizeof(SafeRefCount)); } @@ -201,7 +201,8 @@ void Vector<T>::_copy_on_write() { if (_get_refcount()->get() > 1 ) { /* in use by more than me */ - SafeRefCount *src_new=(SafeRefCount *)memalloc(_get_alloc_size(*_get_size())); + void* mem_new = memalloc(_get_alloc_size(*_get_size())); + SafeRefCount *src_new=(SafeRefCount *)mem_new; src_new->init(); int * _size = (int*)(src_new+1); *_size=*_get_size(); @@ -215,7 +216,7 @@ void Vector<T>::_copy_on_write() { } _unref(_ptr); - _ptr=src_new; + _ptr=_data; } } @@ -260,16 +261,17 @@ Error Vector<T>::resize(int p_size) { if (size()==0) { // alloc from scratch - _ptr = (T*)memalloc(_get_alloc_size(p_size)); - ERR_FAIL_COND_V( !_ptr ,ERR_OUT_OF_MEMORY); + void* ptr=memalloc(_get_alloc_size(p_size)); + ERR_FAIL_COND_V( !ptr ,ERR_OUT_OF_MEMORY); + _ptr=(T*)((uint8_t*)ptr+sizeof(int)+sizeof(SafeRefCount)); _get_refcount()->init(); // init refcount *_get_size()=0; // init size (currently, none) } else { - void *_ptrnew = (T*)memrealloc(_ptr,_get_alloc_size(p_size)); + void *_ptrnew = (T*)memrealloc((uint8_t*)_ptr-sizeof(int)-sizeof(SafeRefCount),_get_alloc_size(p_size)); ERR_FAIL_COND_V( !_ptrnew ,ERR_OUT_OF_MEMORY); - _ptr=_ptrnew; + _ptr=(T*)((uint8_t*)_ptrnew+sizeof(int)+sizeof(SafeRefCount)); } // construct the newly created elements @@ -291,10 +293,10 @@ Error Vector<T>::resize(int p_size) { t->~T(); } - void *_ptrnew = (T*)memrealloc(_ptr,_get_alloc_size(p_size)); + void *_ptrnew = (T*)memrealloc((uint8_t*)_ptr-sizeof(int)-sizeof(SafeRefCount),_get_alloc_size(p_size)); ERR_FAIL_COND_V( !_ptrnew ,ERR_OUT_OF_MEMORY); - _ptr=_ptrnew; + _ptr=(T*)((uint8_t*)_ptrnew+sizeof(int)+sizeof(SafeRefCount)); *_get_size()=p_size; |