Example #1
0
plPXPhysical::~plPXPhysical()
{
    SpamMsg(plSimulationMgr::Log("Destroying physical %s", GetKeyName().c_str()));

    if (fActor)
    {
        // Grab any mesh we may have (they need to be released manually)
        NxConvexMesh* convexMesh = nil;
        NxTriangleMesh* triMesh = nil;
        NxShape* shape = fActor->getShapes()[0];
        if (NxConvexShape* convexShape = shape->isConvexMesh())
            convexMesh = &convexShape->getConvexMesh();
        else if (NxTriangleMeshShape* trimeshShape = shape->isTriangleMesh())
            triMesh = &trimeshShape->getTriangleMesh();

        if (!fActor->isDynamic())
            plPXPhysicalControllerCore::RebuildCache();

        if (fActor->isDynamic() && fActor->readBodyFlag(NX_BF_KINEMATIC))
        {
            if (fGroup == plSimDefs::kGroupDynamic)
                fNumberAnimatedPhysicals--;
            else
                fNumberAnimatedActivators--;
        }

        // Release the actor
        NxScene* scene = plSimulationMgr::GetInstance()->GetScene(fWorldKey);
        scene->releaseActor(*fActor);
        fActor = nil;

        // Now that the actor is freed, release the mesh
        if (convexMesh)
            plSimulationMgr::GetInstance()->GetSDK()->releaseConvexMesh(*convexMesh);
        if (triMesh)
            plSimulationMgr::GetInstance()->GetSDK()->releaseTriangleMesh(*triMesh);

        // Release the scene, so it can be cleaned up if no one else is using it
        plSimulationMgr::GetInstance()->ReleaseScene(fWorldKey);
    }

    if (fWorldHull)
        delete [] fWorldHull;
    if (fSaveTriangles)
        delete [] fSaveTriangles;

    delete fProxyGen;

    // remove sdl modifier
    plSceneObject* sceneObj = plSceneObject::ConvertNoRef(fObjectKey->ObjectIsLoaded());
    if (sceneObj && fSDLMod)
    {
        sceneObj->RemoveModifier(fSDLMod);
    }
    delete fSDLMod;
}
Example #2
0
	void removeFluidContainmentSphere()
	{
		assert(scene->isWritable());

		if(physicslib_fluid_containment_sphere_actor != NULL)
		{
			if(scene && physicslib_fluid_containment_sphere_actor)
			{
				assert(scene->isWritable());
				scene->releaseActor(*physicslib_fluid_containment_sphere_actor);
			}

			physicslib_fluid_containment_sphere_actor = NULL;
			physicslib_fluid_containment_sphere_shape = NULL;
		}
	}
void plPXPhysicalControllerCore::IDeleteController()
{
    if (fController)
    {
        gControllerMgr.releaseController(*fController);
        fController = nil;

        if (fKinematicActor)
        {
            NxScene* scene = plSimulationMgr::GetInstance()->GetScene(fWorldKey);
            scene->releaseActor(*fKinematicActor);
            fKinematicActor = nil;
        }
        plSimulationMgr::GetInstance()->ReleaseScene(fWorldKey);
    }
}
Example #4
0
	~Data()
	{
		removeFluidContainmentSphere();

#ifdef PROJECT_CLAW_PROTO
		unitMaterial = NULL;
#endif

		if(physicslib_fluid_containment_actor != NULL)
		{
			if(scene && physicslib_fluid_containment_actor)
			{
				assert(scene->isWritable());
				scene->releaseActor(*physicslib_fluid_containment_actor);
			}

			physicslib_fluid_containment_actor = NULL;
			physicslib_fluid_containment_shape = NULL;
		}

		if(sdk && scene)
		{
#ifndef NDEBUG
			int actors = scene->getNbActors();
			assert(actors == 1 || actors == 2);

#ifndef NX_DISABLE_FLUIDS
			int fluids = scene->getNbFluids();
			assert(fluids == 0);
#endif
#endif
			scene->shutdownWorkerThreads();
			sdk->releaseScene(*scene);
		}

		if(sdk)
			sdk->release();
	}
Example #5
0
CVoid CScene::Destroy()
{
	NxScene* tempScene = gPhysXscene/*gPhysicsSDK->getScene(i)*/;
	if(tempScene && !g_clickedNew && !g_clickedOpen)
	{
		for( CUInt i = 0; i < m_instanceGeometries.size(); i++ )
		{
			CInstanceGeometry* m_instanceGeo = m_instanceGeometries[i];
			if( tempScene )
			{
				for( CUInt j = 0; j < tempScene->getNbActors(); j++ )
				{
					CChar actorName[MAX_NAME_SIZE];
					if( !tempScene->getActors()[j]->getName() ) continue;
					Cpy( actorName, tempScene->getActors()[j]->getName() );
					if( !Cmp(m_instanceGeo->m_physXName, "\n" ) && Cmp( actorName, m_instanceGeo->m_physXName ) )
					{
						for(CInt nItem =0 ; nItem <  ex_pVandaEngine1Dlg->m_listBoxPhysXElements.GetItemCount(); nItem++)
						{
							CString strText = ex_pVandaEngine1Dlg->m_listBoxPhysXElements.GetItemText(nItem, 0);
							char charPtr[MAX_NAME_SIZE];
							sprintf(charPtr, "%s", strText);
							if(Cmp( m_instanceGeo->m_physXName, charPtr ) )
							{
								ex_pVandaEngine1Dlg->m_listBoxPhysXElements.DeleteItem(nItem);
								ex_pVandaEngine1Dlg->SortPhysXList();
							}
						}

						tempScene->releaseActor( *tempScene->getActors()[j] );
						g_multipleView->m_nx->gControllers->reportSceneChanged();
						m_instanceGeo->m_hasPhysX = CFalse;
						Cpy( m_instanceGeo->m_physXName, "\n" );
					}
				}
			}
		}
	}
	//while(!m_cfxMaterials.empty())
	//{
		//std::map<std::string, cfxMaterial*>::iterator iter = m_cfxMaterials.begin();
		//CDelete(iter->second);
		//m_cfxMaterials.erase(iter);
	//}
	//m_cfxEffects.clear();

	//while(!m_cfxEffects.empty())
	//{
		//std::map<std::string, cfxEffect*>::iterator iter = m_cfxEffects.begin();
		//CDelete(iter->second);
		//m_cfxEffects.erase(iter);
	//}
	//m_cfxEffects.clear();
	//delete all the geometries
	m_textureList.clear(); //save functions
	m_prefabList.clear(); //save functions

	if (g_editorMode == eMODE_PREFAB)
	{
		while (!m_geometries.empty())
		{
			CDelete(m_geometries[0]);
			m_geometries.erase(m_geometries.begin());
		}
		m_geometries.clear();
	}

	m_instanceGeometries.clear();
	//m_instanceControllers.clear();
	while(!m_lightInstances.empty())
	{
		CDelete(m_lightInstances[0]);
		m_lightInstances.erase(m_lightInstances.begin());
	}
	while(!m_lights.empty())
	{
		CDelete( m_lights[0] ); 
		m_lights.erase(m_lights.begin());
	}
	while(!m_cameraInstances.empty())
	{
		for( CUInt size = 0; size < g_cameraInstances.size(); size++ )
		{
			if( Cmp( m_cameraInstances[0]->m_abstractCamera->GetName(), g_cameraInstances[size]->m_abstractCamera->GetName() ) )
			{
				if( g_render.GetActiveInstanceCamera() == g_cameraInstances[size] )
				{
					if (g_multipleView && g_render.GetDefaultInstanceCamera())
					{
						g_render.SetActiveInstanceCamera(g_render.GetDefaultInstanceCamera());
						g_currentCameraType = eCAMERA_DEFAULT_FREE;
						g_multipleView->m_lockInput = CFalse;
					}
					else
					{
						g_render.SetActiveInstanceCamera(NULL);
					}

				}
				g_cameraInstances.erase( g_cameraInstances.begin() + size );
			}
		}
		CDelete(m_cameraInstances[0]);
		m_cameraInstances.erase(m_cameraInstances.begin());
	}

	while(!m_cameras.empty())
	{
		CDelete( m_cameras[0] ); 
		m_cameras.erase(m_cameras.begin());
	}
	while(!m_controllers.empty())
	{
		CDelete( m_controllers[0] );
		m_controllers.erase(m_controllers.begin());
	}
	//Delete all the nodes
	CDelete( m_sceneRoot );
	m_nodes.clear();

	//Clear all the images
	//for( std::vector<CImage*>::iterator it = m_images.begin(); it != m_images.end(); it++ )
	//{
	//	CDelete( *it );
	//}
	//Clear the vector objects
	m_images.clear();

	//clear all the effects
	for( std::vector<CEffect*>::iterator it = m_effects.begin(); it != m_effects.end(); it++ )
	{
		CDelete( *it );
	}
	//Clear the vector objects
	m_effects.clear();

	for( std::vector<CMaterial*>::iterator it = m_materials.begin(); it != m_materials.end(); it++ )
	{
		CDelete( *it );
	}
	//Clear the vector objects
	m_materials.clear();

	for( std::vector<CAnimation*>::iterator it = m_animations.begin(); it != m_animations.end(); it++ )
	{
		CDelete( *it );
	}
	//Clear the vector objects
	m_animations.clear();

	for( std::vector<CAnimationClip*>::iterator it = m_animationClips.begin(); it != m_animationClips.end(); it++ )
	{
		CDelete( *it );
	}
	//Clear the vector objects
	m_animationClips.clear();
}
Example #6
0
CVoid CScene::Destroy()
{
	NxScene* tempScene = gPhysXscene/*gPhysicsSDK->getScene(i)*/;
	if(tempScene && !g_clickedNew && !g_clickedOpen)
	{
		for( CUInt i = 0; i < m_instanceGeometries.size(); i++ )
		{
			CInstanceGeometry* m_instanceGeo = m_instanceGeometries[i];
			if( tempScene )
			{
				for( CUInt j = 0; j < tempScene->getNbActors(); j++ )
				{
					CChar actorName[MAX_URI_SIZE];
					if( !tempScene->getActors()[j]->getName() ) continue;
					Cpy( actorName, tempScene->getActors()[j]->getName() );
					if( !Cmp(m_instanceGeo->m_physXName, "\n" ) && Cmp( actorName, m_instanceGeo->m_physXName ) )
					{
						tempScene->releaseActor( *tempScene->getActors()[j] );
						g_nx->gControllers->reportSceneChanged();
						m_instanceGeo->m_hasPhysX = CFalse;
						Cpy( m_instanceGeo->m_physXName, "\n" );
					}
				}
			}
		}
	}
	//while(!m_cfxMaterials.empty())
	//{
	//	std::map<std::string, cfxMaterial*>::iterator iter = m_cfxMaterials.begin();
	//	CDelete(iter->second);
	//	m_cfxMaterials.erase(iter);
	//}
	//m_cfxEffects.clear();

	//while(!m_cfxEffects.empty())
	//{
	//	std::map<std::string, cfxEffect*>::iterator iter = m_cfxEffects.begin();
	//	CDelete(iter->second);
	//	m_cfxEffects.erase(iter);
	//}
	//m_cfxEffects.clear();
	//delete all the geometries
	//while(!m_geometries.empty())
	//{
	//	CDelete( m_geometries[0] ); 
	//	m_geometries.erase( m_geometries.begin() );
	//}	
	//m_geometries.clear();
	m_instanceGeometries.clear();

	while(!m_lightInstances.empty())
	{
		CDelete(m_lightInstances[0]);
		m_lightInstances.erase(m_lightInstances.begin());
	}
	while(!m_lights.empty())
	{
		CDelete( m_lights[0] ); 
		m_lights.erase(m_lights.begin());
	}
	while(!m_cameraInstances.empty())
	{
		for( CUInt size = 0; size < g_cameraInstances.size(); size++ )
		{
			if( Cmp( m_cameraInstances[0]->m_abstractCamera->GetName(), g_cameraInstances[size]->m_abstractCamera->GetName() ) )
			{
				if( g_render.GetActiveInstanceCamera() == g_cameraInstances[size] )
				{
					if (g_main && g_render.GetDefaultInstanceCamera())
					{
						g_render.SetActiveInstanceCamera(g_render.GetDefaultInstanceCamera());
						g_currentCameraType = eCAMERA_DEFAULT_FREE;
						g_main->m_lockInput = CFalse;
					}
					else
					{
						g_render.SetActiveInstanceCamera(NULL);
					}
				}
				g_cameraInstances.erase( g_cameraInstances.begin() + size );
			}
		}
		CDelete(m_cameraInstances[0]);
		m_cameraInstances.erase(m_cameraInstances.begin());
	}

	while(!m_cameras.empty())
	{
		CDelete( m_cameras[0] ); 
		m_cameras.erase(m_cameras.begin());
	}
	while(!m_controllers.empty())
	{
		CDelete( m_controllers[0] );
		m_controllers.erase(m_controllers.begin());
	}
	//Delete all the nodes
	CDelete( m_sceneRoot );
	m_nodes.clear();

	//Clear all the images
	//for( std::vector<CImage*>::iterator it = m_images.begin(); it != m_images.end(); it++ )
	//{
	//	CDelete( *it );
	//}
	//Clear the vector objects
	m_images.clear();

	//clear all the effects
	for( std::vector<CEffect*>::iterator it = m_effects.begin(); it != m_effects.end(); it++ )
	{
		CDelete( *it );
	}
	//Clear the vector objects
	m_effects.clear();

	for( std::vector<CMaterial*>::iterator it = m_materials.begin(); it != m_materials.end(); it++ )
	{
		CDelete( *it );
	}
	//Clear the vector objects
	m_materials.clear();

	for( std::vector<CAnimation*>::iterator it = m_animations.begin(); it != m_animations.end(); it++ )
	{
		CDelete( *it );
	}
	//Clear the vector objects
	m_animations.clear();

	for( std::vector<CAnimationClip*>::iterator it = m_animationClips.begin(); it != m_animationClips.end(); it++ )
	{
		CDelete( *it );
	}
	//Clear the vector objects
	m_animationClips.clear();
}