Showing the changes to interface/src/Application.cpp (1 of 5 files). Show all
Unified · Split
| @@ -5639,14 +5639,38 @@ bool Application::nearbyEntitiesAreReadyForPhysics() { · 5638 unmodified lines | |||
| 5639 | return false; | 5639 | return false; |
| 5640 | } | 5640 | } |
| 5641 | 5641 | ||
| 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, ...) | ||
| 5643 | QVector<EntityItemPointer> entities; | 5645 | QVector<EntityItemPointer> entities; |
| 5644 | entityTree->withReadLock([&] { | 5646 | 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); | ||
| 5646 | }); | 5672 | }); |
| 5647 | 5673 | ||
| 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. | ||
| 5650 | uint32_t nearbyCount = entities.size(); | 5674 | uint32_t nearbyCount = entities.size(); |
| 5651 | if (nearbyCount == _nearbyEntitiesCountAtLastPhysicsCheck) { | 5675 | if (nearbyCount == _nearbyEntitiesCountAtLastPhysicsCheck) { |
| 5652 | _nearbyEntitiesStabilityCount++; | 5676 | _nearbyEntitiesStabilityCount++; |
| @@ -5662,18 +5686,11 @@ bool Application::nearbyEntitiesAreReadyForPhysics() { · 9 unmodified lines | |||
| 5662 | bool result = true; | 5686 | bool result = true; |
| 5663 | foreach (EntityItemPointer entity, entities) { | 5687 | foreach (EntityItemPointer entity, entities) { |
| 5664 | if (entity->shouldBePhysical() && !entity->isReadyToComputeShape()) { | 5688 | if (entity->shouldBePhysical() && !entity->isReadyToComputeShape()) { |
| 5665 | // BUG: the findEntities() query above is sometimes returning objects that don't actually overlap | 5689 | static QString repeatedMessage = |
| 5666 | // TODO: investigate and fix findQueries() but in the meantime... | 5690 | LogHandler::getInstance().addRepeatedMessageRegex("Physics disabled until entity loads: .*"); |
| 5667 | // WORKAROUND: test the overlap of each entity to verify it matters | 5691 | qCDebug(interfaceapp) << "Physics disabled until entity loads: " << entity->getID() << entity->getName(); |
| 5668 | bool success = false; | 5692 | // don't break here because we want all the relevant entities to start their downloads |
| 5669 | AACube entityCube = entity->getQueryAACube(success); | 5693 | result = false; |
| 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 | } | ||
| 5677 | } | 5694 | } |
| 5678 | } | 5695 | } |
| 5679 | return result; | 5696 | return result; |