diff options
Diffstat (limited to 'core/io')
-rw-r--r-- | core/io/image.cpp | 10 | ||||
-rw-r--r-- | core/io/image.h | 1 | ||||
-rw-r--r-- | core/io/ip.cpp | 16 | ||||
-rw-r--r-- | core/io/ip_address.cpp | 2 | ||||
-rw-r--r-- | core/io/marshalls.cpp | 96 | ||||
-rw-r--r-- | core/io/packed_data_container.cpp | 1 | ||||
-rw-r--r-- | core/io/resource.cpp | 15 | ||||
-rw-r--r-- | core/io/resource_format_binary.cpp | 61 | ||||
-rw-r--r-- | core/io/udp_server.cpp | 2 |
9 files changed, 167 insertions, 37 deletions
diff --git a/core/io/image.cpp b/core/io/image.cpp index 6096211cff..5498b448d7 100644 --- a/core/io/image.cpp +++ b/core/io/image.cpp @@ -521,7 +521,7 @@ void Image::convert(Format p_new_format) { // Includes the main image. const int mipmap_count = get_mipmap_count() + 1; - if (format > FORMAT_RGBE9995 || p_new_format > FORMAT_RGBE9995) { + if (Image::is_format_compressed(format) || Image::is_format_compressed(p_new_format)) { ERR_FAIL_MSG("Cannot convert to <-> from compressed formats. Use compress() and decompress() instead."); } else if (format > FORMAT_RGBA8 || p_new_format > FORMAT_RGBA8) { @@ -1662,7 +1662,7 @@ int Image::_get_dst_image_size(int p_width, int p_height, Format p_format, int & } bool Image::_can_modify(Format p_format) const { - return p_format <= FORMAT_RGBE9995; + return !Image::is_format_compressed(p_format); } template <typename Component, int CC, bool renormalize, @@ -2616,7 +2616,11 @@ int Image::get_image_mipmap_offset_and_dimensions(int p_width, int p_height, For } bool Image::is_compressed() const { - return format > FORMAT_RGBE9995; + return is_format_compressed(format); +} + +bool Image::is_format_compressed(Format p_format) { + return p_format > FORMAT_RGBE9995; } Error Image::decompress() { diff --git a/core/io/image.h b/core/io/image.h index 2cabbb767a..daddfac59d 100644 --- a/core/io/image.h +++ b/core/io/image.h @@ -376,6 +376,7 @@ public: Error compress_from_channels(CompressMode p_mode, UsedChannels p_channels, ASTCFormat p_astc_format = ASTC_FORMAT_4x4); Error decompress(); bool is_compressed() const; + static bool is_format_compressed(Format p_format); void fix_alpha_edges(); void premultiply_alpha(); diff --git a/core/io/ip.cpp b/core/io/ip.cpp index ec86104926..f20d65bef9 100644 --- a/core/io/ip.cpp +++ b/core/io/ip.cpp @@ -148,8 +148,8 @@ PackedStringArray IP::resolve_hostname_addresses(const String &p_hostname, Type resolver->mutex.unlock(); PackedStringArray result; - for (int i = 0; i < res.size(); ++i) { - result.push_back(String(res[i])); + for (const IPAddress &E : res) { + result.push_back(String(E)); } return result; } @@ -206,9 +206,9 @@ IPAddress IP::get_resolve_item_address(ResolverID p_id) const { List<IPAddress> res = resolver->queue[p_id].response; - for (int i = 0; i < res.size(); ++i) { - if (res[i].is_valid()) { - return res[i]; + for (const IPAddress &E : res) { + if (E.is_valid()) { + return E; } } return IPAddress(); @@ -226,9 +226,9 @@ Array IP::get_resolve_item_addresses(ResolverID p_id) const { List<IPAddress> res = resolver->queue[p_id].response; Array result; - for (int i = 0; i < res.size(); ++i) { - if (res[i].is_valid()) { - result.push_back(String(res[i])); + for (const IPAddress &E : res) { + if (E.is_valid()) { + result.push_back(String(E)); } } return result; diff --git a/core/io/ip_address.cpp b/core/io/ip_address.cpp index ce74bb36d6..a93876a2b5 100644 --- a/core/io/ip_address.cpp +++ b/core/io/ip_address.cpp @@ -202,7 +202,7 @@ IPAddress::IPAddress(const String &p_string) { // Wildcard (not a valid IP) wildcard = true; - } else if (p_string.find(":") >= 0) { + } else if (p_string.contains(":")) { // IPv6 _parse_ipv6(p_string); valid = true; diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index 18dbac991c..1928f86d6a 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -1179,6 +1179,73 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int r_variant = carray; } break; + + case Variant::PACKED_VECTOR4_ARRAY: { + ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); + int32_t count = decode_uint32(buf); + buf += 4; + len -= 4; + + Vector<Vector4> varray; + + if (header & HEADER_DATA_FLAG_64) { + ERR_FAIL_MUL_OF(count, sizeof(double) * 4, ERR_INVALID_DATA); + ERR_FAIL_COND_V(count < 0 || count * sizeof(double) * 4 > (size_t)len, ERR_INVALID_DATA); + + if (r_len) { + (*r_len) += 4; // Size of count number. + } + + if (count) { + varray.resize(count); + Vector4 *w = varray.ptrw(); + + for (int32_t i = 0; i < count; i++) { + w[i].x = decode_double(buf + i * sizeof(double) * 4 + sizeof(double) * 0); + w[i].y = decode_double(buf + i * sizeof(double) * 4 + sizeof(double) * 1); + w[i].z = decode_double(buf + i * sizeof(double) * 4 + sizeof(double) * 2); + w[i].w = decode_double(buf + i * sizeof(double) * 4 + sizeof(double) * 3); + } + + int adv = sizeof(double) * 4 * count; + + if (r_len) { + (*r_len) += adv; + } + len -= adv; + buf += adv; + } + } else { + ERR_FAIL_MUL_OF(count, sizeof(float) * 4, ERR_INVALID_DATA); + ERR_FAIL_COND_V(count < 0 || count * sizeof(float) * 4 > (size_t)len, ERR_INVALID_DATA); + + if (r_len) { + (*r_len) += 4; // Size of count number. + } + + if (count) { + varray.resize(count); + Vector4 *w = varray.ptrw(); + + for (int32_t i = 0; i < count; i++) { + w[i].x = decode_float(buf + i * sizeof(float) * 4 + sizeof(float) * 0); + w[i].y = decode_float(buf + i * sizeof(float) * 4 + sizeof(float) * 1); + w[i].z = decode_float(buf + i * sizeof(float) * 4 + sizeof(float) * 2); + w[i].w = decode_float(buf + i * sizeof(float) * 4 + sizeof(float) * 3); + } + + int adv = sizeof(float) * 4 * count; + + if (r_len) { + (*r_len) += adv; + } + len -= adv; + buf += adv; + } + } + r_variant = varray; + + } break; default: { ERR_FAIL_V(ERR_BUG); } @@ -1263,6 +1330,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo case Variant::VECTOR4: case Variant::PACKED_VECTOR2_ARRAY: case Variant::PACKED_VECTOR3_ARRAY: + case Variant::PACKED_VECTOR4_ARRAY: case Variant::TRANSFORM2D: case Variant::TRANSFORM3D: case Variant::PROJECTION: @@ -1628,7 +1696,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo Variant value; - if (E.name == CoreStringNames::get_singleton()->_script) { + if (E.name == CoreStringName(script)) { Ref<Script> script = obj->get_script(); if (script.is_valid()) { String path = script->get_path(); @@ -1947,6 +2015,32 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 4 * 4 * len; } break; + case Variant::PACKED_VECTOR4_ARRAY: { + Vector<Vector4> data = p_variant; + int len = data.size(); + + if (buf) { + encode_uint32(len, buf); + buf += 4; + } + + r_len += 4; + + if (buf) { + for (int i = 0; i < len; i++) { + Vector4 v = data.get(i); + + encode_real(v.x, &buf[0]); + encode_real(v.y, &buf[sizeof(real_t)]); + encode_real(v.z, &buf[sizeof(real_t) * 2]); + encode_real(v.w, &buf[sizeof(real_t) * 3]); + buf += sizeof(real_t) * 4; + } + } + + r_len += sizeof(real_t) * 4 * len; + + } break; default: { ERR_FAIL_V(ERR_BUG); } diff --git a/core/io/packed_data_container.cpp b/core/io/packed_data_container.cpp index 11b0c69774..b20279c9ac 100644 --- a/core/io/packed_data_container.cpp +++ b/core/io/packed_data_container.cpp @@ -244,6 +244,7 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpd case Variant::PACKED_VECTOR2_ARRAY: case Variant::PACKED_VECTOR3_ARRAY: case Variant::PACKED_COLOR_ARRAY: + case Variant::PACKED_VECTOR4_ARRAY: case Variant::STRING_NAME: case Variant::NODE_PATH: { uint32_t pos = tmpdata.size(); diff --git a/core/io/resource.cpp b/core/io/resource.cpp index 74f18ceee1..24ff0e83d2 100644 --- a/core/io/resource.cpp +++ b/core/io/resource.cpp @@ -43,9 +43,9 @@ void Resource::emit_changed() { if (ResourceLoader::is_within_load() && !Thread::is_main_thread()) { // Let the connection happen on the main thread, later, since signals are not thread-safe. - call_deferred("emit_signal", CoreStringNames::get_singleton()->changed); + call_deferred("emit_signal", CoreStringName(changed)); } else { - emit_signal(CoreStringNames::get_singleton()->changed); + emit_signal(CoreStringName(changed)); } } @@ -172,8 +172,8 @@ void Resource::connect_changed(const Callable &p_callable, uint32_t p_flags) { callable_mp(this, &Resource::connect_changed).call_deferred(p_callable, p_flags); return; } - if (!is_connected(CoreStringNames::get_singleton()->changed, p_callable) || p_flags & CONNECT_REFERENCE_COUNTED) { - connect(CoreStringNames::get_singleton()->changed, p_callable, p_flags); + if (!is_connected(CoreStringName(changed), p_callable) || p_flags & CONNECT_REFERENCE_COUNTED) { + connect(CoreStringName(changed), p_callable, p_flags); } } @@ -183,8 +183,8 @@ void Resource::disconnect_changed(const Callable &p_callable) { callable_mp(this, &Resource::disconnect_changed).call_deferred(p_callable); return; } - if (is_connected(CoreStringNames::get_singleton()->changed, p_callable)) { - disconnect(CoreStringNames::get_singleton()->changed, p_callable); + if (is_connected(CoreStringName(changed), p_callable)) { + disconnect(CoreStringName(changed), p_callable); } } @@ -383,7 +383,8 @@ Ref<Resource> Resource::duplicate(bool p_subresources) const { case Variant::Type::PACKED_FLOAT64_ARRAY: case Variant::Type::PACKED_STRING_ARRAY: case Variant::Type::PACKED_VECTOR2_ARRAY: - case Variant::Type::PACKED_VECTOR3_ARRAY: { + case Variant::Type::PACKED_VECTOR3_ARRAY: + case Variant::Type::PACKED_VECTOR4_ARRAY: { r->set(E.name, p.duplicate(p_subresources)); } break; diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index d0a8200546..ab460c5f4c 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -85,15 +85,17 @@ enum { VARIANT_VECTOR4 = 50, VARIANT_VECTOR4I = 51, VARIANT_PROJECTION = 52, + VARIANT_PACKED_VECTOR4_ARRAY = 53, OBJECT_EMPTY = 0, OBJECT_EXTERNAL_RESOURCE = 1, OBJECT_INTERNAL_RESOURCE = 2, OBJECT_EXTERNAL_RESOURCE_INDEX = 3, - // Version 2: added 64 bits support for float and int. - // Version 3: changed nodepath encoding. - // Version 4: new string ID for ext/subresources, breaks forward compat. + // Version 2: Added 64-bit support for float and int. + // Version 3: Changed NodePath encoding. + // Version 4: New string ID for ext/subresources, breaks forward compat. // Version 5: Ability to store script class in the header. - FORMAT_VERSION = 5, + // Version 6: Added PackedVector4Array Variant type. + FORMAT_VERSION = 6, FORMAT_VERSION_CAN_RENAME_DEPS = 1, FORMAT_VERSION_NO_NODEPATH_PROPERTY = 3, }; @@ -653,6 +655,19 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { r_v = array; } break; + case VARIANT_PACKED_VECTOR4_ARRAY: { + uint32_t len = f->get_32(); + + Vector<Vector4> array; + array.resize(len); + Vector4 *w = array.ptrw(); + static_assert(sizeof(Vector4) == 4 * sizeof(real_t)); + const Error err = read_reals(reinterpret_cast<real_t *>(w), f, len * 4); + ERR_FAIL_COND_V(err != OK, err); + + r_v = array; + + } break; default: { ERR_FAIL_V(ERR_FILE_CORRUPT); } break; @@ -1912,33 +1927,33 @@ void ResourceFormatSaverBinaryInstance::write_variant(Ref<FileAccess> f, const V for (int i = 0; i < len; i++) { save_unicode_string(f, r[i]); } - } break; - case Variant::PACKED_VECTOR3_ARRAY: { - f->store_32(VARIANT_PACKED_VECTOR3_ARRAY); - Vector<Vector3> arr = p_property; + + case Variant::PACKED_VECTOR2_ARRAY: { + f->store_32(VARIANT_PACKED_VECTOR2_ARRAY); + Vector<Vector2> arr = p_property; int len = arr.size(); f->store_32(len); - const Vector3 *r = arr.ptr(); + const Vector2 *r = arr.ptr(); for (int i = 0; i < len; i++) { f->store_real(r[i].x); f->store_real(r[i].y); - f->store_real(r[i].z); } - } break; - case Variant::PACKED_VECTOR2_ARRAY: { - f->store_32(VARIANT_PACKED_VECTOR2_ARRAY); - Vector<Vector2> arr = p_property; + + case Variant::PACKED_VECTOR3_ARRAY: { + f->store_32(VARIANT_PACKED_VECTOR3_ARRAY); + Vector<Vector3> arr = p_property; int len = arr.size(); f->store_32(len); - const Vector2 *r = arr.ptr(); + const Vector3 *r = arr.ptr(); for (int i = 0; i < len; i++) { f->store_real(r[i].x); f->store_real(r[i].y); + f->store_real(r[i].z); } - } break; + case Variant::PACKED_COLOR_ARRAY: { f->store_32(VARIANT_PACKED_COLOR_ARRAY); Vector<Color> arr = p_property; @@ -1953,6 +1968,20 @@ void ResourceFormatSaverBinaryInstance::write_variant(Ref<FileAccess> f, const V } } break; + case Variant::PACKED_VECTOR4_ARRAY: { + f->store_32(VARIANT_PACKED_VECTOR4_ARRAY); + Vector<Vector4> arr = p_property; + int len = arr.size(); + f->store_32(len); + const Vector4 *r = arr.ptr(); + for (int i = 0; i < len; i++) { + f->store_real(r[i].x); + f->store_real(r[i].y); + f->store_real(r[i].z); + f->store_real(r[i].w); + } + + } break; default: { ERR_FAIL_MSG("Invalid variant."); } diff --git a/core/io/udp_server.cpp b/core/io/udp_server.cpp index 215c6903a6..75ba784dbd 100644 --- a/core/io/udp_server.cpp +++ b/core/io/udp_server.cpp @@ -161,7 +161,7 @@ Ref<PacketPeerUDP> UDPServer::take_connection() { return conn; } - Peer peer = pending[0]; + Peer peer = pending.front()->get(); pending.pop_front(); peers.push_back(peer); return peer.peer; |