From d3d724530a97018f16699da3d8854652390202eb Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 24 Mar 2016 21:09:45 -0700 Subject: [PATCH 1/2] minor optimiztion --- libraries/entities/src/EntitySimulation.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libraries/entities/src/EntitySimulation.cpp b/libraries/entities/src/EntitySimulation.cpp index 014ab33094..14bfc5ac7a 100644 --- a/libraries/entities/src/EntitySimulation.cpp +++ b/libraries/entities/src/EntitySimulation.cpp @@ -101,12 +101,15 @@ void EntitySimulation::expireMortalEntities(const quint64& now) { prepareEntityForDelete(entity); } else { if (expiry < _nextExpiry) { - // remeber the smallest _nextExpiry so we know when to start the next search + // remember the smallest _nextExpiry so we know when to start the next search _nextExpiry = expiry; } ++itemItr; } } + if (_mortalEntities.size() < 1) { + _nextExpiry = -1; + } } } From ac5c055a1ea1fe07ed2aa3664a8ce1ce366335f5 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 24 Mar 2016 21:11:05 -0700 Subject: [PATCH 2/2] don't verify simulated bit when adding to delete list --- .../physics/src/PhysicalEntitySimulation.cpp | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/libraries/physics/src/PhysicalEntitySimulation.cpp b/libraries/physics/src/PhysicalEntitySimulation.cpp index 497ed2031f..2d219915c8 100644 --- a/libraries/physics/src/PhysicalEntitySimulation.cpp +++ b/libraries/physics/src/PhysicalEntitySimulation.cpp @@ -57,16 +57,18 @@ void PhysicalEntitySimulation::addEntityInternal(EntityItemPointer entity) { } void PhysicalEntitySimulation::removeEntityInternal(EntityItemPointer entity) { - EntitySimulation::removeEntityInternal(entity); - QMutexLocker lock(&_mutex); - _entitiesToAddToPhysics.remove(entity); + if (entity->isSimulated()) { + EntitySimulation::removeEntityInternal(entity); + QMutexLocker lock(&_mutex); + _entitiesToAddToPhysics.remove(entity); - EntityMotionState* motionState = static_cast(entity->getPhysicsInfo()); - if (motionState) { - _outgoingChanges.remove(motionState); - _entitiesToRemoveFromPhysics.insert(entity); - } else { - _entitiesToDelete.insert(entity); + EntityMotionState* motionState = static_cast(entity->getPhysicsInfo()); + if (motionState) { + _outgoingChanges.remove(motionState); + _entitiesToRemoveFromPhysics.insert(entity); + } else { + _entitiesToDelete.insert(entity); + } } } @@ -175,7 +177,7 @@ void PhysicalEntitySimulation::getObjectsToRemoveFromPhysics(VectorOfMotionState _entitiesToRelease.insert(entity); } - if (entity->isSimulated() && entity->isDead()) { + if (entity->isDead()) { _entitiesToDelete.insert(entity); } } @@ -190,7 +192,7 @@ void PhysicalEntitySimulation::deleteObjectsRemovedFromPhysics() { entity->setPhysicsInfo(nullptr); delete motionState; - if (entity->isSimulated() && entity->isDead()) { + if (entity->isDead()) { _entitiesToDelete.insert(entity); } }