/*
	Ninja Library
	
	COPYRIGHT (C) SEGA ENTERSRISES,LTD.
*/

#ifndef _NINJA_API2_H_
#define _NINJA_API2_H_

void	njInitGlobal(void);
void	njInitContext( KMVERTEXCONTEXT *context );
void	njInitModContext(void);
void	njSetCurrentContext( int ctx );
void	njZBufferMode( Int mode );
void    njSetIntensityColor( NJS_ARGB *base, NJS_ARGB *offset );
void	njSetColorMode( Uint32 mode );
Uint32	njGetColorMode( void );

void	njInitPrint(void);
void	njInitSprite( void );
void	njInitShadow( void );

/************************/
/*	 Model Funcion		*/
/************************/
void	njDrawModelSub( NJS_MODEL *model );
void	njDrawObjectSub( NJS_OBJECT *obj );
void	njFastDrawModelSub( NJS_MODEL *model );
void	njFastDrawObjectSub( NJS_OBJECT *obj );
void	njSimpleDrawModelSub( NJS_MODEL *model );
void	njSimpleDrawObjectSub( NJS_OBJECT *obj );
void	njShadowModelSub( NJS_MODEL *model );
void	njShadowObjectSub( NJS_OBJECT *obj );
void	njSetModel( NJS_MODEL *model );
void	njResetModel( void );
void	njSetMeshMaterial( NJS_MESHSET	*mesh );
void	njDrawMesh( NJS_MESHSET *mesh );

void	njDrawModelSub2( NJS_MODEL *model );
void	njDrawObjectSub2( NJS_OBJECT *obj );
void	njFastDrawModelSub2( NJS_MODEL *model );
void	njFastDrawObjectSub2( NJS_OBJECT *obj );
void	njSimpleDrawModelSub2( NJS_MODEL *model );
void	njSimpleDrawObjectSub2( NJS_OBJECT *obj );

/************************/
/*	 Motion Funcion		*/
/************************/
void njMotionIntTranslate( NJS_OBJECT *obj );
void njMotionIntScale( NJS_OBJECT *obj );
void njMotionIntRotateXYZ( NJS_OBJECT *obj );
void njMotionIntRotateZXY( NJS_OBJECT *obj );
void njMotionObjTranslate( NJS_OBJECT *obj );
void njMotionObjRotateXYZ( NJS_OBJECT *obj );
void njMotionObjRotateZXY( NJS_OBJECT *obj );
void njMotionObjScale( NJS_OBJECT *obj );

void njMotionIntTranslateData( NJS_OBJECT *obj );
void njMotionIntScaleData( NJS_OBJECT *obj );
void njMotionIntRotateData( NJS_OBJECT *obj );
void njMotionObjTranslateData( NJS_OBJECT *obj );
void njMotionObjRotateData( NJS_OBJECT *obj );
void njMotionObjScaleData( NJS_OBJECT *obj );
void njMakeMotionLink( void );
void njMakeShapeLink( NJS_OBJECT *obj );

/************************/
/*	 Light Funcion		*/
/************************/
void	njCalculateLightsRGB(NJS_ARGB[2], NJS_POINT3*, NJS_VECTOR*, Int);
void	njCalculateLightsRGBVertex(NJS_ARGB[2], NJS_POINT3*, NJS_VECTOR*, Int);
void	njCalculateLightsRGBPacked(Uint32[2], NJS_POINT3*, NJS_VECTOR*, Int);
void	njCalculateLightsRGBPackedVertex(Uint32[2], NJS_POINT3*, NJS_VECTOR*, Int);
void	njCalcLightMaterials(void);
void	njSetLightQueue(void);
void	njSetQueue(void);

void	njCalculateLightsIntensity(Float[2], NJS_POINT3*, NJS_VECTOR*, Int);
void	njCalculateLightsIntensityVertex(Float[2], NJS_POINT3*, NJS_VECTOR*, Int);
void	njCalcLightMaterials2(void);
void	njSetLightQueue2(void);
void	njSetQueue2(void);

void	njCalcLightMatrices(void);
void	njLightSystemInit(void);
void	njResetQueue(void);
void	njSetLightMaterials(void);
void	njSetLightSystem(void);
void	njGetLightDistance(NJS_POINT3*);

void	njSetLightDirection2(NJS_LIGHT_PTR, Angle, Angle, Angle);

/************************/
/*	 Texture Funcion	*/
/************************/
char *strupr( char *string );

/* njTexFile.c */
Sint32 njTexFopen(const char* filename);
void njTexFclose(void);
void njTexFread(void* buf,Uint32 size);
void njTexFseek(Uint32 size,Uint32 type);
Uint8 *njTexFtell(void);
void njTexFSet(Uint8 *ptr);
void njTexChangeFBuffer(Uint32 size);

/* njTexture.c */
void *njMallocTextureBuffer(Uint32 nbytes);
void njFreeTextureBuffer(Uint32 nbytes);
void *njCacheTextureMalloc(unsigned size);
void njCacheTextureFree(void *block);

/* njTexBmp.c */
Sint32 njLoadBmp(NJS_TEXINFO* info,Uint32 attr);
Sint32 njGetSurfaceBmp(NJS_TEXINFO* info,Uint32 attr);
Sint32 njGetInfoBmp(NJS_TEXINFO* info,Uint32 attr);

/* njTexTga.c */
Sint32 njLoadTga(NJS_TEXINFO* info,Uint32 attr);
Sint32 njGetSurfaceTga(NJS_TEXINFO* info,Uint32 attr);
Sint32 njGetInfoTga(NJS_TEXINFO* info,Uint32 attr);

/* njTexPvr.c */
Sint32 njLoadPvr(NJS_TEXINFO* info,Uint32 attr);
Sint32 njGetSurfacePvr(NJS_TEXINFO* info,Uint32 attr);
Sint32 njGetInfoPvr(NJS_TEXINFO* info,Uint32 attr);

/* njTexinner.c */
Sint32 njTexDownloadMipMap(void* addr,NJS_TEXINFO *info);
Sint32 njTexDownloadCache(void *addr,NJS_TEXINFO *info);
void   njTwiddle(Uint16 *dst,Uint16* src,Sint32 size);
Sint32 njCheckFileName(char* namedst,const char* namesrc);
Uint32 njGetFileGlobalIndex(NJS_TEXNAME *texname);

/* njTexLoad.c */
void *njTextureMalloc(NJS_TEXSURFACE *texsurface);
Sint32 njSetTexInfo(Sint32* nTextureType,Sint32 nWidth,Sint32 nHeight,Sint32 bit,Sint32 cn);
Sint32 njCreateTextureSurface(NJS_TEXSURFACE *texsurface,Sint32 nWidth,Sint32 nHeight,Sint32 nTextureType);
Sint32  njLoadTexMemFromFile(NJS_TEXNAME *texname,NJS_TEXINFO *info);
Sint32 njLoadCacheFromFile(NJS_TEXNAME *texname,NJS_TEXINFO *info);
Sint32 njLoadTexMemFromMemory(NJS_TEXNAME *texname,NJS_TEXINFO *info);
Sint32 njLoadTexMemFromCache(NJS_TEXNAME *texname,NJS_TEXINFO *info);
Sint32 njGetInfoMemory(NJS_TEXINFO* info);

/* njTexList.c */
void   njInitTexMemList(NJS_TEXMEMLIST *addr,Uint32 size);
void   njEntryTexMemList(Uint32 *texname_addr,NJS_TEXINFO *info,Uint32 globalIndex,Uint32 type);
void   njFreeTexMemList(NJS_TEXMEMLIST *texmladdr);
NJS_TEXINFO *njTexMemList(Uint32 globalIndex);

Sint32 njSearchTexList(NJS_TEXMEMLIST *texmemlist,Uint32 size,Uint32 globalIndex);
Sint32 njSearchTexList2(NJS_TEXMEMLIST *texmemlist_st,Uint32 size,NJS_TEXMEMLIST *texmemlist);

/* njSetTextureParam.c */
void njSetTextureParam(NJS_TEXMEMLIST *texmemlist);

/************************/
/*	 Debug Font Funcion	*/
/************************/
void njCharacter(Sint16 x,Sint16 y,Sint8 ch);

/************************/
/*	 3DDraw Funcion		*/
/************************/
int njNearClippingLine(NJS_POINT3COL *p, NJS_POINT3COL *cp, Uint32 attr);
int njFarClipping(NJS_POINT3COL *p, Int n);
#if 0
void njtri_filled(Int num, NJS_POINT3COL *vertex);
void njtri_filled_with_tex(Int num, NJS_POINT3COL *vertex);
void njtri_wired(Int num, NJS_POINT3COL *vertex);
void njtri_wiredpoly(Int num, NJS_POINT3COL *vertex);
void njtri_wiredpoly_with_tex(Int num, NJS_POINT3COL *vertex);
#else
void njtri_filled(Int num, NJS_POINT3COL *vertex,Float **pSQ);
void njtri_filled_with_tex(Int num, NJS_POINT3COL *vertex,Float **pSQ);
void njtri_wired(Int num, NJS_POINT3COL *vertex,Float **pSQ);
void njtri_wiredpoly(Int num, NJS_POINT3COL *vertex,Float **pSQ);
void njtri_wiredpoly_with_tex(Int num, NJS_POINT3COL *vertex,Float **pSQ);
#endif

/************************/
/*	 Collision Funcion  */
/************************/
_inline void njGetBoxMinMax(NJS_BOX *hull, NJS_POINT3 *min, NJS_POINT3 *max);
_inline void njGetSphereMinMax(NJS_SPHERE *hull, NJS_POINT3 *min, NJS_POINT3 *max);
_inline void njGetCapsuleMinMax(NJS_CAPSULE *hull, NJS_POINT3 *min, NJS_POINT3 *max);
_inline Int njCheckBBox(NJS_POINT3 *min_h1, NJS_POINT3 *max_h1, NJS_POINT3 *min_h2, NJS_POINT3 *max_h2);
_inline Int njCheckOverlappedRect(NJS_RECT *rect0, NJS_RECT *rect1);


#endif
