#include "Cpart_emitter.h"

Cpart_emitter::Cpart_emitter(void)
{
}

Cpart_emitter::Cpart_emitter(int max_particles)
{
	m_part_vec.clear();
	m_max_part = max_particles;
	m_current_part_count = 0;

	light=false;

}

bool Cpart_emitter::add_particle(Cparticle* particle)
{
	if (m_current_part_count<m_max_part)
	{
		m_part_vec.push_back(particle);
		m_current_part_count++;
		return true;
	} else return false;
}

void Cpart_emitter::update()
{
	/*
	std::vector<Cparticle*>::iterator it (m_part_vec.begin());

	int index=0;
	while (it != m_part_vec.end())
	{
			//update each object
		m_part_vec[index]->update();
		
		if (m_part_vec[index]->is_dead)
		{
			//remove particle from list
			m_part_vec.erase(it);
			m_current_part_count--;
		}else
		{
			//draw this particle
			m_part_vec[index]->render();

		}

		index++;
		it++;

	}
	*/
	light = false;
	for (unsigned int i = 0; i<m_part_vec.size(); i++)
	{
		
		m_part_vec[i]->update();
		if (!m_part_vec[i]->is_dead)
		{
			light = true;
			m_part_vec[i]->render();

		}
	}



}

void Cpart_emitter::clear_vec (void)
{
	m_part_vec.clear();
	m_current_part_count = 0;
}

int Cpart_emitter::get_curr_part_count()
{
	return m_current_part_count;
}


Cpart_emitter::~Cpart_emitter(void)
{
	m_part_vec.clear();
}
