diff options
author | Juan Linietsky <juan@godotengine.org> | 2019-02-21 20:49:42 -0300 |
---|---|---|
committer | Juan Linietsky <juan@godotengine.org> | 2019-02-21 20:49:42 -0300 |
commit | 8b231b96e347b677ea4189784c960bc4517b8e6a (patch) | |
tree | b5bf271cdce01341e4b221badcdc2c67bbef24f3 /core/io | |
parent | 5784caae73dbb9dcb1e6640884782859c5ab94b6 (diff) |
Implement a cleaner (and better) way to save imagedata from ImageTexture, fixes #18801
Diffstat (limited to 'core/io')
-rw-r--r-- | core/io/resource_format_binary.cpp | 27 | ||||
-rw-r--r-- | core/io/resource_format_binary.h | 8 |
2 files changed, 33 insertions, 2 deletions
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index 77e3efb3a0..d2c656b8eb 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -1666,7 +1666,20 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant if (E->get().usage & PROPERTY_USAGE_STORAGE) { - _find_resources(res->get(E->get().name)); + Variant value = res->get(E->get().name); + if (E->get().usage & PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT) { + RES sres = value; + if (sres.is_valid()) { + NonPersistentKey npk; + npk.base = res; + npk.property = E->get().name; + non_persistent_map[npk] = sres; + resource_set.insert(sres); + saved_resources.push_back(sres); + } + } else { + _find_resources(value); + } } } @@ -1810,7 +1823,17 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p if ((F->get().usage & PROPERTY_USAGE_STORAGE)) { Property p; p.name_idx = get_string_index(F->get().name); - p.value = E->get()->get(F->get().name); + + if (F->get().usage & PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT) { + NonPersistentKey npk; + npk.base = E->get(); + npk.property = F->get().name; + if (non_persistent_map.has(npk)) { + p.value = non_persistent_map[npk]; + } + } else { + p.value = E->get()->get(F->get().name); + } Variant default_value = ClassDB::class_get_default_property_value(E->get()->get_class(), F->get().name); diff --git a/core/io/resource_format_binary.h b/core/io/resource_format_binary.h index 8f2c48e745..c3c477b805 100644 --- a/core/io/resource_format_binary.h +++ b/core/io/resource_format_binary.h @@ -123,6 +123,14 @@ class ResourceFormatSaverBinaryInstance { FileAccess *f; String magic; Set<RES> resource_set; + + struct NonPersistentKey { //for resource properties generated on the fly + RES base; + StringName property; + bool operator<(const NonPersistentKey &p_key) const { return base == p_key.base ? property < p_key.property : base < p_key.base; } + }; + + Map<NonPersistentKey, RES> non_persistent_map; Map<StringName, int> string_map; Vector<StringName> strings; |