From b0d67843c43f50f36a92c4b8694b3df380ce50b1 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Thu, 11 Oct 2012 19:47:30 +0000 Subject: Moved handling of the physics reset for the Docked and Destroyed state from game tp core. --- src/core/entity.cc | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) (limited to 'src/core') diff --git a/src/core/entity.cc b/src/core/entity.cc index 46bcd5d..6ae9e87 100644 --- a/src/core/entity.cc +++ b/src/core/entity.cc @@ -696,9 +696,49 @@ void EntityDynamic::set_state(int state) void EntityDynamic::reset() { + // no bullet physics on NonSolid entities if (!radius() || has_flag(NonSolid)) { return; } + + // remove Docked and Destroyed entities from the physics simulation + if ((state() == core::Entity::Docked) || (state() == core::Entity::Destroyed)) { + + if (entity_body) { + + if (entity_motionstate) { + delete entity_motionstate; + entity_motionstate = 0; + } + + if (zone() && zone()->physics()) { + entity_zone->physics()->removeRigidBody(body()); + } + + if (entity_collision_shape) { + delete entity_collision_shape; + entity_collision_shape = 0; + } + + for (CollisionShapes::iterator sit = entity_collision_child_shapes.begin(); sit != entity_collision_child_shapes.end(); sit++) { + delete (*sit); + (*sit) = 0; + } + entity_collision_child_shapes.clear(); + + if (entity_body) { + delete entity_body; + entity_body = 0; + } + + if (entity_body_info) { + delete entity_body_info; + entity_body_info = 0; + } + } + + return; + } // location and orientation btTransform t; @@ -1182,10 +1222,55 @@ void EntityControlable::set_zone(Zone *zone) void EntityControlable::reset() { + // no bullet physics on NonSolid entities if (!radius() || has_flag(NonSolid)) { return; } + // remove Docked and Destroyed entities from the physics simulation + if ((state() == core::Entity::Docked) || (state() == core::Entity::Destroyed)) { + + if (entity_body) { + + if (entity_motionstate) { + delete entity_motionstate; + entity_motionstate = 0; + } + + if (zone() && zone()->physics()) { + if (entity_actioninterface) { + entity_zone->physics()->removeAction(entity_actioninterface); + delete entity_actioninterface; + entity_actioninterface = 0; + } + entity_zone->physics()->removeRigidBody(body()); + } + + if (entity_collision_shape) { + delete entity_collision_shape; + entity_collision_shape = 0; + } + + for (CollisionShapes::iterator sit = entity_collision_child_shapes.begin(); sit != entity_collision_child_shapes.end(); sit++) { + delete (*sit); + (*sit) = 0; + } + entity_collision_child_shapes.clear(); + + if (entity_body) { + delete entity_body; + entity_body = 0; + } + + if (entity_body_info) { + delete entity_body_info; + entity_body_info = 0; + } + } + + return; + } + // location and orientation btTransform t; t.setIdentity(); -- cgit v1.2.3