mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 13:58:51 +02:00
Add RawEntityData subclass
This commit is contained in:
parent
975bfa6809
commit
3fa538d42d
10 changed files with 70 additions and 35 deletions
|
@ -1157,7 +1157,7 @@ void OctreeServer::domainSettingsRequestComplete() {
|
||||||
|
|
||||||
OctreeUtils::RawOctreeData data;
|
OctreeUtils::RawOctreeData data;
|
||||||
qCDebug(octree_server) << "Reading octree data from" << _persistAbsoluteFilePath;
|
qCDebug(octree_server) << "Reading octree data from" << _persistAbsoluteFilePath;
|
||||||
if (OctreeUtils::readOctreeDataInfoFromFile(_persistAbsoluteFilePath, &data)) {
|
if (data.readOctreeDataInfoFromFile(_persistAbsoluteFilePath)) {
|
||||||
qCDebug(octree_server) << "Current octree data: ID(" << data.id << ") DataVersion(" << data.version << ")";
|
qCDebug(octree_server) << "Current octree data: ID(" << data.id << ") DataVersion(" << data.version << ")";
|
||||||
packet->writePrimitive(true);
|
packet->writePrimitive(true);
|
||||||
auto id = data.id.toRfc4122();
|
auto id = data.id.toRfc4122();
|
||||||
|
@ -1189,7 +1189,7 @@ void OctreeServer::handleOctreeDataFileReply(QSharedPointer<ReceivedMessage> mes
|
||||||
|
|
||||||
OctreeUtils::RawOctreeData data;
|
OctreeUtils::RawOctreeData data;
|
||||||
qCDebug(octree_server) << "Reading octree data from" << _persistAbsoluteFilePath;
|
qCDebug(octree_server) << "Reading octree data from" << _persistAbsoluteFilePath;
|
||||||
if (OctreeUtils::readOctreeDataInfoFromFile(_persistAbsoluteFilePath, &data)) {
|
if (data.readOctreeDataInfoFromFile(_persistAbsoluteFilePath)) {
|
||||||
if (data.id.isNull()) {
|
if (data.id.isNull()) {
|
||||||
qCDebug(octree_server) << "Current octree data has a null id, updating";
|
qCDebug(octree_server) << "Current octree data has a null id, updating";
|
||||||
data.resetIdAndVersion();
|
data.resetIdAndVersion();
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#include "DomainServer.h"
|
#include "DomainServer.h"
|
||||||
|
|
||||||
const std::chrono::seconds DomainContentBackupManager::DEFAULT_PERSIST_INTERVAL { 30 };
|
const std::chrono::seconds DomainContentBackupManager::DEFAULT_PERSIST_INTERVAL { 30 };
|
||||||
|
|
||||||
// Backup format looks like: daily_backup-TIMESTAMP.zip
|
// Backup format looks like: daily_backup-TIMESTAMP.zip
|
||||||
static const QString DATETIME_FORMAT { "yyyy-MM-dd_HH-mm-ss" };
|
static const QString DATETIME_FORMAT { "yyyy-MM-dd_HH-mm-ss" };
|
||||||
static const QString DATETIME_FORMAT_RE { "\\d{4}-\\d{2}-\\d{2}_\\d{2}-\\d{2}-\\d{2}" };
|
static const QString DATETIME_FORMAT_RE { "\\d{4}-\\d{2}-\\d{2}_\\d{2}-\\d{2}-\\d{2}" };
|
||||||
|
|
|
@ -1745,9 +1745,9 @@ void DomainServer::processOctreeDataPersistMessage(QSharedPointer<ReceivedMessag
|
||||||
QFile f(filePath);
|
QFile f(filePath);
|
||||||
if (f.open(QIODevice::WriteOnly)) {
|
if (f.open(QIODevice::WriteOnly)) {
|
||||||
f.write(data);
|
f.write(data);
|
||||||
OctreeUtils::RawOctreeData octreeData;
|
OctreeUtils::RawEntityData entityData;
|
||||||
if (OctreeUtils::readOctreeDataInfoFromData(data, &octreeData)) {
|
if (entityData.readOctreeDataInfoFromData(data)) {
|
||||||
qCDebug(domain_server) << "Wrote new entities file" << octreeData.id << octreeData.version;
|
qCDebug(domain_server) << "Wrote new entities file" << entityData.id << entityData.version;
|
||||||
} else {
|
} else {
|
||||||
qCDebug(domain_server) << "Failed to read new octree data info";
|
qCDebug(domain_server) << "Failed to read new octree data info";
|
||||||
}
|
}
|
||||||
|
@ -1793,8 +1793,8 @@ void DomainServer::processOctreeDataRequestMessage(QSharedPointer<ReceivedMessag
|
||||||
auto entityFilePath = getEntitiesFilePath();
|
auto entityFilePath = getEntitiesFilePath();
|
||||||
|
|
||||||
auto reply = NLPacketList::create(PacketType::OctreeDataFileReply, QByteArray(), true, true);
|
auto reply = NLPacketList::create(PacketType::OctreeDataFileReply, QByteArray(), true, true);
|
||||||
OctreeUtils::RawOctreeData data;
|
OctreeUtils::RawEntityData data;
|
||||||
if (OctreeUtils::readOctreeDataInfoFromFile(entityFilePath, &data)) {
|
if (data.readOctreeDataInfoFromFile(entityFilePath)) {
|
||||||
if (data.id == id && data.version <= version) {
|
if (data.id == id && data.version <= version) {
|
||||||
qCDebug(domain_server) << "ES has sufficient octree data, not sending data";
|
qCDebug(domain_server) << "ES has sufficient octree data, not sending data";
|
||||||
reply->writePrimitive(false);
|
reply->writePrimitive(false);
|
||||||
|
@ -3344,8 +3344,8 @@ void DomainServer::setupGroupCacheRefresh() {
|
||||||
|
|
||||||
void DomainServer::maybeHandleReplacementEntityFile() {
|
void DomainServer::maybeHandleReplacementEntityFile() {
|
||||||
const auto replacementFilePath = getEntitiesReplacementFilePath();
|
const auto replacementFilePath = getEntitiesReplacementFilePath();
|
||||||
OctreeUtils::RawOctreeData data;
|
OctreeUtils::RawEntityData data;
|
||||||
if (!OctreeUtils::readOctreeDataInfoFromFile(replacementFilePath, &data)) {
|
if (!data.readOctreeDataInfoFromFile(replacementFilePath)) {
|
||||||
qCWarning(domain_server) << "Replacement file could not be read, it either doesn't exist or is invalid.";
|
qCWarning(domain_server) << "Replacement file could not be read, it either doesn't exist or is invalid.";
|
||||||
} else {
|
} else {
|
||||||
qCDebug(domain_server) << "Replacing existing entity date with replacement file";
|
qCDebug(domain_server) << "Replacing existing entity date with replacement file";
|
||||||
|
@ -3381,8 +3381,8 @@ void DomainServer::handleOctreeFileReplacement(QByteArray octreeFile) {
|
||||||
jsonOctree = compressedOctree;
|
jsonOctree = compressedOctree;
|
||||||
}
|
}
|
||||||
|
|
||||||
OctreeUtils::RawOctreeData data;
|
OctreeUtils::RawEntityData data;
|
||||||
if (OctreeUtils::readOctreeDataInfoFromData(jsonOctree, &data)) {
|
if (data.readOctreeDataInfoFromData(jsonOctree)) {
|
||||||
data.resetIdAndVersion();
|
data.resetIdAndVersion();
|
||||||
|
|
||||||
gzip(data.toByteArray(), compressedOctree);
|
gzip(data.toByteArray(), compressedOctree);
|
||||||
|
|
|
@ -62,8 +62,8 @@ void EntitiesBackupHandler::recoverBackup(const QString& backupName, QuaZip& zip
|
||||||
|
|
||||||
zipFile.close();
|
zipFile.close();
|
||||||
|
|
||||||
OctreeUtils::RawOctreeData data;
|
OctreeUtils::RawEntityData data;
|
||||||
if (!OctreeUtils::readOctreeDataInfoFromData(rawData, &data)) {
|
if (!data.readOctreeDataInfoFromData(rawData)) {
|
||||||
qCritical() << "Unable to parse octree data during backup recovery";
|
qCritical() << "Unable to parse octree data during backup recovery";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,6 +115,8 @@ public:
|
||||||
|
|
||||||
virtual void update() override { update(true); }
|
virtual void update() override { update(true); }
|
||||||
|
|
||||||
|
std::unique_ptr<OctreeUtils::RawOctreeData> getRawOctreeData();
|
||||||
|
|
||||||
void update(bool simulate);
|
void update(bool simulate);
|
||||||
|
|
||||||
// The newer API...
|
// The newer API...
|
||||||
|
|
|
@ -328,7 +328,7 @@ void Socket::checkForReadyReadBackup() {
|
||||||
void Socket::readPendingDatagrams() {
|
void Socket::readPendingDatagrams() {
|
||||||
int packetSizeWithHeader = -1;
|
int packetSizeWithHeader = -1;
|
||||||
|
|
||||||
while ((packetSizeWithHeader = _udpSocket.pendingDatagramSize()) != -1) {
|
while ((packetSizeWithHeader = _udpSocket.pendingDatagramSize()) > 0) {
|
||||||
|
|
||||||
// we're reading a packet so re-start the readyRead backup timer
|
// we're reading a packet so re-start the readyRead backup timer
|
||||||
_readyReadBackupTimer->start();
|
_readyReadBackupTimer->start();
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include "OctreeElementBag.h"
|
#include "OctreeElementBag.h"
|
||||||
#include "OctreePacketData.h"
|
#include "OctreePacketData.h"
|
||||||
#include "OctreeSceneStats.h"
|
#include "OctreeSceneStats.h"
|
||||||
|
#include "OctreeUtils.h"
|
||||||
|
|
||||||
class ReadBitstreamToTreeParams;
|
class ReadBitstreamToTreeParams;
|
||||||
class Octree;
|
class Octree;
|
||||||
|
@ -328,7 +329,7 @@ public:
|
||||||
virtual void dumpTree() { }
|
virtual void dumpTree() { }
|
||||||
virtual void pruneTree() { }
|
virtual void pruneTree() { }
|
||||||
|
|
||||||
void setEntityVersionInfo(QUuid id, int64_t dataVersion) {
|
void setOctreeVersionInfo(QUuid id, int64_t dataVersion) {
|
||||||
_persistID = id;
|
_persistID = id;
|
||||||
_persistDataVersion = dataVersion;
|
_persistDataVersion = dataVersion;
|
||||||
}
|
}
|
||||||
|
|
|
@ -176,9 +176,9 @@ bool OctreePersistThread::process() {
|
||||||
}
|
}
|
||||||
|
|
||||||
OctreeUtils::RawOctreeData data;
|
OctreeUtils::RawOctreeData data;
|
||||||
if (OctreeUtils::readOctreeDataInfoFromFile(_filename, &data)) {
|
if (data.readOctreeDataInfoFromFile(_filename)) {
|
||||||
qDebug() << "Setting entity version info to: " << data.id << data.version;
|
qDebug() << "Setting entity version info to: " << data.id << data.version;
|
||||||
_tree->setEntityVersionInfo(data.id, data.version);
|
_tree->setOctreeVersionInfo(data.id, data.version);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool persistentFileRead;
|
bool persistentFileRead;
|
||||||
|
|
|
@ -84,7 +84,7 @@ float getOrthographicAccuracySize(float octreeSizeScale, int boundaryLevelAdjust
|
||||||
// Reads octree file and parses it into a QJsonDocument. Handles both gzipped and non-gzipped files.
|
// Reads octree file and parses it into a QJsonDocument. Handles both gzipped and non-gzipped files.
|
||||||
// Returns true if the file was successfully opened and parsed, otherwise false.
|
// Returns true if the file was successfully opened and parsed, otherwise false.
|
||||||
// Example failures: file does not exist, gzipped file cannot be unzipped, invalid JSON.
|
// Example failures: file does not exist, gzipped file cannot be unzipped, invalid JSON.
|
||||||
bool OctreeUtils::readOctreeFile(QString path, QJsonDocument* doc) {
|
bool readOctreeFile(QString path, QJsonDocument* doc) {
|
||||||
QFile file(path);
|
QFile file(path);
|
||||||
if (!file.open(QIODevice::ReadOnly)) {
|
if (!file.open(QIODevice::ReadOnly)) {
|
||||||
qCritical() << "Cannot open json file for reading: " << path;
|
qCritical() << "Cannot open json file for reading: " << path;
|
||||||
|
@ -102,18 +102,16 @@ bool OctreeUtils::readOctreeFile(QString path, QJsonDocument* doc) {
|
||||||
return !doc->isNull();
|
return !doc->isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool readOctreeDataInfoFromJSON(QJsonObject root, OctreeUtils::RawOctreeData* octreeData) {
|
bool OctreeUtils::RawOctreeData::readOctreeDataInfoFromJSON(QJsonObject root) {
|
||||||
if (root.contains("Id") && root.contains("DataVersion")) {
|
if (root.contains("Id") && root.contains("DataVersion")) {
|
||||||
octreeData->id = root["Id"].toVariant().toUuid();
|
id = root["Id"].toVariant().toUuid();
|
||||||
octreeData->version = root["DataVersion"].toInt();
|
version = root["DataVersion"].toInt();
|
||||||
}
|
|
||||||
if (root.contains("Entities")) {
|
|
||||||
octreeData->octreeData = root["Entities"].toArray();
|
|
||||||
}
|
}
|
||||||
|
readSubclassData(root);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OctreeUtils::readOctreeDataInfoFromData(QByteArray data, OctreeUtils::RawOctreeData* octreeData) {
|
bool OctreeUtils::RawOctreeData::readOctreeDataInfoFromData(QByteArray data) {
|
||||||
QByteArray jsonData;
|
QByteArray jsonData;
|
||||||
if (gunzip(data, jsonData)) {
|
if (gunzip(data, jsonData)) {
|
||||||
data = jsonData;
|
data = jsonData;
|
||||||
|
@ -125,30 +123,31 @@ bool OctreeUtils::readOctreeDataInfoFromData(QByteArray data, OctreeUtils::RawOc
|
||||||
}
|
}
|
||||||
|
|
||||||
auto root = doc.object();
|
auto root = doc.object();
|
||||||
return readOctreeDataInfoFromJSON(root, octreeData);
|
return readOctreeDataInfoFromJSON(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reads octree file and parses it into a RawOctreeData object.
|
// Reads octree file and parses it into a RawOctreeData object.
|
||||||
// Returns false if readOctreeFile fails.
|
// Returns false if readOctreeFile fails.
|
||||||
bool OctreeUtils::readOctreeDataInfoFromFile(QString path, OctreeUtils::RawOctreeData* octreeData) {
|
bool OctreeUtils::RawOctreeData::readOctreeDataInfoFromFile(QString path) {
|
||||||
QJsonDocument doc;
|
QJsonDocument doc;
|
||||||
if (!OctreeUtils::readOctreeFile(path, &doc)) {
|
if (!readOctreeFile(path, &doc)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto root = doc.object();
|
auto root = doc.object();
|
||||||
return readOctreeDataInfoFromJSON(root, octreeData);
|
return readOctreeDataInfoFromJSON(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray OctreeUtils::RawOctreeData::toByteArray() {
|
QByteArray OctreeUtils::RawOctreeData::toByteArray() {
|
||||||
const auto protocolVersion = (int)versionForPacketType(PacketType::EntityData);
|
const auto protocolVersion = (int)versionForPacketType(dataPacketType());
|
||||||
QJsonObject obj {
|
QJsonObject obj {
|
||||||
{ "DataVersion", QJsonValue((qint64)version) },
|
{ "DataVersion", QJsonValue((qint64)version) },
|
||||||
{ "Id", QJsonValue(id.toString()) },
|
{ "Id", QJsonValue(id.toString()) },
|
||||||
{ "Version", protocolVersion },
|
{ "Version", protocolVersion },
|
||||||
{ "Entities", octreeData }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
writeSubclassData(obj);
|
||||||
|
|
||||||
QJsonDocument doc;
|
QJsonDocument doc;
|
||||||
doc.setObject(obj);
|
doc.setObject(obj);
|
||||||
|
|
||||||
|
@ -167,8 +166,24 @@ QByteArray OctreeUtils::RawOctreeData::toGzippedByteArray() {
|
||||||
return gzData;
|
return gzData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PacketType OctreeUtils::RawOctreeData::dataPacketType() const {
|
||||||
|
Q_ASSERT(false);
|
||||||
|
qCritical() << "Attemping to read packet type for incomplete base type 'RawOctreeData'";
|
||||||
|
return (PacketType)0;
|
||||||
|
}
|
||||||
|
|
||||||
void OctreeUtils::RawOctreeData::resetIdAndVersion() {
|
void OctreeUtils::RawOctreeData::resetIdAndVersion() {
|
||||||
id = QUuid::createUuid();
|
id = QUuid::createUuid();
|
||||||
version = OctreeUtils::INITIAL_VERSION;
|
version = OctreeUtils::INITIAL_VERSION;
|
||||||
qDebug() << "Reset octree data to: " << id << version;
|
qDebug() << "Reset octree data to: " << id << version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OctreeUtils::RawEntityData::readSubclassData(QJsonObject root) {
|
||||||
|
if (root.contains("Entities")) {
|
||||||
|
entityData = root["Entities"].toArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OctreeUtils::RawEntityData::writeSubclassData(QJsonObject root) const {
|
||||||
|
root["Entities"] = entityData;
|
||||||
|
}
|
|
@ -17,6 +17,10 @@
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
|
|
||||||
|
#include <udt/PacketHeaders.h>
|
||||||
|
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
class AABox;
|
class AABox;
|
||||||
class QJsonDocument;
|
class QJsonDocument;
|
||||||
|
|
||||||
|
@ -31,19 +35,31 @@ public:
|
||||||
QUuid id { QUuid() };
|
QUuid id { QUuid() };
|
||||||
Version version { -1 };
|
Version version { -1 };
|
||||||
|
|
||||||
QJsonArray octreeData;
|
virtual PacketType dataPacketType() const;
|
||||||
|
|
||||||
|
virtual void readSubclassData(QJsonObject root) { }
|
||||||
|
virtual void writeSubclassData(QJsonObject root) const { }
|
||||||
|
|
||||||
void resetIdAndVersion();
|
void resetIdAndVersion();
|
||||||
QByteArray toByteArray();
|
QByteArray toByteArray();
|
||||||
QByteArray toGzippedByteArray();
|
QByteArray toGzippedByteArray();
|
||||||
|
|
||||||
|
bool readOctreeDataInfoFromData(QByteArray data);
|
||||||
|
bool readOctreeDataInfoFromFile(QString path);
|
||||||
|
bool readOctreeDataInfoFromJSON(QJsonObject root);
|
||||||
};
|
};
|
||||||
|
|
||||||
bool readOctreeFile(QString path, QJsonDocument* doc);
|
class RawEntityData : public RawOctreeData {
|
||||||
bool readOctreeDataInfoFromData(QByteArray data, RawOctreeData* octreeData);
|
PacketType dataPacketType() const override { return PacketType::EntityData; }
|
||||||
bool readOctreeDataInfoFromFile(QString path, RawOctreeData* octreeData);
|
void readSubclassData(QJsonObject root) override;
|
||||||
|
void writeSubclassData(QJsonObject root) const override;
|
||||||
|
|
||||||
|
QJsonArray entityData;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// renderAccuracy represents a floating point "visibility" of an object based on it's view from the camera. At a simple
|
/// renderAccuracy represents a floating point "visibility" of an object based on it's view from the camera. At a simple
|
||||||
/// level it returns 0.0f for things that are so small for the current settings that they could not be visible.
|
/// level it returns 0.0f for things that are so small for the current settings that they could not be visible.
|
||||||
float calculateRenderAccuracy(const glm::vec3& position,
|
float calculateRenderAccuracy(const glm::vec3& position,
|
||||||
|
|
Loading…
Reference in a new issue