Merge pull request #13270 from dback2/cloneables

Use version from JSON on domain restore
This commit is contained in:
David Back 2018-06-07 15:15:43 -07:00 committed by GitHub
commit 9a7e199528
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 9 deletions

View file

@ -40,9 +40,10 @@ bool readOctreeFile(QString path, QJsonDocument* doc) {
} }
bool OctreeUtils::RawOctreeData::readOctreeDataInfoFromJSON(QJsonObject root) { bool OctreeUtils::RawOctreeData::readOctreeDataInfoFromJSON(QJsonObject root) {
if (root.contains("Id") && root.contains("DataVersion")) { if (root.contains("Id") && root.contains("DataVersion") && root.contains("Version")) {
id = root["Id"].toVariant().toUuid(); id = root["Id"].toVariant().toUuid();
version = root["DataVersion"].toInt(); dataVersion = root["DataVersion"].toInt();
version = root["Version"].toInt();
} }
readSubclassData(root); readSubclassData(root);
return true; return true;
@ -76,11 +77,10 @@ bool OctreeUtils::RawOctreeData::readOctreeDataInfoFromFile(QString path) {
} }
QByteArray OctreeUtils::RawOctreeData::toByteArray() { QByteArray OctreeUtils::RawOctreeData::toByteArray() {
const auto protocolVersion = (int)versionForPacketType((PacketTypeEnum::Value)dataPacketType());
QJsonObject obj { QJsonObject obj {
{ "DataVersion", QJsonValue((qint64)version) }, { "DataVersion", QJsonValue((qint64)dataVersion) },
{ "Id", QJsonValue(id.toString()) }, { "Id", QJsonValue(id.toString()) },
{ "Version", protocolVersion }, { "Version", QJsonValue((qint64)version) },
}; };
writeSubclassData(obj); writeSubclassData(obj);
@ -111,8 +111,8 @@ PacketType OctreeUtils::RawOctreeData::dataPacketType() const {
void OctreeUtils::RawOctreeData::resetIdAndVersion() { void OctreeUtils::RawOctreeData::resetIdAndVersion() {
id = QUuid::createUuid(); id = QUuid::createUuid();
version = OctreeUtils::INITIAL_VERSION; dataVersion = OctreeUtils::INITIAL_VERSION;
qDebug() << "Reset octree data to: " << id << version; qDebug() << "Reset octree data to: " << id << dataVersion;
} }
void OctreeUtils::RawEntityData::readSubclassData(const QJsonObject& root) { void OctreeUtils::RawEntityData::readSubclassData(const QJsonObject& root) {

View file

@ -28,6 +28,7 @@ constexpr Version INITIAL_VERSION = 0;
class RawOctreeData { class RawOctreeData {
public: public:
QUuid id { QUuid() }; QUuid id { QUuid() };
Version dataVersion { -1 };
Version version { -1 }; Version version { -1 };
virtual PacketType dataPacketType() const; virtual PacketType dataPacketType() const;

View file

@ -179,8 +179,8 @@ bool OctreePersistThread::process() {
OctreeUtils::RawOctreeData data; OctreeUtils::RawOctreeData data;
if (data.readOctreeDataInfoFromFile(_filename)) { if (data.readOctreeDataInfoFromFile(_filename)) {
qDebug() << "Setting entity version info to: " << data.id << data.version; qDebug() << "Setting entity version info to: " << data.id << data.dataVersion;
_tree->setOctreeVersionInfo(data.id, data.version); _tree->setOctreeVersionInfo(data.id, data.dataVersion);
} }
bool persistentFileRead; bool persistentFileRead;