/******************************************************************************************
	CRTEST PS   (c) 1999-2001 ISL

	fx.h			- Particle systems and other type of groovy FX
******************************************************************************************/


#ifndef __FX_H__
#define __FX_H__

#include "global.h"



// ========
// ==== Definition of a particle in a particle system
// ========
typedef struct
{
	long lifeTime;						// How long the particle will last
	long age;							// The current age of the particle
	int bornX, bornY, bornZ;			// Where the particle was born
	int posX, posY, posZ;				// The position of the particle
	int bornVelX, bornVelY, bornVelZ;	// The velocity the particle was born at
	int velX, velY, velZ;				// The current velocity of the particle
	int colour;							// CPW: particle colour
	int dead;
}FX_PARTICLE;


#define PARTICLE_CHILD				1		// The particles position is based of the pos of the system
#define PARTICLE_REINCARNATION		2		// The particle is re-born when it dies
#define PARTICLE_ANIMATE			4		// Use an array of pointers to texture of animating
#define PARTICLE_GRAVITY			8		// The particles Y velocity is affected by gravity
#define PARTICLE_CUSTOM_GENERATE	16
#define PARTICLE_CUSTOM_UPDATE		32
#define PARTICLE_CUSTOM_DRAW		64
#define PARTICLE_ADDITIVE			128		// CPW: use +ve alpha thingy instead of colour key
#define PARTICLE_RAINBOW			256		// CPW: rainbow stuff
#define PARTICLE_SPHERICAL			512
#define PARTICLE_RANDOMLIFE			1024

typedef int (*PARTICLE_GENERATE_PROC)(void * particleSys, int xzRange, int yVelocity);
typedef int (*PARTICLE_UPDATE_PROC)(void *);
typedef int (*PARTICLE_DRAW_PROC)(void *);


// ========
// ==== Definition of the particle system
// ========
typedef struct
{
	int numParticles;				// The number of particles in the particle system
	int originX, originY, originZ;	// The center of the particle system
	int maxLife;
	int flags;						// Flags for controlling the behaviour of the particle system
	short spriteScale;				// Default is 256 (== scale of 1)

	TextureType *particleTexture;	// The texture to use for the particles
	TextureType **texturePtrArray;	// Used for particle systems with different sprites at different ages
	int numTextures;				// Number of texture in the array
	int numDead;	

	FX_PARTICLE *particles;			// Array of particles

	PARTICLE_GENERATE_PROC customGenerate;
	PARTICLE_UPDATE_PROC   customUpdate;
	PARTICLE_DRAW_PROC     customDraw;

} FX_PARTICLE_SYS;




// ========
// ==== Global particle system function defs.
// ========
int particleSys_Init(FX_PARTICLE_SYS *partSys, int num, int type, int maxLife, TextureType *particleTexture);
int particleSys_Destroy(FX_PARTICLE_SYS *partSys);

int particleSys_Generate(FX_PARTICLE_SYS *partSys, int xzRange, int yVelocity);
int particleSys_Update(FX_PARTICLE_SYS *partSys);
int particleSys_Draw(FX_PARTICLE_SYS *partSys);



#endif 