force a full scene send for new ancestors/descendants

This commit is contained in:
Stephen Birarda 2017-02-16 13:05:33 -08:00
parent a3883a746c
commit 9d336a84ab
6 changed files with 75 additions and 18 deletions

View file

@ -35,8 +35,13 @@ void EntityTreeSendThread::preDistributionProcessing() {
// we need to either include the ancestors, descendants, or both for entities matching the filter
// included in the JSON query
// first reset our flagged extra entities so we start with an empty set
nodeData->resetFlaggedExtraEntities();
auto entityTree = std::static_pointer_cast<EntityTree>(_myServer->getOctree());
bool requiresFullScene = false;
// enumerate the set of entity IDs we know currently match the filter
foreach(const QUuid& entityID, nodeData->getSentFilteredEntities()) {
if (includeAncestors) {
@ -45,7 +50,7 @@ void EntityTreeSendThread::preDistributionProcessing() {
entityTree->withReadLock([&]{
auto filteredEntity = entityTree->findEntityByID(entityID);
if (filteredEntity) {
addAncestorsToExtraFlaggedEntities(entityID, *filteredEntity, *nodeData);
requiresFullScene |= addAncestorsToExtraFlaggedEntities(entityID, *filteredEntity, *nodeData);
}
});
}
@ -56,18 +61,27 @@ void EntityTreeSendThread::preDistributionProcessing() {
entityTree->withReadLock([&]{
auto filteredEntity = entityTree->findEntityByID(entityID);
if (filteredEntity) {
addDescendantsToExtraFlaggedEntities(entityID, *filteredEntity, *nodeData);
requiresFullScene |= addDescendantsToExtraFlaggedEntities(entityID, *filteredEntity, *nodeData);
}
});
}
}
if (requiresFullScene) {
// for one or more of the entities matching our filter we found new extra entities to include
// because it is possible that one of these entities hasn't changed since our last send
// and therefore would not be recursed to, we need to force a full traversal for this pass
// of the tree to allow it to grab all of the extra entities we're asking it to include
nodeData->setShouldForceFullScene(requiresFullScene);
}
}
}
}
}
void EntityTreeSendThread::addAncestorsToExtraFlaggedEntities(const QUuid& filteredEntityID,
bool EntityTreeSendThread::addAncestorsToExtraFlaggedEntities(const QUuid& filteredEntityID,
EntityItem& entityItem, EntityNodeData& nodeData) {
// check if this entity has a parent that is also an entity
bool success = false;
@ -77,31 +91,48 @@ void EntityTreeSendThread::addAncestorsToExtraFlaggedEntities(const QUuid& filte
// we found a parent that is an entity item
// first add it to the extra list of things we need to send
nodeData.insertFlaggedExtraEntity(filteredEntityID, entityParent->getID());
bool parentWasNew = nodeData.insertFlaggedExtraEntity(filteredEntityID, entityParent->getID());
// qDebug() << "Adding" << entityParent->getID() << "which is an ancestor of" << filteredEntityID;
// now recursively call ourselves to get its ancestors added too
auto parentEntityItem = std::static_pointer_cast<EntityItem>(entityParent);
addAncestorsToExtraFlaggedEntities(filteredEntityID, *parentEntityItem, nodeData);
bool ancestorsWereNew = addAncestorsToExtraFlaggedEntities(filteredEntityID, *parentEntityItem, nodeData);
// return boolean if our parent or any of our ancestors were new additions (via insertFlaggedExtraEntity)
return parentWasNew || ancestorsWereNew;
}
// since we didn't have a parent niether of our parents or ancestors could be new additions
return false;
}
void EntityTreeSendThread::addDescendantsToExtraFlaggedEntities(const QUuid& filteredEntityID,
bool EntityTreeSendThread::addDescendantsToExtraFlaggedEntities(const QUuid& filteredEntityID,
EntityItem& entityItem, EntityNodeData& nodeData) {
bool hasNewChild = false;
bool hasNewDescendants = false;
// enumerate the immediate children of this entity
foreach (SpatiallyNestablePointer child, entityItem.getChildren()) {
if (child && child->getNestableType() == NestableType::Entity) {
// this is a child that is an entity
// first add it to the extra list of things we need to send
nodeData.insertFlaggedExtraEntity(filteredEntityID, child->getID());
hasNewChild |= nodeData.insertFlaggedExtraEntity(filteredEntityID, child->getID());
// qDebug() << "Adding" << child->getID() << "which is a descendant of" << filteredEntityID;
// now recursively call ourselves to get its descendants added too
auto childEntityItem = std::static_pointer_cast<EntityItem>(child);
addDescendantsToExtraFlaggedEntities(filteredEntityID, *childEntityItem, nodeData);
hasNewDescendants |= addDescendantsToExtraFlaggedEntities(filteredEntityID, *childEntityItem, nodeData);
}
}
// return our boolean indicating if we added new children or descendants as extra entities to send
// (via insertFlaggedExtraEntity)
return hasNewChild || hasNewDescendants;
}

View file

@ -26,8 +26,9 @@ protected:
virtual void preDistributionProcessing() override;
private:
void addAncestorsToExtraFlaggedEntities(const QUuid& filteredEntityID, EntityItem& entityItem, EntityNodeData& nodeData);
void addDescendantsToExtraFlaggedEntities(const QUuid& filteredEntityID, EntityItem& entityItem, EntityNodeData& nodeData);
// the following two methods return booleans to indicate if any extra flagged entities were new additions to set
bool addAncestorsToExtraFlaggedEntities(const QUuid& filteredEntityID, EntityItem& entityItem, EntityNodeData& nodeData);
bool addDescendantsToExtraFlaggedEntities(const QUuid& filteredEntityID, EntityItem& entityItem, EntityNodeData& nodeData);
};

View file

@ -309,8 +309,11 @@ int OctreeSendThread::packetDistributor(SharedNodePointer node, OctreeQueryNode*
return 0;
}
// give our pre-distribution processing a chance to do what it needs
preDistributionProcessing();
if (nodeData->elementBag.isEmpty()) {
// if we're about to do a fresh pass,
// give our pre-distribution processing a chance to do what it needs
preDistributionProcessing();
}
// calculate max number of packets that can be sent during this interval
int clientMaxPacketsPerInterval = std::max(1, (nodeData->getMaxQueryPacketsPerSecond() / INTERVALS_PER_SECOND));
@ -319,9 +322,17 @@ int OctreeSendThread::packetDistributor(SharedNodePointer node, OctreeQueryNode*
int truePacketsSent = 0;
int trueBytesSent = 0;
int packetsSentThisInterval = 0;
bool isFullScene = nodeData->haveJSONParametersChanged() ||
(nodeData->getUsesFrustum()
&& ((!viewFrustumChanged && nodeData->getViewFrustumJustStoppedChanging()) || nodeData->hasLodChanged()));
bool isFullScene = nodeData->shouldForceFullScene();
if (isFullScene) {
// we're forcing a full scene, clear the force in OctreeQueryNode so we don't force it next time again
nodeData->setShouldForceFullScene(false);
} else {
// we aren't forcing a full scene, check if something else suggests we should
isFullScene = nodeData->haveJSONParametersChanged() ||
(nodeData->getUsesFrustum()
&& ((!viewFrustumChanged && nodeData->getViewFrustumJustStoppedChanging()) || nodeData->hasLodChanged()));
}
bool somethingToSend = true; // assume we have something

View file

@ -11,6 +11,11 @@
#include "EntityNodeData.h"
bool EntityNodeData::insertFlaggedExtraEntity(const QUuid& filteredEntityID, const QUuid& extraEntityID) {
_flaggedExtraEntities[filteredEntityID].insert(extraEntityID);
return !_previousFlaggedExtraEntities[filteredEntityID].contains(extraEntityID);
}
bool EntityNodeData::isEntityFlaggedAsExtra(const QUuid& entityID) const {
// enumerate each of the sets for the entities that matched our filter

View file

@ -36,15 +36,19 @@ public:
bool sentFilteredEntity(const QUuid& entityID) { return _sentFilteredEntities.contains(entityID); }
QSet<QUuid> getSentFilteredEntities() { return _sentFilteredEntities; }
// these can only be called from the OctreeSendThread for the given Node
void insertFlaggedExtraEntity(const QUuid& filteredEntityID, const QUuid& extraEntityID)
{ _flaggedExtraEntities[filteredEntityID].insert(extraEntityID); }
// the following flagged extra entity methods can only be called from the OctreeSendThread for the given Node
// inserts the extra entity and returns a boolean indicating wether the extraEntityID was a new addition
bool insertFlaggedExtraEntity(const QUuid& filteredEntityID, const QUuid& extraEntityID);
bool isEntityFlaggedAsExtra(const QUuid& entityID) const;
void resetFlaggedExtraEntities() { _previousFlaggedExtraEntities = _flaggedExtraEntities; _flaggedExtraEntities.clear(); }
private:
quint64 _lastDeletedEntitiesSentAt { usecTimestampNow() };
QSet<QUuid> _sentFilteredEntities;
QHash<QUuid, QSet<QUuid>> _flaggedExtraEntities;
QHash<QUuid, QSet<QUuid>> _previousFlaggedExtraEntities;
};
#endif // hifi_EntityNodeData_h

View file

@ -103,6 +103,9 @@ public:
// call only from OctreeSendThread for the given node
bool haveJSONParametersChanged();
bool shouldForceFullScene() const { return _shouldForceFullScene; }
bool setShouldForceFullScene(bool shouldForceFullScene) { _shouldForceFullScene = shouldForceFullScene; }
private:
OctreeQueryNode(const OctreeQueryNode &);
OctreeQueryNode& operator= (const OctreeQueryNode&);
@ -148,6 +151,8 @@ private:
std::array<char, udt::MAX_PACKET_SIZE> _lastOctreePayload;
QJsonObject _lastCheckJSONParameters;
bool _shouldForceFullScene { false };
};
#endif // hifi_OctreeQueryNode_h