History

be picky when finding nearby entities at login

Andrew Meadows committed 9 years ago

Commit 0bcecdb1 parent 0f4e7fb5 files · +58 −16Browse files

Showing the changes to interface/src/Application.cpp (1 of 5 files). Show all

Unified · Split

interface/src/Application.cpp+33−16
@@ -5639,14 +5639,38 @@ bool Application::nearbyEntitiesAreReadyForPhysics() { · 5638 unmodified lines
56395639 return false;
56405640 }
56415641
5642− AABox avatarBox(getMyAvatar()->getPosition() - glm::vec3(0.5f * PHYSICS_READY_RANGE), glm::vec3(PHYSICS_READY_RANGE));
5642+ // We don't want to use EntityTree::findEntities(AABox, ...) method because that scan will snarf parented entities
5643+ // whose bounding boxes cannot be computed (it is too loose for our purposes here). Instead we manufacture
5644+ // custom filters and use the general-purpose EntityTree::findEntities(filter, ...)
56435645 QVector<EntityItemPointer> entities;
56445646 entityTree->withReadLock([&] {
5645− entityTree->findEntities(avatarBox, entities);
5647+ AABox avatarBox(getMyAvatar()->getPosition() - glm::vec3(PHYSICS_READY_RANGE), glm::vec3(2 * PHYSICS_READY_RANGE));
5648+
5649+ // create two functions that use avatarBox (entityScan and elementScan), the second calls the first
5650+ std::function<bool (EntityItemPointer&)> entityScan = [=](EntityItemPointer& entity) {
5651+ if (entity->shouldBePhysical()) {
5652+ bool success = false;
5653+ AABox entityBox = entity->getAABox(success);
5654+ // important: bail for entities that cannot supply a valid AABox
5655+ return success && avatarBox.touches(entityBox);
5656+ }
5657+ return false;
5658+ };
5659+ std::function<bool(const OctreeElementPointer&, void*)> elementScan = [&](const OctreeElementPointer& element, void* unused) {
5660+ if (element->getAACube().touches(avatarBox)) {
5661+ EntityTreeElementPointer entityTreeElement = std::static_pointer_cast<EntityTreeElement>(element);
5662+ entityTreeElement->getEntities(entityScan, entities);
5663+ return true;
5664+ }
5665+ return false;
5666+ };
5667+
5668+ // Pass the second function to the general-purpose EntityTree::findEntities()
5669+ // which will traverse the tree, apply the two filter functions (to element, then to entities)
5670+ // as it traverses. The end result will be a list of entities that match.
5671+ entityTree->findEntities(elementScan, entities);
56465672 });
56475673
5648− // For reasons I haven't found, we don't necessarily have the full scene when we receive a stats packet. Apply
5649− // a heuristic to try to decide when we actually know about all of the nearby entities.
56505674 uint32_t nearbyCount = entities.size();
56515675 if (nearbyCount == _nearbyEntitiesCountAtLastPhysicsCheck) {
56525676 _nearbyEntitiesStabilityCount++;
@@ -5662,18 +5686,11 @@ bool Application::nearbyEntitiesAreReadyForPhysics() { · 9 unmodified lines
56625686 bool result = true;
56635687 foreach (EntityItemPointer entity, entities) {
56645688 if (entity->shouldBePhysical() && !entity->isReadyToComputeShape()) {
5665− // BUG: the findEntities() query above is sometimes returning objects that don't actually overlap
5666− // TODO: investigate and fix findQueries() but in the meantime...
5667− // WORKAROUND: test the overlap of each entity to verify it matters
5668− bool success = false;
5669− AACube entityCube = entity->getQueryAACube(success);
5670− if (success && avatarBox.touches(entityCube)) {
5671− static QString repeatedMessage =
5672− LogHandler::getInstance().addRepeatedMessageRegex("Physics disabled until entity loads: .*");
5673− qCDebug(interfaceapp) << "Physics disabled until entity loads: " << entity->getID() << entity->getName();
5674− // don't break here because we want all the relevant entities to start their downloads
5675− result = false;
5676− }
5689+ static QString repeatedMessage =
5690+ LogHandler::getInstance().addRepeatedMessageRegex("Physics disabled until entity loads: .*");
5691+ qCDebug(interfaceapp) << "Physics disabled until entity loads: " << entity->getID() << entity->getName();
5692+ // don't break here because we want all the relevant entities to start their downloads
5693+ result = false;
56775694 }
56785695 }
56795696 return result;