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(),
isFullScene, &nodeData->stats, _myServer->getJurisdiction(),
&nodeData->extraEncodeData,
nodeData->getJSONParameters());
nodeData);
nodeData->copyCurrentViewFrustum(params.viewFrustum);
if (viewFrustumChanged) {
nodeData->copyLastKnownViewFrustum(params.lastViewFrustum);

View file

@ -14,7 +14,7 @@
#include <udt/PacketHeaders.h>
#include "../octree/OctreeQueryNode.h"
#include <OctreeQueryNode.h>
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<QUuid> _entitiesSentLastFrame;
};
#endif // hifi_EntityNodeData_h

View file

@ -16,6 +16,7 @@
#include <OctreeUtils.h>
#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<EntityNodeData*>(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 &&

View file

@ -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();

View file

@ -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 <SharedUtil.h>
#include <UUID.h>
#include "OctreeSendThread.h"
void OctreeQueryNode::nodeKilled() {
_isShuttingDown = true;

View file

@ -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 <iostream>
#include <NodeData.h>
#include <OctreeConstants.h>
#include <OctreeElementBag.h>
#include <OctreePacketData.h>
#include <OctreeQuery.h>
#include <OctreeSceneStats.h>
#include "OctreeConstants.h"
#include "OctreeElementBag.h"
#include "OctreePacketData.h"
#include "OctreeQuery.h"
#include "OctreeSceneStats.h"
#include "SentPacketHistory.h"
#include <qqueue.h>