/* e_anim.h */

#ifndef __E_ANIM_H
#define __E_ANIM_H


/* Handles all stuff to do with anims and entity managment since they are*/
/* so closely linked together. */

#define ENTITY_MESSAGE_MAJOR_ERROR			0
#define ENTITY_MESSAGE_SYSTEM_STARTUP		1
#define ENTITY_MESSAGE_SYSTEM_CLOSEDOWN	2
#define ENTITY_MESSAGE_INSTANCE_STARTUP	3
#define ENTITY_MESSAGE_INSTANCE_CLOSEDOWN	4
#define ENTITY_MESSAGE_PREFRAME				5
#define ENTITY_MESSAGE_MIDFRAME				6
#define ENTITY_MESSAGE_AFTERFRAME			7
#define ENTITY_MESSAGE_TICKER					8
#define ENTITY_MESSAGE_COLLIDE				9

/* Some menu typedefs and structures */
/* Typedefs a callback function type for the menu */
typedef 	int anim_CALLBACKFN(int event,void *extradata);

/* Structure for a world entity */
/* An entity is anything is the world that might move or animate under strat control */
typedef struct s_E_Entity {	int identifier;		/* numerical identifier */
										char *title;			/* optional textual title */
										p_LinkList linklist;
										int numcallbacks;		/* number of active callbacks */
										anim_CALLBACKFN *anim_callback;	/* pointers to the callbacks */
										int localdata;
										void *p_localdata;
										br_actor *rootactor;	/* root actor pointer for this entity */
										br_matrix34 editpos;
										br_matrix34 worldpos;
										char transform_type;
										int anim_identifier;
										int anim_frame;
										int anim_first_identifier;
										int anim_last_identifier;
										int anim_total_identifiers;
										float morphtime;
										float tweentime;
										char flag_scd_sent;
										char flag_icd_sent;
								} *p_E_Entity;

/* Definitions for the entity structure */
#define ENTITY_TRANSFORM_HIERARCHY	0
#define ENTITY_TRANSFORM_FLAT			1

// Define structures for holding animation data.

// Pointer to actor plus desired transform matrix.

struct ani_transform {
	br_actor       *actor;
	br_matrix34     mat;
};

// All desired actor transforms required for a single frame.

struct ani_frame {
	struct ani_transform *transforms;
	int             ntransforms;
};

typedef struct s_E_Anim {	int identifier;
									char *title;
									int numframes;
									struct ani_frame *frames;
								};

/* Variable externs */
extern p_LinkListHead entity_editing_list;
extern p_LinkListHead entity_level_list;


/* Function externs */
extern void Editor_SetupAnimEnvironment(void);
extern void Entity_Init(void);
extern void Entity_InitForEditor(void);
extern void Entity_InitForGame(void);

extern p_E_Entity Entity_Create(void);
extern int Entity_AddAnimVUE(p_E_Entity /*this*/,char * /*filename*/);
extern int Entity_Add3DSTree(p_E_Entity /*this*/,char * /*filename*/);

extern p_E_Entity Entity_Load(char * /*filename*/);
extern void Entity_Save(char * /*filename*/);
extern void Entity_SetAnimFrame(p_E_Entity /*this*/,int identifier,int frame);
extern void Entity_AddToGameWorld(p_E_Entity /*this*/);
extern void Entity_SendMessageToAll(int /*message*/);
extern void Entity_SendMessageToOne(int /*message*/,	p_E_Entity /*this*/);
extern br_fmt_results *Entity_LoadAModelCollection(p_E_Entity /*this*/,char * /*filename*/);

extern void *Anim_FiniteDifferenceCalculate(br_model * /*source*/,br_model * /*out*/);
extern void *Anim_FiniteDifferenceCalculateStart(br_model * /*source*/);
extern void Anim_FiniteDifferenceStart(br_model *source,void * /*pstart*/);
extern void Anim_FiniteDifferenceMorphTo(br_model * /*source*/,void * /*pstart*/,float /*fraction*/);

#endif
