send entities that just stopped matching filter

This commit is contained in:
Stephen Birarda 2017-01-18 14:56:08 -08:00
parent 5d1b53c600
commit 112b119f17
6 changed files with 51 additions and 18 deletions

View file

@ -434,7 +434,7 @@ int OctreeSendThread::packetDistributor(SharedNodePointer node, OctreeQueryNode*
nodeData->getLastTimeBagEmpty(), nodeData->getLastTimeBagEmpty(),
isFullScene, &nodeData->stats, _myServer->getJurisdiction(), isFullScene, &nodeData->stats, _myServer->getJurisdiction(),
&nodeData->extraEncodeData, &nodeData->extraEncodeData,
nodeData->getJSONParameters()); nodeData);
nodeData->copyCurrentViewFrustum(params.viewFrustum); nodeData->copyCurrentViewFrustum(params.viewFrustum);
if (viewFrustumChanged) { if (viewFrustumChanged) {
nodeData->copyLastKnownViewFrustum(params.lastViewFrustum); nodeData->copyLastKnownViewFrustum(params.lastViewFrustum);

View file

@ -14,7 +14,7 @@
#include <udt/PacketHeaders.h> #include <udt/PacketHeaders.h>
#include "../octree/OctreeQueryNode.h" #include <OctreeQueryNode.h>
class EntityNodeData : public OctreeQueryNode { class EntityNodeData : public OctreeQueryNode {
public: public:
@ -22,9 +22,15 @@ public:
quint64 getLastDeletedEntitiesSentAt() const { return _lastDeletedEntitiesSentAt; } quint64 getLastDeletedEntitiesSentAt() const { return _lastDeletedEntitiesSentAt; }
void setLastDeletedEntitiesSentAt(quint64 sentAt) { _lastDeletedEntitiesSentAt = sentAt; } 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: private:
quint64 _lastDeletedEntitiesSentAt { usecTimestampNow() }; quint64 _lastDeletedEntitiesSentAt { usecTimestampNow() };
QSet<QUuid> _entitiesSentLastFrame;
}; };
#endif // hifi_EntityNodeData_h #endif // hifi_EntityNodeData_h

View file

@ -16,6 +16,7 @@
#include <OctreeUtils.h> #include <OctreeUtils.h>
#include "EntitiesLogging.h" #include "EntitiesLogging.h"
#include "EntityNodeData.h"
#include "EntityItemProperties.h" #include "EntityItemProperties.h"
#include "EntityTree.h" #include "EntityTree.h"
#include "EntityTreeElement.h" #include "EntityTreeElement.h"
@ -231,7 +232,7 @@ void EntityTreeElement::elementEncodeComplete(EncodeBitstreamParams& params) con
} }
OctreeElement::AppendState EntityTreeElement::appendElementData(OctreePacketData* packetData, OctreeElement::AppendState EntityTreeElement::appendElementData(OctreePacketData* packetData,
EncodeBitstreamParams& params) const { EncodeBitstreamParams& params) const {
OctreeElement::AppendState appendElementState = OctreeElement::COMPLETED; // assume the best... OctreeElement::AppendState appendElementState = OctreeElement::COMPLETED; // assume the best...
@ -291,10 +292,37 @@ OctreeElement::AppendState EntityTreeElement::appendElementData(OctreePacketData
includeThisEntity = false; includeThisEntity = false;
} }
if (!params.jsonFilters.isEmpty()) { auto entityNodeData = dynamic_cast<EntityNodeData*>(params.nodeData);
// if params include JSON filters, check if this entity matches
includeThisEntity = includeThisEntity && entity->matchesJSONFilters(params.jsonFilters); 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) { if (hadElementExtraData) {
includeThisEntity = includeThisEntity && includeThisEntity = includeThisEntity &&

View file

@ -82,7 +82,7 @@ public:
OctreeSceneStats* stats; OctreeSceneStats* stats;
JurisdictionMap* jurisdictionMap; JurisdictionMap* jurisdictionMap;
OctreeElementExtraEncodeData* extraEncodeData; OctreeElementExtraEncodeData* extraEncodeData;
QJsonObject jsonFilters; NodeData* nodeData;
// output hints from the encode process // output hints from the encode process
typedef enum { typedef enum {
@ -110,8 +110,8 @@ public:
bool forceSendScene = true, bool forceSendScene = true,
OctreeSceneStats* stats = IGNORE_SCENE_STATS, OctreeSceneStats* stats = IGNORE_SCENE_STATS,
JurisdictionMap* jurisdictionMap = IGNORE_JURISDICTION_MAP, JurisdictionMap* jurisdictionMap = IGNORE_JURISDICTION_MAP,
OctreeElementExtraEncodeData* extraEncodeData = NULL, OctreeElementExtraEncodeData* extraEncodeData = nullptr,
QJsonObject jsonFilters = QJsonObject()) : NodeData* nodeData = nullptr) :
lastQuerySent(lastQuerySent), lastQuerySent(lastQuerySent),
maxEncodeLevel(maxEncodeLevel), maxEncodeLevel(maxEncodeLevel),
maxLevelReached(0), maxLevelReached(0),
@ -124,7 +124,7 @@ public:
stats(stats), stats(stats),
jurisdictionMap(jurisdictionMap), jurisdictionMap(jurisdictionMap),
extraEncodeData(extraEncodeData), extraEncodeData(extraEncodeData),
jsonFilters(jsonFilters), nodeData(nodeData),
stopReason(UNKNOWN) stopReason(UNKNOWN)
{ {
lastViewFrustum.invalidate(); lastViewFrustum.invalidate();

View file

@ -1,6 +1,6 @@
// //
// OctreeQueryNode.cpp // OctreeQueryNode.cpp
// assignment-client/src/octree // libraries/octree/src
// //
// Created by Stephen Birarda on 3/21/13. // Created by Stephen Birarda on 3/21/13.
// Copyright 2013 High Fidelity, Inc. // Copyright 2013 High Fidelity, Inc.
@ -18,7 +18,6 @@
#include <SharedUtil.h> #include <SharedUtil.h>
#include <UUID.h> #include <UUID.h>
#include "OctreeSendThread.h"
void OctreeQueryNode::nodeKilled() { void OctreeQueryNode::nodeKilled() {
_isShuttingDown = true; _isShuttingDown = true;

View file

@ -1,6 +1,6 @@
// //
// OctreeQueryNode.h // OctreeQueryNode.h
// assignment-client/src/octree // libraries/octree/src
// //
// Created by Brad Hefta-Gaub on 12/4/13. // Created by Brad Hefta-Gaub on 12/4/13.
// Copyright 2013 High Fidelity, Inc. // Copyright 2013 High Fidelity, Inc.
@ -15,11 +15,11 @@
#include <iostream> #include <iostream>
#include <NodeData.h> #include <NodeData.h>
#include <OctreeConstants.h> #include "OctreeConstants.h"
#include <OctreeElementBag.h> #include "OctreeElementBag.h"
#include <OctreePacketData.h> #include "OctreePacketData.h"
#include <OctreeQuery.h> #include "OctreeQuery.h"
#include <OctreeSceneStats.h> #include "OctreeSceneStats.h"
#include "SentPacketHistory.h" #include "SentPacketHistory.h"
#include <qqueue.h> #include <qqueue.h>