summaryrefslogtreecommitdiff
path: root/core/io
diff options
context:
space:
mode:
authorvolzhs <volzhs@gmail.com>2015-06-28 22:28:02 +0900
committervolzhs <volzhs@gmail.com>2015-06-28 22:28:02 +0900
commit584dd4db878d0a9ebf44dc529dad35bf8dd4796b (patch)
treec601222ba20cacc80fba7ff43b5de425db13519c /core/io
parent81a1f32f0c1e4f64bb102c6aa46bcbb4e18bcd55 (diff)
parent2b64f73b0459190d20b2f6de39275ee7979317c4 (diff)
Merge branch 'master' of https://github.com/okamstudio/godot
Diffstat (limited to 'core/io')
-rw-r--r--core/io/resource_format_binary.cpp50
-rw-r--r--core/io/resource_format_binary.h2
-rw-r--r--core/io/resource_format_xml.cpp46
-rw-r--r--core/io/resource_format_xml.h2
4 files changed, 84 insertions, 16 deletions
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index 9fb17bcffb..0f6f8a74b1 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -663,14 +663,18 @@ Error ResourceInteractiveLoaderBinary::poll(){
//maybe it is loaded already
String path;
+ int subindex=0;
if (!main) {
path=internal_resources[s].path;
- if (path.begins_with("local://"))
- path=path.replace("local://",res_path+"::");
+ if (path.begins_with("local://")) {
+ path=path.replace_first("local://","");
+ subindex = path.to_int();
+ path=res_path+"::"+path;
+ }
@@ -709,6 +713,7 @@ Error ResourceInteractiveLoaderBinary::poll(){
RES res = RES( r );
r->set_path(path);
+ r->set_subindex(subindex);
int pc = f->get_32();
@@ -1434,14 +1439,14 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property,
save_unicode_string(path);
} else {
- if (!resource_map.has(res)) {
+ if (!resource_set.has(res)) {
f->store_32(OBJECT_EMPTY);
ERR_EXPLAIN("Resource was not pre cached for the resource section, bug?");
ERR_FAIL();
}
f->store_32(OBJECT_INTERNAL_RESOURCE);
- f->store_32(resource_map[res]);
+ f->store_32(res->get_subindex());
//internal resource
}
@@ -1598,7 +1603,7 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant& p_variant
}
- if (resource_map.has(res))
+ if (resource_set.has(res))
return;
List<PropertyInfo> property_list;
@@ -1613,7 +1618,7 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant& p_variant
}
}
- resource_map[ res ] = saved_resources.size();
+ resource_set.insert(res);
saved_resources.push_back(res);
} break;
@@ -1846,11 +1851,42 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path,const RES& p_
// save internal resource table
f->store_32(saved_resources.size()); //amount of internal resources
Vector<uint64_t> ofs_pos;
+ Set<int> used_indices;
+
+ for(List<RES>::Element *E=saved_resources.front();E;E=E->next()) {
+
+ RES r = E->get();
+ if (r->get_path()=="" || r->get_path().find("::")!=-1) {
+
+ if (r->get_subindex()!=0) {
+ if (used_indices.has(r->get_subindex())) {
+ r->set_subindex(0); //repeated
+ } else {
+ used_indices.insert(r->get_subindex());
+ }
+ }
+ }
+
+ }
+
+
for(List<RES>::Element *E=saved_resources.front();E;E=E->next()) {
+
RES r = E->get();
if (r->get_path()=="" || r->get_path().find("::")!=-1) {
- save_unicode_string("local://"+itos(ofs_pos.size()));
+ if (r->get_subindex()==0) {
+ int new_subindex=1;
+ if (used_indices.size()) {
+ new_subindex=used_indices.back()->get()+1;
+ }
+
+ r->set_subindex(new_subindex);
+ used_indices.insert(new_subindex);
+
+ }
+
+ save_unicode_string("local://"+itos(r->get_subindex()));
if (takeover_paths) {
r->set_path(p_path+"::"+itos(ofs_pos.size()),true);
}
diff --git a/core/io/resource_format_binary.h b/core/io/resource_format_binary.h
index ab2e640a86..da415d97a5 100644
--- a/core/io/resource_format_binary.h
+++ b/core/io/resource_format_binary.h
@@ -129,7 +129,7 @@ class ResourceFormatSaverBinaryInstance {
int bin_meta_idx;
FileAccess *f;
String magic;
- Map<RES,int> resource_map;
+ Set<RES> resource_set;
Map<StringName,int> string_map;
Vector<StringName> strings;
diff --git a/core/io/resource_format_xml.cpp b/core/io/resource_format_xml.cpp
index 3c100d375a..36746a4111 100644
--- a/core/io/resource_format_xml.cpp
+++ b/core/io/resource_format_xml.cpp
@@ -1466,6 +1466,7 @@ Error ResourceInteractiveLoaderXML::poll() {
String type;
String path;
+ int subres=0;
if (!main) {
//loading resource
@@ -1476,11 +1477,15 @@ Error ResourceInteractiveLoaderXML::poll() {
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://",local_path+"::");
+
+ path=path.replace("local://","");
+ subres=path.to_int();
+ path=local_path+"::"+path;
}
@@ -1519,6 +1524,7 @@ Error ResourceInteractiveLoaderXML::poll() {
res = RES( r );
if (path!="")
r->set_path(path);
+ r->set_subindex(subres);
//load properties
@@ -2029,9 +2035,9 @@ void ResourceFormatSaverXMLInstance::write_property(const String& p_name,const V
//internal resource
ERR_EXPLAIN("Resource was not pre cached for the resource section, bug?");
- ERR_FAIL_COND(!resource_map.has(res));
+ ERR_FAIL_COND(!resource_set.has(res));
- params+=" path=\"local://"+itos(resource_map[res])+"\"";
+ params+=" path=\"local://"+itos(res->get_subindex())+"\"";
}
} break;
@@ -2443,7 +2449,7 @@ void ResourceFormatSaverXMLInstance::_find_resources(const Variant& p_variant,bo
return;
}
- if (resource_map.has(res))
+ if (resource_set.has(res))
return;
List<PropertyInfo> property_list;
@@ -2466,7 +2472,7 @@ void ResourceFormatSaverXMLInstance::_find_resources(const Variant& p_variant,bo
I=I->next();
}
- resource_map[ res ] = resource_map.size(); //saved after, so the childs it needs are available when loaded
+ resource_set.insert( res ); //saved after, so the childs it needs are available when loaded
saved_resources.push_back(res);
} break;
@@ -2537,12 +2543,27 @@ Error ResourceFormatSaverXMLInstance::save(const String &p_path,const RES& p_res
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_map.has(res));
+ ERR_CONTINUE(!resource_set.has(res));
bool main = (E->next()==NULL);
write_tabs();
@@ -2552,7 +2573,18 @@ Error ResourceFormatSaverXMLInstance::save(const String &p_path,const RES& p_res
else if (res->get_path().length() && res->get_path().find("::") == -1 )
enter_tag("resource","type=\""+res->get_type()+"\" path=\""+res->get_path()+"\""); //bundled
else {
- int idx = resource_map[res];
+
+ 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_type()+"\" path=\"local://"+itos(idx)+"\"");
if (takeover_paths) {
res->set_path(p_path+"::"+itos(idx),true);
diff --git a/core/io/resource_format_xml.h b/core/io/resource_format_xml.h
index 711b607668..d5ba9eb800 100644
--- a/core/io/resource_format_xml.h
+++ b/core/io/resource_format_xml.h
@@ -123,7 +123,7 @@ class ResourceFormatSaverXMLInstance {
bool skip_editor;
FileAccess *f;
int depth;
- Map<RES,int> resource_map;
+ Set<RES> resource_set;
List<RES> saved_resources;
List<RES> external_resources;