<commit_before>#include "stdafx.h"
#include "ParticleSystem.h"
#include "Particle.h"
#include "BaseFrame.h"
#include "Frames.h"
#include "ParticleData.h"

#include "GLTexture.h"
#include "TextureCache.h"
#include "GLParticleProgram.h"
#include "VoxEngine.h"

ParticleSystem::ParticleSystem(ParticleData particleSystemDescription,double now, double lifetime) {
	this->particleSystemDescription = particleSystemDescription;
	this->creationTime = now;
	if (lifetime < 0)
		deathAt = -1;
	else
		deathAt = creationTime+lifetime;
	nextParticle = 0;
}
ParticleSystem::~ParticleSystem() {
	particleList.clear();
}

//Update the particle emitter spawning particles
bool ParticleSystem::UpdateEmitter() {
	//Adjust the time so it's relative to you
	double now = Game()->Now();
	double systemTime = now-creationTime;
	float systemLifeFactor = (float)(systemTime/(deathAt-creationTime));
	if (deathAt < 0)
		systemLifeFactor = 1;
	
	//A negative death time indicates infinite life
	if ((deathAt < 0) || (deathAt > now)) {
		if (nextParticle == 0)
			nextParticle = systemTime;

		//Generate as many new particles as are necessary to catch up
		float generationRate = particleSystemDescription.GenerationRate.ValueAtSequence(systemLifeFactor);
		//Scale generation rate with particle system options
		//generation rate goes from 25% to 100%
		generationRate *= (VoxEngine::GlobalSavedData.GameOptions.ParticleQuality*.75f+.25f);
		//Check if it's time to spawn a new particle
		double perParticle = 1.0f/generationRate;
		while (nextParticle < systemTime) {
			nextParticle += perParticle;
			particleList.push_back(Particle(now,systemLifeFactor,this,&particleSystemDescription));
		}
	}
	else {
		//Time for death, stop generating particles, when all the particles are gone
		//request your own destruction
		if (particleList.size() <= 0)
			return true;
	}

	//Update all the particles
	for (auto it = particleList.begin(); it != particleList.end();) {
		Particle & p = *it;
		if (p.Update(now)) {
			//The particle requested death, cleanup
			it = particleList.erase(it);
		}
		else
			it++;
	}

	//Keep on living
	return false;
}

//Handle particle system material and draw style now
void ParticleSystem::Draw(ParticleRenderer * renderer, GLParticleProgram * shader, vec3 cameraZAxis) {
	//Enforce the selected material
	switch(particleSystemDescription.MaterialStyle) {
	case ParticleData::NONE:
		glDepthMask(GL_TRUE);
		glDisable (GL_BLEND);
		break;
	case ParticleData::ADDITIVE:
		glDepthMask(GL_FALSE);
		glEnable(GL_BLEND);
		glBlendFunc(GL_ONE, GL_ONE);
		break;
	case ParticleData::BLEND:
		glDepthMask(GL_FALSE);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		break;
	case ParticleData::SCREEN:
		glDepthMask(GL_FALSE);
		glEnable(GL_BLEND);
		glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR);
		break;
	}
	//Sort if necessary
	if (particleSystemDescription.MaterialStyle == ParticleData::BLEND) {
		particleList.sort([cameraZAxis](Particle & a, Particle & b) {
			return glm::dot(a.Position, cameraZAxis) < glm::dot(b.Position, cameraZAxis);
		});
	}
	<commit_msg>Apple compile issue fixed<commit_after>#include "stdafx.h"
#include "ParticleSystem.h"
#include "Particle.h"
#include "BaseFrame.h"
#include "Frames.h"
#include "ParticleData.h"

#include "GLTexture.h"
#include "TextureCache.h"
#include "GLParticleProgram.h"
#include "VoxEngine.h"

ParticleSystem::ParticleSystem(ParticleData particleSystemDescription,double now, double lifetime) {
	this->particleSystemDescription = particleSystemDescription;
	this->creationTime = now;
	if (lifetime < 0)
		deathAt = -1;
	else
		deathAt = creationTime+lifetime;
	nextParticle = 0;
}
ParticleSystem::~ParticleSystem() {
	particleList.clear();
}

//Update the particle emitter spawning particles
bool ParticleSystem::UpdateEmitter() {
	//Adjust the time so it's relative to you
	double now = Game()->Now();
	double systemTime = now-creationTime;
	float systemLifeFactor = (float)(systemTime/(deathAt-creationTime));
	if (deathAt < 0)
		systemLifeFactor = 1;
	
	//A negative death time indicates infinite life
	if ((deathAt < 0) || (deathAt > now)) {
		if (nextParticle == 0)
			nextParticle = systemTime;

		//Generate as many new particles as are necessary to catch up
		float generationRate = particleSystemDescription.GenerationRate.ValueAtSequence(systemLifeFactor);
		//Scale generation rate with particle system options
		//generation rate goes from 25% to 100%
		generationRate *= (VoxEngine::GlobalSavedData.GameOptions.ParticleQuality*.75f+.25f);
		//Check if it's time to spawn a new particle
		double perParticle = 1.0f/generationRate;
		while (nextParticle < systemTime) {
			nextParticle += perParticle;
			particleList.push_back(Particle(now,systemLifeFactor,this,&particleSystemDescription));
		}
	}
	else {
		//Time for death, stop generating particles, when all the particles are gone
		//request your own destruction
		if (particleList.size() <= 0)
			return true;
	}

	//Update all the particles
	for (auto it = particleList.begin(); it != particleList.end();) {
		Particle & p = *it;
		if (p.Update(now)) {
			//The particle requested death, cleanup
			it = particleList.erase(it);
		}
		else
			it++;
	}

	//Keep on living
	return false;
}

//Handle particle system material and draw style now
void ParticleSystem::Draw(ParticleRenderer * renderer, GLParticleProgram * shader, vec3 cameraZAxis) {
	//Enforce the selected material
	switch(particleSystemDescription.MaterialStyle) {
	case ParticleData::NONE:
		glDepthMask(GL_TRUE);
		glDisable (GL_BLEND);
		break;
	case ParticleData::ADDITIVE:
		glDepthMask(GL_FALSE);
		glEnable(GL_BLEND);
		glBlendFunc(GL_ONE, GL_ONE);
		break;
	case ParticleData::BLEND:
		glDepthMask(GL_FALSE);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		break;
	case ParticleData::SCREEN:
		glDepthMask(GL_FALSE);
		glEnable(GL_BLEND);
		glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR);
		break;
	}
	//Sort if necessary
	if (particleSystemDescription.MaterialStyle == ParticleData::BLEND)
    {
		particleList.sort([cameraZAxis](const Particle & a, const Particle & b)
        {
			return glm::dot(a.Position, cameraZAxis) < glm::dot(b.Position, cameraZAxis);
		});
	}
	
{'fraction_non_alphanumeric': 0.11446945337620579, 'fraction_numerical': 0.006430868167202572, 'mean_word_length': 4.9817307692307695, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3690877', 'n_tokens_mistral': 2209, 'n_tokens_neox': 2010, 'n_words': 503}