mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 06:29:30 +02:00
move stuff out of writelock when possible
This commit is contained in:
parent
0bcecdbe66
commit
bbde1bcd63
1 changed files with 13 additions and 14 deletions
|
@ -5643,20 +5643,18 @@ 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
|
||||||
|
std::function<bool (EntityItemPointer&)> entityScan = [=](EntityItemPointer& entity) {
|
||||||
// create two functions that use avatarBox (entityScan and elementScan), the second calls the first
|
if (entity->shouldBePhysical()) {
|
||||||
std::function<bool (EntityItemPointer&)> entityScan = [=](EntityItemPointer& entity) {
|
bool success = false;
|
||||||
if (entity->shouldBePhysical()) {
|
AABox entityBox = entity->getAABox(success);
|
||||||
bool success = false;
|
// important: bail for entities that cannot supply a valid AABox
|
||||||
AABox entityBox = entity->getAABox(success);
|
return success && avatarBox.touches(entityBox);
|
||||||
// important: bail for entities that cannot supply a valid AABox
|
}
|
||||||
return success && avatarBox.touches(entityBox);
|
return false;
|
||||||
}
|
};
|
||||||
return false;
|
std::function<bool(const OctreeElementPointer&, void*)> elementScan = [&](const OctreeElementPointer& element, void* unused) {
|
||||||
};
|
|
||||||
std::function<bool(const OctreeElementPointer&, void*)> elementScan = [&](const OctreeElementPointer& element, void* unused) {
|
|
||||||
if (element->getAACube().touches(avatarBox)) {
|
if (element->getAACube().touches(avatarBox)) {
|
||||||
EntityTreeElementPointer entityTreeElement = std::static_pointer_cast<EntityTreeElement>(element);
|
EntityTreeElementPointer entityTreeElement = std::static_pointer_cast<EntityTreeElement>(element);
|
||||||
entityTreeElement->getEntities(entityScan, entities);
|
entityTreeElement->getEntities(entityScan, entities);
|
||||||
|
@ -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.
|
||||||
|
|
Loading…
Reference in a new issue