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

#include	<shinobi.h>
#include	"Nj.h"
#include	<NjDef.h>
#include	"Data\UV.spa"
#include	"Data\UV.csa"

#define TEXLIST texlist_scene1_model1
#define CELL_SPRITE csprite_scene1_model1
#define CELL_STREAM cstream_scene1_model1

#define PALETTEFILENAME "UVSample.pvp"

Uint32 palette[256];

NJS_TEXPALETTE pl = {palette,0,0,0,0};
Float	x=0.f,y=0.f,z=0.f;
Sint32	rx=0,ry=0,rz=0;
Int step = 0;
Sint32 *wbuf;
NJS_CELL_STREAM_LIST streamlist;
int fno = 0;

/*---------------------------------------------------------------------------
		初期化
		initialize
---------------------------------------------------------------------------*/
Sint32	UserInit(void)
{
	if(nuLoadPaletteFile(PALETTEFILENAME,&pl) < 0){
		return USER_EXIT;
	}
	njSetPaletteMode(pl.mode);
	njSetPaletteData(pl.bank*16 + pl.offset,pl.count,palette);

	if(nuLoadTexture( &TEXLIST ) < 0){
		return USER_EXIT;
	}
	njSetTexture( &TEXLIST );

	if((wbuf = (Sint32*)syMalloc(CELL_SPRITE.nbCell*sizeof(NJS_CELL))) == NULL){
		return USER_EXIT;
	}
	
	njInitCellStreamList(&streamlist,&CELL_SPRITE,wbuf);
	njAddCellStream(&streamlist,&CELL_STREAM);

	return USER_CONTINUE;
}
/*---------------------------------------------------------------------------
		終了処理
		exit
---------------------------------------------------------------------------*/
Sint32	UserExit(void)
{

	syFree(wbuf);

	return USER_CONTINUE;
}
/*---------------------------------------------------------------------------
		メイン
		main
---------------------------------------------------------------------------*/
Sint32	UserMain(void)
{
	Int i,j,t;

#if DEBUG	
	njPrint(NJM_LOCATION(2,3),"CELLSTREAM SAMPLE [UV&SIZE ANIM]");
	njPrint(NJM_LOCATION(2,5),"Frame NO.");
	njPrintD(NJM_LOCATION(11,5),fno,2);
	njPrint(NJM_LOCATION(2,7),"PRESS START");
#endif	
	fno++;
	if(fno == CELL_STREAM.timemax) fno = CELL_STREAM.timemax - 1;


	if(Per->on & PDD_DGT_TA) {
		if(Per->on & PDD_DGT_KU) CELL_SPRITE.zang += 100.f;
		if(Per->on & PDD_DGT_KD) CELL_SPRITE.zang -= 100.f;
	}
	else {

		if(Per->on & PDD_DGT_TL) z -= 1.0f;
		if(Per->on & PDD_DGT_TR) z += 1.0f;

		if(Per->on & PDD_DGT_KU) y += 1.0f;
		if(Per->on & PDD_DGT_KD) y -= 1.0f;
		if(Per->on & PDD_DGT_KL) x -= 1.0f;
		if(Per->on & PDD_DGT_KR) x += 1.0f;

	}

	if(Per->on & PDD_DGT_ST) {
		 njResetCellStreamTime(&streamlist); /**/
		 fno = 0;
	}

	njUnitMatrix(NULL);
	njTranslate( NULL, x, y,-500.f + z);
 	njRotateXYZ( NULL, rx,ry,0 );
	
	step = 1;
	njDrawCellStream3D(&streamlist, NULL, step,NULL);

	return USER_CONTINUE;
}
/*-------------------------------------------------------------------------*/
