aboutsummaryrefslogtreecommitdiff
path: root/core/io
diff options
context:
space:
mode:
Diffstat (limited to 'core/io')
-rw-r--r--core/io/file_access_buffered.cpp4
-rw-r--r--core/io/file_access_buffered_fa.h2
-rw-r--r--core/io/http_client.cpp6
-rw-r--r--core/io/http_client.h2
-rw-r--r--core/io/json.cpp19
-rw-r--r--core/io/json.h4
-rw-r--r--core/io/marshalls.cpp168
-rw-r--r--core/io/packet_peer.cpp14
-rw-r--r--core/io/packet_peer.h8
-rw-r--r--core/io/resource_format_binary.cpp128
-rw-r--r--core/io/resource_format_xml.cpp2882
-rw-r--r--core/io/resource_format_xml.h170
-rw-r--r--core/io/stream_peer.cpp32
-rw-r--r--core/io/stream_peer.h10
-rw-r--r--core/io/tcp_server.cpp4
-rw-r--r--core/io/tcp_server.h2
16 files changed, 245 insertions, 3210 deletions
diff --git a/core/io/file_access_buffered.cpp b/core/io/file_access_buffered.cpp
index 347edc740..71518de38 100644
--- a/core/io/file_access_buffered.cpp
+++ b/core/io/file_access_buffered.cpp
@@ -117,7 +117,7 @@ int FileAccessBuffered::get_buffer(uint8_t *p_dest,int p_elements) const {
int size = (cache.buffer.size() - (file.offset - cache.offset));
size = size - (size % 4);
- //DVector<uint8_t>::Read read = cache.buffer.read();
+ //PoolVector<uint8_t>::Read read = cache.buffer.read();
//memcpy(p_dest, read.ptr() + (file.offset - cache.offset), size);
memcpy(p_dest, cache.buffer.ptr() + (file.offset - cache.offset), size);
p_dest += size;
@@ -152,7 +152,7 @@ int FileAccessBuffered::get_buffer(uint8_t *p_dest,int p_elements) const {
};
int r = MIN(left, to_read);
- //DVector<uint8_t>::Read read = cache.buffer.read();
+ //PoolVector<uint8_t>::Read read = cache.buffer.read();
//memcpy(p_dest+total_read, &read.ptr()[file.offset - cache.offset], r);
memcpy(p_dest+total_read, cache.buffer.ptr() + (file.offset - cache.offset), r);
diff --git a/core/io/file_access_buffered_fa.h b/core/io/file_access_buffered_fa.h
index 8a15584b1..884d40a26 100644
--- a/core/io/file_access_buffered_fa.h
+++ b/core/io/file_access_buffered_fa.h
@@ -53,7 +53,7 @@ class FileAccessBufferedFA : public FileAccessBuffered {
cache.buffer.resize(p_size);
// on dvector
- //DVector<uint8_t>::Write write = cache.buffer.write();
+ //PoolVector<uint8_t>::Write write = cache.buffer.write();
//f.get_buffer(write.ptr(), p_size);
// on vector
diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp
index 4051ae302..b556d4610 100644
--- a/core/io/http_client.cpp
+++ b/core/io/http_client.cpp
@@ -87,7 +87,7 @@ Ref<StreamPeer> HTTPClient::get_connection() const {
return connection;
}
-Error HTTPClient::request_raw( Method p_method, const String& p_url, const Vector<String>& p_headers,const DVector<uint8_t>& p_body) {
+Error HTTPClient::request_raw( Method p_method, const String& p_url, const Vector<String>& p_headers,const PoolVector<uint8_t>& p_body) {
ERR_FAIL_INDEX_V(p_method,METHOD_MAX,ERR_INVALID_PARAMETER);
ERR_FAIL_COND_V(status!=STATUS_CONNECTED,ERR_INVALID_PARAMETER);
@@ -120,7 +120,7 @@ Error HTTPClient::request_raw( Method p_method, const String& p_url, const Vecto
request+="\r\n";
CharString cs=request.utf8();
- DVector<uint8_t> data;
+ PoolVector<uint8_t> data;
//Maybe this goes faster somehow?
for(int i=0;i<cs.length();i++) {
@@ -128,7 +128,7 @@ Error HTTPClient::request_raw( Method p_method, const String& p_url, const Vecto
}
data.append_array( p_body );
- DVector<uint8_t>::Read r = data.read();
+ PoolVector<uint8_t>::Read r = data.read();
Error err = connection->put_data(&r[0], data.size());
if (err) {
diff --git a/core/io/http_client.h b/core/io/http_client.h
index 2e7888230..231475775 100644
--- a/core/io/http_client.h
+++ b/core/io/http_client.h
@@ -172,7 +172,7 @@ public:
void set_connection(const Ref<StreamPeer>& p_connection);
Ref<StreamPeer> get_connection() const;
- Error request_raw( Method p_method, const String& p_url, const Vector<String>& p_headers,const DVector<uint8_t>& p_body);
+ Error request_raw( Method p_method, const String& p_url, const Vector<String>& p_headers,const PoolVector<uint8_t>& p_body);
Error request( Method p_method, const String& p_url, const Vector<String>& p_headers,const String& p_body=String());
Error send_body_text(const String& p_body);
Error send_body_data(const ByteArray& p_body);
diff --git a/core/io/json.cpp b/core/io/json.cpp
index f42155bc9..3280f9475 100644
--- a/core/io/json.cpp
+++ b/core/io/json.cpp
@@ -92,9 +92,9 @@ String JSON::_print_var(const Variant& p_var) {
}
-String JSON::print(const Dictionary& p_dict) {
+String JSON::print(const Variant& p_var) {
- return _print_var(p_dict);
+ return _print_var(p_var);
}
@@ -450,27 +450,24 @@ Error JSON::_parse_object(Dictionary &object,const CharType *p_str,int &index, i
}
-Error JSON::parse(const String& p_json,Dictionary& r_ret,String &r_err_str,int &r_err_line) {
+Error JSON::parse(const String& p_json, Variant &r_ret, String &r_err_str, int &r_err_line) {
const CharType *str = p_json.ptr();
int idx = 0;
int len = p_json.length();
Token token;
- int line=0;
+ r_err_line=0;
String aux_key;
- Error err = _get_token(str,idx,len,token,line,r_err_str);
+ Error err = _get_token(str,idx,len,token,r_err_line,r_err_str);
if (err)
return err;
- if (token.type!=TK_CURLY_BRACKET_OPEN) {
+ err = _parse_value(r_ret,token,str,idx,len,r_err_line,r_err_str);
- r_err_str="Expected '{'";
- return ERR_PARSE_ERROR;
- }
-
- return _parse_object(r_ret,str,idx,len,r_err_line,r_err_str);
+ return err;
+
}
diff --git a/core/io/json.h b/core/io/json.h
index 52fcac145..97457d223 100644
--- a/core/io/json.h
+++ b/core/io/json.h
@@ -74,8 +74,8 @@ class JSON {
static Error _parse_object(Dictionary &object,const CharType *p_str,int &index, int p_len,int &line,String &r_err_str);
public:
- static String print(const Dictionary& p_dict);
- static Error parse(const String& p_json,Dictionary& r_ret,String &r_err_str,int &r_err_line);
+ static String print(const Variant &p_var);
+ static Error parse(const String& p_json,Variant& r_ret,String &r_err_str,int &r_err_line);
};
#endif // JSON_H
diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp
index bc6cc0bb8..0765fc86c 100644
--- a/core/io/marshalls.cpp
+++ b/core/io/marshalls.cpp
@@ -31,6 +31,10 @@
#include "os/keyboard.h"
#include <stdio.h>
+
+#define ENCODE_MASK 0xFF
+#define ENCODE_FLAG_64 1<<16
+
Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *r_len) {
const uint8_t * buf=p_buffer;
@@ -44,14 +48,14 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
uint32_t type=decode_uint32(buf);
- ERR_FAIL_COND_V(type>=Variant::VARIANT_MAX,ERR_INVALID_DATA);
+ ERR_FAIL_COND_V((type&ENCODE_MASK)>=Variant::VARIANT_MAX,ERR_INVALID_DATA);
buf+=4;
len-=4;
if (r_len)
*r_len=4;
- switch(type) {
+ switch(type&ENCODE_MASK) {
case Variant::NIL: {
@@ -68,19 +72,35 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
case Variant::INT: {
ERR_FAIL_COND_V(len<4,ERR_INVALID_DATA);
- int val = decode_uint32(buf);
- r_variant=val;
- if (r_len)
- (*r_len)+=4;
+ if (type&ENCODE_FLAG_64) {
+ int64_t val = decode_uint64(buf);
+ r_variant=val;
+ if (r_len)
+ (*r_len)+=8;
+
+ } else {
+ int32_t val = decode_uint32(buf);
+ r_variant=val;
+ if (r_len)
+ (*r_len)+=4;
+ }
} break;
case Variant::REAL: {
ERR_FAIL_COND_V(len<(int)4,ERR_INVALID_DATA);
- float val = decode_float(buf);
- r_variant=val;
- if (r_len)
- (*r_len)+=4;
+
+ if (type&ENCODE_FLAG_64) {
+ double val = decode_double(buf);
+ r_variant=val;
+ if (r_len)
+ (*r_len)+=8;
+ } else {
+ float val = decode_float(buf);
+ r_variant=val;
+ if (r_len)
+ (*r_len)+=4;
+ }
} break;
case Variant::STRING: {
@@ -272,11 +292,11 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
if (datalen>0) {
len-=5*4;
ERR_FAIL_COND_V( len < datalen, ERR_INVALID_DATA );
- DVector<uint8_t> data;
+ PoolVector<uint8_t> data;
data.resize(datalen);
- DVector<uint8_t>::Write wr = data.write();
+ PoolVector<uint8_t>::Write wr = data.write();
copymem(&wr[0],&buf[20],datalen);
- wr = DVector<uint8_t>::Write();
+ wr = PoolVector<uint8_t>::Write();
@@ -423,7 +443,7 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
(*r_len)+=4;
} break;
- case InputEvent::JOYSTICK_BUTTON: {
+ case InputEvent::JOYPAD_BUTTON: {
ie.joy_button.button_index=decode_uint32(&buf[12]);
if (r_len)
@@ -435,7 +455,7 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
if (r_len)
(*r_len)+=4;
} break;
- case InputEvent::JOYSTICK_MOTION: {
+ case InputEvent::JOYPAD_MOTION: {
ie.joy_motion.axis=decode_uint32(&buf[12]);
ie.joy_motion.axis_value=decode_float(&buf[16]);
@@ -537,17 +557,17 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
ERR_FAIL_COND_V((int)count>len,ERR_INVALID_DATA);
- DVector<uint8_t> data;
+ PoolVector<uint8_t> data;
if (count) {
data.resize(count);
- DVector<uint8_t>::Write w = data.write();
+ PoolVector<uint8_t>::Write w = data.write();
for(int i=0;i<count;i++) {
w[i]=buf[i];
}
- w = DVector<uint8_t>::Write();
+ w = PoolVector<uint8_t>::Write();
}
r_variant=data;
@@ -569,18 +589,18 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
len-=4;
ERR_FAIL_COND_V((int)count*4>len,ERR_INVALID_DATA);
- DVector<int> data;
+ PoolVector<int> data;
if (count) {
//const int*rbuf=(const int*)buf;
data.resize(count);
- DVector<int>::Write w = data.write();
+ PoolVector<int>::Write w = data.write();
for(int i=0;i<count;i++) {
w[i]=decode_uint32(&buf[i*4]);
}
- w = DVector<int>::Write();
+ w = PoolVector<int>::Write();
}
r_variant=Variant(data);
if (r_len) {
@@ -596,18 +616,18 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
len-=4;
ERR_FAIL_COND_V((int)count*4>len,ERR_INVALID_DATA);
- DVector<float> data;
+ PoolVector<float> data;
if (count) {
//const float*rbuf=(const float*)buf;
data.resize(count);
- DVector<float>::Write w = data.write();
+ PoolVector<float>::Write w = data.write();
for(int i=0;i<count;i++) {
w[i]=decode_float(&buf[i*4]);
}
- w = DVector<float>::Write();
+ w = PoolVector<float>::Write();
}
r_variant=data;
@@ -623,7 +643,7 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
uint32_t count = decode_uint32(buf);
ERR_FAIL_COND_V(count<0,ERR_INVALID_DATA);
- DVector<String> strings;
+ PoolVector<String> strings;
buf+=4;
len-=4;
@@ -676,7 +696,7 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
len-=4;
ERR_FAIL_COND_V((int)count*4*2>len,ERR_INVALID_DATA);
- DVector<Vector2> varray;
+ PoolVector<Vector2> varray;
if (r_len) {
(*r_len)+=4;
@@ -684,7 +704,7 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
if (count) {
varray.resize(count);
- DVector<Vector2>::Write w = varray.write();
+ PoolVector<Vector2>::Write w = varray.write();
for(int i=0;i<(int)count;i++) {
@@ -714,7 +734,7 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
len-=4;
ERR_FAIL_COND_V((int)count*4*3>len,ERR_INVALID_DATA);
- DVector<Vector3> varray;
+ PoolVector<Vector3> varray;
if (r_len) {
(*r_len)+=4;
@@ -722,7 +742,7 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
if (count) {
varray.resize(count);
- DVector<Vector3>::Write w = varray.write();
+ PoolVector<Vector3>::Write w = varray.write();
for(int i=0;i<(int)count;i++) {
@@ -753,7 +773,7 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
len-=4;
ERR_FAIL_COND_V((int)count*4*4>len,ERR_INVALID_DATA);
- DVector<Color> carray;
+ PoolVector<Color> carray;
if (r_len) {
(*r_len)+=4;
@@ -761,7 +781,7 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
if (count) {
carray.resize(count);
- DVector<Color>::Write w = carray.write();
+ PoolVector<Color>::Write w = carray.write();
for(int i=0;i<(int)count;i++) {
@@ -796,8 +816,28 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
r_len=0;
+ uint32_t flags=0;
+
+ switch(p_variant.get_type()) {
+
+ case Variant::INT: {
+ int64_t val = p_variant;
+ if (val>0x7FFFFFFF || val < -0x80000000) {
+ flags|=ENCODE_FLAG_64;
+ }
+ } break;
+ case Variant::REAL: {
+
+ double d = p_variant;
+ float f = d;
+ if (double(f)!=d) {
+ flags|=ENCODE_FLAG_64; //always encode real as double
+ }
+ } break;
+ }
+
if (buf) {
- encode_uint32(p_variant.get_type(),buf);
+ encode_uint32(p_variant.get_type()|flags,buf);
buf+=4;
}
r_len+=4;
@@ -819,20 +859,42 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
} break;
case Variant::INT: {
- if (buf) {
- encode_uint32(p_variant.operator int(),buf);
- }
+ int64_t val = p_variant;
+ if (val>0x7FFFFFFF || val < -0x80000000) {
+ //64 bits
+ if (buf) {
+ encode_uint64(val,buf);
+ }
- r_len+=4;
+ r_len+=8;
+ } else {
+ if (buf) {
+ encode_uint32(int32_t(val),buf);
+ }
+ r_len+=4;
+ }
} break;
case Variant::REAL: {
- if (buf) {
- encode_float(p_variant.operator float(),buf);
+ double d = p_variant;
+ float f = d;
+ if (double(f)!=d) {
+ if (buf) {
+ encode_double(p_variant.operator double(),buf);
+ }
+
+ r_len+=8;
+
+ } else {
+
+ if (buf) {
+ encode_double(p_variant.operator float(),buf);
+ }
+
+ r_len+=4;
}
- r_len+=4;
} break;
case Variant::NODE_PATH: {
@@ -1055,7 +1117,7 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
case Variant::IMAGE: {
Image image = p_variant;
- DVector<uint8_t> data=image.get_data();
+ PoolVector<uint8_t> data=image.get_data();
if (buf) {
@@ -1065,7 +1127,7 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
encode_uint32(image.get_height(),&buf[12]);
int ds=data.size();
encode_uint32(ds,&buf[16]);
- DVector<uint8_t>::Read r = data.read();
+ PoolVector<uint8_t>::Read r = data.read();
copymem(&buf[20],&r[0],ds);
}
@@ -1130,7 +1192,7 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
}
llen+=4;
} break;
- case InputEvent::JOYSTICK_BUTTON: {
+ case InputEvent::JOYPAD_BUTTON: {
if (buf) {
@@ -1146,7 +1208,7 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
}
llen+=4;
} break;
- case InputEvent::JOYSTICK_MOTION: {
+ case InputEvent::JOYPAD_MOTION: {
if (buf) {
@@ -1234,14 +1296,14 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
// arrays
case Variant::RAW_ARRAY: {
- DVector<uint8_t> data = p_variant;
+ PoolVector<uint8_t> data = p_variant;
int datalen=data.size();
int datasize=sizeof(uint8_t);
if (buf) {
encode_uint32(datalen,buf);
buf+=4;
- DVector<uint8_t>::Read r = data.read();
+ PoolVector<uint8_t>::Read r = data.read();
copymem(buf,&r[0],datalen*datasize);
}
@@ -1253,14 +1315,14 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
} break;
case Variant::INT_ARRAY: {
- DVector<int> data = p_variant;
+ PoolVector<int> data = p_variant;
int datalen=data.size();
int datasize=sizeof(int32_t);
if (buf) {
encode_uint32(datalen,buf);
buf+=4;
- DVector<int>::Read r = data.read();
+ PoolVector<int>::Read r = data.read();
for(int i=0;i<datalen;i++)
encode_uint32(r[i],&buf[i*datasize]);
@@ -1271,14 +1333,14 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
} break;
case Variant::REAL_ARRAY: {
- DVector<real_t> data = p_variant;
+ PoolVector<real_t> data = p_variant;
int datalen=data.size();
int datasize=sizeof(real_t);
if (buf) {
encode_uint32(datalen,buf);
buf+=4;
- DVector<real_t>::Read r = data.read();
+ PoolVector<real_t>::Read r = data.read();
for(int i=0;i<datalen;i++)
encode_float(r[i],&buf[i*datasize]);
@@ -1290,7 +1352,7 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
case Variant::STRING_ARRAY: {
- DVector<String> data = p_variant;
+ PoolVector<String> data = p_variant;
int len=data.size();
if (buf) {
@@ -1323,7 +1385,7 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
} break;
case Variant::VECTOR2_ARRAY: {
- DVector<Vector2> data = p_variant;
+ PoolVector<Vector2> data = p_variant;
int len=data.size();
if (buf) {
@@ -1351,7 +1413,7 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
} break;
case Variant::VECTOR3_ARRAY: {
- DVector<Vector3> data = p_variant;
+ PoolVector<Vector3> data = p_variant;
int len=data.size();
if (buf) {
@@ -1380,7 +1442,7 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
} break;
case Variant::COLOR_ARRAY: {
- DVector<Color> data = p_variant;
+ PoolVector<Color> data = p_variant;
int len=data.size();
if (buf) {
diff --git a/core/io/packet_peer.cpp b/core/io/packet_peer.cpp
index 720e912e7..5ff09f9fb 100644
--- a/core/io/packet_peer.cpp
+++ b/core/io/packet_peer.cpp
@@ -39,7 +39,7 @@ PacketPeer::PacketPeer() {
last_get_error=OK;
}
-Error PacketPeer::get_packet_buffer(DVector<uint8_t> &r_buffer) const {
+Error PacketPeer::get_packet_buffer(PoolVector<uint8_t> &r_buffer) const {
const uint8_t *buffer;
int buffer_size;
@@ -51,7 +51,7 @@ Error PacketPeer::get_packet_buffer(DVector<uint8_t> &r_buffer) const {
if (buffer_size==0)
return OK;
- DVector<uint8_t>::Write w = r_buffer.write();
+ PoolVector<uint8_t>::Write w = r_buffer.write();
for(int i=0;i<buffer_size;i++)
w[i]=buffer[i];
@@ -59,13 +59,13 @@ Error PacketPeer::get_packet_buffer(DVector<uint8_t> &r_buffer) const {
}
-Error PacketPeer::put_packet_buffer(const DVector<uint8_t> &p_buffer) {
+Error PacketPeer::put_packet_buffer(const PoolVector<uint8_t> &p_buffer) {
int len = p_buffer.size();
if (len==0)
return OK;
- DVector<uint8_t>::Read r = p_buffer.read();
+ PoolVector<uint8_t>::Read r = p_buffer.read();
return put_packet(&r[0],len);
}
@@ -108,12 +108,12 @@ Variant PacketPeer::_bnd_get_var() const {
return var;
};
-Error PacketPeer::_put_packet(const DVector<uint8_t> &p_buffer) {
+Error PacketPeer::_put_packet(const PoolVector<uint8_t> &p_buffer) {
return put_packet_buffer(p_buffer);
}
-DVector<uint8_t> PacketPeer::_get_packet() const {
+PoolVector<uint8_t> PacketPeer::_get_packet() const {
- DVector<uint8_t> raw;
+ PoolVector<uint8_t> raw;
last_get_error=get_packet_buffer(raw);
return raw;
}
diff --git a/core/io/packet_peer.h b/core/io/packet_peer.h
index c67cfb943..bacd5214f 100644
--- a/core/io/packet_peer.h
+++ b/core/io/packet_peer.h
@@ -42,8 +42,8 @@ class PacketPeer : public Reference {
static void _bind_methods();
- Error _put_packet(const DVector<uint8_t> &p_buffer);
- DVector<uint8_t> _get_packet() const;
+ Error _put_packet(const PoolVector<uint8_t> &p_buffer);
+ PoolVector<uint8_t> _get_packet() const;
Error _get_packet_error() const;
@@ -59,8 +59,8 @@ public:
/* helpers / binders */
- virtual Error get_packet_buffer(DVector<uint8_t> &r_buffer) const;
- virtual Error put_packet_buffer(const DVector<uint8_t> &p_buffer);
+ virtual Error get_packet_buffer(PoolVector<uint8_t> &r_buffer) const;
+ virtual Error put_packet_buffer(const PoolVector<uint8_t> &p_buffer);
virtual Error get_var(Variant &r_variant) const;
virtual Error put_var(const Variant& p_packet);
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index 512031b12..16da74fdf 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -68,6 +68,8 @@ enum {
VARIANT_VECTOR3_ARRAY=35,
VARIANT_COLOR_ARRAY=36,
VARIANT_VECTOR2_ARRAY=37,
+ VARIANT_INT64=40,
+ VARIANT_DOUBLE=41,
IMAGE_ENCODING_EMPTY=0,
IMAGE_ENCODING_RAW=1,
@@ -116,10 +118,18 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
r_v=int(f->get_32());
} break;
+ case VARIANT_INT64: {
+
+ r_v=int64_t(f->get_64());
+ } break;
case VARIANT_REAL: {
r_v=f->get_real();
} break;
+ case VARIANT_DOUBLE: {
+
+ r_v=f->get_double();
+ } break;
case VARIANT_STRING: {
r_v=get_unicode_string();
@@ -264,22 +274,22 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
uint32_t datalen = f->get_32();
- DVector<uint8_t> imgdata;
+ PoolVector<uint8_t> imgdata;
imgdata.resize(datalen);
- DVector<uint8_t>::Write w = imgdata.write();
+ PoolVector<uint8_t>::Write w = imgdata.write();
f->get_buffer(w.ptr(),datalen);
_advance_padding(datalen);
- w=DVector<uint8_t>::Write();
+ w=PoolVector<uint8_t>::Write();
r_v=Image(width,height,mipmaps,fmt,imgdata);
} else {
//compressed
- DVector<uint8_t> data;
+ PoolVector<uint8_t> data;
data.resize(f->get_32());
- DVector<uint8_t>::Write w = data.write();
+ PoolVector<uint8_t>::Write w = data.write();
f->get_buffer(w.ptr(),data.size());
- w = DVector<uint8_t>::Write();
+ w = PoolVector<uint8_t>::Write();
Image img;
@@ -448,12 +458,12 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
uint32_t len = f->get_32();
- DVector<uint8_t> array;
+ PoolVector<uint8_t> array;
array.resize(len);
- DVector<uint8_t>::Write w = array.write();
+ PoolVector<uint8_t>::Write w = array.write();
f->get_buffer(w.ptr(),len);
_advance_padding(len);
- w=DVector<uint8_t>::Write();
+ w=PoolVector<uint8_t>::Write();
r_v=array;
} break;
@@ -461,9 +471,9 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
uint32_t len = f->get_32();
- DVector<int> array;
+ PoolVector<int> array;
array.resize(len);
- DVector<int>::Write w = array.write();
+ PoolVector<int>::Write w = array.write();
f->get_buffer((uint8_t*)w.ptr(),len*4);
#ifdef BIG_ENDIAN_ENABLED
{
@@ -475,16 +485,16 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
}
#endif
- w=DVector<int>::Write();
+ w=PoolVector<int>::Write();
r_v=array;
} break;
case VARIANT_REAL_ARRAY: {
uint32_t len = f->get_32();
- DVector<real_t> array;
+ PoolVector<real_t> array;
array.resize(len);
- DVector<real_t>::Write w = array.write();
+ PoolVector<real_t>::Write w = array.write();
f->get_buffer((uint8_t*)w.ptr(),len*sizeof(real_t));
#ifdef BIG_ENDIAN_ENABLED
{
@@ -497,18 +507,18 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
#endif
- w=DVector<real_t>::Write();
+ w=PoolVector<real_t>::Write();
r_v=array;
} break;
case VARIANT_STRING_ARRAY: {
uint32_t len = f->get_32();
- DVector<String> array;
+ PoolVector<String> array;
array.resize(len);
- DVector<String>::Write w = array.write();
+ PoolVector<String>::Write w = array.write();
for(uint32_t i=0;i<len;i++)
w[i]=get_unicode_string();
- w=DVector<String>::Write();
+ w=PoolVector<String>::Write();
r_v=array;
@@ -517,9 +527,9 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
uint32_t len = f->get_32();
- DVector<Vector2> array;
+ PoolVector<Vector2> array;
array.resize(len);
- DVector<Vector2>::Write w = array.write();
+ PoolVector<Vector2>::Write w = array.write();
if (sizeof(Vector2)==8) {
f->get_buffer((uint8_t*)w.ptr(),len*sizeof(real_t)*2);
#ifdef BIG_ENDIAN_ENABLED
@@ -537,7 +547,7 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
ERR_EXPLAIN("Vector2 size is NOT 8!");
ERR_FAIL_V(ERR_UNAVAILABLE);
}
- w=DVector<Vector2>::Write();
+ w=PoolVector<Vector2>::Write();
r_v=array;
} break;
@@ -545,9 +555,9 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
uint32_t len = f->get_32();
- DVector<Vector3> array;
+ PoolVector<Vector3> array;
array.resize(len);
- DVector<Vector3>::Write w = array.write();
+ PoolVector<Vector3>::Write w = array.write();
if (sizeof(Vector3)==12) {
f->get_buffer((uint8_t*)w.ptr(),len*sizeof(real_t)*3);
#ifdef BIG_ENDIAN_ENABLED
@@ -565,7 +575,7 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
ERR_EXPLAIN("Vector3 size is NOT 12!");
ERR_FAIL_V(ERR_UNAVAILABLE);
}
- w=DVector<Vector3>::Write();
+ w=PoolVector<Vector3>::Write();
r_v=array;
} break;
@@ -573,9 +583,9 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
uint32_t len = f->get_32();
- DVector<Color> array;
+ PoolVector<Color> array;
array.resize(len);
- DVector<Color>::Write w = array.write();
+ PoolVector<Color>::Write w = array.write();
if (sizeof(Color)==16) {
f->get_buffer((uint8_t*)w.ptr(),len*sizeof(real_t)*4);
#ifdef BIG_ENDIAN_ENABLED
@@ -593,7 +603,7 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
ERR_EXPLAIN("Color size is NOT 16!");
ERR_FAIL_V(ERR_UNAVAILABLE);
}
- w=DVector<Color>::Write();
+ w=PoolVector<Color>::Write();
r_v=array;
} break;
@@ -1416,15 +1426,33 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property,
} break;
case Variant::INT: {
- f->store_32(VARIANT_INT);
- int val=p_property;
- f->store_32(val);
+ int64_t val = p_property;
+ if (val>0x7FFFFFFF || val < -0x80000000) {
+ f->store_32(VARIANT_INT64);
+ f->store_64(val);
+
+ } else {
+ f->store_32(VARIANT_INT);
+ int val=p_property;
+ f->store_32(int32_t(val));
+
+ }
+
} break;
case Variant::REAL: {
- f->store_32(VARIANT_REAL);
- real_t val=p_property;
- f->store_real(val);
+
+ double d = p_property;
+ float fl = d;
+ if (double(fl)!=d) {
+ f->store_32(VARIANT_DOUBLE);
+ f->store_double(d);
+ } else {
+
+ f->store_32(VARIANT_REAL);
+ f->store_real(fl);
+
+ }
} break;
case Variant::STRING: {
@@ -1587,12 +1615,12 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property,
int dlen = val.get_data().size();
f->store_32(dlen);
- DVector<uint8_t>::Read r = val.get_data().read();
+ PoolVector<uint8_t>::Read r = val.get_data().read();
f->store_buffer(r.ptr(),dlen);
_pad_buffer(dlen);
} else {
- DVector<uint8_t> data;
+ PoolVector<uint8_t> data;
if (encoding==IMAGE_ENCODING_LOSSY) {
data=Image::lossy_packer(val,quality);
@@ -1604,7 +1632,7 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property,
int ds=data.size();
f->store_32(ds);
if (ds>0) {
- DVector<uint8_t>::Read r = data.read();
+ PoolVector<uint8_t>::Read r = data.read();
f->store_buffer(r.ptr(),ds);
_pad_buffer(ds);
@@ -1703,10 +1731,10 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property,
case Variant::RAW_ARRAY: {
f->store_32(VARIANT_RAW_ARRAY);
- DVector<uint8_t> arr = p_property;
+ PoolVector<uint8_t> arr = p_property;
int len=arr.size();
f->store_32(len);
- DVector<uint8_t>::Read r = arr.read();
+ PoolVector<uint8_t>::Read r = arr.read();
f->store_buffer(r.ptr(),len);
_pad_buffer(len);
@@ -1714,10 +1742,10 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property,
case Variant::INT_ARRAY: {
f->store_32(VARIANT_INT_ARRAY);
- DVector<int> arr = p_property;
+ PoolVector<int> arr = p_property;
int len=arr.size();
f->store_32(len);
- DVector<int>::Read r = arr.read();
+ PoolVector<int>::Read r = arr.read();
for(int i=0;i<len;i++)
f->store_32(r[i]);
@@ -1725,10 +1753,10 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property,
case Variant::REAL_ARRAY: {
f->store_32(VARIANT_REAL_ARRAY);
- DVector<real_t> arr = p_property;
+ PoolVector<real_t> arr = p_property;
int len=arr.size();
f->store_32(len);
- DVector<real_t>::Read r = arr.read();
+ PoolVector<real_t>::Read r = arr.read();
for(int i=0;i<len;i++) {
f->store_real(r[i]);
}
@@ -1737,10 +1765,10 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property,
case Variant::STRING_ARRAY: {
f->store_32(VARIANT_STRING_ARRAY);
- DVector<String> arr = p_property;
+ PoolVector<String> arr = p_property;
int len=arr.size();
f->store_32(len);
- DVector<String>::Read r = arr.read();
+ PoolVector<String>::Read r = arr.read();
for(int i=0;i<len;i++) {
save_unicode_string(r[i]);
}
@@ -1749,10 +1777,10 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property,
case Variant::VECTOR3_ARRAY: {
f->store_32(VARIANT_VECTOR3_ARRAY);
- DVector<Vector3> arr = p_property;
+ PoolVector<Vector3> arr = p_property;
int len=arr.size();
f->store_32(len);
- DVector<Vector3>::Read r = arr.read();
+ PoolVector<Vector3>::Read r = arr.read();
for(int i=0;i<len;i++) {
f->store_real(r[i].x);
f->store_real(r[i].y);
@@ -1763,10 +1791,10 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property,
case Variant::VECTOR2_ARRAY: {
f->store_32(VARIANT_VECTOR2_ARRAY);
- DVector<Vector2> arr = p_property;
+ PoolVector<Vector2> arr = p_property;
int len=arr.size();
f->store_32(len);
- DVector<Vector2>::Read r = arr.read();
+ PoolVector<Vector2>::Read r = arr.read();
for(int i=0;i<len;i++) {
f->store_real(r[i].x);
f->store_real(r[i].y);
@@ -1776,10 +1804,10 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property,
case Variant::COLOR_ARRAY: {
f->store_32(VARIANT_COLOR_ARRAY);
- DVector<Color> arr = p_property;
+ PoolVector<Color> arr = p_property;
int len=arr.size();
f->store_32(len);
- DVector<Color>::Read r = arr.read();
+ PoolVector<Color>::Read r = arr.read();
for(int i=0;i<len;i++) {
f->store_real(r[i].r);
f->store_real(r[i].g);
diff --git a/core/io/resource_format_xml.cpp b/core/io/resource_format_xml.cpp
deleted file mode 100644
index d4808d474..000000000
--- a/core/io/resource_format_xml.cpp
+++ /dev/null
@@ -1,2882 +0,0 @@
-/*************************************************************************/
-/* resource_format_xml.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-#include "resource_format_xml.h"
-#include "globals.h"
-#include "version.h"
-#include "os/dir_access.h"
-
-
-ResourceInteractiveLoaderXML::Tag* ResourceInteractiveLoaderXML::parse_tag(bool *r_exit, bool p_printerr, List<String> *r_order) {
-
-
- while(get_char()!='<' && !f->eof_reached()) {}
- if (f->eof_reached()) {
- return NULL;
- }
-
- Tag tag;
- bool exit=false;
- if (r_exit)
- *r_exit=false;
-
- bool complete=false;
- while(!f->eof_reached()) {
-
- CharType c=get_char();
- if (c<33 && tag.name.length() && !exit) {
- break;
- } else if (c=='>') {
- complete=true;
- break;
- } else if (c=='/') {
- exit=true;
- } else {
- tag.name+=c;
- }
- }
-
- if (f->eof_reached()) {
-
- return NULL;
- }
-
- if (exit) {
- if (!tag_stack.size()) {
- if (!p_printerr)
- return NULL;
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Unmatched exit tag </"+tag.name+">");
- ERR_FAIL_COND_V(!tag_stack.size(),NULL);
- }
-
- if (tag_stack.back()->get().name!=tag.name) {
- if (!p_printerr)
- return NULL;
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Mismatched exit tag. Got </"+tag.name+">, expected </"+tag_stack.back()->get().name+">");
- ERR_FAIL_COND_V(tag_stack.back()->get().name!=tag.name,NULL);
- }
-
- if (!complete) {
- while(get_char()!='>' && !f->eof_reached()) {}
- if (f->eof_reached())
- return NULL;
- }
-
- if (r_exit)
- *r_exit=true;
-
- tag_stack.pop_back();
- return NULL;
-
- }
-
- if (!complete) {
- String name;
- CharString r_value;
- bool reading_value=false;
-
- while(!f->eof_reached()) {
-
- CharType c=get_char();
- if (c=='>') {
- if (r_value.size()) {
-
- r_value.push_back(0);
- String str;
- str.parse_utf8(r_value.get_data());
- tag.args[name]=str;
- if (r_order)
- r_order->push_back(name);
- }
- break;
-
- } else if ( ((!reading_value && (c<33)) || c=='=' || c=='"' || c=='\'') && tag.name.length()) {
-
- if (!reading_value && name.length()) {
-
- reading_value=true;
- } else if (reading_value && r_value.size()) {
-
- r_value.push_back(0);
- String str;
- str.parse_utf8(r_value.get_data());
- tag.args[name]=str;
- if (r_order)
- r_order->push_back(name);
- name="";
- r_value.clear();
- reading_value=false;
- }
-
- } else if (reading_value) {
-
- r_value.push_back(c);
- } else {
-
- name+=c;
- }
- }
-
- if (f->eof_reached())
- return NULL;
- }
-
- tag_stack.push_back(tag);
-
- return &tag_stack.back()->get();
-}
-
-
-Error ResourceInteractiveLoaderXML::close_tag(const String& p_name) {
-
- int level=0;
- bool inside_tag=false;
-
- while(true) {
-
- if (f->eof_reached()) {
-
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": EOF found while attempting to find </"+p_name+">");
- ERR_FAIL_COND_V( f->eof_reached(), ERR_FILE_CORRUPT );
- }
-
- uint8_t c = get_char();
-
- if (c == '<') {
-
- if (inside_tag) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Malformed XML. Already inside Tag.");
- ERR_FAIL_COND_V(inside_tag,ERR_FILE_CORRUPT);
- }
- inside_tag=true;
- c = get_char();
- if (c == '/') {
-
- --level;
- } else {
-
- ++level;
- };
- } else if (c == '>') {
-
- if (!inside_tag) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Malformed XML. Already outside Tag");
- ERR_FAIL_COND_V(!inside_tag,ERR_FILE_CORRUPT);
- }
- inside_tag=false;
- if (level == -1) {
- tag_stack.pop_back();
- return OK;
- };
- };
- }
-
- return OK;
-}
-
-void ResourceInteractiveLoaderXML::unquote(String& p_str) {
-
-
- p_str=p_str.strip_edges().replace("\"","").xml_unescape();
-
- /*p_str=p_str.strip_edges();
- p_str=p_str.replace("\"","");
- p_str=p_str.replace("&gt;","<");
- p_str=p_str.replace("&lt;",">");
- p_str=p_str.replace("&apos;","'");
- p_str=p_str.replace("&quot;","\"");
- for (int i=1;i<32;i++) {
-
- char chr[2]={i,0};
- p_str=p_str.replace("&#"+String::num(i)+";",chr);
- }
- p_str=p_str.replace("&amp;","&");
-*/
- //p_str.parse_utf8( p_str.ascii(true).get_data() );
-
-}
-
-Error ResourceInteractiveLoaderXML::goto_end_of_tag() {
-
- uint8_t c;
- while(true) {
-
- c=get_char();
- if (c=='>') //closetag
- break;
- if (f->eof_reached()) {
-
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": EOF found while attempting to find close tag.");
- ERR_FAIL_COND_V( f->eof_reached(), ERR_FILE_CORRUPT );
- }
-
- }
- tag_stack.pop_back();
-
- return OK;
-}
-
-
-Error ResourceInteractiveLoaderXML::parse_property_data(String &r_data) {
-
- r_data="";
- CharString cs;
- while(true) {
-
- CharType c=get_char();
- if (c=='<')
- break;
- ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
- cs.push_back(c);
- }
-
- cs.push_back(0);
-
- r_data.parse_utf8(cs.get_data());
-
- while(get_char()!='>' && !f->eof_reached()) {}
- if (f->eof_reached()) {
-
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Malformed XML.");
- ERR_FAIL_COND_V( f->eof_reached(), ERR_FILE_CORRUPT );
- }
-
- r_data=r_data.strip_edges();
- tag_stack.pop_back();
-
- return OK;
-}
-
-
-Error ResourceInteractiveLoaderXML::_parse_array_element(Vector<char> &buff,bool p_number_only,FileAccess *f,bool *end) {
-
- if (buff.empty())
- buff.resize(32); // optimi
-
- int buff_max=buff.size();
- int buff_size=0;
- *end=false;
- char *buffptr=&buff[0];
- bool found=false;
- bool quoted=false;
-
- while(true) {
-
- char c=get_char();
-
- if (c==0) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": File corrupt (zero found).");
- ERR_FAIL_V(ERR_FILE_CORRUPT);
- } else if (c=='"') {
- quoted=!quoted;
- } else if ((!quoted && ((p_number_only && c<33) || c==',')) || c=='<') {
-
-
- if (c=='<') {
- *end=true;
- break;
- }
- if (c<32 && f->eof_reached()) {
- *end=true;
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": File corrupt (unexpected EOF).");
- ERR_FAIL_V(ERR_FILE_CORRUPT);
- }
-
- if (found)
- break;
-
- } else {
-
- found=true;
- if (buff_size>=buff_max) {
-
- buff_max++;
- buff.resize(buff_max);
- buffptr=buff.ptr();
-
- }
-
- buffptr[buff_size]=c;
- buff_size++;
- }
- }
-
- if (buff_size>=buff_max) {
-
- buff_max++;
- buff.resize(buff_max);
-
- }
-
- buff[buff_size]=0;
- buff_size++;
-
- return OK;
-}
-
-Error ResourceInteractiveLoaderXML::parse_property(Variant& r_v, String &r_name) {
-
- bool exit;
- Tag *tag = parse_tag(&exit);
-
- if (!tag) {
- if (exit) // shouldn't have exited
- return ERR_FILE_EOF;
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": File corrupt (No Property Tag).");
- ERR_FAIL_V(ERR_FILE_CORRUPT);
- }
-
- r_v=Variant();
- r_name="";
-
-
- //ERR_FAIL_COND_V(tag->name!="property",ERR_FILE_CORRUPT);
- //ERR_FAIL_COND_V(!tag->args.has("name"),ERR_FILE_CORRUPT);
-// ERR_FAIL_COND_V(!tag->args.has("type"),ERR_FILE_CORRUPT);
-
- //String name=tag->args["name"];
- //ERR_FAIL_COND_V(name=="",ERR_FILE_CORRUPT);
- String type=tag->name;
- String name=tag->args["name"];
-
- if (type=="") {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": 'type' field is empty.");
- ERR_FAIL_COND_V(type=="",ERR_FILE_CORRUPT);
- }
-
- if (type=="dictionary") {
-
- Dictionary d( tag->args.has("shared") && (String(tag->args["shared"])=="true" || String(tag->args["shared"])=="1"));
-
- while(true) {
-
- Error err;
- String tagname;
- Variant key;
-
- int dictline = get_current_line();
-
-
- err=parse_property(key,tagname);
-
- if (err && err!=ERR_FILE_EOF) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Error parsing dictionary: "+name+" (from line "+itos(dictline)+")");
- ERR_FAIL_COND_V(err && err!=ERR_FILE_EOF,err);
- }
- //ERR_FAIL_COND_V(tagname!="key",ERR_FILE_CORRUPT);
- if (err)
- break;
- Variant value;
- err=parse_property(value,tagname);
- if (err) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Error parsing dictionary: "+name+" (from line "+itos(dictline)+")");
- }
-
- ERR_FAIL_COND_V(err,err);
- //ERR_FAIL_COND_V(tagname!="value",ERR_FILE_CORRUPT);
-
- d[key]=value;
- }
-
-
- //err=parse_property_data(name); // skip the rest
- //ERR_FAIL_COND_V(err,err);
-
- r_name=name;
- r_v=d;
- return OK;
-
- } else if (type=="array") {
-
- if (!tag->args.has("len")) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Array missing 'len' field: "+name);
- ERR_FAIL_COND_V(!tag->args.has("len"),ERR_FILE_CORRUPT);
- }
-
-
- int len=tag->args["len"].to_int();
- bool shared = tag->args.has("shared") && (String(tag->args["shared"])=="true" || String(tag->args["shared"])=="1");
-
- Array array(shared);
- array.resize(len);
-
- Error err;
- Variant v;
- String tagname;
- int idx=0;
- while( (err=parse_property(v,tagname))==OK ) {
-
- ERR_CONTINUE( idx <0 || idx >=len );
-
- array.set(idx,v);
- idx++;
- }
-
- if (idx!=len) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Error loading array (size mismatch): "+name);
- ERR_FAIL_COND_V(idx!=len,err);
- }
-
- if (err!=ERR_FILE_EOF) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Error loading array: "+name);
- ERR_FAIL_COND_V(err!=ERR_FILE_EOF,err);
- }
-
- //err=parse_property_data(name); // skip the rest
- //ERR_FAIL_COND_V(err,err);
-
- r_name=name;
- r_v=array;
- return OK;
-
- } else if (type=="resource") {
-
- if (tag->args.has("path")) {
-
- String path=tag->args["path"];
- String hint;
- if (tag->args.has("resource_type"))
- hint=tag->args["resource_type"];
-
- if (path.begins_with("local://"))
- path=path.replace("local://",local_path+"::");
- else if (path.find("://")==-1 && path.is_rel_path()) {
- // path is relative to file being loaded, so convert to a resource path
- path=GlobalConfig::get_singleton()->localize_path(local_path.get_base_dir().plus_file(path));
-
- }
-
- if (remaps.has(path)) {
- path=remaps[path];
- }
-
- //take advantage of the resource loader cache. The resource is cached on it, even if
- RES res=ResourceLoader::load(path,hint);
-
-
- if (res.is_null()) {
-
- WARN_PRINT(String("Couldn't load resource: "+path).ascii().get_data());
- }
-
- r_v=res.get_ref_ptr();
- } else if (tag->args.has("external")) {
-
- int index = tag->args["external"].to_int();
- if (ext_resources.has(index)) {
- String path=ext_resources[index].path;
- String type=ext_resources[index].type;
-
- //take advantage of the resource loader cache. The resource is cached on it, even if
- RES res=ResourceLoader::load(path,type);
-
- if (res.is_null()) {
-
- WARN_PRINT(String("Couldn't load externalresource: "+path).ascii().get_data());
- }
-
- r_v=res.get_ref_ptr();
- } else {
- WARN_PRINT(String("Invalid external resource index: "+itos(index)).ascii().get_data());
-
- }
- }
-
-
-
-
- Error err=goto_end_of_tag();
- if (err) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Error closing <resource> tag.");
- ERR_FAIL_COND_V(err,err);
- }
-
-
- r_name=name;
-
- return OK;
-
- } else if (type=="image") {
-
- if (!tag->args.has("encoding")) {
- //empty image
- r_v=Image();
- String sdfsdfg;
- Error err=parse_property_data(sdfsdfg);
- return OK;
- }
-
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Image missing 'encoding' field.");
- ERR_FAIL_COND_V( !tag->args.has("encoding"), ERR_FILE_CORRUPT );
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Image missing 'width' field.");
- ERR_FAIL_COND_V( !tag->args.has("width"), ERR_FILE_CORRUPT );
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Image missing 'height' field.");
- ERR_FAIL_COND_V( !tag->args.has("height"), ERR_FILE_CORRUPT );
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Image missing 'format' field.");
- ERR_FAIL_COND_V( !tag->args.has("format"), ERR_FILE_CORRUPT );
-
- String encoding=tag->args["encoding"];
-
- if (encoding=="raw") {
- String width=tag->args["width"];
- String height=tag->args["height"];
- String format=tag->args["format"];
- int mipmaps=tag->args.has("mipmaps")?int(tag->args["mipmaps"].to_int()):int(0);
- int custom_size = tag->args.has("custom_size")?int(tag->args["custom_size"].to_int()):int(0);
-
- r_name=name;
-
- Image::Format imgformat;
-
-/*
- if (format=="grayscale") {
- imgformat=Image::FORMAT_L8;
- } else if (format=="intensity") {
- imgformat=Image::FORMAT_INTENSITY;
- } else if (format=="grayscale_alpha") {
- imgformat=Image::FORMAT_LA8;
- } else if (format=="rgb") {
- imgformat=Image::FORMAT_RGB8;
- } else if (format=="rgba") {
- imgformat=Image::FORMAT_RGBA8;
- } else if (format=="indexed") {
- imgformat=Image::FORMAT_INDEXED;
- } else if (format=="indexed_alpha") {
- imgformat=Image::FORMAT_INDEXED_ALPHA;
- } else if (format=="bc1") {
- imgformat=Image::FORMAT_DXT1;
- } else if (format=="bc2") {
- imgformat=Image::FORMAT_DXT3;
- } else if (format=="bc3") {
- imgformat=Image::FORMAT_DXT5;
- } else if (format=="bc4") {
- imgformat=Image::FORMAT_ATI1;
- } else if (format=="bc5") {
- imgformat=Image::FORMAT_ATI2;
- } else if (format=="pvrtc2") {
- imgformat=Image::FORMAT_PVRTC2;
- } else if (format=="pvrtc2a") {
- imgformat=Image::FORMAT_PVRTC2A;
- } else if (format=="pvrtc4") {
- imgformat=Image::FORMAT_PVRTC4;
- } else if (format=="pvrtc4a") {
- imgformat=Image::FORMAT_PVRTC4A;
- } else if (format=="etc") {
- imgformat=Image::FORMAT_ETC;
- } else if (format=="atc") {
- imgformat=Image::FORMAT_ATC;
- } else if (format=="atcai") {
- imgformat=Image::FORMAT_ATC_ALPHA_INTERPOLATED;
- } else if (format=="atcae") {
- imgformat=Image::FORMAT_ATC_ALPHA_EXPLICIT;
- } else if (format=="custom") {
- imgformat=Image::FORMAT_CUSTOM;
- } else {
-
- ERR_FAIL_V( ERR_FILE_CORRUPT );
- }*/
-
-
- int datasize;
- int w=width.to_int();
- int h=height.to_int();
-
- if (w == 0 && h == 0) {
- //r_v = Image(w, h, imgformat);
- r_v=Image();
- String sdfsdfg;
- Error err=parse_property_data(sdfsdfg);
- return OK;
- };
-
-
- if (datasize==0) {
- //r_v = Image(w, h, imgformat);
- r_v=Image();
- String sdfsdfg;
- Error err=parse_property_data(sdfsdfg);
- return OK;
- };
-
- DVector<uint8_t> pixels;
- pixels.resize(datasize);
- DVector<uint8_t>::Write wb = pixels.write();
-
- int idx=0;
- uint8_t byte;
- while( idx<datasize*2) {
-
- CharType c=get_char();
-
- ERR_FAIL_COND_V(c=='<',ERR_FILE_CORRUPT);
-
- if ( (c>='0' && c<='9') || (c>='A' && c<='F') || (c>='a' && c<='f') ) {
-
- if (idx&1) {
-
- byte|=HEX2CHR(c);
- wb[idx>>1]=byte;
- } else {
-
- byte=HEX2CHR(c)<<4;
- }
-
- idx++;
- }
-
- }
- ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
-
- wb=DVector<uint8_t>::Write();
-
- r_v=Image(w,h,mipmaps,imgformat,pixels);
- String sdfsdfg;
- Error err=parse_property_data(sdfsdfg);
- ERR_FAIL_COND_V(err,err);
-
- return OK;
- }
-
- ERR_FAIL_V(ERR_FILE_CORRUPT);
-
- } else if (type=="raw_array") {
-
- if (!tag->args.has("len")) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": RawArray missing 'len' field: "+name);
- ERR_FAIL_COND_V(!tag->args.has("len"),ERR_FILE_CORRUPT);
- }
- int len=tag->args["len"].to_int();
-
- DVector<uint8_t> bytes;
- bytes.resize(len);
- DVector<uint8_t>::Write w=bytes.write();
- uint8_t *bytesptr=w.ptr();
- int idx=0;
- uint8_t byte;
-
- while( idx<len*2) {
-
- CharType c=get_char();
- if (c<=32)
- continue;
-
- if (idx&1) {
-
- byte|=HEX2CHR(c);
- bytesptr[idx>>1]=byte;
- //printf("%x\n",int(byte));
- } else {
-
- byte=HEX2CHR(c)<<4;
- }
-
- idx++;
- }
-
- ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
-
- w=DVector<uint8_t>::Write();
- r_v=bytes;
- String sdfsdfg;
- Error err=parse_property_data(sdfsdfg);
- ERR_FAIL_COND_V(err,err);
- r_name=name;
-
- return OK;
-
- } else if (type=="int_array") {
-
- if (!tag->args.has("len")) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Array missing 'len' field: "+name);
- ERR_FAIL_COND_V(!tag->args.has("len"),ERR_FILE_CORRUPT);
- }
- int len=tag->args["len"].to_int();
-
- DVector<int> ints;
- ints.resize(len);
- DVector<int>::Write w=ints.write();
- int *intsptr=w.ptr();
- int idx=0;
- String str;
-#if 0
- while( idx<len ) {
-
-
- CharType c=get_char();
- ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
-
- if (c<33 || c==',' || c=='<') {
-
- if (str.length()) {
-
- intsptr[idx]=str.to_int();
- str="";
- idx++;
- }
-
- if (c=='<') {
-
- while(get_char()!='>' && !f->eof_reached()) {}
- ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
- break;
- }
-
- } else {
-
- str+=c;
- }
- }
-
-#else
-
- Vector<char> tmpdata;
-
- while( idx<len ) {
-
- bool end=false;
- Error err = _parse_array_element(tmpdata,true,f,&end);
- ERR_FAIL_COND_V(err,err);
-
- intsptr[idx]=String::to_int(&tmpdata[0]);
- idx++;
- if (end)
- break;
-
- }
-
-#endif
- w=DVector<int>::Write();
-
- r_v=ints;
- Error err=goto_end_of_tag();
- ERR_FAIL_COND_V(err,err);
- r_name=name;
-
- return OK;
- } else if (type=="real_array") {
-
- if (!tag->args.has("len")) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Array missing 'len' field: "+name);
- ERR_FAIL_COND_V(!tag->args.has("len"),ERR_FILE_CORRUPT);
- }
- int len=tag->args["len"].to_int();;
-
- DVector<real_t> reals;
- reals.resize(len);
- DVector<real_t>::Write w=reals.write();
- real_t *realsptr=w.ptr();
- int idx=0;
- String str;
-
-
-#if 0
- while( idx<len ) {
-
-
- CharType c=get_char();
- ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
-
-
- if (c<33 || c==',' || c=='<') {
-
- if (str.length()) {
-
- realsptr[idx]=str.to_double();
- str="";
- idx++;
- }
-
- if (c=='<') {
-
- while(get_char()!='>' && !f->eof_reached()) {}
- ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
- break;
- }
-
- } else {
-
- str+=c;
- }
- }
-
-#else
-
-
-
- Vector<char> tmpdata;
-
- while( idx<len ) {
-
- bool end=false;
- Error err = _parse_array_element(tmpdata,true,f,&end);
- ERR_FAIL_COND_V(err,err);
-
- realsptr[idx]=String::to_double(&tmpdata[0]);
- idx++;
-
- if (end)
- break;
- }
-
-#endif
-
- w=DVector<real_t>::Write();
- r_v=reals;
-
- Error err=goto_end_of_tag();
- ERR_FAIL_COND_V(err,err);
- r_name=name;
-
- return OK;
- } else if (type=="string_array") {
-#if 0
- if (!tag->args.has("len")) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Array missing 'len' field: "+name);
- ERR_FAIL_COND_V(!tag->args.has("len"),ERR_FILE_CORRUPT);
- }
- int len=tag->args["len"].to_int();
-
- DVector<String> strings;
- strings.resize(len);
- DVector<String>::Write w=strings.write();
- String *stringsptr=w.ptr();
- int idx=0;
- String str;
-
- bool inside_str=false;
- CharString cs;
- while( idx<len ) {
-
-
- CharType c=get_char();
- ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
-
-
- if (c=='"') {
- if (inside_str) {
-
- cs.push_back(0);
- String str;
- str.parse_utf8(cs.get_data());
- unquote(str);
- stringsptr[idx]=str;
- cs.clear();
- idx++;
- inside_str=false;
- } else {
- inside_str=true;
- }
- } else if (c=='<') {
-
- while(get_char()!='>' && !f->eof_reached()) {}
- ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
- break;
-
-
- } else if (inside_str){
-
- cs.push_back(c);
- }
- }
- w=DVector<String>::Write();
- r_v=strings;
- String sdfsdfg;
- Error err=parse_property_data(sdfsdfg);
- ERR_FAIL_COND_V(err,err);
-
- r_name=name;
-
- return OK;
-#endif
- if (!tag->args.has("len")) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": String Array missing 'len' field: "+name);
- ERR_FAIL_COND_V(!tag->args.has("len"),ERR_FILE_CORRUPT);
- }
-
-
- int len=tag->args["len"].to_int();
-
- StringArray array;
- array.resize(len);
- DVector<String>::Write w = array.write();
-
- Error err;
- Variant v;
- String tagname;
- int idx=0;
-
-
- while( (err=parse_property(v,tagname))==OK ) {
-
- ERR_CONTINUE( idx <0 || idx >=len );
- String str = v; //convert back to string
- w[idx]=str;
- idx++;
- }
-
- if (idx!=len) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Error loading array (size mismatch): "+name);
- ERR_FAIL_COND_V(idx!=len,err);
- }
-
- if (err!=ERR_FILE_EOF) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Error loading array: "+name);
- ERR_FAIL_COND_V(err!=ERR_FILE_EOF,err);
- }
-
- //err=parse_property_data(name); // skip the rest
- //ERR_FAIL_COND_V(err,err);
-
- r_name=name;
- r_v=array;
- return OK;
-
- } else if (type=="vector3_array") {
-
- if (!tag->args.has("len")) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Array missing 'len' field: "+name);
- ERR_FAIL_COND_V(!tag->args.has("len"),ERR_FILE_CORRUPT);
- }
- int len=tag->args["len"].to_int();;
-
- DVector<Vector3> vectors;
- vectors.resize(len);
- DVector<Vector3>::Write w=vectors.write();
- Vector3 *vectorsptr=w.ptr();
- int idx=0;
- int subidx=0;
- Vector3 auxvec;
- String str;
-
-// uint64_t tbegin = OS::get_singleton()->get_ticks_usec();
-#if 0
- while( idx<len ) {
-
-
- CharType c=get_char();
- ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
-
-
- if (c<33 || c==',' || c=='<') {
-
- if (str.length()) {
-
- auxvec[subidx]=str.to_double();
- subidx++;
- str="";
- if (subidx==3) {
- vectorsptr[idx]=auxvec;
-
- idx++;
- subidx=0;
- }
- }
-
- if (c=='<') {
-
- while(get_char()!='>' && !f->eof_reached()) {}
- ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
- break;
- }
-
- } else {
-
- str+=c;
- }
- }
-#else
-
- Vector<char> tmpdata;
-
- while( idx<len ) {
-
- bool end=false;
- Error err = _parse_array_element(tmpdata,true,f,&end);
- ERR_FAIL_COND_V(err,err);
-
-
- auxvec[subidx]=String::to_double(&tmpdata[0]);
- subidx++;
- if (subidx==3) {
- vectorsptr[idx]=auxvec;
-
- idx++;
- subidx=0;
- }
-
- if (end)
- break;
- }
-
-
-
-#endif
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Premature end of vector3 array");
- ERR_FAIL_COND_V(idx<len,ERR_FILE_CORRUPT);
-// double time_taken = (OS::get_singleton()->get_ticks_usec() - tbegin)/1000000.0;
-
-
- w=DVector<Vector3>::Write();
- r_v=vectors;
- String sdfsdfg;
- Error err=goto_end_of_tag();
- ERR_FAIL_COND_V(err,err);
- r_name=name;
-
- return OK;
-
- } else if (type=="vector2_array") {
-
- if (!tag->args.has("len")) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Array missing 'len' field: "+name);
- ERR_FAIL_COND_V(!tag->args.has("len"),ERR_FILE_CORRUPT);
- }
- int len=tag->args["len"].to_int();;
-
- DVector<Vector2> vectors;
- vectors.resize(len);
- DVector<Vector2>::Write w=vectors.write();
- Vector2 *vectorsptr=w.ptr();
- int idx=0;
- int subidx=0;
- Vector2 auxvec;
- String str;
-
-// uint64_t tbegin = OS::get_singleton()->get_ticks_usec();
-#if 0
- while( idx<len ) {
-
-
- CharType c=get_char();
- ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
-
-
- if (c<22 || c==',' || c=='<') {
-
- if (str.length()) {
-
- auxvec[subidx]=str.to_double();
- subidx++;
- str="";
- if (subidx==2) {
- vectorsptr[idx]=auxvec;
-
- idx++;
- subidx=0;
- }
- }
-
- if (c=='<') {
-
- while(get_char()!='>' && !f->eof_reached()) {}
- ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
- break;
- }
-
- } else {
-
- str+=c;
- }
- }
-#else
-
- Vector<char> tmpdata;
-
- while( idx<len ) {
-
- bool end=false;
- Error err = _parse_array_element(tmpdata,true,f,&end);
- ERR_FAIL_COND_V(err,err);
-
-
- auxvec[subidx]=String::to_double(&tmpdata[0]);
- subidx++;
- if (subidx==2) {
- vectorsptr[idx]=auxvec;
-
- idx++;
- subidx=0;
- }
-
- if (end)
- break;
- }
-
-
-
-#endif
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Premature end of vector2 array");
- ERR_FAIL_COND_V(idx<len,ERR_FILE_CORRUPT);
-// double time_taken = (OS::get_singleton()->get_ticks_usec() - tbegin)/1000000.0;
-
-
- w=DVector<Vector2>::Write();
- r_v=vectors;
- String sdfsdfg;
- Error err=goto_end_of_tag();
- ERR_FAIL_COND_V(err,err);
- r_name=name;
-
- return OK;
-
- } else if (type=="color_array") {
-
- if (!tag->args.has("len")) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Array missing 'len' field: "+name);
- ERR_FAIL_COND_V(!tag->args.has("len"),ERR_FILE_CORRUPT);
- }
- int len=tag->args["len"].to_int();;
-
- DVector<Color> colors;
- colors.resize(len);
- DVector<Color>::Write w=colors.write();
- Color *colorsptr=w.ptr();
- int idx=0;
- int subidx=0;
- Color auxcol;
- String str;
-
- while( idx<len ) {
-
-
- CharType c=get_char();
- ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
-
-
- if (c<33 || c==',' || c=='<') {
-
- if (str.length()) {
-
- auxcol[subidx]=str.to_double();
- subidx++;
- str="";
- if (subidx==4) {
- colorsptr[idx]=auxcol;
- idx++;
- subidx=0;
- }
- }
-
- if (c=='<') {
-
- while(get_char()!='>' && !f->eof_reached()) {}
- ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
- break;
- }
-
- } else {
-
- str+=c;
- }
- }
- w=DVector<Color>::Write();
- r_v=colors;
- String sdfsdfg;
- Error err=parse_property_data(sdfsdfg);
- ERR_FAIL_COND_V(err,err);
- r_name=name;
-
- return OK;
- }
-
-
- String data;
- Error err = parse_property_data(data);
- ERR_FAIL_COND_V(err!=OK,err);
-
- if (type=="nil") {
- // uh do nothing
-
- } else if (type=="bool") {
- // uh do nothing
- if (data.nocasecmp_to("true")==0 || data.to_int()!=0)
- r_v=true;
- else
- r_v=false;
- } else if (type=="int") {
-
- r_v=data.to_int();
- } else if (type=="real") {
-
- r_v=data.to_double();
- } else if (type=="string") {
-
- String str=data;
- unquote(str);
- r_v=str;
- } else if (type=="vector3") {
-
-
- r_v=Vector3(
- data.get_slicec(',',0).to_double(),
- data.get_slicec(',',1).to_double(),
- data.get_slicec(',',2).to_double()
- );
-
- } else if (type=="vector2") {
-
-
- r_v=Vector2(
- data.get_slicec(',',0).to_double(),
- data.get_slicec(',',1).to_double()
- );
-
- } else if (type=="plane") {
-
- r_v=Plane(
- data.get_slicec(',',0).to_double(),
- data.get_slicec(',',1).to_double(),
- data.get_slicec(',',2).to_double(),
- data.get_slicec(',',3).to_double()
- );
-
- } else if (type=="quaternion") {
-
- r_v=Quat(
- data.get_slicec(',',0).to_double(),
- data.get_slicec(',',1).to_double(),
- data.get_slicec(',',2).to_double(),
- data.get_slicec(',',3).to_double()
- );
-
- } else if (type=="rect2") {
-
- r_v=Rect2(
- Vector2(
- data.get_slicec(',',0).to_double(),
- data.get_slicec(',',1).to_double()
- ),
- Vector2(
- data.get_slicec(',',2).to_double(),
- data.get_slicec(',',3).to_double()
- )
- );
-
-
- } else if (type=="aabb") {
-
- r_v=AABB(
- Vector3(
- data.get_slicec(',',0).to_double(),
- data.get_slicec(',',1).to_double(),
- data.get_slicec(',',2).to_double()
- ),
- Vector3(
- data.get_slicec(',',3).to_double(),
- data.get_slicec(',',4).to_double(),
- data.get_slicec(',',5).to_double()
- )
- );
-
- } else if (type=="matrix32") {
-
- Matrix32 m3;
- for (int i=0;i<3;i++) {
- for (int j=0;j<2;j++) {
- m3.elements[i][j]=data.get_slicec(',',i*2+j).to_double();
- }
- }
- r_v=m3;
-
- } else if (type=="matrix3") {
-
- Matrix3 m3;
- for (int i=0;i<3;i++) {
- for (int j=0;j<3;j++) {
- m3.elements[i][j]=data.get_slicec(',',i*3+j).to_double();
- }
- }
- r_v=m3;
-
- } else if (type=="transform") {
-
- Transform tr;
- for (int i=0;i<3;i++) {
- for (int j=0;j<3;j++) {
- tr.basis.elements[i][j]=data.get_slicec(',',i*3+j).to_double();
- }
-
- }
- tr.origin=Vector3(
- data.get_slicec(',',9).to_double(),
- data.get_slicec(',',10).to_double(),
- data.get_slicec(',',11).to_double()
- );
- r_v=tr;
-
- } else if (type=="color") {
-
- r_v=Color(
- data.get_slicec(',',0).to_double(),
- data.get_slicec(',',1).to_double(),
- data.get_slicec(',',2).to_double(),
- data.get_slicec(',',3).to_double()
- );
-
- } else if (type=="node_path") {
-
- String str=data;
- unquote(str);
- r_v=NodePath( str );
- } else if (type=="input_event") {
-
- // ?
- } else {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Unrecognized tag in file: "+type);
- ERR_FAIL_V(ERR_FILE_CORRUPT);
- }
- r_name=name;
- return OK;
-}
-
-
-
-int ResourceInteractiveLoaderXML::get_current_line() const {
-
- return lines;
-}
-
-
-uint8_t ResourceInteractiveLoaderXML::get_char() const {
-
- uint8_t c = f->get_8();
- if (c=='\n')
- lines++;
- return c;
-
-}
-
-
-
-
-///
-
-void ResourceInteractiveLoaderXML::set_local_path(const String& p_local_path) {
-
- res_path=p_local_path;
-}
-
-Ref<Resource> ResourceInteractiveLoaderXML::get_resource() {
-
- return resource;
-}
-Error ResourceInteractiveLoaderXML::poll() {
-
- if (error!=OK)
- return error;
-
- bool exit;
- Tag *tag = parse_tag(&exit);
-
-
- if (!tag) {
- error=ERR_FILE_CORRUPT;
- if (!exit) // shouldn't have exited
- ERR_FAIL_V(error);
- error=ERR_FILE_EOF;
- return error;
- }
-
- RES res;
- //Object *obj=NULL;
-
- bool main;
-
- if (tag->name=="ext_resource") {
-
- error=ERR_FILE_CORRUPT;
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": <ext_resource> missing 'path' field.");
- ERR_FAIL_COND_V(!tag->args.has("path"),ERR_FILE_CORRUPT);
-
- String type="Resource";
- if (tag->args.has("type"))
- type=tag->args["type"];
-
- String path = tag->args["path"];
-
-
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": <ext_resource> can't use a local path, this is a bug?.");
- ERR_FAIL_COND_V(path.begins_with("local://"),ERR_FILE_CORRUPT);
-
- if (path.find("://")==-1 && path.is_rel_path()) {
- // path is relative to file being loaded, so convert to a resource path
- path=GlobalConfig::get_singleton()->localize_path(local_path.get_base_dir().plus_file(path));
- }
-
- if (remaps.has(path)) {
- path=remaps[path];
- }
-
- RES res = ResourceLoader::load(path,type);
-
- if (res.is_null()) {
-
- if (ResourceLoader::get_abort_on_missing_resources()) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": <ext_resource> referenced nonexistent resource at: "+path);
- ERR_FAIL_V(error);
- } else {
- ResourceLoader::notify_dependency_error(local_path,path,type);
- }
- } else {
-
- resource_cache.push_back(res);
- }
-
- if (tag->args.has("index")) {
- ExtResource er;
- er.path=path;
- er.type=type;
- ext_resources[tag->args["index"].to_int()]=er;
- }
-
-
- Error err = close_tag("ext_resource");
- if (err)
- return error;
-
-
- error=OK;
- resource_current++;
- return error;
-
- } else if (tag->name=="resource") {
-
- main=false;
- } else if (tag->name=="main_resource") {
- main=true;
- } else {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": unexpected main tag: "+tag->name);
- error=ERR_FILE_CORRUPT;
- ERR_FAIL_V(error);
- }
-
-
- String type;
- String path;
- int subres=0;
-
- if (!main) {
- //loading resource
-
- error=ERR_FILE_CORRUPT;
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": <resource> missing 'len' field.");
- ERR_FAIL_COND_V(!tag->args.has("path"),ERR_FILE_CORRUPT);
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": <resource> missing 'type' field.");
- ERR_FAIL_COND_V(!tag->args.has("type"),ERR_FILE_CORRUPT);
- path=tag->args["path"];
-
- error=OK;
-
- if (path.begins_with("local://")) {
- //built-in resource (but really external)
-
- path=path.replace("local://","");
- subres=path.to_int();
- path=local_path+"::"+path;
- }
-
-
- if (ResourceCache::has(path)) {
- Error err = close_tag(tag->name);
- if (err) {
- error=ERR_FILE_CORRUPT;
- }
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Unable to close <resource> tag.");
- ERR_FAIL_COND_V( err, err );
- resource_current++;
- error=OK;
- return OK;
- }
-
- type = tag->args["type"];
- } else {
- type=resource_type;
- }
-
- Object *obj = ClassDB::instance(type);
- if (!obj) {
- error=ERR_FILE_CORRUPT;
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Object of unrecognized type in file: "+type);
- }
- ERR_FAIL_COND_V(!obj,ERR_FILE_CORRUPT);
-
- Resource *r = obj->cast_to<Resource>();
- if (!r) {
- error=ERR_FILE_CORRUPT;
- memdelete(obj); //bye
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Object type in resource field not a resource, type is: "+obj->get_class());
- ERR_FAIL_COND_V(!r,ERR_FILE_CORRUPT);
- }
-
- res = RES( r );
- if (path!="")
- r->set_path(path);
- r->set_subindex(subres);
-
- //load properties
-
- while(true) {
-
- String name;
- Variant v;
- Error err;
- err = parse_property(v,name);
- if (err==ERR_FILE_EOF) //tag closed
- break;
- if (err!=OK) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": XML Parsing aborted.");
- ERR_FAIL_COND_V(err!=OK,ERR_FILE_CORRUPT);
- }
-
- obj->set(name,v);
- }
-#ifdef TOOLS_ENABLED
- res->set_edited(false);
-#endif
- resource_cache.push_back(res); //keep it in mem until finished loading
- resource_current++;
- if (main) {
- f->close();
- resource=res;
- if (!ResourceCache::has(res_path)) {
- resource->set_path(res_path);
- }
- error=ERR_FILE_EOF;
- return error;
-
- }
- error=OK;
- return OK;
-}
-
-int ResourceInteractiveLoaderXML::get_stage() const {
-
- return resource_current;
-}
-int ResourceInteractiveLoaderXML::get_stage_count() const {
-
- return resources_total;//+ext_resources;
-}
-
-ResourceInteractiveLoaderXML::~ResourceInteractiveLoaderXML() {
-
- memdelete(f);
-}
-
-void ResourceInteractiveLoaderXML::get_dependencies(FileAccess *f,List<String> *p_dependencies,bool p_add_types) {
-
-
- open(f);
- ERR_FAIL_COND(error!=OK);
-
- while(true) {
- bool exit;
- Tag *tag = parse_tag(&exit);
-
-
- if (!tag) {
- error=ERR_FILE_CORRUPT;
- ERR_FAIL_COND(!exit);
- error=ERR_FILE_EOF;
- return;
- }
-
- if (tag->name!="ext_resource") {
-
- return;
- }
-
- error=ERR_FILE_CORRUPT;
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": <ext_resource> missing 'path' field.");
- ERR_FAIL_COND(!tag->args.has("path"));
-
- String path = tag->args["path"];
-
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": <ext_resource> can't use a local path, this is a bug?.");
- ERR_FAIL_COND(path.begins_with("local://"));
-
- if (path.find("://")==-1 && path.is_rel_path()) {
- // path is relative to file being loaded, so convert to a resource path
- path=GlobalConfig::get_singleton()->localize_path(local_path.get_base_dir().plus_file(path));
- }
-
- if (path.ends_with("*")) {
- ERR_FAIL_COND(!tag->args.has("type"));
- String type = tag->args["type"];
- path = ResourceLoader::guess_full_filename(path,type);
- }
-
- if (p_add_types && tag->args.has("type")) {
- path+="::"+tag->args["type"];
- }
-
- p_dependencies->push_back(path);
-
- Error err = close_tag("ext_resource");
- if (err)
- return;
-
- error=OK;
- }
-
-}
-
-Error ResourceInteractiveLoaderXML::rename_dependencies(FileAccess *p_f, const String &p_path,const Map<String,String>& p_map) {
-
- open(p_f);
- ERR_FAIL_COND_V(error!=OK,error);
-
- //FileAccess
-
- bool old_format=false;
-
- FileAccess *fw = NULL;
-
- String base_path=local_path.get_base_dir();
-
- while(true) {
- bool exit;
- List<String> order;
-
- Tag *tag = parse_tag(&exit,true,&order);
-
- bool done=false;
-
- if (!tag) {
- if (fw) {
- memdelete(fw);
- }
- error=ERR_FILE_CORRUPT;
- ERR_FAIL_COND_V(!exit,error);
- error=ERR_FILE_EOF;
-
- return error;
- }
-
- if (tag->name=="ext_resource") {
-
- if (!tag->args.has("index") || !tag->args.has("path") || !tag->args.has("type")) {
- old_format=true;
- break;
- }
-
- if (!fw) {
-
- fw=FileAccess::open(p_path+".depren",FileAccess::WRITE);
- fw->store_line("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"); //no escape
- fw->store_line("<resource_file type=\""+resource_type+"\" subresource_count=\""+itos(resources_total)+"\" version=\""+itos(VERSION_MAJOR)+"."+itos(VERSION_MINOR)+"\" version_name=\""+VERSION_FULL_NAME+"\">");
-
- }
-
- String path = tag->args["path"];
- String index = tag->args["index"];
- String type = tag->args["type"];
-
-
- bool relative=false;
- if (!path.begins_with("res://")) {
- path=base_path.plus_file(path).simplify_path();
- relative=true;
- }
-
-
- if (p_map.has(path)) {
- String np=p_map[path];
- path=np;
- }
-
- if (relative) {
- //restore relative
- path=base_path.path_to_file(path);
- }
-
- tag->args["path"]=path;
- tag->args["index"]=index;
- tag->args["type"]=type;
-
- } else {
-
- done=true;
- }
-
- String tagt="\t<";
- if (exit)
- tagt+="/";
- tagt+=tag->name;
-
- for(List<String>::Element *E=order.front();E;E=E->next()) {
- tagt+=" "+E->get()+"=\""+tag->args[E->get()]+"\"";
- }
- tagt+=">";
- fw->store_line(tagt);
- if (done)
- break;
- close_tag("ext_resource");
- fw->store_line("\t</ext_resource>");
-
- }
-
-
- if (old_format) {
- if (fw)
- memdelete(fw);
-
- DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
- da->remove(p_path+".depren");
- memdelete(da);
- //fuck it, use the old approach;
-
- WARN_PRINT(("This file is old, so it can't refactor dependencies, opening and resaving: "+p_path).utf8().get_data());
-
- Error err;
- FileAccess *f2 = FileAccess::open(p_path,FileAccess::READ,&err);
- if (err!=OK) {
- ERR_FAIL_COND_V(err!=OK,ERR_FILE_CANT_OPEN);
- }
-
- Ref<ResourceInteractiveLoaderXML> ria = memnew( ResourceInteractiveLoaderXML );
- ria->local_path=GlobalConfig::get_singleton()->localize_path(p_path);
- ria->res_path=ria->local_path;
- ria->remaps=p_map;
- // ria->set_local_path( Globals::get_singleton()->localize_path(p_path) );
- ria->open(f2);
-
- err = ria->poll();
-
- while(err==OK) {
- err=ria->poll();
- }
-
- ERR_FAIL_COND_V(err!=ERR_FILE_EOF,ERR_FILE_CORRUPT);
- RES res = ria->get_resource();
- ERR_FAIL_COND_V(!res.is_valid(),ERR_FILE_CORRUPT);
-
- return ResourceFormatSaverXML::singleton->save(p_path,res);
- }
-
- if (!fw) {
-
- return OK; //nothing to rename, do nothing
- }
-
- uint8_t c=f->get_8();
- while(!f->eof_reached()) {
- fw->store_8(c);
- c=f->get_8();
- }
- f->close();
-
- bool all_ok = fw->get_error()==OK;
-
- memdelete(fw);
-
- if (!all_ok) {
- return ERR_CANT_CREATE;
- }
-
- DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
- da->remove(p_path);
- da->rename(p_path+".depren",p_path);
- memdelete(da);
-
- return OK;
-
-}
-
-
-void ResourceInteractiveLoaderXML::open(FileAccess *p_f) {
-
- error=OK;
-
- lines=1;
- f=p_f;
-
-
- ResourceInteractiveLoaderXML::Tag *tag = parse_tag();
- if (!tag || tag->name!="?xml" || !tag->args.has("version") || !tag->args.has("encoding") || tag->args["encoding"]!="UTF-8") {
-
- error=ERR_FILE_CORRUPT;
- ResourceLoader::notify_load_error("XML is invalid (missing header tags)");
- ERR_EXPLAIN("Not a XML:UTF-8 File: "+local_path);
- ERR_FAIL();
- }
-
- tag_stack.clear();
-
- tag = parse_tag();
-
-
- if (!tag || tag->name!="resource_file" || !tag->args.has("type") || !tag->args.has("version")) {
-
- ResourceLoader::notify_load_error(local_path+": XML is not a valid resource file.");
- error=ERR_FILE_CORRUPT;
- ERR_EXPLAIN("Unrecognized XML File: "+local_path);
- ERR_FAIL();
- }
-
-
- if (tag->args.has("subresource_count"))
- resources_total=tag->args["subresource_count"].to_int();
- resource_current=0;
- resource_type=tag->args["type"];
-
- String version = tag->args["version"];
- if (version.get_slice_count(".")!=2) {
-
- error=ERR_FILE_CORRUPT;
- ResourceLoader::notify_load_error(local_path+":XML version string is invalid: "+version);
- ERR_EXPLAIN("Invalid Version String '"+version+"'' in file: "+local_path);
- ERR_FAIL();
- }
-
- int major = version.get_slicec('.',0).to_int();
- if (major>VERSION_MAJOR) {
-
- error=ERR_FILE_UNRECOGNIZED;
- ResourceLoader::notify_load_error(local_path+": File Format '"+version+"' is too new. Please upgrade to a newer engine version.");
- ERR_EXPLAIN("File Format '"+version+"' is too new! Please upgrade to a a new engine version: "+local_path);
- ERR_FAIL();
-
- }
-
- /*
- String preload_depts = "deps/"+local_path.md5_text();
- if (Globals::get_singleton()->has(preload_depts)) {
- ext_resources.clear();
- //ignore external resources and use these
- NodePath depts=Globals::get_singleton()->get(preload_depts);
-
- for(int i=0;i<depts.get_name_count();i++) {
- ext_resources.push_back(depts.get_name(i));
- }
- print_line(local_path+" - EXTERNAL RESOURCES: "+itos(ext_resources.size()));
- }
-*/
-
-}
-
-String ResourceInteractiveLoaderXML::recognize(FileAccess *p_f) {
-
- error=OK;
-
- lines=1;
- f=p_f;
-
- ResourceInteractiveLoaderXML::Tag *tag = parse_tag();
- if (!tag || tag->name!="?xml" || !tag->args.has("version") || !tag->args.has("encoding") || tag->args["encoding"]!="UTF-8") {
-
-
- return ""; //unrecognized
- }
-
- tag_stack.clear();
-
- tag = parse_tag();
-
- if (!tag || tag->name!="resource_file" || !tag->args.has("type") || !tag->args.has("version")) {
-
- return ""; //unrecognized
- }
-
- return tag->args["type"];
-
-}
-
-/////////////////////
-
-Ref<ResourceInteractiveLoader> ResourceFormatLoaderXML::load_interactive(const String &p_path, Error *r_error) {
-
- if (r_error)
- *r_error=ERR_CANT_OPEN;
-
- Error err;
- FileAccess *f = FileAccess::open(p_path,FileAccess::READ,&err);
-
-
- if (err!=OK) {
-
- ERR_FAIL_COND_V(err!=OK,Ref<ResourceInteractiveLoader>());
- }
-
- Ref<ResourceInteractiveLoaderXML> ria = memnew( ResourceInteractiveLoaderXML );
- ria->local_path=GlobalConfig::get_singleton()->localize_path(p_path);
- ria->res_path=ria->local_path;
-// ria->set_local_path( Globals::get_singleton()->localize_path(p_path) );
- ria->open(f);
-
- return ria;
-}
-
-void ResourceFormatLoaderXML::get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions) const {
-
- if (p_type=="") {
- get_recognized_extensions(p_extensions);
- return;
- }
-
- List<String> extensions;
- ClassDB::get_extensions_for_type(p_type,&extensions);
-
- extensions.sort();
-
- for(List<String>::Element *E=extensions.front();E;E=E->next()) {
- String ext = E->get().to_lower();
- if (ext=="res")
- continue;
- p_extensions->push_back("x"+ext);
- }
-
- p_extensions->push_back("xml");
-
-
-}
-void ResourceFormatLoaderXML::get_recognized_extensions(List<String> *p_extensions) const{
-
- List<String> extensions;
- ClassDB::get_resource_base_extensions(&extensions);
- extensions.sort();
-
- for(List<String>::Element *E=extensions.front();E;E=E->next()) {
- String ext = E->get().to_lower();
- if (ext=="res")
- continue;
- p_extensions->push_back("x"+ext);
- }
-
- p_extensions->push_back("xml");
-}
-
-bool ResourceFormatLoaderXML::handles_type(const String& p_type) const{
-
- return true;
-}
-String ResourceFormatLoaderXML::get_resource_type(const String &p_path) const{
-
-
- String ext=p_path.extension().to_lower();
- if (!ext.begins_with("x")) //a lie but..
- return "";
-
- FileAccess *f = FileAccess::open(p_path,FileAccess::READ);
- if (!f) {
-
- return ""; //could not rwead
- }
-
- Ref<ResourceInteractiveLoaderXML> ria = memnew( ResourceInteractiveLoaderXML );
- ria->local_path=GlobalConfig::get_singleton()->localize_path(p_path);
- ria->res_path=ria->local_path;
-// ria->set_local_path( Globals::get_singleton()->localize_path(p_path) );
- String r = ria->recognize(f);
- return r;
-}
-
-
-void ResourceFormatLoaderXML::get_dependencies(const String& p_path,List<String> *p_dependencies,bool p_add_types) {
-
- FileAccess *f = FileAccess::open(p_path,FileAccess::READ);
- if (!f) {
-
- ERR_FAIL();
- }
-
- Ref<ResourceInteractiveLoaderXML> ria = memnew( ResourceInteractiveLoaderXML );
- ria->local_path=GlobalConfig::get_singleton()->localize_path(p_path);
- ria->res_path=ria->local_path;
-// ria->set_local_path( Globals::get_singleton()->localize_path(p_path) );
- ria->get_dependencies(f,p_dependencies,p_add_types);
-
-
-}
-
-Error ResourceFormatLoaderXML::rename_dependencies(const String &p_path,const Map<String,String>& p_map) {
-
- FileAccess *f = FileAccess::open(p_path,FileAccess::READ);
- if (!f) {
-
- ERR_FAIL_V(ERR_CANT_OPEN);
- }
-
- Ref<ResourceInteractiveLoaderXML> ria = memnew( ResourceInteractiveLoaderXML );
- ria->local_path=GlobalConfig::get_singleton()->localize_path(p_path);
- ria->res_path=ria->local_path;
-// ria->set_local_path( Globals::get_singleton()->localize_path(p_path) );
- return ria->rename_dependencies(f,p_path,p_map);
-}
-
-
-/****************************************************************************************/
-/****************************************************************************************/
-/****************************************************************************************/
-/****************************************************************************************/
-/****************************************************************************************/
-/****************************************************************************************/
-/****************************************************************************************/
-/****************************************************************************************/
-/****************************************************************************************/
-/****************************************************************************************/
-/****************************************************************************************/
-/****************************************************************************************/
-/****************************************************************************************/
-
-
-
-void ResourceFormatSaverXMLInstance::escape(String& p_str) {
-
- p_str=p_str.replace("&","&amp;");
- p_str=p_str.replace("<","&lt;");
- p_str=p_str.replace(">","&gt;");
- p_str=p_str.replace("'","&apos;");
- p_str=p_str.replace("\"","&quot;");
- for (char i=1;i<32;i++) {
-
- char chr[2]={i,0};
- const char hexn[16]={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
- const char hex[8]={'&','#','0','0',hexn[i>>4],hexn[i&0xf],';',0};
-
- p_str=p_str.replace(chr,hex);
- }
-
-
-}
-void ResourceFormatSaverXMLInstance::write_tabs(int p_diff) {
-
- for (int i=0;i<depth+p_diff;i++) {
-
- f->store_8('\t');
- }
-}
-
-void ResourceFormatSaverXMLInstance::write_string(String p_str,bool p_escape) {
-
- /* write an UTF8 string */
- if (p_escape)
- escape(p_str);
-
- f->store_string(p_str);;
- /*
- CharString cs=p_str.utf8();
- const char *data=cs.get_data();
-
- while (*data) {
- f->store_8(*data);
- data++;
- }*/
-
-
-}
-
-void ResourceFormatSaverXMLInstance::enter_tag(const char* p_tag,const String& p_args) {
-
- f->store_8('<');
- int cc = 0;
- const char *c=p_tag;
- while(*c) {
- cc++;
- c++;
- }
- f->store_buffer((const uint8_t*)p_tag,cc);
- if (p_args.length()) {
- f->store_8(' ');
- f->store_string(p_args);
- }
- f->store_8('>');
- depth++;
-
-}
-void ResourceFormatSaverXMLInstance::exit_tag(const char* p_tag) {
-
- depth--;
- f->store_8('<');
- f->store_8('/');
- int cc = 0;
- const char *c=p_tag;
- while(*c) {
- cc++;
- c++;
- }
- f->store_buffer((const uint8_t*)p_tag,cc);
- f->store_8('>');
-
-}
-
-/*
-static bool _check_type(const Variant& p_property) {
-
- if (p_property.get_type()==Variant::_RID)
- return false;
- if (p_property.get_type()==Variant::OBJECT) {
- RES res = p_property;
- if (res.is_null())
- return false;
- }
-
- return true;
-}*/
-
-void ResourceFormatSaverXMLInstance::write_property(const String& p_name,const Variant& p_property,bool *r_ok) {
-
- if (r_ok)
- *r_ok=false;
-
- const char* type;
- String params;
- bool oneliner=true;
-
- switch( p_property.get_type() ) {
-
- case Variant::NIL: type="nil"; break;
- case Variant::BOOL: type="bool"; break;
- case Variant::INT: type="int"; break;
- case Variant::REAL: type="real"; break;
- case Variant::STRING: type="string"; break;
- case Variant::VECTOR2: type="vector2"; break;
- case Variant::RECT2: type="rect2"; break;
- case Variant::VECTOR3: type="vector3"; break;
- case Variant::PLANE: type="plane"; break;
- case Variant::_AABB: type="aabb"; break;
- case Variant::QUAT: type="quaternion"; break;
- case Variant::MATRIX32: type="matrix32"; break;
- case Variant::MATRIX3: type="matrix3"; break;
- case Variant::TRANSFORM: type="transform"; break;
- case Variant::COLOR: type="color"; break;
- case Variant::IMAGE: {
- type="image";
- Image img=p_property;
- if (img.empty()) {
- write_tabs();
- enter_tag(type,"name=\""+p_name+"\"");
- exit_tag(type);
- if (r_ok)
- *r_ok=true;
- return;
- }
- params+="encoding=\"raw\"";
- params+=" width=\""+itos(img.get_width())+"\"";
- params+=" height=\""+itos(img.get_height())+"\"";
- params+=" mipmaps=\""+itos(img.has_mipmaps())+"\"";
-/*
- switch(img.get_format()) {
-
- case Image::FORMAT_L8: params+=" format=\"grayscale\""; break;
- case Image::FORMAT_INTENSITY: params+=" format=\"intensity\""; break;
- case Image::FORMAT_LA8: params+=" format=\"grayscale_alpha\""; break;
- case Image::FORMAT_RGB8: params+=" format=\"rgb\""; break;
- case Image::FORMAT_RGBA8: params+=" format=\"rgba\""; break;
- case Image::FORMAT_INDEXED : params+=" format=\"indexed\""; break;
- case Image::FORMAT_INDEXED_ALPHA: params+=" format=\"indexed_alpha\""; break;
- case Image::FORMAT_DXT1: params+=" format=\"bc1\""; break;
- case Image::FORMAT_DXT3: params+=" format=\"bc2\""; break;
- case Image::FORMAT_DXT5: params+=" format=\"bc3\""; break;
- case Image::FORMAT_ATI1: params+=" format=\"bc4\""; break;
- case Image::FORMAT_ATI2: params+=" format=\"bc5\""; break;
- case Image::FORMAT_PVRTC2: params+=" format=\"pvrtc2\""; break;
- case Image::FORMAT_PVRTC2A: params+=" format=\"pvrtc2a\""; break;
- case Image::FORMAT_PVRTC4: params+=" format=\"pvrtc4\""; break;
- case Image::FORMAT_PVRTC4A: params+=" format=\"pvrtc4a\""; break;
- case Image::FORMAT_ETC: params+=" format=\"etc\""; break;
- case Image::FORMAT_ATC: params+=" format=\"atc\""; break;
- case Image::FORMAT_ATC_ALPHA_EXPLICIT: params+=" format=\"atcae\""; break;
- case Image::FORMAT_ATC_ALPHA_INTERPOLATED: params+=" format=\"atcai\""; break;
- case Image::FORMAT_CUSTOM: params+=" format=\"custom\" custom_size=\""+itos(img.get_data().size())+"\""; break;
- default: {}
- }*/
- } break;
- case Variant::NODE_PATH: type="node_path"; break;
- case Variant::OBJECT: {
- type="resource";
- RES res = p_property;
- if (res.is_null()) {
- write_tabs();
- enter_tag(type,"name=\""+p_name+"\"");
- exit_tag(type);
- if (r_ok)
- *r_ok=true;
-
- return; // don't save it
- }
-
- if (external_resources.has(res)) {
-
- params="external=\""+itos(external_resources[res])+"\"";
- } else {
- params="resource_type=\""+res->get_save_class()+"\"";
-
-
- if (res->get_path().length() && res->get_path().find("::")==-1) {
- //external resource
- String path=relative_paths?local_path.path_to_file(res->get_path()):res->get_path();
- escape(path);
- params+=" path=\""+path+"\"";
- } else {
-
- //internal resource
- ERR_EXPLAIN("Resource was not pre cached for the resource section, bug?");
- ERR_FAIL_COND(!resource_set.has(res));
-
- params+=" path=\"local://"+itos(res->get_subindex())+"\"";
- }
- }
-
- } break;
- case Variant::INPUT_EVENT: type="input_event"; break;
- case Variant::DICTIONARY: type="dictionary"; params="shared=\""+String(p_property.is_shared()?"true":"false")+"\""; oneliner=false; break;
- case Variant::ARRAY: type="array"; params="len=\""+itos(p_property.operator Array().size())+"\" shared=\""+String(p_property.is_shared()?"true":"false")+"\""; oneliner=false; break;
-
- case Variant::RAW_ARRAY: type="raw_array"; params="len=\""+itos(p_property.operator DVector < uint8_t >().size())+"\""; break;
- case Variant::INT_ARRAY: type="int_array"; params="len=\""+itos(p_property.operator DVector < int >().size())+"\""; break;
- case Variant::REAL_ARRAY: type="real_array"; params="len=\""+itos(p_property.operator DVector < real_t >().size())+"\""; break;
- case Variant::STRING_ARRAY: oneliner=false; type="string_array"; params="len=\""+itos(p_property.operator DVector < String >().size())+"\""; break;
- case Variant::VECTOR2_ARRAY: type="vector2_array"; params="len=\""+itos(p_property.operator DVector < Vector2 >().size())+"\""; break;
- case Variant::VECTOR3_ARRAY: type="vector3_array"; params="len=\""+itos(p_property.operator DVector < Vector3 >().size())+"\""; break;
- case Variant::COLOR_ARRAY: type="color_array"; params="len=\""+itos(p_property.operator DVector < Color >().size())+"\""; break;
- default: {
-
- ERR_PRINT("Unknown Variant type.");
- ERR_FAIL();
- }
-
- }
-
- write_tabs();
-
- if (p_name!="") {
- if (params.length())
- enter_tag(type,"name=\""+p_name+"\" "+params);
- else
- enter_tag(type,"name=\""+p_name+"\"");
- } else {
- if (params.length())
- enter_tag(type," "+params);
- else
- enter_tag(type,String());
- }
-
- if (!oneliner)
- f->store_8('\n');
- else
- f->store_8(' ');
-
-
- switch( p_property.get_type() ) {
-
- case Variant::NIL: {
-
- } break;
- case Variant::BOOL: {
-
- write_string( p_property.operator bool() ? "True":"False" );
- } break;
- case Variant::INT: {
-
- write_string( itos(p_property.operator int()) );
- } break;
- case Variant::REAL: {
-
- write_string( rtos(p_property.operator real_t()) );
- } break;
- case Variant::STRING: {
-
- String str=p_property;
- escape(str);
- str="\""+str+"\"";
- write_string( str,false );
- } break;
- case Variant::VECTOR2: {
-
- Vector2 v = p_property;
- write_string( rtoss(v.x) +", "+rtoss(v.y) );
- } break;
- case Variant::RECT2: {
-
- Rect2 aabb = p_property;
- write_string( rtoss(aabb.pos.x) +", "+rtoss(aabb.pos.y) +", "+rtoss(aabb.size.x) +", "+rtoss(aabb.size.y) );
-
- } break;
- case Variant::VECTOR3: {
-
- Vector3 v = p_property;
- write_string( rtoss(v.x) +", "+rtoss(v.y)+", "+rtoss(v.z) );
- } break;
- case Variant::PLANE: {
-
- Plane p = p_property;
- write_string( rtoss(p.normal.x) +", "+rtoss(p.normal.y)+", "+rtoss(p.normal.z)+", "+rtoss(p.d) );
-
- } break;
- case Variant::_AABB: {
-
- AABB aabb = p_property;
- write_string( rtoss(aabb.pos.x) +", "+rtoss(aabb.pos.y) +", "+rtoss(aabb.pos.z) +", "+rtoss(aabb.size.x) +", "+rtoss(aabb.size.y) +", "+rtoss(aabb.size.z) );
-
- } break;
- case Variant::QUAT: {
-
- Quat quat = p_property;
- write_string( rtoss(quat.x)+", "+rtoss(quat.y)+", "+rtoss(quat.z)+", "+rtoss(quat.w)+", ");
-
- } break;
- case Variant::MATRIX32: {
-
- String s;
- Matrix32 m3 = p_property;
- for (int i=0;i<3;i++) {
- for (int j=0;j<2;j++) {
-
- if (i!=0 || j!=0)
- s+=", ";
- s+=rtoss( m3.elements[i][j] );
- }
- }
-
- write_string(s);
-
- } break;
- case Variant::MATRIX3: {
-
- String s;
- Matrix3 m3 = p_property;
- for (int i=0;i<3;i++) {
- for (int j=0;j<3;j++) {
-
- if (i!=0 || j!=0)
- s+=", ";
- s+=rtoss( m3.elements[i][j] );
- }
- }
-
- write_string(s);
-
- } break;
- case Variant::TRANSFORM: {
-
- String s;
- Transform t = p_property;
- Matrix3 &m3 = t.basis;
- for (int i=0;i<3;i++) {
- for (int j=0;j<3;j++) {
-
- if (i!=0 || j!=0)
- s+=", ";
- s+=rtoss( m3.elements[i][j] );
- }
- }
-
- s=s+", "+rtoss(t.origin.x) +", "+rtoss(t.origin.y)+", "+rtoss(t.origin.z);
-
- write_string(s);
- } break;
-
- // misc types
- case Variant::COLOR: {
-
- Color c = p_property;
- write_string( rtoss(c.r) +", "+rtoss(c.g)+", "+rtoss(c.b)+", "+rtoss(c.a) );
-
- } break;
- case Variant::IMAGE: {
-
- String s;
- Image img = p_property;
- DVector<uint8_t> data = img.get_data();
- int len = data.size();
- DVector<uint8_t>::Read r = data.read();
- const uint8_t *ptr=r.ptr();;
- for (int i=0;i<len;i++) {
-
- uint8_t byte = ptr[i];
- const char hex[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
- char str[3]={ hex[byte>>4], hex[byte&0xF], 0};
- s+=str;
- }
-
- write_string(s);
- } break;
- case Variant::NODE_PATH: {
-
- String str=p_property;
- escape(str);
- str="\""+str+"\"";
- write_string( str,false);
-
- } break;
-
- case Variant::OBJECT: {
- /* this saver does not save resources in here
- RES res = p_property;
-
- if (!res.is_null()) {
-
- String path=res->get_path();
- if (!res->is_shared() || !path.length()) {
- // if no path, or path is from inside a scene
- write_object( *res );
- }
-
- }
- */
-
- } break;
- case Variant::INPUT_EVENT: {
-
- write_string( p_property.operator String() );
- } break;
- case Variant::DICTIONARY: {
-
- Dictionary dict = p_property;
-
-
- List<Variant> keys;
- dict.get_key_list(&keys);
- keys.sort();
-
- for(List<Variant>::Element *E=keys.front();E;E=E->next()) {
-
- //if (!_check_type(dict[E->get()]))
- // continue;
- bool ok;
- write_property("",E->get(),&ok);
- ERR_CONTINUE(!ok);
-
- write_property("",dict[E->get()],&ok);
- if (!ok)
- write_property("",Variant()); //at least make the file consistent..
- }
-
-
-
-
- } break;
- case Variant::ARRAY: {
-
- Array array = p_property;
- int len=array.size();
- for (int i=0;i<len;i++) {
-
- write_property("",array[i]);
-
- }
-
- } break;
-
- case Variant::RAW_ARRAY: {
-
- String s;
- DVector<uint8_t> data = p_property;
- int len = data.size();
- DVector<uint8_t>::Read r = data.read();
- const uint8_t *ptr=r.ptr();;
- for (int i=0;i<len;i++) {
-
- uint8_t byte = ptr[i];
- const char hex[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
- char str[3]={ hex[byte>>4], hex[byte&0xF], 0};
- s+=str;
- }
-
- write_string(s,false);
-
- } break;
- case Variant::INT_ARRAY: {
-
- DVector<int> data = p_property;
- int len = data.size();
- DVector<int>::Read r = data.read();
- const int *ptr=r.ptr();;
- write_tabs();
-
- for (int i=0;i<len;i++) {
-
- if (i>0)
- write_string(", ",false);
-
- write_string(itos(ptr[i]),false);
- }
-
-
-
- } break;
- case Variant::REAL_ARRAY: {
-
- DVector<real_t> data = p_property;
- int len = data.size();
- DVector<real_t>::Read r = data.read();
- const real_t *ptr=r.ptr();;
- write_tabs();
- String cm=", " ;
-
- for (int i=0;i<len;i++) {
-
- if (i>0)
- write_string(cm,false);
- write_string(rtoss(ptr[i]),false);
- }
-
-
- } break;
- case Variant::STRING_ARRAY: {
-
- DVector<String> data = p_property;
- int len = data.size();
- DVector<String>::Read r = data.read();
- const String *ptr=r.ptr();;
- String s;
- //write_string("\n");
-
-
-
- for (int i=0;i<len;i++) {
-
- write_tabs(0);
- String str=ptr[i];
- escape(str);
- write_string("<string> \""+str+"\" </string>\n",false);
- }
- } break;
- case Variant::VECTOR2_ARRAY: {
-
- DVector<Vector2> data = p_property;
- int len = data.size();
- DVector<Vector2>::Read r = data.read();
- const Vector2 *ptr=r.ptr();;
- write_tabs();
-
- for (int i=0;i<len;i++) {
-
- if (i>0)
- write_string(", ",false);
- write_string(rtoss(ptr[i].x),false);
- write_string(", "+rtoss(ptr[i].y),false);
-
- }
-
-
- } break;
- case Variant::VECTOR3_ARRAY: {
-
- DVector<Vector3> data = p_property;
- int len = data.size();
- DVector<Vector3>::Read r = data.read();
- const Vector3 *ptr=r.ptr();;
- write_tabs();
-
- for (int i=0;i<len;i++) {
-
- if (i>0)
- write_string(", ",false);
- write_string(rtoss(ptr[i].x),false);
- write_string(", "+rtoss(ptr[i].y),false);
- write_string(", "+rtoss(ptr[i].z),false);
-
- }
-
-
- } break;
- case Variant::COLOR_ARRAY: {
-
- DVector<Color> data = p_property;
- int len = data.size();
- DVector<Color>::Read r = data.read();
- const Color *ptr=r.ptr();;
- write_tabs();
-
- for (int i=0;i<len;i++) {
-
- if (i>0)
- write_string(", ",false);
-
- write_string(rtoss(ptr[i].r),false);
- write_string(", "+rtoss(ptr[i].g),false);
- write_string(", "+rtoss(ptr[i].b),false);
- write_string(", "+rtoss(ptr[i].a),false);
-
- }
-
- } break;
- default: {}
-
- }
- if (oneliner)
- f->store_8(' ');
- else
- write_tabs(-1);
- exit_tag(type);
-
- f->store_8('\n');
-
- if (r_ok)
- *r_ok=true;
-
-}
-
-
-void ResourceFormatSaverXMLInstance::_find_resources(const Variant& p_variant,bool p_main) {
-
-
- switch(p_variant.get_type()) {
- case Variant::OBJECT: {
-
-
- RES res = p_variant.operator RefPtr();
-
- if (res.is_null() || external_resources.has(res))
- return;
-
- if (!p_main && (!bundle_resources ) && res->get_path().length() && res->get_path().find("::") == -1 ) {
- int index = external_resources.size();
- external_resources[res]=index;
- return;
- }
-
- if (resource_set.has(res))
- return;
-
- List<PropertyInfo> property_list;
-
- res->get_property_list( &property_list );
- property_list.sort();
-
- List<PropertyInfo>::Element *I=property_list.front();
-
- while(I) {
-
- PropertyInfo pi=I->get();
-
- if (pi.usage&PROPERTY_USAGE_STORAGE) {
-
- Variant v=res->get(I->get().name);
- _find_resources(v);
- }
-
- I=I->next();
- }
-
- resource_set.insert( res ); //saved after, so the childs it needs are available when loaded
- saved_resources.push_back(res);
-
- } break;
- case Variant::ARRAY: {
-
- Array varray=p_variant;
- int len=varray.size();
- for(int i=0;i<len;i++) {
-
- Variant v=varray.get(i);
- _find_resources(v);
- }
-
- } break;
- case Variant::DICTIONARY: {
-
- Dictionary d=p_variant;
- List<Variant> keys;
- d.get_key_list(&keys);
- for(List<Variant>::Element *E=keys.front();E;E=E->next()) {
-
- Variant v = d[E->get()];
- _find_resources(v);
- }
- } break;
- default: {}
- }
-
-}
-
-
-
-Error ResourceFormatSaverXMLInstance::save(const String &p_path,const RES& p_resource,uint32_t p_flags) {
-
- Error err;
- f = FileAccess::open(p_path, FileAccess::WRITE,&err);
- ERR_FAIL_COND_V( err, ERR_CANT_OPEN );
- FileAccessRef _fref(f);
-
- local_path = GlobalConfig::get_singleton()->localize_path(p_path);
-
- relative_paths=p_flags&ResourceSaver::FLAG_RELATIVE_PATHS;
- skip_editor=p_flags&ResourceSaver::FLAG_OMIT_EDITOR_PROPERTIES;
- bundle_resources=p_flags&ResourceSaver::FLAG_BUNDLE_RESOURCES;
- takeover_paths=p_flags&ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS;
- if (!p_path.begins_with("res://")) {
- takeover_paths=false;
- }
- depth=0;
-
- // save resources
- _find_resources(p_resource,true);
-
- ERR_FAIL_COND_V(err!=OK,err);
-
- write_string("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>",false); //no escape
- write_string("\n",false);
- enter_tag("resource_file","type=\""+p_resource->get_class()+"\" subresource_count=\""+itos(saved_resources.size()+external_resources.size())+"\" version=\""+itos(VERSION_MAJOR)+"."+itos(VERSION_MINOR)+"\" version_name=\""+VERSION_FULL_NAME+"\"");
- write_string("\n",false);
-
- for(Map<RES,int>::Element *E=external_resources.front();E;E=E->next()) {
-
- write_tabs();
- String p = E->key()->get_path();
-
- enter_tag("ext_resource","path=\""+p+"\" type=\""+E->key()->get_save_class()+"\" index=\""+itos(E->get())+"\""); //bundled
- exit_tag("ext_resource"); //bundled
- write_string("\n",false);
- }
-
- Set<int> used_indices;
-
- for(List<RES>::Element *E=saved_resources.front();E;E=E->next()) {
-
- RES res = E->get();
- if (E->next() && (res->get_path()=="" || res->get_path().find("::") != -1 )) {
-
- if (res->get_subindex()!=0) {
- if (used_indices.has(res->get_subindex())) {
- res->set_subindex(0); //repeated
- } else {
- used_indices.insert(res->get_subindex());
- }
- }
- }
- }
-
- for(List<RES>::Element *E=saved_resources.front();E;E=E->next()) {
-
- RES res = E->get();
- ERR_CONTINUE(!resource_set.has(res));
- bool main = (E->next()==NULL);
-
- write_tabs();
-
- if (main)
- enter_tag("main_resource",""); //bundled
- else if (res->get_path().length() && res->get_path().find("::") == -1 )
- enter_tag("resource","type=\""+res->get_class()+"\" path=\""+res->get_path()+"\""); //bundled
- else {
-
- if (res->get_subindex()==0) {
- int new_subindex=1;
- if (used_indices.size()) {
- new_subindex=used_indices.back()->get()+1;
- }
-
- res->set_subindex(new_subindex);
- used_indices.insert(new_subindex);
- }
-
- int idx = res->get_subindex();
- enter_tag("resource","type=\""+res->get_class()+"\" path=\"local://"+itos(idx)+"\"");
- if (takeover_paths) {
- res->set_path(p_path+"::"+itos(idx),true);
- }
-#ifdef TOOLS_ENABLED
- res->set_edited(false);
-#endif
-
-
- }
- write_string("\n",false);
-
-
- List<PropertyInfo> property_list;
- res->get_property_list(&property_list);
-// property_list.sort();
- for(List<PropertyInfo>::Element *PE = property_list.front();PE;PE=PE->next()) {
-
-
- if (skip_editor && PE->get().name.begins_with("__editor"))
- continue;
-
- if (PE->get().usage&PROPERTY_USAGE_STORAGE ) {
-
- String name = PE->get().name;
- Variant value = res->get(name);
-
-
- if ((PE->get().usage&PROPERTY_USAGE_STORE_IF_NONZERO && value.is_zero())||(PE->get().usage&PROPERTY_USAGE_STORE_IF_NONONE && value.is_one()) )
- continue;
-
-
- write_property(name,value);
- }
-
-
- }
-
- write_string("\n",false);
- write_tabs(-1);
- if (main)
- exit_tag("main_resource");
- else
- exit_tag("resource");
-
- write_string("\n",false);
- }
-
- exit_tag("resource_file");
- if (f->get_error()!=OK && f->get_error()!=ERR_FILE_EOF) {
- f->close();
- return ERR_CANT_CREATE;
- }
-
- f->close();
- //memdelete(f);
-
- return OK;
-}
-
-
-
-Error ResourceFormatSaverXML::save(const String &p_path,const RES& p_resource,uint32_t p_flags) {
-
- ResourceFormatSaverXMLInstance saver;
- return saver.save(p_path,p_resource,p_flags);
-
-}
-
-bool ResourceFormatSaverXML::recognize(const RES& p_resource) const {
-
-
- return true; // all recognized!
-}
-void ResourceFormatSaverXML::get_recognized_extensions(const RES& p_resource,List<String> *p_extensions) const {
-
-
- //here comes the sun, lalalala
- String base = p_resource->get_base_extension().to_lower();
- p_extensions->push_back("xml");
- if (base!="res") {
-
- p_extensions->push_back("x"+base);
- }
-
-}
-
-ResourceFormatSaverXML* ResourceFormatSaverXML::singleton=NULL;
-ResourceFormatSaverXML::ResourceFormatSaverXML() {
- singleton=this;
-}
diff --git a/core/io/resource_format_xml.h b/core/io/resource_format_xml.h
deleted file mode 100644
index 097c2e43f..000000000
--- a/core/io/resource_format_xml.h
+++ /dev/null
@@ -1,170 +0,0 @@
-/*************************************************************************/
-/* resource_format_xml.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-#ifndef RESOURCE_FORMAT_XML_H
-#define RESOURCE_FORMAT_XML_H
-
-#include "io/resource_loader.h"
-#include "io/resource_saver.h"
-#include "os/file_access.h"
-
-
-
-class ResourceInteractiveLoaderXML : public ResourceInteractiveLoader {
-
- String local_path;
- String res_path;
-
- FileAccess *f;
-
- struct Tag {
-
- String name;
- HashMap<String,String> args;
-
- };
-
- _FORCE_INLINE_ Error _parse_array_element(Vector<char> &buff,bool p_number_only,FileAccess *f,bool *end);
-
-
- struct ExtResource {
- String path;
- String type;
- };
-
-
- Map<String,String> remaps;
-
- Map<int,ExtResource> ext_resources;
-
- int resources_total;
- int resource_current;
- String resource_type;
-
- mutable int lines;
- uint8_t get_char() const;
- int get_current_line() const;
-
-friend class ResourceFormatLoaderXML;
- List<Tag> tag_stack;
-
- List<RES> resource_cache;
- Tag* parse_tag(bool* r_exit=NULL,bool p_printerr=true,List<String> *r_order=NULL);
- Error close_tag(const String& p_name);
- _FORCE_INLINE_ void unquote(String& p_str);
- Error goto_end_of_tag();
- Error parse_property_data(String &r_data);
- Error parse_property(Variant& r_v, String &r_name);
-
- Error error;
-
- RES resource;
-
-public:
-
- virtual void set_local_path(const String& p_local_path);
- virtual Ref<Resource> get_resource();
- virtual Error poll();
- virtual int get_stage() const;
- virtual int get_stage_count() const;
-
- void open(FileAccess *p_f);
- String recognize(FileAccess *p_f);
- void get_dependencies(FileAccess *p_f, List<String> *p_dependencies, bool p_add_types);
- Error rename_dependencies(FileAccess *p_f, const String &p_path,const Map<String,String>& p_map);
-
-
- ~ResourceInteractiveLoaderXML();
-
-};
-
-class ResourceFormatLoaderXML : public ResourceFormatLoader {
-public:
-
- virtual Ref<ResourceInteractiveLoader> load_interactive(const String &p_path,Error *r_error=NULL);
- virtual void get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions) const;
- virtual void get_recognized_extensions(List<String> *p_extensions) const;
- virtual bool handles_type(const String& p_type) const;
- virtual String get_resource_type(const String &p_path) const;
- virtual void get_dependencies(const String& p_path, List<String> *p_dependencies, bool p_add_types=false);
- virtual Error rename_dependencies(const String &p_path,const Map<String,String>& p_map);
-
-
-};
-
-
-////////////////////////////////////////////////////////////////////////////////////////////
-
-
-class ResourceFormatSaverXMLInstance {
-
- String local_path;
-
-
-
- bool takeover_paths;
- bool relative_paths;
- bool bundle_resources;
- bool skip_editor;
- FileAccess *f;
- int depth;
- Set<RES> resource_set;
- List<RES> saved_resources;
- Map<RES,int> external_resources;
-
- void enter_tag(const char* p_tag,const String& p_args=String());
- void exit_tag(const char* p_tag);
-
- void _find_resources(const Variant& p_variant,bool p_main=false);
- void write_property(const String& p_name,const Variant& p_property,bool *r_ok=NULL);
-
-
- void escape(String& p_str);
- void write_tabs(int p_diff=0);
- void write_string(String p_str,bool p_escape=true);
-
-
-public:
-
- Error save(const String &p_path,const RES& p_resource,uint32_t p_flags=0);
-
-
-};
-
-class ResourceFormatSaverXML : public ResourceFormatSaver {
-public:
- static ResourceFormatSaverXML* singleton;
- virtual Error save(const String &p_path,const RES& p_resource,uint32_t p_flags=0);
- virtual bool recognize(const RES& p_resource) const;
- virtual void get_recognized_extensions(const RES& p_resource,List<String> *p_extensions) const;
-
- ResourceFormatSaverXML();
-};
-
-
-#endif // RESOURCE_FORMAT_XML_H
diff --git a/core/io/stream_peer.cpp b/core/io/stream_peer.cpp
index 218e17278..a2812edb8 100644
--- a/core/io/stream_peer.cpp
+++ b/core/io/stream_peer.cpp
@@ -29,16 +29,16 @@
#include "stream_peer.h"
#include "io/marshalls.h"
-Error StreamPeer::_put_data(const DVector<uint8_t>& p_data) {
+Error StreamPeer::_put_data(const PoolVector<uint8_t>& p_data) {
int len = p_data.size();
if (len==0)
return OK;
- DVector<uint8_t>::Read r = p_data.read();
+ PoolVector<uint8_t>::Read r = p_data.read();
return put_data(&r[0],len);
}
-Array StreamPeer::_put_partial_data(const DVector<uint8_t>& p_data) {
+Array StreamPeer::_put_partial_data(const PoolVector<uint8_t>& p_data) {
Array ret;
@@ -49,7 +49,7 @@ Array StreamPeer::_put_partial_data(const DVector<uint8_t>& p_data) {
return ret;
}
- DVector<uint8_t>::Read r = p_data.read();
+ PoolVector<uint8_t>::Read r = p_data.read();
int sent;
Error err = put_partial_data(&r[0],len,sent);
@@ -66,18 +66,18 @@ Array StreamPeer::_get_data(int p_bytes) {
Array ret;
- DVector<uint8_t> data;
+ PoolVector<uint8_t> data;
data.resize(p_bytes);
if (data.size()!=p_bytes) {
ret.push_back(ERR_OUT_OF_MEMORY);
- ret.push_back(DVector<uint8_t>());
+ ret.push_back(PoolVector<uint8_t>());
return ret;
}
- DVector<uint8_t>::Write w = data.write();
+ PoolVector<uint8_t>::Write w = data.write();
Error err = get_data(&w[0],p_bytes);
- w = DVector<uint8_t>::Write();
+ w = PoolVector<uint8_t>::Write();
ret.push_back(err);
ret.push_back(data);
return ret;
@@ -88,19 +88,19 @@ Array StreamPeer::_get_partial_data(int p_bytes) {
Array ret;
- DVector<uint8_t> data;
+ PoolVector<uint8_t> data;
data.resize(p_bytes);
if (data.size()!=p_bytes) {
ret.push_back(ERR_OUT_OF_MEMORY);
- ret.push_back(DVector<uint8_t>());
+ ret.push_back(PoolVector<uint8_t>());
return ret;
}
- DVector<uint8_t>::Write w = data.write();
+ PoolVector<uint8_t>::Write w = data.write();
int received;
Error err = get_partial_data(&w[0],p_bytes,received);
- w = DVector<uint8_t>::Write();
+ w = PoolVector<uint8_t>::Write();
if (err!=OK) {
data.resize(0);
@@ -454,7 +454,7 @@ Error StreamPeerBuffer::put_data(const uint8_t* p_data,int p_bytes) {
}
- DVector<uint8_t>::Write w = data.write();
+ PoolVector<uint8_t>::Write w = data.write();
copymem(&w[pointer],p_data,p_bytes);
pointer+=p_bytes;
@@ -490,7 +490,7 @@ Error StreamPeerBuffer::get_partial_data(uint8_t* p_buffer, int p_bytes,int &r_r
r_received=p_bytes;
}
- DVector<uint8_t>::Read r = data.read();
+ PoolVector<uint8_t>::Read r = data.read();
copymem(p_buffer,r.ptr(),r_received);
}
@@ -520,13 +520,13 @@ void StreamPeerBuffer::resize(int p_size){
data.resize(p_size);
}
-void StreamPeerBuffer::set_data_array(const DVector<uint8_t> & p_data){
+void StreamPeerBuffer::set_data_array(const PoolVector<uint8_t> & p_data){
data=p_data;
pointer=0;
}
-DVector<uint8_t> StreamPeerBuffer::get_data_array() const{
+PoolVector<uint8_t> StreamPeerBuffer::get_data_array() const{
return data;
}
diff --git a/core/io/stream_peer.h b/core/io/stream_peer.h
index 232a908dd..eb0f90ba5 100644
--- a/core/io/stream_peer.h
+++ b/core/io/stream_peer.h
@@ -38,8 +38,8 @@ protected:
static void _bind_methods();
//bind helpers
- Error _put_data(const DVector<uint8_t>& p_data);
- Array _put_partial_data(const DVector<uint8_t>& p_data);
+ Error _put_data(const PoolVector<uint8_t>& p_data);
+ Array _put_partial_data(const PoolVector<uint8_t>& p_data);
Array _get_data(int p_bytes);
Array _get_partial_data(int p_bytes);
@@ -96,7 +96,7 @@ class StreamPeerBuffer : public StreamPeer {
GDCLASS(StreamPeerBuffer,StreamPeer);
- DVector<uint8_t> data;
+ PoolVector<uint8_t> data;
int pointer;
protected:
@@ -116,8 +116,8 @@ public:
void resize(int p_size);
- void set_data_array(const DVector<uint8_t> & p_data);
- DVector<uint8_t> get_data_array() const;
+ void set_data_array(const PoolVector<uint8_t> & p_data);
+ PoolVector<uint8_t> get_data_array() const;
void clear();
diff --git a/core/io/tcp_server.cpp b/core/io/tcp_server.cpp
index 751dfbadc..bfa5dce58 100644
--- a/core/io/tcp_server.cpp
+++ b/core/io/tcp_server.cpp
@@ -44,7 +44,7 @@ TCP_Server* TCP_Server::create() {
return _create();
}
-Error TCP_Server::_listen(uint16_t p_port, DVector<String> p_accepted_hosts) {
+Error TCP_Server::_listen(uint16_t p_port, PoolVector<String> p_accepted_hosts) {
List<String> hosts;
for(int i=0;i<p_accepted_hosts.size();i++)
@@ -62,7 +62,7 @@ void TCP_Server::set_ip_type(IP::Type p_type) {
void TCP_Server::_bind_methods() {
ClassDB::bind_method(_MD("set_ip_type","ip_type"),&TCP_Server::set_ip_type);
- ClassDB::bind_method(_MD("listen","port","accepted_hosts"),&TCP_Server::_listen,DEFVAL(DVector<String>()));
+ ClassDB::bind_method(_MD("listen","port","accepted_hosts"),&TCP_Server::_listen,DEFVAL(PoolVector<String>()));
ClassDB::bind_method(_MD("is_connection_available"),&TCP_Server::is_connection_available);
ClassDB::bind_method(_MD("take_connection"),&TCP_Server::take_connection);
ClassDB::bind_method(_MD("stop"),&TCP_Server::stop);
diff --git a/core/io/tcp_server.h b/core/io/tcp_server.h
index 5fd65575f..3d7b3ddd8 100644
--- a/core/io/tcp_server.h
+++ b/core/io/tcp_server.h
@@ -43,7 +43,7 @@ protected:
static TCP_Server* (*_create)();
//bind helper
- Error _listen(uint16_t p_port, DVector<String> p_accepted_hosts=DVector<String>());
+ Error _listen(uint16_t p_port, PoolVector<String> p_accepted_hosts=PoolVector<String>());
static void _bind_methods();
public: