mirror of
https://github.com/overte-org/overte.git
synced 2025-08-11 06:22:10 +02:00
delete child entities when parent is deleted
This commit is contained in:
parent
8d2ab50616
commit
0a2fb77698
5 changed files with 48 additions and 4 deletions
|
@ -272,6 +272,18 @@ void EntityServer::readAdditionalConfiguration(const QJsonObject& settingsSectio
|
||||||
tree->setWantTerseEditLogging(wantTerseEditLogging);
|
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
|
// 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.
|
// set of stats to have, but we'd probably want a different data structure if we keep it very long.
|
||||||
|
|
|
@ -58,6 +58,8 @@ public:
|
||||||
virtual void trackViewerGone(const QUuid& sessionID) override;
|
virtual void trackViewerGone(const QUuid& sessionID) override;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
virtual void nodeAdded(SharedNodePointer node);
|
||||||
|
virtual void nodeKilled(SharedNodePointer node);
|
||||||
void pruneDeletedEntities();
|
void pruneDeletedEntities();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -127,8 +127,8 @@ public:
|
||||||
public slots:
|
public slots:
|
||||||
/// runs the octree server assignment
|
/// runs the octree server assignment
|
||||||
void run();
|
void run();
|
||||||
void nodeAdded(SharedNodePointer node);
|
virtual void nodeAdded(SharedNodePointer node);
|
||||||
void nodeKilled(SharedNodePointer node);
|
virtual void nodeKilled(SharedNodePointer node);
|
||||||
void sendStatsPacket();
|
void sendStatsPacket();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
|
@ -448,6 +448,18 @@ void EntityTree::processRemovedEntities(const DeleteEntityOperator& theOperator)
|
||||||
const RemovedEntities& entities = theOperator.getEntities();
|
const RemovedEntities& entities = theOperator.getEntities();
|
||||||
foreach(const EntityToDeleteDetails& details, entities) {
|
foreach(const EntityToDeleteDetails& details, entities) {
|
||||||
EntityItemPointer theEntity = details.entity;
|
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();
|
theEntity->die();
|
||||||
|
|
||||||
if (getIsServer()) {
|
if (getIsServer()) {
|
||||||
|
@ -1000,6 +1012,10 @@ void EntityTree::fixupMissingParents() {
|
||||||
moveOperator.addEntityToMoveList(entity, newCube);
|
moveOperator.addEntityToMoveList(entity, newCube);
|
||||||
iter.remove();
|
iter.remove();
|
||||||
entity->markAncestorMissing(false);
|
entity->markAncestorMissing(false);
|
||||||
|
} else if (_avatarIDs.contains(entity->getParentID())) {
|
||||||
|
_childrenOfAvatars[entity->getParentID()] += entity->getEntityItemID();
|
||||||
|
iter.remove();
|
||||||
|
entity->markAncestorMissing(false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// entity was deleted before we found its parent.
|
// 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() {
|
void EntityTree::update() {
|
||||||
fixupMissingParents();
|
fixupMissingParents();
|
||||||
if (_simulation) {
|
if (_simulation) {
|
||||||
|
|
|
@ -241,6 +241,10 @@ public:
|
||||||
Q_INVOKABLE int getJointIndex(const QUuid& entityID, const QString& name) const;
|
Q_INVOKABLE int getJointIndex(const QUuid& entityID, const QString& name) const;
|
||||||
Q_INVOKABLE QStringList getJointNames(const QUuid& entityID) 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:
|
public slots:
|
||||||
void callLoader(EntityItemID entityID);
|
void callLoader(EntityItemID entityID);
|
||||||
|
|
||||||
|
@ -313,8 +317,11 @@ protected:
|
||||||
quint64 _maxEditDelta = 0;
|
quint64 _maxEditDelta = 0;
|
||||||
quint64 _treeResetTime = 0;
|
quint64 _treeResetTime = 0;
|
||||||
|
|
||||||
void fixupMissingParents();
|
void fixupMissingParents(); // try to hook members of _missingParent to parent instances
|
||||||
QVector<EntityItemWeakPointer> _missingParent;
|
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
|
#endif // hifi_EntityTree_h
|
||||||
|
|
Loading…
Reference in a new issue