update entity MotionType when it changes

This commit is contained in:
Andrew Meadows 2014-11-19 17:05:31 -08:00
parent 8bd3779d7d
commit 51da678675
3 changed files with 10 additions and 3 deletions

View file

@ -103,6 +103,7 @@ bool DeleteEntityOperator::preRecursion(OctreeElement* element) {
entityTreeElement->removeEntityItem(theEntity); // remove it from the element
_tree->setContainingElement(entityItemID, NULL); // update or id to element lookup
_tree->removeEntityFromPhysicsEngine(theEntity);
theEntity->destroyMotionState();
delete theEntity; // now actually delete the entity!
_foundCount++;
}

View file

@ -119,8 +119,8 @@ EntityItem::EntityItem(const EntityItemID& entityItemID, const EntityItemPropert
EntityItem::~EntityItem() {
#ifdef USE_BULLET_PHYSICS
// make sure the _motionState is already deleted (e.g. the entity has been removed
// from the physics simulation) BEFORE you get here
// Make sure the EntityItem has been removed from the physics engine AND
// that its _motionState has been destroyed BEFORE you get here.
assert(_motionState == NULL);
#endif // USE_BULLET_PHYSICS
}

View file

@ -619,6 +619,13 @@ void EntityTree::updateEntityState(EntityItem* entity) {
break;
}
entity->setSimulationState(newState);
if (_physicsEngine) {
EntityMotionState* motionState = entity->getMotionState();
if (motionState) {
_physicsEngine->updateEntityMotionType(motionState);
}
}
}
}
@ -659,7 +666,6 @@ void EntityTree::removeEntityFromPhysicsEngine(EntityItem* entity) {
EntityMotionState* motionState = entity->getMotionState();
if (motionState) {
_physicsEngine->removeEntity(static_cast<CustomMotionState*>(motionState));
entity->destroyMotionState();
}
#endif // USE_BULLET_PHYSICS
}