diff --git a/assignment-client/src/octree/OctreeSendThread.cpp b/assignment-client/src/octree/OctreeSendThread.cpp index f905ae652f..46ea49e9a7 100644 --- a/assignment-client/src/octree/OctreeSendThread.cpp +++ b/assignment-client/src/octree/OctreeSendThread.cpp @@ -452,11 +452,10 @@ int OctreeSendThread::packetDistributor(OctreeQueryNode* nodeData, bool viewFrus _myServer->getOctree()->lockForRead(); quint64 lockWaitEnd = usecTimestampNow(); lockWaitElapsedUsec = (float)(lockWaitEnd - lockWaitStart); - quint64 encodeStart = usecTimestampNow(); bytesWritten = _myServer->getOctree()->encodeTreeBitstream(subTree, &_packetData, nodeData->elementBag, params); - + quint64 encodeEnd = usecTimestampNow(); encodeElapsedUsec = (float)(encodeEnd - encodeStart); diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 346070c567..ef02aafbc8 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -59,6 +59,7 @@ void EntityItem::initFromEntityItemID(const EntityItemID& entityItemID) { _lastUpdated = 0; _created = 0; // TODO: when do we actually want to make this "now" + _changedOnServer = 0; _position = glm::vec3(0,0,0); _rotation = DEFAULT_ROTATION; @@ -87,6 +88,7 @@ EntityItem::EntityItem(const EntityItemID& entityItemID) { _lastEditedFromRemoteInRemoteTime = 0; _lastUpdated = 0; _created = 0; + _changedOnServer = 0; initFromEntityItemID(entityItemID); } @@ -97,6 +99,7 @@ EntityItem::EntityItem(const EntityItemID& entityItemID, const EntityItemPropert _lastEditedFromRemoteInRemoteTime = 0; _lastUpdated = 0; _created = properties.getCreated(); + _changedOnServer = 0; initFromEntityItemID(entityItemID); setProperties(properties, true); // force copy } diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index 2117ec25b0..ae44e3931b 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -70,10 +70,14 @@ public: /// Last edited time of this entity universal usecs quint64 getLastEdited() const { return _lastEdited; } - void setLastEdited(quint64 lastEdited) { _lastEdited = _lastUpdated = lastEdited; } + void setLastEdited(quint64 lastEdited) + { _lastEdited = _lastUpdated = lastEdited; _changedOnServer = glm::max(lastEdited, _changedOnServer); } float getEditedAgo() const /// Elapsed seconds since this entity was last edited { return (float)(usecTimestampNow() - getLastEdited()) / (float)USECS_PER_SECOND; } + void markAsChangedOnServer() { _changedOnServer = usecTimestampNow(); } + quint64 getLastChangedOnServer() const { return _changedOnServer; } + // TODO: eventually only include properties changed since the params.lastViewFrustumSent time virtual EntityPropertyFlags getEntityProperties(EncodeBitstreamParams& params) const; @@ -268,6 +272,7 @@ protected: quint64 _lastEditedFromRemote; // this is the last time we received and edit from the server quint64 _lastEditedFromRemoteInRemoteTime; // time in server time space the last time we received and edit from the server quint64 _created; + quint64 _changedOnServer; glm::vec3 _position; glm::vec3 _dimensions; diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index 21df5498ec..f31f21ebe9 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -497,6 +497,7 @@ int EntityTree::processEditPacketData(PacketType packetType, const unsigned char // if the entityItem exists, then update it if (existingEntity) { updateEntity(entityItemID, properties); + existingEntity->markAsChangedOnServer(); } else { qDebug() << "User attempted to edit an unknown entity. ID:" << entityItemID; } @@ -505,6 +506,7 @@ int EntityTree::processEditPacketData(PacketType packetType, const unsigned char entityItemID = assignEntityID(entityItemID); EntityItem* newEntity = addEntity(entityItemID, properties); if (newEntity) { + newEntity->markAsChangedOnServer(); notifyNewlyCreatedEntity(*newEntity, senderNode); } } diff --git a/libraries/entities/src/EntityTreeElement.cpp b/libraries/entities/src/EntityTreeElement.cpp index 59dce80ecc..079fb1bba7 100644 --- a/libraries/entities/src/EntityTreeElement.cpp +++ b/libraries/entities/src/EntityTreeElement.cpp @@ -238,7 +238,7 @@ void EntityTreeElement::elementEncodeComplete(EncodeBitstreamParams& params, Oct OctreeElement::AppendState EntityTreeElement::appendElementData(OctreePacketData* packetData, EncodeBitstreamParams& params) const { - + OctreeElement::AppendState appendElementState = OctreeElement::COMPLETED; // assume the best... // first, check the params.extraEncodeData to see if there's any partial re-encode data for this element @@ -289,7 +289,8 @@ OctreeElement::AppendState EntityTreeElement::appendElementData(OctreePacketData for (uint16_t i = 0; i < _entityItems->size(); i++) { EntityItem* entity = (*_entityItems)[i]; bool includeThisEntity = true; - if (!params.forceSendScene && entity->getLastEdited() < params.lastViewFrustumSent) { + + if (!params.forceSendScene && entity->getLastChangedOnServer() < params.lastViewFrustumSent) { includeThisEntity = false; } @@ -324,7 +325,6 @@ OctreeElement::AppendState EntityTreeElement::appendElementData(OctreePacketData if (successAppendEntityCount) { foreach (uint16_t i, indexesOfEntitiesToInclude) { EntityItem* entity = (*_entityItems)[i]; - LevelDetails entityLevel = packetData->startLevel(); OctreeElement::AppendState appendEntityState = entity->appendEntityData(packetData, params, entityTreeElementExtraEncodeData);