From 5c93dbd20d35c79b7a73cad5f30d3cd352b23560 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Fri, 19 May 2017 13:48:29 -0700 Subject: [PATCH] be more careful about fixing up entities which arrived before their parents --- libraries/entities/src/AddEntityOperator.cpp | 4 ---- libraries/entities/src/EntityItem.cpp | 4 +--- libraries/entities/src/EntityTree.cpp | 13 +++++-------- libraries/shared/src/SpatiallyNestable.h | 4 ---- 4 files changed, 6 insertions(+), 19 deletions(-) diff --git a/libraries/entities/src/AddEntityOperator.cpp b/libraries/entities/src/AddEntityOperator.cpp index 1c39b40495..7cf4e4a472 100644 --- a/libraries/entities/src/AddEntityOperator.cpp +++ b/libraries/entities/src/AddEntityOperator.cpp @@ -27,10 +27,6 @@ AddEntityOperator::AddEntityOperator(EntityTreePointer tree, EntityItemPointer n bool success; auto queryCube = _newEntity->getQueryAACube(success); - if (!success) { - _newEntity->markAncestorMissing(true); - } - _newEntityBox = queryCube.clamp((float)(-HALF_TREE_SCALE), (float)HALF_TREE_SCALE); } diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 44b0869d85..800bae5617 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -1373,11 +1373,9 @@ bool EntityItem::setProperties(const EntityItemProperties& properties) { if (saveQueryAACube != _queryAACube) { somethingChanged = true; } - } else { - markAncestorMissing(true); } - // Now check the sub classes + // Now check the sub classes somethingChanged |= setSubClassProperties(properties); // Finally notify if change detected diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index 84dc3844e3..403d981409 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -295,7 +295,7 @@ bool EntityTree::updateEntityWithElement(EntityItemPointer entity, const EntityI _missingParent.append(childEntity); continue; } - if (!childEntity->isParentIDValid()) { + if (!childEntity->getParentID().isNull()) { QWriteLocker locker(&_missingParentLock); _missingParent.append(childEntity); } @@ -383,9 +383,7 @@ EntityItemPointer EntityTree::addEntity(const EntityItemID& entityID, const Enti // Recurse the tree and store the entity in the correct tree element AddEntityOperator theOperator(getThisPointer(), result); recurseTreeWithOperator(&theOperator); - if (result->getAncestorMissing()) { - // we added the entity, but didn't know about all its ancestors, so it went into the wrong place. - // add it to a list of entities needing to be fixed once their parents are known. + if (!result->getParentID().isNull()) { QWriteLocker locker(&_missingParentLock); _missingParent.append(result); } @@ -1221,11 +1219,11 @@ void EntityTree::fixupMissingParents() { // entity was deleted before we found its parent iter.remove(); } - bool queryAACubeSuccess; + bool queryAACubeSuccess { false }; + bool maxAACubeSuccess { false }; AACube newCube = entity->getQueryAACube(queryAACubeSuccess); if (queryAACubeSuccess) { // make sure queryAACube encompasses maxAACube - bool maxAACubeSuccess; AACube maxAACube = entity->getMaximumAACube(maxAACubeSuccess); if (maxAACubeSuccess && !newCube.contains(maxAACube)) { newCube = maxAACube; @@ -1233,7 +1231,7 @@ void EntityTree::fixupMissingParents() { } bool doMove = false; - if (entity->isParentIDValid()) { + if (entity->isParentIDValid() && maxAACubeSuccess) { // maxAACubeSuccess of true means all ancestors are known iter.remove(); // this entity is all hooked up; we can remove it from the list // this entity's parent was previously not known, and now is. Update its location in the EntityTree... doMove = true; @@ -1266,7 +1264,6 @@ void EntityTree::fixupMissingParents() { if (queryAACubeSuccess && doMove) { moveOperator.addEntityToMoveList(entity, newCube); - entity->markAncestorMissing(false); } } diff --git a/libraries/shared/src/SpatiallyNestable.h b/libraries/shared/src/SpatiallyNestable.h index 6589a44307..b98ab4c358 100644 --- a/libraries/shared/src/SpatiallyNestable.h +++ b/libraries/shared/src/SpatiallyNestable.h @@ -158,9 +158,6 @@ public: SpatiallyNestablePointer getThisPointer() const; - void markAncestorMissing(bool value) { _missingAncestor = value; } - bool getAncestorMissing() { return _missingAncestor; } - void forEachChild(std::function actor); void forEachDescendant(std::function actor); @@ -207,7 +204,6 @@ protected: mutable AACube _queryAACube; mutable bool _queryAACubeSet { false }; - bool _missingAncestor { false }; quint64 _scaleChanged { 0 }; quint64 _translationChanged { 0 }; quint64 _rotationChanged { 0 };