mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 06:53:01 +02:00
Merge pull request #7345 from sethalves/delete-parentless-entities-redux
Delete parentless entities redux
This commit is contained in:
commit
830f53cc46
5 changed files with 65 additions and 9 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:
|
||||||
|
|
|
@ -86,6 +86,11 @@ void EntityTree::postAddEntity(EntityItemPointer entity) {
|
||||||
if (_simulation) {
|
if (_simulation) {
|
||||||
_simulation->addEntity(entity);
|
_simulation->addEntity(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!entity->isParentIDValid()) {
|
||||||
|
_missingParent.append(entity);
|
||||||
|
}
|
||||||
|
|
||||||
_isDirty = true;
|
_isDirty = true;
|
||||||
maybeNotifyNewCollisionSoundURL("", entity->getCollisionSoundURL());
|
maybeNotifyNewCollisionSoundURL("", entity->getCollisionSoundURL());
|
||||||
emit addingEntity(entity->getEntityItemID());
|
emit addingEntity(entity->getEntityItemID());
|
||||||
|
@ -252,6 +257,9 @@ bool EntityTree::updateEntityWithElement(EntityItemPointer entity, const EntityI
|
||||||
_missingParent.append(childEntity);
|
_missingParent.append(childEntity);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (!childEntity->isParentIDValid()) {
|
||||||
|
_missingParent.append(childEntity);
|
||||||
|
}
|
||||||
|
|
||||||
UpdateEntityOperator theChildOperator(getThisPointer(), containingElement, childEntity, queryCube);
|
UpdateEntityOperator theChildOperator(getThisPointer(), containingElement, childEntity, queryCube);
|
||||||
recurseTreeWithOperator(&theChildOperator);
|
recurseTreeWithOperator(&theChildOperator);
|
||||||
|
@ -448,6 +456,17 @@ 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;
|
||||||
|
|
||||||
|
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()) {
|
||||||
|
@ -992,14 +1011,23 @@ void EntityTree::fixupMissingParents() {
|
||||||
EntityItemWeakPointer entityWP = iter.next();
|
EntityItemWeakPointer entityWP = iter.next();
|
||||||
EntityItemPointer entity = entityWP.lock();
|
EntityItemPointer entity = entityWP.lock();
|
||||||
if (entity) {
|
if (entity) {
|
||||||
bool success;
|
if (entity->isParentIDValid()) {
|
||||||
AACube newCube = entity->getQueryAACube(success);
|
// this entity's parent was previously not known, and now is. Update its location in the EntityTree...
|
||||||
if (success) {
|
bool success;
|
||||||
// this entity's parent (or ancestry) was previously not fully known, and now is. Update its
|
AACube newCube = entity->getQueryAACube(success);
|
||||||
// location in the EntityTree.
|
if (!success) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
moveOperator.addEntityToMoveList(entity, newCube);
|
moveOperator.addEntityToMoveList(entity, newCube);
|
||||||
iter.remove();
|
iter.remove();
|
||||||
entity->markAncestorMissing(false);
|
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 {
|
} else {
|
||||||
// entity was deleted before we found its parent.
|
// 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() {
|
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