diff --git a/assignment-client/src/octree/OctreeSendThread.cpp b/assignment-client/src/octree/OctreeSendThread.cpp index 68938887d7..8fb79a336a 100644 --- a/assignment-client/src/octree/OctreeSendThread.cpp +++ b/assignment-client/src/octree/OctreeSendThread.cpp @@ -434,7 +434,7 @@ int OctreeSendThread::packetDistributor(SharedNodePointer node, OctreeQueryNode* nodeData->getLastTimeBagEmpty(), isFullScene, &nodeData->stats, _myServer->getJurisdiction(), &nodeData->extraEncodeData, - nodeData->getJSONParameters()); + nodeData); nodeData->copyCurrentViewFrustum(params.viewFrustum); if (viewFrustumChanged) { nodeData->copyLastKnownViewFrustum(params.lastViewFrustum); diff --git a/assignment-client/src/entities/EntityNodeData.h b/libraries/entities/src/EntityNodeData.h similarity index 64% rename from assignment-client/src/entities/EntityNodeData.h rename to libraries/entities/src/EntityNodeData.h index e1f8a91030..b3a576b1ad 100644 --- a/assignment-client/src/entities/EntityNodeData.h +++ b/libraries/entities/src/EntityNodeData.h @@ -14,7 +14,7 @@ #include -#include "../octree/OctreeQueryNode.h" +#include class EntityNodeData : public OctreeQueryNode { public: @@ -22,9 +22,15 @@ public: quint64 getLastDeletedEntitiesSentAt() const { return _lastDeletedEntitiesSentAt; } void setLastDeletedEntitiesSentAt(quint64 sentAt) { _lastDeletedEntitiesSentAt = sentAt; } + + // these can only be called from the OctreeSendThread for the given Node + void insertEntitySentLastFrame(const QUuid& entityID) { _entitiesSentLastFrame.insert(entityID); } + void removeEntitySentLastFrame(const QUuid& entityID) { _entitiesSentLastFrame.remove(entityID); } + bool sentEntityLastFrame(const QUuid& entityID) { return _entitiesSentLastFrame.contains(entityID); } private: quint64 _lastDeletedEntitiesSentAt { usecTimestampNow() }; + QSet _entitiesSentLastFrame; }; #endif // hifi_EntityNodeData_h diff --git a/libraries/entities/src/EntityTreeElement.cpp b/libraries/entities/src/EntityTreeElement.cpp index 67a9265aa1..1f9edb6866 100644 --- a/libraries/entities/src/EntityTreeElement.cpp +++ b/libraries/entities/src/EntityTreeElement.cpp @@ -16,6 +16,7 @@ #include #include "EntitiesLogging.h" +#include "EntityNodeData.h" #include "EntityItemProperties.h" #include "EntityTree.h" #include "EntityTreeElement.h" @@ -231,7 +232,7 @@ void EntityTreeElement::elementEncodeComplete(EncodeBitstreamParams& params) con } OctreeElement::AppendState EntityTreeElement::appendElementData(OctreePacketData* packetData, - EncodeBitstreamParams& params) const { + EncodeBitstreamParams& params) const { OctreeElement::AppendState appendElementState = OctreeElement::COMPLETED; // assume the best... @@ -291,10 +292,37 @@ OctreeElement::AppendState EntityTreeElement::appendElementData(OctreePacketData includeThisEntity = false; } - if (!params.jsonFilters.isEmpty()) { - // if params include JSON filters, check if this entity matches - includeThisEntity = includeThisEntity && entity->matchesJSONFilters(params.jsonFilters); + auto entityNodeData = dynamic_cast(params.nodeData); + + if (entityNodeData) { + // we have an EntityNodeData instance + // so we should assume that means we might have JSON filters to check + auto jsonFilters = entityNodeData->getJSONParameters(); + + if (!jsonFilters.isEmpty()) { + // if params include JSON filters, check if this entity matches + bool entityMatchesFilters = entity->matchesJSONFilters(jsonFilters); + + if (entityMatchesFilters) { + // we should include this entity unless it has already been excluded + includeThisEntity = includeThisEntity && true; + + // make sure this entity is in the set of entities sent last frame + entityNodeData->insertEntitySentLastFrame(entity->getID()); + + } else { + // we might include this entity if it matched in the previous frame + if (entityNodeData->sentEntityLastFrame(entity->getID())) { + includeThisEntity = includeThisEntity && true; + + entityNodeData->removeEntitySentLastFrame(entity->getID()); + } else { + includeThisEntity = false; + } + } + } } + if (hadElementExtraData) { includeThisEntity = includeThisEntity && diff --git a/libraries/octree/src/Octree.h b/libraries/octree/src/Octree.h index fa739f83a6..9a132d6046 100644 --- a/libraries/octree/src/Octree.h +++ b/libraries/octree/src/Octree.h @@ -82,7 +82,7 @@ public: OctreeSceneStats* stats; JurisdictionMap* jurisdictionMap; OctreeElementExtraEncodeData* extraEncodeData; - QJsonObject jsonFilters; + NodeData* nodeData; // output hints from the encode process typedef enum { @@ -110,8 +110,8 @@ public: bool forceSendScene = true, OctreeSceneStats* stats = IGNORE_SCENE_STATS, JurisdictionMap* jurisdictionMap = IGNORE_JURISDICTION_MAP, - OctreeElementExtraEncodeData* extraEncodeData = NULL, - QJsonObject jsonFilters = QJsonObject()) : + OctreeElementExtraEncodeData* extraEncodeData = nullptr, + NodeData* nodeData = nullptr) : lastQuerySent(lastQuerySent), maxEncodeLevel(maxEncodeLevel), maxLevelReached(0), @@ -124,7 +124,7 @@ public: stats(stats), jurisdictionMap(jurisdictionMap), extraEncodeData(extraEncodeData), - jsonFilters(jsonFilters), + nodeData(nodeData), stopReason(UNKNOWN) { lastViewFrustum.invalidate(); diff --git a/assignment-client/src/octree/OctreeQueryNode.cpp b/libraries/octree/src/OctreeQueryNode.cpp similarity index 99% rename from assignment-client/src/octree/OctreeQueryNode.cpp rename to libraries/octree/src/OctreeQueryNode.cpp index 6b0536e31d..01d2d85704 100644 --- a/assignment-client/src/octree/OctreeQueryNode.cpp +++ b/libraries/octree/src/OctreeQueryNode.cpp @@ -1,6 +1,6 @@ // // OctreeQueryNode.cpp -// assignment-client/src/octree +// libraries/octree/src // // Created by Stephen Birarda on 3/21/13. // Copyright 2013 High Fidelity, Inc. @@ -18,7 +18,6 @@ #include #include -#include "OctreeSendThread.h" void OctreeQueryNode::nodeKilled() { _isShuttingDown = true; diff --git a/assignment-client/src/octree/OctreeQueryNode.h b/libraries/octree/src/OctreeQueryNode.h similarity index 96% rename from assignment-client/src/octree/OctreeQueryNode.h rename to libraries/octree/src/OctreeQueryNode.h index 96f46cb2fa..021b293804 100644 --- a/assignment-client/src/octree/OctreeQueryNode.h +++ b/libraries/octree/src/OctreeQueryNode.h @@ -1,6 +1,6 @@ // // OctreeQueryNode.h -// assignment-client/src/octree +// libraries/octree/src // // Created by Brad Hefta-Gaub on 12/4/13. // Copyright 2013 High Fidelity, Inc. @@ -15,11 +15,11 @@ #include #include -#include -#include -#include -#include -#include +#include "OctreeConstants.h" +#include "OctreeElementBag.h" +#include "OctreePacketData.h" +#include "OctreeQuery.h" +#include "OctreeSceneStats.h" #include "SentPacketHistory.h" #include