Esempio n. 1
0
	//---------------------------------------------------------------------
	void ParticleUniversePlugin::shutdown()
	{
		// Delete the manager.
		// The manager must be deleted before all factories are deleted (also the factories of other plugins)
#ifdef CN_MODIFY
		PU_DELETE_T(mParticleRendererManager, ParticleRendererManager, MEMCATEGORY_SCENE_CONTROL);
#endif

		PU_DELETE_T(mParticleSystemManager, ParticleSystemManager, MEMCATEGORY_SCENE_CONTROL);
	}
	//-----------------------------------------------------------------------
	TextureRotator::~TextureRotator(void)
	{
		if (mDynRotation)
		{
			PU_DELETE_T(mDynRotation, DynamicAttribute, MEMCATEGORY_SCENE_OBJECTS);
			mDynRotation = 0;
		}

		if (mDynRotationSpeed)
		{
			PU_DELETE_T(mDynRotationSpeed, DynamicAttribute, MEMCATEGORY_SCENE_OBJECTS);
			mDynRotationSpeed = 0;
		}
	}
	//-----------------------------------------------------------------------
	void ParticleEmitter::setDynEmissionRate(DynamicAttribute* dynEmissionRate)
	{
		if (mDynEmissionRate)
			PU_DELETE_T(mDynEmissionRate, DynamicAttribute, MEMCATEGORY_SCENE_OBJECTS);

		mDynEmissionRate = dynEmissionRate;
	}
	//-----------------------------------------------------------------------
	void ParticleEmitter::setDynTotalTimeToLive(DynamicAttribute* dynTotalTimeToLive)
	{
		if (mDynTotalTimeToLive)
			PU_DELETE_T(mDynTotalTimeToLive, DynamicAttribute, MEMCATEGORY_SCENE_OBJECTS);

		mDynTotalTimeToLive = dynTotalTimeToLive;
	}
	//-----------------------------------------------------------------------
	void LightRenderer::_destroyAll(void)
	{
		if (!mParentTechnique)
			return;

		// Note: The created ChildSceneNodes are destroyed when the ParticleSystem is destroyed
		vector<LightRendererVisualData*>::const_iterator it;
		vector<LightRendererVisualData*>::const_iterator itEnd = mAllVisualData.end();
		for (it = mAllVisualData.begin(); it != itEnd; ++it)
		{
			PU_DELETE_T(*it, LightRendererVisualData, MEMCATEGORY_SCENE_OBJECTS);
		}

		mAllVisualData.clear();
		mVisualData.clear();

		// Destroy the Lights. Do it like this, because it must be assured that the light still exists
		// and has not already been destroyed.
		Ogre::SceneManager* sceneManager = mParentTechnique->getParentSystem()->getSceneManager();
		for (size_t i = 0; i < mQuota; i++)
		{
			if (sceneManager->hasLight(mLightName + StringConverter::toString(i)))
			{
				sceneManager->destroyLight(mLightName + StringConverter::toString(i));
			}
		}
		mLights.clear();

		// Reset the visual data in the pool
		mParentTechnique->initVisualDataInPool();
	}
	//-----------------------------------------------------------------------
	void ParticleEmitter::setDynParticleMass(DynamicAttribute* dynParticleMass)
	{
		if (mDynParticleMass)
			PU_DELETE_T(mDynParticleMass, DynamicAttribute, MEMCATEGORY_SCENE_OBJECTS);

		mDynParticleMass = dynParticleMass;
	}
	//-----------------------------------------------------------------------
	void ParticleEmitter::setDynAngle(DynamicAttribute* dynAngle)
	{
		if (mDynAngle)
			PU_DELETE_T(mDynAngle, DynamicAttribute, MEMCATEGORY_SCENE_OBJECTS);

		mDynAngle = dynAngle;
	}
	//-----------------------------------------------------------------------
	void ParticleEmitter::setDynVelocity(DynamicAttribute* dynVelocity)
	{
		if (mDynVelocity)
			PU_DELETE_T(mDynVelocity, DynamicAttribute, MEMCATEGORY_SCENE_OBJECTS);

		mDynVelocity = dynVelocity;
	}
	//-----------------------------------------------------------------------
	void TextureRotator::setRotation(DynamicAttribute* dynRotation)
	{
		if (mDynRotation)
			PU_DELETE_T(mDynRotation, DynamicAttribute, MEMCATEGORY_SCENE_OBJECTS);

		mDynRotation = dynRotation;
	}
	//-----------------------------------------------------------------------
	void VortexAffector::setRotationSpeed(DynamicAttribute* dynRotationSpeed)
	{
		if (mDynRotationSpeed)
			PU_DELETE_T(mDynRotationSpeed, DynamicAttribute, MEMCATEGORY_SCENE_OBJECTS);

		mDynRotationSpeed = dynRotationSpeed;
	}
	//-----------------------------------------------------------------------
	VortexAffector::~VortexAffector(void)
	{
		if (mDynRotationSpeed)
		{
			PU_DELETE_T(mDynRotationSpeed, DynamicAttribute, MEMCATEGORY_SCENE_OBJECTS);
			mDynRotationSpeed = 0;
		}
	}
	//-----------------------------------------------------------------------
	void ParticleEmitter::setDynParticleDepth(DynamicAttribute* dynParticleDepth)
	{
		if (mDynParticleDepth)
			PU_DELETE_T(mDynParticleDepth, DynamicAttribute, MEMCATEGORY_SCENE_OBJECTS);

		mDynParticleDepth = dynParticleDepth;
		mDynParticleDepthSet = true;
	}
	//-----------------------------------------------------------------------
	MeshSurfaceEmitter::~MeshSurfaceEmitter(void)
    {
		if (mMeshInfo)
		{
			PU_DELETE_T(mMeshInfo, MeshInfo, MEMCATEGORY_SCENE_OBJECTS);
			mMeshInfo = 0;
		}
	}
	//-----------------------------------------------------------------------
	void ParticleEmitter::setDynParticleAllDimensions(DynamicAttribute* dynParticleAllDimensions)
	{
		if (mDynParticleAllDimensions)
			PU_DELETE_T(mDynParticleAllDimensions, DynamicAttribute, MEMCATEGORY_SCENE_OBJECTS);

		mDynParticleAllDimensions = dynParticleAllDimensions;
		mDynParticleAllDimensionsSet = true;
	}
	//-----------------------------------------------------------------------
	void ParticleEmitter::setDynParticleHeight(DynamicAttribute* dynParticleHeight)
	{
		if (mDynParticleHeight)
			PU_DELETE_T(mDynParticleHeight, DynamicAttribute, MEMCATEGORY_SCENE_OBJECTS);

		mDynParticleHeight = dynParticleHeight;
		mDynParticleHeightSet = true;
	}
	//-----------------------------------------------------------------------
	void ParticleEmitter::setDynDuration(DynamicAttribute* dynDuration)
	{
		if (mDynDuration)
			PU_DELETE_T(mDynDuration, DynamicAttribute, MEMCATEGORY_SCENE_OBJECTS);

		mDynDuration = dynDuration;
		mDynDurationSet = true;
		_initTimeBased();
	}
	//-----------------------------------------------------------------------
	void ParticleEmitter::setDynRepeatDelay(DynamicAttribute* dynRepeatDelay)
	{
		if (mDynRepeatDelay)
			PU_DELETE_T(mDynRepeatDelay, DynamicAttribute, MEMCATEGORY_SCENE_OBJECTS);

		mDynRepeatDelay = dynRepeatDelay;
		mDynRepeatDelaySet = true;
		_initTimeBased();
	}
	//-----------------------------------------------------------------------
	void EntityRenderer::_destroyAll(void)
	{
		if (!mParentTechnique)
			return;


		// Delete the visual data
		vector<EntityRendererVisualData*>::const_iterator it;
		vector<EntityRendererVisualData*>::const_iterator itEnd = mAllVisualData.end();
		for (it = mAllVisualData.begin(); it != itEnd; ++it)
		{
			PU_DELETE_T(*it, EntityRendererVisualData, MEMCATEGORY_SCENE_OBJECTS);
		}

		mAllVisualData.clear();
		mVisualData.clear();

		// V1.5: Destroy the created ChildSceneNodes (which leads to detaching the Entities)
		if (mParentTechnique->getParentSystem())
		{
			Ogre::SceneNode* parentNode = mParentTechnique->getParentSystem()->getParentSceneNode();
			if (parentNode)
			{
				String sceneNodeName;
				std::stringstream ss; 
				unsigned short numChilds = parentNode->numChildren();
				for (unsigned short i = 0; i < numChilds; ++i)
				{
					Ogre::Node* node = parentNode->getChild(i);
					if (node)
					{
						Ogre::String name = node->getName();
						if (name.find("ParticleUniverse") != Ogre::String::npos)
						{
							parentNode->removeAndDestroyChild(i);
						}
					}
				}
			}
		} // V1.5

		// Destroy the Entities. Do it like this, because it must be assured that the entity still exists
		// and has not already been destroyed.
		Ogre::SceneManager* sceneManager = mParentTechnique->getParentSystem()->getSceneManager();
		for (size_t i = 0; i < mQuota; i++)
		{
			if (sceneManager->hasEntity(mEntityName + StringConverter::toString(i)))
			{
				sceneManager->destroyEntity(mEntityName + StringConverter::toString(i));
			}
		}
		mEntities.clear();

		// Reset the visual data in the pool
		mParentTechnique->initVisualDataInPool();
	}
	//-----------------------------------------------------------------------
	void ParticlePool::destroyAllVisualParticles(void)
	{
		vector<VisualParticle*>::iterator it;
		for (it = mVisualParticles.begin(); it != mVisualParticles.end(); ++it)
		{
			PU_DELETE_T(*it, VisualParticle, MEMCATEGORY_SCENE_OBJECTS);
		}
		mVisualParticles.clear();
		mVisualParticlesPool.clear();
	}
    //-----------------------------------------------------------------------
	void MeshSurfaceEmitter::build(void)
	{
		// Delete the mesh info if already existing
		if (mMeshInfo)
		{
			PU_DELETE_T(mMeshInfo, MeshInfo, MEMCATEGORY_SCENE_OBJECTS);
			mMeshInfo = 0;
		}

		// Generate meshinfo.
		mMeshInfo = PU_NEW_T(MeshInfo, MEMCATEGORY_SCENE_OBJECTS)(mMeshName, mDistribution, mOrientation, mScale);
	}
Esempio n. 21
0
	//---------------------------------------------------------------------
	void ParticleUniversePlugin::uninstall()
	{
		// Delete all factories created in dllStartPlugin (after deleting the ParticleSystemManager)
		vector<ParticleRendererFactory*>::iterator ri;
		for (ri = mRendererFactories.begin(); ri != mRendererFactories.end(); ++ri)
		{
			PU_DELETE *ri;
		}

		vector<ParticleEmitterFactory*>::iterator ei;
		for (ei = mEmitterFactories.begin(); ei != mEmitterFactories.end(); ++ei)
		{
			PU_DELETE *ei;
		}

		vector<ParticleAffectorFactory*>::iterator ai;
		for (ai = mAffectorFactories.begin(); ai != mAffectorFactories.end(); ++ai)
		{
			PU_DELETE *ai;
		}
		
		vector<ParticleObserverFactory*>::iterator oi;
		for (oi = mObserverFactories.begin(); oi != mObserverFactories.end(); ++oi)
		{
			PU_DELETE *oi;
		}
		
		vector<ParticleEventHandlerFactory*>::iterator ehi;
		for (ehi = mEventHandlerFactories.begin(); ehi != mEventHandlerFactories.end(); ++ehi)
		{
			PU_DELETE *ehi;
		}

		vector<ExternFactory*>::iterator exi;
		for (exi = mExternFactories.begin(); exi != mExternFactories.end(); ++exi)
		{
			PU_DELETE *exi;
		}

		vector<ParticleBehaviourFactory*>::iterator bi;
		for (bi = mBehaviourFactories.begin(); bi != mBehaviourFactories.end(); ++bi)
		{
			PU_DELETE *bi;
		}

#ifdef PU_PHYSICS_PHYSX
		// Delete the PhysXBridge
		PU_DELETE_T(mPhysXBridge, PhysXBridge, MEMCATEGORY_SCENE_CONTROL);
#endif // PU_PHYSICS_PHYSX
	}
	//-----------------------------------------------------------------------
	void RibbonTrailRenderer::_destroyAll(void)
	{
		if (!mParentTechnique)
			return;

		// Remove the listener
		mParentTechnique->removeTechniqueListener(this);
		
		// Detach the Ribbontrail
		if (mChildNode && mTrail && mTrail->isAttached())
		{
			mChildNode->detachObject(mTrail);
		}

		// Delete the Ribbontrail
		Ogre::SceneManager* sceneManager = mParentTechnique->getParentSystem()->getSceneManager();
		if (mTrail && sceneManager && sceneManager->hasRibbonTrail(mRibbonTrailName))
		{
			sceneManager->destroyRibbonTrail(mRibbonTrailName);
			mTrail = 0;
		}

		// Delete the visual data
		vector<RibbonTrailRendererVisualData*>::const_iterator it;
		vector<RibbonTrailRendererVisualData*>::const_iterator itEnd = mAllVisualData.end();
		for (it = mAllVisualData.begin(); it != itEnd; ++it)
		{
			PU_DELETE_T(*it, RibbonTrailRendererVisualData, MEMCATEGORY_SCENE_OBJECTS);
		}

		mAllVisualData.clear();
		mVisualData.clear();

		// Reset the visual data in the pool
		mParentTechnique->initVisualDataInPool();

		// Destroy the children of the childnode, but not the childnode itself, because this gives a delete-order problem
		if (mChildNode)
		{
			mChildNode->removeAndDestroyAllChildren();
		}
	}
	//-----------------------------------------------------------------------
	void BeamRenderer::_destroyAll(void)
	{
		if (!mParentTechnique)
			return;

		// Remove the listener
		mParentTechnique->removeTechniqueListener(this);

		// Detach the billboardchain
		Ogre::SceneNode* parentNode = mParentTechnique->getParentSystem()->getParentSceneNode();
		if (parentNode && mBillboardChain && mBillboardChain->isAttached())
		{
			parentNode->detachObject(mBillboardChain);
		}

		// Delete the BillboardChain
		Ogre::SceneManager* sceneManager = mParentTechnique->getParentSystem()->getSceneManager();
		if (mBillboardChain && sceneManager && sceneManager->hasBillboardChain(mBillboardChainName))
		{
			sceneManager->destroyBillboardChain(mBillboardChainName);
			mBillboardChain = 0;
		}

		// Delete the visual data
		vector<BeamRendererVisualData*>::const_iterator it;
		vector<BeamRendererVisualData*>::const_iterator itEnd = mAllVisualData.end();
		for (it = mAllVisualData.begin(); it != itEnd; ++it)
		{
			PU_DELETE_T(*it, BeamRendererVisualData, MEMCATEGORY_SCENE_OBJECTS);
		}

		mAllVisualData.clear();
		mVisualData.clear();

		// Reset the visual data in the pool
		mParentTechnique->initVisualDataInPool();
	}
	//-----------------------------------------------------------------------
	ParticleEmitter::~ParticleEmitter(void)
	{
		if (mDynEmissionRate)
			PU_DELETE_T(mDynEmissionRate, DynamicAttribute, MEMCATEGORY_SCENE_OBJECTS);

		if (mDynTotalTimeToLive)
			PU_DELETE_T(mDynTotalTimeToLive, DynamicAttribute, MEMCATEGORY_SCENE_OBJECTS);

		if (mDynParticleMass)
			PU_DELETE_T(mDynParticleMass, DynamicAttribute, MEMCATEGORY_SCENE_OBJECTS);

		if (mDynVelocity)
			PU_DELETE_T(mDynVelocity, DynamicAttribute, MEMCATEGORY_SCENE_OBJECTS);

		if (mDynDuration)
			PU_DELETE_T(mDynDuration, DynamicAttribute, MEMCATEGORY_SCENE_OBJECTS);

		if (mDynRepeatDelay)
			PU_DELETE_T(mDynRepeatDelay, DynamicAttribute, MEMCATEGORY_SCENE_OBJECTS);

		if (mDynParticleAllDimensions)
			PU_DELETE_T(mDynParticleAllDimensions, DynamicAttribute, MEMCATEGORY_SCENE_OBJECTS);

		if (mDynParticleWidth)
			PU_DELETE_T(mDynParticleWidth, DynamicAttribute, MEMCATEGORY_SCENE_OBJECTS);

		if (mDynParticleHeight)
			PU_DELETE_T(mDynParticleHeight, DynamicAttribute, MEMCATEGORY_SCENE_OBJECTS);

		if (mDynParticleDepth)
			PU_DELETE_T(mDynParticleDepth, DynamicAttribute, MEMCATEGORY_SCENE_OBJECTS);

		if (mEmissionRateCameraDependency)
			mCameraDependencyFactory.destroy(mEmissionRateCameraDependency);

		if (mDynAngle)
			PU_DELETE_T(mDynAngle, DynamicAttribute, MEMCATEGORY_SCENE_OBJECTS);
	}