Merge branch 'master' of github.com:highfidelity/hifi into far-grab-nondynamic

This commit is contained in:
druiz17 2017-10-10 09:17:16 -07:00
commit 9ff1b2c815
6 changed files with 53 additions and 4 deletions

View file

@ -5639,14 +5639,37 @@ bool Application::nearbyEntitiesAreReadyForPhysics() {
return false;
}
// We don't want to use EntityTree::findEntities(AABox, ...) method because that scan will snarf parented entities
// whose bounding boxes cannot be computed (it is too loose for our purposes here). Instead we manufacture
// custom filters and use the general-purpose EntityTree::findEntities(filter, ...)
QVector<EntityItemPointer> entities;
AABox avatarBox(getMyAvatar()->getPosition() - glm::vec3(PHYSICS_READY_RANGE), glm::vec3(2 * PHYSICS_READY_RANGE));
// create two functions that use avatarBox (entityScan and elementScan), the second calls the first
std::function<bool (EntityItemPointer&)> entityScan = [=](EntityItemPointer& entity) {
if (entity->shouldBePhysical()) {
bool success = false;
AABox entityBox = entity->getAABox(success);
// important: bail for entities that cannot supply a valid AABox
return success && avatarBox.touches(entityBox);
}
return false;
};
std::function<bool(const OctreeElementPointer&, void*)> elementScan = [&](const OctreeElementPointer& element, void* unused) {
if (element->getAACube().touches(avatarBox)) {
EntityTreeElementPointer entityTreeElement = std::static_pointer_cast<EntityTreeElement>(element);
entityTreeElement->getEntities(entityScan, entities);
return true;
}
return false;
};
entityTree->withReadLock([&] {
AABox box(getMyAvatar()->getPosition() - glm::vec3(PHYSICS_READY_RANGE), glm::vec3(2 * PHYSICS_READY_RANGE));
entityTree->findEntities(box, entities);
// Pass the second function to the general-purpose EntityTree::findEntities()
// which will traverse the tree, apply the two filter functions (to element, then to entities)
// as it traverses. The end result will be a list of entities that match.
entityTree->findEntities(elementScan, entities);
});
// For reasons I haven't found, we don't necessarily have the full scene when we receive a stats packet. Apply
// a heuristic to try to decide when we actually know about all of the nearby entities.
uint32_t nearbyCount = entities.size();
if (nearbyCount == _nearbyEntitiesCountAtLastPhysicsCheck) {
_nearbyEntitiesStabilityCount++;

View file

@ -1240,6 +1240,7 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce
mapJoints(entity, model->getJointNames());
}
animate(entity);
emit requestRenderUpdate();
}
}

View file

@ -864,6 +864,12 @@ void EntityTree::findEntities(const ViewFrustum& frustum, QVector<EntityItemPoin
foundEntities.swap(args.entities);
}
// NOTE: assumes caller has handled locking
void EntityTree::findEntities(RecurseOctreeOperation& elementFilter,
QVector<EntityItemPointer>& foundEntities) {
recurseTreeWithOperation(elementFilter, nullptr);
}
EntityItemPointer EntityTree::findEntityByID(const QUuid& id) {
EntityItemID entityID(id);
return findEntityByEntityItemID(entityID);

View file

@ -165,6 +165,11 @@ public:
/// \param foundEntities[out] vector of EntityItemPointer
void findEntities(const ViewFrustum& frustum, QVector<EntityItemPointer>& foundEntities);
/// finds all entities that match scanOperator
/// \parameter scanOperator function that scans entities that match criteria
/// \parameter foundEntities[out] vector of EntityItemPointer
void findEntities(RecurseOctreeOperation& scanOperator, QVector<EntityItemPointer>& foundEntities);
void addNewlyCreatedHook(NewlyCreatedEntityHook* hook);
void removeNewlyCreatedHook(NewlyCreatedEntityHook* hook);

View file

@ -869,6 +869,14 @@ void EntityTreeElement::getEntities(const ViewFrustum& frustum, QVector<EntityIt
});
}
void EntityTreeElement::getEntities(EntityItemFilter& filter, QVector<EntityItemPointer>& foundEntities) {
forEachEntity([&](EntityItemPointer entity) {
if (filter(entity)) {
foundEntities.push_back(entity);
}
});
}
EntityItemPointer EntityTreeElement::getEntityWithEntityItemID(const EntityItemID& id) const {
EntityItemPointer foundEntity = NULL;
withReadLock([&] {

View file

@ -27,6 +27,7 @@ class EntityTreeElement;
using EntityItems = QVector<EntityItemPointer>;
using EntityTreeElementWeakPointer = std::weak_ptr<EntityTreeElement>;
using EntityTreeElementPointer = std::shared_ptr<EntityTreeElement>;
using EntityItemFilter = std::function<bool(EntityItemPointer&)>;
class EntityTreeUpdateArgs {
public:
@ -199,6 +200,11 @@ public:
/// \param entities[out] vector of non-const EntityItemPointer
void getEntities(const ViewFrustum& frustum, QVector<EntityItemPointer>& foundEntities);
/// finds all entities that match filter
/// \param filter function that adds matching entities to foundEntities
/// \param entities[out] vector of non-const EntityItemPointer
void getEntities(EntityItemFilter& filter, QVector<EntityItemPointer>& foundEntities);
EntityItemPointer getEntityWithID(uint32_t id) const;
EntityItemPointer getEntityWithEntityItemID(const EntityItemID& id) const;
void getEntitiesInside(const AACube& box, QVector<EntityItemPointer>& foundEntities);