Merge pull request #6421 from ZappoMan/outOfOrderDelete

Possible fix to abandoned lines/entities
This commit is contained in:
Seth Alves 2015-11-19 10:26:14 -08:00
commit 2938f0d835
4 changed files with 48 additions and 9 deletions

View file

@ -500,6 +500,15 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
}
}
// before proceeding, check to see if this is an entity that we know has been deleted, which
// might happen in the case of out-of-order and/or recorvered packets, if we've deleted the entity
// we can confidently ignore this packet
EntityTreePointer tree = getTree();
if (tree && tree->isDeletedEntity(_id)) {
qDebug() << "Recieved packet for previously deleted entity [" << _id << "] ignoring. (inside " << __FUNCTION__ << ")";
ignoreServerPacket = true;
}
if (ignoreServerPacket) {
overwriteLocalData = false;
#ifdef WANT_DEBUG

View file

@ -68,6 +68,7 @@ void EntityTree::eraseAllOctreeElements(bool createNewRoot) {
Octree::eraseAllOctreeElements(createNewRoot);
resetClientEditStats();
clearDeletedEntities();
}
bool EntityTree::handlesEditPacketType(PacketType packetType) const {
@ -398,6 +399,9 @@ void EntityTree::processRemovedEntities(const DeleteEntityOperator& theOperator)
// set up the deleted entities ID
QWriteLocker locker(&_recentlyDeletedEntitiesLock);
_recentlyDeletedEntityItemIDs.insert(deletedAt, theEntity->getEntityItemID());
} else {
// on the client side, we also remember that we deleted this entity, we don't care about the time
trackDeletedEntity(theEntity->getEntityItemID());
}
if (_simulation) {

View file

@ -228,6 +228,11 @@ public:
EntityTreePointer getThisPointer() { return std::static_pointer_cast<EntityTree>(shared_from_this()); }
bool isDeletedEntity(const QUuid& id) {
QReadLocker locker(&_deletedEntitiesLock);
return _deletedEntityItemIDs.contains(id);
}
signals:
void deletingEntity(const EntityItemID& entityID);
void addingEntity(const EntityItemID& entityID);
@ -235,7 +240,7 @@ signals:
void newCollisionSoundURL(const QUrl& url);
void clearingEntities();
private:
protected:
void processRemovedEntities(const DeleteEntityOperator& theOperator);
bool updateEntityWithElement(EntityItemPointer entity, const EntityItemProperties& properties,
@ -252,8 +257,22 @@ private:
QReadWriteLock _newlyCreatedHooksLock;
QVector<NewlyCreatedEntityHook*> _newlyCreatedHooks;
mutable QReadWriteLock _recentlyDeletedEntitiesLock;
QMultiMap<quint64, QUuid> _recentlyDeletedEntityItemIDs;
mutable QReadWriteLock _recentlyDeletedEntitiesLock; /// lock of server side recent deletes
QMultiMap<quint64, QUuid> _recentlyDeletedEntityItemIDs; /// server side recent deletes
mutable QReadWriteLock _deletedEntitiesLock; /// lock of client side recent deletes
QSet<QUuid> _deletedEntityItemIDs; /// client side recent deletes
void clearDeletedEntities() {
QWriteLocker locker(&_deletedEntitiesLock);
_deletedEntityItemIDs.clear();
}
void trackDeletedEntity(const QUuid& id) {
QWriteLocker locker(&_deletedEntitiesLock);
_deletedEntityItemIDs << id;
}
EntityItemFBXService* _fbxService;
QHash<EntityItemID, EntityTreeElementPointer> _entityToElementMap;

View file

@ -894,12 +894,19 @@ int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int
entityItem = EntityTypes::constructEntityItem(dataAt, bytesLeftToRead, args);
if (entityItem) {
bytesForThisEntity = entityItem->readEntityDataFromBuffer(dataAt, bytesLeftToRead, args);
addEntityItem(entityItem); // add this new entity to this elements entities
entityItemID = entityItem->getEntityItemID();
_myTree->setContainingElement(entityItemID, getThisPointer());
_myTree->postAddEntity(entityItem);
if (entityItem->getCreated() == UNKNOWN_CREATED_TIME) {
entityItem->recordCreationTime();
// don't add if we've recently deleted....
if (!_myTree->isDeletedEntity(entityItem->getID())) {
addEntityItem(entityItem); // add this new entity to this elements entities
entityItemID = entityItem->getEntityItemID();
_myTree->setContainingElement(entityItemID, getThisPointer());
_myTree->postAddEntity(entityItem);
if (entityItem->getCreated() == UNKNOWN_CREATED_TIME) {
entityItem->recordCreationTime();
}
} else {
qDebug() << "Recieved packet for previously deleted entity [" <<
entityItem->getID() << "] ignoring. (inside " << __FUNCTION__ << ")";
}
}
}