/**********************************************************************

	Title :			Particle Module header 
	Filename :		particle.h
	Author :		Thomas Szirtes
	Revision :		1.0

	Notes :			Particle System module - contains generators,
					graphics, animation and forces

	Copyright :		(C) SEGA Europe 1998

  **********************************************************************/

#ifndef	PARTICLE_H_INC
#define PARTICLE_H_INC

/*
 *		Definitions
 */

#define	PG_FLAG_ALPHA		0x0001
#define	PG_FLAG_TEXLOADED	0x8000
#define	PG_FLAG_SIZE		0x0002
#define	PG_FLAG_TABLE		0x4000
#define PG_FLAG_AUTO		0x0000
#define	PG_FLAG_RELATIVE	0x0004
#define	PG_FLAG_ABSOLUTE	0x0000

/*
 *		Structure Definitions
 */

/* animation table entry */
typedef struct {
	NJS_ARGB	argb;			/* alter color */
	Float		size;			/* size */
	Uint16		animi;			/* animation index number */
} PGTABLE;

/* description of graphic parameters */
typedef struct {
	float		bsize;
	float		dsize;
	NJS_ARGB	bcolor;			/* birth colour */
	NJS_ARGB	dcolor;			/* death colour */

	float		size_step;		/* calculated */
	NJS_ARGB	color_step;		/* calculated */
} PGAUTO;



/* setup for graphics */
typedef struct {
	NJS_TEXLIST	*texlist;		/* pointer to texanim list */
	NJS_TEXANIM	*texanim;		/* pointer to texture list */
	Uint8		*animtab;		/* number of anims , 0=none */
	float		size;
	Uint16		flags;			/* flags to indicate that textures are loaded */
	void		*pchg;			/* manual - table, auto - datastruc */
} PGRAPHIC;


/* GENERIC STRUCTURES */

/* description of forces */
typedef struct pforce {
	float			elv;			/* spherical direction */
	float			azi;
	float			speed;			/* wind speed */
	NJS_VECTOR		vel;			/* calculation velocity (internal use only) */
	void			*callback;		/* callback routine *not implemented yet* - for dynamic wind changes */
	struct pforce	*next;			/* next force in list, NULL if none */
} PFORCE;

/* Instance of particle */
typedef struct {
	NJS_VECTOR	pos;			/* current position of particle */
	NJS_VECTOR	vel;			/* directional velocity of particle */
	Uint16		age;			/* -age of particle (in frames) */
} PARTICLE;

/* Generator memory */
typedef struct {
	float		rseed;			/* random seed */
	Uint16		frame;			/* frame count */
	PARTICLE	*p;				/* pointer to particle ring buffer */
	Uint16		listsize;		/* number of particles in ring buffer */
	Uint16		pfront;			/* front index of ring buffer */
} PGENERATOR;

/* Particle system description  */
typedef struct {
	float		random;			/* amount of random factor to add */
	NJS_VECTOR	pos;			/* desired position of generator */
	float		azi;
	float		elv;			/* decided to use spherical coordinates - makes randomizing easier */
	float		speed;
	float		weight;			/* set to zero for weightless calculation */
	Sint16		rate;			/* rate of generation */
	Uint16		lifespan;		/* lifespan of particles */
	Uint16		maxparticle;	/* maxnumber of particles allowed */
	PGENERATOR	*pg;			/* * generated by code * pointer to particle generator */
	PGRAPHIC	*pgfx;
	PFORCE		*force;			/* pointer to force */
} PSYSTEM;

/* A database of particle systems/generators */
typedef	struct {
	int			numitems;
	PSYSTEM		**systems;
	} PDATABASE;

/*
 *		Function Prototypes
 */

/*--------------------------------------------------------------------------

  void PARTICLE_Kill( PSYSTEM *ps )

  Parameters:
	ps		pointer to particle system 
 
  Returns:
 
  Notes:
	Kills system
 
  --------------------------------------------------------------------------*/
void PARTICLE_Kill( PSYSTEM * );

/*--------------------------------------------------------------------------

  void PARTICLE_Update( PGENERATOR *pg )
 
  Parameters:
	pg		pointer to particle generator 
 
  Returns:
 
  Notes:
	Updates all live particles belonging to generator
 
  --------------------------------------------------------------------------*/
void PARTICLE_Update( PSYSTEM * );

/*--------------------------------------------------------------------------

  void PARTICLE_Generator( PSYSTEM *ps )
 
  Parameters:
 	ps		pointer to particle system
 
  Returns:
 
  Notes:
	Generates new particles from specified generator
 
  --------------------------------------------------------------------------*/
void PARTICLE_Generator( PSYSTEM * );

/*--------------------------------------------------------------------------

  void PARTICLE_Create( PSYSTEM *ps )
 
  Parameters:
 	ps		pointer to particle system
 
  Returns:

  Notes:
 	Initializes particle system
 
  --------------------------------------------------------------------------*/
void PARTICLE_Create( PSYSTEM * );

/*--------------------------------------------------------------------------

  void PARTICLE_MoveGenerator( PSYSTEM *ps )
 
  Parameters:
 	ps		pointer to particle system
 
  Returns:
 
  Notes:
	Moves generator to desired position
 
  --------------------------------------------------------------------------*/
void PARTICLE_MoveGenerator( PSYSTEM *, NJS_VECTOR );


/*--------------------------------------------------------------------------

  void PDATABASE_AnalysisMap( void )

  Parameters:
 
  Returns:
 
  Notes:
	Counts up all smoke generators - which are basically a special case of
	a building
  
  --------------------------------------------------------------------------*/
void	PDATABASE_AnalysisMap( PDATABASE * );


/*--------------------------------------------------------------------------

  void	PDATABASE_Kill	(void)

  Parameters:
 
  Returns:
 
  Notes:

  --------------------------------------------------------------------------*/

void	PDATABASE_Kill	( PDATABASE * );
#endif 