Merge pull request #7472 from AndrewMeadows/delete-mortal-entities

expire mortal entities correctly
This commit is contained in:
Philip Rosedale 2016-03-25 11:33:07 -07:00
commit e891fd219b
2 changed files with 17 additions and 12 deletions

View file

@ -101,12 +101,15 @@ void EntitySimulation::expireMortalEntities(const quint64& now) {
prepareEntityForDelete(entity); prepareEntityForDelete(entity);
} else { } else {
if (expiry < _nextExpiry) { 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; _nextExpiry = expiry;
} }
++itemItr; ++itemItr;
} }
} }
if (_mortalEntities.size() < 1) {
_nextExpiry = -1;
}
} }
} }

View file

@ -57,16 +57,18 @@ void PhysicalEntitySimulation::addEntityInternal(EntityItemPointer entity) {
} }
void PhysicalEntitySimulation::removeEntityInternal(EntityItemPointer entity) { void PhysicalEntitySimulation::removeEntityInternal(EntityItemPointer entity) {
EntitySimulation::removeEntityInternal(entity); if (entity->isSimulated()) {
QMutexLocker lock(&_mutex); EntitySimulation::removeEntityInternal(entity);
_entitiesToAddToPhysics.remove(entity); QMutexLocker lock(&_mutex);
_entitiesToAddToPhysics.remove(entity);
EntityMotionState* motionState = static_cast<EntityMotionState*>(entity->getPhysicsInfo()); EntityMotionState* motionState = static_cast<EntityMotionState*>(entity->getPhysicsInfo());
if (motionState) { if (motionState) {
_outgoingChanges.remove(motionState); _outgoingChanges.remove(motionState);
_entitiesToRemoveFromPhysics.insert(entity); _entitiesToRemoveFromPhysics.insert(entity);
} else { } else {
_entitiesToDelete.insert(entity); _entitiesToDelete.insert(entity);
}
} }
} }
@ -175,7 +177,7 @@ void PhysicalEntitySimulation::getObjectsToRemoveFromPhysics(VectorOfMotionState
_entitiesToRelease.insert(entity); _entitiesToRelease.insert(entity);
} }
if (entity->isSimulated() && entity->isDead()) { if (entity->isDead()) {
_entitiesToDelete.insert(entity); _entitiesToDelete.insert(entity);
} }
} }
@ -190,7 +192,7 @@ void PhysicalEntitySimulation::deleteObjectsRemovedFromPhysics() {
entity->setPhysicsInfo(nullptr); entity->setPhysicsInfo(nullptr);
delete motionState; delete motionState;
if (entity->isSimulated() && entity->isDead()) { if (entity->isDead()) {
_entitiesToDelete.insert(entity); _entitiesToDelete.insert(entity);
} }
} }