/*---------------------------------------------------------------------------
  Shinobi2 Sample
  COPYRIGHT (C) SEGA ENTERPRISES, LTD.
---------------------------------------------------------------------------*/

#include	<shinobi.h>
#include	"Nj.h"

#define LIGHT0		kao_abc_skelton_camera01_Light
#define LMOTION0	motion_kao_abc_skelton_camera01_Light
#define LIGHT1		kao_abc_skelton_camera01_point_Light01_1
#define LMOTION1	motion_kao_abc_skelton_camera01_point_Light01_1
#define LIGHT2		kao_abc_skelton_camera01_point_Light01_2
#define LMOTION2	motion_kao_abc_skelton_camera01_point_Light01_2
#define LIGHT3		kao_abc_skelton_camera01_Ambient

#define OBJECT0		object_kao_abc_skelton_camera01_haikei_Null_haikei_Null
#define TEXLIST0	texlist_kao_abc_skelton_camera01_haikei_Null
#define OBJECT1		object_kao_abc_skelton_camera01_hito_kage01_layer2_hito_kage01_layer2
#define TEXLIST1	texlist_kao_abc_skelton_camera01_hito_kage01_layer2
#define OBJECT2		object_kao_abc_skelton_camera01_kao_x2_kao_x2
#define TEXLIST2	texlist_kao_abc_skelton_camera01_kao_x2

#define MOTION0		motion_kao_abc_skelton_camera01_haikei_Null
#define MOTION1		motion_kao_abc_skelton_camera01_hito_kage01_layer2
#define MOTION20	motion_kao_abc_skelton_camera01_kao_x2
#define MOTION21	cshape_motion_kao_abc_skelton_camera01_kao_x2
#define SSHAPELIST	cshapelist_kao_abc_skelton_camera01_kao_x2

#define CAMERA		kao_abc_skelton_camera01_Camera
#define CMOTION		motion_kao_abc_skelton_camera01_Camera


extern NJS_LIGHT	LIGHT0[];
extern NJS_MOTION	LMOTION0[];
extern NJS_LIGHT	LIGHT1[];
extern NJS_MOTION	LMOTION1[];
extern NJS_LIGHT	LIGHT2[];
extern NJS_MOTION	LMOTION2[];
extern NJS_LIGHT	LIGHT3[];

extern NJS_CNK_OBJECT OBJECT0[];
extern NJS_TEXLIST TEXLIST0[];
extern NJS_CNK_OBJECT OBJECT1[];
extern NJS_TEXLIST TEXLIST1[];
extern NJS_CNK_OBJECT OBJECT2[];
extern NJS_TEXLIST TEXLIST2[];

extern NJS_MOTION	MOTION0[];
extern NJS_MOTION	MOTION1[];
extern NJS_MOTION	MOTION20[];
extern NJS_MOTION	MOTION21[];
extern NJS_CSHAPELIST SSHAPELIST[];

extern NJS_CAMERA	CAMERA[];
extern NJS_MOTION	CMOTION[];

Float frame0 = 0.f;
Float frame1 = 0.f;
Float frame2 = 0.f;
Float lframe = 0.f;
Float cframe = 0.f;

#define LIGHT_NUM	(3)

NJS_MLIGHT_MOTION mlight;
NJS_LIGHT	*lights[LIGHT_NUM];
NJS_MOTION	*lmotions[LIGHT_NUM];

#define MAX_SHAPE_NUM		(100)
Float			*pShapeBuf;

/*---------------------------------------------------------------------------
		初期化
		initialize
---------------------------------------------------------------------------*/
Sint32	UserInit(void)
{
	pShapeBuf	= NULL;

	if(nuLoadTexture(TEXLIST0) < 0){
		return USER_EXIT;
	}

	if(nuLoadTexture(TEXLIST1) < 0){
		return USER_EXIT;
	}

	if(nuLoadTexture(TEXLIST2) < 0){
		return USER_EXIT;
	}

	if ( ( pShapeBuf = syMalloc( 16 * MAX_SHAPE_NUM )) == NULL ) {
		return	USER_EXIT;
	}
	
	//	シェープバッファの確保
	njInitShape( pShapeBuf, MAX_SHAPE_NUM);
	njSetShapeList( SSHAPELIST);

	/* ライトの設定 */
	njCnkSetEasyMultiLight(LIGHT_NUM);

	lights[0] = LIGHT0;
	lights[1] = LIGHT1;
	lights[2] = LIGHT2;
	lmotions[0] = LMOTION0;
	lmotions[1] = LMOTION1;
	lmotions[2] = LMOTION2;

	mlight.n = LIGHT_NUM;
	mlight.lights = lights;
	mlight.motions = lmotions;
	
	return USER_CONTINUE;
}
/*---------------------------------------------------------------------------
		終了処理
		exit
---------------------------------------------------------------------------*/
Sint32	UserExit(void)
{
	syFree(pShapeBuf);
	return USER_CONTINUE;
}

/*---------------------------------------------------------------------------
		メイン
		main
---------------------------------------------------------------------------*/
Sint32	UserMain(void)
{

#if DEBUG
 	njPrint( NJM_LOCATION( 2,2 ), "Ninja2 LIGHT MOTION");
 	njPrint( NJM_LOCATION( 2,4 ), "MOTION: %f",lframe);
#endif
	

	njMultiLightMotion( &mlight, lframe);
	njCnkSetEasyMultiAmbient(LIGHT3->r, LIGHT3->g, LIGHT3->b);
	
	njPushMatrixEx();
	njCameraMotion(CAMERA,CMOTION,cframe);
	njCnkSetEasyMultiLightMatrices();
	
	njSetTexture(TEXLIST0);
	njCnkEasyMultiDrawMotion( OBJECT0, MOTION0, frame0);
	
	njSetTexture(TEXLIST1);
	njCnkEasyMultiDrawMotion( OBJECT1, MOTION1, frame1);
	
	njSetTexture(TEXLIST2);
	njCnkEasyMultiDrawShapeMotion( OBJECT2, MOTION20, MOTION21, frame2);

	njPopMatrixEx();

	lframe += 0.5f;
	if(LMOTION0->nbFrame < lframe) lframe = 0.f;

	cframe += 0.5f;
	if(CMOTION->nbFrame < cframe) cframe = 0.f;

	frame0 += 0.5f;
	if(MOTION0->nbFrame < frame0) frame0 = 0.f;

	frame1 += 0.5f;
	if(MOTION1->nbFrame < frame1) frame1 = 0.f;

	frame2 += 0.5f;
	if(MOTION20->nbFrame < frame2) frame2 = 0.f;
	
	return USER_CONTINUE;
}
/*-------------------------------------------------------------------------*/
