move stuff out of writelock when possible

This commit is contained in:
Andrew Meadows 2017-10-09 10:42:42 -07:00
parent 0bcecdbe66
commit bbde1bcd63

View file

@ -5643,9 +5643,7 @@ bool Application::nearbyEntitiesAreReadyForPhysics() {
// whose bounding boxes cannot be computed (it is too loose for our purposes here). Instead we manufacture // 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, ...) // custom filters and use the general-purpose EntityTree::findEntities(filter, ...)
QVector<EntityItemPointer> entities; QVector<EntityItemPointer> entities;
entityTree->withReadLock([&] {
AABox avatarBox(getMyAvatar()->getPosition() - glm::vec3(PHYSICS_READY_RANGE), glm::vec3(2 * PHYSICS_READY_RANGE)); 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 // create two functions that use avatarBox (entityScan and elementScan), the second calls the first
std::function<bool (EntityItemPointer&)> entityScan = [=](EntityItemPointer& entity) { std::function<bool (EntityItemPointer&)> entityScan = [=](EntityItemPointer& entity) {
if (entity->shouldBePhysical()) { if (entity->shouldBePhysical()) {
@ -5665,6 +5663,7 @@ bool Application::nearbyEntitiesAreReadyForPhysics() {
return false; return false;
}; };
entityTree->withReadLock([&] {
// Pass the second function to the general-purpose EntityTree::findEntities() // 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) // 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. // as it traverses. The end result will be a list of entities that match.