Exemplo n.º 1
0
	void Group::pushParticle(std::vector<EmitterData>::iterator& emitterIt,unsigned int& nbManualBorn)
	{
		Particle* ptr = pool.makeActive();
		if (ptr == NULL)
		{
			if (pool.getNbEmpty() > 0)
			{
				Particle p(this,pool.getNbActive());
				launchParticle(p,emitterIt,nbManualBorn);
				pool.pushActive(p);
			}
			else if (nbManualBorn > 0)
				popNextManualAdding(nbManualBorn);
		}
		else
		{
			ptr->init();
			launchParticle(*ptr,emitterIt,nbManualBorn);
		}
	}
Exemplo n.º 2
0
void Group::pushParticle(EmitterData* &emitterIt, uint32& nbManualBorn)
{
	Particle* ptr = pool.makeActive();
	if( ptr == NULL )
	{
		if(pool.getSizeOfEmpty() > 0)
		{
			Particle p(this, pool.getSizeOfActive());
			launchParticle(p, emitterIt, nbManualBorn);
			pool.pushActive(p);
		}
		else if(nbManualBorn > 0)
			popNextManualAdding(nbManualBorn);
	}
	else
	{
		ptr->init();
		launchParticle(*ptr, emitterIt, nbManualBorn);
	}
}
Exemplo n.º 3
0
	bool Group::update(float deltaTime)
	{
		unsigned int nbManualBorn = nbBufferedParticles;
		unsigned int nbAutoBorn = 0;

		bool hasActiveEmitters = false;	

		// Updates emitters
		activeEmitters.clear();
		std::vector<Emitter*>::const_iterator endIt = emitters.end();
		for (std::vector<Emitter*>::const_iterator it = emitters.begin(); it != endIt; ++it)
		{
			if ((*it)->isActive())
			{
				int nb = (*it)->updateNumber(deltaTime);
				if (nb > 0)
				{
					EmitterData data = {*it,nb};
					activeEmitters.push_back(data);
					nbAutoBorn += nb;
				}
			}

			hasActiveEmitters |= !((*it)->isSleeping());
		}
		std::vector<EmitterData>::iterator emitterIt = activeEmitters.begin();

		unsigned int nbBorn = nbAutoBorn + nbManualBorn;

		// Inits bounding box
		if (boundingBoxEnabled)
		{
			const float maxFloat = std::numeric_limits<float>::max();
			AABBMin.set(maxFloat,maxFloat,maxFloat);
			AABBMax.set(-maxFloat,-maxFloat,-maxFloat);
		}

		// Prepare modifiers for processing
		activeModifiers.clear();
		for (std::vector<Modifier*>::iterator it = modifiers.begin(); it != modifiers.end(); ++it)
		{
			(*it)->beginProcess(*this);
			if ((*it)->isActive())
				activeModifiers.push_back(*it);
		}

		// Updates particles
		for (size_t i = 0; i < pool.getNbActive(); ++i)
		{
			if ((pool[i].update(deltaTime))||((fupdate != NULL)&&((*fupdate)(pool[i],deltaTime))))
			{
				if (fdeath != NULL)
					(*fdeath)(pool[i]);

				if (nbBorn > 0)
				{
					pool[i].init();
					launchParticle(pool[i],emitterIt,nbManualBorn);
					--nbBorn;
				}
				else
				{
					particleData[i].sqrDist = 0.0f;
					pool.makeInactive(i);
					--i;
				}
			}
			else
			{
				if (boundingBoxEnabled)
					updateAABB(pool[i]);

				if (distanceComputationEnabled)
					pool[i].computeSqrDist();
			}
		}

		// Terminates modifiers processing
		for (std::vector<Modifier*>::iterator it = modifiers.begin(); it != modifiers.end(); ++it)
			(*it)->endProcess(*this);

		// Emits new particles if some left
		for (int i = nbBorn; i > 0; --i)
			pushParticle(emitterIt,nbManualBorn);

		// Sorts particles if enabled
		if ((sortingEnabled)&&(pool.getNbActive() > 1))
			sortParticles(0,pool.getNbActive() - 1);

		if ((!boundingBoxEnabled)||(pool.getNbActive() == 0))
		{
			AABBMin.set(0.0f,0.0f,0.0f);
			AABBMax.set(0.0f,0.0f,0.0f);
		}

		return (hasActiveEmitters)||(pool.getNbActive() > 0);
	}
Exemplo n.º 4
0
bool Group::update(float deltaTimeInSeconds)
{
	uint32 nbManualBorn = NumOfBufferedParticles;
	uint32 nbAutoBorn = 0;

	bool hasActiveEmitters = false;

	// Updates emitters
	activeEmitters.clear();

	Emitter** endIt = emitters.end();
	for( Emitter** it = emitters.begin(); it < endIt; ++it )
	{
		if( (*it)->isActive() )
		{
			uint32 nb = (*it)->updateNumber(deltaTimeInSeconds);
			if( nb > 0 )
			{
				EmitterData data = {*it, nb};
				activeEmitters.add(data);
				nbAutoBorn += nb;
			}
		}

		hasActiveEmitters |= !((*it)->isSleeping());
	}

	EmitterData* emitterIt = activeEmitters.begin();

	uint32 nbBorn = nbAutoBorn + nbManualBorn;

	// Inits bounding box
	if(boundingBoxEnabled)
	{
		boundingBoxAABB.vcMin.Set(0, 0, 0);
		boundingBoxAABB.vcMax.Set(0, 0, 0);
		boundingBoxAABB.vcCenter.Set(0, 0, 0);
	}

	// Prepare modifiers for processing
	activeModifiers.clear();
	for( Modifier** it = modifiers.begin(); it < modifiers.end(); ++it )
	{
		(*it)->beginProcess(*this);
		if( (*it)->isActive() )
			activeModifiers.add(*it);
	}

	// Updates particles
	for( uint32 i = 0; i < pool.getSizeOfActive(); ++i )
	{
		if( pool[i].update(deltaTimeInSeconds) || ((fupdate != NULL) && ((*fupdate)(pool[i], deltaTimeInSeconds))) )
		{
			if( fdeath != NULL )
				(*fdeath)(pool[i]);

			if( nbBorn > 0 )
			{
				pool[i].init();
				launchParticle(pool[i], emitterIt, nbManualBorn);
				--nbBorn;
			}
			else
			{
				particleData[i].sqrDist = 0.0f;
				pool.makeInactive(i);
				--i;
			}
		}
		else
		{
			if( boundingBoxEnabled )
				updateAABB(pool[i]);

			if( distanceComputationEnabled )
				pool[i].computeSqrDist();
		}
	}

	// Terminates modifiers processing
	for( Modifier** it = modifiers.begin(); it < modifiers.end(); ++it )
		(*it)->endProcess(*this);

	// Emits new particles if some left
	for( uint32 i = nbBorn; i > 0; --i )
		pushParticle(emitterIt, nbManualBorn);

	// Sorts particles if enabled
	if( sortingEnabled && (pool.getSizeOfActive() > 1) )
		sortParticles(0, pool.getSizeOfActive() - 1);

	if( !boundingBoxEnabled || (pool.getSizeOfActive() == 0) )
	{
		boundingBoxAABB.vcMin.Set(0, 0, 0);
		boundingBoxAABB.vcMax.Set(0, 0, 0);
		boundingBoxAABB.vcCenter.Set(0, 0, 0);
	}

	return hasActiveEmitters || (pool.getSizeOfActive() > 0);
}