|
@@ -93,7 +93,6 @@ enum {
|
|
|
};
|
|
|
|
|
|
void ResourceInteractiveLoaderBinary::_advance_padding(uint32_t p_len) {
|
|
|
-
|
|
|
uint32_t extra = 4 - (p_len % 4);
|
|
|
if (extra < 4) {
|
|
|
for (uint32_t i = 0; i < extra; i++)
|
|
@@ -102,7 +101,6 @@ void ResourceInteractiveLoaderBinary::_advance_padding(uint32_t p_len) {
|
|
|
}
|
|
|
|
|
|
StringName ResourceInteractiveLoaderBinary::_get_string() {
|
|
|
-
|
|
|
uint32_t id = f->get_32();
|
|
|
if (id & 0x80000000) {
|
|
|
uint32_t len = id & 0x7FFFFFFF;
|
|
@@ -121,42 +119,32 @@ StringName ResourceInteractiveLoaderBinary::_get_string() {
|
|
|
}
|
|
|
|
|
|
Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
|
|
|
-
|
|
|
uint32_t type = f->get_32();
|
|
|
print_bl("find property of type: " + itos(type));
|
|
|
|
|
|
switch (type) {
|
|
|
-
|
|
|
case VARIANT_NIL: {
|
|
|
-
|
|
|
r_v = Variant();
|
|
|
} break;
|
|
|
case VARIANT_BOOL: {
|
|
|
-
|
|
|
r_v = bool(f->get_32());
|
|
|
} break;
|
|
|
case VARIANT_INT: {
|
|
|
-
|
|
|
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();
|
|
|
} break;
|
|
|
case VARIANT_VECTOR2: {
|
|
|
-
|
|
|
Vector2 v;
|
|
|
v.x = f->get_real();
|
|
|
v.y = f->get_real();
|
|
@@ -164,7 +152,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
|
|
|
|
|
|
} break;
|
|
|
case VARIANT_RECT2: {
|
|
|
-
|
|
|
Rect2 v;
|
|
|
v.position.x = f->get_real();
|
|
|
v.position.y = f->get_real();
|
|
@@ -174,7 +161,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
|
|
|
|
|
|
} break;
|
|
|
case VARIANT_VECTOR3: {
|
|
|
-
|
|
|
Vector3 v;
|
|
|
v.x = f->get_real();
|
|
|
v.y = f->get_real();
|
|
@@ -182,7 +168,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
|
|
|
r_v = v;
|
|
|
} break;
|
|
|
case VARIANT_PLANE: {
|
|
|
-
|
|
|
Plane v;
|
|
|
v.normal.x = f->get_real();
|
|
|
v.normal.y = f->get_real();
|
|
@@ -200,7 +185,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
|
|
|
|
|
|
} break;
|
|
|
case VARIANT_AABB: {
|
|
|
-
|
|
|
AABB v;
|
|
|
v.position.x = f->get_real();
|
|
|
v.position.y = f->get_real();
|
|
@@ -212,7 +196,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
|
|
|
|
|
|
} break;
|
|
|
case VARIANT_MATRIX32: {
|
|
|
-
|
|
|
Transform2D v;
|
|
|
v.elements[0].x = f->get_real();
|
|
|
v.elements[0].y = f->get_real();
|
|
@@ -224,7 +207,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
|
|
|
|
|
|
} break;
|
|
|
case VARIANT_MATRIX3: {
|
|
|
-
|
|
|
Basis v;
|
|
|
v.elements[0].x = f->get_real();
|
|
|
v.elements[0].y = f->get_real();
|
|
@@ -239,7 +221,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
|
|
|
|
|
|
} break;
|
|
|
case VARIANT_TRANSFORM: {
|
|
|
-
|
|
|
Transform v;
|
|
|
v.basis.elements[0].x = f->get_real();
|
|
|
v.basis.elements[0].y = f->get_real();
|
|
@@ -256,7 +237,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
|
|
|
r_v = v;
|
|
|
} break;
|
|
|
case VARIANT_COLOR: {
|
|
|
-
|
|
|
Color v;
|
|
|
v.r = f->get_real();
|
|
|
v.g = f->get_real();
|
|
@@ -267,7 +247,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
|
|
|
} break;
|
|
|
|
|
|
case VARIANT_NODE_PATH: {
|
|
|
-
|
|
|
Vector<StringName> names;
|
|
|
Vector<StringName> subnames;
|
|
|
bool absolute;
|
|
@@ -291,15 +270,12 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
|
|
|
|
|
|
} break;
|
|
|
case VARIANT_RID: {
|
|
|
-
|
|
|
r_v = f->get_32();
|
|
|
} break;
|
|
|
case VARIANT_OBJECT: {
|
|
|
-
|
|
|
uint32_t objtype = f->get_32();
|
|
|
|
|
|
switch (objtype) {
|
|
|
-
|
|
|
case OBJECT_EMPTY: {
|
|
|
//do none
|
|
|
|
|
@@ -345,7 +321,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
|
|
|
WARN_PRINT("Broken external resource! (index out of size)");
|
|
|
r_v = Variant();
|
|
|
} else {
|
|
|
-
|
|
|
String exttype = external_resources[erindex].type;
|
|
|
String path = external_resources[erindex].path;
|
|
|
|
|
@@ -364,14 +339,12 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
|
|
|
|
|
|
} break;
|
|
|
default: {
|
|
|
-
|
|
|
ERR_FAIL_V(ERR_FILE_CORRUPT);
|
|
|
} break;
|
|
|
}
|
|
|
|
|
|
} break;
|
|
|
case VARIANT_DICTIONARY: {
|
|
|
-
|
|
|
uint32_t len = f->get_32();
|
|
|
Dictionary d; //last bit means shared
|
|
|
len &= 0x7FFFFFFF;
|
|
@@ -387,7 +360,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
|
|
|
r_v = d;
|
|
|
} break;
|
|
|
case VARIANT_ARRAY: {
|
|
|
-
|
|
|
uint32_t len = f->get_32();
|
|
|
Array a; //last bit means shared
|
|
|
len &= 0x7FFFFFFF;
|
|
@@ -402,7 +374,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
|
|
|
|
|
|
} break;
|
|
|
case VARIANT_RAW_ARRAY: {
|
|
|
-
|
|
|
uint32_t len = f->get_32();
|
|
|
|
|
|
PoolVector<uint8_t> array;
|
|
@@ -415,7 +386,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
|
|
|
|
|
|
} break;
|
|
|
case VARIANT_INT_ARRAY: {
|
|
|
-
|
|
|
uint32_t len = f->get_32();
|
|
|
|
|
|
PoolVector<int> array;
|
|
@@ -426,7 +396,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
|
|
|
{
|
|
|
uint32_t *ptr = (uint32_t *)w.ptr();
|
|
|
for (int i = 0; i < len; i++) {
|
|
|
-
|
|
|
ptr[i] = BSWAP32(ptr[i]);
|
|
|
}
|
|
|
}
|
|
@@ -436,7 +405,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
|
|
|
r_v = array;
|
|
|
} break;
|
|
|
case VARIANT_REAL_ARRAY: {
|
|
|
-
|
|
|
uint32_t len = f->get_32();
|
|
|
|
|
|
PoolVector<real_t> array;
|
|
@@ -447,7 +415,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
|
|
|
{
|
|
|
uint32_t *ptr = (uint32_t *)w.ptr();
|
|
|
for (int i = 0; i < len; i++) {
|
|
|
-
|
|
|
ptr[i] = BSWAP32(ptr[i]);
|
|
|
}
|
|
|
}
|
|
@@ -458,7 +425,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
|
|
|
r_v = array;
|
|
|
} break;
|
|
|
case VARIANT_STRING_ARRAY: {
|
|
|
-
|
|
|
uint32_t len = f->get_32();
|
|
|
PoolVector<String> array;
|
|
|
array.resize(len);
|
|
@@ -470,7 +436,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
|
|
|
|
|
|
} break;
|
|
|
case VARIANT_VECTOR2_ARRAY: {
|
|
|
-
|
|
|
uint32_t len = f->get_32();
|
|
|
|
|
|
PoolVector<Vector2> array;
|
|
@@ -482,7 +447,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
|
|
|
{
|
|
|
uint32_t *ptr = (uint32_t *)w.ptr();
|
|
|
for (int i = 0; i < len * 2; i++) {
|
|
|
-
|
|
|
ptr[i] = BSWAP32(ptr[i]);
|
|
|
}
|
|
|
}
|
|
@@ -497,7 +461,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
|
|
|
|
|
|
} break;
|
|
|
case VARIANT_VECTOR3_ARRAY: {
|
|
|
-
|
|
|
uint32_t len = f->get_32();
|
|
|
|
|
|
PoolVector<Vector3> array;
|
|
@@ -509,7 +472,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
|
|
|
{
|
|
|
uint32_t *ptr = (uint32_t *)w.ptr();
|
|
|
for (int i = 0; i < len * 3; i++) {
|
|
|
-
|
|
|
ptr[i] = BSWAP32(ptr[i]);
|
|
|
}
|
|
|
}
|
|
@@ -524,7 +486,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
|
|
|
|
|
|
} break;
|
|
|
case VARIANT_COLOR_ARRAY: {
|
|
|
-
|
|
|
uint32_t len = f->get_32();
|
|
|
|
|
|
PoolVector<Color> array;
|
|
@@ -536,7 +497,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
|
|
|
{
|
|
|
uint32_t *ptr = (uint32_t *)w.ptr();
|
|
|
for (int i = 0; i < len * 4; i++) {
|
|
|
-
|
|
|
ptr[i] = BSWAP32(ptr[i]);
|
|
|
}
|
|
|
}
|
|
@@ -567,7 +527,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
|
|
|
|
|
|
const uint32_t current_version = 0;
|
|
|
if (format_version > current_version) {
|
|
|
-
|
|
|
ERR_PRINT("Format version for encoded binary image is too new.");
|
|
|
return ERR_PARSE_ERROR;
|
|
|
}
|
|
@@ -599,10 +558,8 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
|
|
|
Ref<Image> image;
|
|
|
|
|
|
if (encoding == IMAGE_ENCODING_LOSSY && Image::lossy_unpacker) {
|
|
|
-
|
|
|
image = Image::lossy_unpacker(data);
|
|
|
} else if (encoding == IMAGE_ENCODING_LOSSLESS && Image::lossless_unpacker) {
|
|
|
-
|
|
|
image = Image::lossless_unpacker(data);
|
|
|
}
|
|
|
_advance_padding(data.size());
|
|
@@ -621,23 +578,19 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
|
|
|
}
|
|
|
|
|
|
void ResourceInteractiveLoaderBinary::set_local_path(const String &p_local_path) {
|
|
|
-
|
|
|
res_path = p_local_path;
|
|
|
}
|
|
|
|
|
|
Ref<Resource> ResourceInteractiveLoaderBinary::get_resource() {
|
|
|
-
|
|
|
return resource;
|
|
|
}
|
|
|
Error ResourceInteractiveLoaderBinary::poll() {
|
|
|
-
|
|
|
if (error != OK)
|
|
|
return error;
|
|
|
|
|
|
int s = stage;
|
|
|
|
|
|
if (s < external_resources.size()) {
|
|
|
-
|
|
|
String path = external_resources[s].path;
|
|
|
|
|
|
if (remaps.has(path)) {
|
|
@@ -645,12 +598,9 @@ Error ResourceInteractiveLoaderBinary::poll() {
|
|
|
}
|
|
|
RES res = ResourceLoader::load(path, external_resources[s].type);
|
|
|
if (res.is_null()) {
|
|
|
-
|
|
|
if (!ResourceLoader::get_abort_on_missing_resources()) {
|
|
|
-
|
|
|
ResourceLoader::notify_dependency_error(local_path, path, external_resources[s].type);
|
|
|
} else {
|
|
|
-
|
|
|
error = ERR_FILE_MISSING_DEPENDENCIES;
|
|
|
ERR_FAIL_V_MSG(error, "Can't load dependency: " + path + ".");
|
|
|
}
|
|
@@ -666,7 +616,6 @@ Error ResourceInteractiveLoaderBinary::poll() {
|
|
|
s -= external_resources.size();
|
|
|
|
|
|
if (s >= internal_resources.size()) {
|
|
|
-
|
|
|
error = ERR_BUG;
|
|
|
ERR_FAIL_COND_V(s >= internal_resources.size(), error);
|
|
|
}
|
|
@@ -678,7 +627,6 @@ Error ResourceInteractiveLoaderBinary::poll() {
|
|
|
int subindex = 0;
|
|
|
|
|
|
if (!main) {
|
|
|
-
|
|
|
path = internal_resources[s].path;
|
|
|
if (path.begins_with("local://")) {
|
|
|
path = path.replace_first("local://", "");
|
|
@@ -693,7 +641,6 @@ Error ResourceInteractiveLoaderBinary::poll() {
|
|
|
return error;
|
|
|
}
|
|
|
} else {
|
|
|
-
|
|
|
if (!ResourceCache::has(res_path))
|
|
|
path = res_path;
|
|
|
}
|
|
@@ -728,7 +675,6 @@ Error ResourceInteractiveLoaderBinary::poll() {
|
|
|
//set properties
|
|
|
|
|
|
for (int i = 0; i < pc; i++) {
|
|
|
-
|
|
|
StringName name = _get_string();
|
|
|
|
|
|
if (name == StringName()) {
|
|
@@ -752,7 +698,6 @@ Error ResourceInteractiveLoaderBinary::poll() {
|
|
|
resource_cache.push_back(res);
|
|
|
|
|
|
if (main) {
|
|
|
-
|
|
|
f->close();
|
|
|
resource = res;
|
|
|
resource->set_as_translation_remapped(translation_remapped);
|
|
@@ -765,28 +710,23 @@ Error ResourceInteractiveLoaderBinary::poll() {
|
|
|
return OK;
|
|
|
}
|
|
|
int ResourceInteractiveLoaderBinary::get_stage() const {
|
|
|
-
|
|
|
return stage;
|
|
|
}
|
|
|
int ResourceInteractiveLoaderBinary::get_stage_count() const {
|
|
|
-
|
|
|
return external_resources.size() + internal_resources.size();
|
|
|
}
|
|
|
|
|
|
void ResourceInteractiveLoaderBinary::set_translation_remapped(bool p_remapped) {
|
|
|
-
|
|
|
translation_remapped = p_remapped;
|
|
|
}
|
|
|
|
|
|
static void save_ustring(FileAccess *f, const String &p_string) {
|
|
|
-
|
|
|
CharString utf8 = p_string.utf8();
|
|
|
f->store_32(utf8.length() + 1);
|
|
|
f->store_buffer((const uint8_t *)utf8.get_data(), utf8.length() + 1);
|
|
|
}
|
|
|
|
|
|
static String get_ustring(FileAccess *f) {
|
|
|
-
|
|
|
int len = f->get_32();
|
|
|
Vector<char> str_buf;
|
|
|
str_buf.resize(len);
|
|
@@ -797,7 +737,6 @@ static String get_ustring(FileAccess *f) {
|
|
|
}
|
|
|
|
|
|
String ResourceInteractiveLoaderBinary::get_unicode_string() {
|
|
|
-
|
|
|
int len = f->get_32();
|
|
|
if (len > str_buf.size()) {
|
|
|
str_buf.resize(len);
|
|
@@ -811,13 +750,11 @@ String ResourceInteractiveLoaderBinary::get_unicode_string() {
|
|
|
}
|
|
|
|
|
|
void ResourceInteractiveLoaderBinary::get_dependencies(FileAccess *p_f, List<String> *p_dependencies, bool p_add_types) {
|
|
|
-
|
|
|
open(p_f);
|
|
|
if (error)
|
|
|
return;
|
|
|
|
|
|
for (int i = 0; i < external_resources.size(); i++) {
|
|
|
-
|
|
|
String dep = external_resources[i].path;
|
|
|
|
|
|
if (p_add_types && external_resources[i].type != String()) {
|
|
@@ -829,7 +766,6 @@ void ResourceInteractiveLoaderBinary::get_dependencies(FileAccess *p_f, List<Str
|
|
|
}
|
|
|
|
|
|
void ResourceInteractiveLoaderBinary::open(FileAccess *p_f) {
|
|
|
-
|
|
|
error = OK;
|
|
|
|
|
|
f = p_f;
|
|
@@ -874,7 +810,6 @@ void ResourceInteractiveLoaderBinary::open(FileAccess *p_f) {
|
|
|
print_bl("format: " + itos(ver_format));
|
|
|
|
|
|
if (ver_format > FORMAT_VERSION || ver_major > VERSION_MAJOR) {
|
|
|
-
|
|
|
f->close();
|
|
|
ERR_FAIL_MSG(vformat("File '%s' can't be loaded, as it uses a format version (%d) or engine version (%d.%d) which are not supported by your engine version (%s).",
|
|
|
local_path, ver_format, ver_major, ver_minor, VERSION_BRANCH));
|
|
@@ -891,7 +826,6 @@ void ResourceInteractiveLoaderBinary::open(FileAccess *p_f) {
|
|
|
uint32_t string_table_size = f->get_32();
|
|
|
string_map.resize(string_table_size);
|
|
|
for (uint32_t i = 0; i < string_table_size; i++) {
|
|
|
-
|
|
|
StringName s = get_unicode_string();
|
|
|
string_map.write[i] = s;
|
|
|
}
|
|
@@ -900,7 +834,6 @@ void ResourceInteractiveLoaderBinary::open(FileAccess *p_f) {
|
|
|
|
|
|
uint32_t ext_resources_size = f->get_32();
|
|
|
for (uint32_t i = 0; i < ext_resources_size; i++) {
|
|
|
-
|
|
|
ExtResource er;
|
|
|
er.type = get_unicode_string();
|
|
|
|
|
@@ -913,7 +846,6 @@ void ResourceInteractiveLoaderBinary::open(FileAccess *p_f) {
|
|
|
uint32_t int_resources_size = f->get_32();
|
|
|
|
|
|
for (uint32_t i = 0; i < int_resources_size; i++) {
|
|
|
-
|
|
|
IntResource ir;
|
|
|
ir.path = get_unicode_string();
|
|
|
ir.offset = f->get_64();
|
|
@@ -923,7 +855,6 @@ void ResourceInteractiveLoaderBinary::open(FileAccess *p_f) {
|
|
|
print_bl("int resources: " + itos(int_resources_size));
|
|
|
|
|
|
if (f->eof_reached()) {
|
|
|
-
|
|
|
error = ERR_FILE_CORRUPT;
|
|
|
f->close();
|
|
|
ERR_FAIL_MSG("Premature end of file (EOF): " + local_path + ".");
|
|
@@ -931,7 +862,6 @@ void ResourceInteractiveLoaderBinary::open(FileAccess *p_f) {
|
|
|
}
|
|
|
|
|
|
String ResourceInteractiveLoaderBinary::recognize(FileAccess *p_f) {
|
|
|
-
|
|
|
error = OK;
|
|
|
|
|
|
f = p_f;
|
|
@@ -965,7 +895,6 @@ String ResourceInteractiveLoaderBinary::recognize(FileAccess *p_f) {
|
|
|
uint32_t ver_format = f->get_32();
|
|
|
|
|
|
if (ver_format > FORMAT_VERSION || ver_major > VERSION_MAJOR) {
|
|
|
-
|
|
|
f->close();
|
|
|
return "";
|
|
|
}
|
|
@@ -983,13 +912,11 @@ ResourceInteractiveLoaderBinary::ResourceInteractiveLoaderBinary() :
|
|
|
}
|
|
|
|
|
|
ResourceInteractiveLoaderBinary::~ResourceInteractiveLoaderBinary() {
|
|
|
-
|
|
|
if (f)
|
|
|
memdelete(f);
|
|
|
}
|
|
|
|
|
|
Ref<ResourceInteractiveLoader> ResourceFormatLoaderBinary::load_interactive(const String &p_path, const String &p_original_path, Error *r_error) {
|
|
|
-
|
|
|
if (r_error)
|
|
|
*r_error = ERR_FILE_CANT_OPEN;
|
|
|
|
|
@@ -1009,7 +936,6 @@ Ref<ResourceInteractiveLoader> ResourceFormatLoaderBinary::load_interactive(cons
|
|
|
}
|
|
|
|
|
|
void ResourceFormatLoaderBinary::get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const {
|
|
|
-
|
|
|
if (p_type == "") {
|
|
|
get_recognized_extensions(p_extensions);
|
|
|
return;
|
|
@@ -1026,7 +952,6 @@ void ResourceFormatLoaderBinary::get_recognized_extensions_for_type(const String
|
|
|
}
|
|
|
}
|
|
|
void ResourceFormatLoaderBinary::get_recognized_extensions(List<String> *p_extensions) const {
|
|
|
-
|
|
|
List<String> extensions;
|
|
|
ClassDB::get_resource_base_extensions(&extensions);
|
|
|
extensions.sort();
|
|
@@ -1038,12 +963,10 @@ void ResourceFormatLoaderBinary::get_recognized_extensions(List<String> *p_exten
|
|
|
}
|
|
|
|
|
|
bool ResourceFormatLoaderBinary::handles_type(const String &p_type) const {
|
|
|
-
|
|
|
return true; //handles all
|
|
|
}
|
|
|
|
|
|
void ResourceFormatLoaderBinary::get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types) {
|
|
|
-
|
|
|
FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
|
|
|
ERR_FAIL_COND_MSG(!f, "Cannot open file '" + p_path + "'.");
|
|
|
|
|
@@ -1055,7 +978,6 @@ void ResourceFormatLoaderBinary::get_dependencies(const String &p_path, List<Str
|
|
|
}
|
|
|
|
|
|
Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, const Map<String, String> &p_map) {
|
|
|
-
|
|
|
//Error error=OK;
|
|
|
|
|
|
FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
|
|
@@ -1121,7 +1043,6 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons
|
|
|
uint32_t ver_format = f->get_32();
|
|
|
|
|
|
if (ver_format < FORMAT_VERSION_CAN_RENAME_DEPS) {
|
|
|
-
|
|
|
memdelete(f);
|
|
|
memdelete(fw);
|
|
|
DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
|
@@ -1157,7 +1078,6 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons
|
|
|
}
|
|
|
|
|
|
if (ver_format > FORMAT_VERSION || ver_major > VERSION_MAJOR) {
|
|
|
-
|
|
|
memdelete(f);
|
|
|
memdelete(fw);
|
|
|
ERR_FAIL_V_MSG(ERR_FILE_UNRECOGNIZED,
|
|
@@ -1188,7 +1108,6 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons
|
|
|
fw->store_32(string_table_size);
|
|
|
|
|
|
for (uint32_t i = 0; i < string_table_size; i++) {
|
|
|
-
|
|
|
String s = get_ustring(f);
|
|
|
save_ustring(fw, s);
|
|
|
}
|
|
@@ -1197,7 +1116,6 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons
|
|
|
uint32_t ext_resources_size = f->get_32();
|
|
|
fw->store_32(ext_resources_size);
|
|
|
for (uint32_t i = 0; i < ext_resources_size; i++) {
|
|
|
-
|
|
|
String type = get_ustring(f);
|
|
|
String path = get_ustring(f);
|
|
|
|
|
@@ -1228,7 +1146,6 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons
|
|
|
fw->store_32(int_resources_size);
|
|
|
|
|
|
for (uint32_t i = 0; i < int_resources_size; i++) {
|
|
|
-
|
|
|
String path = get_ustring(f);
|
|
|
uint64_t offset = f->get_64();
|
|
|
save_ustring(fw, path);
|
|
@@ -1262,7 +1179,6 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons
|
|
|
}
|
|
|
|
|
|
String ResourceFormatLoaderBinary::get_resource_type(const String &p_path) const {
|
|
|
-
|
|
|
FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
|
|
|
if (!f) {
|
|
|
return ""; //could not rwead
|
|
@@ -1281,7 +1197,6 @@ String ResourceFormatLoaderBinary::get_resource_type(const String &p_path) const
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
void ResourceFormatSaverBinaryInstance::_pad_buffer(FileAccess *f, int p_bytes) {
|
|
|
-
|
|
|
int extra = 4 - (p_bytes % 4);
|
|
|
if (extra < 4) {
|
|
|
for (int i = 0; i < extra; i++)
|
|
@@ -1290,27 +1205,21 @@ void ResourceFormatSaverBinaryInstance::_pad_buffer(FileAccess *f, int p_bytes)
|
|
|
}
|
|
|
|
|
|
void ResourceFormatSaverBinaryInstance::_write_variant(const Variant &p_property, const PropertyInfo &p_hint) {
|
|
|
-
|
|
|
write_variant(f, p_property, resource_set, external_resources, string_map, p_hint);
|
|
|
}
|
|
|
|
|
|
void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Variant &p_property, Set<RES> &resource_set, Map<RES, int> &external_resources, Map<StringName, int> &string_map, const PropertyInfo &p_hint) {
|
|
|
-
|
|
|
switch (p_property.get_type()) {
|
|
|
-
|
|
|
case Variant::NIL: {
|
|
|
-
|
|
|
f->store_32(VARIANT_NIL);
|
|
|
// don't store anything
|
|
|
} break;
|
|
|
case Variant::BOOL: {
|
|
|
-
|
|
|
f->store_32(VARIANT_BOOL);
|
|
|
bool val = p_property;
|
|
|
f->store_32(val);
|
|
|
} break;
|
|
|
case Variant::INT: {
|
|
|
-
|
|
|
int64_t val = p_property;
|
|
|
if (val > 0x7FFFFFFF || val < -(int64_t)0x80000000) {
|
|
|
f->store_32(VARIANT_INT64);
|
|
@@ -1323,28 +1232,24 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
|
|
|
|
|
|
} break;
|
|
|
case Variant::REAL: {
|
|
|
-
|
|
|
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: {
|
|
|
-
|
|
|
f->store_32(VARIANT_STRING);
|
|
|
String val = p_property;
|
|
|
save_unicode_string(f, val);
|
|
|
|
|
|
} break;
|
|
|
case Variant::VECTOR2: {
|
|
|
-
|
|
|
f->store_32(VARIANT_VECTOR2);
|
|
|
Vector2 val = p_property;
|
|
|
f->store_real(val.x);
|
|
@@ -1352,7 +1257,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
|
|
|
|
|
|
} break;
|
|
|
case Variant::RECT2: {
|
|
|
-
|
|
|
f->store_32(VARIANT_RECT2);
|
|
|
Rect2 val = p_property;
|
|
|
f->store_real(val.position.x);
|
|
@@ -1362,7 +1266,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
|
|
|
|
|
|
} break;
|
|
|
case Variant::VECTOR3: {
|
|
|
-
|
|
|
f->store_32(VARIANT_VECTOR3);
|
|
|
Vector3 val = p_property;
|
|
|
f->store_real(val.x);
|
|
@@ -1371,7 +1274,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
|
|
|
|
|
|
} break;
|
|
|
case Variant::PLANE: {
|
|
|
-
|
|
|
f->store_32(VARIANT_PLANE);
|
|
|
Plane val = p_property;
|
|
|
f->store_real(val.normal.x);
|
|
@@ -1381,7 +1283,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
|
|
|
|
|
|
} break;
|
|
|
case Variant::QUAT: {
|
|
|
-
|
|
|
f->store_32(VARIANT_QUAT);
|
|
|
Quat val = p_property;
|
|
|
f->store_real(val.x);
|
|
@@ -1391,7 +1292,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
|
|
|
|
|
|
} break;
|
|
|
case Variant::AABB: {
|
|
|
-
|
|
|
f->store_32(VARIANT_AABB);
|
|
|
AABB val = p_property;
|
|
|
f->store_real(val.position.x);
|
|
@@ -1403,7 +1303,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
|
|
|
|
|
|
} break;
|
|
|
case Variant::TRANSFORM2D: {
|
|
|
-
|
|
|
f->store_32(VARIANT_MATRIX32);
|
|
|
Transform2D val = p_property;
|
|
|
f->store_real(val.elements[0].x);
|
|
@@ -1415,7 +1314,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
|
|
|
|
|
|
} break;
|
|
|
case Variant::BASIS: {
|
|
|
-
|
|
|
f->store_32(VARIANT_MATRIX3);
|
|
|
Basis val = p_property;
|
|
|
f->store_real(val.elements[0].x);
|
|
@@ -1430,7 +1328,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
|
|
|
|
|
|
} break;
|
|
|
case Variant::TRANSFORM: {
|
|
|
-
|
|
|
f->store_32(VARIANT_TRANSFORM);
|
|
|
Transform val = p_property;
|
|
|
f->store_real(val.basis.elements[0].x);
|
|
@@ -1448,7 +1345,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
|
|
|
|
|
|
} break;
|
|
|
case Variant::COLOR: {
|
|
|
-
|
|
|
f->store_32(VARIANT_COLOR);
|
|
|
Color val = p_property;
|
|
|
f->store_real(val.r);
|
|
@@ -1483,14 +1379,12 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
|
|
|
|
|
|
} break;
|
|
|
case Variant::_RID: {
|
|
|
-
|
|
|
f->store_32(VARIANT_RID);
|
|
|
WARN_PRINT("Can't save RIDs.");
|
|
|
RID val = p_property;
|
|
|
f->store_32(val.get_id());
|
|
|
} break;
|
|
|
case Variant::OBJECT: {
|
|
|
-
|
|
|
f->store_32(VARIANT_OBJECT);
|
|
|
RES res = p_property;
|
|
|
if (res.is_null()) {
|
|
@@ -1502,7 +1396,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
|
|
|
f->store_32(OBJECT_EXTERNAL_RESOURCE_INDEX);
|
|
|
f->store_32(external_resources[res]);
|
|
|
} else {
|
|
|
-
|
|
|
if (!resource_set.has(res)) {
|
|
|
f->store_32(OBJECT_EMPTY);
|
|
|
ERR_FAIL_MSG("Resource was not pre cached for the resource section, most likely due to circular reference.");
|
|
@@ -1515,7 +1408,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
|
|
|
|
|
|
} break;
|
|
|
case Variant::DICTIONARY: {
|
|
|
-
|
|
|
f->store_32(VARIANT_DICTIONARY);
|
|
|
Dictionary d = p_property;
|
|
|
f->store_32(uint32_t(d.size()));
|
|
@@ -1524,7 +1416,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
|
|
|
d.get_key_list(&keys);
|
|
|
|
|
|
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
|
|
|
-
|
|
|
/*
|
|
|
if (!_check_type(dict[E->get()]))
|
|
|
continue;
|
|
@@ -1536,18 +1427,15 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
|
|
|
|
|
|
} break;
|
|
|
case Variant::ARRAY: {
|
|
|
-
|
|
|
f->store_32(VARIANT_ARRAY);
|
|
|
Array a = p_property;
|
|
|
f->store_32(uint32_t(a.size()));
|
|
|
for (int i = 0; i < a.size(); i++) {
|
|
|
-
|
|
|
write_variant(f, a[i], resource_set, external_resources, string_map);
|
|
|
}
|
|
|
|
|
|
} break;
|
|
|
case Variant::POOL_BYTE_ARRAY: {
|
|
|
-
|
|
|
f->store_32(VARIANT_RAW_ARRAY);
|
|
|
PoolVector<uint8_t> arr = p_property;
|
|
|
int len = arr.size();
|
|
@@ -1558,7 +1446,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
|
|
|
|
|
|
} break;
|
|
|
case Variant::POOL_INT_ARRAY: {
|
|
|
-
|
|
|
f->store_32(VARIANT_INT_ARRAY);
|
|
|
PoolVector<int> arr = p_property;
|
|
|
int len = arr.size();
|
|
@@ -1569,7 +1456,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
|
|
|
|
|
|
} break;
|
|
|
case Variant::POOL_REAL_ARRAY: {
|
|
|
-
|
|
|
f->store_32(VARIANT_REAL_ARRAY);
|
|
|
PoolVector<real_t> arr = p_property;
|
|
|
int len = arr.size();
|
|
@@ -1581,7 +1467,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
|
|
|
|
|
|
} break;
|
|
|
case Variant::POOL_STRING_ARRAY: {
|
|
|
-
|
|
|
f->store_32(VARIANT_STRING_ARRAY);
|
|
|
PoolVector<String> arr = p_property;
|
|
|
int len = arr.size();
|
|
@@ -1593,7 +1478,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
|
|
|
|
|
|
} break;
|
|
|
case Variant::POOL_VECTOR3_ARRAY: {
|
|
|
-
|
|
|
f->store_32(VARIANT_VECTOR3_ARRAY);
|
|
|
PoolVector<Vector3> arr = p_property;
|
|
|
int len = arr.size();
|
|
@@ -1607,7 +1491,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
|
|
|
|
|
|
} break;
|
|
|
case Variant::POOL_VECTOR2_ARRAY: {
|
|
|
-
|
|
|
f->store_32(VARIANT_VECTOR2_ARRAY);
|
|
|
PoolVector<Vector2> arr = p_property;
|
|
|
int len = arr.size();
|
|
@@ -1620,7 +1503,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
|
|
|
|
|
|
} break;
|
|
|
case Variant::POOL_COLOR_ARRAY: {
|
|
|
-
|
|
|
f->store_32(VARIANT_COLOR_ARRAY);
|
|
|
PoolVector<Color> arr = p_property;
|
|
|
int len = arr.size();
|
|
@@ -1635,17 +1517,14 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
|
|
|
|
|
|
} break;
|
|
|
default: {
|
|
|
-
|
|
|
ERR_FAIL_MSG("Invalid variant.");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void ResourceFormatSaverBinaryInstance::_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))
|
|
@@ -1669,9 +1548,7 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant
|
|
|
res->get_property_list(&property_list);
|
|
|
|
|
|
for (List<PropertyInfo>::Element *E = property_list.front(); E; E = E->next()) {
|
|
|
-
|
|
|
if (E->get().usage & PROPERTY_USAGE_STORAGE) {
|
|
|
-
|
|
|
Variant value = res->get(E->get().name);
|
|
|
if (E->get().usage & PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT) {
|
|
|
RES sres = value;
|
|
@@ -1695,11 +1572,9 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant
|
|
|
} break;
|
|
|
|
|
|
case Variant::ARRAY: {
|
|
|
-
|
|
|
Array varray = p_variant;
|
|
|
int len = varray.size();
|
|
|
for (int i = 0; i < len; i++) {
|
|
|
-
|
|
|
const Variant &v = varray.get(i);
|
|
|
_find_resources(v);
|
|
|
}
|
|
@@ -1707,12 +1582,10 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant
|
|
|
} 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()) {
|
|
|
-
|
|
|
_find_resources(E->get());
|
|
|
Variant v = d[E->get()];
|
|
|
_find_resources(v);
|
|
@@ -1733,7 +1606,6 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant
|
|
|
}
|
|
|
|
|
|
void ResourceFormatSaverBinaryInstance::save_unicode_string(FileAccess *f, const String &p_string, bool p_bit_on_len) {
|
|
|
-
|
|
|
CharString utf8 = p_string.utf8();
|
|
|
if (p_bit_on_len) {
|
|
|
f->store_32((utf8.length() + 1) | 0x80000000);
|
|
@@ -1744,7 +1616,6 @@ void ResourceFormatSaverBinaryInstance::save_unicode_string(FileAccess *f, const
|
|
|
}
|
|
|
|
|
|
int ResourceFormatSaverBinaryInstance::get_string_index(const String &p_string) {
|
|
|
-
|
|
|
StringName s = p_string;
|
|
|
if (string_map.has(s))
|
|
|
return string_map[s];
|
|
@@ -1755,7 +1626,6 @@ int ResourceFormatSaverBinaryInstance::get_string_index(const String &p_string)
|
|
|
}
|
|
|
|
|
|
Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p_resource, uint32_t p_flags) {
|
|
|
-
|
|
|
Error err;
|
|
|
if (p_flags & ResourceSaver::FLAG_COMPRESS) {
|
|
|
FileAccessCompressed *fac = memnew(FileAccessCompressed);
|
|
@@ -1816,9 +1686,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
|
|
|
List<ResourceData> resources;
|
|
|
|
|
|
{
|
|
|
-
|
|
|
for (List<RES>::Element *E = saved_resources.front(); E; E = E->next()) {
|
|
|
-
|
|
|
ResourceData &rd = resources.push_back(ResourceData())->get();
|
|
|
rd.type = E->get()->get_class();
|
|
|
|
|
@@ -1826,7 +1694,6 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
|
|
|
E->get()->get_property_list(&property_list);
|
|
|
|
|
|
for (List<PropertyInfo>::Element *F = property_list.front(); F; F = F->next()) {
|
|
|
-
|
|
|
if (skip_editor && F->get().name.begins_with("__editor"))
|
|
|
continue;
|
|
|
if ((F->get().usage & PROPERTY_USAGE_STORAGE)) {
|
|
@@ -1873,7 +1740,6 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
|
|
|
}
|
|
|
|
|
|
for (int i = 0; i < save_order.size(); i++) {
|
|
|
-
|
|
|
save_unicode_string(f, save_order[i]->get_save_class());
|
|
|
String path = save_order[i]->get_path();
|
|
|
path = relative_paths ? local_path.path_to_file(path) : path;
|
|
@@ -1885,10 +1751,8 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
|
|
|
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
|
|
@@ -1900,7 +1764,6 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
|
|
|
}
|
|
|
|
|
|
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) {
|
|
@@ -1931,7 +1794,6 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
|
|
|
|
|
|
//now actually save the resources
|
|
|
for (List<ResourceData>::Element *E = resources.front(); E; E = E->next()) {
|
|
|
-
|
|
|
ResourceData &rd = E->get();
|
|
|
|
|
|
ofs_table.push_back(f->get_position());
|
|
@@ -1939,7 +1801,6 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
|
|
|
f->store_32(rd.properties.size());
|
|
|
|
|
|
for (List<Property>::Element *F = rd.properties.front(); F; F = F->next()) {
|
|
|
-
|
|
|
Property &p = F->get();
|
|
|
f->store_32(p.name_idx);
|
|
|
_write_variant(p.value, F->get().pi);
|
|
@@ -1968,19 +1829,16 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
|
|
|
}
|
|
|
|
|
|
Error ResourceFormatSaverBinary::save(const String &p_path, const RES &p_resource, uint32_t p_flags) {
|
|
|
-
|
|
|
String local_path = ProjectSettings::get_singleton()->localize_path(p_path);
|
|
|
ResourceFormatSaverBinaryInstance saver;
|
|
|
return saver.save(local_path, p_resource, p_flags);
|
|
|
}
|
|
|
|
|
|
bool ResourceFormatSaverBinary::recognize(const RES &p_resource) const {
|
|
|
-
|
|
|
return true; //all recognized
|
|
|
}
|
|
|
|
|
|
void ResourceFormatSaverBinary::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const {
|
|
|
-
|
|
|
String base = p_resource->get_base_extension().to_lower();
|
|
|
p_extensions->push_back(base);
|
|
|
if (base != "res")
|
|
@@ -1990,6 +1848,5 @@ void ResourceFormatSaverBinary::get_recognized_extensions(const RES &p_resource,
|
|
|
ResourceFormatSaverBinary *ResourceFormatSaverBinary::singleton = NULL;
|
|
|
|
|
|
ResourceFormatSaverBinary::ResourceFormatSaverBinary() {
|
|
|
-
|
|
|
singleton = this;
|
|
|
}
|