Skip to content

Commit

Permalink
Multiple scene editing *POTENTIALLY UNSTABLE*
Browse files Browse the repository at this point in the history
-ability to edit multiple scenes at the same time
-resource internal IDs are now persistent, this makes multiple scene
editing possible but maaaaay result in file corruption bugs (tested and
could not find anything but possibility exists because core code
changed, report immediately if you find this).
-properly save settings, layout, etc when edited
-script editing is independent from scene editing now
-show a yellow box when a script belongs to the scene
  • Loading branch information
reduz committed Jun 22, 2015
1 parent 37af8b4 commit e9bbb97
Show file tree
Hide file tree
Showing 37 changed files with 1,260 additions and 276 deletions.
50 changes: 43 additions & 7 deletions core/io/resource_format_binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}



Expand Down Expand Up @@ -709,6 +713,7 @@ Error ResourceInteractiveLoaderBinary::poll(){
RES res = RES( r );

r->set_path(path);
r->set_subindex(subindex);

int pc = f->get_32();

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion core/io/resource_format_binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
46 changes: 39 additions & 7 deletions core/io/resource_format_xml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1466,6 +1466,7 @@ Error ResourceInteractiveLoaderXML::poll() {

String type;
String path;
int subres=0;

if (!main) {
//loading resource
Expand All @@ -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;
}


Expand Down Expand Up @@ -1519,6 +1524,7 @@ Error ResourceInteractiveLoaderXML::poll() {
res = RES( r );
if (path!="")
r->set_path(path);
r->set_subindex(subres);

//load properties

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion core/io/resource_format_xml.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
58 changes: 58 additions & 0 deletions core/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "core_string_names.h"
#include "translation.h"
#include "os/os.h"
#include "resource.h"

#ifdef DEBUG_ENABLED

Expand Down Expand Up @@ -1464,6 +1465,63 @@ StringName Object::tr(const StringName& p_message) const {

}


void Object::_clear_internal_resource_paths(const Variant &p_var) {

switch(p_var.get_type()) {

case Variant::OBJECT: {

RES r = p_var;
if (!r.is_valid())
return;

if (!r->get_path().begins_with("res://") || r->get_path().find("::")==-1)
return; //not an internal resource

Object *object=p_var;
if (!object)
return;

r->set_path("");
r->clear_internal_resource_paths();
} break;
case Variant::ARRAY: {

Array a=p_var;
for(int i=0;i<a.size();i++) {
_clear_internal_resource_paths(a[i]);
}

} break;
case Variant::DICTIONARY: {

Dictionary d=p_var;
List<Variant> keys;
d.get_key_list(&keys);

for (List<Variant>::Element *E=keys.front();E;E=E->next()) {

_clear_internal_resource_paths(E->get());
_clear_internal_resource_paths(d[E->get()]);
}
} break;
}

}

void Object::clear_internal_resource_paths() {

List<PropertyInfo> pinfo;

get_property_list(&pinfo);

for(List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) {

_clear_internal_resource_paths(get(E->get().name));
}
}

void Object::_bind_methods() {

ObjectTypeDB::bind_method(_MD("get_type"),&Object::get_type);
Expand Down
7 changes: 7 additions & 0 deletions core/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,8 @@ friend void postinitialize_handler(Object*);
Array _get_property_list_bind() const;
Array _get_method_list_bind() const;

void _clear_internal_resource_paths(const Variant &p_var);

public: //should be protected, but bug in clang++
static void initialize_type();
_FORCE_INLINE_ static void register_custom_data_to_otdb() {};
Expand Down Expand Up @@ -599,6 +601,9 @@ friend void postinitialize_handler(Object*);

_FORCE_INLINE_ void set_message_translation(bool p_enable) { _can_translate=p_enable; }
_FORCE_INLINE_ bool can_translate_messages() const { return _can_translate; }

void clear_internal_resource_paths();

Object();
virtual ~Object();

Expand Down Expand Up @@ -651,6 +656,8 @@ friend void unregister_core_types();

#endif



};

//needed by macros
Expand Down
12 changes: 12 additions & 0 deletions core/resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,17 @@ String Resource::get_path() const {
return path_cache;
}

void Resource::set_subindex(int p_sub_index) {

subindex=p_sub_index;
}

int Resource::get_subindex() const{

return subindex;
}


void Resource::set_name(const String& p_name) {

name=p_name;
Expand Down Expand Up @@ -326,6 +337,7 @@ Resource::Resource() {
last_modified_time=0;
#endif

subindex=0;
}


Expand Down
4 changes: 4 additions & 0 deletions core/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ friend class ResourceCache;

String name;
String path_cache;
int subindex;

virtual bool _use_builtin_script() const { return true; }

Expand Down Expand Up @@ -132,6 +133,9 @@ friend class ResourceCache;
void set_path(const String& p_path,bool p_take_over=false);
String get_path() const;

void set_subindex(int p_sub_index);
int get_subindex() const;

Ref<Resource> duplicate(bool p_subresources=false);

void set_import_metadata(const Ref<ResourceImportMetadata>& p_metadata);
Expand Down
Loading

0 comments on commit e9bbb97

Please sign in to comment.