don't save entites with invalid parentIDs (or with IDs that indicates an avatar) to the persist file

This commit is contained in:
Seth Alves 2016-01-18 16:50:26 -08:00
parent 29945bba92
commit e365d93ed9
7 changed files with 21 additions and 8 deletions

View file

@ -1291,12 +1291,13 @@ void EntityTree::remapIDs() {
recurseTreeWithOperator(&theOperator); recurseTreeWithOperator(&theOperator);
} }
bool EntityTree::writeToMap(QVariantMap& entityDescription, OctreeElementPointer element, bool skipDefaultValues) { bool EntityTree::writeToMap(QVariantMap& entityDescription, OctreeElementPointer element, bool skipDefaultValues,
bool skipThoseWithBadParents) {
if (! entityDescription.contains("Entities")) { if (! entityDescription.contains("Entities")) {
entityDescription["Entities"] = QVariantList(); entityDescription["Entities"] = QVariantList();
} }
QScriptEngine scriptEngine; QScriptEngine scriptEngine;
RecurseOctreeToMapOperator theOperator(entityDescription, element, &scriptEngine, skipDefaultValues); RecurseOctreeToMapOperator theOperator(entityDescription, element, &scriptEngine, skipDefaultValues, skipThoseWithBadParents);
recurseTreeWithOperator(&theOperator); recurseTreeWithOperator(&theOperator);
return true; return true;
} }

View file

@ -199,7 +199,8 @@ public:
void remapIDs(); void remapIDs();
virtual bool writeToMap(QVariantMap& entityDescription, OctreeElementPointer element, bool skipDefaultValues) override; virtual bool writeToMap(QVariantMap& entityDescription, OctreeElementPointer element, bool skipDefaultValues,
bool skipThoseWithBadParents) override;
virtual bool readFromMap(QVariantMap& entityDescription) override; virtual bool readFromMap(QVariantMap& entityDescription) override;
float getContentsLargestDimension(); float getContentsLargestDimension();

View file

@ -16,12 +16,14 @@
RecurseOctreeToMapOperator::RecurseOctreeToMapOperator(QVariantMap& map, RecurseOctreeToMapOperator::RecurseOctreeToMapOperator(QVariantMap& map,
OctreeElementPointer top, OctreeElementPointer top,
QScriptEngine* engine, QScriptEngine* engine,
bool skipDefaultValues) : bool skipDefaultValues,
bool skipThoseWithBadParents) :
RecurseOctreeOperator(), RecurseOctreeOperator(),
_map(map), _map(map),
_top(top), _top(top),
_engine(engine), _engine(engine),
_skipDefaultValues(skipDefaultValues) _skipDefaultValues(skipDefaultValues),
_skipThoseWithBadParents(skipThoseWithBadParents)
{ {
// if some element "top" was given, only save information for that element and its children. // if some element "top" was given, only save information for that element and its children.
if (_top) { if (_top) {
@ -47,6 +49,10 @@ bool RecurseOctreeToMapOperator::postRecursion(OctreeElementPointer element) {
QVariantList entitiesQList = qvariant_cast<QVariantList>(_map["Entities"]); QVariantList entitiesQList = qvariant_cast<QVariantList>(_map["Entities"]);
entityTreeElement->forEachEntity([&](EntityItemPointer entityItem) { entityTreeElement->forEachEntity([&](EntityItemPointer entityItem) {
if (_skipThoseWithBadParents && !entityItem->isParentIDValid()) {
return; // we weren't able to resolve a parent from _parentID, so don't save this entity.
}
EntityItemProperties properties = entityItem->getProperties(); EntityItemProperties properties = entityItem->getProperties();
QScriptValue qScriptValues; QScriptValue qScriptValues;
if (_skipDefaultValues) { if (_skipDefaultValues) {

View file

@ -13,7 +13,8 @@
class RecurseOctreeToMapOperator : public RecurseOctreeOperator { class RecurseOctreeToMapOperator : public RecurseOctreeOperator {
public: public:
RecurseOctreeToMapOperator(QVariantMap& map, OctreeElementPointer top, QScriptEngine* engine, bool skipDefaultValues); RecurseOctreeToMapOperator(QVariantMap& map, OctreeElementPointer top, QScriptEngine* engine, bool skipDefaultValues,
bool skipThoseWithBadParents);
bool preRecursion(OctreeElementPointer element); bool preRecursion(OctreeElementPointer element);
bool postRecursion(OctreeElementPointer element); bool postRecursion(OctreeElementPointer element);
private: private:
@ -22,4 +23,5 @@ public:
QScriptEngine* _engine; QScriptEngine* _engine;
bool _withinTop; bool _withinTop;
bool _skipDefaultValues; bool _skipDefaultValues;
bool _skipThoseWithBadParents;
}; };

View file

@ -1919,7 +1919,7 @@ void Octree::writeToJSONFile(const char* fileName, OctreeElementPointer element,
entityDescription["Version"] = (int) expectedVersion; entityDescription["Version"] = (int) expectedVersion;
// store the entity data // store the entity data
bool entityDescriptionSuccess = writeToMap(entityDescription, top, true); bool entityDescriptionSuccess = writeToMap(entityDescription, top, true, true);
if (!entityDescriptionSuccess) { if (!entityDescriptionSuccess) {
qCritical("Failed to convert Entities to QVariantMap while saving to json."); qCritical("Failed to convert Entities to QVariantMap while saving to json.");
return; return;

View file

@ -304,7 +304,8 @@ public:
void writeToFile(const char* filename, OctreeElementPointer element = NULL, QString persistAsFileType = "svo"); void writeToFile(const char* filename, OctreeElementPointer element = NULL, QString persistAsFileType = "svo");
void writeToJSONFile(const char* filename, OctreeElementPointer element = NULL, bool doGzip = false); void writeToJSONFile(const char* filename, OctreeElementPointer element = NULL, bool doGzip = false);
void writeToSVOFile(const char* filename, OctreeElementPointer element = NULL); void writeToSVOFile(const char* filename, OctreeElementPointer element = NULL);
virtual bool writeToMap(QVariantMap& entityDescription, OctreeElementPointer element, bool skipDefaultValues) = 0; virtual bool writeToMap(QVariantMap& entityDescription, OctreeElementPointer element, bool skipDefaultValues,
bool skipThoseWithBadParents) = 0;
// Octree importers // Octree importers
bool readFromFile(const char* filename); bool readFromFile(const char* filename);

View file

@ -118,6 +118,8 @@ public:
void die() { _isDead = true; } void die() { _isDead = true; }
bool isDead() const { return _isDead; } bool isDead() const { return _isDead; }
bool isParentIDValid() const { bool success = false; getParentPointer(success); return success; }
protected: protected:
const NestableType _nestableType; // EntityItem or an AvatarData const NestableType _nestableType; // EntityItem or an AvatarData
QUuid _id; QUuid _id;