/* ***********************************************************************************/
/* * "a3x_glob.h"																	**/
/* * Written by :	Sébastien Rubens												**/
/* * Tabulations :	4 char															**/
/* ***********************************************************************************/
#ifndef A3X_GLOB_H
#define A3X_GLOB_H
 
#include "specif\a3x_pref.h"
/* ***********************************************************************************/
/*                                                                       Main Defines*/
#define	KillChannels
 
/* ***********************************************************************************/
/*                                                                            Defines*/
 
#define	SEB_Invalid	0xFFFF
 
#define	xZero		((SEB_xReal) 0.0)
#define	xOne		((SEB_xReal) 1.0)
#define xHalfOne	((SEB_xReal) 0.5)
 
/*#define	xEps		((SEB_xReal) 0.0001)*/
/*#define	xOneSubEps	((SEB_xReal) 0.9999)*/
#define	xHalfPi		((SEB_xReal) 1.570796326795)
#define	xPi			((SEB_xReal) 3.14159265359)
#define	xTwoPi		((SEB_xReal) 6.28318530718)
 
#define	xExpandValue	((SEB_xReal)3.05185094759971922971282082583e-5)
#define xCompactValue 32767.0f
 
#define	lEps		1
#define	lOne		32767
#define	lOneSubEps	32766
 
#define	lDecSin		3L
#define	lNbSin		8192L				/* Size of sinus table*/
#define	lNbSinDiv2	(lNbSin >> 1)
#define	lNbSinDiv4	(lNbSin >> 2)
#define	lNbSin34	(lNbSinDiv4 * 3)
#define	lMaskNbSin	(lNbSin - 1)
 
 
 
/* ***********************************************************************************/
#define	SEB_xMaskQuatOri		0x0001
#define	SEB_xMaskQuatSca		0x0002
#define	SEB_xMaskScaleValues	0x0004
#define	SEB_xMaskPosition		0x0008
#define	SEB_xMaskAllLow			0x000F
#define	SEB_xMaskIdQuatOri		0x0010
#define	SEB_xMaskIdQuatSca		0x0020
#define	SEB_xMaskIdScaleValues	0x0040
#define	SEB_xMaskLastKey		0x0080
#define	SEB_xMaskZeroAngCentre	0x0100
 
#define	SEB_xTypeWrapLastKey		0x0200
#define	SEB_xTypeChangeOfHierarchy	0x0400
#define	SEB_xTypeHierarchized	0x0800
#define	SEB_xTypeSoundEvent		0x1000
 
 
 
/* ***********************************************************************************/
/*                                                                  Types definitions*/
/* ***********************************************************************************/
 
/* ----------------------------------------------------------------------------------*/
/*                                      Matrices, vectors and quaternions definitions*/
/* ----------------------------------------------------------------------------------*/
typedef SEB_xReal		tdxMatrix33[3][3];
typedef SEB_xReal		tdxVector3[3];
typedef SEB_xReal		tdxQuater4[4];
typedef unsigned long	tdxULongVector3[3];
typedef signed short	tdxSShortQuater4[4];
 
 
typedef char			tdFileName[256];
 
/* ----------------------------------------------------------------------------------*/
/*                                                                   Stack definition*/
/* ----------------------------------------------------------------------------------*/
typedef struct	tdstStackInfos_ {
	unsigned long	ulPosAlloc;
	unsigned long	ulStackPos;
	unsigned long	ulMaxPos;
	unsigned long	ulResetPos;
}	tdstStackInfos;
 
/* ----------------------------------------------------------------------------------*/
/*                                                       Cutted animations definition*/
/* ----------------------------------------------------------------------------------*/
typedef struct	tdstCuttedAnim_ {
	unsigned short	uwStartFrame;
	unsigned short	uwEndFrame;
	unsigned short	uwPrevAnim;
	unsigned short	uwNextAnim;
	unsigned short	uwMaxNumberOfElements;
	unsigned short	uwAlign;
}	tdstCuttedAnim;
 
 
/* ----------------------------------------------------------------------------------*/
/*                                                                               NTTO*/
/* ----------------------------------------------------------------------------------*/
typedef struct	tdstFileNTTO_ {	
#ifndef U64
	unsigned short	uwTypeOfObject;						/* + hierarchized object info !*/
	unsigned short	ucNumberInTable;	/* temporary a short AR9810*/
	unsigned char	ucTransparency;
#else
	unsigned short	uwTypeOfObject;						/* + hierarchized object info !*/
	unsigned char	ucNumberInTable;
	unsigned char	ucTransparency;
#endif
}	tdstFileNTTO;
 
typedef struct	tdstNTTO_ {	
#ifndef U64
	unsigned short	uwTypeOfObject;						/* + hierarchized object info !*/
	unsigned short	ucNumberInTable;	/* temporary a short AR9810*/
	unsigned char	ucTransparency;
#else
	unsigned short	uwTypeOfObject;						/* + hierarchized object info !*/
	unsigned char	ucNumberInTable;
	unsigned char	ucTransparency;
#endif
}	tdstNTTO;
 
/* ----------------------------------------------------------------------------------*/
/*                                                                          Hierarchy*/
/* ----------------------------------------------------------------------------------*/
typedef struct	tdstFileHierarchy_ {
	unsigned short	uwChild;
	unsigned short	uwFather;
}	tdstFileHierarchy;
 
typedef struct	tdstBinHierarchy_ {
	unsigned short	uwChild;
	unsigned short	uwFather;
}	tdstBinHierarchy;
 
typedef struct tdstHierarchy_ {
	unsigned short	uwChild;
	unsigned short	uwFather;
}	tdstHierarchy;
 
/* ----------------------------------------------------------------------------------*/
/*                                                                         Only Frame*/
/* ----------------------------------------------------------------------------------*/
typedef struct	tdstFileOnlyFrame_ {
	unsigned short	uwNumOfAngularSpeedQuat;
	unsigned short	uwNumOfSpeedVector;
 
	unsigned short	uwHierarchyNbCouples;
	unsigned short	uwNumOfHierarchyCouples;
 
	unsigned short	uwNumOfSavedFrame;
	unsigned short	uwAlign;
}	tdstFileOnlyFrame;
 
typedef struct	tdstBinOnlyFrame_ {
	signed long		slNumOfAngularSpeedQuat;
	signed long		slNumOfSpeedVector;
 
	unsigned short	uwHierarchyNbCouples;
	unsigned short	uwNumOfSavedFrame;
 
	signed long		slNumOfHierarchyCouples;
 
	tdxQuater4		tdxAngularSpeedQuat;	/* only for binarisation*/
	tdxVector3		tdxSpeedVector;			/* only for binarisation*/
}	tdstBinOnlyFrame;
 
typedef struct	tdstOnlyFrame_ {
	unsigned short	uwNumOfAngularSpeedQuat;
	unsigned short	uwNumOfSpeedVector;
 
	unsigned short	uwHierarchyNbCouples;
	unsigned short	uwNumOfFirstHierarchyCouple;
 
	unsigned short	uwNumOfSavedFrame;
/*	unsigned short	uwAlign; // AR9811 To save memory...*/
}	tdstOnlyFrame;
 
/* ----------------------------------------------------------------------------------*/
/*                                                                            Channel*/
/* ----------------------------------------------------------------------------------*/
typedef struct	tdstFileChannel_ {
	unsigned short	uwNumberOfKeys;
	unsigned short	uwChannelNumber;
	unsigned short	uwNumOfLocalPivotPos;
	unsigned short	uwAlign;
}	tdstFileChannel;
 
typedef struct	tdstBinChannel_ {
	unsigned short	uwNumberOfKeys;
	unsigned short	uwChannelNumber;
	signed long		slNumOfLocalPivotPos;
 
/*	signed long		slNumOfFrameNTTO;		// in tdstBinFrame*/
	signed long		slNumOfFrames;
/*	signed short	slNumOfKeyFrame;		// in tdstBinFrame*/
 
	unsigned short	uwUsedChannel;			/* only for binarisation*/
	unsigned short	uwGenerateChannel;		/* only for binarisation*/
 
	tdxVector3		a3_xLocalPivotPos;		/* only for binarisation*/
}	tdstBinChannel;
 
typedef struct	tdstChannel_ {
	unsigned short	uwNumberOfKeys;
	unsigned short	uwChannelNumber;
	unsigned short	uwNumOfLocalPivotPos;
 
	unsigned short	uwNumOfFirstFrame;
	unsigned long	ulNumOfFirstFrameKF;
	unsigned short	uwNumOfFirstKeyFrame;
/*	unsigned short	uwAlign; // AR9811 To save memory...*/
}	tdstChannel;
 
/* ----------------------------------------------------------------------------------*/
/*                                                                          Frames KF*/
/* ----------------------------------------------------------------------------------*/
typedef struct	tdstFrameKF_ {
	unsigned short	uwNumOfKeyFrame;
/*	unsigned short	uwAlign; //AR9808 Too much memory lost*/
}	tdstFrameKF;
 
/* ----------------------------------------------------------------------------------*/
/*                                                                              Frame*/
/* ----------------------------------------------------------------------------------*/
typedef struct	tdstFileFrame_ {
/*	signed short	swNumberInTable;*/
/*	unsigned short	uwTypeOfObject;						// + hierarchized object info !*/
	unsigned short	uwNumOfNTTO;
/*	unsigned short	uwAlign; //AR9808 Too much memory lost*/
}	tdstFileFrame;
 
typedef struct	tdstBinFrame_ {
	signed short	swNumberInTable;
	unsigned short	uwTypeOfObject;
	unsigned short	uwFrameNumber;
	unsigned char	ucTransparency;
	unsigned char	ucAlign;
 
	tdxQuater4		a4_xQuatOri;			/* Orientation of quaternion*/
	tdxQuater4		a4_xQuatSca;			/* Orientation of scale*/
	tdxVector3		a3_xScaleValues;		/* Scaling values*/
	tdxVector3		a3_xPosition;			/* Channel position*/
	tdxVector3		a3_xWorldPivotPosition;	/* Pivot position in world axes*/
	SEB_xReal		xDistMaster;
	SEB_xReal		xInterpolationParameter;
	unsigned short	uwMask;					/* Interpolation mask to speed up calculation*/
	unsigned short	uwAttribute;			/* Key attribute*/
	unsigned short	uwChildrenInHierarchy;	/* only for binarisation*/
 
	signed long		slNumOfNTTO;
 
	signed long		slNumOfQuatOri;
	signed long		slNumOfQuatSca;
	signed long		slNumOfScaleValues;
	signed long		slNumOfPosition;
}	tdstBinFrame;
 
typedef struct	tdstFrame_ {
/*	signed short	swNumberInTable;*/
/*	unsigned short	uwTypeOfObject;						// + hierarchized object info !*/
/*	unsigned short	uwNumOfNTTO;*/
 
	unsigned short	uwNumOfNTTO;
/*	unsigned short	uwAlign; //AR9808 Too much memory lost*/
}	tdstFrame;
 
/* ----------------------------------------------------------------------------------*/
/*                                                                          Key Frame*/
/* ----------------------------------------------------------------------------------*/
typedef struct	tdstFileKeyFrame_ {
	unsigned short	uwFrameNumber;
	unsigned short	uwMask;
 
	unsigned short	uwNumOfQuatOri;
	unsigned short	uwNumOfQuatSca;
	unsigned short	uwNumOfScaleValues;
	unsigned short	uwNumOfPosition;
	signed short	swInterpolationParameter;
}	tdstFileKeyFrame;
 
typedef struct	tdstKeyFrame_ {
	tdxVector3		a3_xWorldPivotPosition;
	SEB_xReal		xDistMaster;
 
	unsigned short	uwFrameNumber;
	unsigned short	uwMask;
 
	unsigned short	uwNumOfQuatOri;
	unsigned short	uwNumOfQuatSca;
	unsigned short	uwNumOfScaleValues;
	unsigned short	uwNumOfPosition;
 
	unsigned short	uwAngQuatOri;
	unsigned short	uwAngQuatSca;
	unsigned short	uwAngObjCentre;
	signed short	swInterpolationParameter;
}	tdstKeyFrame;
 
 
/* ----------------------------------------------------------------------------------*/
/*                                                                        A3D General*/
/* ----------------------------------------------------------------------------------*/
typedef struct	tdstFileA3dAnimationGENERAL_ {
	unsigned short	uwAnimationSpeed;
 
	unsigned short	uwNumberOfVectors;
	unsigned short	uwNumberOfQuaternions;
	unsigned short	uwNumberOfHierarchies;
	unsigned short	uwNumberOfSavedNTTO;
	unsigned short	uwNumberOfSavedFrames;
 
	unsigned short	uwNumberOfChannels;
	unsigned short	uwNumberOfFrames;
	unsigned short	uwNumberOfKeyFrames;
	unsigned short	uwNumberOfEvents;
	unsigned short	uwNumOfFirstPosition;
 
	unsigned short	uwStartFrame;
	unsigned short	uwEndFrame;
	unsigned short	uwFakeAnimSpeed;
	unsigned short	uwFlags;
 
	unsigned short	uwNumOfAnimationTranslationOffset;
	unsigned short	uwNumOfAnimationRotationOffset;
 
	unsigned short	uwNumberOfMorphData;
}	tdstFileA3dAnimationGENERAL;
 
/* For fast load (reduced structure)*/
typedef struct	tdstShortA3dGENERAL_
{
	unsigned short		uwNumberOfFrames;
	unsigned short		uwFrameRate;
	unsigned short		uwMaxNumberOfElements;
	unsigned short		uwNumberOfEvents;
	unsigned short		uwNumberOfMorphData;
	unsigned short		uwAlign;
 
	tdxVector3			a3_xAnimationTranslationOffset;
	tdxSShortQuater4	a4_uwAnimationRotationOffset; /* Can be Eliminated... See later*/
}	tdstShortA3dGENERAL;
 
typedef struct	tdstBinA3dAnimationGENERAL_ {
	unsigned short	uwAnimationSpeed;
 
	unsigned short	uwNumberOfSavedVectors;
	unsigned short	uwNumberOfSavedQuaternions;
	unsigned short	uwNumberOfHierarchies;
	unsigned short	uwNumberOfSavedNTTO;
	unsigned short	uwNumberOfSavedFrames;
 
	unsigned short	uwNumberOfChannels;
	unsigned short	uwNumberOfFrames;
	unsigned short	uwNumberOfKeyFrames;
	unsigned short	uwNumberOfEvents;
	unsigned short	uwNumberOfMorphData;
	unsigned short	uwAlign;
 
	unsigned short	uwStartFrame;
	unsigned short	uwEndFrame;
	unsigned short	uwFlags;
	unsigned short	uwFakeAnimSpeed;
 
	signed long		slNumOfAnimationTranslationOffset;
	signed long		slNumOfAnimationRotationOffset;
	signed long		slNumOfPositions;
 
	signed long		slNumOfSavedVectors;
	signed long		slNumOfSavedQuaternions;
	signed long		slNumOfHierarchies;
	signed long		slNumOfSavedNTTO;
	signed long		slNumOfOnlyFrames;
	signed long		slNumOfChannels;
	signed long		slNumOfEvents;
	signed long		slNumOfMorphData;
 
	/* ----------------*/
	signed long		slNumOfFramesNTTO;
 
	/* Before optimisation*/
	unsigned short	uwNumberOfVectors;
	unsigned short	uwNumberOfQuaternions;
	signed long		slNumOfVectors;
	signed long		slNumOfQuaternions;
 
	tdxVector3		uwAnimationTranslationOffset;
	tdxQuater4		uwAnimationRotationOffset;
}	tdstBinA3dAnimationGENERAL;
 
typedef struct	tdstA3dGENERAL_ {
	unsigned short	uwAnimationSpeed;
 
	unsigned short	uwNumberOfVectors;
	unsigned short	uwNumberOfQuaternions;
	unsigned short	uwNumberOfHierarchies;
	unsigned short	uwNumberOfNTTO;
	unsigned short	uwNumberOfSavedFrames;
 
	unsigned short	uwNumberOfChannels;
	unsigned short	uwNumberOfFrames;
	unsigned short	uwNumberOfKeyFrames;
	unsigned short	uwNumberOfEvents;
	unsigned short	uwNumOfFirstPosition;
 
	unsigned short	uwStartFrame;
	unsigned short	uwEndFrame;
	unsigned short	uwFakeAnimSpeed;
	unsigned short	uwFlags;
 
	unsigned short	uwNumOfAnimationTranslationOffset;
	unsigned short	uwNumOfAnimationRotationOffset;
 
	unsigned short	uwNumberOfMorphData;
 
	unsigned short	uwNumOfFirstVector;
	unsigned short	uwNumOfFirstQuaternion;
	unsigned short	uwNumOfFirstHierarchy;
	unsigned short	uwNumOfFirstNTTO;
	
	unsigned short	uwNumOfFirstOnlyFrame;
	unsigned short	uwNumOfFirstChannel;
	unsigned short	uwNumOfFirstEvent;
	unsigned short	uwNumOfFirstMorphData;
 
}	tdstA3dGENERAL;
 
 
/* ----------------------------------------------------------------------------------*/
/*                                                                         Morph Data*/
/* ----------------------------------------------------------------------------------*/
typedef struct tdstFileMorphData_ {
	unsigned char	ucTarget;
	unsigned char	ucMorphingAmount;
	unsigned short	uwChannelNumber;
	unsigned short	uwFrameNumber;
	unsigned short	uwAlign; /* Usefull for storage structures AR9809*/
}	tdstFileMorphData; /*AR9803 Written into binary file*/
 
typedef struct tdstBinMorphData_ {
	unsigned char	ucTarget;
	unsigned char	ucMorphingAmount;
	unsigned short	uwChannelNumber;
	unsigned short	uwFrameNumber;
	unsigned short	uwAlign;
}	tdstBinMorphData; /*AR9803 Filled by scripts*/
 
/* ----------------------------------------------------------------------------------*/
/*																     Event definition*/
/* ----------------------------------------------------------------------------------*/
#define A3i_Version		0x1110	/* 1.17 */
 
/* AR9809 Now, this structure is common (event loaded the same way than PC)*/
 
/* Storage structure*/
typedef struct tdstFileEvent_ {
	unsigned short		usEventNumberInTBL;	
	unsigned short		uwFrameNumber;
	unsigned short      uwChannelNumber;
	unsigned short		uwAlign;
} tdstFileEvent;
 
/* Binarisation structure*/
typedef struct tdstBinEvent_ {
	unsigned short		usEventNumberInTBL;	
	unsigned short		uwFrameNumber;		
	unsigned short      uwChannelNumber;
} tdstBinEvent;
 
/* ***********************************************************************************/
#endif
