Exemplo n.º 1
0
CPhysicsObject::~CPhysicsObject() {
	m_bRemoving = true;

	if (m_pEnv) {
		RemoveShadowController();
		m_pEnv->GetDragController()->RemovePhysicsObject(this);

		if (m_pFluidController)
			m_pEnv->DestroyFluidController((IPhysicsFluidController *)m_pFluidController);
	}

	for (int i = 0; i < m_pConstraintVec.Count(); i++) {
		m_pConstraintVec[i]->ObjectDestroyed(this);
	}

	for (int i = 0; i < m_pControllers.Count(); i++) {
		m_pControllers[i]->ObjectDestroyed(this);
	}
	
	if (m_pEnv && m_pObject) {
		// Don't change this. This will eventually pan out to removeRigidBody.
		// Using removeCollisionObject because of a certain soft body fix.
		m_pEnv->GetBulletEnvironment()->removeCollisionObject(m_pObject);

		// Sphere collision shape is allocated when we're a sphere. Delete it.
		if (m_bIsSphere)
			delete (btSphereShape *)m_pObject->getCollisionShape();

		delete m_pObject->getMotionState();
		delete m_pObject;
	}
}
CPhysicsObject::~CPhysicsObject( void )
{
	RemoveShadowController();

	if ( m_pObject )
	{
		// prevents callbacks to the game code / unlink from this object
		m_callbacks = 0;
		m_pGameData = 0;
		m_pObject->client_data = 0;

		IVP_Core *pCore = m_pObject->get_core();
		if ( pCore->physical_unmoveable == IVP_TRUE && pCore->controllers_of_core.n_elems )
		{
			// go ahead and notify them if this happens in the real world
			for(int i = pCore->controllers_of_core.len()-1; i >=0 ;i-- ) 
			{
				IVP_Controller *my_controller = pCore->controllers_of_core.element_at(i);
				my_controller->core_is_going_to_be_deleted_event(pCore);
				Assert(my_controller==pCore->environment->get_gravity_controller());
			}
		}

		// UNDONE: Don't free the surface manager here
		// UNDONE: Remove reference to it by calling something in physics_collide
		IVP_SurfaceManager *pSurman = GetSurfaceManager();

		IVP_Environment *pEnv = m_pObject->get_environment();
		CPhysicsEnvironment *pVEnv = (CPhysicsEnvironment *)pEnv->client_data;

		// BUGBUG: Sometimes IVP will call a "revive" on the object we're deleting!
		if ( pVEnv && pVEnv->ShouldQuickDelete() )
		{
			m_pObject->delete_silently();
		}
		else
		{
			m_pObject->delete_and_check_vicinity();
		}
		delete pSurman;
	}
}