/*
 * (C) Copyright Ian D. Romanick 2006
 * All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * on the rights to use, copy, modify, merge, publish, distribute, sub
 * license, and/or sell copies of the Software, and to permit persons to whom
 * the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
 * AUTHORS, COPYRIGHT HOLDERS, AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 * USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#ifndef IDR_PARTICLE_H
#define IDR_PARTICLE_H

#include "data.h"
#include "Settings.h"
#include "vector.h"

class idr_particle_system {
 public:
	idr_particle_system(void);
	idr_particle_system(unsigned max_particles, float time_to_live);

	void draw_particles(cbk_object_data_tank PlayerView, PFNGLBINDBUFFERARBPROC bind_buffer);
	bool update_particles(double time_slice);

	float LifeTime;
	cbk_vector Position;
	cbk_object_data_tank *Tank;

	GLuint c_light_id;

	GLuint c_texture_id;

	GLfloat ParticleColor[3];

	void reset_particles(void);

 private:
	// Gravitational effect on the Y position of a particle's velocity.
	float gravity;

	// Initial time to live for a new particle.
	float initial_ttl;

	// Maximum number of active particles at any given instant.
	unsigned max_particles;

	// Number of particles that are actually active.
	unsigned active_particles;

	// Time since previous particle was emitted.
	float last_particle_time;

	// Current position of each particle.  Each position is stored as a 4 element vector.  The 4th element must be 1.0.
	float *positions;

	// Velocity, stored in abstract units per second, for each particle.  Each velocity is stored as a 4 element vector.  The 4th element must be 0.0.
	float *velocities;

	// Time, in seconds, that each particle has left to live.
	float *time_to_live;

	void init_particle(unsigned idx);
};

#endif /* IDR_PARTICLE_H */
