Ejemplo n.º 1
0
	void Group::reallocate(size_t capacity)
	{
		if (capacity > pool.getNbReserved())
		{
			pool.reallocate(capacity);

			Particle::ParticleData* newData = new Particle::ParticleData[pool.getNbReserved()];
			float* newCurrentParams = new float[pool.getNbReserved() * model->getSizeOfParticleCurrentArray()];
			float* newExtendedParams = new float[pool.getNbReserved() * model->getSizeOfParticleExtendedArray()];

			memcpy(newData,particleData,pool.getNbTotal() * sizeof(Particle::ParticleData));
			memcpy(newCurrentParams,particleCurrentParams,pool.getNbTotal() * sizeof(float) * model->getSizeOfParticleCurrentArray());
			memcpy(newExtendedParams,particleExtendedParams,pool.getNbTotal() * sizeof(float) * model->getSizeOfParticleExtendedArray());

			delete[] particleData;
			delete[] particleCurrentParams;
			delete[] particleExtendedParams;

			particleData = newData;
			particleCurrentParams = newCurrentParams;
			particleExtendedParams = newExtendedParams;

			// Destroys all the buffers
			destroyAllBuffers();
		}
	}
Ejemplo n.º 2
0
	void Group::reallocate(size_t capacity)
	{
		if (capacity > pool.getNbReserved())
		{
			pool.reallocate(capacity);

			Particle::ParticleData* newData = new Particle::ParticleData[pool.getNbReserved()];
			float* newCurrentParams = new float[pool.getNbReserved() * model->getSizeOfParticleCurrentArray()];
			float* newExtendedParams = new float[pool.getNbReserved() * model->getSizeOfParticleExtendedArray()];

			std::memcpy(newData,particleData,pool.getNbTotal() * sizeof(Particle::ParticleData));
			std::memcpy(newCurrentParams,particleCurrentParams,pool.getNbTotal() * sizeof(float) * model->getSizeOfParticleCurrentArray());
			std::memcpy(newExtendedParams,particleExtendedParams,pool.getNbTotal() * sizeof(float) * model->getSizeOfParticleExtendedArray());

			delete[] particleData;
			delete[] particleCurrentParams;
			delete[] particleExtendedParams;

			particleData = newData;
			particleCurrentParams = newCurrentParams;
			particleExtendedParams = newExtendedParams;

			for (Pool<Particle>::iterator it = pool.begin(); it != pool.endInactive(); ++it)
			{
				it->group = this;
				it->data = particleData + it->index;
				it->currentParams = particleCurrentParams + it->index * model->getSizeOfParticleCurrentArray();
				it->extendedParams = particleExtendedParams + it->index * model->getSizeOfParticleExtendedArray();
			}

			// Destroys all the buffers
			destroyAllBuffers();
		}
	}
Ejemplo n.º 3
0
	void Group::setModel(Model* newmodel)
	{
		if(!newmodel) newmodel = &getDefaultModel();
		if(model == newmodel) return;

		// empty and change model
		empty();

		decrementChildReference(model);
		incrementChildReference(newmodel);
		model = newmodel;

		// recreate data
		delete[] particleData;
		delete[] particleCurrentParams;
		delete[] particleExtendedParams;

		particleData = new Particle::ParticleData[pool.getNbReserved()];
		particleCurrentParams = new float[pool.getNbReserved() * model->getSizeOfParticleCurrentArray()];
		particleExtendedParams = new float[pool.getNbReserved() * model->getSizeOfParticleExtendedArray()];

		pool.clear();

		// Destroys all the buffers
		destroyAllBuffers();
	}
Ejemplo n.º 4
0
	Group::~Group()
	{
		delete[] particleData;
		delete[] particleCurrentParams;
		delete[] particleExtendedParams;

		// destroys additional buffers
		destroyAllBuffers();
	}