Merge pull request #7345 from sethalves/delete-parentless-entities-redux

Delete parentless entities redux
This commit is contained in:
Brad Hefta-Gaub 2016-03-14 10:04:22 -07:00
commit 830f53cc46
5 changed files with 65 additions and 9 deletions

View file

@ -272,6 +272,18 @@ void EntityServer::readAdditionalConfiguration(const QJsonObject& settingsSectio
tree->setWantTerseEditLogging(wantTerseEditLogging);
}
void EntityServer::nodeAdded(SharedNodePointer node) {
EntityTreePointer tree = std::static_pointer_cast<EntityTree>(_tree);
tree->knowAvatarID(node->getUUID());
OctreeServer::nodeAdded(node);
}
void EntityServer::nodeKilled(SharedNodePointer node) {
EntityTreePointer tree = std::static_pointer_cast<EntityTree>(_tree);
tree->deleteDescendantsOfAvatar(node->getUUID());
tree->forgetAvatarID(node->getUUID());
OctreeServer::nodeKilled(node);
}
// FIXME - this stats tracking is somewhat temporary to debug the Whiteboard issues. It's not a bad
// set of stats to have, but we'd probably want a different data structure if we keep it very long.

View file

@ -58,6 +58,8 @@ public:
virtual void trackViewerGone(const QUuid& sessionID) override;
public slots:
virtual void nodeAdded(SharedNodePointer node);
virtual void nodeKilled(SharedNodePointer node);
void pruneDeletedEntities();
protected:

View file

@ -127,8 +127,8 @@ public:
public slots:
/// runs the octree server assignment
void run();
void nodeAdded(SharedNodePointer node);
void nodeKilled(SharedNodePointer node);
virtual void nodeAdded(SharedNodePointer node);
virtual void nodeKilled(SharedNodePointer node);
void sendStatsPacket();
private slots:

View file

@ -86,6 +86,11 @@ void EntityTree::postAddEntity(EntityItemPointer entity) {
if (_simulation) {
_simulation->addEntity(entity);
}
if (!entity->isParentIDValid()) {
_missingParent.append(entity);
}
_isDirty = true;
maybeNotifyNewCollisionSoundURL("", entity->getCollisionSoundURL());
emit addingEntity(entity->getEntityItemID());
@ -252,6 +257,9 @@ bool EntityTree::updateEntityWithElement(EntityItemPointer entity, const EntityI
_missingParent.append(childEntity);
continue;
}
if (!childEntity->isParentIDValid()) {
_missingParent.append(childEntity);
}
UpdateEntityOperator theChildOperator(getThisPointer(), containingElement, childEntity, queryCube);
recurseTreeWithOperator(&theChildOperator);
@ -448,6 +456,17 @@ void EntityTree::processRemovedEntities(const DeleteEntityOperator& theOperator)
const RemovedEntities& entities = theOperator.getEntities();
foreach(const EntityToDeleteDetails& details, entities) {
EntityItemPointer theEntity = details.entity;
if (getIsServer()) {
QSet<EntityItemID> childrenIDs;
theEntity->forEachChild([&](SpatiallyNestablePointer child) {
if (child->getNestableType() == NestableType::Entity) {
childrenIDs += child->getID();
}
});
deleteEntities(childrenIDs, true, true);
}
theEntity->die();
if (getIsServer()) {
@ -992,14 +1011,23 @@ void EntityTree::fixupMissingParents() {
EntityItemWeakPointer entityWP = iter.next();
EntityItemPointer entity = entityWP.lock();
if (entity) {
bool success;
AACube newCube = entity->getQueryAACube(success);
if (success) {
// this entity's parent (or ancestry) was previously not fully known, and now is. Update its
// location in the EntityTree.
if (entity->isParentIDValid()) {
// this entity's parent was previously not known, and now is. Update its location in the EntityTree...
bool success;
AACube newCube = entity->getQueryAACube(success);
if (!success) {
continue;
}
moveOperator.addEntityToMoveList(entity, newCube);
iter.remove();
entity->markAncestorMissing(false);
} else if (_avatarIDs.contains(entity->getParentID())) {
if (!_childrenOfAvatars.contains(entity->getParentID())) {
_childrenOfAvatars[entity->getParentID()] = QSet<EntityItemID>();
}
_childrenOfAvatars[entity->getParentID()] += entity->getEntityItemID();
iter.remove();
entity->markAncestorMissing(false);
}
} else {
// entity was deleted before we found its parent.
@ -1014,6 +1042,13 @@ void EntityTree::fixupMissingParents() {
}
void EntityTree::deleteDescendantsOfAvatar(QUuid avatarID) {
if (_childrenOfAvatars.contains(avatarID)) {
deleteEntities(_childrenOfAvatars[avatarID]);
_childrenOfAvatars.remove(avatarID);
}
}
void EntityTree::update() {
fixupMissingParents();
if (_simulation) {

View file

@ -241,6 +241,10 @@ public:
Q_INVOKABLE int getJointIndex(const QUuid& entityID, const QString& name) const;
Q_INVOKABLE QStringList getJointNames(const QUuid& entityID) const;
void knowAvatarID(QUuid avatarID) { _avatarIDs += avatarID; }
void forgetAvatarID(QUuid avatarID) { _avatarIDs -= avatarID; }
void deleteDescendantsOfAvatar(QUuid avatarID);
public slots:
void callLoader(EntityItemID entityID);
@ -313,8 +317,11 @@ protected:
quint64 _maxEditDelta = 0;
quint64 _treeResetTime = 0;
void fixupMissingParents();
QVector<EntityItemWeakPointer> _missingParent;
void fixupMissingParents(); // try to hook members of _missingParent to parent instances
QVector<EntityItemWeakPointer> _missingParent; // entites with a parentID but no (yet) known parent instance
// we maintain a list of avatarIDs to notice when an entity is a child of one.
QSet<QUuid> _avatarIDs; // IDs of avatars connected to entity server
QHash<QUuid, QSet<EntityItemID>> _childrenOfAvatars; // which entities are children of which avatars
};
#endif // hifi_EntityTree_h