delete child entities when parent is deleted

This commit is contained in:
Seth Alves 2016-03-13 07:04:50 -07:00
parent 8d2ab50616
commit 0a2fb77698
5 changed files with 48 additions and 4 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

@ -448,6 +448,18 @@ void EntityTree::processRemovedEntities(const DeleteEntityOperator& theOperator)
const RemovedEntities& entities = theOperator.getEntities();
foreach(const EntityToDeleteDetails& details, entities) {
EntityItemPointer theEntity = details.entity;
qDebug() << "processRemovedEntities on " << theEntity->getID() << theEntity->getName();
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()) {
@ -1000,6 +1012,10 @@ void EntityTree::fixupMissingParents() {
moveOperator.addEntityToMoveList(entity, newCube);
iter.remove();
entity->markAncestorMissing(false);
} else if (_avatarIDs.contains(entity->getParentID())) {
_childrenOfAvatars[entity->getParentID()] += entity->getEntityItemID();
iter.remove();
entity->markAncestorMissing(false);
}
} else {
// entity was deleted before we found its parent.
@ -1014,6 +1030,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