summaryrefslogtreecommitdiff
path: root/core/packed_data_container.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/packed_data_container.cpp')
-rw-r--r--core/packed_data_container.cpp43
1 files changed, 0 insertions, 43 deletions
diff --git a/core/packed_data_container.cpp b/core/packed_data_container.cpp
index 17b5905a93..b8f83f96a5 100644
--- a/core/packed_data_container.cpp
+++ b/core/packed_data_container.cpp
@@ -34,7 +34,6 @@
#include "core/io/marshalls.h"
Variant PackedDataContainer::getvar(const Variant &p_key, bool *r_valid) const {
-
bool err = false;
Variant ret = _key_at_ofs(0, p_key, err);
if (r_valid)
@@ -43,12 +42,10 @@ Variant PackedDataContainer::getvar(const Variant &p_key, bool *r_valid) const {
}
int PackedDataContainer::size() const {
-
return _size(0);
};
Variant PackedDataContainer::_iter_init_ofs(const Array &p_iter, uint32_t p_offset) {
-
Array ref = p_iter;
uint32_t size = _size(p_offset);
if (size == 0 || ref.size() != 1)
@@ -60,7 +57,6 @@ Variant PackedDataContainer::_iter_init_ofs(const Array &p_iter, uint32_t p_offs
}
Variant PackedDataContainer::_iter_next_ofs(const Array &p_iter, uint32_t p_offset) {
-
Array ref = p_iter;
int size = _size(p_offset);
if (ref.size() != 1)
@@ -74,7 +70,6 @@ Variant PackedDataContainer::_iter_next_ofs(const Array &p_iter, uint32_t p_offs
}
Variant PackedDataContainer::_iter_get_ofs(const Variant &p_iter, uint32_t p_offset) {
-
int size = _size(p_offset);
int pos = p_iter;
if (pos < 0 || pos >= size)
@@ -86,12 +81,10 @@ Variant PackedDataContainer::_iter_get_ofs(const Variant &p_iter, uint32_t p_off
bool err = false;
if (type == TYPE_ARRAY) {
-
uint32_t vpos = decode_uint32(rd + p_offset + 8 + pos * 4);
return _get_at_ofs(vpos, rd, err);
} else if (type == TYPE_DICT) {
-
uint32_t vpos = decode_uint32(rd + p_offset + 8 + pos * 12 + 4);
return _get_at_ofs(vpos, rd, err);
} else {
@@ -100,11 +93,9 @@ Variant PackedDataContainer::_iter_get_ofs(const Variant &p_iter, uint32_t p_off
}
Variant PackedDataContainer::_get_at_ofs(uint32_t p_ofs, const uint8_t *p_buf, bool &err) const {
-
uint32_t type = decode_uint32(p_buf + p_ofs);
if (type == TYPE_ARRAY || type == TYPE_DICT) {
-
Ref<PackedDataContainerRef> pdcr = memnew(PackedDataContainerRef);
Ref<PackedDataContainer> pdc = Ref<PackedDataContainer>((PackedDataContainer *)this);
@@ -112,12 +103,10 @@ Variant PackedDataContainer::_get_at_ofs(uint32_t p_ofs, const uint8_t *p_buf, b
pdcr->offset = p_ofs;
return pdcr;
} else {
-
Variant v;
Error rerr = decode_variant(v, p_buf + p_ofs, datalen - p_ofs, nullptr, false);
if (rerr != OK) {
-
err = true;
ERR_FAIL_COND_V_MSG(err != OK, Variant(), "Error when trying to decode Variant.");
}
@@ -126,7 +115,6 @@ Variant PackedDataContainer::_get_at_ofs(uint32_t p_ofs, const uint8_t *p_buf, b
}
uint32_t PackedDataContainer::_type_at_ofs(uint32_t p_ofs) const {
-
const uint8_t *rd = data.ptr();
const uint8_t *r = &rd[p_ofs];
uint32_t type = decode_uint32(r);
@@ -135,19 +123,16 @@ uint32_t PackedDataContainer::_type_at_ofs(uint32_t p_ofs) const {
};
int PackedDataContainer::_size(uint32_t p_ofs) const {
-
const uint8_t *rd = data.ptr();
ERR_FAIL_COND_V(!rd, 0);
const uint8_t *r = &rd[p_ofs];
uint32_t type = decode_uint32(r);
if (type == TYPE_ARRAY) {
-
uint32_t len = decode_uint32(r + 4);
return len;
} else if (type == TYPE_DICT) {
-
uint32_t len = decode_uint32(r + 4);
return len;
};
@@ -156,15 +141,12 @@ int PackedDataContainer::_size(uint32_t p_ofs) const {
};
Variant PackedDataContainer::_key_at_ofs(uint32_t p_ofs, const Variant &p_key, bool &err) const {
-
const uint8_t *rd = data.ptr();
const uint8_t *r = &rd[p_ofs];
uint32_t type = decode_uint32(r);
if (type == TYPE_ARRAY) {
-
if (p_key.is_num()) {
-
int idx = p_key;
int len = decode_uint32(r + 4);
if (idx < 0 || idx >= len) {
@@ -180,7 +162,6 @@ Variant PackedDataContainer::_key_at_ofs(uint32_t p_ofs, const Variant &p_key, b
}
} else if (type == TYPE_DICT) {
-
uint32_t hash = p_key.hash();
uint32_t len = decode_uint32(r + 4);
@@ -206,18 +187,14 @@ Variant PackedDataContainer::_key_at_ofs(uint32_t p_ofs, const Variant &p_key, b
return Variant();
} else {
-
err = true;
return Variant();
}
}
uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpdata, Map<String, uint32_t> &string_cache) {
-
switch (p_data.get_type()) {
-
case Variant::STRING: {
-
String s = p_data;
if (string_cache.has(s)) {
return string_cache[s];
@@ -251,7 +228,6 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpd
case Variant::PACKED_COLOR_ARRAY:
case Variant::STRING_NAME:
case Variant::NODE_PATH: {
-
uint32_t pos = tmpdata.size();
int len;
encode_variant(p_data, nullptr, len, false);
@@ -263,11 +239,9 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpd
// misc types
case Variant::_RID:
case Variant::OBJECT: {
-
return _pack(Variant(), tmpdata, string_cache);
} break;
case Variant::DICTIONARY: {
-
Dictionary d = p_data;
//size is known, use sort
uint32_t pos = tmpdata.size();
@@ -281,7 +255,6 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpd
List<DictKey> sortk;
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
-
DictKey dk;
dk.hash = E->get().hash();
dk.key = E->get();
@@ -292,7 +265,6 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpd
int idx = 0;
for (List<DictKey>::Element *E = sortk.front(); E; E = E->next()) {
-
encode_uint32(E->get().hash, &tmpdata.write[pos + 8 + idx * 12 + 0]);
uint32_t ofs = _pack(E->get().key, tmpdata, string_cache);
encode_uint32(ofs, &tmpdata.write[pos + 8 + idx * 12 + 4]);
@@ -305,7 +277,6 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpd
} break;
case Variant::ARRAY: {
-
Array a = p_data;
//size is known, use sort
uint32_t pos = tmpdata.size();
@@ -315,7 +286,6 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpd
encode_uint32(len, &tmpdata.write[pos + 4]);
for (int i = 0; i < len; i++) {
-
uint32_t ofs = _pack(a[i], tmpdata, string_cache);
encode_uint32(ofs, &tmpdata.write[pos + 8 + i * 4]);
}
@@ -332,7 +302,6 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpd
}
Error PackedDataContainer::pack(const Variant &p_data) {
-
Vector<uint8_t> tmpdata;
Map<String, uint32_t> string_cache;
_pack(p_data, tmpdata, string_cache);
@@ -345,7 +314,6 @@ Error PackedDataContainer::pack(const Variant &p_data) {
}
void PackedDataContainer::_set_data(const Vector<uint8_t> &p_data) {
-
data = p_data;
datalen = data.size();
}
@@ -355,21 +323,17 @@ Vector<uint8_t> PackedDataContainer::_get_data() const {
}
Variant PackedDataContainer::_iter_init(const Array &p_iter) {
-
return _iter_init_ofs(p_iter, 0);
}
Variant PackedDataContainer::_iter_next(const Array &p_iter) {
-
return _iter_next_ofs(p_iter, 0);
}
Variant PackedDataContainer::_iter_get(const Variant &p_iter) {
-
return _iter_get_ofs(p_iter, 0);
}
void PackedDataContainer::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("_set_data"), &PackedDataContainer::_set_data);
ClassDB::bind_method(D_METHOD("_get_data"), &PackedDataContainer::_get_data);
ClassDB::bind_method(D_METHOD("_iter_init"), &PackedDataContainer::_iter_init);
@@ -384,26 +348,21 @@ void PackedDataContainer::_bind_methods() {
//////////////////
Variant PackedDataContainerRef::_iter_init(const Array &p_iter) {
-
return from->_iter_init_ofs(p_iter, offset);
}
Variant PackedDataContainerRef::_iter_next(const Array &p_iter) {
-
return from->_iter_next_ofs(p_iter, offset);
}
Variant PackedDataContainerRef::_iter_get(const Variant &p_iter) {
-
return from->_iter_get_ofs(p_iter, offset);
}
bool PackedDataContainerRef::_is_dictionary() const {
-
return from->_type_at_ofs(offset) == PackedDataContainer::TYPE_DICT;
};
void PackedDataContainerRef::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("size"), &PackedDataContainerRef::size);
ClassDB::bind_method(D_METHOD("_iter_init"), &PackedDataContainerRef::_iter_init);
ClassDB::bind_method(D_METHOD("_iter_get"), &PackedDataContainerRef::_iter_get);
@@ -412,7 +371,6 @@ void PackedDataContainerRef::_bind_methods() {
}
Variant PackedDataContainerRef::getvar(const Variant &p_key, bool *r_valid) const {
-
bool err = false;
Variant ret = from->_key_at_ofs(offset, p_key, err);
if (r_valid)
@@ -421,6 +379,5 @@ Variant PackedDataContainerRef::getvar(const Variant &p_key, bool *r_valid) cons
}
int PackedDataContainerRef::size() const {
-
return from->_size(offset);
};