mirror of
https://github.com/overte-org/overte.git
synced 2025-04-14 07:27:04 +02:00
OctreeDataUtils - use new json from DS also; allow upload of large domains
This commit is contained in:
parent
8c347fae70
commit
6ee837d47c
3 changed files with 25 additions and 54 deletions
|
@ -3411,20 +3411,11 @@ void DomainServer::maybeHandleReplacementEntityFile() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DomainServer::handleOctreeFileReplacement(QByteArray octreeFile) {
|
void DomainServer::handleOctreeFileReplacement(QByteArray octreeFile) {
|
||||||
//Assume we have compressed data
|
|
||||||
auto compressedOctree = octreeFile;
|
|
||||||
QByteArray jsonOctree;
|
|
||||||
|
|
||||||
bool wasCompressed = gunzip(compressedOctree, jsonOctree);
|
|
||||||
if (!wasCompressed) {
|
|
||||||
// the source was not compressed, assume we were sent regular JSON data
|
|
||||||
jsonOctree = compressedOctree;
|
|
||||||
}
|
|
||||||
|
|
||||||
OctreeUtils::RawEntityData data;
|
OctreeUtils::RawEntityData data;
|
||||||
if (data.readOctreeDataInfoFromData(jsonOctree)) {
|
if (data.readOctreeDataInfoFromData(octreeFile)) {
|
||||||
data.resetIdAndVersion();
|
data.resetIdAndVersion();
|
||||||
|
|
||||||
|
QByteArray compressedOctree;
|
||||||
gzip(data.toByteArray(), compressedOctree);
|
gzip(data.toByteArray(), compressedOctree);
|
||||||
|
|
||||||
// write the compressed octree data to a special file
|
// write the compressed octree data to a special file
|
||||||
|
|
|
@ -47,16 +47,6 @@ namespace {
|
||||||
|
|
||||||
} // Anon namespace.
|
} // Anon namespace.
|
||||||
|
|
||||||
bool OctreeUtils::RawOctreeData::readOctreeDataInfoFromJSON(QJsonObject root) {
|
|
||||||
if (root.contains("Id") && root.contains("DataVersion") && root.contains("Version")) {
|
|
||||||
id = root["Id"].toVariant().toUuid();
|
|
||||||
dataVersion = root["DataVersion"].toInt();
|
|
||||||
version = root["Version"].toInt();
|
|
||||||
}
|
|
||||||
readSubclassData(root);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool OctreeUtils::RawOctreeData::readOctreeDataInfoFromMap(const QVariantMap& map) {
|
bool OctreeUtils::RawOctreeData::readOctreeDataInfoFromMap(const QVariantMap& map) {
|
||||||
if (map.contains("Id") && map.contains("DataVersion") && map.contains("Version")) {
|
if (map.contains("Id") && map.contains("DataVersion") && map.contains("Version")) {
|
||||||
id = map["Id"].toUuid();
|
id = map["Id"].toUuid();
|
||||||
|
@ -94,28 +84,25 @@ bool OctreeUtils::RawOctreeData::readOctreeDataInfoFromFile(QString path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray data = file.readAll();
|
QByteArray data = file.readAll();
|
||||||
QByteArray jsonData;
|
|
||||||
|
|
||||||
if (!gunzip(data, jsonData)) {
|
return readOctreeDataInfoFromData(data);
|
||||||
jsonData = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
return readOctreeDataInfoFromData(jsonData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray OctreeUtils::RawOctreeData::toByteArray() {
|
QByteArray OctreeUtils::RawOctreeData::toByteArray() {
|
||||||
QJsonObject obj {
|
QByteArray jsonString;
|
||||||
{ "DataVersion", QJsonValue((qint64)dataVersion) },
|
|
||||||
{ "Id", QJsonValue(id.toString()) },
|
|
||||||
{ "Version", QJsonValue((qint64)version) },
|
|
||||||
};
|
|
||||||
|
|
||||||
writeSubclassData(obj);
|
jsonString += QString(R"({
|
||||||
|
"DataVersion": %1,
|
||||||
|
)").arg(dataVersion);
|
||||||
|
|
||||||
QJsonDocument doc;
|
writeSubclassData(jsonString);
|
||||||
doc.setObject(obj);
|
|
||||||
|
|
||||||
return doc.toJson();
|
jsonString += QString(R"(,
|
||||||
|
"Id": "%1",
|
||||||
|
"Version": %2
|
||||||
|
})").arg(id.toString()).arg(version);
|
||||||
|
|
||||||
|
return jsonString;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray OctreeUtils::RawOctreeData::toGzippedByteArray() {
|
QByteArray OctreeUtils::RawOctreeData::toGzippedByteArray() {
|
||||||
|
@ -142,24 +129,21 @@ void OctreeUtils::RawOctreeData::resetIdAndVersion() {
|
||||||
qDebug() << "Reset octree data to: " << id << dataVersion;
|
qDebug() << "Reset octree data to: " << id << dataVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OctreeUtils::RawEntityData::readSubclassData(const QJsonObject& root) {
|
|
||||||
if (root.contains("Entities")) {
|
|
||||||
entityData = root["Entities"].toArray();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void OctreeUtils::RawEntityData::readSubclassData(const QVariantMap& root) {
|
void OctreeUtils::RawEntityData::readSubclassData(const QVariantMap& root) {
|
||||||
variantEntityData = root["Entities"].toList();
|
variantEntityData = root["Entities"].toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OctreeUtils::RawEntityData::writeSubclassData(QJsonObject& root) const {
|
void OctreeUtils::RawEntityData::writeSubclassData(QByteArray& root) const {
|
||||||
//root["Entities"] = entityData;
|
root += " \"Entities\": [";
|
||||||
QJsonArray entitiesJsonArray;
|
|
||||||
for (auto entityIter = variantEntityData.begin(); entityIter != variantEntityData.end(); ++entityIter) {
|
for (auto entityIter = variantEntityData.begin(); entityIter != variantEntityData.end(); ++entityIter) {
|
||||||
entitiesJsonArray += entityIter->toJsonObject();
|
if (entityIter != variantEntityData.begin()) {
|
||||||
|
root += ",";
|
||||||
|
}
|
||||||
|
root += "\n ";
|
||||||
|
// Convert to string and remove trailing LF.
|
||||||
|
root += QJsonDocument(entityIter->toJsonObject()).toJson().chopped(1);
|
||||||
}
|
}
|
||||||
|
root += "]";
|
||||||
root["Entities"] = entitiesJsonArray;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PacketType OctreeUtils::RawEntityData::dataPacketType() const { return PacketType::EntityData; }
|
PacketType OctreeUtils::RawEntityData::dataPacketType() const { return PacketType::EntityData; }
|
||||||
|
|
|
@ -33,9 +33,8 @@ public:
|
||||||
|
|
||||||
virtual PacketType dataPacketType() const;
|
virtual PacketType dataPacketType() const;
|
||||||
|
|
||||||
virtual void readSubclassData(const QJsonObject& root) { }
|
|
||||||
virtual void readSubclassData(const QVariantMap& root) { }
|
virtual void readSubclassData(const QVariantMap& root) { }
|
||||||
virtual void writeSubclassData(QJsonObject& root) const { }
|
virtual void writeSubclassData(QByteArray& root) const { }
|
||||||
|
|
||||||
void resetIdAndVersion();
|
void resetIdAndVersion();
|
||||||
QByteArray toByteArray();
|
QByteArray toByteArray();
|
||||||
|
@ -43,18 +42,15 @@ public:
|
||||||
|
|
||||||
bool readOctreeDataInfoFromData(QByteArray data);
|
bool readOctreeDataInfoFromData(QByteArray data);
|
||||||
bool readOctreeDataInfoFromFile(QString path);
|
bool readOctreeDataInfoFromFile(QString path);
|
||||||
bool readOctreeDataInfoFromJSON(QJsonObject root);
|
|
||||||
bool readOctreeDataInfoFromMap(const QVariantMap& map);
|
bool readOctreeDataInfoFromMap(const QVariantMap& map);
|
||||||
};
|
};
|
||||||
|
|
||||||
class RawEntityData : public RawOctreeData {
|
class RawEntityData : public RawOctreeData {
|
||||||
public:
|
public:
|
||||||
PacketType dataPacketType() const override;
|
PacketType dataPacketType() const override;
|
||||||
void readSubclassData(const QJsonObject& root) override;
|
|
||||||
void readSubclassData(const QVariantMap& root) override;
|
void readSubclassData(const QVariantMap& root) override;
|
||||||
void writeSubclassData(QJsonObject& root) const override;
|
void writeSubclassData(QByteArray& root) const override;
|
||||||
|
|
||||||
QJsonArray entityData;
|
|
||||||
QVariantList variantEntityData;
|
QVariantList variantEntityData;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue